@@ -21,6 +21,10 @@ my $RESET = "\x1b[m";
2121my $COLOR = qr /\x1b\[ [0-9;]*m/ ;
2222my $BORING = qr /$COLOR |\s / ;
2323
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+
2428my @removed ;
2529my @added ;
2630my $in_hunk ;
@@ -32,12 +36,12 @@ $SIG{PIPE} = 'DEFAULT';
3236while (<>) {
3337 if (!$in_hunk ) {
3438 print ;
35- $in_hunk = /^$COLOR *\@/;
39+ $in_hunk = /^$GRAPH * $ COLOR *\@/;
3640 }
37- elsif (/ ^$COLOR *-/ ) {
41+ elsif (/ ^$GRAPH * $ COLOR *-/ ) {
3842 push @removed , $_ ;
3943 }
40- elsif (/ ^$COLOR *\+ / ) {
44+ elsif (/ ^$GRAPH * $ COLOR *\+ / ) {
4145 push @added , $_ ;
4246 }
4347 else {
@@ -46,7 +50,7 @@ while (<>) {
4650 @added = ();
4751
4852 print ;
49- $in_hunk = /^$COLOR *[\@ ]/;
53+ $in_hunk = /^$GRAPH * $ COLOR *[\@ ]/;
5054 }
5155
5256 # Most of the time there is enough output to keep things streaming,
@@ -163,6 +167,9 @@ sub highlight_pair {
163167 }
164168}
165169
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 "+"
166173sub split_line {
167174 local $_ = shift ;
168175 return utf8::decode($_ ) ?
@@ -211,8 +218,8 @@ sub is_pair_interesting {
211218 my $suffix_a = join (' ' , @$a [($sa +1)..$#$a ]);
212219 my $suffix_b = join (' ' , @$b [($sb +1)..$#$b ]);
213220
214- return $prefix_a !~ / ^$COLOR *-$BORING *$ / ||
215- $prefix_b !~ / ^$COLOR *\+ $BORING *$ / ||
221+ return $prefix_a !~ / ^$GRAPH * $ COLOR *-$BORING *$ / ||
222+ $prefix_b !~ / ^$GRAPH * $ COLOR *\+ $BORING *$ / ||
216223 $suffix_a !~ / ^$BORING *$ / ||
217224 $suffix_b !~ / ^$BORING *$ / ;
218225}
0 commit comments