diff options
author | Junio C Hamano <gitster@pobox.com> | 2007-09-17 00:44:17 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2007-09-17 23:12:15 -0700 |
commit | a087cc9819d5790a0aeb42c2bd74f781c555e8d6 (patch) | |
tree | 8987c5276acacad2520e12db970e4a1158ae3adf /builtin-gc.c | |
parent | e9831e83e063844b90cf9e525d0003715dd8b395 (diff) | |
download | git-a087cc9819d5790a0aeb42c2bd74f781c555e8d6.tar.gz |
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>
Diffstat (limited to 'builtin-gc.c')
-rw-r--r-- | builtin-gc.c | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/builtin-gc.c b/builtin-gc.c index f046a2a665..bf29f5e1a2 100644 --- a/builtin-gc.c +++ b/builtin-gc.c @@ -64,7 +64,7 @@ static void append_option(const char **cmd, const char *opt, int max_length) cmd[i] = NULL; } -static int need_to_gc(void) +static int too_many_loose_objects(void) { /* * Quickly check if a "gc" is needed, by estimating how @@ -80,13 +80,6 @@ static int need_to_gc(void) int num_loose = 0; int needed = 0; - /* - * Setting gc.auto to 0 or negative can disable the - * automatic gc - */ - if (gc_auto_threshold <= 0) - return 0; - if (sizeof(path) <= snprintf(path, sizeof(path), "%s/17", objdir)) { warning("insanely long object directory %.*s", 50, objdir); return 0; @@ -109,6 +102,18 @@ static int need_to_gc(void) return needed; } +static int need_to_gc(void) +{ + /* + * Setting gc.auto to 0 or negative can disable the + * automatic gc + */ + if (gc_auto_threshold <= 0) + return 0; + + return too_many_loose_objects(); +} + int cmd_gc(int argc, const char **argv, const char *prefix) { int i; @@ -170,5 +175,9 @@ int cmd_gc(int argc, const char **argv, const char *prefix) if (run_command_v_opt(argv_rerere, RUN_GIT_CMD)) return error(FAILED_RUN, argv_rerere[0]); + if (auto_gc && too_many_loose_objects()) + warning("There are too many unreachable loose objects; " + "run 'git prune' to remove them."); + return 0; } |