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 19/21] Convert sha1_array_for_each_unique and for_each_abbrev to object_id
Date: Sun, 26 Mar 2017 16:01:41 +0000	[thread overview]
Message-ID: <20170326160143.769630-20-sandals@crustytoothpaste.net> (raw)
In-Reply-To: <20170326160143.769630-1-sandals@crustytoothpaste.net>

Make sha1_array_for_each_unique take a callback using struct object_id.
Since one of these callbacks is an argument to for_each_abbrev, convert
those as well.  Rename various functions, replacing "sha1" with "oid".

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 builtin/cat-file.c         |  4 ++--
 builtin/receive-pack.c     | 12 ++++++------
 builtin/rev-parse.c        |  4 ++--
 cache.h                    |  2 +-
 sha1-array.c               |  4 ++--
 sha1-array.h               |  6 +++---
 sha1_name.c                | 14 ++++++--------
 submodule.c                | 20 ++++++++++----------
 t/helper/test-sha1-array.c |  6 +++---
 9 files changed, 35 insertions(+), 37 deletions(-)

diff --git a/builtin/cat-file.c b/builtin/cat-file.c
index 8fbb667170..eb0043231d 100644
--- a/builtin/cat-file.c
+++ b/builtin/cat-file.c
@@ -401,10 +401,10 @@ struct object_cb_data {
 	struct expand_data *expand;
 };
 
-static int batch_object_cb(const unsigned char sha1[20], void *vdata)
+static int batch_object_cb(const struct object_id *oid, void *vdata)
 {
 	struct object_cb_data *data = vdata;
-	hashcpy(data->expand->oid.hash, sha1);
+	oidcpy(&data->expand->oid, oid);
 	batch_object_write(NULL, data->opt, data->expand);
 	return 0;
 }
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index 56d1a59922..5b83e4c87b 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -225,10 +225,10 @@ static int receive_pack_config(const char *var, const char *value, void *cb)
 	return git_default_config(var, value, cb);
 }
 
-static void show_ref(const char *path, const unsigned char *sha1)
+static void show_ref(const char *path, const struct object_id *oid)
 {
 	if (sent_capabilities) {
-		packet_write_fmt(1, "%s %s\n", sha1_to_hex(sha1), path);
+		packet_write_fmt(1, "%s %s\n", oid_to_hex(oid), path);
 	} else {
 		struct strbuf cap = STRBUF_INIT;
 
@@ -244,7 +244,7 @@ static void show_ref(const char *path, const unsigned char *sha1)
 			strbuf_addstr(&cap, " push-options");
 		strbuf_addf(&cap, " agent=%s", git_user_agent_sanitized());
 		packet_write_fmt(1, "%s %s%c%s\n",
-			     sha1_to_hex(sha1), path, 0, cap.buf);
+			     oid_to_hex(oid), path, 0, cap.buf);
 		strbuf_release(&cap);
 		sent_capabilities = 1;
 	}
@@ -271,7 +271,7 @@ static int show_ref_cb(const char *path_full, const struct object_id *oid,
 	} else {
 		oidset_insert(seen, oid);
 	}
-	show_ref(path, oid->hash);
+	show_ref(path, oid);
 	return 0;
 }
 
@@ -284,7 +284,7 @@ static void show_one_alternate_ref(const char *refname,
 	if (oidset_insert(seen, oid))
 		return;
 
-	show_ref(".have", oid->hash);
+	show_ref(".have", oid);
 }
 
 static void write_head_info(void)
@@ -295,7 +295,7 @@ static void write_head_info(void)
 	for_each_alternate_ref(show_one_alternate_ref, &seen);
 	oidset_clear(&seen);
 	if (!sent_capabilities)
-		show_ref("capabilities^{}", null_sha1);
+		show_ref("capabilities^{}", &null_oid);
 
 	advertise_shallow_grafts(1);
 
diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c
index 1e5bdea0d5..8d635add8f 100644
--- a/builtin/rev-parse.c
+++ b/builtin/rev-parse.c
@@ -205,9 +205,9 @@ static int anti_reference(const char *refname, const struct object_id *oid, int
 	return 0;
 }
 
-static int show_abbrev(const unsigned char *sha1, void *cb_data)
+static int show_abbrev(const struct object_id *oid, void *cb_data)
 {
-	show_rev(NORMAL, sha1, NULL);
+	show_rev(NORMAL, oid->hash, NULL);
 	return 0;
 }
 
diff --git a/cache.h b/cache.h
index 179bdc5da2..93e7f0d000 100644
--- a/cache.h
+++ b/cache.h
@@ -1350,7 +1350,7 @@ extern int get_sha1_with_context(const char *str, unsigned flags, unsigned char
 
 extern int get_oid(const char *str, struct object_id *oid);
 
-typedef int each_abbrev_fn(const unsigned char *sha1, void *);
+typedef int each_abbrev_fn(const struct object_id *oid, void *);
 extern int for_each_abbrev(const char *prefix, each_abbrev_fn, void *);
 
 extern int set_disambiguate_hint_config(const char *var, const char *value);
diff --git a/sha1-array.c b/sha1-array.c
index 1082b3dc11..82a7f4435c 100644
--- a/sha1-array.c
+++ b/sha1-array.c
@@ -43,7 +43,7 @@ void sha1_array_clear(struct sha1_array *array)
 }
 
 int sha1_array_for_each_unique(struct sha1_array *array,
-				for_each_sha1_fn fn,
+				for_each_oid_fn fn,
 				void *data)
 {
 	int i;
@@ -55,7 +55,7 @@ int sha1_array_for_each_unique(struct sha1_array *array,
 		int ret;
 		if (i > 0 && !oidcmp(array->oid + i, array->oid + i - 1))
 			continue;
-		ret = fn(array->oid[i].hash, data);
+		ret = fn(array->oid + i, data);
 		if (ret)
 			return ret;
 	}
diff --git a/sha1-array.h b/sha1-array.h
index 4cc55b15af..e2bb139efb 100644
--- a/sha1-array.h
+++ b/sha1-array.h
@@ -14,10 +14,10 @@ void sha1_array_append(struct sha1_array *array, const struct object_id *sha1);
 int sha1_array_lookup(struct sha1_array *array, const struct object_id *oid);
 void sha1_array_clear(struct sha1_array *array);
 
-typedef int (*for_each_sha1_fn)(const unsigned char sha1[20],
-				void *data);
+typedef int (*for_each_oid_fn)(const struct object_id *oid,
+			       void *data);
 int sha1_array_for_each_unique(struct sha1_array *array,
-			       for_each_sha1_fn fn,
+			       for_each_oid_fn fn,
 			       void *data);
 
 #endif /* SHA1_ARRAY_H */
diff --git a/sha1_name.c b/sha1_name.c
index 1316832d73..a9501fb964 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -342,34 +342,32 @@ static int init_object_disambiguation(const char *name, int len,
 	return 0;
 }
 
-static int show_ambiguous_object(const unsigned char *sha1, void *data)
+static int show_ambiguous_object(const struct object_id *oid, void *data)
 {
 	const struct disambiguate_state *ds = data;
-	struct object_id oid;
 	struct strbuf desc = STRBUF_INIT;
 	int type;
 
 
-	hashcpy(oid.hash, sha1);
-	if (ds->fn && !ds->fn(&oid, ds->cb_data))
+	if (ds->fn && !ds->fn(oid, ds->cb_data))
 		return 0;
 
-	type = sha1_object_info(sha1, NULL);
+	type = sha1_object_info(oid->hash, NULL);
 	if (type == OBJ_COMMIT) {
-		struct commit *commit = lookup_commit(sha1);
+		struct commit *commit = lookup_commit(oid->hash);
 		if (commit) {
 			struct pretty_print_context pp = {0};
 			pp.date_mode.type = DATE_SHORT;
 			format_commit_message(commit, " %ad - %s", &desc, &pp);
 		}
 	} else if (type == OBJ_TAG) {
-		struct tag *tag = lookup_tag(sha1);
+		struct tag *tag = lookup_tag(oid->hash);
 		if (!parse_tag(tag) && tag->tag)
 			strbuf_addf(&desc, " %s", tag->tag);
 	}
 
 	advise("  %s %s%s",
-	       find_unique_abbrev(sha1, DEFAULT_ABBREV),
+	       find_unique_abbrev(oid->hash, DEFAULT_ABBREV),
 	       typename(type) ? typename(type) : "unknown type",
 	       desc.buf);
 
diff --git a/submodule.c b/submodule.c
index 7912cba4f6..29dd91c793 100644
--- a/submodule.c
+++ b/submodule.c
@@ -551,18 +551,18 @@ static int has_remote(const char *refname, const struct object_id *oid,
 	return 1;
 }
 
-static int append_sha1_to_argv(const unsigned char sha1[20], void *data)
+static int append_oid_to_argv(const struct object_id *oid, void *data)
 {
 	struct argv_array *argv = data;
-	argv_array_push(argv, sha1_to_hex(sha1));
+	argv_array_push(argv, oid_to_hex(oid));
 	return 0;
 }
 
-static int check_has_commit(const unsigned char sha1[20], void *data)
+static int check_has_commit(const struct object_id *oid, void *data)
 {
 	int *has_commit = data;
 
-	if (!lookup_commit_reference(sha1))
+	if (!lookup_commit_reference(oid->hash))
 		*has_commit = 0;
 
 	return 0;
@@ -601,7 +601,7 @@ static int submodule_needs_pushing(const char *path, struct sha1_array *commits)
 		int needs_pushing = 0;
 
 		argv_array_push(&cp.args, "rev-list");
-		sha1_array_for_each_unique(commits, append_sha1_to_argv, &cp.args);
+		sha1_array_for_each_unique(commits, append_oid_to_argv, &cp.args);
 		argv_array_pushl(&cp.args, "--not", "--remotes", "-n", "1" , NULL);
 
 		prepare_submodule_repo_env(&cp.env_array);
@@ -687,7 +687,7 @@ int find_unpushed_submodules(struct sha1_array *commits,
 
 	/* argv.argv[0] will be ignored by setup_revisions */
 	argv_array_push(&argv, "find_unpushed_submodules");
-	sha1_array_for_each_unique(commits, append_sha1_to_argv, &argv);
+	sha1_array_for_each_unique(commits, append_oid_to_argv, &argv);
 	argv_array_push(&argv, "--not");
 	argv_array_pushf(&argv, "--remotes=%s", remotes_name);
 
@@ -831,9 +831,9 @@ void check_for_new_submodule_commits(struct object_id *oid)
 	sha1_array_append(&ref_tips_after_fetch, oid);
 }
 
-static int add_sha1_to_argv(const unsigned char sha1[20], void *data)
+static int add_oid_to_argv(const struct object_id *oid, void *data)
 {
-	argv_array_push(data, sha1_to_hex(sha1));
+	argv_array_push(data, oid_to_hex(oid));
 	return 0;
 }
 
@@ -850,10 +850,10 @@ static void calculate_changed_submodule_paths(void)
 	init_revisions(&rev, NULL);
 	argv_array_push(&argv, "--"); /* argv[0] program name */
 	sha1_array_for_each_unique(&ref_tips_after_fetch,
-				   add_sha1_to_argv, &argv);
+				   add_oid_to_argv, &argv);
 	argv_array_push(&argv, "--not");
 	sha1_array_for_each_unique(&ref_tips_before_fetch,
-				   add_sha1_to_argv, &argv);
+				   add_oid_to_argv, &argv);
 	setup_revisions(argv.argc, argv.argv, &rev, NULL);
 	if (prepare_revision_walk(&rev))
 		die("revision walk setup failed");
diff --git a/t/helper/test-sha1-array.c b/t/helper/test-sha1-array.c
index 3680511849..2f3d406b63 100644
--- a/t/helper/test-sha1-array.c
+++ b/t/helper/test-sha1-array.c
@@ -1,9 +1,9 @@
 #include "cache.h"
 #include "sha1-array.h"
 
-static int print_sha1(const unsigned char sha1[20], void *data)
+static int print_oid(const struct object_id *oid, void *data)
 {
-	puts(sha1_to_hex(sha1));
+	puts(oid_to_hex(oid));
 	return 0;
 }
 
@@ -27,7 +27,7 @@ int cmd_main(int argc, const char **argv)
 		} else if (!strcmp(line.buf, "clear"))
 			sha1_array_clear(&array);
 		else if (!strcmp(line.buf, "for_each_unique"))
-			sha1_array_for_each_unique(&array, print_sha1, NULL);
+			sha1_array_for_each_unique(&array, print_oid, NULL);
 		else
 			die("unknown command: %s", line.buf);
 	}

  parent reply	other threads:[~2017-03-26 16:02 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 ` [PATCH v2 11/21] sha1_name: convert struct disambiguate_state to object_id brian m. carlson
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 ` brian m. carlson [this message]
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-20-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.