@matheusbsbs / matheus-bagliano / commits / ffa84ffb77
Fork 0

Allow arbitrary number of arguments to git-pack-objects

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> Signed-off-by: Junio C Hamano <junkio@cox.net>

Roland Dreier committed Feb 25, 2007 at 09:34 UTC ffa84ffb77b06f9793967fb4f4dd5c946da8e341
1 file changed +9 -3
builtin-pack-objects.c
+9 -3
@@ -1551,9 +1551,12 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
1551 int use_internal_rev_list = 0;
1552 int thin = 0;
1553 int i;
1554 - const char *rp_av[64];
1554 + const char **rp_av;
1555 + int rp_ac_alloc = 64;
1556 int rp_ac;
1557
1558 + rp_av = xcalloc(rp_ac_alloc, sizeof(*rp_av));
1559 +
1560 rp_av[0] = "pack-objects";
1561 rp_av[1] = "--objects"; /* --thin will make it --objects-edge */
1562 rp_ac = 2;
@@ -1626,8 +1629,11 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
1629 !strcmp("--reflog", arg) ||
1630 !strcmp("--all", arg)) {
1631 use_internal_rev_list = 1;
1629 - if (ARRAY_SIZE(rp_av) - 1 <= rp_ac)
1630 - die("too many internal rev-list options");
1632 + if (rp_ac >= rp_ac_alloc - 1) {
1633 + rp_ac_alloc = alloc_nr(rp_ac_alloc);
1634 + rp_av = xrealloc(rp_av,
1635 + rp_ac_alloc * sizeof(*rp_av));
1636 + }
1637 rp_av[rp_ac++] = arg;
1638 continue;
1639 }