Skip to content

Commit 2052c52

Browse files
committed
Merge branch 'jk/add-i-highlight'
* jk/add-i-highlight: add--interactive: allow custom diff highlighting programs
2 parents 1b68962 + 0114384 commit 2052c52

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

‎Documentation/config.txt‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1887,6 +1887,14 @@ interactive.singleKey::
18871887
setting is silently ignored if portable keystroke input
18881888
is not available; requires the Perl module Term::ReadKey.
18891889

1890+
interactive.diffFilter::
1891+
When an interactive command (such as `git add --patch`) shows
1892+
a colorized diff, git will pipe the diff through the shell
1893+
command defined by this configuration variable. The command may
1894+
mark up the diff further for human consumption, provided that it
1895+
retains a one-to-one correspondence with the lines in the
1896+
original diff. Defaults to disabled (no filtering).
1897+
18901898
log.abbrevCommit::
18911899
If true, makes linkgit:git-log[1], linkgit:git-show[1], and
18921900
linkgit:git-whatchanged[1] assume `--abbrev-commit`. You may

‎git-add--interactive.perl‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
my $normal_color = $repo->get_color("", "reset");
4646

4747
my $diff_algorithm = $repo->config('diff.algorithm');
48+
my $diff_filter = $repo->config('interactive.difffilter');
4849

4950
my $use_readkey = 0;
5051
my $use_termcap = 0;
@@ -754,7 +755,14 @@ sub parse_diff {
754755
my @diff = run_cmd_pipe("git", @diff_cmd, "--", $path);
755756
my @colored = ();
756757
if ($diff_use_color) {
757-
@colored = run_cmd_pipe("git", @diff_cmd, qw(--color --), $path);
758+
my @display_cmd = ("git", @diff_cmd, qw(--color --), $path);
759+
if (defined $diff_filter) {
760+
# quotemeta is overkill, but sufficient for shell-quoting
761+
my $diff = join(' ', map { quotemeta } @display_cmd);
762+
@display_cmd = ("$diff | $diff_filter");
763+
}
764+
765+
@colored = run_cmd_pipe(@display_cmd);
758766
}
759767
my (@hunk) = { TEXT => [], DISPLAY => [], TYPE => 'header' };
760768

@@ -765,7 +773,7 @@ sub parse_diff {
765773
}
766774
push @{$hunk[-1]{TEXT}}, $diff[$i];
767775
push @{$hunk[-1]{DISPLAY}},
768-
($diff_use_color ? $colored[$i] : $diff[$i]);
776+
(@colored ? $colored[$i] : $diff[$i]);
769777
}
770778
return @hunk;
771779
}

0 commit comments

Comments
 (0)