git-gc --auto: restructure the way "repack" command line is built.
We used to build the command line to run repack outside of need_to_gc() but with the next patch we would want to tweak the command line depending on the nature of need. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
Sep 17, 2007 at 00:48 UTC
95143f9e686dee144e0ff4a20190b923e20e1b64
1 file changed
+10
-5
builtin-gc.c
+10
-5
@@ -29,8 +29,6 @@ static const char *argv_repack[MAX_ADD] = {"repack", "-a", "-d", "-l", NULL};
29
static const char *argv_prune[] = {"prune", NULL};
30
static const char *argv_rerere[] = {"rerere", "gc", NULL};
31
32
-static const char *argv_repack_auto[] = {"repack", "-d", "-l", NULL};
33
-
32
static int gc_config(const char *var, const char *value)
33
{
34
if (!strcmp(var, "gc.packrefs")) {
@@ -104,6 +102,8 @@ static int too_many_loose_objects(void)
102
103
static int need_to_gc(void)
104
{
105
+ int ac = 0;
106
+
107
/*
108
* Setting gc.auto to 0 or negative can disable the
109
* automatic gc
@@ -111,7 +111,14 @@ static int need_to_gc(void)
111
if (gc_auto_threshold <= 0)
112
return 0;
113
114
- return too_many_loose_objects();
114
+ if (!too_many_loose_objects())
115
+ return 0;
116
+
117
+ argv_repack[ac++] = "repack";
118
+ argv_repack[ac++] = "-d";
119
+ argv_repack[ac++] = "-l";
120
+ argv_repack[ac++] = NULL;
121
+ return 1;
122
}
123
124
int cmd_gc(int argc, const char **argv, const char *prefix)
@@ -154,8 +161,6 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
161
* Auto-gc should be least intrusive as possible.
162
*/
163
prune = 0;
157
- for (i = 0; i < ARRAY_SIZE(argv_repack_auto); i++)
158
- argv_repack[i] = argv_repack_auto[i];
164
if (!need_to_gc())
165
return 0;
166
}