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

Re: [PATCH 3/3] Teach git-index-pack how to keep a pack file.

From
Nicolas Pitre <nico@cam.org>
Date
Oct 30, 2006, 03:47 UTC
Message-ID
<Pine.LNX.4.64.0610292232440.11384@xanadu.home>
In-Reply-To
<20061029094159.GE3847@spearce.org>
On Sun, 29 Oct 2006, Shawn Pearce wrote:
Show 6 quoted lines
>  I'm throwing a pair of pipes around index-pack so I can capture
>  the pack name thus allowing receive-pack to delete the correct
>  .keep file after its completed the ref updates.  At that point
>  receive-pack can easily examine the object count in the pack header
>  and compare that against a config entry to decide if it should be
>  keeping the pack or exploding it.

Is it really worth the trouble? Especially if you've already written the pack out, why just not keep it instead of burning more CPU cycles exploding it? The next repack will delete it anyway.

At least for the fetch/pull case here's what I've done so far. It is not complete as the .keep file is not deleted as I'm not clear exactly where in git-fetch.sh it can be safely deleted. But at least it works to the point of displaying the name of the file it should consider for deletion.

diff --git a/fetch-clone.c b/fetch-clone.c
index 96cdab4..c5747f4 100644
--- a/fetch-clone.c
+++ b/fetch-clone.c
@@ -81,7 +81,7 @@ int receive_unpack_pack(int xd[2], const
 
 int receive_keep_pack(int xd[2], const char *me, int quiet, int sideband)
 {
-	const char *argv[5] = { "index-pack", "--stdin", "--fix-thin",
+	const char *argv[6] = { "index-pack", "--stdin", "--fix-thin", "--keep",
 				quiet ? NULL : "-v", NULL };
 	return get_pack(xd, me, sideband, argv);
 }
diff --git a/git-fetch.sh b/git-fetch.sh
index 539dff6..dd0c00b 100755
--- a/git-fetch.sh
+++ b/git-fetch.sh
@@ -378,6 +378,10 @@ fetch_main () {
 	  failed)
 		  echo >&2 "Fetch failure: $remote"
 		  exit 1 ;;
+	  pack)
+		  pack_lockfile="$GIT_OBJECT_DIRECTORY/pack/pack-$remote_name.keep"
+		  [ -e "$pack_lockfile" ] && echo >&2 "$pack_lockfile exists"
+		  continue ;;
 	  esac
 	  found=
 	  single_force=
diff --git a/index-pack.c b/index-pack.c
index b37dd78..8db3c93 100644
--- a/index-pack.c
+++ b/index-pack.c
@@ -767,18 +767,6 @@ static void final(const char *final_pack
 		if (err)
 			die("error while closing pack file: %s", strerror(errno));
 		chmod(curr_pack_name, 0444);
-
-		/*
-		 * Let's just mimic git-unpack-objects here and write
-		 * the last part of the buffer to stdout.
-		 */
-		while (input_len) {
-			err = xwrite(1, input_buffer + input_offset, input_len);
-			if (err <= 0)
-				break;
-			input_len -= err;
-			input_offset += err;
-		}
 	}
 
 	if (keep_msg) {
@@ -818,6 +806,27 @@ static void final(const char *final_pack
 		if (move_temp_to_file(curr_index_name, final_index_name))
 			die("cannot store index file");
 	}
+
+	if (!from_stdin) {
+		printf("%s\n", sha1_to_hex(sha1));
+	} else {
+		char buf[48];
+		int len = snprintf(buf, sizeof(buf), "pack\t%s\n",
+				   sha1_to_hex(sha1));
+		xwrite(1, buf, len);
+
+		/*
+		 * Let's just mimic git-unpack-objects here and write
+		 * the last part of the input buffer to stdout.
+		 */
+		while (input_len) {
+			err = xwrite(1, input_buffer + input_offset, input_len);
+			if (err <= 0)
+				break;
+			input_len -= err;
+			input_offset += err;
+		}
+	}
 }
 
 int main(int argc, char **argv)
@@ -921,8 +930,5 @@ int main(int argc, char **argv)
 	free(index_name_buf);
 	free(keep_name_buf);
 
-	if (!from_stdin)
-		printf("%s\n", sha1_to_hex(sha1));
-
 	return 0;
Previous: Michael S. Tsirkin
Message 5 of 5 in “Teach git-index-pack how to keep a pack file.”
  1. 3/3 Teach git-index-pack how to keep a pack file.Shawn Pearce, Oct 29, 2006
  2. Jakub NarebskiOct 29, 2006
  3. Junio C HamanoOct 29, 2006
  4. Michael S. TsirkinOct 29, 2006
  5. Nicolas PitreOct 30, 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.