summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 097128d)
raw | patch | inline | side by side (parent: 097128d)
author | Jeff King <peff@peff.net> | |
Mon, 13 Feb 2012 22:33:10 +0000 (17:33 -0500) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Mon, 13 Feb 2012 23:57:06 +0000 (15:57 -0800) |
The current code structure assumes that we will only look at
a pair of lines at any given time, and that the end result
should always be to output that pair. However, we want to
eventually handle multi-line hunks, which will involve
collating pairs of removed/added lines. Let's refactor the
code to return highlighted pairs instead of printing them.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
a pair of lines at any given time, and that the end result
should always be to output that pair. However, we want to
eventually handle multi-line hunks, which will involve
collating pairs of removed/added lines. Let's refactor the
code to return highlighted pairs instead of printing them.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
contrib/diff-highlight/diff-highlight | patch | blob | history |
index 0d8df84a20fd2745176b733d1b7437ac8d53c5aa..279d21181e9e34a8b4295a7624d43533bd5dca3e 100755 (executable)
$window[2] =~ /^$COLOR*\+/ &&
$window[3] !~ /^$COLOR*\+/) {
print shift @window;
- show_pair(shift @window, shift @window);
+ show_hunk(shift @window, shift @window);
}
else {
print shift @window;
$window[1] =~ /^$COLOR*-/ &&
$window[2] =~ /^$COLOR*\+/) {
print shift @window;
- show_pair(shift @window, shift @window);
+ show_hunk(shift @window, shift @window);
}
# And then flush any remaining lines.
exit 0;
-sub show_pair {
+sub show_hunk {
+ my ($a, $b) = @_;
+
+ print highlight_pair($a, $b);
+}
+
+sub highlight_pair {
my @a = split_line(shift);
my @b = split_line(shift);
}
if (is_pair_interesting(\@a, $pa, $sa, \@b, $pb, $sb)) {
- print highlight(\@a, $pa, $sa);
- print highlight(\@b, $pb, $sb);
+ return highlight_line(\@a, $pa, $sa),
+ highlight_line(\@b, $pb, $sb);
}
else {
- print join('', @a);
- print join('', @b);
+ return join('', @a),
+ join('', @b);
}
}
split /($COLOR*)/;
}
-sub highlight {
+sub highlight_line {
my ($line, $prefix, $suffix) = @_;
return join('',