Skip to contentSkip to conversation

Display change history as a diff between two dirs

PATCH New Roland Kaufmann 1 participant 1 message Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 Display change history as a diff between two dirs

Watching patches serially it can be difficult to get an overview of how a pervasive change is distributed through-out different modules. Thus;

Extract snapshots of the files that have changed between two revisions into temporary directories and launch a graphical tool to show the diff between them.

Use existing functionality in git-diff to get the files themselves, and git-difftool to launch the diff viewer.

Based on a script called 'git-diffc' by Nitin Gupta.

---
Following issues are addressed in this revised patch:

* Test explicitly for errors. Use die to show messages and exit. However, I assume that git, mkdir and cp are capable of producing sensible messages themselves, and in those cases just exit.

* Temporary directory is created using mktemp using the -d option which is usable on most modern platforms. On more crippled platforms, I revert to using Perl, since it has the best chance of being available (if not, then I reckon there are larger parts of Git that won't work).

I have tested this approach with msysGit. Unfortunately, I don't have testing capabilities for Solaris, HP-UX or AIX.

* Snapshots are taken using only one invocation of git diff; no separate listing of files processed.

* If there are no files in either snapshots (i.e. you are comparing two empty directories), then don't launch the diff-viewer. This takes care of many cases where it is invoked with options that are really not applicable.

* Scripts and manpage are put in contrib/ to gather feedback about the usefulness and design issues before I make a go at adding it as an option to git-diff itself. (README tells how to install since it is not in the main Makefile).

 contrib/dirdiff/README                 |   10 +++++
 contrib/dirdiff/git-dirdiff--helper.sh |   37 ++++++++++++++++++++
 contrib/dirdiff/git-dirdiff.sh         |   58 ++++++++++++++++++++++++++++++++
 contrib/dirdiff/git-dirdiff.txt        |   55 ++++++++++++++++++++++++++++++
 4 files changed, 160 insertions(+), 0 deletions(-)
 create mode 100644 contrib/dirdiff/README
 create mode 100755 contrib/dirdiff/git-dirdiff--helper.sh
 create mode 100755 contrib/dirdiff/git-dirdiff.sh
 create mode 100644 contrib/dirdiff/git-dirdiff.txt
contrib/dirdiff/README new file +10 -0
new file mode 100644
index 0000000..d06461a
@@ -0,0 +1,10 @@
+# install on GNU, BSD:
+for f in "" "--helper"; do
+  b=git-dirdiff$f
+  sudo install -m 0755 contrib/dirdiff/$b.sh $(git --exec-path)/$b
+done
+
+# install on Windows
+for /f %a in ('git --exec-path') do set GIT_PATH=%a
+set GIT_PATH=%GIT_PATH:/=\%
+for %a in ("" "--helper") do copy contrib\dirdiff\git-dirdiff%~a.sh "%GIT_PATH%\%~a" /y
contrib/dirdiff/git-dirdiff--helper.sh new file +37 -0
new file mode 100755
index 0000000..8ff0124
@@ -0,0 +1,37 @@
+#!/bin/sh
+#
+# Accumulate files in a changeset into a pre-defined directory.
+#
+# Copyright (C) 2011 Roland Kaufmann
+#
+# Based on a script called git-diffc by Nitin Gupta and valuable
+# suggestions by Junio C. Hamano.
+#
+# This file is licensed under the GPL v2, or a later version
+# at the discretion of the official Git maintainer.
+
+. git-sh-setup
+
+# check that we are called by git-dirdiff
+test -z "$__GIT_DIFF_DIR" &&
+  die Error: Do not call $(basename "$0") directly
+
+# what is the directory name of the file that has changed
+RELDIR=$(dirname "$1") ||
+  exit $?
+
+# don't attempt to copy new or removed files
+if test "$2" != "/dev/null"
+then
+  mkdir -p "$__GIT_DIFF_DIR/old/$RELDIR" ||
+    exit $?
+  cp "$2" "$__GIT_DIFF_DIR/old/$1" ||
+    exit $?
+fi
+if test "$5" != "/dev/null"
+then
+  mkdir -p "$__GIT_DIFF_DIR/new/$RELDIR" ||
+    exit $?
+  cp "$5" "$__GIT_DIFF_DIR/new/$1" ||
+    exit $?
+fi
contrib/dirdiff/git-dirdiff.sh new file +58 -0

58 lines not on this page · raw message

contrib/dirdiff/git-dirdiff.txt new file +55 -0

55 lines not on this page · raw message

Signature · 1 line
1.7.1