Skip to content

Commit 5078f34

Browse files
dreamergitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3b34934 commit 5078f34

File tree

10 files changed

+36
-34
lines changed

10 files changed

+36
-34
lines changed

builtin/am.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1641,8 +1641,8 @@ static void do_commit(const struct am_state *state)
16411641
setenv("GIT_COMMITTER_DATE",
16421642
state->ignore_date ? "" : state->author_date, 1);
16431643

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))
16461646
die(_("failed to write commit object"));
16471647

16481648
reflog_msg = getenv("GIT_REFLOG_ACTION");

builtin/commit-tree.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix)
117117
die_errno("git commit-tree: failed to read");
118118
}
119119

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)) {
122122
strbuf_release(&buffer);
123123
return 1;
124124
}

builtin/commit.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1794,8 +1794,9 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
17941794
append_merge_tag_headers(parents, &tail);
17951795
}
17961796

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)) {
17991800
rollback_index_files();
18001801
die(_("failed to write commit object"));
18011802
}

builtin/merge.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -820,8 +820,8 @@ static int merge_trivial(struct commit *head, struct commit_list *remoteheads)
820820
pptr = commit_list_append(head, pptr);
821821
pptr = commit_list_append(remoteheads->item, pptr);
822822
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))
825825
die(_("failed to write commit object"));
826826
finish(head, remoteheads, &result_commit, "In-index merge");
827827
drop_save();
@@ -845,8 +845,8 @@ static int finish_automerge(struct commit *head,
845845
commit_list_insert(head, &parents);
846846
strbuf_addch(&merge_msg, '\n');
847847
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))
850850
die(_("failed to write commit object"));
851851
strbuf_addf(&buf, "Merge made by the '%s' strategy.", wt_strategy);
852852
finish(head, remoteheads, &result_commit, buf.buf);

commit.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1380,9 +1380,8 @@ void free_commit_extra_headers(struct commit_extra_header *extra)
13801380
}
13811381
}
13821382

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,
13861385
const char *author, const char *sign_commit)
13871386
{
13881387
struct commit_extra_header *extra = NULL, **tail = &extra;
@@ -1511,16 +1510,16 @@ N_("Warning: commit message did not conform to UTF-8.\n"
15111510
"variable i18n.commitencoding to the encoding your project uses.\n");
15121511

15131512
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,
15161515
const char *author, const char *sign_commit,
15171516
struct commit_extra_header *extra)
15181517
{
15191518
int result;
15201519
int encoding_is_utf8;
15211520
struct strbuf buffer;
15221521

1523-
assert_sha1_type(tree, OBJ_TREE);
1522+
assert_sha1_type(tree->hash, OBJ_TREE);
15241523

15251524
if (memchr(msg, '\0', msg_len))
15261525
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,
15291528
encoding_is_utf8 = is_encoding_utf8(git_commit_encoding);
15301529

15311530
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));
15331532

15341533
/*
15351534
* 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,
15681567
goto out;
15691568
}
15701569

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);
15721571
out:
15731572
strbuf_release(&buffer);
15741573
return result;

commit.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -262,14 +262,15 @@ extern void append_merge_tag_headers(struct commit_list *parents,
262262
struct commit_extra_header ***tail);
263263

264264
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,
267267
const char *author, const char *sign_commit);
268268

269269
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,
273274
struct commit_extra_header *);
274275

275276
extern struct commit_extra_header *read_commit_extra_headers(struct commit *, const char **);

notes-cache.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ int notes_cache_write(struct notes_cache *c)
5656

5757
if (write_notes_tree(&c->tree, tree_oid.hash))
5858
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)
6161
return -1;
6262
if (update_ref("update notes cache", c->tree.update_ref, &commit_oid,
6363
NULL, 0, UPDATE_REFS_QUIET_ON_ERR) < 0)

notes-merge.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -642,9 +642,8 @@ int notes_merge(struct notes_merge_options *o,
642642
struct commit_list *parents = NULL;
643643
commit_list_insert(remote, &parents); /* LIFO order */
644644
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);
648647
}
649648

650649
found_result:
@@ -718,8 +717,8 @@ int notes_merge_commit(struct notes_merge_options *o,
718717
strbuf_setlen(&path, baselen);
719718
}
720719

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);
723722
unuse_commit_buffer(partial_commit, buffer);
724723
if (o->verbosity >= 4)
725724
printf("Finalized notes merge commit: %s\n",

notes-utils.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
void create_notes_commit(struct notes_tree *t, struct commit_list *parents,
88
const char *msg, size_t msg_len,
9-
unsigned char *result_sha1)
9+
struct object_id *result_oid)
1010
{
1111
struct object_id tree_oid;
1212

@@ -27,7 +27,8 @@ void create_notes_commit(struct notes_tree *t, struct commit_list *parents,
2727
/* else: t->ref points to nothing, assume root/orphan commit */
2828
}
2929

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))
3132
die("Failed to commit notes tree to database");
3233
}
3334

@@ -47,7 +48,7 @@ void commit_notes(struct notes_tree *t, const char *msg)
4748
strbuf_addstr(&buf, msg);
4849
strbuf_complete_line(&buf);
4950

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);
5152
strbuf_insert(&buf, 0, "notes: ", 7); /* commit message starts at index 7 */
5253
update_ref(buf.buf, t->update_ref, &commit_oid, NULL, 0,
5354
UPDATE_REFS_DIE_ON_ERR);

notes-utils.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
* The resulting commit SHA1 is stored in result_sha1.
1616
*/
1717
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);
1920

2021
void commit_notes(struct notes_tree *t, const char *msg);
2122

0 commit comments

Comments
 (0)