Notes API: get_note(): Return the note annotating the given object
Created by a simple cleanup and rename of lookup_notes(). Signed-off-by: Johan Herland <johan@herland.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Johan Herland committed
Feb 13, 2010 at 22:28 UTC
9b391f218a5b732a5a8abae87d3165e97fe2f6f6
2 files changed
+15
-7
notes.c
+8
-7
@@ -462,12 +462,13 @@ void remove_note(const unsigned char *object_sha1)
462
return note_tree_remove(&root_node, 0, &l);
463
}
464
465
-static unsigned char *lookup_notes(const unsigned char *object_sha1)
465
+const unsigned char *get_note(const unsigned char *object_sha1)
466
{
467
- struct leaf_node *found = note_tree_find(&root_node, 0, object_sha1);
468
- if (found)
469
- return found->val_sha1;
470
- return NULL;
467
+ struct leaf_node *found;
468
+
469
+ assert(initialized);
470
+ found = note_tree_find(&root_node, 0, object_sha1);
471
+ return found ? found->val_sha1 : NULL;
472
}
473
474
void free_notes(void)
@@ -481,7 +482,7 @@ void format_note(const unsigned char *object_sha1, struct strbuf *sb,
482
const char *output_encoding, int flags)
483
{
484
static const char utf8[] = "utf-8";
484
- unsigned char *sha1;
485
+ const unsigned char *sha1;
486
char *msg, *msg_p;
487
unsigned long linelen, msglen;
488
enum object_type type;
@@ -489,7 +490,7 @@ void format_note(const unsigned char *object_sha1, struct strbuf *sb,
490
if (!initialized)
491
init_notes(NULL, 0);
492
492
- sha1 = lookup_notes(object_sha1);
493
+ sha1 = get_note(object_sha1);
494
if (!sha1)
495
return;
496
notes.h
+7
@@ -28,6 +28,13 @@ void add_note(const unsigned char *object_sha1,
28
/* Remove the given note object from the internal notes tree structure */
29
void remove_note(const unsigned char *object_sha1);
30
31
+/*
32
+ * Get the note object SHA1 containing the note data for the given object
33
+ *
34
+ * Return NULL if the given object has no notes.
35
+ */
36
+const unsigned char *get_note(const unsigned char *object_sha1);
37
+
38
/* Free (and de-initialize) the internal notes tree structure */
39
void free_notes(void);
40