Skip to content

Commit 095c741

Browse files
avargitster
authored andcommitted
commit: run git gc --auto just before the post-commit hook
Change the behavior of git-commit back to what it was back in d4bb43e ("Invoke "git gc --auto" from commit, merge, am and rebase.", 2007-09-05) when it was git-commit.sh. Shortly afterwards in f5bbc32 ("Port git commit to C.", 2007-11-08) when it was ported to C, the "git gc --auto" invocation went away. Since that unintended regression, git gc --auto only ran for git-am, git-merge, git-fetch, and git-receive-pack. It was possible to write a script that would "git commit" a lot of data locally, and gc would never run. One such repository that was locally committing generated zone file changes had grown to a size of ~60GB before a daily cronjob was added to "git gc", bringing it down to less than 1GB. This will make such cases work without intervention. I think fixing such pathological cases where the repository will grow forever is a worthwhile trade-off for spending a couple of milliseconds calling "git gc --auto" (in the common cases where it doesn't do anything). Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 38e79b1 commit 095c741

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

builtin/commit.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1615,6 +1615,7 @@ int run_commit_hook(int editor_is_used, const char *index_file, const char *name
16151615

16161616
int cmd_commit(int argc, const char **argv, const char *prefix)
16171617
{
1618+
const char *argv_gc_auto[] = {"gc", "--auto", NULL};
16181619
static struct wt_status s;
16191620
static struct option builtin_commit_options[] = {
16201621
OPT__QUIET(&quiet, N_("suppress summary after successful commit")),
@@ -1835,6 +1836,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
18351836
"not exceeded, and then \"git reset HEAD\" to recover."));
18361837

18371838
rerere(0);
1839+
run_command_v_opt(argv_gc_auto, RUN_GIT_CMD);
18381840
run_commit_hook(use_editor, get_index_file(), "post-commit", NULL);
18391841
if (amend && !no_post_rewrite) {
18401842
struct notes_rewrite_cfg *cfg;

0 commit comments

Comments
 (0)