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 <johan@herland.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Johan Herland committed
Jun 12, 2013 at 02:13 UTC
bf9a05ba46a9d464424d22482aaa54abdd28b77d
4 files changed
+41
-41
notes-merge.c
+1
-26
@@ -9,6 +9,7 @@
9
#include "notes.h"
10
#include "notes-merge.h"
11
#include "strbuf.h"
12
+#include "notes-utils.h"
13
14
struct notes_merge_pair {
15
unsigned char obj[20], base[20], local[20], remote[20];
@@ -530,32 +531,6 @@ static int merge_from_diffs(struct notes_merge_options *o,
531
return conflicts ? -1 : 1;
532
}
533
533
-void create_notes_commit(struct notes_tree *t, struct commit_list *parents,
534
- const struct strbuf *msg, unsigned char *result_sha1)
535
-{
536
- unsigned char tree_sha1[20];
537
-
538
- assert(t->initialized);
539
-
540
- if (write_notes_tree(t, tree_sha1))
541
- die("Failed to write notes tree to database");
542
-
543
- if (!parents) {
544
- /* Deduce parent commit from t->ref */
545
- unsigned char parent_sha1[20];
546
- if (!read_ref(t->ref, parent_sha1)) {
547
- struct commit *parent = lookup_commit(parent_sha1);
548
- if (!parent || parse_commit(parent))
549
- die("Failed to find/parse commit %s", t->ref);
550
- commit_list_insert(parent, &parents);
551
- }
552
- /* else: t->ref points to nothing, assume root/orphan commit */
553
- }
554
-
555
- if (commit_tree(msg, tree_sha1, parents, result_sha1, NULL, NULL))
556
- die("Failed to commit notes tree to database");
557
-}
558
-
534
int notes_merge(struct notes_merge_options *o,
535
struct notes_tree *local_tree,
536
unsigned char *result_sha1)
notes-merge.h
-14
@@ -25,20 +25,6 @@ struct notes_merge_options {
25
26
void init_notes_merge_options(struct notes_merge_options *o);
27
28
-/*
29
- * Create new notes commit from the given notes tree
30
- *
31
- * Properties of the created commit:
32
- * - tree: the result of converting t to a tree object with write_notes_tree().
33
- * - parents: the given parents OR (if NULL) the commit referenced by t->ref.
34
- * - author/committer: the default determined by commmit_tree().
35
- * - commit message: msg
36
- *
37
- * The resulting commit SHA1 is stored in result_sha1.
38
- */
39
-void create_notes_commit(struct notes_tree *t, struct commit_list *parents,
40
- const struct strbuf *msg, unsigned char *result_sha1);
41
-
28
/*
29
* Merge notes from o->remote_ref into o->local_ref
30
*
notes-utils.c
+26
-1
@@ -2,7 +2,32 @@
2
#include "commit.h"
3
#include "refs.h"
4
#include "notes-utils.h"
5
-#include "notes-merge.h" /* for create_notes_commit() */
5
+
6
+void create_notes_commit(struct notes_tree *t, struct commit_list *parents,
7
+ const struct strbuf *msg, unsigned char *result_sha1)
8
+{
9
+ unsigned char tree_sha1[20];
10
+
11
+ assert(t->initialized);
12
+
13
+ if (write_notes_tree(t, tree_sha1))
14
+ die("Failed to write notes tree to database");
15
+
16
+ if (!parents) {
17
+ /* Deduce parent commit from t->ref */
18
+ unsigned char parent_sha1[20];
19
+ if (!read_ref(t->ref, parent_sha1)) {
20
+ struct commit *parent = lookup_commit(parent_sha1);
21
+ if (!parent || parse_commit(parent))
22
+ die("Failed to find/parse commit %s", t->ref);
23
+ commit_list_insert(parent, &parents);
24
+ }
25
+ /* else: t->ref points to nothing, assume root/orphan commit */
26
+ }
27
+
28
+ if (commit_tree(msg, tree_sha1, parents, result_sha1, NULL, NULL))
29
+ die("Failed to commit notes tree to database");
30
+}
31
32
void commit_notes(struct notes_tree *t, const char *msg)
33
{
notes-utils.h
+14
@@ -3,6 +3,20 @@
3
4
#include "notes.h"
5
6
+/*
7
+ * Create new notes commit from the given notes tree
8
+ *
9
+ * Properties of the created commit:
10
+ * - tree: the result of converting t to a tree object with write_notes_tree().
11
+ * - parents: the given parents OR (if NULL) the commit referenced by t->ref.
12
+ * - author/committer: the default determined by commmit_tree().
13
+ * - commit message: msg
14
+ *
15
+ * The resulting commit SHA1 is stored in result_sha1.
16
+ */
17
+void create_notes_commit(struct notes_tree *t, struct commit_list *parents,
18
+ const struct strbuf *msg, unsigned char *result_sha1);
19
+
20
void commit_notes(struct notes_tree *t, const char *msg);
21
22
struct notes_rewrite_cfg {