git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "brian m. carlson" <sandals@crustytoothpaste.net>
To: git@vger.kernel.org
Cc: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>,
	"Patryk Obara" <patryk.obara@gmail.com>,
	"Jeff King" <peff@peff.net>,
	"Eric Sunshine" <sunshine@sunshineco.com>
Subject: [PATCH v2 08/36] strbuf: convert strbuf_add_unique_abbrev to use struct object_id
Date: Sun, 25 Feb 2018 21:11:44 +0000	[thread overview]
Message-ID: <20180225211212.477570-9-sandals@crustytoothpaste.net> (raw)
In-Reply-To: <20180225211212.477570-1-sandals@crustytoothpaste.net>

Convert the declaration and definition of strbuf_add_unique_abbrev to
make it take a pointer to struct object_id.  Predeclare the struct in
strbuf.h, as cache.h includes strbuf.h before it declares the struct,
and otherwise the struct declaration would have the wrong scope.

Apply the following semantic patch, along with the standard object_id
transforms, to adjust the callers:

@@
expression E1, E2, E3;
@@
- strbuf_add_unique_abbrev(E1, E2.hash, E3);
+ strbuf_add_unique_abbrev(E1, &E2, E3);

@@
expression E1, E2, E3;
@@
- strbuf_add_unique_abbrev(E1, E2->hash, E3);
+ strbuf_add_unique_abbrev(E1, E2, E3);

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 builtin/checkout.c | 2 +-
 builtin/fetch.c    | 8 ++++----
 builtin/tag.c      | 2 +-
 merge-recursive.c  | 2 +-
 pretty.c           | 8 ++++----
 strbuf.c           | 4 ++--
 strbuf.h           | 8 +++++++-
 submodule.c        | 4 ++--
 transport.c        | 4 ++--
 wt-status.c        | 6 +++---
 10 files changed, 27 insertions(+), 21 deletions(-)

diff --git a/builtin/checkout.c b/builtin/checkout.c
index 87182aa018..bc68d423e5 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -720,7 +720,7 @@ static int add_pending_uninteresting_ref(const char *refname,
 static void describe_one_orphan(struct strbuf *sb, struct commit *commit)
 {
 	strbuf_addstr(sb, "  ");
-	strbuf_add_unique_abbrev(sb, commit->object.oid.hash, DEFAULT_ABBREV);
+	strbuf_add_unique_abbrev(sb, &commit->object.oid, DEFAULT_ABBREV);
 	strbuf_addch(sb, ' ');
 	if (!parse_commit(commit))
 		pp_commit_easy(CMIT_FMT_ONELINE, commit, sb);
diff --git a/builtin/fetch.c b/builtin/fetch.c
index 8ee998ea2e..3b8988e51d 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -697,9 +697,9 @@ static int update_local_ref(struct ref *ref,
 	if (in_merge_bases(current, updated)) {
 		struct strbuf quickref = STRBUF_INIT;
 		int r;
-		strbuf_add_unique_abbrev(&quickref, current->object.oid.hash, DEFAULT_ABBREV);
+		strbuf_add_unique_abbrev(&quickref, &current->object.oid, DEFAULT_ABBREV);
 		strbuf_addstr(&quickref, "..");
-		strbuf_add_unique_abbrev(&quickref, ref->new_oid.hash, DEFAULT_ABBREV);
+		strbuf_add_unique_abbrev(&quickref, &ref->new_oid, DEFAULT_ABBREV);
 		if ((recurse_submodules != RECURSE_SUBMODULES_OFF) &&
 		    (recurse_submodules != RECURSE_SUBMODULES_ON))
 			check_for_new_submodule_commits(&ref->new_oid);
@@ -712,9 +712,9 @@ static int update_local_ref(struct ref *ref,
 	} else if (force || ref->force) {
 		struct strbuf quickref = STRBUF_INIT;
 		int r;
-		strbuf_add_unique_abbrev(&quickref, current->object.oid.hash, DEFAULT_ABBREV);
+		strbuf_add_unique_abbrev(&quickref, &current->object.oid, DEFAULT_ABBREV);
 		strbuf_addstr(&quickref, "...");
-		strbuf_add_unique_abbrev(&quickref, ref->new_oid.hash, DEFAULT_ABBREV);
+		strbuf_add_unique_abbrev(&quickref, &ref->new_oid, DEFAULT_ABBREV);
 		if ((recurse_submodules != RECURSE_SUBMODULES_OFF) &&
 		    (recurse_submodules != RECURSE_SUBMODULES_ON))
 			check_for_new_submodule_commits(&ref->new_oid);
diff --git a/builtin/tag.c b/builtin/tag.c
index 8885e21ddc..99dba2d907 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -289,7 +289,7 @@ static void create_reflog_msg(const struct object_id *oid, struct strbuf *sb)
 		strbuf_addstr(sb, rla);
 	} else {
 		strbuf_addstr(sb, "tag: tagging ");
-		strbuf_add_unique_abbrev(sb, oid->hash, DEFAULT_ABBREV);
+		strbuf_add_unique_abbrev(sb, oid, DEFAULT_ABBREV);
 	}
 
 	strbuf_addstr(sb, " (");
diff --git a/merge-recursive.c b/merge-recursive.c
index c886f2e9cd..f58f13957e 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -228,7 +228,7 @@ static void output_commit_title(struct merge_options *o, struct commit *commit)
 		strbuf_addf(&o->obuf, "virtual %s\n",
 			merge_remote_util(commit)->name);
 	else {
-		strbuf_add_unique_abbrev(&o->obuf, commit->object.oid.hash,
+		strbuf_add_unique_abbrev(&o->obuf, &commit->object.oid,
 					 DEFAULT_ABBREV);
 		strbuf_addch(&o->obuf, ' ');
 		if (parse_commit(commit) != 0)
diff --git a/pretty.c b/pretty.c
index f7ce490230..34fe891fc0 100644
--- a/pretty.c
+++ b/pretty.c
@@ -549,7 +549,7 @@ static void add_merge_info(const struct pretty_print_context *pp,
 		struct object_id *oidp = &parent->item->object.oid;
 		strbuf_addch(sb, ' ');
 		if (pp->abbrev)
-			strbuf_add_unique_abbrev(sb, oidp->hash, pp->abbrev);
+			strbuf_add_unique_abbrev(sb, oidp, pp->abbrev);
 		else
 			strbuf_addstr(sb, oid_to_hex(oidp));
 		parent = parent->next;
@@ -1156,7 +1156,7 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
 		return 1;
 	case 'h':		/* abbreviated commit hash */
 		strbuf_addstr(sb, diff_get_color(c->auto_color, DIFF_COMMIT));
-		strbuf_add_unique_abbrev(sb, commit->object.oid.hash,
+		strbuf_add_unique_abbrev(sb, &commit->object.oid,
 					 c->pretty_ctx->abbrev);
 		strbuf_addstr(sb, diff_get_color(c->auto_color, DIFF_RESET));
 		return 1;
@@ -1164,7 +1164,7 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
 		strbuf_addstr(sb, oid_to_hex(&commit->tree->object.oid));
 		return 1;
 	case 't':		/* abbreviated tree hash */
-		strbuf_add_unique_abbrev(sb, commit->tree->object.oid.hash,
+		strbuf_add_unique_abbrev(sb, &commit->tree->object.oid,
 					 c->pretty_ctx->abbrev);
 		return 1;
 	case 'P':		/* parent hashes */
@@ -1178,7 +1178,7 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
 		for (p = commit->parents; p; p = p->next) {
 			if (p != commit->parents)
 				strbuf_addch(sb, ' ');
-			strbuf_add_unique_abbrev(sb, p->item->object.oid.hash,
+			strbuf_add_unique_abbrev(sb, &p->item->object.oid,
 						 c->pretty_ctx->abbrev);
 		}
 		return 1;
diff --git a/strbuf.c b/strbuf.c
index 1df674e919..128fbec503 100644
--- a/strbuf.c
+++ b/strbuf.c
@@ -869,12 +869,12 @@ void strbuf_addftime(struct strbuf *sb, const char *fmt, const struct tm *tm,
 	strbuf_setlen(sb, sb->len + len);
 }
 
-void strbuf_add_unique_abbrev(struct strbuf *sb, const unsigned char *sha1,
+void strbuf_add_unique_abbrev(struct strbuf *sb, const struct object_id *oid,
 			      int abbrev_len)
 {
 	int r;
 	strbuf_grow(sb, GIT_SHA1_HEXSZ + 1);
-	r = find_unique_abbrev_r(sb->buf + sb->len, sha1, abbrev_len);
+	r = find_unique_abbrev_r(sb->buf + sb->len, oid->hash, abbrev_len);
 	strbuf_setlen(sb, sb->len + r);
 }
 
diff --git a/strbuf.h b/strbuf.h
index 14c8c10d66..cd7ad898eb 100644
--- a/strbuf.h
+++ b/strbuf.h
@@ -70,6 +70,12 @@ struct strbuf {
 extern char strbuf_slopbuf[];
 #define STRBUF_INIT  { .alloc = 0, .len = 0, .buf = strbuf_slopbuf }
 
+/*
+ * Predeclare this here, since cache.h includes this file before it defines the
+ * struct.
+ */
+struct object_id;
+
 /**
  * Life Cycle Functions
  * --------------------
@@ -539,7 +545,7 @@ extern void strbuf_list_free(struct strbuf **);
  * the strbuf `sb`.
  */
 extern void strbuf_add_unique_abbrev(struct strbuf *sb,
-				     const unsigned char *sha1,
+				     const struct object_id *oid,
 				     int abbrev_len);
 
 /**
diff --git a/submodule.c b/submodule.c
index 47ddc9b273..d4a482e647 100644
--- a/submodule.c
+++ b/submodule.c
@@ -540,9 +540,9 @@ static void show_submodule_header(struct diff_options *o, const char *path,
 
 output_header:
 	strbuf_addf(&sb, "Submodule %s ", path);
-	strbuf_add_unique_abbrev(&sb, one->hash, DEFAULT_ABBREV);
+	strbuf_add_unique_abbrev(&sb, one, DEFAULT_ABBREV);
 	strbuf_addstr(&sb, (fast_backward || fast_forward) ? ".." : "...");
-	strbuf_add_unique_abbrev(&sb, two->hash, DEFAULT_ABBREV);
+	strbuf_add_unique_abbrev(&sb, two, DEFAULT_ABBREV);
 	if (message)
 		strbuf_addf(&sb, " %s\n", message);
 	else
diff --git a/transport.c b/transport.c
index 00d48b5b56..87de35dd5e 100644
--- a/transport.c
+++ b/transport.c
@@ -367,7 +367,7 @@ static void print_ok_ref_status(struct ref *ref, int porcelain, int summary_widt
 		char type;
 		const char *msg;
 
-		strbuf_add_unique_abbrev(&quickref, ref->old_oid.hash,
+		strbuf_add_unique_abbrev(&quickref, &ref->old_oid,
 					 DEFAULT_ABBREV);
 		if (ref->forced_update) {
 			strbuf_addstr(&quickref, "...");
@@ -378,7 +378,7 @@ static void print_ok_ref_status(struct ref *ref, int porcelain, int summary_widt
 			type = ' ';
 			msg = NULL;
 		}
-		strbuf_add_unique_abbrev(&quickref, ref->new_oid.hash,
+		strbuf_add_unique_abbrev(&quickref, &ref->new_oid,
 					 DEFAULT_ABBREV);
 
 		print_ref_status(type, quickref.buf, ref, ref->peer_ref, msg,
diff --git a/wt-status.c b/wt-status.c
index f5debcd2b4..98e558a70b 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -1187,7 +1187,7 @@ static void abbrev_sha1_in_line(struct strbuf *line)
 		strbuf_trim(split[1]);
 		if (!get_oid(split[1]->buf, &oid)) {
 			strbuf_reset(split[1]);
-			strbuf_add_unique_abbrev(split[1], oid.hash,
+			strbuf_add_unique_abbrev(split[1], &oid,
 						 DEFAULT_ABBREV);
 			strbuf_addch(split[1], ' ');
 			strbuf_reset(line);
@@ -1421,7 +1421,7 @@ static char *get_branch(const struct worktree *wt, const char *path)
 		;
 	else if (!get_oid_hex(sb.buf, &oid)) {
 		strbuf_reset(&sb);
-		strbuf_add_unique_abbrev(&sb, oid.hash, DEFAULT_ABBREV);
+		strbuf_add_unique_abbrev(&sb, &oid, DEFAULT_ABBREV);
 	} else if (!strcmp(sb.buf, "detached HEAD")) /* rebase */
 		goto got_nothing;
 	else			/* bisect */
@@ -1458,7 +1458,7 @@ static int grab_1st_switch(struct object_id *ooid, struct object_id *noid,
 	if (!strcmp(cb->buf.buf, "HEAD")) {
 		/* HEAD is relative. Resolve it to the right reflog entry. */
 		strbuf_reset(&cb->buf);
-		strbuf_add_unique_abbrev(&cb->buf, noid->hash, DEFAULT_ABBREV);
+		strbuf_add_unique_abbrev(&cb->buf, noid, DEFAULT_ABBREV);
 	}
 	return 1;
 }

  parent reply	other threads:[~2018-02-25 21:14 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-25 21:11 [PATCH v2 00/36] object_id part 12 brian m. carlson
2018-02-25 21:11 ` [PATCH v2 01/36] bulk-checkin: convert index_bulk_checkin to struct object_id brian m. carlson
2018-02-25 21:11 ` [PATCH v2 02/36] builtin/write-tree: convert " brian m. carlson
2018-02-25 21:11 ` [PATCH v2 03/36] cache-tree: convert write_*_as_tree to object_id brian m. carlson
2018-02-25 21:11 ` [PATCH v2 04/36] cache-tree: convert remnants to struct object_id brian m. carlson
2018-02-26 11:15   ` Duy Nguyen
2018-02-25 21:11 ` [PATCH v2 05/36] resolve-undo: convert struct resolve_undo_info to object_id brian m. carlson
2018-02-26 11:25   ` Duy Nguyen
2018-02-27  2:01     ` brian m. carlson
2018-02-28  9:38       ` Duy Nguyen
2018-02-25 21:11 ` [PATCH v2 06/36] tree: convert read_tree_recursive to struct object_id brian m. carlson
2018-02-25 21:11 ` [PATCH v2 07/36] ref-filter: convert grab_objectname " brian m. carlson
2018-02-25 21:11 ` brian m. carlson [this message]
2018-02-25 21:11 ` [PATCH v2 09/36] wt-status: convert struct wt_status_state to object_id brian m. carlson
2018-02-25 21:11 ` [PATCH v2 10/36] Convert find_unique_abbrev* to struct object_id brian m. carlson
2018-02-25 21:11 ` [PATCH v2 11/36] http-walker: convert struct object_request to use " brian m. carlson
2018-02-25 21:11 ` [PATCH v2 12/36] send-pack: convert remaining functions to " brian m. carlson
2018-02-25 21:11 ` [PATCH v2 13/36] replace_object: convert struct replace_object to object_id brian m. carlson
2018-02-25 21:11 ` [PATCH v2 14/36] builtin/mktag: convert to struct object_id brian m. carlson
2018-02-25 21:11 ` [PATCH v2 15/36] archive: convert write_archive_entry_fn_t to object_id brian m. carlson
2018-02-25 21:11 ` [PATCH v2 16/36] archive: convert sha1_file_to_archive to struct object_id brian m. carlson
2018-02-25 21:11 ` [PATCH v2 17/36] builtin/index-pack: convert struct ref_delta_entry to object_id brian m. carlson
2018-02-25 21:11 ` [PATCH v2 18/36] sha1_file: convert read_loose_object to use struct object_id brian m. carlson
2018-02-25 21:11 ` [PATCH v2 19/36] sha1_file: convert check_sha1_signature to " brian m. carlson
2018-02-25 21:11 ` [PATCH v2 20/36] streaming: convert open_istream to use " brian m. carlson
2018-02-25 21:11 ` [PATCH v2 21/36] builtin/mktree: convert to " brian m. carlson
2018-02-25 21:11 ` [PATCH v2 22/36] sha1_file: convert assert_sha1_type to object_id brian m. carlson
2018-02-25 21:11 ` [PATCH v2 23/36] sha1_file: convert retry_bad_packed_offset to struct object_id brian m. carlson
2018-02-25 21:12 ` [PATCH v2 24/36] packfile: convert unpack_entry " brian m. carlson
2018-02-25 21:12 ` [PATCH v2 25/36] Convert remaining callers of sha1_object_info_extended to object_id brian m. carlson
2018-02-25 21:12 ` [PATCH v2 26/36] sha1_file: convert sha1_object_info* " brian m. carlson
2018-02-25 21:12 ` [PATCH v2 27/36] builtin/fmt-merge-msg: convert remaining code " brian m. carlson
2018-02-25 21:12 ` [PATCH v2 28/36] builtin/notes: convert static functions " brian m. carlson
2018-02-25 21:12 ` [PATCH v2 29/36] tree-walk: convert get_tree_entry_follow_symlinks internals " brian m. carlson
2018-02-25 21:12 ` [PATCH v2 30/36] streaming: convert istream internals to struct object_id brian m. carlson
2018-02-25 21:12 ` [PATCH v2 31/36] tree-walk: convert tree entry functions to object_id brian m. carlson
2018-02-25 21:12 ` [PATCH v2 32/36] sha1_file: convert read_object_with_reference " brian m. carlson
2018-02-25 21:12 ` [PATCH v2 33/36] sha1_file: convert read_sha1_file to struct object_id brian m. carlson
2018-02-25 21:12 ` [PATCH v2 34/36] Convert lookup_replace_object " brian m. carlson
2018-02-26 11:37   ` Duy Nguyen
2018-02-25 21:12 ` [PATCH v2 35/36] sha1_file: introduce a constant for max header length brian m. carlson
2018-02-25 21:12 ` [PATCH v2 36/36] convert: convert to struct object_id brian m. carlson

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=20180225211212.477570-9-sandals@crustytoothpaste.net \
    --to=sandals@crustytoothpaste.net \
    --cc=git@vger.kernel.org \
    --cc=patryk.obara@gmail.com \
    --cc=pclouds@gmail.com \
    --cc=peff@peff.net \
    --cc=sunshine@sunshineco.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.
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 NNTP newsgroup(s).