Skip to contentSkip to conversation

difftool: teach difftool to handle directory diffs

PATCH In review Tim Henigan 2 participants 2 messages Jun 15, 2016 Documentation

lore
Share & tools
lore
#0 lore raw

PATCH v15 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 7fbdc6c on the th/difftool-diffall branch [1].

Changes in v15:
- The output of 'git diff --raw' now is now split on the NULL tokens first, instead of ':'. As pointed out by Junio Hamano on the Git list [2], ':' is valid filename character on some systems.
- Replaced double quotes with single quotes where appropriate. This change was requested by David Aguilar on the Git list [3].
- The source of a copied file is no longer shown on the left-hand side of the diff.

[1]: https://github.com/gitster/git/tree/th/difftool-diffall
[2]: http://thread.gmane.org/gmane.comp.version-control.git/196009/focus=196024
[3]: http://thread.gmane.org/gmane.comp.version-control.git/196009/focus=196062

 Documentation/git-difftool.txt |    6 +
 git-difftool--helper.sh        |   19 ++-
 git-difftool.perl              |  266 ++++++++++++++++++++++++++++++++++++----
 t/t7800-difftool.sh            |   39 ++++++
 4 files changed, 303 insertions(+), 27 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 +245 -21

309 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.29.geead
#1 lore raw
Quoted 7 lines · Tim Henigan
git-difftool.perl +7 -0
+	while ($i < $#rawdiff) {
+		if ($rawdiff[$i] =~ /^::/) {
+			print "Combined diff formats ('-c' and '--cc') are not supported in directory diff mode.\n";
+			exit(1);
+		}
+
+		my ($lmode, $rmode, $lsha1, $rsha1, $status) = split(' ', substr($rawdiff[$i], 1));

git-difftool.perl usage: git difftool [-t|--tool=<tool>] · line 110

Quoted 10 lines
git-difftool.perl +10 -0
+		my $src_path = $rawdiff[$i + 1];
+		my $dst_path;
+
+		if ($status =~ /^[CR]/) {
+			$dst_path = $rawdiff[$i + 2];
+			$i += 3;
+		} else {
+			$dst_path = $src_path;
+			$i += 2;
+		}

The update to this part looks good to me ;-)

Thanks. Will replace what is queued.