commit: convert commit_tree* to object_id
Convert the definitions and declarations of commit_tree and commit_tree_extended to use struct object_id and adjust all usages of these functions. Signed-off-by: Patryk Obara <patryk.obara@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Patryk Obara committed
Jan 28, 2018 at 01:13 UTC
5078f344591ee3c454e64ff73e6563f0a3f14950
10 files changed
+36
-34
builtin/am.c
+2
-2
@@ -1641,8 +1641,8 @@ static void do_commit(const struct am_state *state)
1641
setenv("GIT_COMMITTER_DATE",
1642
state->ignore_date ? "" : state->author_date, 1);
1643
1644
- if (commit_tree(state->msg, state->msg_len, tree.hash, parents, commit.hash,
1645
- author, state->sign_commit))
1644
+ if (commit_tree(state->msg, state->msg_len, &tree, parents, &commit,
1645
+ author, state->sign_commit))
1646
die(_("failed to write commit object"));
1647
1648
reflog_msg = getenv("GIT_REFLOG_ACTION");
builtin/commit-tree.c
+2
-2
@@ -117,8 +117,8 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix)
117
die_errno("git commit-tree: failed to read");
118
}
119
120
- if (commit_tree(buffer.buf, buffer.len, tree_oid.hash, parents,
121
- commit_oid.hash, NULL, sign_commit)) {
120
+ if (commit_tree(buffer.buf, buffer.len, &tree_oid, parents, &commit_oid,
121
+ NULL, sign_commit)) {
122
strbuf_release(&buffer);
123
return 1;
124
}
builtin/commit.c
+3
-2
@@ -1794,8 +1794,9 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
1794
append_merge_tag_headers(parents, &tail);
1795
}
1796
1797
- if (commit_tree_extended(sb.buf, sb.len, active_cache_tree->oid.hash,
1798
- parents, oid.hash, author_ident.buf, sign_commit, extra)) {
1797
+ if (commit_tree_extended(sb.buf, sb.len, &active_cache_tree->oid,
1798
+ parents, &oid, author_ident.buf, sign_commit,
1799
+ extra)) {
1800
rollback_index_files();
1801
die(_("failed to write commit object"));
1802
}
builtin/merge.c
+4
-4
@@ -820,8 +820,8 @@ static int merge_trivial(struct commit *head, struct commit_list *remoteheads)
820
pptr = commit_list_append(head, pptr);
821
pptr = commit_list_append(remoteheads->item, pptr);
822
prepare_to_commit(remoteheads);
823
- if (commit_tree(merge_msg.buf, merge_msg.len, result_tree.hash, parents,
824
- result_commit.hash, NULL, sign_commit))
823
+ if (commit_tree(merge_msg.buf, merge_msg.len, &result_tree, parents,
824
+ &result_commit, NULL, sign_commit))
825
die(_("failed to write commit object"));
826
finish(head, remoteheads, &result_commit, "In-index merge");
827
drop_save();
@@ -845,8 +845,8 @@ static int finish_automerge(struct commit *head,
845
commit_list_insert(head, &parents);
846
strbuf_addch(&merge_msg, '\n');
847
prepare_to_commit(remoteheads);
848
- if (commit_tree(merge_msg.buf, merge_msg.len, result_tree->hash, parents,
849
- result_commit.hash, NULL, sign_commit))
848
+ if (commit_tree(merge_msg.buf, merge_msg.len, result_tree, parents,
849
+ &result_commit, NULL, sign_commit))
850
die(_("failed to write commit object"));
851
strbuf_addf(&buf, "Merge made by the '%s' strategy.", wt_strategy);
852
finish(head, remoteheads, &result_commit, buf.buf);
commit.c
+7
-8
@@ -1380,9 +1380,8 @@ void free_commit_extra_headers(struct commit_extra_header *extra)
1380
}
1381
}
1382
1383
-int commit_tree(const char *msg, size_t msg_len,
1384
- const unsigned char *tree,
1385
- struct commit_list *parents, unsigned char *ret,
1383
+int commit_tree(const char *msg, size_t msg_len, const struct object_id *tree,
1384
+ struct commit_list *parents, struct object_id *ret,
1385
const char *author, const char *sign_commit)
1386
{
1387
struct commit_extra_header *extra = NULL, **tail = &extra;
@@ -1511,8 +1510,8 @@ N_("Warning: commit message did not conform to UTF-8.\n"
1510
"variable i18n.commitencoding to the encoding your project uses.\n");
1511
1512
int commit_tree_extended(const char *msg, size_t msg_len,
1514
- const unsigned char *tree,
1515
- struct commit_list *parents, unsigned char *ret,
1513
+ const struct object_id *tree,
1514
+ struct commit_list *parents, struct object_id *ret,
1515
const char *author, const char *sign_commit,
1516
struct commit_extra_header *extra)
1517
{
@@ -1520,7 +1519,7 @@ int commit_tree_extended(const char *msg, size_t msg_len,
1519
int encoding_is_utf8;
1520
struct strbuf buffer;
1521
1523
- assert_sha1_type(tree, OBJ_TREE);
1522
+ assert_sha1_type(tree->hash, OBJ_TREE);
1523
1524
if (memchr(msg, '\0', msg_len))
1525
return error("a NUL byte in commit log message not allowed.");
@@ -1529,7 +1528,7 @@ int commit_tree_extended(const char *msg, size_t msg_len,
1528
encoding_is_utf8 = is_encoding_utf8(git_commit_encoding);
1529
1530
strbuf_init(&buffer, 8192); /* should avoid reallocs for the headers */
1532
- strbuf_addf(&buffer, "tree %s\n", sha1_to_hex(tree));
1531
+ strbuf_addf(&buffer, "tree %s\n", oid_to_hex(tree));
1532
1533
/*
1534
* NOTE! This ordering means that the same exact tree merged with a
@@ -1568,7 +1567,7 @@ int commit_tree_extended(const char *msg, size_t msg_len,
1567
goto out;
1568
}
1569
1571
- result = write_sha1_file(buffer.buf, buffer.len, commit_type, ret);
1570
+ result = write_sha1_file(buffer.buf, buffer.len, commit_type, ret->hash);
1571
out:
1572
strbuf_release(&buffer);
1573
return result;
commit.h
+6
-5
@@ -262,14 +262,15 @@ extern void append_merge_tag_headers(struct commit_list *parents,
262
struct commit_extra_header ***tail);
263
264
extern int commit_tree(const char *msg, size_t msg_len,
265
- const unsigned char *tree,
266
- struct commit_list *parents, unsigned char *ret,
265
+ const struct object_id *tree,
266
+ struct commit_list *parents, struct object_id *ret,
267
const char *author, const char *sign_commit);
268
269
extern int commit_tree_extended(const char *msg, size_t msg_len,
270
- const unsigned char *tree,
271
- struct commit_list *parents, unsigned char *ret,
272
- const char *author, const char *sign_commit,
270
+ const struct object_id *tree,
271
+ struct commit_list *parents,
272
+ struct object_id *ret, const char *author,
273
+ const char *sign_commit,
274
struct commit_extra_header *);
275
276
extern struct commit_extra_header *read_commit_extra_headers(struct commit *, const char **);
notes-cache.c
+2
-2
@@ -56,8 +56,8 @@ int notes_cache_write(struct notes_cache *c)
56
57
if (write_notes_tree(&c->tree, tree_oid.hash))
58
return -1;
59
- if (commit_tree(c->validity, strlen(c->validity), tree_oid.hash, NULL,
60
- commit_oid.hash, NULL, NULL) < 0)
59
+ if (commit_tree(c->validity, strlen(c->validity), &tree_oid, NULL,
60
+ &commit_oid, NULL, NULL) < 0)
61
return -1;
62
if (update_ref("update notes cache", c->tree.update_ref, &commit_oid,
63
NULL, 0, UPDATE_REFS_QUIET_ON_ERR) < 0)
notes-merge.c
+4
-5
@@ -642,9 +642,8 @@ int notes_merge(struct notes_merge_options *o,
642
struct commit_list *parents = NULL;
643
commit_list_insert(remote, &parents); /* LIFO order */
644
commit_list_insert(local, &parents);
645
- create_notes_commit(local_tree, parents,
646
- o->commit_msg.buf, o->commit_msg.len,
647
- result_oid->hash);
645
+ create_notes_commit(local_tree, parents, o->commit_msg.buf,
646
+ o->commit_msg.len, result_oid);
647
}
648
649
found_result:
@@ -718,8 +717,8 @@ int notes_merge_commit(struct notes_merge_options *o,
717
strbuf_setlen(&path, baselen);
718
}
719
721
- create_notes_commit(partial_tree, partial_commit->parents,
722
- msg, strlen(msg), result_oid->hash);
720
+ create_notes_commit(partial_tree, partial_commit->parents, msg,
721
+ strlen(msg), result_oid);
722
unuse_commit_buffer(partial_commit, buffer);
723
if (o->verbosity >= 4)
724
printf("Finalized notes merge commit: %s\n",
notes-utils.c
+4
-3
@@ -6,7 +6,7 @@
6
7
void create_notes_commit(struct notes_tree *t, struct commit_list *parents,
8
const char *msg, size_t msg_len,
9
- unsigned char *result_sha1)
9
+ struct object_id *result_oid)
10
{
11
struct object_id tree_oid;
12
@@ -27,7 +27,8 @@ void create_notes_commit(struct notes_tree *t, struct commit_list *parents,
27
/* else: t->ref points to nothing, assume root/orphan commit */
28
}
29
30
- if (commit_tree(msg, msg_len, tree_oid.hash, parents, result_sha1, NULL, NULL))
30
+ if (commit_tree(msg, msg_len, &tree_oid, parents, result_oid, NULL,
31
+ NULL))
32
die("Failed to commit notes tree to database");
33
}
34
@@ -47,7 +48,7 @@ void commit_notes(struct notes_tree *t, const char *msg)
48
strbuf_addstr(&buf, msg);
49
strbuf_complete_line(&buf);
50
50
- create_notes_commit(t, NULL, buf.buf, buf.len, commit_oid.hash);
51
+ create_notes_commit(t, NULL, buf.buf, buf.len, &commit_oid);
52
strbuf_insert(&buf, 0, "notes: ", 7); /* commit message starts at index 7 */
53
update_ref(buf.buf, t->update_ref, &commit_oid, NULL, 0,
54
UPDATE_REFS_DIE_ON_ERR);
notes-utils.h
+2
-1
@@ -15,7 +15,8 @@
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 char *msg, size_t msg_len, unsigned char *result_sha1);
18
+ const char *msg, size_t msg_len,
19
+ struct object_id *result_oid);
20
21
void commit_notes(struct notes_tree *t, const char *msg);
22