{"thread":{"id":"28811","subject":"[PATCH v2] Display change history as a diff between two dirs","startedAt":"2011-10-31T22:21:58Z","lastAt":"2011-10-31T22:21:58Z","messageCount":1,"participants":["Roland Kaufmann"],"isPatch":true,"patchVersion":2,"patchTotal":null},"messages":[{"id":"178585","messageId":"4EAF1F86.5020108@gmail.com","threadId":"28811","inReplyTo":null,"subject":"[PATCH v2] Display change history as a diff between two dirs","fromName":"Roland Kaufmann","fromEmail":"rlndkfmn+git@gmail.com","sentAt":"2011-10-31T22:21:58Z","receivedAt":"2011-10-31T22:21:58Z","isPatch":true,"sender":{"key":"rlndkfmn+git@gmail.com","avatar":null},"body":"Watching patches serially it can be difficult to get an overview of how\na pervasive change is distributed through-out different modules. Thus;\n\nExtract snapshots of the files that have changed between two revisions\ninto temporary directories and launch a graphical tool to show the diff\nbetween them.\n\nUse existing functionality in git-diff to get the files themselves, and\ngit-difftool to launch the diff viewer.\n\nBased on a script called 'git-diffc' by Nitin Gupta.\n\nSigned-off-by: Roland Kaufmann <rlndkfmn+git@gmail.com>\n---\nFollowing issues are addressed in this revised patch:\n\n* Test explicitly for errors. Use `die` to show messages and exit. \n  However, I assume that git, mkdir and cp are capable of producing \n  sensible messages themselves, and in those cases just exit.\n\n* Temporary directory is created using mktemp using the -d option which\n  is usable on most modern platforms. On more crippled platforms, I \n  revert to using Perl, since it has the best chance of being available \n  (if not, then I reckon there are larger parts of Git that won't work).\n\n  I have tested this approach with msysGit. Unfortunately, I don't have\n  testing capabilities for Solaris, HP-UX or AIX.\n\n* Snapshots are taken using only one invocation of `git diff`; no \n  separate listing of files processed.\n\n* If there are no files in either snapshots (i.e. you are comparing two\n  empty directories), then don't launch the diff-viewer. This takes\n  care of many cases where it is invoked with options that are really \n  not applicable.\n\n* Scripts and manpage are put in contrib/ to gather feedback about the\n  usefulness and design issues before I make a go at adding it as an\n  option to git-diff itself. (README tells how to install since it is\n  not in the main Makefile).\n\n contrib/dirdiff/README                 |   10 +++++\n contrib/dirdiff/git-dirdiff--helper.sh |   37 ++++++++++++++++++++\n contrib/dirdiff/git-dirdiff.sh         |   58 ++++++++++++++++++++++++++++++++\n contrib/dirdiff/git-dirdiff.txt        |   55 ++++++++++++++++++++++++++++++\n 4 files changed, 160 insertions(+), 0 deletions(-)\n create mode 100644 contrib/dirdiff/README\n create mode 100755 contrib/dirdiff/git-dirdiff--helper.sh\n create mode 100755 contrib/dirdiff/git-dirdiff.sh\n create mode 100644 contrib/dirdiff/git-dirdiff.txt\n\ndiff --git a/contrib/dirdiff/README b/contrib/dirdiff/README\nnew file mode 100644\nindex 0000000..d06461a\n--- /dev/null\n+++ b/contrib/dirdiff/README\n@@ -0,0 +1,10 @@\n+# install on GNU, BSD:\n+for f in \"\" \"--helper\"; do\n+  b=git-dirdiff$f\n+  sudo install -m 0755 contrib/dirdiff/$b.sh $(git --exec-path)/$b\n+done\n+\n+# install on Windows\n+for /f %a in ('git --exec-path') do set GIT_PATH=%a\n+set GIT_PATH=%GIT_PATH:/=\\%\n+for %a in (\"\" \"--helper\") do copy contrib\\dirdiff\\git-dirdiff%~a.sh \"%GIT_PATH%\\%~a\" /y\ndiff --git a/contrib/dirdiff/git-dirdiff--helper.sh b/contrib/dirdiff/git-dirdiff--helper.sh\nnew file mode 100755\nindex 0000000..8ff0124\n--- /dev/null\n+++ b/contrib/dirdiff/git-dirdiff--helper.sh\n@@ -0,0 +1,37 @@\n+#!/bin/sh\n+#\n+# Accumulate files in a changeset into a pre-defined directory.\n+#\n+# Copyright (C) 2011 Roland Kaufmann\n+#\n+# Based on a script called git-diffc by Nitin Gupta and valuable\n+# suggestions by Junio C. Hamano.\n+#\n+# This file is licensed under the GPL v2, or a later version\n+# at the discretion of the official Git maintainer.\n+\n+. git-sh-setup\n+\n+# check that we are called by git-dirdiff\n+test -z \"$__GIT_DIFF_DIR\" &&\n+  die Error: Do not call $(basename \"$0\") directly\n+\n+# what is the directory name of the file that has changed\n+RELDIR=$(dirname \"$1\") ||\n+  exit $?\n+\n+# don't attempt to copy new or removed files\n+if test \"$2\" != \"/dev/null\"\n+then\n+  mkdir -p \"$__GIT_DIFF_DIR/old/$RELDIR\" ||\n+    exit $?\n+  cp \"$2\" \"$__GIT_DIFF_DIR/old/$1\" ||\n+    exit $?\n+fi\n+if test \"$5\" != \"/dev/null\"\n+then\n+  mkdir -p \"$__GIT_DIFF_DIR/new/$RELDIR\" ||\n+    exit $?\n+  cp \"$5\" \"$__GIT_DIFF_DIR/new/$1\" ||\n+    exit $?\n+fi\ndiff --git a/contrib/dirdiff/git-dirdiff.sh b/contrib/dirdiff/git-dirdiff.sh\nnew file mode 100755\nindex 0000000..faf2f00\n--- /dev/null\n+++ b/contrib/dirdiff/git-dirdiff.sh\n@@ -0,0 +1,58 @@\n+#!/bin/sh\n+#\n+# Display differences between two commits with a directory comparison.\n+#\n+# Copyright (C) 2011 Roland Kaufmann\n+#\n+# Based on a script called git-diffc by Nitin Gupta and valuable\n+# suggestions by Junio C. Hamano.\n+#\n+# This file is licensed under the GPL v2, or a later version\n+# at the discretion of the official Git maintainer.\n+\n+. git-sh-setup\n+\n+# TMPDIR points to the designated space for temporary files; only if\n+# not set use /tmp (MSYS even mounts %TEMP% to there)\n+test -z \"$TMPDIR\" && TMPDIR=/tmp\n+\n+# create a temporary directory to hold snapshots of changed files\n+# note that SunOS and MSYS do not have mktemp (but GnuWin32 has!)\n+case $(uname -s) in\n+MINGW* | SunOS* | HP-UX* | AIX*)\n+  __GIT_DIFF_DIR=$(perl -e \"use File::Temp qw/tempdir/; print tempdir(\\\"git-dirdiff.XXXXXX\\\", DIR=>\\\"$TMPDIR\\\")\")\n+  ;;\n+*)\n+  __GIT_DIFF_DIR=$(mktemp -d \"$TMPDIR/git-dirdiff.XXXXXX\")\n+  ;;\n+esac\n+test -d \"$__GIT_DIFF_DIR\" -a -w \"$__GIT_DIFF_DIR\" ||\n+  die Error: Could not create a temporary subdir in $TMPDIR\n+\n+# cleanup after we're done\n+trap 'rm -rf $__GIT_DIFF_DIR' 0\n+\n+# export this variable so that scripts called indirectly can access it\n+export __GIT_DIFF_DIR\n+\n+# let the helper script accumulate all changed files into the temporary\n+# directory letting 'git diff' do all the heavy lifting\n+GIT_EXTERNAL_DIFF=git-dirdiff--helper git --no-pager diff \"$@\" ||\n+  exit $?\n+\n+# if there are only hidden files, then the first argument will be the\n+# wildcard, and $2 and $3 will be the special directory files . and ..\n+isempty () {\n+  set - $1/* $1/.*\n+  test ! \\( -f \"$1\" -o -f \"$4\" \\)\n+}\n+\n+# no-op if no files were changed\n+isempty \"$__GIT_DIFF_DIR/old\" && isempty \"$__GIT_DIFF_DIR/new\" &&\n+  exit 0\n+\n+# run original diff program, reckoning it will understand directories\n+# modes and shas does not apply to the root directories so submit dummy\n+# values for those, hoping that the diff tool does not use them.\n+git-difftool--helper - \"$__GIT_DIFF_DIR/old\" deadbeef 0755 \"$__GIT_DIFF_DIR/new\" babeface 0755 ||\n+  exit $?\ndiff --git a/contrib/dirdiff/git-dirdiff.txt b/contrib/dirdiff/git-dirdiff.txt\nnew file mode 100644\nindex 0000000..bdd2581\n--- /dev/null\n+++ b/contrib/dirdiff/git-dirdiff.txt\n@@ -0,0 +1,55 @@\n+git-dirdiff(1)\n+==============\n+\n+NAME\n+----\n+git-dirdiff - Show changes using directory compare\n+\n+SYNOPSIS\n+--------\n+[verse]\n+'git dirdiff' [<options>] [<commit> [<commit>]] [--] [<path>...]\n+\n+DESCRIPTION\n+-----------\n+'git dirdiff' is a git command that allows you to compare revisions\n+as a difference between two directories. 'git dirdiff' is a frontend\n+to linkgit:git-diff[1].\n+\n+OPTIONS\n+-------\n+See linkgit:git-diff[1] for the list of supported options.\n+\n+CONFIG VARIABLES\n+----------------\n+'git dirdiff' uses the same config variables as linkgit:git-difftool[1]\n+to determine which difftool should be used.\n+\n+TEMPORARY FILES\n+---------------\n+'git dirdiff' creates a directory with 'mktemp' to hold snapshots of the\n+files which are different in the two revisions. This directory is removed\n+when the diff viewer terminates.\n+\n+NOTES\n+-----\n+The diff viewer must support being passed directories instead of files\n+as its arguments.\n++\n+Files that are not put under version control are not included when\n+viewing the difference between a revision and the working directory.\n+\n+SEE ALSO\n+--------\n+linkgit:git-diff[1]::\n+\t Show changes between commits, commit and working tree, etc\n+\n+linkgit:git-difftool[1]::\n+\tShow changes using common diff tools\n+\n+linkgit:git-config[1]::\n+\t Get and set repository or global options\n+\n+GIT\n+---\n+Part of the linkgit:git[1] suite\n-- \n1.7.1\n"}]}