summaryrefslogtreecommitdiff
path: root/builtin-notes.c
diff options
context:
space:
mode:
authorLibravatar Johan Herland <johan@herland.net>2010-02-13 22:28:28 +0100
committerLibravatar Junio C Hamano <gitster@pobox.com>2010-02-13 19:36:15 -0800
commitd6576e1fe3ee4bd7bd2cf01d17499c94da24876f (patch)
treee0d6fa73ea4ed0b9eaca0d2a23c689622909a13f /builtin-notes.c
parentNotes API: prune_notes(): Prune notes that belong to non-existing objects (diff)
downloadtgif-d6576e1fe3ee4bd7bd2cf01d17499c94da24876f.tar.xz
builtin-notes: Add "prune" subcommand for removing notes for missing objects
"git notes prune" will remove all notes that annotate unreachable/non- existing objects. The patch includes tests verifying correct behaviour of the new subcommand. Suggested-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Johan Herland <johan@herland.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin-notes.c')
-rw-r--r--builtin-notes.c28
1 files changed, 18 insertions, 10 deletions
diff --git a/builtin-notes.c b/builtin-notes.c
index 7c4007523b..48bc455a1a 100644
--- a/builtin-notes.c
+++ b/builtin-notes.c
@@ -21,6 +21,7 @@ static const char * const git_notes_usage[] = {
"git notes edit [-m <msg> | -F <file>] [<object>]",
"git notes show [<object>]",
"git notes remove [<object>]",
+ "git notes prune",
NULL
};
@@ -201,7 +202,7 @@ int cmd_notes(int argc, const char **argv, const char *prefix)
const char *object_ref;
char logmsg[100];
- int edit = 0, show = 0, remove = 0;
+ int edit = 0, show = 0, remove = 0, prune = 0;
const char *msgfile = NULL;
struct msg_arg msg = { 0, STRBUF_INIT };
struct option options[] = {
@@ -222,8 +223,10 @@ int cmd_notes(int argc, const char **argv, const char *prefix)
show = 1;
else if (argc && !strcmp(argv[0], "remove"))
remove = 1;
+ else if (argc && !strcmp(argv[0], "prune"))
+ prune = 1;
- if (edit + show + remove != 1)
+ if (edit + show + remove + prune != 1)
usage_with_options(git_notes_usage, options);
if ((msg.given || msgfile) && !edit) {
@@ -237,7 +240,7 @@ int cmd_notes(int argc, const char **argv, const char *prefix)
}
object_ref = argc == 2 ? argv[1] : "HEAD";
- if (argc > 2) {
+ if (argc > 2 || (prune && argc > 1)) {
error("too many parameters");
usage_with_options(git_notes_usage, options);
}
@@ -264,7 +267,7 @@ int cmd_notes(int argc, const char **argv, const char *prefix)
return execv_git_cmd(show_args);
}
- /* edit/remove command */
+ /* edit/remove/prune command */
if (remove)
strbuf_reset(&buf);
@@ -278,12 +281,17 @@ int cmd_notes(int argc, const char **argv, const char *prefix)
die_errno("could not open or read '%s'", msgfile);
}
- create_note(object, &buf, msg.given || msgfile || remove, note,
- new_note);
- if (is_null_sha1(new_note))
- remove_note(t, object);
- else
- add_note(t, object, new_note, combine_notes_overwrite);
+ if (prune) {
+ hashclr(new_note);
+ prune_notes(t);
+ } else {
+ create_note(object, &buf, msg.given || msgfile || remove, note,
+ new_note);
+ if (is_null_sha1(new_note))
+ remove_note(t, object);
+ else
+ add_note(t, object, new_note, combine_notes_overwrite);
+ }
snprintf(logmsg, sizeof(logmsg), "Note %s by 'git notes %s'",
is_null_sha1(new_note) ? "removed" : "added", argv[0]);
commit_notes(t, logmsg);