summaryrefslogtreecommitdiff
path: root/builtin
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2011-05-18 23:44:30 (GMT)
committerJunio C Hamano <gitster@pobox.com>2011-05-19 17:54:16 (GMT)
commit46538012d943156ead4024fb510a1ce5d4ff443a (patch)
tree8e167868b9e1a252582013f21c556d6a73e9280b /builtin
parent2d370d2fbcf896912cc0739b806224f9a270bb5e (diff)
downloadgit-46538012d943156ead4024fb510a1ce5d4ff443a.zip
git-46538012d943156ead4024fb510a1ce5d4ff443a.tar.gz
git-46538012d943156ead4024fb510a1ce5d4ff443a.tar.bz2
notes remove: --stdin reads from the standard input
Teach the command to read object names to remove from the standard input, in addition to the object names given from the command line. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin')
-rw-r--r--builtin/notes.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/builtin/notes.c b/builtin/notes.c
index 541f776..f8e437d 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -953,7 +953,7 @@ static int merge(int argc, const char **argv, const char *prefix)
return result < 0; /* return non-zero on conflicts */
}
-#define MISSING_OK 1
+#define IGNORE_MISSING 1
static int remove_one_note(struct notes_tree *t, const char *name, unsigned flag)
{
@@ -966,16 +966,19 @@ static int remove_one_note(struct notes_tree *t, const char *name, unsigned flag
fprintf(stderr, _("Object %s has no note\n"), name);
else
fprintf(stderr, _("Removing note for object %s\n"), name);
- return (flag & MISSING_OK) ? 0 : 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",
- MISSING_OK),
+ IGNORE_MISSING),
+ OPT_BOOLEAN(0, "stdin", &from_stdin,
+ "read object names from the standard input"),
OPT_END()
};
struct notes_tree *t;
@@ -986,7 +989,7 @@ static int remove_cmd(int argc, const char **argv, const char *prefix)
t = init_notes_check("remove");
- if (!argc) {
+ if (!argc && !from_stdin) {
retval = remove_one_note(t, "HEAD", flag);
} else {
while (*argv) {
@@ -994,6 +997,14 @@ static int remove_cmd(int argc, const char **argv, const char *prefix)
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);