summaryrefslogtreecommitdiff
path: root/builtin-notes.c
diff options
context:
space:
mode:
authorLibravatar Johan Herland <johan@herland.net>2010-02-13 22:28:24 +0100
committerLibravatar Junio C Hamano <gitster@pobox.com>2010-02-13 19:36:14 -0800
commita0b4dfa9b35a2ebac578ea5547b041bb78557238 (patch)
tree13c126a0b799f0251e9669dd25afa31b374e01aa /builtin-notes.c
parentTeach notes code to properly preserve non-notes in the notes tree (diff)
downloadtgif-a0b4dfa9b35a2ebac578ea5547b041bb78557238.tar.xz
Teach builtin-notes to remove empty notes
When the result of editing a note is an empty string, the associated note entry should be deleted from the notes tree. This allows deleting notes by invoking either "git notes -m ''" or "git notes -F /dev/null". 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.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/builtin-notes.c b/builtin-notes.c
index 89aa6e072e..7b4cb1367e 100644
--- a/builtin-notes.c
+++ b/builtin-notes.c
@@ -113,7 +113,7 @@ static void create_note(const unsigned char *object,
stripspace(buf, 1);
- if (!skip_editor && !buf->len) {
+ if (!buf->len) {
fprintf(stderr, "Removing note for object %s\n",
sha1_to_hex(object));
hashclr(result);
@@ -197,7 +197,8 @@ int cmd_notes(int argc, const char **argv, const char *prefix)
struct notes_tree *t;
unsigned char object[20], new_note[20];
const unsigned char *note;
- const char *object_ref;
+ const char *object_ref, *logmsg;
+
int edit = 0, show = 0;
const char *msgfile = NULL;
struct msg_arg msg = { 0, STRBUF_INIT };
@@ -271,8 +272,14 @@ int cmd_notes(int argc, const char **argv, const char *prefix)
}
create_note(object, &buf, msg.given || msgfile, note, new_note);
- add_note(t, object, new_note, combine_notes_overwrite);
- commit_notes(t, "Note added by 'git notes edit'");
+ if (is_null_sha1(new_note)) {
+ remove_note(t, object);
+ logmsg = "Note removed by 'git notes edit'";
+ } else {
+ add_note(t, object, new_note, combine_notes_overwrite);
+ logmsg = "Note added by 'git notes edit'";
+ }
+ commit_notes(t, logmsg);
free_notes(t);
strbuf_release(&buf);