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: "Michael Haggerty" <mhagger@alum.mit.edu>,
	"Stefan Beller" <sbeller@google.com>, "Jeff King" <peff@peff.net>,
	"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH v2 01/53] fetch-pack: convert to struct object_id
Date: Mon,  1 May 2017 02:28:54 +0000	[thread overview]
Message-ID: <20170501022946.258735-2-sandals@crustytoothpaste.net> (raw)
In-Reply-To: <20170501022946.258735-1-sandals@crustytoothpaste.net>

Convert all uses of unsigned char [20] to struct object_id.  Switch one
use of get_sha1_hex to parse_oid_hex to avoid the need for a constant.
This change is necessary in order to convert parse_object.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 fetch-pack.c | 89 ++++++++++++++++++++++++++++++------------------------------
 1 file changed, 45 insertions(+), 44 deletions(-)

diff --git a/fetch-pack.c b/fetch-pack.c
index afb8b0502..b42d01f42 100644
--- a/fetch-pack.c
+++ b/fetch-pack.c
@@ -118,9 +118,9 @@ static void rev_list_push(struct commit *commit, int mark)
 	}
 }
 
-static int rev_list_insert_ref(const char *refname, const unsigned char *sha1)
+static int rev_list_insert_ref(const char *refname, const struct object_id *oid)
 {
-	struct object *o = deref_tag(parse_object(sha1), refname, 0);
+	struct object *o = deref_tag(parse_object(oid->hash), refname, 0);
 
 	if (o && o->type == OBJ_COMMIT)
 		rev_list_push((struct commit *)o, SEEN);
@@ -131,7 +131,7 @@ static int rev_list_insert_ref(const char *refname, const unsigned char *sha1)
 static int rev_list_insert_ref_oid(const char *refname, const struct object_id *oid,
 				   int flag, void *cb_data)
 {
-	return rev_list_insert_ref(refname, oid->hash);
+	return rev_list_insert_ref(refname, oid);
 }
 
 static int clear_marks(const char *refname, const struct object_id *oid,
@@ -183,7 +183,7 @@ static void mark_common(struct commit *commit,
   Get the next rev to send, ignoring the common.
 */
 
-static const unsigned char *get_rev(void)
+static const struct object_id *get_rev(void)
 {
 	struct commit *commit = NULL;
 
@@ -222,7 +222,7 @@ static const unsigned char *get_rev(void)
 		}
 	}
 
-	return commit->object.oid.hash;
+	return &commit->object.oid;
 }
 
 enum ack_type {
@@ -251,7 +251,7 @@ static void consume_shallow_list(struct fetch_pack_args *args, int fd)
 	}
 }
 
-static enum ack_type get_ack(int fd, unsigned char *result_sha1)
+static enum ack_type get_ack(int fd, struct object_id *result_oid)
 {
 	int len;
 	char *line = packet_read_line(fd, &len);
@@ -262,7 +262,7 @@ static enum ack_type get_ack(int fd, unsigned char *result_sha1)
 	if (!strcmp(line, "NAK"))
 		return NAK;
 	if (skip_prefix(line, "ACK ", &arg)) {
-		if (!get_sha1_hex(arg, result_sha1)) {
+		if (!get_oid_hex(arg, result_oid)) {
 			arg += 40;
 			len -= arg - line;
 			if (len < 1)
@@ -293,7 +293,7 @@ static void send_request(struct fetch_pack_args *args,
 
 static void insert_one_alternate_object(struct object *obj)
 {
-	rev_list_insert_ref(NULL, obj->oid.hash);
+	rev_list_insert_ref(NULL, &obj->oid);
 }
 
 #define INITIAL_FLUSH 16
@@ -317,12 +317,12 @@ static int next_flush(struct fetch_pack_args *args, int count)
 }
 
 static int find_common(struct fetch_pack_args *args,
-		       int fd[2], unsigned char *result_sha1,
+		       int fd[2], struct object_id *result_oid,
 		       struct ref *refs)
 {
 	int fetching;
 	int count = 0, flushes = 0, flush_at = INITIAL_FLUSH, retval;
-	const unsigned char *sha1;
+	const struct object_id *oid;
 	unsigned in_vain = 0;
 	int got_continue = 0;
 	int got_ready = 0;
@@ -340,7 +340,7 @@ static int find_common(struct fetch_pack_args *args,
 
 	fetching = 0;
 	for ( ; refs ; refs = refs->next) {
-		unsigned char *remote = refs->old_oid.hash;
+		struct object_id *remote = &refs->old_oid;
 		const char *remote_hex;
 		struct object *o;
 
@@ -354,12 +354,12 @@ static int find_common(struct fetch_pack_args *args,
 		 * interested in the case we *know* the object is
 		 * reachable and we have already scanned it.
 		 */
-		if (((o = lookup_object(remote)) != NULL) &&
+		if (((o = lookup_object(remote->hash)) != NULL) &&
 				(o->flags & COMPLETE)) {
 			continue;
 		}
 
-		remote_hex = sha1_to_hex(remote);
+		remote_hex = oid_to_hex(remote);
 		if (!fetching) {
 			struct strbuf c = STRBUF_INIT;
 			if (multi_ack == 2)     strbuf_addstr(&c, " multi_ack_detailed");
@@ -410,25 +410,25 @@ static int find_common(struct fetch_pack_args *args,
 	if (args->deepen) {
 		char *line;
 		const char *arg;
-		unsigned char sha1[20];
+		struct object_id oid;
 
 		send_request(args, fd[1], &req_buf);
 		while ((line = packet_read_line(fd[0], NULL))) {
 			if (skip_prefix(line, "shallow ", &arg)) {
-				if (get_sha1_hex(arg, sha1))
+				if (get_oid_hex(arg, &oid))
 					die(_("invalid shallow line: %s"), line);
-				register_shallow(sha1);
+				register_shallow(oid.hash);
 				continue;
 			}
 			if (skip_prefix(line, "unshallow ", &arg)) {
-				if (get_sha1_hex(arg, sha1))
+				if (get_oid_hex(arg, &oid))
 					die(_("invalid unshallow line: %s"), line);
-				if (!lookup_object(sha1))
+				if (!lookup_object(oid.hash))
 					die(_("object not found: %s"), line);
 				/* make sure that it is parsed as shallow */
-				if (!parse_object(sha1))
+				if (!parse_object(oid.hash))
 					die(_("error in object: %s"), line);
-				if (unregister_shallow(sha1))
+				if (unregister_shallow(oid.hash))
 					die(_("no shallow found: %s"), line);
 				continue;
 			}
@@ -447,9 +447,9 @@ static int find_common(struct fetch_pack_args *args,
 
 	flushes = 0;
 	retval = -1;
-	while ((sha1 = get_rev())) {
-		packet_buf_write(&req_buf, "have %s\n", sha1_to_hex(sha1));
-		print_verbose(args, "have %s", sha1_to_hex(sha1));
+	while ((oid = get_rev())) {
+		packet_buf_write(&req_buf, "have %s\n", oid_to_hex(oid));
+		print_verbose(args, "have %s", oid_to_hex(oid));
 		in_vain++;
 		if (flush_at <= ++count) {
 			int ack;
@@ -469,10 +469,10 @@ static int find_common(struct fetch_pack_args *args,
 
 			consume_shallow_list(args, fd[0]);
 			do {
-				ack = get_ack(fd[0], result_sha1);
+				ack = get_ack(fd[0], result_oid);
 				if (ack)
 					print_verbose(args, _("got %s %d %s"), "ack",
-						      ack, sha1_to_hex(result_sha1));
+						      ack, oid_to_hex(result_oid));
 				switch (ack) {
 				case ACK:
 					flushes = 0;
@@ -483,9 +483,9 @@ static int find_common(struct fetch_pack_args *args,
 				case ACK_ready:
 				case ACK_continue: {
 					struct commit *commit =
-						lookup_commit(result_sha1);
+						lookup_commit(result_oid->hash);
 					if (!commit)
-						die(_("invalid commit %s"), sha1_to_hex(result_sha1));
+						die(_("invalid commit %s"), oid_to_hex(result_oid));
 					if (args->stateless_rpc
 					 && ack == ACK_common
 					 && !(commit->object.flags & COMMON)) {
@@ -493,7 +493,7 @@ static int find_common(struct fetch_pack_args *args,
 						 * on the next RPC request so the peer knows
 						 * it is in common with us.
 						 */
-						const char *hex = sha1_to_hex(result_sha1);
+						const char *hex = oid_to_hex(result_oid);
 						packet_buf_write(&req_buf, "have %s\n", hex);
 						state_len = req_buf.len;
 						/*
@@ -538,10 +538,10 @@ static int find_common(struct fetch_pack_args *args,
 	if (!got_ready || !no_done)
 		consume_shallow_list(args, fd[0]);
 	while (flushes || multi_ack) {
-		int ack = get_ack(fd[0], result_sha1);
+		int ack = get_ack(fd[0], result_oid);
 		if (ack) {
 			print_verbose(args, _("got %s (%d) %s"), "ack",
-				      ack, sha1_to_hex(result_sha1));
+				      ack, oid_to_hex(result_oid));
 			if (ack == ACK)
 				return 0;
 			multi_ack = 1;
@@ -555,9 +555,9 @@ static int find_common(struct fetch_pack_args *args,
 
 static struct commit_list *complete;
 
-static int mark_complete(const unsigned char *sha1)
+static int mark_complete(const struct object_id *oid)
 {
-	struct object *o = parse_object(sha1);
+	struct object *o = parse_object(oid->hash);
 
 	while (o && o->type == OBJ_TAG) {
 		struct tag *t = (struct tag *) o;
@@ -579,7 +579,7 @@ static int mark_complete(const unsigned char *sha1)
 static int mark_complete_oid(const char *refname, const struct object_id *oid,
 			     int flag, void *cb_data)
 {
-	return mark_complete(oid->hash);
+	return mark_complete(oid);
 }
 
 static void mark_recent_complete_commits(struct fetch_pack_args *args,
@@ -637,14 +637,15 @@ static void filter_refs(struct fetch_pack_args *args,
 
 	/* Append unmatched requests to the list */
 	for (i = 0; i < nr_sought; i++) {
-		unsigned char sha1[20];
+		struct object_id oid;
+		const char *p;
 
 		ref = sought[i];
 		if (ref->match_status != REF_NOT_MATCHED)
 			continue;
-		if (get_sha1_hex(ref->name, sha1) ||
-		    ref->name[40] != '\0' ||
-		    hashcmp(sha1, ref->old_oid.hash))
+		if (parse_oid_hex(ref->name, &oid, &p) ||
+		    *p != '\0' ||
+		    oidcmp(&oid, &ref->old_oid))
 			continue;
 
 		if ((allow_unadvertised_object_request &
@@ -661,7 +662,7 @@ static void filter_refs(struct fetch_pack_args *args,
 
 static void mark_alternate_complete(struct object *obj)
 {
-	mark_complete(obj->oid.hash);
+	mark_complete(&obj->oid);
 }
 
 static int everything_local(struct fetch_pack_args *args,
@@ -724,17 +725,17 @@ static int everything_local(struct fetch_pack_args *args,
 	filter_refs(args, refs, sought, nr_sought);
 
 	for (retval = 1, ref = *refs; ref ; ref = ref->next) {
-		const unsigned char *remote = ref->old_oid.hash;
+		const struct object_id *remote = &ref->old_oid;
 		struct object *o;
 
-		o = lookup_object(remote);
+		o = lookup_object(remote->hash);
 		if (!o || !(o->flags & COMPLETE)) {
 			retval = 0;
-			print_verbose(args, "want %s (%s)", sha1_to_hex(remote),
+			print_verbose(args, "want %s (%s)", oid_to_hex(remote),
 				      ref->name);
 			continue;
 		}
-		print_verbose(args, _("already have %s (%s)"), sha1_to_hex(remote),
+		print_verbose(args, _("already have %s (%s)"), oid_to_hex(remote),
 			      ref->name);
 	}
 	return retval;
@@ -873,7 +874,7 @@ static struct ref *do_fetch_pack(struct fetch_pack_args *args,
 				 char **pack_lockfile)
 {
 	struct ref *ref = copy_ref_list(orig_ref);
-	unsigned char sha1[20];
+	struct object_id oid;
 	const char *agent_feature;
 	int agent_len;
 
@@ -945,7 +946,7 @@ static struct ref *do_fetch_pack(struct fetch_pack_args *args,
 		packet_flush(fd[1]);
 		goto all_done;
 	}
-	if (find_common(args, fd, sha1, ref) < 0)
+	if (find_common(args, fd, &oid, ref) < 0)
 		if (!args->keep_pack)
 			/* When cloning, it is not unusual to have
 			 * no common commit.

  reply	other threads:[~2017-05-01  2:30 UTC|newest]

Thread overview: 69+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-01  2:28 [PATCH v2 00/53] object_id part 8 brian m. carlson
2017-05-01  2:28 ` brian m. carlson [this message]
2017-05-01  2:28 ` [PATCH v2 02/53] Clean up outstanding object_id transforms brian m. carlson
2017-05-02 18:05   ` Brandon Williams
2017-05-03 23:41     ` brian m. carlson
2017-05-01  2:28 ` [PATCH v2 03/53] Convert struct cache_tree to use struct object_id brian m. carlson
2017-05-02 18:13   ` Brandon Williams
2017-05-03 23:36     ` brian m. carlson
2017-05-01  2:28 ` [PATCH v2 04/53] builtin/name-rev: convert to " brian m. carlson
2017-05-01  2:28 ` [PATCH v2 05/53] builtin/prune: " brian m. carlson
2017-05-01  2:28 ` [PATCH v2 06/53] bundle: " brian m. carlson
2017-05-01  2:29 ` [PATCH v2 07/53] branch: " brian m. carlson
2017-05-01  2:29 ` [PATCH v2 08/53] builtin/blame: convert static function " brian m. carlson
2017-05-01  2:29 ` [PATCH v2 09/53] builtin/rev-parse: convert " brian m. carlson
2017-05-01 21:54   ` Jonathan Tan
2017-05-01  2:29 ` [PATCH v2 10/53] fast-import: convert internal structs " brian m. carlson
2017-05-01  2:29 ` [PATCH v2 11/53] fast-import: convert " brian m. carlson
2017-05-01 22:07   ` Jonathan Tan
2017-05-01 22:27     ` Jeff King
2017-05-01 22:36       ` Jonathan Tan
2017-05-03 23:34       ` brian m. carlson
2017-05-01  2:29 ` [PATCH v2 12/53] submodule: convert merge_submodule to use " brian m. carlson
2017-05-01  2:29 ` [PATCH v2 13/53] notes-cache: convert to " brian m. carlson
2017-05-01  2:29 ` [PATCH v2 14/53] parse-options-cb: " brian m. carlson
2017-05-01  2:29 ` [PATCH v2 15/53] reflog_expire: " brian m. carlson
2017-05-01  2:29 ` [PATCH v2 16/53] builtin/verify-commit: " brian m. carlson
2017-05-01  2:29 ` [PATCH v2 17/53] tag: convert parse_tag_buffer " brian m. carlson
2017-05-01  2:29 ` [PATCH v2 18/53] http-push: convert some static functions " brian m. carlson
2017-05-01  2:29 ` [PATCH v2 19/53] notes-utils: convert internals " brian m. carlson
2017-05-01  2:29 ` [PATCH v2 20/53] revision: convert prepare_show_merge " brian m. carlson
2017-05-01  2:29 ` [PATCH v2 21/53] shallow: convert shallow registration functions to object_id brian m. carlson
2017-05-01  2:29 ` [PATCH v2 22/53] sequencer: convert some functions to struct object_id brian m. carlson
2017-05-01  2:29 ` [PATCH v2 23/53] builtin/tag: convert " brian m. carlson
2017-05-01  2:29 ` [PATCH v2 24/53] Convert remaining callers of lookup_commit_reference* to object_id brian m. carlson
2017-05-01  2:29 ` [PATCH v2 25/53] Convert lookup_commit* to struct object_id brian m. carlson
2017-05-01  2:29 ` [PATCH v2 26/53] pack: convert struct pack_idx_entry " brian m. carlson
2017-05-01  2:29 ` [PATCH v2 27/53] builtin/unpack-objects: convert " brian m. carlson
2017-05-01  2:29 ` [PATCH v2 28/53] Convert remaining callers of lookup_blob to object_id brian m. carlson
2017-05-01  2:29 ` [PATCH v2 29/53] Convert lookup_blob to struct object_id brian m. carlson
2017-05-01  2:29 ` [PATCH v2 30/53] tree: convert read_tree_1 to use struct object_id internally brian m. carlson
2017-05-01  2:29 ` [PATCH v2 31/53] builtin/reflog: convert tree_is_complete to take struct object_id brian m. carlson
2017-05-01  2:29 ` [PATCH v2 32/53] Convert lookup_tree to " brian m. carlson
2017-05-01  2:29 ` [PATCH v2 33/53] log-tree: convert " brian m. carlson
2017-05-01  2:29 ` [PATCH v2 34/53] Convert lookup_tag " brian m. carlson
2017-05-01  2:29 ` [PATCH v2 35/53] Convert the verify_pack callback " brian m. carlson
2017-05-01  2:29 ` [PATCH v2 36/53] Convert struct ref_array_item " brian m. carlson
2017-05-01  2:29 ` [PATCH v2 37/53] ref-filter: convert some static functions " brian m. carlson
2017-05-01  2:29 ` [PATCH v2 38/53] refs: convert struct ref_update to use " brian m. carlson
2017-05-01  2:29 ` [PATCH v2 39/53] refs/files-backend: convert many internals to " brian m. carlson
2017-05-01 23:24   ` Jonathan Tan
2017-05-03 23:30     ` brian m. carlson
2017-05-01  2:29 ` [PATCH v2 40/53] http-push: convert process_ls_object and descendants to object_id brian m. carlson
2017-05-01  2:29 ` [PATCH v2 41/53] revision: rename add_pending_sha1 to add_pending_oid brian m. carlson
2017-05-01  2:29 ` [PATCH v2 42/53] revision: convert remaining parse_object callers to object_id brian m. carlson
2017-05-01  2:29 ` [PATCH v2 43/53] upload-pack: " brian m. carlson
2017-05-01  2:29 ` [PATCH v2 44/53] sha1_name: convert internals of peel_onion " brian m. carlson
2017-05-01  2:29 ` [PATCH v2 45/53] builtin/read-tree: convert to struct object_id brian m. carlson
2017-05-01  2:29 ` [PATCH v2 46/53] builtin/ls-files: convert overlay_tree_on_cache to object_id brian m. carlson
2017-05-01  2:29 ` [PATCH v2 47/53] sequencer: convert fast_forward_to to struct object_id brian m. carlson
2017-05-01  2:29 ` [PATCH v2 48/53] merge: convert checkout_fast_forward " brian m. carlson
2017-05-01  2:29 ` [PATCH v2 49/53] builtin/ls-tree: convert " brian m. carlson
2017-05-01  2:29 ` [PATCH v2 50/53] diff-lib: convert do_diff_cache " brian m. carlson
2017-05-01  2:29 ` [PATCH v2 51/53] sequencer: convert do_recursive_merge " brian m. carlson
2017-05-01  2:29 ` [PATCH v2 52/53] tree: convert parse_tree_indirect " brian m. carlson
2017-05-01  2:29 ` [PATCH v2 53/53] object: convert parse_object* to take " brian m. carlson
2017-05-01 23:44   ` Jonathan Tan
2017-05-01 21:10 ` [PATCH v2 00/53] object_id part 8 Stefan Beller
2017-05-02 19:09 ` Brandon Williams
2017-05-04  0:50 ` 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

  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=20170501022946.258735-2-sandals@crustytoothpaste.net \
    --to=sandals@crustytoothpaste.net \
    --cc=git@vger.kernel.org \
    --cc=mhagger@alum.mit.edu \
    --cc=pclouds@gmail.com \
    --cc=peff@peff.net \
    --cc=sbeller@google.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).