Skip to content

Commit 7e4ffb4

Browse files
bhendersongitster
authored andcommitted
diff-highlight: add support for --graph output
Signed-off-by: Brian Henderson <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent caf5ea7 commit 7e4ffb4

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

contrib/diff-highlight/diff-highlight

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ my $RESET = "\x1b[m";
2121
my $COLOR = qr/\x1b\[[0-9;]*m/;
2222
my $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+
2428
my @removed;
2529
my @added;
2630
my $in_hunk;
@@ -32,12 +36,12 @@ $SIG{PIPE} = 'DEFAULT';
3236
while (<>) {
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 "+"
166173
sub 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
}

contrib/diff-highlight/t/t9400-diff-highlight.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ test_expect_failure 'diff-highlight highlights mismatched hunk size' '
209209

210210
# TODO add multi-byte test
211211

212-
test_expect_failure 'diff-highlight works with the --graph option' '
212+
test_expect_success 'diff-highlight works with the --graph option' '
213213
dh_test_setup_history &&
214214
215215
# topo-order so that the order of the commits is the same as with --graph

0 commit comments

Comments
 (0)