summaryrefslogtreecommitdiff
path: root/git-add--interactive.perl
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2016-02-27 05:37:06 (GMT)
committerJunio C Hamano <gitster@pobox.com>2016-02-28 18:53:54 (GMT)
commit01143847dbf4fbf27268650f3ace16eac03b3130 (patch)
tree190b07e4d7394842da11b82d346cf420f5e7b771 /git-add--interactive.perl
parentf02fbc4f9433937ee0463d0342d6d7d97e1f6f1e (diff)
downloadgit-01143847dbf4fbf27268650f3ace16eac03b3130.zip
git-01143847dbf4fbf27268650f3ace16eac03b3130.tar.gz
git-01143847dbf4fbf27268650f3ace16eac03b3130.tar.bz2
add--interactive: allow custom diff highlighting programs
The patch hunk selector of add--interactive knows how ask git for colorized diffs, and correlate them with the uncolored diffs we apply. But there's not any way for somebody who uses a diff-filter tool like contrib's diff-highlight to see their normal highlighting. This patch lets users define an arbitrary shell command to pipe the colorized diff through. The exact output shouldn't matter (since we just show the result to humans) as long as it is line-compatible with the original diff (so that hunk-splitting can split the colorized version, too). I left two minor issues with the new system that I don't think are worth fixing right now, but could be done later: 1. We only filter colorized diffs. Theoretically a user could want to filter a non-colorized diff, but I find it unlikely in practice. Users who are doing things like diff-highlighting are likely to want color, too. 2. add--interactive will re-colorize a diff which has been hand-edited, but it won't have run through the filter. Fixing this is conceptually easy (just pipe the diff through the filter), but practically hard to do without using tempfiles (it would need to feed data to and read the result from the filter without deadlocking; this raises portability questions with respect to Windows). I've punted on both issues for now, and if somebody really cares later, they can do a patch on top. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'git-add--interactive.perl')
-rwxr-xr-xgit-add--interactive.perl12
1 files changed, 10 insertions, 2 deletions
diff --git a/git-add--interactive.perl b/git-add--interactive.perl
index 77876d4..822f857 100755
--- a/git-add--interactive.perl
+++ b/git-add--interactive.perl
@@ -45,6 +45,7 @@ my ($diff_new_color) =
my $normal_color = $repo->get_color("", "reset");
my $diff_algorithm = $repo->config('diff.algorithm');
+my $diff_filter = $repo->config('interactive.difffilter');
my $use_readkey = 0;
my $use_termcap = 0;
@@ -754,7 +755,14 @@ sub parse_diff {
my @diff = run_cmd_pipe("git", @diff_cmd, "--", $path);
my @colored = ();
if ($diff_use_color) {
- @colored = run_cmd_pipe("git", @diff_cmd, qw(--color --), $path);
+ my @display_cmd = ("git", @diff_cmd, qw(--color --), $path);
+ if (defined $diff_filter) {
+ # quotemeta is overkill, but sufficient for shell-quoting
+ my $diff = join(' ', map { quotemeta } @display_cmd);
+ @display_cmd = ("$diff | $diff_filter");
+ }
+
+ @colored = run_cmd_pipe(@display_cmd);
}
my (@hunk) = { TEXT => [], DISPLAY => [], TYPE => 'header' };
@@ -765,7 +773,7 @@ sub parse_diff {
}
push @{$hunk[-1]{TEXT}}, $diff[$i];
push @{$hunk[-1]{DISPLAY}},
- ($diff_use_color ? $colored[$i] : $diff[$i]);
+ (@colored ? $colored[$i] : $diff[$i]);
}
return @hunk;
}