return result < 0; /* return non-zero on conflicts */
}
-static int remove_one_note(struct notes_tree *t, const char *name)
+#define IGNORE_MISSING 1
+
+static int remove_one_note(struct notes_tree *t, const char *name, unsigned flag)
{
int status;
unsigned char sha1[20];
fprintf(stderr, _("Object %s has no note\n"), name);
else
fprintf(stderr, _("Removing note for object %s\n"), name);
- return status;
+ return (flag & IGNORE_MISSING) ? 0 : status;
}
static int remove_cmd(int argc, const char **argv, const char *prefix)
{
+ unsigned flag = 0;
+ int from_stdin = 0;
struct option options[] = {
+ OPT_BIT(0, "ignore-missing", &flag,
+ "attempt to remove non-existent note is not an error",
+ IGNORE_MISSING),
+ OPT_BOOLEAN(0, "stdin", &from_stdin,
+ "read object names from the standard input"),
OPT_END()
};
struct notes_tree *t;
t = init_notes_check("remove");
- if (!argc) {
- retval = remove_one_note(t, "HEAD");
+ if (!argc && !from_stdin) {
+ retval = remove_one_note(t, "HEAD", flag);
} else {
while (*argv) {
- retval |= remove_one_note(t, *argv);
+ retval |= remove_one_note(t, *argv, flag);
argv++;
}
}
+ if (from_stdin) {
+ struct strbuf sb = STRBUF_INIT;
+ while (strbuf_getwholeline(&sb, stdin, '\n') != EOF) {
+ strbuf_rtrim(&sb);
+ retval |= remove_one_note(t, sb.buf, flag);
+ }
+ strbuf_release(&sb);
+ }
if (!retval)
commit_notes(t, "Notes removed by 'git notes remove'");
free_notes(t);