Skip to content

Commit a99c5e5

Browse files
committed
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'
2 parents c58499c + bfe392e commit a99c5e5

File tree

1 file changed

+24
-28
lines changed

1 file changed

+24
-28
lines changed

contrib/diffall/git-diffall

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -36,21 +36,20 @@ fi
3636

3737
start_dir=$(pwd)
3838

39-
# needed to access tar utility
39+
# All the file paths returned by the diff command are relative to the root
40+
# of the working copy. So if the script is called from a subdirectory, it
41+
# must switch to the root of working copy before trying to use those paths.
4042
cdup=$(git rev-parse --show-cdup) &&
4143
cd "$cdup" || {
4244
echo >&2 "Cannot chdir to $cdup, the toplevel of the working tree"
4345
exit 1
4446
}
4547

46-
# mktemp is not available on all platforms (missing from msysgit)
47-
# Use a hard-coded tmp dir if it is not available
48-
tmp="$(mktemp -d -t tmp.XXXXXX 2>/dev/null)" || {
49-
tmp=/tmp/git-diffall-tmp.$$
50-
mkdir "$tmp" || exit 1
51-
}
52-
53-
trap 'rm -rf "$tmp" 2>/dev/null' EXIT
48+
# set up temp dir
49+
tmp=$(perl -e 'use File::Temp qw(tempdir);
50+
$t=tempdir("/tmp/git-diffall.XXXXX") or exit(1);
51+
print $t') || exit 1
52+
trap 'rm -rf "$tmp"' EXIT
5453

5554
left=
5655
right=
@@ -180,34 +179,32 @@ fi
180179
mkdir -p "$tmp/$left_dir" "$tmp/$right_dir"
181180

182181
# Populate the tmp/right_dir directory with the files to be compared
183-
if test -n "$right"
184-
then
185-
while read name
186-
do
182+
while read name
183+
do
184+
if test -n "$right"
185+
then
187186
ls_list=$(git ls-tree $right "$name")
188187
if test -n "$ls_list"
189188
then
190189
mkdir -p "$tmp/$right_dir/$(dirname "$name")"
191190
git show "$right":"$name" >"$tmp/$right_dir/$name" || true
192191
fi
193-
done < "$tmp/filelist"
194-
elif test -n "$compare_staged"
195-
then
196-
while read name
197-
do
192+
elif test -n "$compare_staged"
193+
then
198194
ls_list=$(git ls-files -- "$name")
199195
if test -n "$ls_list"
200196
then
201197
mkdir -p "$tmp/$right_dir/$(dirname "$name")"
202198
git show :"$name" >"$tmp/$right_dir/$name"
203199
fi
204-
done < "$tmp/filelist"
205-
else
206-
# Mac users have gnutar rather than tar
207-
(tar --ignore-failed-read -c -T "$tmp/filelist" | (cd "$tmp/$right_dir" && tar -x)) || {
208-
gnutar --ignore-failed-read -c -T "$tmp/filelist" | (cd "$tmp/$right_dir" && gnutar -x)
209-
}
210-
fi
200+
else
201+
if test -e "$name"
202+
then
203+
mkdir -p "$tmp/$right_dir/$(dirname "$name")"
204+
cp "$name" "$tmp/$right_dir/$name"
205+
fi
206+
fi
207+
done < "$tmp/filelist"
211208

212209
# Populate the tmp/left_dir directory with the files to be compared
213210
while read name
@@ -236,9 +233,8 @@ do
236233
fi
237234
done < "$tmp/filelist"
238235

239-
cd "$tmp"
240-
LOCAL="$left_dir"
241-
REMOTE="$right_dir"
236+
LOCAL="$tmp/$left_dir"
237+
REMOTE="$tmp/$right_dir"
242238

243239
if test -n "$diff_tool"
244240
then

0 commit comments

Comments
 (0)