Skip to content

Commit 7f710ea

Browse files
trastgitster
authored andcommitted
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 <[email protected]> Acked-by: Johan Herland <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent dcf783a commit 7f710ea

File tree

3 files changed

+6
-0
lines changed

3 files changed

+6
-0
lines changed

builtin-notes.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,8 @@ int commit_notes(struct notes_tree *t, const char *msg)
249249
t = &default_notes_tree;
250250
if (!t->initialized || !t->ref || !*t->ref)
251251
die("Cannot commit uninitialized/unreferenced notes tree");
252+
if (!t->dirty)
253+
return 0; /* don't have to commit an unchanged tree */
252254

253255
/* Prepare commit message and reflog message */
254256
strbuf_addstr(&buf, "notes: "); /* commit message starts at index 7 */

notes.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -933,6 +933,7 @@ void init_notes(struct notes_tree *t, const char *notes_ref,
933933
t->ref = notes_ref ? xstrdup(notes_ref) : NULL;
934934
t->combine_notes = combine_notes;
935935
t->initialized = 1;
936+
t->dirty = 0;
936937

937938
if (flags & NOTES_INIT_EMPTY || !notes_ref ||
938939
read_ref(notes_ref, object_sha1))
@@ -1011,6 +1012,7 @@ void add_note(struct notes_tree *t, const unsigned char *object_sha1,
10111012
if (!t)
10121013
t = &default_notes_tree;
10131014
assert(t->initialized);
1015+
t->dirty = 1;
10141016
if (!combine_notes)
10151017
combine_notes = t->combine_notes;
10161018
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)
10261028
if (!t)
10271029
t = &default_notes_tree;
10281030
assert(t->initialized);
1031+
t->dirty = 1;
10291032
hashcpy(l.key_sha1, object_sha1);
10301033
hashclr(l.val_sha1);
10311034
return note_tree_remove(t, t->root, 0, &l);

notes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ extern struct notes_tree {
4040
char *ref;
4141
combine_notes_fn *combine_notes;
4242
int initialized;
43+
int dirty;
4344
} default_notes_tree;
4445

4546
/*

0 commit comments

Comments
 (0)