{"thread":{"id":"23809","subject":"[PATCH] notes: dry-run and verbose options for prune","startedAt":"2010-05-14T21:42:07Z","lastAt":"2010-05-16T13:53:30Z","messageCount":4,"participants":["Michael J Gruber","Johan Herland","Stephen Boyd"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"141704","messageId":"ecbe317d2f12d83185f3c3242c0350051e3b4bfa.1273873273.git.git@drmicha.warpmail.net","threadId":"23809","inReplyTo":null,"subject":"[PATCH] notes: dry-run and verbose options for prune","fromName":"Michael J Gruber","fromEmail":"git@drmicha.warpmail.net","sentAt":"2010-05-14T21:42:07Z","receivedAt":"2010-05-14T21:42:07Z","isPatch":true,"sender":{"key":"git@grubix.eu","avatar":"https://avatars.githubusercontent.com/u/233215?v=4"},"body":"Introduce -n and -v options for \"git notes prune\" in complete analogy to\n\"git prune\" so that one can check for dangling notes easily.\n\nThe output is a list of names of objects whose notes would be resp.\nare removed so that one can check the object (\"git show sha1\") as well as\nthe note (\"git notes show sha1\").\n\nSigned-off-by: Michael J Gruber <git@drmicha.warpmail.net>\n---\n Documentation/git-notes.txt |    9 +++++++-\n builtin/notes.c             |   13 ++++++++---\n notes.c                     |    7 ++++-\n notes.h                     |    5 +++-\n t/t3306-notes-prune.sh      |   48 +++++++++++++++++++++++++++++++++++++++++-\n 5 files changed, 72 insertions(+), 10 deletions(-)\n\ndiff --git a/Documentation/git-notes.txt b/Documentation/git-notes.txt\nindex 4e5113b..0f32792 100644\n--- a/Documentation/git-notes.txt\n+++ b/Documentation/git-notes.txt\n@@ -15,7 +15,7 @@ SYNOPSIS\n 'git notes' edit [<object>]\n 'git notes' show [<object>]\n 'git notes' remove [<object>]\n-'git notes' prune\n+'git notes' prune [-n | -v]\n \n \n DESCRIPTION\n@@ -121,6 +121,13 @@ OPTIONS\n \tGIT_NOTES_REF and the \"core.notesRef\" configuration.  The ref\n \tis taken to be in `refs/notes/` if it is not qualified.\n \n+-n::\n+\tDo not remove anything; just report the object names whose notes\n+\twould be removed.\n+\n+-v::\n+\tReport all object names whose notes are removed.\n+\n \n NOTES\n -----\ndiff --git a/builtin/notes.c b/builtin/notes.c\nindex 52b72fc..8c2ac51 100644\n--- a/builtin/notes.c\n+++ b/builtin/notes.c\n@@ -26,7 +26,7 @@ static const char * const git_notes_usage[] = {\n \t\"git notes [--ref <notes_ref>] edit [<object>]\",\n \t\"git notes [--ref <notes_ref>] show [<object>]\",\n \t\"git notes [--ref <notes_ref>] remove [<object>]\",\n-\t\"git notes [--ref <notes_ref>] prune\",\n+\t\"git notes [--ref <notes_ref>] prune [-n | -v]\",\n \tNULL\n };\n \n@@ -67,7 +67,7 @@ static const char * const git_notes_remove_usage[] = {\n };\n \n static const char * const git_notes_prune_usage[] = {\n-\t\"git notes prune\",\n+\t\"git notes prune [<options>]\",\n \tNULL\n };\n \n@@ -792,7 +792,10 @@ static int remove_cmd(int argc, const char **argv, const char *prefix)\n static int prune(int argc, const char **argv, const char *prefix)\n {\n \tstruct notes_tree *t;\n+\tint show_only, verbose;\n \tstruct option options[] = {\n+\t\tOPT_BOOLEAN('n', NULL, &show_only, \"do not remove, show only\"),\n+\t\tOPT_BOOLEAN('v', NULL, &verbose, \"report pruned notes\"),\n \t\tOPT_END()\n \t};\n \n@@ -806,8 +809,10 @@ static int prune(int argc, const char **argv, const char *prefix)\n \n \tt = init_notes_check(\"prune\");\n \n-\tprune_notes(t);\n-\tcommit_notes(t, \"Notes removed by 'git notes prune'\");\n+\tprune_notes(t, (verbose ? NOTES_PRUNE_VERBOSE : 0) |\n+\t\t(show_only ? NOTES_PRUNE_VERBOSE|NOTES_PRUNE_DRYRUN : 0) );\n+\tif (!show_only)\n+\t\tcommit_notes(t, \"Notes removed by 'git notes prune'\");\n \tfree_notes(t);\n \treturn 0;\n }\ndiff --git a/notes.c b/notes.c\nindex e425e19..6ee04e7 100644\n--- a/notes.c\n+++ b/notes.c\n@@ -1083,7 +1083,7 @@ int write_notes_tree(struct notes_tree *t, unsigned char *result)\n \treturn ret;\n }\n \n-void prune_notes(struct notes_tree *t)\n+void prune_notes(struct notes_tree *t, int flags)\n {\n \tstruct note_delete_list *l = NULL;\n \n@@ -1094,7 +1094,10 @@ void prune_notes(struct notes_tree *t)\n \tfor_each_note(t, 0, prune_notes_helper, &l);\n \n \twhile (l) {\n-\t\tremove_note(t, l->sha1);\n+\t\tif (flags & NOTES_PRUNE_VERBOSE)\n+\t\t\tprintf(\"%s\\n\", sha1_to_hex(l->sha1));\n+\t\tif (!(flags & NOTES_PRUNE_DRYRUN))\n+\t\t\tremove_note(t, l->sha1);\n \t\tl = l->next;\n \t}\n }\ndiff --git a/notes.h b/notes.h\nindex 9f59277..cc2dff2 100644\n--- a/notes.h\n+++ b/notes.h\n@@ -171,6 +171,9 @@ int for_each_note(struct notes_tree *t, int flags, each_note_fn fn,\n  */\n int write_notes_tree(struct notes_tree *t, unsigned char *result);\n \n+/* Flags controlling the operation of prune */\n+#define NOTES_PRUNE_VERBOSE 1\n+#define NOTES_PRUNE_DRYRUN 2\n /*\n  * Remove all notes annotating non-existing objects from the given notes tree\n  *\n@@ -181,7 +184,7 @@ int write_notes_tree(struct notes_tree *t, unsigned char *result);\n  * structure are not persistent until a subsequent call to write_notes_tree()\n  * returns zero.\n  */\n-void prune_notes(struct notes_tree *t);\n+void prune_notes(struct notes_tree *t, int flags);\n \n /*\n  * Free (and de-initialize) the given notes_tree structure\ndiff --git a/t/t3306-notes-prune.sh b/t/t3306-notes-prune.sh\nindex a0ed035..a47e4b5 100755\n--- a/t/t3306-notes-prune.sh\n+++ b/t/t3306-notes-prune.sh\n@@ -60,7 +60,7 @@ test_expect_success 'verify commits and notes' '\n \n test_expect_success 'remove some commits' '\n \n-\tgit reset --hard HEAD~2 &&\n+\tgit reset --hard HEAD~1 &&\n \tgit reflog expire --expire=now HEAD &&\n \tgit gc --prune=now\n '\n@@ -68,7 +68,7 @@ test_expect_success 'remove some commits' '\n test_expect_success 'verify that commits are gone' '\n \n \t! git cat-file -p 5ee1c35e83ea47cd3cc4f8cbee0568915fbbbd29 &&\n-\t! git cat-file -p 08341ad9e94faa089d60fd3f523affb25c6da189 &&\n+\tgit cat-file -p 08341ad9e94faa089d60fd3f523affb25c6da189 &&\n \tgit cat-file -p ab5f302035f2e7aaf04265f08b42034c23256e1f\n '\n \n@@ -79,6 +79,26 @@ test_expect_success 'verify that notes are still present' '\n \tgit notes show ab5f302035f2e7aaf04265f08b42034c23256e1f\n '\n \n+test_expect_success 'prune -n does not remove notes' '\n+\n+\tgit notes list > expect &&\n+\tgit notes prune -n &&\n+\tgit notes list > actual &&\n+\ttest_cmp expect actual\n+'\n+\n+cat > expect <<EOF\n+5ee1c35e83ea47cd3cc4f8cbee0568915fbbbd29\n+EOF\n+\n+test_expect_success 'prune -n lists prunable notes' '\n+\n+\t\n+\tgit notes prune -n > actual &&\n+\ttest_cmp expect actual\n+' \n+\n+\n test_expect_success 'prune notes' '\n \n \tgit notes prune\n@@ -87,6 +107,30 @@ test_expect_success 'prune notes' '\n test_expect_success 'verify that notes are gone' '\n \n \t! git notes show 5ee1c35e83ea47cd3cc4f8cbee0568915fbbbd29 &&\n+\tgit notes show 08341ad9e94faa089d60fd3f523affb25c6da189 &&\n+\tgit notes show ab5f302035f2e7aaf04265f08b42034c23256e1f\n+'\n+\n+test_expect_success 'remove some commits' '\n+\n+\tgit reset --hard HEAD~1 &&\n+\tgit reflog expire --expire=now HEAD &&\n+\tgit gc --prune=now\n+'\n+\n+cat > expect <<EOF\n+08341ad9e94faa089d60fd3f523affb25c6da189\n+EOF\n+\n+test_expect_success 'prune -v notes' '\n+\n+\tgit notes prune -v > actual &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'verify that notes are gone' '\n+\n+\t! git notes show 5ee1c35e83ea47cd3cc4f8cbee0568915fbbbd29 &&\n \t! git notes show 08341ad9e94faa089d60fd3f523affb25c6da189 &&\n \tgit notes show ab5f302035f2e7aaf04265f08b42034c23256e1f\n '\n-- \n1.7.1.240.geeaa4d\n"},{"id":"141708","messageId":"201005150138.16618.johan@herland.net","threadId":"23809","inReplyTo":"ecbe317d2f12d83185f3c3242c0350051e3b4bfa.1273873273.git.git@drmicha.warpmail.net","subject":"Re: [PATCH] notes: dry-run and verbose options for prune","fromName":"Johan Herland","fromEmail":"johan@herland.net","sentAt":"2010-05-14T23:38:16Z","receivedAt":"2010-05-14T23:38:16Z","isPatch":true,"sender":{"key":"johan@herland.net","avatar":"https://avatars.githubusercontent.com/u/547031?v=4"},"body":"On Friday 14 May 2010, Michael J Gruber wrote:\n> Introduce -n and -v options for \"git notes prune\" in complete analogy to\n> \"git prune\" so that one can check for dangling notes easily.\n> \n> The output is a list of names of objects whose notes would be resp.\n> are removed so that one can check the object (\"git show sha1\") as well as\n> the note (\"git notes show sha1\").\n> \n> Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net>\n\nLove it! :)\n\nAcked-by: Johan Herland <johan@herland.net>\n\n\nThanks!\n\n...Johan\n\n\n-- \nJohan Herland, <johan@herland.net>\nwww.herland.net\n"},{"id":"141748","messageId":"4BEF1D93.7070305@gmail.com","threadId":"23809","inReplyTo":"ecbe317d2f12d83185f3c3242c0350051e3b4bfa.1273873273.git.git@drmicha.warpmail.net","subject":"Re: [PATCH] notes: dry-run and verbose options for prune","fromName":"Stephen Boyd","fromEmail":"bebarino@gmail.com","sentAt":"2010-05-15T22:17:55Z","receivedAt":"2010-05-15T22:17:55Z","isPatch":true,"sender":{"key":"bebarino@gmail.com","avatar":"https://avatars.githubusercontent.com/u/38832?v=4"},"body":"On 05/14/2010 02:42 PM, Michael J Gruber wrote:\n> @@ -792,7 +792,10 @@ static int remove_cmd(int argc, const char **argv, const char *prefix)\n>  static int prune(int argc, const char **argv, const char *prefix)\n>  {\n>  \tstruct notes_tree *t;\n> +\tint show_only, verbose;\n>  \tstruct option options[] = {\n> +\t\tOPT_BOOLEAN('n', NULL, &show_only, \"do not remove, show only\"),\n> +\t\tOPT_BOOLEAN('v', NULL, &verbose, \"report pruned notes\"),\n>  \t\tOPT_END()\n>  \t};\n>   \n\nWhy not use the standard OPT__DRY_RUN and OPT__VERBOSE macros?\n\n---->8----\n\ndiff --git a/Documentation/git-notes.txt b/Documentation/git-notes.txt\nindex 0f32792..6e53c9a 100644\n--- a/Documentation/git-notes.txt\n+++ b/Documentation/git-notes.txt\n@@ -122,10 +122,12 @@ OPTIONS\n        is taken to be in `refs/notes/` if it is not qualified.\n \n -n::\n+--dry-run::\n        Do not remove anything; just report the object names whose notes\n        would be removed.\n \n -v::\n+--verbose::\n        Report all object names whose notes are removed.\n \n \ndiff --git a/builtin/notes.c b/builtin/notes.c\nindex 8c2ac51..0ae2561 100644\n--- a/builtin/notes.c\n+++ b/builtin/notes.c\n@@ -794,8 +794,8 @@ static int prune(int argc, const char **argv, const char *pr\n        struct notes_tree *t;\n        int show_only, verbose;\n        struct option options[] = {\n-               OPT_BOOLEAN('n', NULL, &show_only, \"do not remove, show only\"),\n-               OPT_BOOLEAN('v', NULL, &verbose, \"report pruned notes\"),\n+               OPT__DRY_RUN(&show_only),\n+               OPT__VERBOSE(&verbose),\n                OPT_END()\n        };\n \n"},{"id":"141772","messageId":"4BEFF8DA.502@drmicha.warpmail.net","threadId":"23809","inReplyTo":"4BEF1D93.7070305@gmail.com","subject":"Re: [PATCH] notes: dry-run and verbose options for prune","fromName":"Michael J Gruber","fromEmail":"git@drmicha.warpmail.net","sentAt":"2010-05-16T13:53:30Z","receivedAt":"2010-05-16T13:53:30Z","isPatch":true,"sender":{"key":"git@grubix.eu","avatar":"https://avatars.githubusercontent.com/u/233215?v=4"},"body":"Stephen Boyd venit, vidit, dixit 16.05.2010 00:17:\n> On 05/14/2010 02:42 PM, Michael J Gruber wrote:\n>> @@ -792,7 +792,10 @@ static int remove_cmd(int argc, const char **argv, const char *prefix)\n>>  static int prune(int argc, const char **argv, const char *prefix)\n>>  {\n>>  \tstruct notes_tree *t;\n>> +\tint show_only, verbose;\n>>  \tstruct option options[] = {\n>> +\t\tOPT_BOOLEAN('n', NULL, &show_only, \"do not remove, show only\"),\n>> +\t\tOPT_BOOLEAN('v', NULL, &verbose, \"report pruned notes\"),\n>>  \t\tOPT_END()\n>>  \t};\n>>   \n> \n> Why not use the standard OPT__DRY_RUN and OPT__VERBOSE macros?\n\nBecause of the part you cut out: complete analogy with \"git prune\".\n\nI don't mind using the OPT__ions, but suggest that unification as a\nseparate task (involving all occurences of -v and -n, not just this one).\n\n> \n> ---->8----\n> \n> diff --git a/Documentation/git-notes.txt b/Documentation/git-notes.txt\n> index 0f32792..6e53c9a 100644\n> --- a/Documentation/git-notes.txt\n> +++ b/Documentation/git-notes.txt\n> @@ -122,10 +122,12 @@ OPTIONS\n>         is taken to be in `refs/notes/` if it is not qualified.\n>  \n>  -n::\n> +--dry-run::\n>         Do not remove anything; just report the object names whose notes\n>         would be removed.\n>  \n>  -v::\n> +--verbose::\n>         Report all object names whose notes are removed.\n>  \n>  \n> diff --git a/builtin/notes.c b/builtin/notes.c\n> index 8c2ac51..0ae2561 100644\n> --- a/builtin/notes.c\n> +++ b/builtin/notes.c\n> @@ -794,8 +794,8 @@ static int prune(int argc, const char **argv, const char *pr\n>         struct notes_tree *t;\n>         int show_only, verbose;\n>         struct option options[] = {\n> -               OPT_BOOLEAN('n', NULL, &show_only, \"do not remove, show only\"),\n> -               OPT_BOOLEAN('v', NULL, &verbose, \"report pruned notes\"),\n> +               OPT__DRY_RUN(&show_only),\n> +               OPT__VERBOSE(&verbose),\n>                 OPT_END()\n>         };\n>  \n> \n> \n"}]}