From: Johan Herland <johan@herland.net>
To: git@vger.kernel.org
Cc: Stefan Naewe <stefan.naewe@atlas-elektronik.com>
Subject: [PATCH 2/2] notes.h: Extend remove_note to return the SHA1 of the removed note, if any
Date: Tue, 31 Aug 2010 17:59:05 +0200 [thread overview]
Message-ID: <201008311759.05908.johan@herland.net> (raw)
In-Reply-To: <201008311753.37433.johan@herland.net>
It might be useful to identify which note was removed by a call to
remove_note(). Add an optional parameter to remove_note() for recording
the SHA1 of the removed note object. If no note is removed by remove_note(),
null_sha1 is stored in this parameter.
Signed-off-by: Johan Herland <johan@herland.net>
---
This patch is very much optional. It adds a small API extension that
_might_ be useful in the future.
builtin/notes.c | 6 +++---
notes.c | 7 +++++--
notes.h | 6 +++++-
3 files changed, 13 insertions(+), 6 deletions(-)
diff --git a/builtin/notes.c b/builtin/notes.c
index 6d07aac..e5c8208 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -572,7 +572,7 @@ static int add(int argc, const char **argv, const char *prefix)
create_note(object, &msg, 0, note, new_note);
if (is_null_sha1(new_note))
- remove_note(t, object);
+ remove_note(t, object, NULL);
else
add_note(t, object, new_note, combine_notes_overwrite);
@@ -711,7 +711,7 @@ static int append_edit(int argc, const char **argv, const char *prefix)
create_note(object, &msg, !edit, note, new_note);
if (is_null_sha1(new_note))
- remove_note(t, object);
+ remove_note(t, object, NULL);
else
add_note(t, object, new_note, combine_notes_overwrite);
@@ -786,7 +786,7 @@ static int remove_cmd(int argc, const char **argv, const char *prefix)
t = init_notes_check("remove");
- retval = remove_note(t, object);
+ retval = remove_note(t, object, NULL);
if (retval)
fprintf(stderr, "Object %s has no note\n", sha1_to_hex(object));
else {
diff --git a/notes.c b/notes.c
index 70d0013..9fe857b 100644
--- a/notes.c
+++ b/notes.c
@@ -1006,7 +1006,8 @@ void add_note(struct notes_tree *t, const unsigned char *object_sha1,
note_tree_insert(t, t->root, 0, l, PTR_TYPE_NOTE, combine_notes);
}
-int remove_note(struct notes_tree *t, const unsigned char *object_sha1)
+int remove_note(struct notes_tree *t, const unsigned char *object_sha1,
+ unsigned char *removed_note)
{
struct leaf_node l;
@@ -1016,6 +1017,8 @@ int remove_note(struct notes_tree *t, const unsigned char *object_sha1)
hashcpy(l.key_sha1, object_sha1);
hashclr(l.val_sha1);
note_tree_remove(t, t->root, 0, &l);
+ if (removed_note)
+ hashcpy(removed_note, l.val_sha1);
if (is_null_sha1(l.val_sha1)) // no note was removed
return 1;
t->dirty = 1;
@@ -1085,7 +1088,7 @@ void prune_notes(struct notes_tree *t, int flags)
if (flags & NOTES_PRUNE_VERBOSE)
printf("%s\n", sha1_to_hex(l->sha1));
if (!(flags & NOTES_PRUNE_DRYRUN))
- remove_note(t, l->sha1);
+ remove_note(t, l->sha1, NULL);
l = l->next;
}
}
diff --git a/notes.h b/notes.h
index 5106761..c61e962 100644
--- a/notes.h
+++ b/notes.h
@@ -90,9 +90,13 @@ void add_note(struct notes_tree *t, const unsigned char *object_sha1,
* structure are not persistent until a subsequent call to write_notes_tree()
* returns zero.
*
+ * If removed_note is non-NULL, the SHA1 of the removed note will be written
+ * there. If there was no note to remove, then null_sha1 will be written there.
+ *
* Return 0 if a note was removed; 1 if there was no note to remove.
*/
-int remove_note(struct notes_tree *t, const unsigned char *object_sha1);
+int remove_note(struct notes_tree *t, const unsigned char *object_sha1,
+ unsigned char *removed_note);
/*
* Get the note object SHA1 containing the note data for the given object
--
1.7.2.220.gea1d3
prev parent reply other threads:[~2010-08-31 15:59 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-08-31 8:09 Q. about usage of notes Stefan Naewe
2010-08-31 9:07 ` Johan Herland
2010-08-31 10:13 ` Stefan Naewe
2010-08-31 10:15 ` Stefan Naewe
2010-08-31 15:16 ` [RFC] notes: avoid recommitting identical trees Michael J Gruber
2010-08-31 16:01 ` Jeff King
2010-08-31 16:15 ` Michael J Gruber
2010-08-31 16:44 ` Junio C Hamano
2010-08-31 18:26 ` Michael J Gruber
2010-08-31 18:29 ` Jeff King
2010-08-31 18:45 ` Michael J Gruber
2010-08-31 18:43 ` Junio C Hamano
2010-08-31 16:08 ` Johan Herland
2010-08-31 15:53 ` Q. about usage of notes Johan Herland
2010-08-31 15:56 ` [PATCH 1/2] notes: Don't create (empty) commit when removing non-existing notes Johan Herland
2010-08-31 15:59 ` Johan Herland [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=201008311759.05908.johan@herland.net \
--to=johan@herland.net \
--cc=git@vger.kernel.org \
--cc=stefan.naewe@atlas-elektronik.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).