Skip to content

Commit

Permalink
Merge branch 'th/git-diffall'
Browse files Browse the repository at this point in the history
* 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'
  • Loading branch information
Junio C Hamano committed Mar 16, 2012
2 parents c58499c + bfe392e commit a99c5e5
Showing 1 changed file with 24 additions and 28 deletions.
52 changes: 24 additions & 28 deletions contrib/diffall/git-diffall
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a99c5e5

Please sign in to comment.