Skip to content

Commit bf9a05b

Browse files
jherlandgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 49c2470 commit bf9a05b

File tree

4 files changed

+41
-41
lines changed

4 files changed

+41
-41
lines changed

notes-merge.c

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "notes.h"
1010
#include "notes-merge.h"
1111
#include "strbuf.h"
12+
#include "notes-utils.h"
1213

1314
struct notes_merge_pair {
1415
unsigned char obj[20], base[20], local[20], remote[20];
@@ -530,32 +531,6 @@ static int merge_from_diffs(struct notes_merge_options *o,
530531
return conflicts ? -1 : 1;
531532
}
532533

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-
559534
int notes_merge(struct notes_merge_options *o,
560535
struct notes_tree *local_tree,
561536
unsigned char *result_sha1)

notes-merge.h

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,6 @@ struct notes_merge_options {
2525

2626
void init_notes_merge_options(struct notes_merge_options *o);
2727

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-
4228
/*
4329
* Merge notes from o->remote_ref into o->local_ref
4430
*

notes-utils.c

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,32 @@
22
#include "commit.h"
33
#include "refs.h"
44
#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+
}
631

732
void commit_notes(struct notes_tree *t, const char *msg)
833
{

notes-utils.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,20 @@
33

44
#include "notes.h"
55

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+
620
void commit_notes(struct notes_tree *t, const char *msg);
721

822
struct notes_rewrite_cfg {

0 commit comments

Comments
 (0)