{"thread":{"id":"47949","subject":"[PATCH] commit: run git gc --auto just before the pre-commit hook","startedAt":"2018-02-28T22:14:15Z","lastAt":"2018-02-28T23:39:24Z","messageCount":4,"participants":["Ævar Arnfjörð Bjarmason","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"340630","messageId":"20180228221358.16286-1-avarab@gmail.com","threadId":"47949","inReplyTo":null,"subject":"[PATCH] commit: run git gc --auto just before the pre-commit hook","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2018-02-28T22:13:58Z","receivedAt":"2018-02-28T22:14:15Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Change the behavior of git-commit back to what it was back in\nd4bb43ee27 (\"Invoke \"git gc --auto\" from commit, merge, am and\nrebase.\", 2007-09-05) when it was git-commit.sh.\n\nShortly afterwards in f5bbc3225c (\"Port git commit to C.\", 2007-11-08)\nwhen it was ported to C the \"git gc --auto\" invocation went away.\n\nBefore this git gc --auto only ran for\ngit-{am,merge,fetch,receive-pack}, therefore it was possible to write\na script that would \"git commit\" a lot of data locally, and gc would\nnever run.\n\nOne such repository that was locally committing generated zone file\nchanges had grown to a size of ~60GB before a daily cronjob was added\nto \"git gc\", bringing it down to less than 1GB. This will make such\ncases work transparently.\n\nI think fixing such pathological cases where the repository will grow\nforever is a worthwhile trade-off for spending a couple of\nmilliseconds calling \"git gc --auto\" (in the common cases where it\ndoesn't do anything).\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n builtin/commit.c | 2 ++\n 1 file changed, 2 insertions(+)\n\ndiff --git a/builtin/commit.c b/builtin/commit.c\nindex e8e8d13be4..b671367840 100644\n--- a/builtin/commit.c\n+++ b/builtin/commit.c\n@@ -1402,6 +1402,7 @@ int run_commit_hook(int editor_is_used, const char *index_file, const char *name\n \n int cmd_commit(int argc, const char **argv, const char *prefix)\n {\n+\tconst char *argv_gc_auto[] = {\"gc\", \"--auto\", NULL};\n \tstatic struct wt_status s;\n \tstatic struct option builtin_commit_options[] = {\n \t\tOPT__QUIET(&quiet, N_(\"suppress summary after successful commit\")),\n@@ -1608,6 +1609,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)\n \n \trerere(0);\n \trun_commit_hook(use_editor, get_index_file(), \"post-commit\", NULL);\n+\trun_command_v_opt(argv_gc_auto, RUN_GIT_CMD);\n \tif (amend && !no_post_rewrite) {\n \t\tcommit_post_rewrite(current_head, &oid);\n \t}\n-- \n2.15.1.424.g9478a66081\n\n"},{"id":"340635","messageId":"xmqqzi3siw88.fsf@gitster-ct.c.googlers.com","threadId":"47949","inReplyTo":"20180228221358.16286-1-avarab@gmail.com","subject":"Re: [PATCH] commit: run git gc --auto just before the pre-commit hook","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2018-02-28T22:29:43Z","receivedAt":"2018-02-28T22:29:52Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Ævar Arnfjörð Bjarmason  <avarab@gmail.com> writes:\n\n> Change the behavior of git-commit back to what it was back in\n> d4bb43ee27 (\"Invoke \"git gc --auto\" from commit, merge, am and\n> rebase.\", 2007-09-05) when it was git-commit.sh.\n\n... which was to run it just before post-commit.  Do I retitle this\npatch before queuing?\n\nThe code seems to run it \"after\" post-commit.  We need to explain\nwhy we chose to run it differently from the old practice, when we\nclaim we resurrect the old behaviour with this change.\n\n> Shortly afterwards in f5bbc3225c (\"Port git commit to C.\", 2007-11-08)\n> when it was ported to C the \"git gc --auto\" invocation went away.\n\nSo this is a decade late regression fix?  As they say, better late\nthan never, probably.\n\n> @@ -1608,6 +1609,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)\n>  \n>  \trerere(0);\n>  \trun_commit_hook(use_editor, get_index_file(), \"post-commit\", NULL);\n> +\trun_command_v_opt(argv_gc_auto, RUN_GIT_CMD);\n>  \tif (amend && !no_post_rewrite) {\n>  \t\tcommit_post_rewrite(current_head, &oid);\n>  \t}\n"},{"id":"340638","messageId":"20180228230425.14952-1-avarab@gmail.com","threadId":"47949","inReplyTo":"xmqqzi3siw88.fsf@gitster-ct.c.googlers.com","subject":"[PATCH v2] commit: run git gc --auto just before the pre-commit hook","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2018-02-28T23:04:25Z","receivedAt":"2018-02-28T23:04:41Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Change the behavior of git-commit back to what it was back in\nd4bb43ee27 (\"Invoke \"git gc --auto\" from commit, merge, am and\nrebase.\", 2007-09-05) when it was git-commit.sh.\n\nShortly afterwards in f5bbc3225c (\"Port git commit to C.\", 2007-11-08)\nwhen it was ported to C, the \"git gc --auto\" invocation went away.\n\nBefore this, git gc --auto only ran for\ngit-{am,merge,fetch,receive-pack}. Therefore it was possible to write\na script that would \"git commit\" a lot of data locally, and gc would\nnever run.\n\nOne such repository that was locally committing generated zone file\nchanges had grown to a size of ~60GB before a daily cronjob was added\nto \"git gc\", bringing it down to less than 1GB. This will make such\ncases work without intervention.\n\nI think fixing such pathological cases where the repository will grow\nforever is a worthwhile trade-off for spending a couple of\nmilliseconds calling \"git gc --auto\" (in the common cases where it\ndoesn't do anything).\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n\nOn Wed, Feb 28 2018, Junio C. Hamano jotted:\n\n> Ævar Arnfjörð Bjarmason  <avarab@gmail.com> writes:\n>\n>> Change the behavior of git-commit back to what it was back in\n>> d4bb43ee27 (\"Invoke \"git gc --auto\" from commit, merge, am and\n>> rebase.\", 2007-09-05) when it was git-commit.sh.\n>\n> ... which was to run it just before post-commit.  Do I retitle this\n> patch before queuing?\n\nDo'h. Of course I screw up something simple like that, sorry. This v2\nfixes it, and I also rephrased the commit message a bit (more commas &\nfull-stops).\n\n> So this is a decade late regression fix?  As they say, better late\n> than never, probably.\n\nYup.\n\nI wonder if it would also be a good idea to run git gc --auto on \"git\npush\". It itself won't create any objects, but it would be a nice\nproxy in many cases for picking up anything else we missed due to\nvarious object writing commands that won't run --auto.\n\n builtin/commit.c | 2 ++\n 1 file changed, 2 insertions(+)\n\ndiff --git a/builtin/commit.c b/builtin/commit.c\nindex e8e8d13be4..a16a056f6a 100644\n--- a/builtin/commit.c\n+++ b/builtin/commit.c\n@@ -1402,6 +1402,7 @@ int run_commit_hook(int editor_is_used, const char *index_file, const char *name\n \n int cmd_commit(int argc, const char **argv, const char *prefix)\n {\n+\tconst char *argv_gc_auto[] = {\"gc\", \"--auto\", NULL};\n \tstatic struct wt_status s;\n \tstatic struct option builtin_commit_options[] = {\n \t\tOPT__QUIET(&quiet, N_(\"suppress summary after successful commit\")),\n@@ -1607,6 +1608,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)\n \t\t     \"not exceeded, and then \\\"git reset HEAD\\\" to recover.\"));\n \n \trerere(0);\n+\trun_command_v_opt(argv_gc_auto, RUN_GIT_CMD);\n \trun_commit_hook(use_editor, get_index_file(), \"post-commit\", NULL);\n \tif (amend && !no_post_rewrite) {\n \t\tcommit_post_rewrite(current_head, &oid);\n-- \n2.15.1.424.g9478a66081\n\n"},{"id":"340678","messageId":"xmqqmuzsit0c.fsf@gitster-ct.c.googlers.com","threadId":"47949","inReplyTo":"20180228230425.14952-1-avarab@gmail.com","subject":"Re: [PATCH v2] commit: run git gc --auto just before the pre-commit hook","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2018-02-28T23:39:15Z","receivedAt":"2018-02-28T23:39:24Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Ævar Arnfjörð Bjarmason  <avarab@gmail.com> writes:\n\n>> Ævar Arnfjörð Bjarmason  <avarab@gmail.com> writes:\n>>\n>>> Change the behavior of git-commit back to what it was back in\n>>> d4bb43ee27 (\"Invoke \"git gc --auto\" from commit, merge, am and\n>>> rebase.\", 2007-09-05) when it was git-commit.sh.\n>>\n>> ... which was to run it just before post-commit.  Do I retitle this\n>> patch before queuing?\n>\n> Do'h. Of course I screw up something simple like that, sorry. This v2\n> fixes it, and I also rephrased the commit message a bit (more commas &\n> full-stops).\n\nI guess I still need to retitle it ;-) But that can happen tomorrow\n(I have the previous one with local fixes that pretty much matches\nv2 modulo the body of the log message on 'pu', ready to be pushed\nout).\n\n> I wonder if it would also be a good idea to run git gc --auto on \"git\n> push\". It itself won't create any objects, but it would be a nice\n> proxy in many cases for picking up anything else we missed due to\n> various object writing commands that won't run --auto.\n\nBefore \"push\" starts producing a pack might be a good optimization,\nas reading from a packed repository is often more performant than a\nrepository full of loose objects.\n\n"}]}