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

Fix archive-destroying "git repack -a -d" bug

From
Linus Torvalds <torvalds@osdl.org>
Date
Sep 18, 2005, 01:46 UTC
Message-ID
<Pine.LNX.4.58.0509171839590.26803@g5.osdl.org>

Using "git repack -a -d" can destroy your git archive if you use it twice in succession.

Why? Because the new pack will be called the same as the old pack. And we delete the old packs _after_ we've moved the new pack to the .git/objects/ directory, which means that we'll delete the new pack too!

This is a totally untested patch that may or may not fix this.
Signed-off-by: Linus "testing is for suckers" Torvalds <torvalds@osdl.org>
---
diff --git a/git-repack.sh b/git-repack.sh
--- a/git-repack.sh
+++ b/git-repack.sh
@@ -31,10 +31,6 @@ case ",$all_into_one," in
 	rev_list=
 	rev_parse='--all'
 	pack_objects=
-	# This part is a stop-gap until we have proper pack redundancy
-	# checker.
-	existing=`cd "$PACKDIR" && \
-	    find . -type f \( -name '*.pack' -o -name '*.idx' \) -print`
 	;;
 esac
 name=$(git-rev-list --objects $rev_list $(git-rev-parse $rev_parse) |
@@ -54,8 +50,13 @@ exit
 
 if test "$remove_redandant" = t
 then
+	# This part is a stop-gap until we have proper pack redundancy
+	# checker.
 	# We know $existing are all redandant only when
 	# all-into-one is used.
+	existing=`cd "$PACKDIR" && \
+	    find . -type f \( -name '*.pack' -o -name '*.idx' \) -print |
+	    grep -v $name`
 	if test "$all_into_one" != '' && test "$existing" != ''
 	then
 		( cd "$PACKDIR" && rm -f $existing )
Next: Dave Jones
Message 1 of 4 in “Fix archive-destroying "git repack -a -d" bug”
  1. Linus TorvaldsSep 18, 2005
  2. Dave JonesSep 18, 2005
  3. Linus TorvaldsSep 18, 2005
  4. Junio C HamanoSep 18, 2005

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.