From bf9a05ba46a9d464424d22482aaa54abdd28b77d Mon Sep 17 00:00:00 2001 From: Johan Herland Date: Wed, 12 Jun 2013 02:13:01 +0200 Subject: Move create_notes_commit() from notes-merge.c into notes-utils.c create_notes_commit() is needed by both the notes-merge code, and by commit_notes() in notes-utils. Since it is generally useful, and not bound to the notes-merge machinery, we move it from (the more specific) notes-merge to (the more general) notes-utils. Signed-off-by: Johan Herland Signed-off-by: Junio C Hamano --- notes-utils.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'notes-utils.c') diff --git a/notes-utils.c b/notes-utils.c index 5c9c976b80..9107c379d9 100644 --- a/notes-utils.c +++ b/notes-utils.c @@ -2,7 +2,32 @@ #include "commit.h" #include "refs.h" #include "notes-utils.h" -#include "notes-merge.h" /* for create_notes_commit() */ + +void create_notes_commit(struct notes_tree *t, struct commit_list *parents, + const struct strbuf *msg, unsigned char *result_sha1) +{ + unsigned char tree_sha1[20]; + + assert(t->initialized); + + if (write_notes_tree(t, tree_sha1)) + die("Failed to write notes tree to database"); + + if (!parents) { + /* Deduce parent commit from t->ref */ + unsigned char parent_sha1[20]; + if (!read_ref(t->ref, parent_sha1)) { + struct commit *parent = lookup_commit(parent_sha1); + if (!parent || parse_commit(parent)) + die("Failed to find/parse commit %s", t->ref); + commit_list_insert(parent, &parents); + } + /* else: t->ref points to nothing, assume root/orphan commit */ + } + + if (commit_tree(msg, tree_sha1, parents, result_sha1, NULL, NULL)) + die("Failed to commit notes tree to database"); +} void commit_notes(struct notes_tree *t, const char *msg) { -- cgit v1.2.3