All of lore.kernel.org
 help / color / mirror / Atom feed
From: "brian m. carlson" <sandals@crustytoothpaste.net>
To: git@vger.kernel.org
Cc: "Jeff King" <peff@peff.net>,
	"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>,
	"Junio C Hamano" <gitster@pobox.com>
Subject: [PATCH v2 11/21] sha1_name: convert struct disambiguate_state to object_id
Date: Sun, 26 Mar 2017 16:01:33 +0000	[thread overview]
Message-ID: <20170326160143.769630-12-sandals@crustytoothpaste.net> (raw)
In-Reply-To: <20170326160143.769630-1-sandals@crustytoothpaste.net>

Convert struct disambiguate_state to use struct object_id by changing
the structure definition and applying the following semantic patch:

@@
struct disambiguate_state E1;
@@
- E1.bin_pfx
+ E1.bin_pfx.hash

@@
struct disambiguate_state *E1;
@@
- E1->bin_pfx
+ E1->bin_pfx.hash

@@
struct disambiguate_state E1;
@@
- E1.candidate
+ E1.candidate.hash

@@
struct disambiguate_state *E1;
@@
- E1->candidate
+ E1->candidate.hash

This conversion is needed so we can convert disambiguate_hint_fn later.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 sha1_name.c | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/sha1_name.c b/sha1_name.c
index 3db166b40b..cf6f4be0c6 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -16,11 +16,11 @@ typedef int (*disambiguate_hint_fn)(const unsigned char *, void *);
 struct disambiguate_state {
 	int len; /* length of prefix in hex chars */
 	char hex_pfx[GIT_MAX_HEXSZ + 1];
-	unsigned char bin_pfx[GIT_MAX_RAWSZ];
+	struct object_id bin_pfx;
 
 	disambiguate_hint_fn fn;
 	void *cb_data;
-	unsigned char candidate[GIT_MAX_RAWSZ];
+	struct object_id candidate;
 	unsigned candidate_exists:1;
 	unsigned candidate_checked:1;
 	unsigned candidate_ok:1;
@@ -37,10 +37,10 @@ static void update_candidates(struct disambiguate_state *ds, const unsigned char
 	}
 	if (!ds->candidate_exists) {
 		/* this is the first candidate */
-		hashcpy(ds->candidate, current);
+		hashcpy(ds->candidate.hash, current);
 		ds->candidate_exists = 1;
 		return;
-	} else if (!hashcmp(ds->candidate, current)) {
+	} else if (!hashcmp(ds->candidate.hash, current)) {
 		/* the same as what we already have seen */
 		return;
 	}
@@ -52,14 +52,14 @@ static void update_candidates(struct disambiguate_state *ds, const unsigned char
 	}
 
 	if (!ds->candidate_checked) {
-		ds->candidate_ok = ds->fn(ds->candidate, ds->cb_data);
+		ds->candidate_ok = ds->fn(ds->candidate.hash, ds->cb_data);
 		ds->disambiguate_fn_used = 1;
 		ds->candidate_checked = 1;
 	}
 
 	if (!ds->candidate_ok) {
 		/* discard the candidate; we know it does not satisfy fn */
-		hashcpy(ds->candidate, current);
+		hashcpy(ds->candidate.hash, current);
 		ds->candidate_checked = 0;
 		return;
 	}
@@ -151,7 +151,7 @@ static void unique_in_pack(struct packed_git *p,
 		int cmp;
 
 		current = nth_packed_object_sha1(p, mid);
-		cmp = hashcmp(ds->bin_pfx, current);
+		cmp = hashcmp(ds->bin_pfx.hash, current);
 		if (!cmp) {
 			first = mid;
 			break;
@@ -170,7 +170,7 @@ static void unique_in_pack(struct packed_git *p,
 	 */
 	for (i = first; i < num && !ds->ambiguous; i++) {
 		current = nth_packed_object_sha1(p, i);
-		if (!match_sha(ds->len, ds->bin_pfx, current))
+		if (!match_sha(ds->len, ds->bin_pfx.hash, current))
 			break;
 		update_candidates(ds, current);
 	}
@@ -213,12 +213,12 @@ static int finish_object_disambiguation(struct disambiguate_state *ds,
 		 * same repository!
 		 */
 		ds->candidate_ok = (!ds->disambiguate_fn_used ||
-				    ds->fn(ds->candidate, ds->cb_data));
+				    ds->fn(ds->candidate.hash, ds->cb_data));
 
 	if (!ds->candidate_ok)
 		return SHORT_NAME_AMBIGUOUS;
 
-	hashcpy(sha1, ds->candidate);
+	hashcpy(sha1, ds->candidate.hash);
 	return 0;
 }
 
@@ -332,7 +332,7 @@ static int init_object_disambiguation(const char *name, int len,
 		ds->hex_pfx[i] = c;
 		if (!(i & 1))
 			val <<= 4;
-		ds->bin_pfx[i >> 1] |= val;
+		ds->bin_pfx.hash[i >> 1] |= val;
 	}
 
 	ds->len = len;

  parent reply	other threads:[~2017-03-26 16:03 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-26 16:01 [PATCH v2 00/21] object_id part 7 brian m. carlson
2017-03-26 16:01 ` [PATCH v2 01/21] Define new hash-size constants for allocating memory brian m. carlson
2017-03-26 16:01 ` [PATCH v2 02/21] Convert GIT_SHA1_HEXSZ used for allocation to GIT_MAX_HEXSZ brian m. carlson
2017-03-26 16:01 ` [PATCH v2 03/21] Convert GIT_SHA1_RAWSZ used for allocation to GIT_MAX_RAWSZ brian m. carlson
2017-03-26 16:01 ` [PATCH v2 04/21] builtin/diff: convert to struct object_id brian m. carlson
2017-03-26 16:01 ` [PATCH v2 05/21] builtin/pull: convert portions " brian m. carlson
2017-03-26 16:01 ` [PATCH v2 06/21] builtin/receive-pack: fix incorrect pointer arithmetic brian m. carlson
2017-03-28  6:51   ` Jeff King
2017-03-28 16:58     ` Junio C Hamano
2017-03-26 16:01 ` [PATCH v2 07/21] builtin/receive-pack: convert portions to struct object_id brian m. carlson
2017-03-28  7:07   ` Jeff King
2017-03-29 23:21     ` brian m. carlson
2017-03-30  1:37       ` Jeff King
2017-03-26 16:01 ` [PATCH v2 08/21] fsck: convert init_skiplist " brian m. carlson
2017-03-26 16:01 ` [PATCH v2 09/21] parse-options-cb: convert sha1_array_append caller " brian m. carlson
2017-03-26 16:01 ` [PATCH v2 10/21] test-sha1-array: convert most code " brian m. carlson
2017-03-26 16:01 ` brian m. carlson [this message]
2017-03-26 16:01 ` [PATCH v2 12/21] sha1_name: convert disambiguate_hint_fn to take object_id brian m. carlson
2017-03-26 16:01 ` [PATCH v2 13/21] submodule: convert check_for_new_submodule_commits to object_id brian m. carlson
2017-03-26 16:01 ` [PATCH v2 14/21] builtin/pull: convert to struct object_id brian m. carlson
2017-03-26 16:01 ` [PATCH v2 15/21] sha1-array: convert internal storage for struct sha1_array to object_id brian m. carlson
2017-03-28  7:24   ` Jeff King
2017-03-26 16:01 ` [PATCH v2 16/21] Make sha1_array_append take a struct object_id * brian m. carlson
2017-03-28  7:26   ` Jeff King
2017-03-28 17:27   ` Junio C Hamano
2017-03-29  0:06     ` brian m. carlson
2017-03-29 15:14       ` Junio C Hamano
2017-03-29 22:28         ` brian m. carlson
2017-03-26 16:01 ` [PATCH v2 17/21] Convert remaining callers of sha1_array_lookup to object_id brian m. carlson
2017-03-26 16:01 ` [PATCH v2 18/21] Convert sha1_array_lookup to take struct object_id brian m. carlson
2017-03-26 16:01 ` [PATCH v2 19/21] Convert sha1_array_for_each_unique and for_each_abbrev to object_id brian m. carlson
2017-03-26 16:01 ` [PATCH v2 20/21] Rename sha1_array to oid_array brian m. carlson
2017-03-26 16:01 ` [PATCH v2 21/21] Documentation: update and rename api-sha1-array.txt brian m. carlson
2017-03-28  7:31 ` [PATCH v2 00/21] object_id part 7 Jeff King
2017-03-28 11:13   ` brian m. carlson
2017-03-28 17:35     ` Jeff King
2017-03-28 17:42       ` Jeff King
2017-03-28 19:40         ` Junio C Hamano
2017-03-28 20:00           ` Jeff King
2017-03-28 17:32   ` Junio C Hamano

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=20170326160143.769630-12-sandals@crustytoothpaste.net \
    --to=sandals@crustytoothpaste.net \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=pclouds@gmail.com \
    --cc=peff@peff.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.