{"thread":{"id":"10149","subject":"[PATCH 1/2] git-gc: allow --prune to be specified with --auto","startedAt":"2007-10-05T00:12:49Z","lastAt":"2007-10-05T00:12:49Z","messageCount":1,"participants":["Steven Grimm"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"54890","messageId":"20071005001249.GA12896@midwinter.com","threadId":"10149","inReplyTo":null,"subject":"[PATCH 1/2] git-gc: allow --prune to be specified with --auto","fromName":"Steven Grimm","fromEmail":"koreth@midwinter.com","sentAt":"2007-10-05T00:12:49Z","receivedAt":"2007-10-05T00:12:49Z","isPatch":true,"sender":{"key":"koreth@midwinter.com","avatar":"https://gravatar.com/avatar/71b4d2e8b62f168bdc9e9205341159e3567003b4f9e2127c617c5fa0a1f5bad2?d=mp&s=160"},"body":"This will run git-prune only if there are still lots of loose objects\nafter the repack finishes. Obviously the caveats about pruning not being\na safe operation to run concurrently with other git commands still apply.\n\nSigned-off-by: Steven Grimm <koreth@midwinter.com>\n---\n Documentation/git-gc.txt |    4 +++-\n builtin-gc.c             |   18 +++++++++++++-----\n 2 files changed, 16 insertions(+), 6 deletions(-)\n\ndiff --git a/Documentation/git-gc.txt b/Documentation/git-gc.txt\nindex b9d5660..60731e9 100644\n--- a/Documentation/git-gc.txt\n+++ b/Documentation/git-gc.txt\n@@ -33,7 +33,9 @@ OPTIONS\n \tdone by default.  Pass this option if you want it, and only\n \twhen you know nobody else is creating new objects in the\n \trepository at the same time (e.g. never use this option\n-\tin a cron script).\n+\tin a cron script). If used with the `--auto` option,\n+\tpruning will only be done if there are many loose objects\n+\tin the repository after gitlink:git-repack[1] is finished.\n \n --aggressive::\n \tUsually 'git-gc' runs very quickly while providing good disk\ndiff --git a/builtin-gc.c b/builtin-gc.c\nindex 23ad2b6..b65cacc 100644\n--- a/builtin-gc.c\n+++ b/builtin-gc.c\n@@ -208,7 +208,6 @@ int cmd_gc(int argc, const char **argv, const char *prefix)\n \t\t/*\n \t\t * Auto-gc should be least intrusive as possible.\n \t\t */\n-\t\tprune = 0;\n \t\tif (!need_to_gc())\n \t\t\treturn 0;\n \t}\n@@ -222,15 +221,24 @@ int cmd_gc(int argc, const char **argv, const char *prefix)\n \tif (run_command_v_opt(argv_repack, RUN_GIT_CMD))\n \t\treturn error(FAILED_RUN, argv_repack[0]);\n \n+\tif (auto_gc) {\n+\t\tif (too_many_loose_objects()) {\n+\t\t\tif (! prune) {\n+\t\t\t\twarning(\"There are too many unreachable loose \"\n+\t\t\t\t\t\"objects; run 'git gc --prune' to \"\n+\t\t\t\t\t\"remove them.\");\n+\t\t\t}\n+\t\t\t// else we will run the prune next\n+\t\t} else {\n+\t\t\tprune = 0;\n+\t\t}\n+\t}\n+\n \tif (prune && run_command_v_opt(argv_prune, RUN_GIT_CMD))\n \t\treturn error(FAILED_RUN, argv_prune[0]);\n \n \tif (run_command_v_opt(argv_rerere, RUN_GIT_CMD))\n \t\treturn error(FAILED_RUN, argv_rerere[0]);\n \n-\tif (auto_gc && too_many_loose_objects())\n-\t\twarning(\"There are too many unreachable loose objects; \"\n-\t\t\t\"run 'git prune' to remove them.\");\n-\n \treturn 0;\n }\n-- \n1.5.3.4.203.gcc61a\n"}]}