Skip to content

Commit bbca96d

Browse files
dreamergitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b7d591d commit bbca96d

File tree

4 files changed

+13
-11
lines changed

4 files changed

+13
-11
lines changed

notes-cache.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ int notes_cache_write(struct notes_cache *c)
5454
if (!c->tree.dirty)
5555
return 0;
5656

57-
if (write_notes_tree(&c->tree, tree_oid.hash))
57+
if (write_notes_tree(&c->tree, &tree_oid))
5858
return -1;
5959
if (commit_tree(c->validity, strlen(c->validity), &tree_oid, NULL,
6060
&commit_oid, NULL, NULL) < 0)

notes-utils.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ void create_notes_commit(struct notes_tree *t, struct commit_list *parents,
1212

1313
assert(t->initialized);
1414

15-
if (write_notes_tree(t, tree_oid.hash))
15+
if (write_notes_tree(t, &tree_oid))
1616
die("Failed to write notes tree to database");
1717

1818
if (!parents) {

notes.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,11 +1123,12 @@ int for_each_note(struct notes_tree *t, int flags, each_note_fn fn,
11231123
return for_each_note_helper(t, t->root, 0, 0, flags, fn, cb_data);
11241124
}
11251125

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)
11271127
{
11281128
struct tree_write_stack root;
11291129
struct write_each_note_data cb_data;
11301130
int ret;
1131+
int flags;
11311132

11321133
if (!t)
11331134
t = &default_notes_tree;
@@ -1141,12 +1142,13 @@ int write_notes_tree(struct notes_tree *t, unsigned char *result)
11411142
cb_data.next_non_note = t->first_non_note;
11421143

11431144
/* 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);
11501152
strbuf_release(&root.buf);
11511153
return ret;
11521154
}

notes.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,15 +217,15 @@ int for_each_note(struct notes_tree *t, int flags, each_note_fn fn,
217217
* Write the given notes_tree structure to the object database
218218
*
219219
* 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.
221221
*
222222
* Returns zero on success, non-zero on failure.
223223
*
224224
* IMPORTANT: Changes made to the given notes_tree are not persistent until
225225
* this function has returned zero. Please also remember to create a
226226
* corresponding commit object, and update the appropriate notes ref.
227227
*/
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);
229229

230230
/* Flags controlling the operation of prune */
231231
#define NOTES_PRUNE_VERBOSE 1

0 commit comments

Comments
 (0)