difftool: teach difftool to handle directory diffs
PATCH v12 8/9 difftool: teach difftool to handle directory diffs
When 'difftool' is called to compare a range of commits that modify more than one file, it opens a separate instance of the diff tool for each file that changed.
The new '--dir-diff' option copies all the modified files to a temporary location and runs a directory diff on them in a single instance of the diff tool.
---
This replaces 5038aa2 on the 'th/difftool-diffall' branch.
Changes in v12:
- Updates based on patch review by David Aguilar [1]
* Reword script header comment to no longer enumerate each exported var.
* Changed shebang line to #!/usr/bin/perl.
* Changed $null_mode to use string form of "0" x 6.
* Changed $null_sha1 to use string form of "0" x 40.
* Changed for(@rawdiff) loop to use $#rawdiff.
* Dropped extra parens from all 'system' calls.
* The return value of all 'system' calls are now checked.
* Changed 'for (@working_tree)' to 'for my $file (@working_tree)'.
* Changed 'foreach my $path' to 'for my $path'.
* All calls to 'defined()' now use consistent style.
* Comment about ActiveState Perl 'exec' is now retained.
- Changes to allow 'difftool' to be called with $GIT_DIR and $GIT_WORK_TREE overridden at the command-line (or via core.worktree):
* Changed 'git diff --raw' to be called using backticks to insure that env vars set by the user on the command-line (i.e. GIT_DIR and GIT_WORK_TREE) are used.
* Added comments indicating why $GIT_DIR is explicitly set prior to calling 'git update-index' and 'git checkout-index'.
* If $GIT_DIR is set by the script, it is now unset after being used.
* $GIT_INDEX_FILE is now always unset after being used.
* Added helper function (find_worktree) to work around issues with Git->repository->wc_path(). See the comment in the script for details.
[1]: http://thread.gmane.org/gmane.comp.version-control.git/194721/focus=195014
Documentation/git-difftool.txt | 6 ++ git-difftool--helper.sh | 19 ++-- git-difftool.perl | 216 ++++++++++++++++++++++++++++++++++++---- t/t7800-difftool.sh | 39 ++++++++ 4 files changed, 254 insertions(+), 26 deletions(-)
Documentation/git-difftool.txt +6 -0
@@ -19,6 +19,12 @@ linkgit:git-diff[1]. OPTIONS ------- +-d:: +--dir-diff:: + Copy the modified files to a temporary location and perform + a directory diff on them. This mode never prompts before + launching the diff tool. + -y:: --no-prompt:: Do not prompt before launching a diff tool.
git-difftool--helper.sh +13 -6
@@ -73,9 +73,16 @@ then fi fi -# Launch the merge tool on each path provided by 'git diff' -while test $# -gt 6 -do - launch_merge_tool "$1" "$2" "$5" - shift 7 -done +if test -n "$GIT_DIFFTOOL_DIRDIFF" +then + LOCAL="$1" + REMOTE="$2" + run_merge_tool "$merge_tool" false +else + # Launch the merge tool on each path provided by 'git diff' + while test $# -gt 6 + do + launch_merge_tool "$1" "$2" "$5" + shift 7 + done +fi
git-difftool.perl +196 -20
254 lines not on this page · raw message
t/t7800-difftool.sh +39 -0
@@ -319,4 +319,43 @@ test_expect_success PERL 'say no to the second file' ' echo "$diff" | stdin_doesnot_contain br2 ' +test_expect_success PERL 'setup change in subdirectory' ' + git checkout master && + mkdir sub && + echo master >sub/sub && + git add sub/sub && + git commit -m "added sub/sub" && + echo test >>file && + echo test >>sub/sub && + git add . && + git commit -m "modified both" +' + +test_expect_success PERL 'difftool -d' ' + diff=$(git difftool -d --extcmd ls branch) && + echo "$diff" | stdin_contains sub && + echo "$diff" | stdin_contains file +' + +test_expect_success PERL 'difftool --dir-diff' ' + diff=$(git difftool --dir-diff --extcmd ls branch) && + echo "$diff" | stdin_contains sub && + echo "$diff" | stdin_contains file +' + +test_expect_success PERL 'difftool --dir-diff ignores --prompt' ' + diff=$(git difftool --dir-diff --prompt --extcmd ls branch) && + echo "$diff" | stdin_contains sub && + echo "$diff" | stdin_contains file +' + +test_expect_success PERL 'difftool --dir-diff from subdirectory' ' + ( + cd sub && + diff=$(git difftool --dir-diff --extcmd ls branch) && + echo "$diff" | stdin_contains sub && + echo "$diff" | stdin_contains file + ) +' + test_done
Signature · 1 line
1.7.10.rc1.26.g40aa3
git-difftool.perl usage: git difftool [-t|--tool=<tool>] · line 66
Quoted 5 lines · Tim Henigan
git-difftool.perl +5
-0+sub setup_dir_diff +{ + # Run the diff; exit immediately if no diff found + my $cmd = "git diff --raw --no-abbrev -z " . join(" ", @ARGV); + my $diffrtn = `$cmd` or die $!;
Why this change? It looks like a rather unpleasant regression compared to the previous one that used "command_oneline", so that each element of @ARGV was given as a single argument to the command. Now, you are splitting any argument that has $IFS in it.
Quoted 12 lines · Junio C Hamano
git-difftool.perl usage: git difftool [-t|--tool=<tool>] · line 66
Quoted 5 lines · Tim Henigan
git-difftool.perl +5
-0+sub setup_dir_diff +{ + # Run the diff; exit immediately if no diff found + my $cmd = "git diff --raw --no-abbrev -z " . join(" ", @ARGV); + my $diffrtn = `$cmd` or die $!;Why this change? It looks like a rather unpleasant regression compared to the previous one that used "
command_oneline", so that each element of @ARGV was given as a single argument to the command. Now, you are splitting any argument that has $IFS in it.
The 'Git->repository->command*' functions all override the $GIT_WORK_TREE set by the user on the command line with 'pwd'. They also override the 'core.worktree' setting, if it is used.
So without this change, the following fails:
$ GIT_DIR=<dir> GIT_WORK_TREE=<dir> git difftool -d
Would the following change be better?
- my $cmd = "git diff --raw --no-abbrev -z " . join(" ", @ARGV);
+ my $cmd = "git diff --raw --no-abbrev -z @ARGV";
Quoted 4 lines · Tim Henigan
Would the following change be better?
- my $cmd = "git diff --raw --no-abbrev -z " .
join(" ", @ARGV);
+ my $cmd = "git diff --raw --no-abbrev -z @ARGV";
They look exactly the same to me.
Quoted 8 lines · Junio C Hamano
Quoted 4 lines · Tim Henigan
Would the following change be better?
- my $cmd = "git diff --raw --no-abbrev -z " .
join(" ", @ARGV);
+ my $cmd = "git diff --raw --no-abbrev -z @ARGV";They look exactly the same to me.
The issue is that this does not properly handle shell characters, IFS, etc.
I think a simple solution would be to use git diff --exit-code --quiet here.
e.g.
my $rc = system('git', 'diff', '--exit-code', '--quiet', @ARGV);That avoids the shell and properly handles shell meta-characters, IFS, etc.
Signature · 1 line
David
Quoted 10 lines · David Aguilar
The issue is that this does not properly handle shell characters, IFS, etc.
I think a simple solution would be to use git diff --exit-code --quiet here.
e.g.
my $rc =
system('git', 'diff', '--exit-code', '--quiet', @ARGV);That avoids the shell and properly handles shell meta-characters, IFS, etc.
The problem is that I need the output of 'git diff' to drive the rest of the script. Getting STDOUT from a system() call is difficult, so I switched to backticks. Obviously I missed the regression.
The best solution seems to be to find a way to make 'Git->repository->command*' to work with $GIT_DIR and $GIT_WORK_TREE. I will send v13 with this change soon.