* [PATCH v4] Display change history as a diff between two dirs
@ 2012-02-25 21:47 Roland Kaufmann
2012-02-27 0:13 ` Junio C Hamano
0 siblings, 1 reply; 3+ messages in thread
From: Roland Kaufmann @ 2012-02-25 21:47 UTC (permalink / raw)
To: gitster; +Cc: git
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.
Signed-off-by: Roland Kaufmann <rlndkfmn+git@gmail.com>
---
Issue addressed in this revision:
* If changes were made in subdirectories the script though the diff
set between the two trees was empty, because it only checked for
regular files.
contrib/dirdiff/README | 10 ++++
contrib/dirdiff/git-dirdiff--helper.sh | 37 ++++++++++++++++
contrib/dirdiff/git-dirdiff.sh | 72 ++++++++++++++++++++++++++++++++
contrib/dirdiff/git-dirdiff.txt | 71 +++++++++++++++++++++++++++++++
4 files changed, 190 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
diff --git a/contrib/dirdiff/README b/contrib/dirdiff/README
new file mode 100644
index 0000000..d06461a
--- /dev/null
+++ b/contrib/dirdiff/README
@@ -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
diff --git a/contrib/dirdiff/git-dirdiff--helper.sh b/contrib/dirdiff/git-dirdiff--helper.sh
new file mode 100755
index 0000000..a23efee
--- /dev/null
+++ b/contrib/dirdiff/git-dirdiff--helper.sh
@@ -0,0 +1,37 @@
+#!/bin/sh
+#
+# Accumulate files in a changeset into a pre-defined directory.
+#
+# Copyright (C) 2011-2012 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
diff --git a/contrib/dirdiff/git-dirdiff.sh b/contrib/dirdiff/git-dirdiff.sh
new file mode 100755
index 0000000..33c294d
--- /dev/null
+++ b/contrib/dirdiff/git-dirdiff.sh
@@ -0,0 +1,72 @@
+#!/bin/sh
+#
+# Display differences between two commits with a directory comparison.
+#
+# Copyright (C) 2011-2012 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
+
+# TMPDIR points to the designated space for temporary files; only if
+# not set use /tmp (MSYS even mounts %TEMP% to there)
+test -z "$TMPDIR" && TMPDIR=/tmp
+
+# create a temporary directory to hold snapshots of changed files
+# fallback on crippled platforms is to use a Perl module
+case $(uname -s) in
+Linux | *BSD | Darwin | windows* | CYGWIN_NT*)
+ __GIT_DIFF_DIR=$(mktemp -d "$TMPDIR/git-dirdiff.XXXXXX")
+ ;;
+*)
+ __GIT_DIFF_DIR=$(perl -e "use File::Temp qw/tempdir/; print tempdir(\"git-dirdiff.XXXXXX\", DIR=>\"$TMPDIR\")")
+ ;;
+esac
+test -d "$__GIT_DIFF_DIR" -a -w "$__GIT_DIFF_DIR" ||
+ die Error: Could not create a temporary subdir in $TMPDIR
+
+# cleanup after we're done
+trap 'rm -rf $__GIT_DIFF_DIR' 0
+
+# export this variable so that scripts called indirectly can access it
+export __GIT_DIFF_DIR
+
+# let the helper script accumulate all changed files into the temporary
+# directory letting 'git diff' do all the heavy lifting
+GIT_EXTERNAL_DIFF=git-dirdiff--helper git --no-pager diff "$@" ||
+ exit $?
+
+# first and second argument will always be the special directory links
+# if there are no hidden files nor regular files, then $3 will be the
+# second wildcard unexpanded
+isempty () {
+ set - $1/.* $1/*
+ test ! -e "$3"
+}
+
+# no-op if no files were changed
+isempty "$__GIT_DIFF_DIR/old" && isempty "$__GIT_DIFF_DIR/new" &&
+ exit 0
+
+# if a different tool is setup for tree comparison, launch that instead
+# if GIT_EXTERNAL_TREEDIFF is not set, then use GIT_EXTERNAL_DIFF
+if test -n "$GIT_EXTERNAL_DIFF"
+then
+ GIT_DIFFTOOL_EXTCMD=$GIT_EXTERNAL_DIFF
+ export GIT_DIFFTOOL_EXTCMD
+fi
+if test -n "$GIT_EXTERNAL_TREEDIFF"
+then
+ GIT_DIFFTOOL_EXTCMD=$GIT_EXTERNAL_TREEDIFF
+ export GIT_DIFFTOOL_EXTCMD
+fi
+
+# run original diff program, reckoning it will understand directories
+# modes and shas does not apply to the root directories so submit dummy
+# values for those, hoping that the diff tool does not use them.
+git-difftool--helper - "$__GIT_DIFF_DIR/old" deadbeef 0755 "$__GIT_DIFF_DIR/new" babeface 0755 ||
+ exit $?
diff --git a/contrib/dirdiff/git-dirdiff.txt b/contrib/dirdiff/git-dirdiff.txt
new file mode 100644
index 0000000..b80430a
--- /dev/null
+++ b/contrib/dirdiff/git-dirdiff.txt
@@ -0,0 +1,71 @@
+git-dirdiff(1)
+==============
+
+NAME
+----
+git-dirdiff - Show changes using directory compare
+
+SYNOPSIS
+--------
+[verse]
+'git dirdiff' [<options>] [<commit> [<commit>]] [--] [<path>...]
+
+DESCRIPTION
+-----------
+'git dirdiff' is a git command that allows you to compare revisions
+as a difference between two directories. 'git dirdiff' is a frontend
+to linkgit:git-diff[1].
+
+OPTIONS
+-------
+See linkgit:git-diff[1] for the list of supported options.
+
+ENVIRONMENT VARIABLES
+---------------------
+'GIT_EXTERNAL_TREEDIFF'::
+ When 'GIT_EXTERNAL_TREEDIFF' is set, the program named by it is
+ used as a diff viewer. The program must accept 7 parameters, where
+ parameter 2 is the path to a temporary directory containing the
+ "old" revision, and parameter 5 is the path of the "new" revision.
+ The other five parameters will only contain dummy values, and their
+ contents are subject to change.
+
+'GIT_EXTERNAL_DIFF'::
+ If and only if 'GIT_EXTERNAL_TREEDIFF' is not set, 'git dirdiff'
+ will use the contents of 'GIT_EXTERNAL_DIFF' as the name of the
+ diff viewer.
+
+CONFIG VARIABLES
+----------------
+If none of the above environment variables are set, 'git dirdiff' will
+use the same config variables as linkgit:git-difftool[1] to determine
+which difftool should be used.
+
+TEMPORARY FILES
+---------------
+'git dirdiff' creates a directory with 'mktemp' to hold snapshots of the
+files which are different in the two revisions. This directory is removed
+when the diff viewer terminates.
+
+NOTES
+-----
+The diff viewer must support being passed directories instead of files
+as its arguments.
++
+Files that are not put under version control are not included when
+viewing the difference between a revision and the working directory.
+
+SEE ALSO
+--------
+linkgit:git-diff[1]::
+ Show changes between commits, commit and working tree, etc
+
+linkgit:git-difftool[1]::
+ Show changes using common diff tools
+
+linkgit:git-config[1]::
+ Get and set repository or global options
+
+GIT
+---
+Part of the linkgit:git[1] suite
--
1.7.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v4] Display change history as a diff between two dirs
2012-02-25 21:47 [PATCH v4] Display change history as a diff between two dirs Roland Kaufmann
@ 2012-02-27 0:13 ` Junio C Hamano
2012-02-27 11:31 ` Roland Kaufmann
0 siblings, 1 reply; 3+ messages in thread
From: Junio C Hamano @ 2012-02-27 0:13 UTC (permalink / raw)
To: Roland Kaufmann, Tim Henigan; +Cc: git
Roland Kaufmann <rlndkfmn+git@gmail.com> writes:
> 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.
>
> Signed-off-by: Roland Kaufmann <rlndkfmn+git@gmail.com>
> ---
Sorry, but I completely forgot about this three-month old topic (the last
discussion was early November last year).
How does this compare with Tim Henigan's "diffall"? I think the problem
these two topics try to address is the same, and their approach may be
similar enough that having one consolidated effort might be worth it.
I seem to have suggested during the previous review round of this series
the same thing I suggested to Tim, that we _might_ want to instead have
the logic to populate the two temporary trees on the core side with a new
external diff interface.
http://thread.gmane.org/gmane.comp.version-control.git/184458/focus=184462
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v4] Display change history as a diff between two dirs
2012-02-27 0:13 ` Junio C Hamano
@ 2012-02-27 11:31 ` Roland Kaufmann
0 siblings, 0 replies; 3+ messages in thread
From: Roland Kaufmann @ 2012-02-27 11:31 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Tim Henigan, git
On Mon, Feb 27, 2012 at 01:13, Junio C Hamano <gitster@pobox.com> wrote:
> How does this compare with Tim Henigan's "diffall"? I think the problem
> these two topics try to address is the same, and their approach may be
> similar enough that having one consolidated effort might be worth it.
Yes, I certainly agree. From a quick glance it seems to do exactly the
same thing (and both take inspirations from scripts already floating
around on the net); I guess that is a sign that it is an idea whose time
has come! :-)
The major difference is that Tim's version generate the list of files
and then extract them, whereas my current version piggybacks on
the external diff interface (as you suggested in one of the previous
reviews). Which of these approaches -- if any -- has the most merit
I think depends on the plans for that interface.
But until that's decided upon, it would have been nice if a version
could hang out in contrib/ to gather some experience.
--
Roland.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2012-02-27 11:32 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-02-25 21:47 [PATCH v4] Display change history as a diff between two dirs Roland Kaufmann
2012-02-27 0:13 ` Junio C Hamano
2012-02-27 11:31 ` Roland Kaufmann
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).