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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sun, 29 Oct 2006, Shawn Pearce wrote:

>  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;
 }
-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]