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

[PATCH 2/2] Allow fetch-pack to decide keeping the fetched pack without exploding

From
Junio C Hamano <junkio@cox.net>
Date
Jan 23, 2007, 06:47 UTC
Message-ID
<7vzm8ansrt.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<Pine.LNX.4.63.0701212234520.22628@wbgn013.biozentrum.uni-wuerzburg.de>

With --keep-auto option, fetch-pack decides to keep the pack without exploding it just like receive-pack does.

We may want to later make this the default.
Signed-off-by: Junio C Hamano <junkio@cox.net>
---
 And this is the second half.  It looks larger than it really
 is, because it involves some code movements; it removes two
 separate functions that called get_pack() and moves what they
 did to get_pack() after setup_sideband() happens.
 Although I did test it with --keep-auto with large and small
 packs once each. I haven't tested this at all with the
 git-fetch script.
 fetch-pack.c |   91 +++++++++++++++++++++++++++++++++++++--------------------
 1 files changed, 59 insertions(+), 32 deletions(-)
diff --git a/fetch-pack.c b/fetch-pack.c
index 726140a..4ee041c 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -4,9 +4,11 @@
 #include "commit.h"
 #include "tag.h"
 #include "exec_cmd.h"
+#include "pack.h"
 #include "sideband.h"
 
 static int keep_pack;
+static int keep_auto;
 static int quiet;
 static int verbose;
 static int fetch_all;
@@ -486,13 +488,58 @@ static pid_t setup_sideband(int fd[2], int xd[2])
 	return side_pid;
 }
 
-static int get_pack(int xd[2], const char **argv)
+static int get_pack(int xd[2])
 {
 	int status;
 	pid_t pid, side_pid;
 	int fd[2];
+	const char *argv[20];
+	char keep_arg[256];
+	char hdr_arg[256];
+	const char **av;
+	int do_keep = keep_pack;
 
 	side_pid = setup_sideband(fd, xd);
+
+	av = argv;
+	*hdr_arg = 0;
+	if (keep_auto) {
+		struct pack_header header;
+
+		if (read_pack_header(fd[0], &header))
+			die("protocol error: bad pack header");
+		snprintf(hdr_arg, sizeof(hdr_arg), "--pack_header=%u,%u",
+			 ntohl(header.hdr_version), ntohl(header.hdr_entries));
+		if (ntohl(header.hdr_entries) < keep_auto)
+			do_keep = 0;
+		else
+			do_keep = 1;
+	}
+
+	if (do_keep) {
+		*av++ = "index-pack";
+		*av++ = "--stdin";
+		if (!quiet)
+			*av++ = "-v";
+		if (use_thin_pack)
+			*av++ = "--fix-thin";
+		if (keep_pack > 1 || keep_auto) {
+			int s = sprintf(keep_arg,
+					"--keep=fetch-pack %d on ", getpid());
+			if (gethostname(keep_arg + s, sizeof(keep_arg) - s))
+				strcpy(keep_arg + s, "localhost");
+			*av++ = keep_arg;
+		}
+	}
+	else {
+		*av++ = "unpack-objects";
+		if (quiet)
+			*av++ = "-q";
+	}
+	if (*hdr_arg)
+		*av++ = hdr_arg;
+	*av++ = NULL;
+
 	pid = fork();
 	if (pid < 0)
 		die("fetch-pack: unable to fork off %s", argv[0]);
@@ -522,39 +569,10 @@ static int get_pack(int xd[2], const char **argv)
 	die("%s died of unnatural causes %d", argv[0], status);
 }
 
-static int explode_rx_pack(int xd[2])
-{
-	const char *argv[3] = { "unpack-objects", quiet ? "-q" : NULL, NULL };
-	return get_pack(xd, argv);
-}
-
-static int keep_rx_pack(int xd[2])
-{
-	const char *argv[6];
-	char keep_arg[256];
-	int n = 0;
-
-	argv[n++] = "index-pack";
-	argv[n++] = "--stdin";
-	if (!quiet)
-		argv[n++] = "-v";
-	if (use_thin_pack)
-		argv[n++] = "--fix-thin";
-	if (keep_pack > 1) {
-		int s = sprintf(keep_arg, "--keep=fetch-pack %i on ", getpid());
-		if (gethostname(keep_arg + s, sizeof(keep_arg) - s))
-			strcpy(keep_arg + s, "localhost");
-		argv[n++] = keep_arg;
-	}
-	argv[n] = NULL;
-	return get_pack(xd, argv);
-}
-
 static int fetch_pack(int fd[2], int nr_match, char **match)
 {
 	struct ref *ref;
 	unsigned char sha1[20];
-	int status;
 
 	get_remote_heads(fd[0], &ref, 0, NULL, 0);
 	if (is_repository_shallow() && !server_supports("shallow"))
@@ -589,8 +607,7 @@ static int fetch_pack(int fd[2], int nr_match, char **match)
 			 */
 			fprintf(stderr, "warning: no common commits\n");
 
-	status = (keep_pack) ? keep_rx_pack(fd) : explode_rx_pack(fd);
-	if (status)
+	if (get_pack(fd))
 		die("git-fetch-pack: fetch failed.");
 
  all_done:
@@ -655,6 +672,16 @@ int main(int argc, char **argv)
 				keep_pack++;
 				continue;
 			}
+			if (!strcmp("--keep-auto", arg)) {
+				keep_auto = 100;
+				continue;
+			}
+			if (!strncmp("--keep-auto=", arg, 12)) {
+				keep_auto = strtoul(arg + 12, NULL, 0);
+				if (keep_auto < 20)
+					keep_auto = 20;
+				continue;
+			}
 			if (!strcmp("--thin", arg)) {
 				use_thin_pack = 1;
 				continue;
-- 
1.5.0.rc2.gc9a89
Previous: Junio C HamanoNext: Johannes Schindelin
Message 46 of 70 in “[Announce] GIT v1.5.0-rc2”
  1. Junio C HamanoJan 21, 2007
  2. Jakub NarebskiJan 21, 2007
  3. Junio C HamanoJan 21, 2007
  4. Johannes SchindelinJan 21, 2007
  5. Bill LearJan 23, 2007
  6. Johannes SchindelinJan 23, 2007
  7. Bill LearJan 23, 2007
  8. Uwe Kleine-KönigJan 23, 2007
  9. Bill LearJan 23, 2007
  10. Uwe Kleine-KönigJan 24, 2007
  11. Johannes SchindelinJan 23, 2007
  12. Peter BaumannJan 23, 2007
  13. Bill LearJan 23, 2007
  14. Linus TorvaldsJan 23, 2007
  15. Mark NudelmanJan 24, 2007
  16. Linus TorvaldsJan 24, 2007
  17. Linus TorvaldsJan 24, 2007
  18. Junio C HamanoJan 24, 2007
  19. Mark NudelmanMar 27, 2007
  20. Junio C HamanoJan 21, 2007
  21. Bill LearJan 21, 2007
  22. Bill LearJan 21, 2007
  23. MichaelJan 21, 2007
  24. Johannes SchindelinJan 21, 2007
  25. Jakub NarebskiJan 21, 2007
  26. Johannes SchindelinJan 21, 2007
  27. Jakub NarebskiJan 21, 2007
  28. Willy TarreauJan 21, 2007
  29. Jakub NarebskiJan 21, 2007
  30. Junio C HamanoJan 21, 2007
  31. H. Peter AnvinJan 21, 2007
  32. Nicolas PitreJan 22, 2007
  33. Horst H. von BrandJan 21, 2007
  34. Junio C HamanoJan 22, 2007
  35. Horst H. von BrandJan 21, 2007
  36. Junio C HamanoJan 21, 2007
  37. Johannes SchindelinJan 21, 2007
  38. Jakub NarebskiJan 21, 2007
  39. Johannes SchindelinJan 21, 2007
  40. Jakub NarebskiJan 21, 2007
  41. Johannes SchindelinJan 21, 2007
  42. Jakub NarebskiJan 21, 2007
  43. Junio C HamanoJan 22, 2007
  44. Junio C HamanoJan 22, 2007
  45. 1/2 Refactor the pack header reading function out of receive-pack.cJunio C Hamano, Jan 23, 2007
  46. 2/2 Allow fetch-pack to decide keeping the fetched pack without explodingJunio C Hamano, Jan 23, 2007
  47. Johannes SchindelinJan 23, 2007
  48. Jakub NarebskiJan 23, 2007
  49. code movements in diffs, was Re: [PATCH 2/2] Allow fetch-pack to decide keeping the fetched pack without explodingJohannes Schindelin, Jan 23, 2007
  50. Nicolas PitreJan 23, 2007
  51. fetch-pack: remove --keep-auto and make it the default.Junio C Hamano, Jan 25, 2007
  52. Johannes SchindelinJan 25, 2007
  53. Junio C HamanoJan 25, 2007
  54. Johannes SchindelinJan 25, 2007
  55. Junio C HamanoJan 26, 2007
  56. Allow non-developer to clone, checkout and fetch easier.Junio C Hamano, Jan 26, 2007
  57. Alex RiesenJan 26, 2007
  58. Johannes SixtJan 26, 2007
  59. Consolidate {receive,fetch}.unpackLimitJunio C Hamano, Jan 25, 2007
  60. Nicolas PitreJan 25, 2007
  61. Shawn O. PearceJan 25, 2007
  62. Linus TorvaldsJan 23, 2007
  63. David KågedalJan 23, 2007
  64. Johannes SchindelinJan 23, 2007
  65. Jakub NarebskiJan 23, 2007
  66. Carl WorthJan 22, 2007
  67. Junio C HamanoJan 22, 2007
  68. Carl WorthJan 23, 2007
  69. Jakub NarebskiJan 22, 2007
  70. Junio C HamanoJan 22, 2007

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.