@matheusbsbs / matheus-bagliano / commits / 7f710ea982
Fork 0

notes: track whether notes_trees were changed at all

Currently, the notes copying is a bit wasteful since it always creates new trees, even if no notes were copied at all. Teach add_note() and remove_note() to flag the affected notes tree as changed ('dirty'). Then teach builtin/notes.c to use this knowledge and avoid committing trees that weren't changed. Signed-off-by: Thomas Rast <trast@student.ethz.ch> Acked-by: Johan Herland <johan@herland.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Thomas Rast committed Mar 12, 2010 at 18:04 UTC 7f710ea98262c7d81006c16c727796d9e6aeaa81
3 files changed +6
builtin-notes.c
+2
@@ -249,6 +249,8 @@ int commit_notes(struct notes_tree *t, const char *msg)
249 t = &default_notes_tree;
250 if (!t->initialized || !t->ref || !*t->ref)
251 die("Cannot commit uninitialized/unreferenced notes tree");
252 + if (!t->dirty)
253 + return 0; /* don't have to commit an unchanged tree */
254
255 /* Prepare commit message and reflog message */
256 strbuf_addstr(&buf, "notes: "); /* commit message starts at index 7 */
notes.c
+3
@@ -933,6 +933,7 @@ void init_notes(struct notes_tree *t, const char *notes_ref,
933 t->ref = notes_ref ? xstrdup(notes_ref) : NULL;
934 t->combine_notes = combine_notes;
935 t->initialized = 1;
936 + t->dirty = 0;
937
938 if (flags & NOTES_INIT_EMPTY || !notes_ref ||
939 read_ref(notes_ref, object_sha1))
@@ -1011,6 +1012,7 @@ void add_note(struct notes_tree *t, const unsigned char *object_sha1,
1012 if (!t)
1013 t = &default_notes_tree;
1014 assert(t->initialized);
1015 + t->dirty = 1;
1016 if (!combine_notes)
1017 combine_notes = t->combine_notes;
1018 l = (struct leaf_node *) xmalloc(sizeof(struct leaf_node));
@@ -1026,6 +1028,7 @@ void remove_note(struct notes_tree *t, const unsigned char *object_sha1)
1028 if (!t)
1029 t = &default_notes_tree;
1030 assert(t->initialized);
1031 + t->dirty = 1;
1032 hashcpy(l.key_sha1, object_sha1);
1033 hashclr(l.val_sha1);
1034 return note_tree_remove(t, t->root, 0, &l);
notes.h
+1
@@ -40,6 +40,7 @@ extern struct notes_tree {
40 char *ref;
41 combine_notes_fn *combine_notes;
42 int initialized;
43 + int dirty;
44 } default_notes_tree;
45
46 /*