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>
This commit is contained in:
Brian Henderson 2016-08-29 10:33:47 -07:00 committed by Junio C Hamano
parent caf5ea707c
commit 7e4ffb4c17
2 changed files with 14 additions and 7 deletions

View file

@ -21,6 +21,10 @@ my $RESET = "\x1b[m";
my $COLOR = qr/\x1b\[[0-9;]*m/;
my $BORING = qr/$COLOR|\s/;
# The patch portion of git log -p --graph should only ever have preceding | and
# not / or \ as merge history only shows up on the commit line.
my $GRAPH = qr/$COLOR?\|$COLOR?\s+/;
my @removed;
my @added;
my $in_hunk;
@ -32,12 +36,12 @@ $SIG{PIPE} = 'DEFAULT';
while (<>) {
if (!$in_hunk) {
print;
$in_hunk = /^$COLOR*\@/;
$in_hunk = /^$GRAPH*$COLOR*\@/;
}
elsif (/^$COLOR*-/) {
elsif (/^$GRAPH*$COLOR*-/) {
push @removed, $_;
}
elsif (/^$COLOR*\+/) {
elsif (/^$GRAPH*$COLOR*\+/) {
push @added, $_;
}
else {
@ -46,7 +50,7 @@ while (<>) {
@added = ();
print;
$in_hunk = /^$COLOR*[\@ ]/;
$in_hunk = /^$GRAPH*$COLOR*[\@ ]/;
}
# Most of the time there is enough output to keep things streaming,
@ -163,6 +167,9 @@ sub highlight_pair {
}
}
# we split either by $COLOR or by character. This has the side effect of
# leaving in graph cruft. It works because the graph cruft does not contain "-"
# or "+"
sub split_line {
local $_ = shift;
return utf8::decode($_) ?
@ -211,8 +218,8 @@ sub is_pair_interesting {
my $suffix_a = join('', @$a[($sa+1)..$#$a]);
my $suffix_b = join('', @$b[($sb+1)..$#$b]);
return $prefix_a !~ /^$COLOR*-$BORING*$/ ||
$prefix_b !~ /^$COLOR*\+$BORING*$/ ||
return $prefix_a !~ /^$GRAPH*$COLOR*-$BORING*$/ ||
$prefix_b !~ /^$GRAPH*$COLOR*\+$BORING*$/ ||
$suffix_a !~ /^$BORING*$/ ||
$suffix_b !~ /^$BORING*$/;
}

View file

@ -209,7 +209,7 @@ test_expect_failure 'diff-highlight highlights mismatched hunk size' '
# TODO add multi-byte test
test_expect_failure 'diff-highlight works with the --graph option' '
test_expect_success 'diff-highlight works with the --graph option' '
dh_test_setup_history &&
# topo-order so that the order of the commits is the same as with --graph