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>
Martin Langhoff committed
Sep 4, 2006 at 17:42 UTC
0ea2582d1cbbacd91eb0f040c4994ecd2bb6cdb9
1 file changed
+7
-4
git-repack.sh
+7
-4
@@ -24,8 +24,10 @@ do
24
shift
25
done
26
27
-rm -f .tmp-pack-*
27
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
31
32
# There will be more repacking strategies to come...
33
case ",$all_into_one," in
@@ -42,11 +44,12 @@ case ",$all_into_one," in
44
find . -type f \( -name '*.pack' -o -name '*.idx' \) -print`
45
;;
46
esac
47
+
48
pack_objects="$pack_objects $local $quiet $no_reuse_delta$extra"
49
name=$( { git-rev-list --objects --all $rev_list ||
50
echo "git-rev-list died with exit code $?"
51
} |
49
- git-pack-objects --non-empty $pack_objects .tmp-pack) ||
52
+ git-pack-objects --non-empty $pack_objects "$PACKTMP") ||
53
exit 1
54
if [ -z "$name" ]; then
55
echo Nothing new to pack.
@@ -64,8 +67,8 @@ else
67
"$PACKDIR/old-pack-$name.$sfx"
68
fi
69
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" &&
72
test -f "$PACKDIR/pack-$name.pack" &&
73
test -f "$PACKDIR/pack-$name.idx" || {
74
echo >&2 "Couldn't replace the existing pack with updated one."