summaryrefslogtreecommitdiff
path: root/notes-merge.c
diff options
context:
space:
mode:
authorJohan Herland <johan@herland.net>2010-11-09 22:49:47 +0100
committerJunio C Hamano <gitster@pobox.com>2010-11-17 13:21:30 -0800
commit56881843d4d916a166ac4c6ba1803e5ceba9c44d (patch)
treee0f9edaaaf032fb9998953dcc9ada0eb6bc738ec /notes-merge.c
parent75ef3f4a5cc69b21bc825ed0e739030d77a4f077 (diff)
downloadgit-56881843d4d916a166ac4c6ba1803e5ceba9c44d.tar.gz
builtin/notes.c: Refactor creation of notes commits.
Create new function create_notes_commit() which is slightly more general than commit_notes() (accepts multiple commit parents and does not auto-update the notes ref). This function will be used by the notes-merge functionality in future patches. Also rewrite builtin/notes.c:commit_notes() to reuse this new function. Signed-off-by: Johan Herland <johan@herland.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'notes-merge.c')
-rw-r--r--notes-merge.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/notes-merge.c b/notes-merge.c
index ab9885039e..b9956c3bf3 100644
--- a/notes-merge.c
+++ b/notes-merge.c
@@ -1,6 +1,7 @@
#include "cache.h"
#include "commit.h"
#include "refs.h"
+#include "notes.h"
#include "notes-merge.h"
void init_notes_merge_options(struct notes_merge_options *o)
@@ -17,6 +18,32 @@ void init_notes_merge_options(struct notes_merge_options *o)
} \
} while (0)
+void create_notes_commit(struct notes_tree *t, struct commit_list *parents,
+ const char *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))
+ die("Failed to commit notes tree to database");
+}
+
int notes_merge(struct notes_merge_options *o,
unsigned char *result_sha1)
{