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

git-gc --auto: protect ourselves from accumulated cruft

Deciding to run "repack -d -l" when there are too many loose objects would backfire when there are too many loose objects that are unreachable, because repacking that way would never improve the situation. Detect that case by checking the number of loose objects again after automatic garbage collection runs, and issue an warning to run "prune" manually. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Sep 17, 2007 at 00:44 UTC a087cc9819d5790a0aeb42c2bd74f781c555e8d6
1 file changed +17 -8
builtin-gc.c
+17 -8
@@ -64,7 +64,7 @@ static void append_option(const char **cmd, const char *opt, int max_length)
64 cmd[i] = NULL;
65 }
66
67 -static int need_to_gc(void)
67 +static int too_many_loose_objects(void)
68 {
69 /*
70 * Quickly check if a "gc" is needed, by estimating how
@@ -80,13 +80,6 @@ static int need_to_gc(void)
80 int num_loose = 0;
81 int needed = 0;
82
83 - /*
84 - * Setting gc.auto to 0 or negative can disable the
85 - * automatic gc
86 - */
87 - if (gc_auto_threshold <= 0)
88 - return 0;
89 -
83 if (sizeof(path) <= snprintf(path, sizeof(path), "%s/17", objdir)) {
84 warning("insanely long object directory %.*s", 50, objdir);
85 return 0;
@@ -109,6 +102,18 @@ static int need_to_gc(void)
102 return needed;
103 }
104
105 +static int need_to_gc(void)
106 +{
107 + /*
108 + * Setting gc.auto to 0 or negative can disable the
109 + * automatic gc
110 + */
111 + if (gc_auto_threshold <= 0)
112 + return 0;
113 +
114 + return too_many_loose_objects();
115 +}
116 +
117 int cmd_gc(int argc, const char **argv, const char *prefix)
118 {
119 int i;
@@ -170,5 +175,9 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
175 if (run_command_v_opt(argv_rerere, RUN_GIT_CMD))
176 return error(FAILED_RUN, argv_rerere[0]);
177
178 + if (auto_gc && too_many_loose_objects())
179 + warning("There are too many unreachable loose objects; "
180 + "run 'git prune' to remove them.");
181 +
182 return 0;
183 }