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'
This commit is contained in:
Junio C Hamano 2012-03-15 21:54:42 -07:00
commit a99c5e5921

View File

@ -36,21 +36,20 @@ fi
start_dir=$(pwd) 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) && cdup=$(git rev-parse --show-cdup) &&
cd "$cdup" || { cd "$cdup" || {
echo >&2 "Cannot chdir to $cdup, the toplevel of the working tree" echo >&2 "Cannot chdir to $cdup, the toplevel of the working tree"
exit 1 exit 1
} }
# mktemp is not available on all platforms (missing from msysgit) # set up temp dir
# Use a hard-coded tmp dir if it is not available tmp=$(perl -e 'use File::Temp qw(tempdir);
tmp="$(mktemp -d -t tmp.XXXXXX 2>/dev/null)" || { $t=tempdir("/tmp/git-diffall.XXXXX") or exit(1);
tmp=/tmp/git-diffall-tmp.$$ print $t') || exit 1
mkdir "$tmp" || exit 1 trap 'rm -rf "$tmp"' EXIT
}
trap 'rm -rf "$tmp" 2>/dev/null' EXIT
left= left=
right= right=
@ -180,34 +179,32 @@ fi
mkdir -p "$tmp/$left_dir" "$tmp/$right_dir" mkdir -p "$tmp/$left_dir" "$tmp/$right_dir"
# Populate the tmp/right_dir directory with the files to be compared # Populate the tmp/right_dir directory with the files to be compared
if test -n "$right" while read name
then do
while read name if test -n "$right"
do then
ls_list=$(git ls-tree $right "$name") ls_list=$(git ls-tree $right "$name")
if test -n "$ls_list" if test -n "$ls_list"
then then
mkdir -p "$tmp/$right_dir/$(dirname "$name")" mkdir -p "$tmp/$right_dir/$(dirname "$name")"
git show "$right":"$name" >"$tmp/$right_dir/$name" || true git show "$right":"$name" >"$tmp/$right_dir/$name" || true
fi fi
done < "$tmp/filelist" elif test -n "$compare_staged"
elif test -n "$compare_staged" then
then
while read name
do
ls_list=$(git ls-files -- "$name") ls_list=$(git ls-files -- "$name")
if test -n "$ls_list" if test -n "$ls_list"
then then
mkdir -p "$tmp/$right_dir/$(dirname "$name")" mkdir -p "$tmp/$right_dir/$(dirname "$name")"
git show :"$name" >"$tmp/$right_dir/$name" git show :"$name" >"$tmp/$right_dir/$name"
fi fi
done < "$tmp/filelist" else
else if test -e "$name"
# Mac users have gnutar rather than tar then
(tar --ignore-failed-read -c -T "$tmp/filelist" | (cd "$tmp/$right_dir" && tar -x)) || { mkdir -p "$tmp/$right_dir/$(dirname "$name")"
gnutar --ignore-failed-read -c -T "$tmp/filelist" | (cd "$tmp/$right_dir" && gnutar -x) cp "$name" "$tmp/$right_dir/$name"
} fi
fi fi
done < "$tmp/filelist"
# Populate the tmp/left_dir directory with the files to be compared # Populate the tmp/left_dir directory with the files to be compared
while read name while read name
@ -236,9 +233,8 @@ do
fi fi
done < "$tmp/filelist" done < "$tmp/filelist"
cd "$tmp" LOCAL="$tmp/$left_dir"
LOCAL="$left_dir" REMOTE="$tmp/$right_dir"
REMOTE="$right_dir"
if test -n "$diff_tool" if test -n "$diff_tool"
then then