Skip to content

Commit 0ea2582

Browse files
Martin LanghoffJunio C Hamano
authored andcommitted
git-repack: create new packs inside $GIT_DIR, not cwd
Avoid failing when cwd is !writable by writing the packfiles in $GIT_DIR, which is more in line with other commands. Without this, git-repack was failing when run from crontab by non-root user accounts. For large repositories, this also makes the mv operation a lot cheaper, and avoids leaving temp packfiles around the fs upon failure. Signed-off-by: Martin Langhoff <martin@catalyst.net.nz> Signed-off-by: Junio C Hamano <junkio@cox.net>
1 parent 42cabc3 commit 0ea2582

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

git-repack.sh

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ do
2424
shift
2525
done
2626

27-
rm -f .tmp-pack-*
2827
PACKDIR="$GIT_OBJECT_DIRECTORY/pack"
28+
PACKTMP="$GIT_DIR/.tmp-$$-pack"
29+
rm -f "$PACKTMP"-*
30+
trap 'rm -f "$PACKTMP"-*' 0 1 2 3 15
2931

3032
# There will be more repacking strategies to come...
3133
case ",$all_into_one," in
@@ -42,11 +44,12 @@ case ",$all_into_one," in
4244
find . -type f \( -name '*.pack' -o -name '*.idx' \) -print`
4345
;;
4446
esac
47+
4548
pack_objects="$pack_objects $local $quiet $no_reuse_delta$extra"
4649
name=$( { git-rev-list --objects --all $rev_list ||
4750
echo "git-rev-list died with exit code $?"
4851
} |
49-
git-pack-objects --non-empty $pack_objects .tmp-pack) ||
52+
git-pack-objects --non-empty $pack_objects "$PACKTMP") ||
5053
exit 1
5154
if [ -z "$name" ]; then
5255
echo Nothing new to pack.
@@ -64,8 +67,8 @@ else
6467
"$PACKDIR/old-pack-$name.$sfx"
6568
fi
6669
done &&
67-
mv -f .tmp-pack-$name.pack "$PACKDIR/pack-$name.pack" &&
68-
mv -f .tmp-pack-$name.idx "$PACKDIR/pack-$name.idx" &&
70+
mv -f "$PACKTMP-$name.pack" "$PACKDIR/pack-$name.pack" &&
71+
mv -f "$PACKTMP-$name.idx" "$PACKDIR/pack-$name.idx" &&
6972
test -f "$PACKDIR/pack-$name.pack" &&
7073
test -f "$PACKDIR/pack-$name.idx" || {
7174
echo >&2 "Couldn't replace the existing pack with updated one."

0 commit comments

Comments
 (0)