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>
This commit is contained in:
Patryk Obara 2018-01-28 01:13:18 +01:00 committed by Junio C Hamano
parent b7d591d17b
commit bbca96d579
4 changed files with 13 additions and 11 deletions

View File

@ -54,7 +54,7 @@ int notes_cache_write(struct notes_cache *c)
if (!c->tree.dirty)
return 0;
if (write_notes_tree(&c->tree, tree_oid.hash))
if (write_notes_tree(&c->tree, &tree_oid))
return -1;
if (commit_tree(c->validity, strlen(c->validity), &tree_oid, NULL,
&commit_oid, NULL, NULL) < 0)

View File

@ -12,7 +12,7 @@ void create_notes_commit(struct notes_tree *t, struct commit_list *parents,
assert(t->initialized);
if (write_notes_tree(t, tree_oid.hash))
if (write_notes_tree(t, &tree_oid))
die("Failed to write notes tree to database");
if (!parents) {

16
notes.c
View File

@ -1123,11 +1123,12 @@ int for_each_note(struct notes_tree *t, int flags, each_note_fn fn,
return for_each_note_helper(t, t->root, 0, 0, flags, fn, cb_data);
}
int write_notes_tree(struct notes_tree *t, unsigned char *result)
int write_notes_tree(struct notes_tree *t, struct object_id *result)
{
struct tree_write_stack root;
struct write_each_note_data cb_data;
int ret;
int flags;
if (!t)
t = &default_notes_tree;
@ -1141,12 +1142,13 @@ int write_notes_tree(struct notes_tree *t, unsigned char *result)
cb_data.next_non_note = t->first_non_note;
/* Write tree objects representing current notes tree */
ret = for_each_note(t, FOR_EACH_NOTE_DONT_UNPACK_SUBTREES |
FOR_EACH_NOTE_YIELD_SUBTREES,
write_each_note, &cb_data) ||
write_each_non_note_until(NULL, &cb_data) ||
tree_write_stack_finish_subtree(&root) ||
write_sha1_file(root.buf.buf, root.buf.len, tree_type, result);
flags = FOR_EACH_NOTE_DONT_UNPACK_SUBTREES |
FOR_EACH_NOTE_YIELD_SUBTREES;
ret = for_each_note(t, flags, write_each_note, &cb_data) ||
write_each_non_note_until(NULL, &cb_data) ||
tree_write_stack_finish_subtree(&root) ||
write_sha1_file(root.buf.buf, root.buf.len, tree_type,
result->hash);
strbuf_release(&root.buf);
return ret;
}

View File

@ -217,7 +217,7 @@ int for_each_note(struct notes_tree *t, int flags, each_note_fn fn,
* Write the given notes_tree structure to the object database
*
* Creates a new tree object encapsulating the current state of the given
* notes_tree, and stores its SHA1 into the 'result' argument.
* notes_tree, and stores its object id into the 'result' argument.
*
* Returns zero on success, non-zero on failure.
*
@ -225,7 +225,7 @@ int for_each_note(struct notes_tree *t, int flags, each_note_fn fn,
* this function has returned zero. Please also remember to create a
* corresponding commit object, and update the appropriate notes ref.
*/
int write_notes_tree(struct notes_tree *t, unsigned char *result);
int write_notes_tree(struct notes_tree *t, struct object_id *result);
/* Flags controlling the operation of prune */
#define NOTES_PRUNE_VERBOSE 1