gc: ignore old gc.log files
PATCH v6 1/1 gc: ignore old gc.log files
A server can end up in a state where there are lots of unreferenced loose objects (say, because many users are doing a bunch of rebasing and pushing their rebased branches). Running "git gc --auto" in this state would cause a gc.log file to be created, preventing future auto gcs, causing pack files to pile up. Since many git operations are O(n) in the number of pack files, this would lead to poor performance.
Git should never get itself into a state where it refuses to do any maintenance, just because at some point some piece of the maintenance didn't make progress.
Teach Git to ignore gc.log files which are older than (by default) one day old, which can be tweaked via the gc.logExpiry configuration variable. That way, these pack files will get cleaned up, if necessary, at least once per day. And operators who find a need for more-frequent gcs can adjust gc.logExpiry to meet their needs.
There is also some cleanup: a successful manual gc, or a warning-free auto gc with an old log file, will remove any old gc.log files.
It might still happen that manual intervention is required (e.g. because the repo is corrupt), but at the very least it won't be because Git is too dumb to try again.
--- Documentation/config.txt | 6 +++++ builtin/gc.c | 57 ++++++++++++++++++++++++++++++++++++++++++------ t/t6500-gc.sh | 15 +++++++++++++ 3 files changed, 71 insertions(+), 7 deletions(-)
Documentation/config.txt +6 -0
@@ -1402,6 +1402,12 @@ gc.autoDetach:: Make `git gc --auto` return immediately and run in background if the system supports it. Default is true. +gc.logExpiry:: + If the file gc.log exists, then `git gc --auto` won't run + unless that file is more than 'gc.logExpiry' old. Default is + "1.day". See `gc.pruneExpire` for more ways to specify its + value. + gc.packRefs:: Running `git pack-refs` in a repository renders it unclonable by Git versions prior to 1.5.1.2 over dumb
builtin/gc.c +50 -7
103 lines not on this page · raw message
t/t6500-gc.sh +15 -0
@@ -67,5 +67,20 @@ test_expect_success 'auto gc with too many loose objects does not attempt to cre test_line_count = 2 new # There is one new pack and its .idx ' +test_expect_success 'background auto gc does not run if gc.log is present and recent but does if it is old' ' + test_commit foo && + test_commit bar && + git repack && + test_config gc.autopacklimit 1 && + test_config gc.autodetach true && + echo fleem >.git/gc.log && + test_must_fail git gc --auto 2>err && + test_i18ngrep "^error:" err && + test_config gc.logexpiry 5.days && + test-chmtime =-345600 .git/gc.log && + test_must_fail git gc --auto && + test_config gc.logexpiry 2.days && + git gc --auto +' test_done
Signature · 1 line
2.11.GIT
builtin/gc.c static int aggressive_window = 250; · line 37
Quoted 2 lines · David Turner
builtin/gc.c +2
-0+static unsigned long gc_log_expire_time; +static const char *gc_log_expire ="1.day.ago" ;
OK.
builtin/gc.c static void gc_config(void) · line 137
Quoted 6 lines
builtin/gc.c +2
-0@@ -113,6 +133,8 @@ static void gc_config(void)git_config_get_bool ("gc.autodetach" , &detach_auto);git_config_date_string ("gc.pruneexpire" , &prune_expire);git_config_date_string ("gc.worktreepruneexpire" , &prune_worktrees_expire); +git_config_date_string ("gc.logexpiry" , &gc_log_expire); +
OK.
I think I had a stale one queued; will replace.
Thanks.