{"thread":{"id":"6948","subject":"[PATCH] Allow arbitrary number of arguments to git-pack-objects","startedAt":"2007-02-25T17:34:27Z","lastAt":"2007-02-25T17:34:27Z","messageCount":1,"participants":["Roland Dreier"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"35439","messageId":"871wkep2e4.fsf@digitalvampire.org","threadId":"6948","inReplyTo":null,"subject":"[PATCH] Allow arbitrary number of arguments to git-pack-objects","fromName":"Roland Dreier","fromEmail":"roland@digitalvampire.org","sentAt":"2007-02-25T17:34:27Z","receivedAt":"2007-02-25T17:34:27Z","isPatch":true,"sender":{"key":"roland@digitalvampire.org","avatar":null},"body":"If a repository ever gets in a situation where there are too many\npacks (more than 60 or so), perhaps because of frequent use of\ngit-fetch -k or incremental git-repack, then it becomes impossible to\nfully repack the repository with git-repack -a.  That command just\ndies with the cryptic message\n\n    fatal: too many internal rev-list options\n\nThis message comes from git-pack-objects, which is passed one command\nline option like --unpacked=pack-<SHA1>.pack for each pack file to be\nrepacked.  However, the current code has a static limit of 64 command\nline arguments and just aborts if more arguments are passed to it.\n\nFix this by dynamically allocating the array of command line\narguments, and doubling the size each time it overflows.\n\nSigned-off-by: Roland Dreier <roland@digitalvampire.org>\n---\ndiff --git a/builtin-pack-objects.c b/builtin-pack-objects.c\nindex b5ed9ce..c4bbe43 100644\n--- a/builtin-pack-objects.c\n+++ b/builtin-pack-objects.c\n@@ -1551,9 +1551,12 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)\n \tint use_internal_rev_list = 0;\n \tint thin = 0;\n \tint i;\n-\tconst char *rp_av[64];\n+\tconst char **rp_av;\n+\tint rp_ac_max = 64;\n \tint rp_ac;\n \n+\trp_av = xcalloc(rp_ac_max, sizeof *rp_av);\n+\n \trp_av[0] = \"pack-objects\";\n \trp_av[1] = \"--objects\"; /* --thin will make it --objects-edge */\n \trp_ac = 2;\n@@ -1626,8 +1629,10 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)\n \t\t    !strcmp(\"--reflog\", arg) ||\n \t\t    !strcmp(\"--all\", arg)) {\n \t\t\tuse_internal_rev_list = 1;\n-\t\t\tif (ARRAY_SIZE(rp_av) - 1 <= rp_ac)\n-\t\t\t\tdie(\"too many internal rev-list options\");\n+\t\t\tif (rp_ac_max - 1 <= rp_ac) {\n+\t\t\t\trp_ac_max *= 2;\n+\t\t\t\trp_av = xrealloc(rp_av, rp_ac_max * sizeof *rp_av);\n+\t\t\t}\n \t\t\trp_av[rp_ac++] = arg;\n \t\t\tcontinue;\n \t\t}\n"}]}