Skip to contentSkip to conversation

difftool: teach difftool to handle directory diffs

PATCH Superseded Tim Henigan 1 participant 1 message Jun 15, 2016 Documentation

v10 of 15 Superseded Latest is v15 →

lore
Share & tools
lore
#0 lore raw

PATCH v10 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 update is intended to be applied to the branch currently found at 'th/difftool-diffall' (based on pu).

Changes in v10:

As Ramsay Jones pointed out on the Git list [1], t7800.3 is failing on some systems because the exit code from difftool is incorrect.

difftool wraps some commands in 'git_cmd_try' blocks. If an exception is raised, these blocks call Carp::croak to exit. However, there appears to be a bug in Carp::croak that causes it to always exit with errno 9 "Bad file descriptor" on some systems.

This happens even with a simple one-liner like:
perl -e 'use 5.008; use Carp qw(croak); print $!+0, " $!\n";'

The above is expected to print "0" and exit without error. However, on the problem systems it prints "9 Bad file descriptor".

To fix the problem, we need to:
- Drop commit 0440ed72 (patch 7/9 "difftool: replace system call with Git::command_noisy") from the series.
- Replace commit 6fbdb7b (patch 8/9 "difftool: teach difftool to handle directory diffs") with this patch. This version changes all instances of 'git_cmd_try' to simple 'system' calls.

[1]: http://thread.gmane.org/gmane.comp.version-control.git/194284/focus=194540

 Documentation/git-difftool.txt |    6 ++
 git-difftool--helper.sh        |   19 +++--
 git-difftool.perl              |  158 +++++++++++++++++++++++++++++++++++-----
 t/t7800-difftool.sh            |   39 ++++++++++
 4 files changed, 197 insertions(+), 25 deletions(-)
Documentation/git-difftool.txt +6 -0
index fe38f66..aba5e76 100644
@@ -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
index e6558d1..3d0fe0c 100755
@@ -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 +139 -19

197 lines not on this page · raw message

t/t7800-difftool.sh +39 -0
index e716d06..478c1be 100755
@@ -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.28.geb866