Skip to content

Commit dd6f90b

Browse files
committed
Recognize other lines generated by sdiff
1 parent df95192 commit dd6f90b

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

bin/csdiff

+12-4
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ my $CHANGED = ON_BLUE;
7272
my $MISSINGNL = ON_MAGENTA;
7373
my $UNCHANGED = "";
7474
my $OMITTED = MAGENTA;
75+
my $MESSAGE = BLACK . ON_YELLOW; # lines generated by sdiff outside of diffs proper
7576

7677
my $OFF = RESET;
7778

@@ -174,7 +175,13 @@ my @spec = ();
174175
for (my $n=0;$n<@out;$n++) {
175176
my $line = $out[$n];
176177
chomp $line;
177-
my $spec = length($line) >= $spos ? substr($line,$spos,1) : " ";
178+
my $spec = " ";
179+
if ($line =~ /^diff |^Common subdirectories:|^Only in/) {
180+
$spec = "m"; # means a message generated by sdiff
181+
$line = $MESSAGE.$line.$OFF."\n";
182+
} else {
183+
$spec = length($line) >= $spos ? substr($line,$spos,1) : " ";
184+
}
178185
if ($spec eq ">") {
179186
$line .= (" " x ($cols - length($line)));
180187
$line = $INSERT.$line.$OFF."\n";
@@ -187,9 +194,9 @@ for (my $n=0;$n<@out;$n++) {
187194
} elsif (($spec eq "/") || ($spec eq "\\")) {
188195
$line .= (" " x ($cols - length($line)));
189196
$line = $MISSINGNL.$line.$OFF."\n";
190-
} else {
191-
$line = $UNCHANGED.$line.$UNCHOFF."\n";
197+
} elsif ($spec ne "m") {
192198
$spec = " ";
199+
$line = $UNCHANGED.$line.$UNCHOFF."\n";
193200
}
194201
$out[$n] = $line;
195202
$spec[$n] = $spec;
@@ -198,6 +205,7 @@ for (my $n=0;$n<@out;$n++) {
198205
my %SHOW_SPECS=();
199206
$FILTERS ||= "udamco"; # all
200207
$FILTERS .= "u" if defined($CONTEXT);
208+
$SHOW_SPECS{"m"}=1; # sdiff messages
201209
$SHOW_SPECS{" "}=1 if $FILTERS =~ /[us]/i; # unchanged/same
202210
$SHOW_SPECS{"<"}=1 if $FILTERS =~ /d/i; # deleted
203211
$SHOW_SPECS{">"}=1 if $FILTERS =~ /a/i; # added
@@ -210,7 +218,7 @@ if (defined($CONTEXT)) {
210218
my $prevend = -1;
211219
for (my $n=0;$n<@out;$n++) {
212220
my $spec = $spec[$n] || " ";
213-
next if $spec eq " " || !$SHOW_SPECS{$spec};
221+
next if $spec =~ /[m ]/ || !$SHOW_SPECS{$spec};
214222
my $start = $n - $CONTEXT; $start = 0 if $start < 0;
215223
$start = $prevend + 1 if $start <= $prevend;
216224
my $end = $n;

0 commit comments

Comments
 (0)