diff-highlight: add support for --graph output

Signed-off-by: Brian Henderson <henderson.bj@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Brian Henderson committed Aug 29, 2016 at 10:33 UTC 7e4ffb4c1778c725db3db116f016ef2ad1c6d218
2 files changed +14 -7
contrib/diff-highlight/diff-highlight
+13 -6
@@ -21,6 +21,10 @@ my $RESET = "\x1b[m";
21 my $COLOR = qr/\x1b\[[0-9;]*m/;
22 my $BORING = qr/$COLOR|\s/;
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 +
28 my @removed;
29 my @added;
30 my $in_hunk;
@@ -32,12 +36,12 @@ $SIG{PIPE} = 'DEFAULT';
36 while (<>) {
37 if (!$in_hunk) {
38 print;
35 - $in_hunk = /^$COLOR*\@/;
39 + $in_hunk = /^$GRAPH*$COLOR*\@/;
40 }
37 - elsif (/^$COLOR*-/) {
41 + elsif (/^$GRAPH*$COLOR*-/) {
42 push @removed, $_;
43 }
40 - elsif (/^$COLOR*\+/) {
44 + elsif (/^$GRAPH*$COLOR*\+/) {
45 push @added, $_;
46 }
47 else {
@@ -46,7 +50,7 @@ while (<>) {
50 @added = ();
51
52 print;
49 - $in_hunk = /^$COLOR*[\@ ]/;
53 + $in_hunk = /^$GRAPH*$COLOR*[\@ ]/;
54 }
55
56 # Most of the time there is enough output to keep things streaming,
@@ -163,6 +167,9 @@ sub highlight_pair {
167 }
168 }
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 "+"
173 sub split_line {
174 local $_ = shift;
175 return utf8::decode($_) ?
@@ -211,8 +218,8 @@ sub is_pair_interesting {
218 my $suffix_a = join('', @$a[($sa+1)..$#$a]);
219 my $suffix_b = join('', @$b[($sb+1)..$#$b]);
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*$/ ||
223 $suffix_a !~ /^$BORING*$/ ||
224 $suffix_b !~ /^$BORING*$/;
225 }
contrib/diff-highlight/t/t9400-diff-highlight.sh
+1 -1
@@ -209,7 +209,7 @@ test_expect_failure 'diff-highlight highlights mismatched hunk size' '
209
210 # TODO add multi-byte test
211
212 -test_expect_failure 'diff-highlight works with the --graph option' '
212 +test_expect_success 'diff-highlight works with the --graph option' '
213 dh_test_setup_history &&
214
215 # topo-order so that the order of the commits is the same as with --graph