{"thread":{"id":"16743","subject":"[PATCH] gc: make --prune useful again by accepting an optional parameter","startedAt":"2008-12-15T20:22:22Z","lastAt":"2008-12-15T21:17:30Z","messageCount":3,"participants":["Johannes Schindelin","Brandon Casey"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"97998","messageId":"alpine.DEB.1.00.0812152121260.30769@pacific.mpi-cbg.de","threadId":"16743","inReplyTo":null,"subject":"[PATCH] gc: make --prune useful again by accepting an optional parameter","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2008-12-15T20:22:22Z","receivedAt":"2008-12-15T20:22:22Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"\nWith this patch, \"git gc --no-prune\" will not prune any loose (and\ndangling) object, and \"git gc --prune=5.minutes.ago\" will prune\nall loose objects older than 5 minutes.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n\n\tNot meant for 1.6.1, obviously.\n\n Documentation/git-gc.txt |    9 ++++++++-\n builtin-gc.c             |   13 ++++++++-----\n t/t5304-prune.sh         |   20 ++++++++++++++++++++\n 3 files changed, 36 insertions(+), 6 deletions(-)\n\ndiff --git a/Documentation/git-gc.txt b/Documentation/git-gc.txt\nindex 7086eea..fcef5fb 100644\n--- a/Documentation/git-gc.txt\n+++ b/Documentation/git-gc.txt\n@@ -8,7 +8,7 @@ git-gc - Cleanup unnecessary files and optimize the local repository\n \n SYNOPSIS\n --------\n-'git gc' [--aggressive] [--auto] [--quiet]\n+'git gc' [--aggressive] [--auto] [--quiet] [--prune=<date>]\n \n DESCRIPTION\n -----------\n@@ -59,6 +59,13 @@ are consolidated into a single pack by using the `-A` option of\n 'git-repack'. Setting `gc.autopacklimit` to 0 disables\n automatic consolidation of packs.\n \n+--prune=<date>::\n+\tPrune loose objects older than date (default is 2 weeks ago).\n+\tThis option is on by default.\n+\n+--no-prune::\n+\tDo not prune any loose objects.\n+\n --quiet::\n \tSuppress all progress reports.\n \ndiff --git a/builtin-gc.c b/builtin-gc.c\nindex bbc41ac..078c5b3 100644\n--- a/builtin-gc.c\n+++ b/builtin-gc.c\n@@ -199,14 +199,15 @@ static int need_to_gc(void)\n \n int cmd_gc(int argc, const char **argv, const char *prefix)\n {\n-\tint prune = 0;\n \tint aggressive = 0;\n \tint auto_gc = 0;\n \tint quiet = 0;\n \tchar buf[80];\n \n \tstruct option builtin_gc_options[] = {\n-\t\tOPT_BOOLEAN(0, \"prune\", &prune, \"prune unreferenced objects (deprecated)\"),\n+\t\t{ OPTION_STRING, 0, \"prune\", &prune_expire, \"date\",\n+\t\t\t\"prune unreferenced objects (deprecated)\",\n+\t\t\tPARSE_OPT_OPTARG, NULL, (intptr_t)prune_expire },\n \t\tOPT_BOOLEAN(0, \"aggressive\", &aggressive, \"be more thorough (increased runtime)\"),\n \t\tOPT_BOOLEAN(0, \"auto\", &auto_gc, \"enable auto-gc mode\"),\n \t\tOPT_BOOLEAN('q', \"quiet\", &quiet, \"suppress progress reports\"),\n@@ -255,9 +256,11 @@ 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-\targv_prune[2] = prune_expire;\n-\tif (run_command_v_opt(argv_prune, RUN_GIT_CMD))\n-\t\treturn error(FAILED_RUN, argv_prune[0]);\n+\tif (prune_expire) {\n+\t\targv_prune[2] = prune_expire;\n+\t\tif (run_command_v_opt(argv_prune, RUN_GIT_CMD))\n+\t\t\treturn error(FAILED_RUN, argv_prune[0]);\n+\t}\n \n \tif (run_command_v_opt(argv_rerere, RUN_GIT_CMD))\n \t\treturn error(FAILED_RUN, argv_rerere[0]);\ndiff --git a/t/t5304-prune.sh b/t/t5304-prune.sh\nindex 771c0a0..2e9c4a9 100755\n--- a/t/t5304-prune.sh\n+++ b/t/t5304-prune.sh\n@@ -112,4 +112,24 @@ test_expect_success 'prune: do not prune heads listed as an argument' '\n \n '\n \n+test_expect_success 'gc --no-prune && gc --prune=<date>' '\n+\n+\tbefore=$(git count-objects | sed \"s/ .*//\") &&\n+\tBLOB=$(echo aleph_0 | git hash-object -w --stdin) &&\n+\tBLOB_FILE=.git/objects/$(echo $BLOB | sed \"s/^../&\\//\") &&\n+\ttest $((1 + $before)) = $(git count-objects | sed \"s/ .*//\") &&\n+\ttest -f $BLOB_FILE &&\n+\ttest-chmtime =-$((86400*5001)) $BLOB_FILE &&\n+\tgit gc --no-prune &&\n+\ttest 1 = $(git count-objects | sed \"s/ .*//\") &&\n+\ttest -f $BLOB_FILE &&\n+\tgit gc --prune=5002.days.ago &&\n+\ttest 1 = $(git count-objects | sed \"s/ .*//\") &&\n+\ttest -f $BLOB_FILE &&\n+\tgit gc --prune=5000.days.ago &&\n+\ttest 0 = $(git count-objects | sed \"s/ .*//\") &&\n+\ttest ! -f $BLOB_FILE\n+\n+'\n+\n test_done\n-- \n1.6.0.4.1189.g8876f\n"},{"id":"98002","messageId":"j2kXTHA5qGwfTMznJutKnr1RHH7prDrQbr4BYlw-pt2V9gVgqTSERQ@cipher.nrlssc.navy.mil","threadId":"16743","inReplyTo":"alpine.DEB.1.00.0812152121260.30769@pacific.mpi-cbg.de","subject":"Re: [PATCH] gc: make --prune useful again by accepting an optional parameter","fromName":"Brandon Casey","fromEmail":"casey@nrlssc.navy.mil","sentAt":"2008-12-15T21:07:54Z","receivedAt":"2008-12-15T21:07:54Z","isPatch":true,"sender":{"key":"drafnel@gmail.com","avatar":"https://avatars.githubusercontent.com/u/921167?v=4"},"body":"Johannes Schindelin wrote:\n> With this patch, \"git gc --no-prune\" will not prune any loose (and\n> dangling) object, and \"git gc --prune=5.minutes.ago\" will prune\n> all loose objects older than 5 minutes.\n> \n> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n> ---\n\n<snip>\n\n> diff --git a/builtin-gc.c b/builtin-gc.c\n> index bbc41ac..078c5b3 100644\n> --- a/builtin-gc.c\n> +++ b/builtin-gc.c\n> @@ -199,14 +199,15 @@ static int need_to_gc(void)\n>  \n>  int cmd_gc(int argc, const char **argv, const char *prefix)\n>  {\n> -\tint prune = 0;\n>  \tint aggressive = 0;\n>  \tint auto_gc = 0;\n>  \tint quiet = 0;\n>  \tchar buf[80];\n>  \n>  \tstruct option builtin_gc_options[] = {\n> -\t\tOPT_BOOLEAN(0, \"prune\", &prune, \"prune unreferenced objects (deprecated)\"),\n> +\t\t{ OPTION_STRING, 0, \"prune\", &prune_expire, \"date\",\n> +\t\t\t\"prune unreferenced objects (deprecated)\",\n\nThe help string still contains \"deprecated\".\n\n> +\t\t\tPARSE_OPT_OPTARG, NULL, (intptr_t)prune_expire },\n>  \t\tOPT_BOOLEAN(0, \"aggressive\", &aggressive, \"be more thorough (increased runtime)\"),\n>  \t\tOPT_BOOLEAN(0, \"auto\", &auto_gc, \"enable auto-gc mode\"),\n>  \t\tOPT_BOOLEAN('q', \"quiet\", &quiet, \"suppress progress reports\"),\n> @@ -255,9 +256,11 @@ 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> -\targv_prune[2] = prune_expire;\n> -\tif (run_command_v_opt(argv_prune, RUN_GIT_CMD))\n> -\t\treturn error(FAILED_RUN, argv_prune[0]);\n> +\tif (prune_expire) {\n> +\t\targv_prune[2] = prune_expire;\n> +\t\tif (run_command_v_opt(argv_prune, RUN_GIT_CMD))\n> +\t\t\treturn error(FAILED_RUN, argv_prune[0]);\n> +\t}\n\n\nWhen --no-prune is used, not only will packed loose objects not be pruned,\nbut the cleanup of temporary files that git-prune performs will not be done.\n\nMaybe this should be relaxed from \"will not prune _any_ loose object\" to \"will\nnot prune any unreferenced object\".\n\nIf something like:\n\n   if (!prune_expire)\n   \tprune_expire = \"never\";\n\nis added after option parsing, then I think this will satisfy people's requests\nand it will also apply nicely on top of Nico's patch to avoid unpacking objects\nwhen prune_expire == \"now\".\n\n-brandon\n"},{"id":"98003","messageId":"4SmUUF2C_ZbcUqUDScx1sSKXIHaQNjKdBXG6Q2GBMY4@cipher.nrlssc.navy.mil","threadId":"16743","inReplyTo":"j2kXTHA5qGwfTMznJutKnr1RHH7prDrQbr4BYlw-pt2V9gVgqTSERQ@cipher.nrlssc.navy.mil","subject":"Re: [PATCH] gc: make --prune useful again by accepting an optional parameter","fromName":"Brandon Casey","fromEmail":"casey@nrlssc.navy.mil","sentAt":"2008-12-15T21:17:30Z","receivedAt":"2008-12-15T21:17:30Z","isPatch":true,"sender":{"key":"drafnel@gmail.com","avatar":"https://avatars.githubusercontent.com/u/921167?v=4"},"body":"Brandon Casey wrote:\n\n> When --no-prune is used, not only will packed loose objects not be pruned,\n> but the cleanup of temporary files that git-prune performs will not be done.\n\nI forgot that the temporary file cleanup also honors --expire, so there will\nstill be no cleanup of temporary files if prune_expire = \"never\". I think the\nrest of my remarks are still valid.\n\n-brandon\n"}]}