contrib: added git-diffall
PATCH v3 1/1 contrib: added git-diffall
The 'git difftool' command allows the user to view diffs using an external tool. It runs a separate instance of the tool for each file in the diff. This makes it tedious to review changes spanning multiple files.
The 'git-diffall' script instead prepares temporary directories with the files to be compared and launches a single instance of the external diff tool to view them (i.e. a directory diff).
The 'diff.tool' or 'merge.tool' configuration variable is used to specify which external tool is used.
---
This script has been hosted on GitHub [1] since April 2010. Enough people have found it useful that I hope it will be considered for inclusion in the standard git install, either in contrib or as a new core command.
Changes in v3:
- Fixed a bug that caused failures if file names included spaces
- Added unique suffix to tmp dir name (tmp/git-diffall-tmp.$$)
- Renamed "common_ancestor" to "merge_base"
- Cleaned up README to be more accurate
- Added useful error message if --extcmd is final option, but no command was specified
- Removed spaces after redirection operators
v3 matches commit f36e4881e5 on GitHub [1].
Changes in v2:
- Changed to #!/bin/sh
- Eliminated use of 'which' statements
- Fixed trap function to actually run on abnormal exit
- Simplified path concatenation logic ($IFS)
- Corrected indentation errors
- Improved readability of while loop
- Cleaned up quoting of variables
v2 matches commit 5d4b90de3 on GitHub [1].
[1]: https://github.com/thenigan/git-diffall
contrib/diffall/README | 24 ++++ contrib/diffall/git-diffall | 261 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 285 insertions(+) create mode 100644 contrib/diffall/README create mode 100755 contrib/diffall/git-diffall
contrib/diffall/README new file +24 -0
@@ -0,0 +1,24 @@ +The git-diffall script provides a directory based diff mechanism +for git. The script relies on the diff.tool configuration option +to determine what diff viewer is used. + +This script is compatible with most common forms used to specify a +range of revisions to diff: + + 1. git diffall: shows diff between working tree and staged changes + 2. git diffall --cached [<commit>]: shows diff between staged + changes and HEAD (or other named commit) + 3. git diffall <commit>: shows diff between working tree and named + commit + 4. git diffall <commit> <commit>: show diff between two named commit + 5. git diffall <commit>..<commit>: same as above + 6. git diffall <commit>...<commit>: show the changes on the branch + containing and up to the second , starting at a common ancestor + of both <commit> + +Note: all forms take an optional path limiter [--] [<path>*] + +This script is based on an example provided by Thomas Rast on the +Git list [1]: + +[1] http://thread.gmane.org/gmane.comp.version-control.git/124807
contrib/diffall/git-diffall new file +261 -0
261 lines not on this page · raw message
Signature · 1 line
1.7.9.GIT
Quoted 11 lines · Tim Henigan
The 'git difftool' command allows the user to view diffs using an external tool. It runs a separate instance of the tool for each file in the diff. This makes it tedious to review changes spanning multiple files.
The 'git-diffall' script instead prepares temporary directories with the files to be compared and launches a single instance of the external diff tool to view them (i.e. a directory diff).
The 'diff.tool' or 'merge.tool' configuration variable is used to specify which external tool is used.
Shouldn't the primary interface "--extcmd=" also be advertised here?
contrib/diffall/README line 3
Quoted 9 lines
contrib/diffall/README new file +3
-0@@ -0,0 +1,24 @@ +The git-diffall script provides a directory based diff mechanism +for git. The script relies on the diff.tool configuration option +to determine what diff viewer is used.
Same here.
contrib/diffall/README line 13
Quoted 9 lines
contrib/diffall/README new file +9
-0+This script is compatible with most common forms used to specify a +range of revisions to diff: + + 1. git diffall: shows diff between working tree and staged changes + 2. git diffall --cached [<commit>]: shows diff between staged + changes and HEAD (or other named commit) + 3. git diffall <commit>: shows diff between working tree and named + commit + 4. git diffall <commit> <commit>: show diff between two named commit
I seem to recall the previous round said "named commits" here...
contrib/diffall/README line 19
Quoted 6 lines
contrib/diffall/README new file +6
-0+ 5. git diffall <commit>..<commit>: same as above + 6. git diffall <commit>...<commit>: show the changes on the branch + containing and up to the second , starting at a common ancestor + of both <commit> + +Note: all forms take an optional path limiter [--] [<path>*]
Doesn't 3. above make "--" mandatory if you give a pathspec? I.e.
... take an optional pathspec [-- <pathspec>]*
contrib/diffall/git-diffall line 49
Quoted 11 lines
contrib/diffall/git-diffall new file +4
-0@@ -0,0 +1,261 @@ +# mktemp is not available on all platforms (missing from msysgit) +# Use a hard-coded tmp dir if it is not available +tmp="$(mktemp -d -t tmp.XXXXXX 2>/dev/null)" || { + tmp=/git-diffall-tmp.$$
Missing /tmp in front?
Quoted 7 lines
contrib/diffall/git-diffall new file +7
-0+ mkdir "$tmp" || exit 1 +} + ... +while test $# != 0 +do + case "$1" in + -h|--h|--he|--hel|--help)
contrib/diffall/git-diffall line 79
Quoted 10 lines
contrib/diffall/git-diffall new file +10
-0+ usage + ;; + --cached) + compare_staged=1 + ;; + --copy-back) + copy_back=1 + ;; + -x|--e|--ex|--ext|--extc|--extcm|--extcmd) + if test -z $2
testing $# would be more logical, no?
contrib/diffall/git-diffall line 89
Quoted 10 lines
contrib/diffall/git-diffall new file +10
-0+ then + echo You must specify the tool for use with --extcmd + usage + else + diff_tool=$2 + shift + fi + ;; + --) + path_sep=1
The name path_sep makes one wonder "are we somehow talking about differences between '/' vs '\' here?" In other parts of the system, this is typically called "dashdash_seen"; the meaning of it is "expect nothing but pathspecs from here on", so "expect_pathspec" could be an alternative name for it.
contrib/diffall/git-diffall line 198
Quoted 6 lines
...
contrib/diffall/git-diffall new file +5
-0+elif test -n "$compare_staged" +then + while read name + do + ls_list=$(git ls-files -- "$name")
Ok, the use of $name is now slightly tightened with the surrounding dq throughout the script. Better (even though $paths are still prone to splitting by $IFS).
Thanks, will replace what was queued in 'pu'.