summaryrefslogtreecommitdiff
path: root/contrib/diffall/git-diffall
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2012-03-16 04:54:42 (GMT)
committerJunio C Hamano <gitster@pobox.com>2012-03-16 04:54:42 (GMT)
commita99c5e5921fcb4fd003fd3424be4db649393731f (patch)
treeeefb03f2142a3aa1c9604fd00ba341a9615c0423 /contrib/diffall/git-diffall
parentc58499c317ccb04aba4e0c5b3bee78683027f095 (diff)
parentbfe392e3674770e8a0312d4945b0a5f2c9007eab (diff)
downloadgit-a99c5e5921fcb4fd003fd3424be4db649393731f.zip
git-a99c5e5921fcb4fd003fd3424be4db649393731f.tar.gz
git-a99c5e5921fcb4fd003fd3424be4db649393731f.tar.bz2
Merge branch 'th/git-diffall'
* th/git-diffall: contrib/diffall: fix cleanup trap on Windows contrib/diffall: eliminate duplicate while loops contrib/diffall: eliminate use of tar contrib/diffall: create tmp dirs without mktemp contrib/diffall: comment actual reason for 'cdup'
Diffstat (limited to 'contrib/diffall/git-diffall')
-rwxr-xr-xcontrib/diffall/git-diffall52
1 files changed, 24 insertions, 28 deletions
diff --git a/contrib/diffall/git-diffall b/contrib/diffall/git-diffall
index 9bbd27f..84f2b65 100755
--- a/contrib/diffall/git-diffall
+++ b/contrib/diffall/git-diffall
@@ -36,21 +36,20 @@ fi
start_dir=$(pwd)
-# needed to access tar utility
+# All the file paths returned by the diff command are relative to the root
+# of the working copy. So if the script is called from a subdirectory, it
+# must switch to the root of working copy before trying to use those paths.
cdup=$(git rev-parse --show-cdup) &&
cd "$cdup" || {
echo >&2 "Cannot chdir to $cdup, the toplevel of the working tree"
exit 1
}
-# 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=/tmp/git-diffall-tmp.$$
- mkdir "$tmp" || exit 1
-}
-
-trap 'rm -rf "$tmp" 2>/dev/null' EXIT
+# set up temp dir
+tmp=$(perl -e 'use File::Temp qw(tempdir);
+ $t=tempdir("/tmp/git-diffall.XXXXX") or exit(1);
+ print $t') || exit 1
+trap 'rm -rf "$tmp"' EXIT
left=
right=
@@ -180,34 +179,32 @@ fi
mkdir -p "$tmp/$left_dir" "$tmp/$right_dir"
# Populate the tmp/right_dir directory with the files to be compared
-if test -n "$right"
-then
- while read name
- do
+while read name
+do
+ if test -n "$right"
+ then
ls_list=$(git ls-tree $right "$name")
if test -n "$ls_list"
then
mkdir -p "$tmp/$right_dir/$(dirname "$name")"
git show "$right":"$name" >"$tmp/$right_dir/$name" || true
fi
- done < "$tmp/filelist"
-elif test -n "$compare_staged"
-then
- while read name
- do
+ elif test -n "$compare_staged"
+ then
ls_list=$(git ls-files -- "$name")
if test -n "$ls_list"
then
mkdir -p "$tmp/$right_dir/$(dirname "$name")"
git show :"$name" >"$tmp/$right_dir/$name"
fi
- done < "$tmp/filelist"
-else
- # Mac users have gnutar rather than tar
- (tar --ignore-failed-read -c -T "$tmp/filelist" | (cd "$tmp/$right_dir" && tar -x)) || {
- gnutar --ignore-failed-read -c -T "$tmp/filelist" | (cd "$tmp/$right_dir" && gnutar -x)
- }
-fi
+ else
+ if test -e "$name"
+ then
+ mkdir -p "$tmp/$right_dir/$(dirname "$name")"
+ cp "$name" "$tmp/$right_dir/$name"
+ fi
+ fi
+done < "$tmp/filelist"
# Populate the tmp/left_dir directory with the files to be compared
while read name
@@ -236,9 +233,8 @@ do
fi
done < "$tmp/filelist"
-cd "$tmp"
-LOCAL="$left_dir"
-REMOTE="$right_dir"
+LOCAL="$tmp/$left_dir"
+REMOTE="$tmp/$right_dir"
if test -n "$diff_tool"
then