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

[PATCH] Allow arbitrary number of arguments to git-pack-objects

From
RDRoland Dreier <roland@digitalvampire.org>
Date
Feb 25, 2007, 17:34 UTC
Message-ID
<871wkep2e4.fsf@digitalvampire.org>

If a repository ever gets in a situation where there are too many packs (more than 60 or so), perhaps because of frequent use of git-fetch -k or incremental git-repack, then it becomes impossible to fully repack the repository with git-repack -a. That command just dies with the cryptic message

    fatal: too many internal rev-list options

This message comes from git-pack-objects, which is passed one command line option like --unpacked=pack-<SHA1>.pack for each pack file to be repacked. However, the current code has a static limit of 64 command line arguments and just aborts if more arguments are passed to it.

Fix this by dynamically allocating the array of command line arguments, and doubling the size each time it overflows.

Signed-off-by: Roland Dreier <roland@digitalvampire.org>
---
diff --git a/builtin-pack-objects.c b/builtin-pack-objects.c
index b5ed9ce..c4bbe43 100644
--- a/builtin-pack-objects.c
+++ b/builtin-pack-objects.c
@@ -1551,9 +1551,12 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
 	int use_internal_rev_list = 0;
 	int thin = 0;
 	int i;
-	const char *rp_av[64];
+	const char **rp_av;
+	int rp_ac_max = 64;
 	int rp_ac;
 
+	rp_av = xcalloc(rp_ac_max, sizeof *rp_av);
+
 	rp_av[0] = "pack-objects";
 	rp_av[1] = "--objects"; /* --thin will make it --objects-edge */
 	rp_ac = 2;
@@ -1626,8 +1629,10 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
 		    !strcmp("--reflog", arg) ||
 		    !strcmp("--all", arg)) {
 			use_internal_rev_list = 1;
-			if (ARRAY_SIZE(rp_av) - 1 <= rp_ac)
-				die("too many internal rev-list options");
+			if (rp_ac_max - 1 <= rp_ac) {
+				rp_ac_max *= 2;
+				rp_av = xrealloc(rp_av, rp_ac_max * sizeof *rp_av);
+			}
 			rp_av[rp_ac++] = arg;
 			continue;
 		}
Message 1 of 1 in “Allow arbitrary number of arguments to git-pack-objects”
  1. Allow arbitrary number of arguments to git-pack-objectsRoland Dreier, Feb 25, 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.