notes: convert write_notes_tree to object_id
Convert the definition and declaration of write_notes_tree to struct object_id and adjust usage of this function. Additionally, improve style of small part of this function, as old formatting made it hard to understand at glance what this part of code is doing. Signed-off-by: Patryk Obara <patryk.obara@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Patryk Obara committed
Jan 28, 2018 at 01:13 UTC
bbca96d579b31900c9c0ad39299a3c9a3bd276f9
4 files changed
+13
-11
notes-cache.c
+1
-1
@@ -54,7 +54,7 @@ int notes_cache_write(struct notes_cache *c)
54
if (!c->tree.dirty)
55
return 0;
56
57
- if (write_notes_tree(&c->tree, tree_oid.hash))
57
+ if (write_notes_tree(&c->tree, &tree_oid))
58
return -1;
59
if (commit_tree(c->validity, strlen(c->validity), &tree_oid, NULL,
60
&commit_oid, NULL, NULL) < 0)
notes-utils.c
+1
-1
@@ -12,7 +12,7 @@ void create_notes_commit(struct notes_tree *t, struct commit_list *parents,
12
13
assert(t->initialized);
14
15
- if (write_notes_tree(t, tree_oid.hash))
15
+ if (write_notes_tree(t, &tree_oid))
16
die("Failed to write notes tree to database");
17
18
if (!parents) {
notes.c
+9
-7
@@ -1123,11 +1123,12 @@ int for_each_note(struct notes_tree *t, int flags, each_note_fn fn,
1123
return for_each_note_helper(t, t->root, 0, 0, flags, fn, cb_data);
1124
}
1125
1126
-int write_notes_tree(struct notes_tree *t, unsigned char *result)
1126
+int write_notes_tree(struct notes_tree *t, struct object_id *result)
1127
{
1128
struct tree_write_stack root;
1129
struct write_each_note_data cb_data;
1130
int ret;
1131
+ int flags;
1132
1133
if (!t)
1134
t = &default_notes_tree;
@@ -1141,12 +1142,13 @@ int write_notes_tree(struct notes_tree *t, unsigned char *result)
1142
cb_data.next_non_note = t->first_non_note;
1143
1144
/* Write tree objects representing current notes tree */
1144
- ret = for_each_note(t, FOR_EACH_NOTE_DONT_UNPACK_SUBTREES |
1145
- FOR_EACH_NOTE_YIELD_SUBTREES,
1146
- write_each_note, &cb_data) ||
1147
- write_each_non_note_until(NULL, &cb_data) ||
1148
- tree_write_stack_finish_subtree(&root) ||
1149
- write_sha1_file(root.buf.buf, root.buf.len, tree_type, result);
1145
+ flags = FOR_EACH_NOTE_DONT_UNPACK_SUBTREES |
1146
+ FOR_EACH_NOTE_YIELD_SUBTREES;
1147
+ ret = for_each_note(t, flags, write_each_note, &cb_data) ||
1148
+ write_each_non_note_until(NULL, &cb_data) ||
1149
+ tree_write_stack_finish_subtree(&root) ||
1150
+ write_sha1_file(root.buf.buf, root.buf.len, tree_type,
1151
+ result->hash);
1152
strbuf_release(&root.buf);
1153
return ret;
1154
}
notes.h
+2
-2
@@ -217,7 +217,7 @@ int for_each_note(struct notes_tree *t, int flags, each_note_fn fn,
217
* Write the given notes_tree structure to the object database
218
*
219
* Creates a new tree object encapsulating the current state of the given
220
- * notes_tree, and stores its SHA1 into the 'result' argument.
220
+ * notes_tree, and stores its object id into the 'result' argument.
221
*
222
* Returns zero on success, non-zero on failure.
223
*
@@ -225,7 +225,7 @@ int for_each_note(struct notes_tree *t, int flags, each_note_fn fn,
225
* this function has returned zero. Please also remember to create a
226
* corresponding commit object, and update the appropriate notes ref.
227
*/
228
-int write_notes_tree(struct notes_tree *t, unsigned char *result);
228
+int write_notes_tree(struct notes_tree *t, struct object_id *result);
229
230
/* Flags controlling the operation of prune */
231
#define NOTES_PRUNE_VERBOSE 1