From 2cc0f53b53e7d5456ec45713a201142754d69249 Mon Sep 17 00:00:00 2001 From: John Keeping Date: Wed, 12 Jun 2013 19:44:10 +0100 Subject: add--interactive: respect diff.algorithm When staging hunks interactively it is sometimes useful to use an alternative diff algorithm which splits the changes into hunks in a more logical manner. This is not possible because the plumbing commands called by add--interactive ignore the "diff.algorithm" configuration option (as they should). Since add--interactive is a porcelain command it should respect this configuration variable. To do this, make it read diff.algorithm and pass its value to the underlying diff-index and diff-files invocations. At this point, do not add options to "git add", "git reset" or "git checkout" (all of which can call git-add--interactive). If a user wants to override the value on the command line they can use: git -c diff.algorithm=$ALGO ... Signed-off-by: John Keeping Reviewed-by: Jeff King Signed-off-by: Junio C Hamano --- git-add--interactive.perl | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/git-add--interactive.perl b/git-add--interactive.perl index d2c4ce6e1..531095916 100755 --- a/git-add--interactive.perl +++ b/git-add--interactive.perl @@ -44,6 +44,8 @@ my ($diff_new_color) = my $normal_color = $repo->get_color("", "reset"); +my $diff_algorithm = $repo->config('diff.algorithm'); + my $use_readkey = 0; my $use_termcap = 0; my %term_escapes; @@ -731,6 +733,9 @@ sub run_git_apply { sub parse_diff { my ($path) = @_; my @diff_cmd = split(" ", $patch_mode_flavour{DIFF}); + if (defined $diff_algorithm) { + push @diff_cmd, "--diff-algorithm=${diff_algorithm}"; + } if (defined $patch_mode_revision) { push @diff_cmd, $patch_mode_revision; } -- cgit v1.2.1 From e5c29097826be86e2f18139491cdf9c830c7fa3e Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sun, 23 Jun 2013 12:19:05 -0700 Subject: add -i: add extra options at the right place in "diff" command line Appending "--diff-algorithm=histogram" at the end of canned command line for various modes of "diff" is correct for most of them but not for "stash" that has a non-option already wired in, like so: 'stash' => { DIFF => 'diff-index -p HEAD', Appending an extra option after non-option may happen to work due to overly lax command line parser, but that is not something we should rely on. Instead, splice in the extra argument immediately after the command name (i.e. 'diff-index', 'diff-files', etc.). Signed-off-by: Junio C Hamano --- git-add--interactive.perl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-add--interactive.perl b/git-add--interactive.perl index 531095916..75a991f7e 100755 --- a/git-add--interactive.perl +++ b/git-add--interactive.perl @@ -734,7 +734,7 @@ sub parse_diff { my ($path) = @_; my @diff_cmd = split(" ", $patch_mode_flavour{DIFF}); if (defined $diff_algorithm) { - push @diff_cmd, "--diff-algorithm=${diff_algorithm}"; + splice @diff_cmd, 1, 0, "--diff-algorithm=${diff_algorithm}"; } if (defined $patch_mode_revision) { push @diff_cmd, $patch_mode_revision; -- cgit v1.2.1