git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] git-repack: create new packs inside $PACKDIR, not cwd

From
MLMartin Langhoff <martin@catalyst.net.nz>
Date
Sep 4, 2006, 05:42 UTC
Message-ID
<11573485523752-git-send-email-martin@catalyst.net.nz>

Avoid failing when cwd is !writable by writing the packfiles directly in the $PACKDIR.

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>
---
 git-repack.sh |    9 +++++----
 1 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/git-repack.sh b/git-repack.sh
index 584a732..ccc8e43 100755
--- a/git-repack.sh
+++ b/git-repack.sh
@@ -42,11 +42,13 @@ case ",$all_into_one," in
 	    find . -type f \( -name '*.pack' -o -name '*.idx' \) -print`
 	;;
 esac
+
+mkdir -p "$PACKDIR" || exit
 pack_objects="$pack_objects $local $quiet $no_reuse_delta$extra"
 name=$( { git-rev-list --objects --all $rev_list ||
 	  echo "git-rev-list died with exit code $?"
 	} |
-	git-pack-objects --non-empty $pack_objects .tmp-pack) ||
+	git-pack-objects --non-empty $pack_objects "$PACKDIR/.tmp-pack") ||
 	exit 1
 if [ -z "$name" ]; then
 	echo Nothing new to pack.
@@ -54,7 +56,6 @@ else
 	if test "$quiet" != '-q'; then
 	    echo "Pack pack-$name created."
 	fi
-	mkdir -p "$PACKDIR" || exit
 
 	for sfx in pack idx
 	do
@@ -64,8 +65,8 @@ else
 				"$PACKDIR/old-pack-$name.$sfx"
 		fi
 	done &&
-	mv -f .tmp-pack-$name.pack "$PACKDIR/pack-$name.pack" &&
-	mv -f .tmp-pack-$name.idx  "$PACKDIR/pack-$name.idx" &&
+	mv -f "$PACKDIR/.tmp-pack-$name.pack" "$PACKDIR/pack-$name.pack" &&
+	mv -f "$PACKDIR/.tmp-pack-$name.idx"  "$PACKDIR/pack-$name.idx" &&
 	test -f "$PACKDIR/pack-$name.pack" &&
 	test -f "$PACKDIR/pack-$name.idx" || {
 		echo >&2 "Couldn't replace the existing pack with updated one."
-- 
1.4.2.gdfe7


-- 
VGER BF report: S 1
Next: Martin Waitz
Message 1 of 8 in “git-repack: create new packs inside $PACKDIR, not cwd”
  1. git-repack: create new packs inside $PACKDIR, not cwdMartin Langhoff, Sep 4, 2006
  2. Martin WaitzSep 4, 2006
  3. Junio C HamanoSep 4, 2006
  4. Junio C HamanoSep 4, 2006
  5. Martin Langhoff (CatalystIT)Sep 4, 2006
  6. Junio C HamanoSep 4, 2006
  7. Martin Langhoff (CatalystIT)Sep 4, 2006
  8. Junio C HamanoSep 4, 2006

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.