@matheusbsbs / matheus-bagliano / commits / a9f2adff80
Fork 0

notes: dry-run and verbose options for prune

Introduce -n and -v options for "git notes prune" in complete analogy to "git prune" so that one can check for dangling notes easily. The output is a list of names of objects whose notes would be resp. are removed so that one can check the object ("git show sha1") as well as the note ("git notes show sha1"). Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net> Acked-by: Johan Herland <johan@herland.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Michael J Gruber committed May 14, 2010 at 23:42 UTC a9f2adff802308481f2e638bae0c5b6e205251a3
5 files changed +72 -10
Documentation/git-notes.txt
+8 -1
@@ -15,7 +15,7 @@ SYNOPSIS
15 'git notes' edit [<object>]
16 'git notes' show [<object>]
17 'git notes' remove [<object>]
18 -'git notes' prune
18 +'git notes' prune [-n | -v]
19
20
21 DESCRIPTION
@@ -121,6 +121,13 @@ OPTIONS
121 GIT_NOTES_REF and the "core.notesRef" configuration. The ref
122 is taken to be in `refs/notes/` if it is not qualified.
123
124 +-n::
125 + Do not remove anything; just report the object names whose notes
126 + would be removed.
127 +
128 +-v::
129 + Report all object names whose notes are removed.
130 +
131
132 NOTES
133 -----
builtin/notes.c
+9 -4
@@ -26,7 +26,7 @@ static const char * const git_notes_usage[] = {
26 "git notes [--ref <notes_ref>] edit [<object>]",
27 "git notes [--ref <notes_ref>] show [<object>]",
28 "git notes [--ref <notes_ref>] remove [<object>]",
29 - "git notes [--ref <notes_ref>] prune",
29 + "git notes [--ref <notes_ref>] prune [-n | -v]",
30 NULL
31 };
32
@@ -67,7 +67,7 @@ static const char * const git_notes_remove_usage[] = {
67 };
68
69 static const char * const git_notes_prune_usage[] = {
70 - "git notes prune",
70 + "git notes prune [<options>]",
71 NULL
72 };
73
@@ -792,7 +792,10 @@ static int remove_cmd(int argc, const char **argv, const char *prefix)
792 static int prune(int argc, const char **argv, const char *prefix)
793 {
794 struct notes_tree *t;
795 + int show_only = 0, verbose = 0;
796 struct option options[] = {
797 + OPT_BOOLEAN('n', NULL, &show_only, "do not remove, show only"),
798 + OPT_BOOLEAN('v', NULL, &verbose, "report pruned notes"),
799 OPT_END()
800 };
801
@@ -806,8 +809,10 @@ static int prune(int argc, const char **argv, const char *prefix)
809
810 t = init_notes_check("prune");
811
809 - prune_notes(t);
810 - commit_notes(t, "Notes removed by 'git notes prune'");
812 + prune_notes(t, (verbose ? NOTES_PRUNE_VERBOSE : 0) |
813 + (show_only ? NOTES_PRUNE_VERBOSE|NOTES_PRUNE_DRYRUN : 0) );
814 + if (!show_only)
815 + commit_notes(t, "Notes removed by 'git notes prune'");
816 free_notes(t);
817 return 0;
818 }
notes.c
+5 -2
@@ -1083,7 +1083,7 @@ int write_notes_tree(struct notes_tree *t, unsigned char *result)
1083 return ret;
1084 }
1085
1086 -void prune_notes(struct notes_tree *t)
1086 +void prune_notes(struct notes_tree *t, int flags)
1087 {
1088 struct note_delete_list *l = NULL;
1089
@@ -1094,7 +1094,10 @@ void prune_notes(struct notes_tree *t)
1094 for_each_note(t, 0, prune_notes_helper, &l);
1095
1096 while (l) {
1097 - remove_note(t, l->sha1);
1097 + if (flags & NOTES_PRUNE_VERBOSE)
1098 + printf("%s\n", sha1_to_hex(l->sha1));
1099 + if (!(flags & NOTES_PRUNE_DRYRUN))
1100 + remove_note(t, l->sha1);
1101 l = l->next;
1102 }
1103 }
notes.h
+4 -1
@@ -171,6 +171,9 @@ int for_each_note(struct notes_tree *t, int flags, each_note_fn fn,
171 */
172 int write_notes_tree(struct notes_tree *t, unsigned char *result);
173
174 +/* Flags controlling the operation of prune */
175 +#define NOTES_PRUNE_VERBOSE 1
176 +#define NOTES_PRUNE_DRYRUN 2
177 /*
178 * Remove all notes annotating non-existing objects from the given notes tree
179 *
@@ -181,7 +184,7 @@ int write_notes_tree(struct notes_tree *t, unsigned char *result);
184 * structure are not persistent until a subsequent call to write_notes_tree()
185 * returns zero.
186 */
184 -void prune_notes(struct notes_tree *t);
187 +void prune_notes(struct notes_tree *t, int flags);
188
189 /*
190 * Free (and de-initialize) the given notes_tree structure
t/t3306-notes-prune.sh
+46 -2
@@ -60,7 +60,7 @@ test_expect_success 'verify commits and notes' '
60
61 test_expect_success 'remove some commits' '
62
63 - git reset --hard HEAD~2 &&
63 + git reset --hard HEAD~1 &&
64 git reflog expire --expire=now HEAD &&
65 git gc --prune=now
66 '
@@ -68,7 +68,7 @@ test_expect_success 'remove some commits' '
68 test_expect_success 'verify that commits are gone' '
69
70 ! git cat-file -p 5ee1c35e83ea47cd3cc4f8cbee0568915fbbbd29 &&
71 - ! git cat-file -p 08341ad9e94faa089d60fd3f523affb25c6da189 &&
71 + git cat-file -p 08341ad9e94faa089d60fd3f523affb25c6da189 &&
72 git cat-file -p ab5f302035f2e7aaf04265f08b42034c23256e1f
73 '
74
@@ -79,11 +79,55 @@ test_expect_success 'verify that notes are still present' '
79 git notes show ab5f302035f2e7aaf04265f08b42034c23256e1f
80 '
81
82 +test_expect_success 'prune -n does not remove notes' '
83 +
84 + git notes list > expect &&
85 + git notes prune -n &&
86 + git notes list > actual &&
87 + test_cmp expect actual
88 +'
89 +
90 +cat > expect <<EOF
91 +5ee1c35e83ea47cd3cc4f8cbee0568915fbbbd29
92 +EOF
93 +
94 +test_expect_success 'prune -n lists prunable notes' '
95 +
96 +
97 + git notes prune -n > actual &&
98 + test_cmp expect actual
99 +'
100 +
101 +
102 test_expect_success 'prune notes' '
103
104 git notes prune
105 '
106
107 +test_expect_success 'verify that notes are gone' '
108 +
109 + ! git notes show 5ee1c35e83ea47cd3cc4f8cbee0568915fbbbd29 &&
110 + git notes show 08341ad9e94faa089d60fd3f523affb25c6da189 &&
111 + git notes show ab5f302035f2e7aaf04265f08b42034c23256e1f
112 +'
113 +
114 +test_expect_success 'remove some commits' '
115 +
116 + git reset --hard HEAD~1 &&
117 + git reflog expire --expire=now HEAD &&
118 + git gc --prune=now
119 +'
120 +
121 +cat > expect <<EOF
122 +08341ad9e94faa089d60fd3f523affb25c6da189
123 +EOF
124 +
125 +test_expect_success 'prune -v notes' '
126 +
127 + git notes prune -v > actual &&
128 + test_cmp expect actual
129 +'
130 +
131 test_expect_success 'verify that notes are gone' '
132
133 ! git notes show 5ee1c35e83ea47cd3cc4f8cbee0568915fbbbd29 &&