Skip to content

Commit

Permalink
Merge branch 'jk/add-i-highlight'
Browse files Browse the repository at this point in the history
* jk/add-i-highlight:
  add--interactive: allow custom diff highlighting programs
  • Loading branch information
Junio C Hamano committed Apr 3, 2016
2 parents 1b68962 + 0114384 commit 2052c52
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
8 changes: 8 additions & 0 deletions Documentation/config.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1887,6 +1887,14 @@ interactive.singleKey::
setting is silently ignored if portable keystroke input
is not available; requires the Perl module Term::ReadKey.

interactive.diffFilter::
When an interactive command (such as `git add --patch`) shows
a colorized diff, git will pipe the diff through the shell
command defined by this configuration variable. The command may
mark up the diff further for human consumption, provided that it
retains a one-to-one correspondence with the lines in the
original diff. Defaults to disabled (no filtering).

log.abbrevCommit::
If true, makes linkgit:git-log[1], linkgit:git-show[1], and
linkgit:git-whatchanged[1] assume `--abbrev-commit`. You may
Expand Down
12 changes: 10 additions & 2 deletions git-add--interactive.perl
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
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;
Expand Down Expand Up @@ -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' };

Expand All @@ -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;
}
Expand Down

0 comments on commit 2052c52

Please sign in to comment.