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>
This commit is contained in:
Patryk Obara 2018-01-28 01:13:16 +01:00 committed by Junio C Hamano
parent 3b34934dca
commit 5078f34459
10 changed files with 36 additions and 34 deletions

View File

@ -1641,8 +1641,8 @@ static void do_commit(const struct am_state *state)
setenv("GIT_COMMITTER_DATE", setenv("GIT_COMMITTER_DATE",
state->ignore_date ? "" : state->author_date, 1); state->ignore_date ? "" : state->author_date, 1);
if (commit_tree(state->msg, state->msg_len, tree.hash, parents, commit.hash, if (commit_tree(state->msg, state->msg_len, &tree, parents, &commit,
author, state->sign_commit)) author, state->sign_commit))
die(_("failed to write commit object")); die(_("failed to write commit object"));
reflog_msg = getenv("GIT_REFLOG_ACTION"); reflog_msg = getenv("GIT_REFLOG_ACTION");

View File

@ -117,8 +117,8 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix)
die_errno("git commit-tree: failed to read"); die_errno("git commit-tree: failed to read");
} }
if (commit_tree(buffer.buf, buffer.len, tree_oid.hash, parents, if (commit_tree(buffer.buf, buffer.len, &tree_oid, parents, &commit_oid,
commit_oid.hash, NULL, sign_commit)) { NULL, sign_commit)) {
strbuf_release(&buffer); strbuf_release(&buffer);
return 1; return 1;
} }

View File

@ -1794,8 +1794,9 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
append_merge_tag_headers(parents, &tail); append_merge_tag_headers(parents, &tail);
} }
if (commit_tree_extended(sb.buf, sb.len, active_cache_tree->oid.hash, if (commit_tree_extended(sb.buf, sb.len, &active_cache_tree->oid,
parents, oid.hash, author_ident.buf, sign_commit, extra)) { parents, &oid, author_ident.buf, sign_commit,
extra)) {
rollback_index_files(); rollback_index_files();
die(_("failed to write commit object")); die(_("failed to write commit object"));
} }

View File

@ -820,8 +820,8 @@ static int merge_trivial(struct commit *head, struct commit_list *remoteheads)
pptr = commit_list_append(head, pptr); pptr = commit_list_append(head, pptr);
pptr = commit_list_append(remoteheads->item, pptr); pptr = commit_list_append(remoteheads->item, pptr);
prepare_to_commit(remoteheads); prepare_to_commit(remoteheads);
if (commit_tree(merge_msg.buf, merge_msg.len, result_tree.hash, parents, if (commit_tree(merge_msg.buf, merge_msg.len, &result_tree, parents,
result_commit.hash, NULL, sign_commit)) &result_commit, NULL, sign_commit))
die(_("failed to write commit object")); die(_("failed to write commit object"));
finish(head, remoteheads, &result_commit, "In-index merge"); finish(head, remoteheads, &result_commit, "In-index merge");
drop_save(); drop_save();
@ -845,8 +845,8 @@ static int finish_automerge(struct commit *head,
commit_list_insert(head, &parents); commit_list_insert(head, &parents);
strbuf_addch(&merge_msg, '\n'); strbuf_addch(&merge_msg, '\n');
prepare_to_commit(remoteheads); prepare_to_commit(remoteheads);
if (commit_tree(merge_msg.buf, merge_msg.len, result_tree->hash, parents, if (commit_tree(merge_msg.buf, merge_msg.len, result_tree, parents,
result_commit.hash, NULL, sign_commit)) &result_commit, NULL, sign_commit))
die(_("failed to write commit object")); die(_("failed to write commit object"));
strbuf_addf(&buf, "Merge made by the '%s' strategy.", wt_strategy); strbuf_addf(&buf, "Merge made by the '%s' strategy.", wt_strategy);
finish(head, remoteheads, &result_commit, buf.buf); finish(head, remoteheads, &result_commit, buf.buf);

View File

@ -1380,9 +1380,8 @@ void free_commit_extra_headers(struct commit_extra_header *extra)
} }
} }
int commit_tree(const char *msg, size_t msg_len, int commit_tree(const char *msg, size_t msg_len, const struct object_id *tree,
const unsigned char *tree, struct commit_list *parents, struct object_id *ret,
struct commit_list *parents, unsigned char *ret,
const char *author, const char *sign_commit) const char *author, const char *sign_commit)
{ {
struct commit_extra_header *extra = NULL, **tail = &extra; struct commit_extra_header *extra = NULL, **tail = &extra;
@ -1511,8 +1510,8 @@ N_("Warning: commit message did not conform to UTF-8.\n"
"variable i18n.commitencoding to the encoding your project uses.\n"); "variable i18n.commitencoding to the encoding your project uses.\n");
int commit_tree_extended(const char *msg, size_t msg_len, int commit_tree_extended(const char *msg, size_t msg_len,
const unsigned char *tree, const struct object_id *tree,
struct commit_list *parents, unsigned char *ret, struct commit_list *parents, struct object_id *ret,
const char *author, const char *sign_commit, const char *author, const char *sign_commit,
struct commit_extra_header *extra) struct commit_extra_header *extra)
{ {
@ -1520,7 +1519,7 @@ int commit_tree_extended(const char *msg, size_t msg_len,
int encoding_is_utf8; int encoding_is_utf8;
struct strbuf buffer; struct strbuf buffer;
assert_sha1_type(tree, OBJ_TREE); assert_sha1_type(tree->hash, OBJ_TREE);
if (memchr(msg, '\0', msg_len)) if (memchr(msg, '\0', msg_len))
return error("a NUL byte in commit log message not allowed."); 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,
encoding_is_utf8 = is_encoding_utf8(git_commit_encoding); encoding_is_utf8 = is_encoding_utf8(git_commit_encoding);
strbuf_init(&buffer, 8192); /* should avoid reallocs for the headers */ strbuf_init(&buffer, 8192); /* should avoid reallocs for the headers */
strbuf_addf(&buffer, "tree %s\n", sha1_to_hex(tree)); strbuf_addf(&buffer, "tree %s\n", oid_to_hex(tree));
/* /*
* NOTE! This ordering means that the same exact tree merged with a * 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,
goto out; goto out;
} }
result = write_sha1_file(buffer.buf, buffer.len, commit_type, ret); result = write_sha1_file(buffer.buf, buffer.len, commit_type, ret->hash);
out: out:
strbuf_release(&buffer); strbuf_release(&buffer);
return result; return result;

View File

@ -262,14 +262,15 @@ extern void append_merge_tag_headers(struct commit_list *parents,
struct commit_extra_header ***tail); struct commit_extra_header ***tail);
extern int commit_tree(const char *msg, size_t msg_len, extern int commit_tree(const char *msg, size_t msg_len,
const unsigned char *tree, const struct object_id *tree,
struct commit_list *parents, unsigned char *ret, struct commit_list *parents, struct object_id *ret,
const char *author, const char *sign_commit); const char *author, const char *sign_commit);
extern int commit_tree_extended(const char *msg, size_t msg_len, extern int commit_tree_extended(const char *msg, size_t msg_len,
const unsigned char *tree, const struct object_id *tree,
struct commit_list *parents, unsigned char *ret, struct commit_list *parents,
const char *author, const char *sign_commit, struct object_id *ret, const char *author,
const char *sign_commit,
struct commit_extra_header *); struct commit_extra_header *);
extern struct commit_extra_header *read_commit_extra_headers(struct commit *, const char **); extern struct commit_extra_header *read_commit_extra_headers(struct commit *, const char **);

View File

@ -56,8 +56,8 @@ int notes_cache_write(struct notes_cache *c)
if (write_notes_tree(&c->tree, tree_oid.hash)) if (write_notes_tree(&c->tree, tree_oid.hash))
return -1; return -1;
if (commit_tree(c->validity, strlen(c->validity), tree_oid.hash, NULL, if (commit_tree(c->validity, strlen(c->validity), &tree_oid, NULL,
commit_oid.hash, NULL, NULL) < 0) &commit_oid, NULL, NULL) < 0)
return -1; return -1;
if (update_ref("update notes cache", c->tree.update_ref, &commit_oid, if (update_ref("update notes cache", c->tree.update_ref, &commit_oid,
NULL, 0, UPDATE_REFS_QUIET_ON_ERR) < 0) NULL, 0, UPDATE_REFS_QUIET_ON_ERR) < 0)

View File

@ -642,9 +642,8 @@ int notes_merge(struct notes_merge_options *o,
struct commit_list *parents = NULL; struct commit_list *parents = NULL;
commit_list_insert(remote, &parents); /* LIFO order */ commit_list_insert(remote, &parents); /* LIFO order */
commit_list_insert(local, &parents); commit_list_insert(local, &parents);
create_notes_commit(local_tree, parents, create_notes_commit(local_tree, parents, o->commit_msg.buf,
o->commit_msg.buf, o->commit_msg.len, o->commit_msg.len, result_oid);
result_oid->hash);
} }
found_result: found_result:
@ -718,8 +717,8 @@ int notes_merge_commit(struct notes_merge_options *o,
strbuf_setlen(&path, baselen); strbuf_setlen(&path, baselen);
} }
create_notes_commit(partial_tree, partial_commit->parents, create_notes_commit(partial_tree, partial_commit->parents, msg,
msg, strlen(msg), result_oid->hash); strlen(msg), result_oid);
unuse_commit_buffer(partial_commit, buffer); unuse_commit_buffer(partial_commit, buffer);
if (o->verbosity >= 4) if (o->verbosity >= 4)
printf("Finalized notes merge commit: %s\n", printf("Finalized notes merge commit: %s\n",

View File

@ -6,7 +6,7 @@
void create_notes_commit(struct notes_tree *t, struct commit_list *parents, void create_notes_commit(struct notes_tree *t, struct commit_list *parents,
const char *msg, size_t msg_len, const char *msg, size_t msg_len,
unsigned char *result_sha1) struct object_id *result_oid)
{ {
struct object_id tree_oid; struct object_id tree_oid;
@ -27,7 +27,8 @@ void create_notes_commit(struct notes_tree *t, struct commit_list *parents,
/* else: t->ref points to nothing, assume root/orphan commit */ /* else: t->ref points to nothing, assume root/orphan commit */
} }
if (commit_tree(msg, msg_len, tree_oid.hash, parents, result_sha1, NULL, NULL)) if (commit_tree(msg, msg_len, &tree_oid, parents, result_oid, NULL,
NULL))
die("Failed to commit notes tree to database"); die("Failed to commit notes tree to database");
} }
@ -47,7 +48,7 @@ void commit_notes(struct notes_tree *t, const char *msg)
strbuf_addstr(&buf, msg); strbuf_addstr(&buf, msg);
strbuf_complete_line(&buf); strbuf_complete_line(&buf);
create_notes_commit(t, NULL, buf.buf, buf.len, commit_oid.hash); create_notes_commit(t, NULL, buf.buf, buf.len, &commit_oid);
strbuf_insert(&buf, 0, "notes: ", 7); /* commit message starts at index 7 */ strbuf_insert(&buf, 0, "notes: ", 7); /* commit message starts at index 7 */
update_ref(buf.buf, t->update_ref, &commit_oid, NULL, 0, update_ref(buf.buf, t->update_ref, &commit_oid, NULL, 0,
UPDATE_REFS_DIE_ON_ERR); UPDATE_REFS_DIE_ON_ERR);

View File

@ -15,7 +15,8 @@
* The resulting commit SHA1 is stored in result_sha1. * The resulting commit SHA1 is stored in result_sha1.
*/ */
void create_notes_commit(struct notes_tree *t, struct commit_list *parents, void create_notes_commit(struct notes_tree *t, struct commit_list *parents,
const char *msg, size_t msg_len, unsigned char *result_sha1); const char *msg, size_t msg_len,
struct object_id *result_oid);
void commit_notes(struct notes_tree *t, const char *msg); void commit_notes(struct notes_tree *t, const char *msg);