git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "brian m. carlson" <sandals@crustytoothpaste.net>
To: git@vger.kernel.org
Cc: "Paul Tan" <pyokagan@gmail.com>,
	"Junio C Hamano" <gitster@pobox.com>,
	"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>,
	"Jeff King" <peff@peff.net>
Subject: [PATCH 12/20] builtin/blame: convert file to use struct object_id
Date: Sun, 28 Aug 2016 23:27:49 +0000	[thread overview]
Message-ID: <20160828232757.373278-13-sandals@crustytoothpaste.net> (raw)
In-Reply-To: <20160828232757.373278-1-sandals@crustytoothpaste.net>

Convert this file to use struct object_id, and additionally convert some
uses of the constant 40 to GIT_SHA1_HEXSZ.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 builtin/blame.c | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/builtin/blame.c b/builtin/blame.c
index 527b66a4..6650e7dd 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -1941,7 +1941,7 @@ static void emit_other(struct scoreboard *sb, struct blame_entry *ent, int opt)
 	cp = nth_line(sb, ent->lno);
 	for (cnt = 0; cnt < ent->num_lines; cnt++) {
 		char ch;
-		int length = (opt & OUTPUT_LONG_OBJECT_NAME) ? 40 : abbrev;
+		int length = (opt & OUTPUT_LONG_OBJECT_NAME) ? GIT_SHA1_HEXSZ : abbrev;
 
 		if (suspect->commit->object.flags & UNINTERESTING) {
 			if (blank_boundary)
@@ -2232,12 +2232,12 @@ static void verify_working_tree_path(struct commit *work_tree, const char *path)
 	int pos;
 
 	for (parents = work_tree->parents; parents; parents = parents->next) {
-		const unsigned char *commit_sha1 = parents->item->object.oid.hash;
-		unsigned char blob_sha1[20];
+		const struct object_id *commit_oid = &parents->item->object.oid;
+		struct object_id blob_oid;
 		unsigned mode;
 
-		if (!get_tree_entry(commit_sha1, path, blob_sha1, &mode) &&
-		    sha1_object_info(blob_sha1, NULL) == OBJ_BLOB)
+		if (!get_tree_entry(commit_oid->hash, path, blob_oid.hash, &mode) &&
+		    sha1_object_info(blob_oid.hash, NULL) == OBJ_BLOB)
 			return;
 	}
 
@@ -2250,13 +2250,13 @@ static void verify_working_tree_path(struct commit *work_tree, const char *path)
 		die("no such path '%s' in HEAD", path);
 }
 
-static struct commit_list **append_parent(struct commit_list **tail, const unsigned char *sha1)
+static struct commit_list **append_parent(struct commit_list **tail, const struct object_id *oid)
 {
 	struct commit *parent;
 
-	parent = lookup_commit_reference(sha1);
+	parent = lookup_commit_reference(oid->hash);
 	if (!parent)
-		die("no such commit %s", sha1_to_hex(sha1));
+		die("no such commit %s", oid_to_hex(oid));
 	return &commit_list_insert(parent, tail)->next;
 }
 
@@ -2273,10 +2273,10 @@ static void append_merge_parents(struct commit_list **tail)
 	}
 
 	while (!strbuf_getwholeline_fd(&line, merge_head, '\n')) {
-		unsigned char sha1[20];
-		if (line.len < 40 || get_sha1_hex(line.buf, sha1))
+		struct object_id oid;
+		if (line.len < GIT_SHA1_HEXSZ || get_oid_hex(line.buf, &oid))
 			die("unknown line in '%s': %s", git_path_merge_head(), line.buf);
-		tail = append_parent(tail, sha1);
+		tail = append_parent(tail, &oid);
 	}
 	close(merge_head);
 	strbuf_release(&line);
@@ -2305,7 +2305,7 @@ static struct commit *fake_working_tree_commit(struct diff_options *opt,
 	struct commit *commit;
 	struct origin *origin;
 	struct commit_list **parent_tail, *parent;
-	unsigned char head_sha1[20];
+	struct object_id head_oid;
 	struct strbuf buf = STRBUF_INIT;
 	const char *ident;
 	time_t now;
@@ -2321,10 +2321,10 @@ static struct commit *fake_working_tree_commit(struct diff_options *opt,
 	commit->date = now;
 	parent_tail = &commit->parents;
 
-	if (!resolve_ref_unsafe("HEAD", RESOLVE_REF_READING, head_sha1, NULL))
+	if (!resolve_ref_unsafe("HEAD", RESOLVE_REF_READING, head_oid.hash, NULL))
 		die("no such ref: HEAD");
 
-	parent_tail = append_parent(parent_tail, head_sha1);
+	parent_tail = append_parent(parent_tail, &head_oid);
 	append_merge_parents(parent_tail);
 	verify_working_tree_path(commit, path);
 

  parent reply	other threads:[~2016-08-28 23:28 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-28 23:27 [PATCH 00/20] object_id part 5 brian m. carlson
2016-08-28 23:27 ` [PATCH 01/20] cache: convert struct cache_entry to use struct object_id brian m. carlson
2016-08-29 10:50   ` Johannes Schindelin
2016-08-29 13:48   ` Jakub Narębski
2016-08-29 15:43     ` Johannes Schindelin
2016-08-29 22:25       ` brian m. carlson
2016-08-28 23:27 ` [PATCH 02/20] builtin/apply: convert static functions to " brian m. carlson
2016-08-28 23:27 ` [PATCH 03/20] builtin/blame: convert struct origin to use " brian m. carlson
2016-08-28 23:27 ` [PATCH 04/20] builtin/log: convert some static functions " brian m. carlson
2016-08-28 23:27 ` [PATCH 05/20] builtin/cat-file: convert struct expand_data " brian m. carlson
2016-08-28 23:27 ` [PATCH 06/20] builtin/cat-file: convert some static functions to " brian m. carlson
2016-08-28 23:27 ` [PATCH 07/20] builtin: convert textconv_object to use " brian m. carlson
2016-08-28 23:27 ` [PATCH 08/20] streaming: make stream_blob_to_fd take " brian m. carlson
2016-08-29 11:26   ` Johannes Schindelin
2016-08-28 23:27 ` [PATCH 09/20] builtin/checkout: convert some static functions to " brian m. carlson
2016-08-28 23:27 ` [PATCH 10/20] notes-merge: convert struct notes_merge_pair " brian m. carlson
2016-08-31 10:51   ` Johannes Schindelin
2016-08-28 23:27 ` [PATCH 11/20] Convert read_mmblob to take " brian m. carlson
2016-08-28 23:27 ` brian m. carlson [this message]
2016-08-28 23:27 ` [PATCH 13/20] builtin/rm: convert to use " brian m. carlson
2016-08-28 23:27 ` [PATCH 14/20] notes: convert init_notes " brian m. carlson
2016-08-28 23:27 ` [PATCH 15/20] builtin/update-index: convert file to " brian m. carlson
2016-08-28 23:27 ` [PATCH 16/20] sha1_name: convert get_sha1_mb " brian m. carlson
2016-08-28 23:27 ` [PATCH 17/20] refs: add an update_ref_oid function brian m. carlson
2016-08-28 23:27 ` [PATCH 18/20] builtin/am: convert to struct object_id brian m. carlson
2016-08-29  7:02   ` Paul Tan
2016-08-29 22:15     ` brian m. carlson
2016-08-28 23:27 ` [PATCH 19/20] builtin/commit-tree: " brian m. carlson
2016-08-28 23:27 ` [PATCH 20/20] builtin/reset: convert to use " brian m. carlson
2016-08-31 11:08   ` Johannes Schindelin

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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to=20160828232757.373278-13-sandals@crustytoothpaste.net \
    --to=sandals@crustytoothpaste.net \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=pclouds@gmail.com \
    --cc=peff@peff.net \
    --cc=pyokagan@gmail.com \
    /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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).