@@ -21,6 +21,10 @@ my $RESET = "\x1b[m";
21
21
my $COLOR = qr /\x1b\[ [0-9;]*m/ ;
22
22
my $BORING = qr /$COLOR |\s / ;
23
23
24
+ # The patch portion of git log -p --graph should only ever have preceding | and
25
+ # not / or \ as merge history only shows up on the commit line.
26
+ my $GRAPH = qr /$COLOR ?\| $COLOR ?\s +/ ;
27
+
24
28
my @removed ;
25
29
my @added ;
26
30
my $in_hunk ;
@@ -32,12 +36,12 @@ $SIG{PIPE} = 'DEFAULT';
32
36
while (<>) {
33
37
if (!$in_hunk ) {
34
38
print ;
35
- $in_hunk = /^$COLOR *\@/;
39
+ $in_hunk = /^$GRAPH * $ COLOR *\@/;
36
40
}
37
- elsif (/ ^$COLOR *-/ ) {
41
+ elsif (/ ^$GRAPH * $ COLOR *-/ ) {
38
42
push @removed , $_ ;
39
43
}
40
- elsif (/ ^$COLOR *\+ / ) {
44
+ elsif (/ ^$GRAPH * $ COLOR *\+ / ) {
41
45
push @added , $_ ;
42
46
}
43
47
else {
@@ -46,7 +50,7 @@ while (<>) {
46
50
@added = ();
47
51
48
52
print ;
49
- $in_hunk = /^$COLOR *[\@ ]/;
53
+ $in_hunk = /^$GRAPH * $ COLOR *[\@ ]/;
50
54
}
51
55
52
56
# Most of the time there is enough output to keep things streaming,
@@ -163,6 +167,9 @@ sub highlight_pair {
163
167
}
164
168
}
165
169
170
+ # we split either by $COLOR or by character. This has the side effect of
171
+ # leaving in graph cruft. It works because the graph cruft does not contain "-"
172
+ # or "+"
166
173
sub split_line {
167
174
local $_ = shift ;
168
175
return utf8::decode($_ ) ?
@@ -211,8 +218,8 @@ sub is_pair_interesting {
211
218
my $suffix_a = join (' ' , @$a [($sa +1)..$#$a ]);
212
219
my $suffix_b = join (' ' , @$b [($sb +1)..$#$b ]);
213
220
214
- return $prefix_a !~ / ^$COLOR *-$BORING *$ / ||
215
- $prefix_b !~ / ^$COLOR *\+ $BORING *$ / ||
221
+ return $prefix_a !~ / ^$GRAPH * $ COLOR *-$BORING *$ / ||
222
+ $prefix_b !~ / ^$GRAPH * $ COLOR *\+ $BORING *$ / ||
216
223
$suffix_a !~ / ^$BORING *$ / ||
217
224
$suffix_b !~ / ^$BORING *$ / ;
218
225
}
0 commit comments