All of lore.kernel.org
 help / color / mirror / Atom feed
From: Patryk Obara <patryk.obara@gmail.com>
To: git@vger.kernel.org, "Junio C Hamano" <gitster@pobox.com>,
	"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>,
	"brian m . carlson" <sandals@crustytoothpaste.net>,
	"Jonathan Tan" <jonathantanmy@google.com>
Subject: [PATCH v3 08/14] commit: convert commit_tree* to object_id
Date: Wed, 24 Jan 2018 12:12:00 +0100	[thread overview]
Message-ID: <4e65fc05d792a9714dbe714bbdc0be1064466218.1516790478.git.patryk.obara@gmail.com> (raw)
In-Reply-To: <cover.1516790478.git.patryk.obara@gmail.com>
In-Reply-To: <cover.1516790478.git.patryk.obara@gmail.com>

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>
---
 builtin/am.c          |  4 ++--
 builtin/commit-tree.c |  4 ++--
 builtin/commit.c      |  5 +++--
 builtin/merge.c       |  8 ++++----
 commit.c              | 15 +++++++--------
 commit.h              | 11 ++++++-----
 notes-cache.c         |  4 ++--
 notes-merge.c         |  9 ++++-----
 notes-utils.c         |  7 ++++---
 notes-utils.h         |  3 ++-
 10 files changed, 36 insertions(+), 34 deletions(-)

diff --git a/builtin/am.c b/builtin/am.c
index acfe9d3c8c..6e6abb05cd 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -1641,8 +1641,8 @@ static void do_commit(const struct am_state *state)
 		setenv("GIT_COMMITTER_DATE",
 			state->ignore_date ? "" : state->author_date, 1);
 
-	if (commit_tree(state->msg, state->msg_len, tree.hash, parents, commit.hash,
-				author, state->sign_commit))
+	if (commit_tree(state->msg, state->msg_len, &tree, parents, &commit,
+			author, state->sign_commit))
 		die(_("failed to write commit object"));
 
 	reflog_msg = getenv("GIT_REFLOG_ACTION");
diff --git a/builtin/commit-tree.c b/builtin/commit-tree.c
index 2177251e24..e5bdf57b1e 100644
--- a/builtin/commit-tree.c
+++ b/builtin/commit-tree.c
@@ -117,8 +117,8 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix)
 			die_errno("git commit-tree: failed to read");
 	}
 
-	if (commit_tree(buffer.buf, buffer.len, tree_oid.hash, parents,
-			commit_oid.hash, NULL, sign_commit)) {
+	if (commit_tree(buffer.buf, buffer.len, &tree_oid, parents, &commit_oid,
+			NULL, sign_commit)) {
 		strbuf_release(&buffer);
 		return 1;
 	}
diff --git a/builtin/commit.c b/builtin/commit.c
index 4610e3d8e3..e5974a5999 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -1794,8 +1794,9 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
 		append_merge_tag_headers(parents, &tail);
 	}
 
-	if (commit_tree_extended(sb.buf, sb.len, active_cache_tree->oid.hash,
-			 parents, oid.hash, author_ident.buf, sign_commit, extra)) {
+	if (commit_tree_extended(sb.buf, sb.len, &active_cache_tree->oid,
+				 parents, &oid, author_ident.buf, sign_commit,
+				 extra)) {
 		rollback_index_files();
 		die(_("failed to write commit object"));
 	}
diff --git a/builtin/merge.c b/builtin/merge.c
index 30264cfd7c..92ba99a1a5 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -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(remoteheads->item, pptr);
 	prepare_to_commit(remoteheads);
-	if (commit_tree(merge_msg.buf, merge_msg.len, result_tree.hash, parents,
-			result_commit.hash, NULL, sign_commit))
+	if (commit_tree(merge_msg.buf, merge_msg.len, &result_tree, parents,
+			&result_commit, NULL, sign_commit))
 		die(_("failed to write commit object"));
 	finish(head, remoteheads, &result_commit, "In-index merge");
 	drop_save();
@@ -845,8 +845,8 @@ static int finish_automerge(struct commit *head,
 		commit_list_insert(head, &parents);
 	strbuf_addch(&merge_msg, '\n');
 	prepare_to_commit(remoteheads);
-	if (commit_tree(merge_msg.buf, merge_msg.len, result_tree->hash, parents,
-			result_commit.hash, NULL, sign_commit))
+	if (commit_tree(merge_msg.buf, merge_msg.len, result_tree, parents,
+			&result_commit, NULL, sign_commit))
 		die(_("failed to write commit object"));
 	strbuf_addf(&buf, "Merge made by the '%s' strategy.", wt_strategy);
 	finish(head, remoteheads, &result_commit, buf.buf);
diff --git a/commit.c b/commit.c
index ff51c9f34a..643f3daec3 100644
--- a/commit.c
+++ b/commit.c
@@ -1380,9 +1380,8 @@ void free_commit_extra_headers(struct commit_extra_header *extra)
 	}
 }
 
-int commit_tree(const char *msg, size_t msg_len,
-		const unsigned char *tree,
-		struct commit_list *parents, unsigned char *ret,
+int commit_tree(const char *msg, size_t msg_len, const struct object_id *tree,
+		struct commit_list *parents, struct object_id *ret,
 		const char *author, const char *sign_commit)
 {
 	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");
 
 int commit_tree_extended(const char *msg, size_t msg_len,
-			 const unsigned char *tree,
-			 struct commit_list *parents, unsigned char *ret,
+			 const struct object_id *tree,
+			 struct commit_list *parents, struct object_id *ret,
 			 const char *author, const char *sign_commit,
 			 struct commit_extra_header *extra)
 {
@@ -1520,7 +1519,7 @@ int commit_tree_extended(const char *msg, size_t msg_len,
 	int encoding_is_utf8;
 	struct strbuf buffer;
 
-	assert_sha1_type(tree, OBJ_TREE);
+	assert_sha1_type(tree->hash, OBJ_TREE);
 
 	if (memchr(msg, '\0', msg_len))
 		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);
 
 	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
@@ -1568,7 +1567,7 @@ int commit_tree_extended(const char *msg, size_t msg_len,
 		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:
 	strbuf_release(&buffer);
 	return result;
diff --git a/commit.h b/commit.h
index 425f402775..0fb8271665 100644
--- a/commit.h
+++ b/commit.h
@@ -262,14 +262,15 @@ extern void append_merge_tag_headers(struct commit_list *parents,
 				     struct commit_extra_header ***tail);
 
 extern int commit_tree(const char *msg, size_t msg_len,
-		       const unsigned char *tree,
-		       struct commit_list *parents, unsigned char *ret,
+		       const struct object_id *tree,
+		       struct commit_list *parents, struct object_id *ret,
 		       const char *author, const char *sign_commit);
 
 extern int commit_tree_extended(const char *msg, size_t msg_len,
-				const unsigned char *tree,
-				struct commit_list *parents, unsigned char *ret,
-				const char *author, const char *sign_commit,
+				const struct object_id *tree,
+				struct commit_list *parents,
+				struct object_id *ret, const char *author,
+				const char *sign_commit,
 				struct commit_extra_header *);
 
 extern struct commit_extra_header *read_commit_extra_headers(struct commit *, const char **);
diff --git a/notes-cache.c b/notes-cache.c
index 17ee8602b3..d2f87147cc 100644
--- a/notes-cache.c
+++ b/notes-cache.c
@@ -56,8 +56,8 @@ int notes_cache_write(struct notes_cache *c)
 
 	if (write_notes_tree(&c->tree, tree_oid.hash))
 		return -1;
-	if (commit_tree(c->validity, strlen(c->validity), tree_oid.hash, NULL,
-			commit_oid.hash, NULL, NULL) < 0)
+	if (commit_tree(c->validity, strlen(c->validity), &tree_oid, NULL,
+			&commit_oid, NULL, NULL) < 0)
 		return -1;
 	if (update_ref("update notes cache", c->tree.update_ref, &commit_oid,
 		       NULL, 0, UPDATE_REFS_QUIET_ON_ERR) < 0)
diff --git a/notes-merge.c b/notes-merge.c
index 0f6573cb17..c09c5e0e47 100644
--- a/notes-merge.c
+++ b/notes-merge.c
@@ -642,9 +642,8 @@ int notes_merge(struct notes_merge_options *o,
 		struct commit_list *parents = NULL;
 		commit_list_insert(remote, &parents); /* LIFO order */
 		commit_list_insert(local, &parents);
-		create_notes_commit(local_tree, parents,
-				    o->commit_msg.buf, o->commit_msg.len,
-				    result_oid->hash);
+		create_notes_commit(local_tree, parents, o->commit_msg.buf,
+				    o->commit_msg.len, result_oid);
 	}
 
 found_result:
@@ -718,8 +717,8 @@ int notes_merge_commit(struct notes_merge_options *o,
 		strbuf_setlen(&path, baselen);
 	}
 
-	create_notes_commit(partial_tree, partial_commit->parents,
-			    msg, strlen(msg), result_oid->hash);
+	create_notes_commit(partial_tree, partial_commit->parents, msg,
+			    strlen(msg), result_oid);
 	unuse_commit_buffer(partial_commit, buffer);
 	if (o->verbosity >= 4)
 		printf("Finalized notes merge commit: %s\n",
diff --git a/notes-utils.c b/notes-utils.c
index 5c8e70c98f..058c642dac 100644
--- a/notes-utils.c
+++ b/notes-utils.c
@@ -6,7 +6,7 @@
 
 void create_notes_commit(struct notes_tree *t, struct commit_list *parents,
 			 const char *msg, size_t msg_len,
-			 unsigned char *result_sha1)
+			 struct object_id *result_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 */
 	}
 
-	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");
 }
 
@@ -47,7 +48,7 @@ void commit_notes(struct notes_tree *t, const char *msg)
 	strbuf_addstr(&buf, msg);
 	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 */
 	update_ref(buf.buf, t->update_ref, &commit_oid, NULL, 0,
 		   UPDATE_REFS_DIE_ON_ERR);
diff --git a/notes-utils.h b/notes-utils.h
index 1190578398..5d79cbef51 100644
--- a/notes-utils.h
+++ b/notes-utils.h
@@ -15,7 +15,8 @@
  * The resulting commit SHA1 is stored in result_sha1.
  */
 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);
 
-- 
2.14.3


  parent reply	other threads:[~2018-01-24 11:12 UTC|newest]

Thread overview: 75+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-18 14:50 [PATCH 00/11] Some fixes and bunch of object_id conversions Patryk Obara
2018-01-18 14:50 ` [PATCH 01/11] http-push: improve error log Patryk Obara
2018-01-18 14:50 ` [PATCH 02/11] clang-format: adjust penalty for return type line break Patryk Obara
2018-01-18 14:50 ` [PATCH 03/11] sha1_file: convert pretend_sha1_file to object_id Patryk Obara
2018-01-18 14:50 ` [PATCH 04/11] dir: convert struct sha1_stat to use object_id Patryk Obara
2018-01-18 14:50 ` [PATCH 05/11] sha1_file: convert hash_sha1_file to object_id Patryk Obara
2018-01-18 14:50 ` [PATCH 06/11] cache: clear whole hash buffer with oidclr Patryk Obara
2018-01-18 14:50 ` [PATCH 07/11] match-trees: convert splice_tree to object_id Patryk Obara
2018-01-18 14:51 ` [PATCH 08/11] commit: convert commit_tree* " Patryk Obara
2018-01-18 14:51 ` [PATCH 09/11] notes: convert combine_notes_* " Patryk Obara
2018-01-18 14:51 ` [PATCH 10/11] notes: convert write_notes_tree " Patryk Obara
2018-01-18 14:51 ` [PATCH 11/11] sha1_file: convert write_sha1_file " Patryk Obara
2018-01-20 20:44   ` brian m. carlson
2018-01-21 16:26     ` Patryk Obara
2018-01-18 17:42 ` [PATCH 00/11] Some fixes and bunch of object_id conversions Jonathan Tan
2018-01-20 20:58 ` brian m. carlson
2018-01-21 16:35   ` Patryk Obara
2018-01-22 11:04 ` [PATCH v2 00/14] " Patryk Obara
2018-01-22 11:04   ` [PATCH v2 01/14] http-push: improve error log Patryk Obara
2018-01-22 11:04   ` [PATCH v2 02/14] clang-format: adjust penalty for return type line break Patryk Obara
2018-01-22 11:04   ` [PATCH v2 03/14] sha1_file: convert pretend_sha1_file to object_id Patryk Obara
2018-01-22 11:04   ` [PATCH v2 04/14] dir: convert struct sha1_stat to use object_id Patryk Obara
2018-01-22 11:04   ` [PATCH v2 05/14] sha1_file: convert hash_sha1_file to object_id Patryk Obara
2018-01-22 11:49     ` Duy Nguyen
2018-01-22 12:44       ` Patryk Obara
2018-01-22 12:52         ` Duy Nguyen
2018-01-22 11:04   ` [PATCH v2 06/14] cache: clear whole hash buffer with oidclr Patryk Obara
2018-01-22 11:04   ` [PATCH v2 07/14] match-trees: convert splice_tree to object_id Patryk Obara
2018-01-22 11:56     ` Duy Nguyen
2018-01-22 13:12       ` Patryk Obara
2018-01-23  1:29         ` Duy Nguyen
2018-01-22 11:04   ` [PATCH v2 08/14] commit: convert commit_tree* " Patryk Obara
2018-01-22 11:04   ` [PATCH v2 09/14] notes: convert combine_notes_* " Patryk Obara
2018-01-22 11:04   ` [PATCH v2 10/14] notes: convert write_notes_tree " Patryk Obara
2018-01-22 12:03     ` Duy Nguyen
2018-01-22 11:04   ` [PATCH v2 11/14] sha1_file: convert write_sha1_file " Patryk Obara
2018-01-22 11:04   ` [PATCH v2 12/14] sha1_file: convert force_object_loose " Patryk Obara
2018-01-22 11:04   ` [PATCH v2 13/14] sha1_file: convert write_loose_object " Patryk Obara
2018-01-22 11:04   ` [PATCH v2 14/14] sha1_file: rename hash_sha1_file_literally Patryk Obara
2018-01-22 12:14   ` [PATCH v2 00/14] Some fixes and bunch of object_id conversions Duy Nguyen
2018-01-22 13:26     ` Patryk Obara
2018-01-24 11:11   ` [PATCH v3 " Patryk Obara
2018-01-24 11:11     ` [PATCH v3 01/14] http-push: improve error log Patryk Obara
2018-01-24 11:11     ` [PATCH v3 02/14] clang-format: adjust penalty for return type line break Patryk Obara
2018-01-24 11:11     ` [PATCH v3 03/14] sha1_file: convert pretend_sha1_file to object_id Patryk Obara
2018-01-24 11:11     ` [PATCH v3 04/14] dir: convert struct sha1_stat to use object_id Patryk Obara
2018-01-24 21:36       ` Junio C Hamano
2018-01-24 11:11     ` [PATCH v3 05/14] sha1_file: convert hash_sha1_file to object_id Patryk Obara
2018-01-24 11:11     ` [PATCH v3 06/14] cache: clear whole hash buffer with oidclr Patryk Obara
2018-01-24 11:11     ` [PATCH v3 07/14] match-trees: convert splice_tree to object_id Patryk Obara
2018-01-24 11:12     ` Patryk Obara [this message]
2018-01-24 11:12     ` [PATCH v3 09/14] notes: convert combine_notes_* " Patryk Obara
2018-01-24 11:12     ` [PATCH v3 10/14] notes: convert write_notes_tree " Patryk Obara
2018-01-24 11:12     ` [PATCH v3 11/14] sha1_file: convert write_sha1_file " Patryk Obara
2018-01-24 11:12     ` [PATCH v3 12/14] sha1_file: convert force_object_loose " Patryk Obara
2018-01-24 11:12     ` [PATCH v3 13/14] sha1_file: convert write_loose_object " Patryk Obara
2018-01-26 23:14       ` brian m. carlson
2018-01-24 11:12     ` [PATCH v3 14/14] sha1_file: rename hash_sha1_file_literally Patryk Obara
2018-01-24 21:28     ` [PATCH v3 00/14] Some fixes and bunch of object_id conversions Junio C Hamano
2018-01-24 21:41     ` Junio C Hamano
2018-01-25  9:53       ` Duy Nguyen
2018-01-27  0:12       ` brian m. carlson
2018-01-28  0:13     ` [PATCH v4 00/12] A " Patryk Obara
2018-01-28  0:13       ` [PATCH v4 01/12] sha1_file: convert pretend_sha1_file to object_id Patryk Obara
2018-01-28  0:13       ` [PATCH v4 02/12] dir: convert struct sha1_stat to use object_id Patryk Obara
2018-01-28  0:13       ` [PATCH v4 03/12] sha1_file: convert hash_sha1_file to object_id Patryk Obara
2018-01-28  0:13       ` [PATCH v4 04/12] cache: clear whole hash buffer with oidclr Patryk Obara
2018-01-28  0:13       ` [PATCH v4 05/12] match-trees: convert splice_tree to object_id Patryk Obara
2018-01-28  0:13       ` [PATCH v4 06/12] commit: convert commit_tree* " Patryk Obara
2018-01-28  0:13       ` [PATCH v4 07/12] notes: convert combine_notes_* " Patryk Obara
2018-01-28  0:13       ` [PATCH v4 08/12] notes: convert write_notes_tree " Patryk Obara
2018-01-28  0:13       ` [PATCH v4 09/12] sha1_file: convert write_sha1_file " Patryk Obara
2018-01-28  0:13       ` [PATCH v4 10/12] sha1_file: convert force_object_loose " Patryk Obara
2018-01-28  0:13       ` [PATCH v4 11/12] sha1_file: convert write_loose_object " Patryk Obara
2018-01-28  0:13       ` [PATCH v4 12/12] sha1_file: rename hash_sha1_file_literally Patryk Obara

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4e65fc05d792a9714dbe714bbdc0be1064466218.1516790478.git.patryk.obara@gmail.com \
    --to=patryk.obara@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jonathantanmy@google.com \
    --cc=pclouds@gmail.com \
    --cc=sandals@crustytoothpaste.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.