git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH 00/12] object_id part 9
@ 2017-07-03 18:55 brian m. carlson
  2017-07-03 18:55 ` [PATCH 01/12] builtin/fsck: convert remaining caller of get_sha1 to object_id brian m. carlson
                   ` (12 more replies)
  0 siblings, 13 replies; 20+ messages in thread
From: brian m. carlson @ 2017-07-03 18:55 UTC (permalink / raw)
  To: git; +Cc: Brandon Williams, Stefan Beller, Jeff King

This is the ninth in a series of series to convert Git to use struct
object_id.  This series converts the remaining callers of get_sha1 and
friends to take and use struct object_id, and in doing so, renames them
to get_oid and friends.

It is possible there will be some other conflicts with in flight topics,
as get_sha1 is commonly used in the codebase.  This is unavoidable to
some extent, but should be kept in mind.  My experience is that usually
the required changes for conversion are minimal.

This series is much reduced in size thanks to the conversion work done
by Brandon Williams in his earlier series touching the notes code.

brian m. carlson (12):
  builtin/fsck: convert remaining caller of get_sha1 to object_id
  builtin/merge-tree: convert remaining caller of get_sha1 to object_id
  submodule: convert submodule config lookup to use object_id
  remote: convert struct push_cas to struct object_id
  sequencer: convert to struct object_id
  builtin/update_ref: convert to struct object_id
  bisect: convert bisect_checkout to struct object_id
  builtin/unpack-file: convert to struct object_id
  builtin/verify-tag: convert to struct object_id
  Convert remaining callers of get_sha1 to get_oid.
  sha1_name: convert get_sha1* to get_oid*
  sha1_name: convert GET_SHA1* flags to GET_OID*

 apply.c                          |   4 +-
 archive.c                        |   2 +-
 bisect.c                         |  18 +--
 builtin/am.c                     |   6 +-
 builtin/cat-file.c               |   8 +-
 builtin/commit-tree.c            |   4 +-
 builtin/commit.c                 |   8 +-
 builtin/fsck.c                   |   8 +-
 builtin/grep.c                   |   8 +-
 builtin/log.c                    |   4 +-
 builtin/merge-tree.c             |   6 +-
 builtin/receive-pack.c           |   4 +-
 builtin/replace.c                |   4 +-
 builtin/reset.c                  |  10 +-
 builtin/rev-parse.c              |   8 +-
 builtin/show-branch.c            |   8 +-
 builtin/submodule--helper.c      |   8 +-
 builtin/unpack-file.c            |  12 +-
 builtin/update-ref.c             |  69 ++++++------
 builtin/verify-tag.c             |   8 +-
 cache.h                          |  45 ++++----
 commit.c                         |   4 +-
 config.c                         |  12 +-
 config.h                         |   4 +-
 mailmap.c                        |   6 +-
 notes.c                          |   2 +-
 refs.c                           |   2 +-
 remote.c                         |   8 +-
 remote.h                         |   2 +-
 revision.c                       |  16 +--
 sequencer.c                      |  65 +++++------
 sha1_name.c                      | 234 +++++++++++++++++++--------------------
 submodule-config.c               |  36 +++---
 submodule-config.h               |  10 +-
 submodule.c                      |  32 +++---
 submodule.h                      |   2 +-
 t/helper/test-submodule-config.c |  10 +-
 transport-helper.c               |   2 +-
 38 files changed, 345 insertions(+), 354 deletions(-)


^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PATCH 01/12] builtin/fsck: convert remaining caller of get_sha1 to object_id
  2017-07-03 18:55 [PATCH 00/12] object_id part 9 brian m. carlson
@ 2017-07-03 18:55 ` brian m. carlson
  2017-07-03 18:55 ` [PATCH 02/12] builtin/merge-tree: " brian m. carlson
                   ` (11 subsequent siblings)
  12 siblings, 0 replies; 20+ messages in thread
From: brian m. carlson @ 2017-07-03 18:55 UTC (permalink / raw)
  To: git; +Cc: Brandon Williams, Stefan Beller, Jeff King

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

diff --git a/builtin/fsck.c b/builtin/fsck.c
index 87c675689..d601d07fd 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -738,12 +738,12 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
 	heads = 0;
 	for (i = 0; i < argc; i++) {
 		const char *arg = argv[i];
-		unsigned char sha1[20];
-		if (!get_sha1(arg, sha1)) {
-			struct object *obj = lookup_object(sha1);
+		struct object_id oid;
+		if (!get_oid(arg, &oid)) {
+			struct object *obj = lookup_object(oid.hash);
 
 			if (!obj || !(obj->flags & HAS_OBJ)) {
-				error("%s: object missing", sha1_to_hex(sha1));
+				error("%s: object missing", oid_to_hex(&oid));
 				errors_found |= ERROR_OBJECT;
 				continue;
 			}

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH 02/12] builtin/merge-tree: convert remaining caller of get_sha1 to object_id
  2017-07-03 18:55 [PATCH 00/12] object_id part 9 brian m. carlson
  2017-07-03 18:55 ` [PATCH 01/12] builtin/fsck: convert remaining caller of get_sha1 to object_id brian m. carlson
@ 2017-07-03 18:55 ` brian m. carlson
  2017-07-03 18:55 ` [PATCH 03/12] submodule: convert submodule config lookup to use object_id brian m. carlson
                   ` (10 subsequent siblings)
  12 siblings, 0 replies; 20+ messages in thread
From: brian m. carlson @ 2017-07-03 18:55 UTC (permalink / raw)
  To: git; +Cc: Brandon Williams, Stefan Beller, Jeff King

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

diff --git a/builtin/merge-tree.c b/builtin/merge-tree.c
index bad6735c7..f12da292c 100644
--- a/builtin/merge-tree.c
+++ b/builtin/merge-tree.c
@@ -347,12 +347,12 @@ static void merge_trees(struct tree_desc t[3], const char *base)
 
 static void *get_tree_descriptor(struct tree_desc *desc, const char *rev)
 {
-	unsigned char sha1[20];
+	struct object_id oid;
 	void *buf;
 
-	if (get_sha1(rev, sha1))
+	if (get_oid(rev, &oid))
 		die("unknown rev %s", rev);
-	buf = fill_tree_descriptor(desc, sha1);
+	buf = fill_tree_descriptor(desc, oid.hash);
 	if (!buf)
 		die("%s is not a tree", rev);
 	return buf;

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH 03/12] submodule: convert submodule config lookup to use object_id
  2017-07-03 18:55 [PATCH 00/12] object_id part 9 brian m. carlson
  2017-07-03 18:55 ` [PATCH 01/12] builtin/fsck: convert remaining caller of get_sha1 to object_id brian m. carlson
  2017-07-03 18:55 ` [PATCH 02/12] builtin/merge-tree: " brian m. carlson
@ 2017-07-03 18:55 ` brian m. carlson
  2017-07-03 18:55 ` [PATCH 04/12] remote: convert struct push_cas to struct object_id brian m. carlson
                   ` (9 subsequent siblings)
  12 siblings, 0 replies; 20+ messages in thread
From: brian m. carlson @ 2017-07-03 18:55 UTC (permalink / raw)
  To: git; +Cc: Brandon Williams, Stefan Beller, Jeff King

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 builtin/grep.c                   |  4 ++--
 builtin/submodule--helper.c      |  8 ++++----
 config.c                         | 12 ++++++------
 config.h                         |  4 ++--
 submodule-config.c               | 36 ++++++++++++++++++------------------
 submodule-config.h               | 10 +++++-----
 submodule.c                      | 32 ++++++++++++++++----------------
 submodule.h                      |  2 +-
 t/helper/test-submodule-config.c | 10 +++++-----
 9 files changed, 59 insertions(+), 59 deletions(-)

diff --git a/builtin/grep.c b/builtin/grep.c
index f752f642f..397b5f049 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -652,7 +652,7 @@ static int grep_submodule(struct grep_opt *opt, const struct object_id *oid,
 		 */
 		if (oid) {
 			const struct submodule *sub =
-					submodule_from_path(null_sha1, path);
+					submodule_from_path(&null_oid, path);
 			if (sub)
 				path = git_path("modules/%s", sub->name);
 
@@ -861,7 +861,7 @@ static int grep_objects(struct grep_opt *opt, const struct pathspec *pathspec,
 		/* load the gitmodules file for this rev */
 		if (recurse_submodules) {
 			submodule_free();
-			gitmodules_config_sha1(real_obj->oid.hash);
+			gitmodules_config_oid(&real_obj->oid);
 		}
 		if (grep_object(opt, pathspec, real_obj, list->objects[i].name, list->objects[i].path)) {
 			hit = 1;
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index 8517032b3..45cb93287 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -350,7 +350,7 @@ static void init_submodule(const char *path, const char *prefix, int quiet)
 	} else
 		displaypath = xstrdup(path);
 
-	sub = submodule_from_path(null_sha1, path);
+	sub = submodule_from_path(&null_oid, path);
 
 	if (!sub)
 		die(_("No url found for submodule path '%s' in .gitmodules"),
@@ -476,7 +476,7 @@ static int module_name(int argc, const char **argv, const char *prefix)
 		usage(_("git submodule--helper name <path>"));
 
 	gitmodules_config();
-	sub = submodule_from_path(null_sha1, argv[1]);
+	sub = submodule_from_path(&null_oid, argv[1]);
 
 	if (!sub)
 		die(_("no submodule mapping found in .gitmodules for path '%s'"),
@@ -795,7 +795,7 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce,
 		goto cleanup;
 	}
 
-	sub = submodule_from_path(null_sha1, ce->name);
+	sub = submodule_from_path(&null_oid, ce->name);
 
 	if (suc->recursive_prefix)
 		displaypath = relative_path(suc->recursive_prefix,
@@ -1060,7 +1060,7 @@ static const char *remote_submodule_branch(const char *path)
 	gitmodules_config();
 	git_config(submodule_config, NULL);
 
-	sub = submodule_from_path(null_sha1, path);
+	sub = submodule_from_path(&null_oid, path);
 	if (!sub)
 		return NULL;
 
diff --git a/config.c b/config.c
index 1cd40a5fe..eb2dae5fb 100644
--- a/config.c
+++ b/config.c
@@ -1466,9 +1466,9 @@ int git_config_from_mem(config_fn_t fn, const enum config_origin_type origin_typ
 	return do_config_from(&top, fn, data);
 }
 
-int git_config_from_blob_sha1(config_fn_t fn,
+int git_config_from_blob_oid(config_fn_t fn,
 			      const char *name,
-			      const unsigned char *sha1,
+			      const struct object_id *oid,
 			      void *data)
 {
 	enum object_type type;
@@ -1476,7 +1476,7 @@ int git_config_from_blob_sha1(config_fn_t fn,
 	unsigned long size;
 	int ret;
 
-	buf = read_sha1_file(sha1, &type, &size);
+	buf = read_sha1_file(oid->hash, &type, &size);
 	if (!buf)
 		return error("unable to load config blob object '%s'", name);
 	if (type != OBJ_BLOB) {
@@ -1494,11 +1494,11 @@ static int git_config_from_blob_ref(config_fn_t fn,
 				    const char *name,
 				    void *data)
 {
-	unsigned char sha1[20];
+	struct object_id oid;
 
-	if (get_sha1(name, sha1) < 0)
+	if (get_oid(name, &oid) < 0)
 		return error("unable to resolve config blob '%s'", name);
-	return git_config_from_blob_sha1(fn, name, sha1, data);
+	return git_config_from_blob_oid(fn, name, &oid, data);
 }
 
 const char *git_etc_gitconfig(void)
diff --git a/config.h b/config.h
index 9e038cce2..033920048 100644
--- a/config.h
+++ b/config.h
@@ -39,8 +39,8 @@ extern int git_default_config(const char *, const char *, void *);
 extern int git_config_from_file(config_fn_t fn, const char *, void *);
 extern int git_config_from_mem(config_fn_t fn, const enum config_origin_type,
 					const char *name, const char *buf, size_t len, void *data);
-extern int git_config_from_blob_sha1(config_fn_t fn, const char *name,
-				     const unsigned char *sha1, void *data);
+extern int git_config_from_blob_oid(config_fn_t fn, const char *name,
+				    const struct object_id *oid, void *data);
 extern void git_config_push_parameter(const char *text);
 extern int git_config_from_parameters(config_fn_t fn, void *data);
 extern void read_early_config(config_fn_t cb, void *data);
diff --git a/submodule-config.c b/submodule-config.c
index d8f8d5ea3..ad2c447b8 100644
--- a/submodule-config.c
+++ b/submodule-config.c
@@ -402,19 +402,19 @@ static int parse_config(const char *var, const char *value, void *data)
 	return ret;
 }
 
-int gitmodule_sha1_from_commit(const unsigned char *treeish_name,
-				      unsigned char *gitmodules_sha1,
+int gitmodule_oid_from_commit(const struct object_id *treeish_name,
+				      struct object_id *gitmodules_oid,
 				      struct strbuf *rev)
 {
 	int ret = 0;
 
-	if (is_null_sha1(treeish_name)) {
-		hashclr(gitmodules_sha1);
+	if (is_null_oid(treeish_name)) {
+		oidclr(gitmodules_oid);
 		return 1;
 	}
 
-	strbuf_addf(rev, "%s:.gitmodules", sha1_to_hex(treeish_name));
-	if (get_sha1(rev->buf, gitmodules_sha1) >= 0)
+	strbuf_addf(rev, "%s:.gitmodules", oid_to_hex(treeish_name));
+	if (get_oid(rev->buf, gitmodules_oid) >= 0)
 		ret = 1;
 
 	return ret;
@@ -425,13 +425,13 @@ int gitmodule_sha1_from_commit(const unsigned char *treeish_name,
  * revisions.
  */
 static const struct submodule *config_from(struct submodule_cache *cache,
-		const unsigned char *treeish_name, const char *key,
+		const struct object_id *treeish_name, const char *key,
 		enum lookup_type lookup_type)
 {
 	struct strbuf rev = STRBUF_INIT;
 	unsigned long config_size;
 	char *config = NULL;
-	unsigned char sha1[20];
+	struct object_id oid;
 	enum object_type type;
 	const struct submodule *submodule = NULL;
 	struct parse_config_parameter parameter;
@@ -451,28 +451,28 @@ static const struct submodule *config_from(struct submodule_cache *cache,
 		return entry->config;
 	}
 
-	if (!gitmodule_sha1_from_commit(treeish_name, sha1, &rev))
+	if (!gitmodule_oid_from_commit(treeish_name, &oid, &rev))
 		goto out;
 
 	switch (lookup_type) {
 	case lookup_name:
-		submodule = cache_lookup_name(cache, sha1, key);
+		submodule = cache_lookup_name(cache, oid.hash, key);
 		break;
 	case lookup_path:
-		submodule = cache_lookup_path(cache, sha1, key);
+		submodule = cache_lookup_path(cache, oid.hash, key);
 		break;
 	}
 	if (submodule)
 		goto out;
 
-	config = read_sha1_file(sha1, &type, &config_size);
+	config = read_sha1_file(oid.hash, &type, &config_size);
 	if (!config || type != OBJ_BLOB)
 		goto out;
 
 	/* fill the submodule config into the cache */
 	parameter.cache = cache;
-	parameter.treeish_name = treeish_name;
-	parameter.gitmodules_sha1 = sha1;
+	parameter.treeish_name = treeish_name->hash;
+	parameter.gitmodules_sha1 = oid.hash;
 	parameter.overwrite = 0;
 	git_config_from_mem(parse_config, CONFIG_ORIGIN_SUBMODULE_BLOB, rev.buf,
 			config, config_size, &parameter);
@@ -481,9 +481,9 @@ static const struct submodule *config_from(struct submodule_cache *cache,
 
 	switch (lookup_type) {
 	case lookup_name:
-		return cache_lookup_name(cache, sha1, key);
+		return cache_lookup_name(cache, oid.hash, key);
 	case lookup_path:
-		return cache_lookup_path(cache, sha1, key);
+		return cache_lookup_path(cache, oid.hash, key);
 	default:
 		return NULL;
 	}
@@ -515,14 +515,14 @@ int parse_submodule_config_option(const char *var, const char *value)
 	return parse_config(var, value, &parameter);
 }
 
-const struct submodule *submodule_from_name(const unsigned char *treeish_name,
+const struct submodule *submodule_from_name(const struct object_id *treeish_name,
 		const char *name)
 {
 	ensure_cache_init();
 	return config_from(&the_submodule_cache, treeish_name, name, lookup_name);
 }
 
-const struct submodule *submodule_from_path(const unsigned char *treeish_name,
+const struct submodule *submodule_from_path(const struct object_id *treeish_name,
 		const char *path)
 {
 	ensure_cache_init();
diff --git a/submodule-config.h b/submodule-config.h
index d434ecdb4..ab37558e7 100644
--- a/submodule-config.h
+++ b/submodule-config.h
@@ -27,12 +27,12 @@ extern int parse_update_recurse_submodules_arg(const char *opt, const char *arg)
 extern int parse_push_recurse_submodules_arg(const char *opt, const char *arg);
 extern int parse_submodule_config_option(const char *var, const char *value);
 extern const struct submodule *submodule_from_name(
-		const unsigned char *commit_or_tree, const char *name);
+		const struct object_id *commit_or_tree, const char *name);
 extern const struct submodule *submodule_from_path(
-		const unsigned char *commit_or_tree, const char *path);
-extern int gitmodule_sha1_from_commit(const unsigned char *commit_sha1,
-				      unsigned char *gitmodules_sha1,
-				      struct strbuf *rev);
+		const struct object_id *commit_or_tree, const char *path);
+extern int gitmodule_oid_from_commit(const struct object_id *commit_oid,
+				     struct object_id *gitmodules_oid,
+				     struct strbuf *rev);
 extern void submodule_free(void);
 
 #endif /* SUBMODULE_CONFIG_H */
diff --git a/submodule.c b/submodule.c
index 71e0c5a85..d3fee650a 100644
--- a/submodule.c
+++ b/submodule.c
@@ -68,7 +68,7 @@ int update_path_in_gitmodules(const char *oldpath, const char *newpath)
 	if (gitmodules_is_unmerged)
 		die(_("Cannot change unmerged .gitmodules, resolve merge conflicts first"));
 
-	submodule = submodule_from_path(null_sha1, oldpath);
+	submodule = submodule_from_path(&null_oid, oldpath);
 	if (!submodule || !submodule->name) {
 		warning(_("Could not find section in .gitmodules where path=%s"), oldpath);
 		return -1;
@@ -102,7 +102,7 @@ int remove_path_from_gitmodules(const char *path)
 	if (gitmodules_is_unmerged)
 		die(_("Cannot change unmerged .gitmodules, resolve merge conflicts first"));
 
-	submodule = submodule_from_path(null_sha1, path);
+	submodule = submodule_from_path(&null_oid, path);
 	if (!submodule || !submodule->name) {
 		warning(_("Could not find section in .gitmodules where path=%s"), path);
 		return -1;
@@ -146,7 +146,7 @@ static int add_submodule_odb(const char *path)
 void set_diffopt_flags_from_submodule_config(struct diff_options *diffopt,
 					     const char *path)
 {
-	const struct submodule *submodule = submodule_from_path(null_sha1, path);
+	const struct submodule *submodule = submodule_from_path(&null_oid, path);
 	if (submodule) {
 		if (submodule->ignore)
 			handle_ignore_submodules_arg(diffopt, submodule->ignore);
@@ -255,14 +255,14 @@ void gitmodules_config(void)
 	}
 }
 
-void gitmodules_config_sha1(const unsigned char *commit_sha1)
+void gitmodules_config_oid(const struct object_id *commit_oid)
 {
 	struct strbuf rev = STRBUF_INIT;
-	unsigned char sha1[20];
+	struct object_id oid;
 
-	if (gitmodule_sha1_from_commit(commit_sha1, sha1, &rev)) {
-		git_config_from_blob_sha1(git_modules_config, rev.buf,
-					  sha1, NULL);
+	if (gitmodule_oid_from_commit(commit_oid, &oid, &rev)) {
+		git_config_from_blob_oid(submodule_config, rev.buf,
+					 &oid, NULL);
 	}
 	strbuf_release(&rev);
 }
@@ -282,7 +282,7 @@ int is_submodule_initialized(const char *path)
 	char *key = NULL;
 	char *value = NULL;
 	const struct string_list *sl;
-	const struct submodule *module = submodule_from_path(null_sha1, path);
+	const struct submodule *module = submodule_from_path(&null_oid, path);
 
 	/* early return if there isn't a path->module mapping */
 	if (!module)
@@ -727,7 +727,7 @@ const struct submodule *submodule_from_ce(const struct cache_entry *ce)
 	if (!should_update_submodules())
 		return NULL;
 
-	return submodule_from_path(null_sha1, ce->name);
+	return submodule_from_path(&null_oid, ce->name);
 }
 
 static struct oid_array *submodule_commits(struct string_list *submodules,
@@ -1155,9 +1155,9 @@ static int get_next_submodule(struct child_process *cp,
 		if (!S_ISGITLINK(ce->ce_mode))
 			continue;
 
-		submodule = submodule_from_path(null_sha1, ce->name);
+		submodule = submodule_from_path(&null_oid, ce->name);
 		if (!submodule)
-			submodule = submodule_from_name(null_sha1, ce->name);
+			submodule = submodule_from_name(&null_oid, ce->name);
 
 		default_argv = "yes";
 		if (spf->command_line_option == RECURSE_SUBMODULES_DEFAULT) {
@@ -1533,7 +1533,7 @@ int submodule_move_head(const char *path,
 	if (old && !is_submodule_populated_gently(path, error_code_ptr))
 		return 0;
 
-	sub = submodule_from_path(null_sha1, path);
+	sub = submodule_from_path(&null_oid, path);
 
 	if (!sub)
 		die("BUG: could not get submodule information for '%s'", path);
@@ -1815,7 +1815,7 @@ static void relocate_single_git_dir_into_superproject(const char *prefix,
 
 	real_old_git_dir = real_pathdup(old_git_dir, 1);
 
-	sub = submodule_from_path(null_sha1, path);
+	sub = submodule_from_path(&null_oid, path);
 	if (!sub)
 		die(_("could not lookup name for submodule '%s'"), path);
 
@@ -1871,7 +1871,7 @@ void absorb_git_dir_into_superproject(const char *prefix,
 		* superproject did not rewrite the git file links yet,
 		* fix it now.
 		*/
-		sub = submodule_from_path(null_sha1, path);
+		sub = submodule_from_path(&null_oid, path);
 		if (!sub)
 			die(_("could not lookup name for submodule '%s'"), path);
 		connect_work_tree_and_git_dir(path,
@@ -2014,7 +2014,7 @@ int submodule_to_gitdir(struct strbuf *buf, const char *submodule)
 	}
 	if (!is_git_directory(buf->buf)) {
 		gitmodules_config();
-		sub = submodule_from_path(null_sha1, submodule);
+		sub = submodule_from_path(&null_oid, submodule);
 		if (!sub) {
 			ret = -1;
 			goto cleanup;
diff --git a/submodule.h b/submodule.h
index cbe5c1726..5110caff4 100644
--- a/submodule.h
+++ b/submodule.h
@@ -46,7 +46,7 @@ int option_parse_recurse_submodules_worktree_updater(const struct option *opt,
 						     const char *arg, int unset);
 void load_submodule_cache(void);
 extern void gitmodules_config(void);
-extern void gitmodules_config_sha1(const unsigned char *commit_sha1);
+extern void gitmodules_config_oid(const struct object_id *commit_oid);
 extern int is_submodule_initialized(const char *path);
 /*
  * Determine if a submodule has been populated at a given 'path' by checking if
diff --git a/t/helper/test-submodule-config.c b/t/helper/test-submodule-config.c
index c6c57bba0..e13fbcc1b 100644
--- a/t/helper/test-submodule-config.c
+++ b/t/helper/test-submodule-config.c
@@ -41,7 +41,7 @@ int cmd_main(int argc, const char **argv)
 	git_config(git_test_config, NULL);
 
 	while (*arg) {
-		unsigned char commit_sha1[20];
+		struct object_id commit_oid;
 		const struct submodule *submodule;
 		const char *commit;
 		const char *path_or_name;
@@ -50,14 +50,14 @@ int cmd_main(int argc, const char **argv)
 		path_or_name = arg[1];
 
 		if (commit[0] == '\0')
-			hashclr(commit_sha1);
-		else if (get_sha1(commit, commit_sha1) < 0)
+			oidclr(&commit_oid);
+		else if (get_oid(commit, &commit_oid) < 0)
 			die_usage(argc, argv, "Commit not found.");
 
 		if (lookup_name) {
-			submodule = submodule_from_name(commit_sha1, path_or_name);
+			submodule = submodule_from_name(&commit_oid, path_or_name);
 		} else
-			submodule = submodule_from_path(commit_sha1, path_or_name);
+			submodule = submodule_from_path(&commit_oid, path_or_name);
 		if (!submodule)
 			die_usage(argc, argv, "Submodule not found.");
 

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH 04/12] remote: convert struct push_cas to struct object_id
  2017-07-03 18:55 [PATCH 00/12] object_id part 9 brian m. carlson
                   ` (2 preceding siblings ...)
  2017-07-03 18:55 ` [PATCH 03/12] submodule: convert submodule config lookup to use object_id brian m. carlson
@ 2017-07-03 18:55 ` brian m. carlson
  2017-07-03 18:55 ` [PATCH 05/12] sequencer: convert " brian m. carlson
                   ` (8 subsequent siblings)
  12 siblings, 0 replies; 20+ messages in thread
From: brian m. carlson @ 2017-07-03 18:55 UTC (permalink / raw)
  To: git; +Cc: Brandon Williams, Stefan Beller, Jeff King

This gets rid of one use of get_sha1.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 remote.c | 6 +++---
 remote.h | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/remote.c b/remote.c
index d87482573..9da9040bf 100644
--- a/remote.c
+++ b/remote.c
@@ -2294,8 +2294,8 @@ static int parse_push_cas_option(struct push_cas_option *cas, const char *arg, i
 	if (!*colon)
 		entry->use_tracking = 1;
 	else if (!colon[1])
-		hashclr(entry->expect);
-	else if (get_sha1(colon + 1, entry->expect))
+		oidclr(&entry->expect);
+	else if (get_oid(colon + 1, &entry->expect))
 		return error("cannot parse expected object name '%s'", colon + 1);
 	return 0;
 }
@@ -2342,7 +2342,7 @@ static void apply_cas(struct push_cas_option *cas,
 			continue;
 		ref->expect_old_sha1 = 1;
 		if (!entry->use_tracking)
-			hashcpy(ref->old_oid_expect.hash, cas->entry[i].expect);
+			oidcpy(&ref->old_oid_expect, &entry->expect);
 		else if (remote_tracking(remote, ref->name, &ref->old_oid_expect))
 			oidclr(&ref->old_oid_expect);
 		return;
diff --git a/remote.h b/remote.h
index 6c28cd3e4..2ecf4c8c7 100644
--- a/remote.h
+++ b/remote.h
@@ -282,7 +282,7 @@ struct ref *get_stale_heads(struct refspec *refs, int ref_count, struct ref *fet
 struct push_cas_option {
 	unsigned use_tracking_for_rest:1;
 	struct push_cas {
-		unsigned char expect[20];
+		struct object_id expect;
 		unsigned use_tracking:1;
 		char *refname;
 	} *entry;

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH 05/12] sequencer: convert to struct object_id
  2017-07-03 18:55 [PATCH 00/12] object_id part 9 brian m. carlson
                   ` (3 preceding siblings ...)
  2017-07-03 18:55 ` [PATCH 04/12] remote: convert struct push_cas to struct object_id brian m. carlson
@ 2017-07-03 18:55 ` brian m. carlson
  2017-07-03 18:55 ` [PATCH 06/12] builtin/update_ref: " brian m. carlson
                   ` (7 subsequent siblings)
  12 siblings, 0 replies; 20+ messages in thread
From: brian m. carlson @ 2017-07-03 18:55 UTC (permalink / raw)
  To: git; +Cc: Brandon Williams, Stefan Beller, Jeff King

Convert the remaining instances of unsigned char * to struct object_id.
This removes several calls to get_sha1.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 sequencer.c | 59 ++++++++++++++++++++++++++++++-----------------------------
 1 file changed, 30 insertions(+), 29 deletions(-)

diff --git a/sequencer.c b/sequencer.c
index 3010faf86..16d48a4fb 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -691,7 +691,7 @@ static int run_git_commit(const char *defmsg, struct replay_opts *opts,
 
 static int is_original_commit_empty(struct commit *commit)
 {
-	const unsigned char *ptree_sha1;
+	const struct object_id *ptree_oid;
 
 	if (parse_commit(commit))
 		return error(_("could not parse commit %s\n"),
@@ -701,12 +701,12 @@ static int is_original_commit_empty(struct commit *commit)
 		if (parse_commit(parent))
 			return error(_("could not parse parent commit %s\n"),
 				oid_to_hex(&parent->object.oid));
-		ptree_sha1 = parent->tree->object.oid.hash;
+		ptree_oid = &parent->tree->object.oid;
 	} else {
-		ptree_sha1 = EMPTY_TREE_SHA1_BIN; /* commit is root */
+		ptree_oid = &empty_tree_oid; /* commit is root */
 	}
 
-	return !hashcmp(ptree_sha1, commit->tree->object.oid.hash);
+	return !oidcmp(ptree_oid, &commit->tree->object.oid);
 }
 
 /*
@@ -896,18 +896,18 @@ static int update_squash_messages(enum todo_command command,
 
 static void flush_rewritten_pending(void) {
 	struct strbuf buf = STRBUF_INIT;
-	unsigned char newsha1[20];
+	struct object_id newoid;
 	FILE *out;
 
-	if (strbuf_read_file(&buf, rebase_path_rewritten_pending(), 82) > 0 &&
-	    !get_sha1("HEAD", newsha1) &&
+	if (strbuf_read_file(&buf, rebase_path_rewritten_pending(), (GIT_MAX_HEXSZ + 1) * 2) > 0 &&
+	    !get_oid("HEAD", &newoid) &&
 	    (out = fopen_or_warn(rebase_path_rewritten_list(), "a"))) {
 		char *bol = buf.buf, *eol;
 
 		while (*bol) {
 			eol = strchrnul(bol, '\n');
 			fprintf(out, "%.*s %s\n", (int)(eol - bol),
-					bol, sha1_to_hex(newsha1));
+					bol, oid_to_hex(&newoid));
 			if (!*eol)
 				break;
 			bol = eol + 1;
@@ -1594,36 +1594,37 @@ static int rollback_is_safe(void)
 	return !oidcmp(&actual_head, &expected_head);
 }
 
-static int reset_for_rollback(const unsigned char *sha1)
+static int reset_for_rollback(const struct object_id *oid)
 {
 	const char *argv[4];	/* reset --merge <arg> + NULL */
 
 	argv[0] = "reset";
 	argv[1] = "--merge";
-	argv[2] = sha1_to_hex(sha1);
+	argv[2] = oid_to_hex(oid);
 	argv[3] = NULL;
 	return run_command_v_opt(argv, RUN_GIT_CMD);
 }
 
 static int rollback_single_pick(void)
 {
-	unsigned char head_sha1[20];
+	struct object_id head_oid;
 
 	if (!file_exists(git_path_cherry_pick_head()) &&
 	    !file_exists(git_path_revert_head()))
 		return error(_("no cherry-pick or revert in progress"));
-	if (read_ref_full("HEAD", 0, head_sha1, NULL))
+	if (read_ref_full("HEAD", 0, head_oid.hash, NULL))
 		return error(_("cannot resolve HEAD"));
-	if (is_null_sha1(head_sha1))
+	if (is_null_oid(&head_oid))
 		return error(_("cannot abort from a branch yet to be born"));
-	return reset_for_rollback(head_sha1);
+	return reset_for_rollback(&head_oid);
 }
 
 int sequencer_rollback(struct replay_opts *opts)
 {
 	FILE *f;
-	unsigned char sha1[20];
+	struct object_id oid;
 	struct strbuf buf = STRBUF_INIT;
+	const char *p;
 
 	f = fopen(git_path_head_file(), "r");
 	if (!f && errno == ENOENT) {
@@ -1643,12 +1644,12 @@ int sequencer_rollback(struct replay_opts *opts)
 		goto fail;
 	}
 	fclose(f);
-	if (get_sha1_hex(buf.buf, sha1) || buf.buf[40] != '\0') {
+	if (parse_oid_hex(buf.buf, &oid, &p) || *p != '\0') {
 		error(_("stored pre-cherry-pick HEAD file '%s' is corrupt"),
 			git_path_head_file());
 		goto fail;
 	}
-	if (is_null_sha1(sha1)) {
+	if (is_null_oid(&oid)) {
 		error(_("cannot abort from a branch yet to be born"));
 		goto fail;
 	}
@@ -1658,7 +1659,7 @@ int sequencer_rollback(struct replay_opts *opts)
 		warning(_("You seem to have moved HEAD. "
 			  "Not rewinding, check your HEAD!"));
 	} else
-	if (reset_for_rollback(sha1))
+	if (reset_for_rollback(&oid))
 		goto fail;
 	strbuf_release(&buf);
 	return sequencer_remove_state(opts);
@@ -1788,13 +1789,13 @@ static int make_patch(struct commit *commit, struct replay_opts *opts)
 
 static int intend_to_amend(void)
 {
-	unsigned char head[20];
+	struct object_id head;
 	char *p;
 
-	if (get_sha1("HEAD", head))
+	if (get_oid("HEAD", &head))
 		return error(_("cannot read HEAD"));
 
-	p = sha1_to_hex(head);
+	p = oid_to_hex(&head);
 	return write_message(p, strlen(p), rebase_path_amend(), 1);
 }
 
@@ -2079,10 +2080,10 @@ static int pick_commits(struct todo_list *todo_list, struct replay_opts *opts)
 		if (read_oneliner(&head_ref, rebase_path_head_name(), 0) &&
 				starts_with(head_ref.buf, "refs/")) {
 			const char *msg;
-			unsigned char head[20], orig[20];
+			struct object_id head, orig;
 			int res;
 
-			if (get_sha1("HEAD", head)) {
+			if (get_oid("HEAD", &head)) {
 				res = error(_("cannot read HEAD"));
 cleanup_head_ref:
 				strbuf_release(&head_ref);
@@ -2090,7 +2091,7 @@ static int pick_commits(struct todo_list *todo_list, struct replay_opts *opts)
 				return res;
 			}
 			if (!read_oneliner(&buf, rebase_path_orig_head(), 0) ||
-					get_sha1_hex(buf.buf, orig)) {
+					get_oid_hex(buf.buf, &orig)) {
 				res = error(_("could not read orig-head"));
 				goto cleanup_head_ref;
 			}
@@ -2101,7 +2102,7 @@ static int pick_commits(struct todo_list *todo_list, struct replay_opts *opts)
 			}
 			msg = reflog_message(opts, "finish", "%s onto %s",
 				head_ref.buf, buf.buf);
-			if (update_ref(msg, head_ref.buf, head, orig,
+			if (update_ref(msg, head_ref.buf, head.hash, orig.hash,
 					REF_NODEREF, UPDATE_REFS_MSG_ON_ERR)) {
 				res = error(_("could not update %s"),
 					head_ref.buf);
@@ -2205,16 +2206,16 @@ static int commit_staged_changes(struct replay_opts *opts)
 
 	if (file_exists(rebase_path_amend())) {
 		struct strbuf rev = STRBUF_INIT;
-		unsigned char head[20], to_amend[20];
+		struct object_id head, to_amend;
 
-		if (get_sha1("HEAD", head))
+		if (get_oid("HEAD", &head))
 			return error(_("cannot amend non-existing commit"));
 		if (!read_oneliner(&rev, rebase_path_amend(), 0))
 			return error(_("invalid file: '%s'"), rebase_path_amend());
-		if (get_sha1_hex(rev.buf, to_amend))
+		if (get_oid_hex(rev.buf, &to_amend))
 			return error(_("invalid contents: '%s'"),
 				rebase_path_amend());
-		if (hashcmp(head, to_amend))
+		if (oidcmp(&head, &to_amend))
 			return error(_("\nYou have uncommitted changes in your "
 				       "working tree. Please, commit them\n"
 				       "first and then run 'git rebase "

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH 06/12] builtin/update_ref: convert to struct object_id
  2017-07-03 18:55 [PATCH 00/12] object_id part 9 brian m. carlson
                   ` (4 preceding siblings ...)
  2017-07-03 18:55 ` [PATCH 05/12] sequencer: convert " brian m. carlson
@ 2017-07-03 18:55 ` brian m. carlson
  2017-07-03 20:49   ` Ævar Arnfjörð Bjarmason
  2017-07-03 18:55 ` [PATCH 07/12] bisect: convert bisect_checkout " brian m. carlson
                   ` (6 subsequent siblings)
  12 siblings, 1 reply; 20+ messages in thread
From: brian m. carlson @ 2017-07-03 18:55 UTC (permalink / raw)
  To: git; +Cc: Brandon Williams, Stefan Beller, Jeff King

Convert the uses of unsigned char * to struct object_id.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 builtin/update-ref.c | 69 ++++++++++++++++++++++++++--------------------------
 1 file changed, 34 insertions(+), 35 deletions(-)

diff --git a/builtin/update-ref.c b/builtin/update-ref.c
index 40ccfc193..6b90c5dea 100644
--- a/builtin/update-ref.c
+++ b/builtin/update-ref.c
@@ -94,10 +94,10 @@ static char *parse_refname(struct strbuf *input, const char **next)
  * provided but cannot be converted to a SHA-1, die.  flags can
  * include PARSE_SHA1_OLD and/or PARSE_SHA1_ALLOW_EMPTY.
  */
-static int parse_next_sha1(struct strbuf *input, const char **next,
-			   unsigned char *sha1,
-			   const char *command, const char *refname,
-			   int flags)
+static int parse_next_oid(struct strbuf *input, const char **next,
+			  struct object_id *oid,
+			  const char *command, const char *refname,
+			  int flags)
 {
 	struct strbuf arg = STRBUF_INIT;
 	int ret = 0;
@@ -115,11 +115,11 @@ static int parse_next_sha1(struct strbuf *input, const char **next,
 		(*next)++;
 		*next = parse_arg(*next, &arg);
 		if (arg.len) {
-			if (get_sha1(arg.buf, sha1))
+			if (get_oid(arg.buf, oid))
 				goto invalid;
 		} else {
 			/* Without -z, an empty value means all zeros: */
-			hashclr(sha1);
+			oidclr(oid);
 		}
 	} else {
 		/* With -z, read the next NUL-terminated line */
@@ -133,13 +133,13 @@ static int parse_next_sha1(struct strbuf *input, const char **next,
 		*next += arg.len;
 
 		if (arg.len) {
-			if (get_sha1(arg.buf, sha1))
+			if (get_oid(arg.buf, oid))
 				goto invalid;
 		} else if (flags & PARSE_SHA1_ALLOW_EMPTY) {
 			/* With -z, treat an empty value as all zeros: */
 			warning("%s %s: missing <newvalue>, treating as zero",
 				command, refname);
-			hashclr(sha1);
+			oidclr(oid);
 		} else {
 			/*
 			 * With -z, an empty non-required value means
@@ -182,26 +182,25 @@ static const char *parse_cmd_update(struct ref_transaction *transaction,
 {
 	struct strbuf err = STRBUF_INIT;
 	char *refname;
-	unsigned char new_sha1[20];
-	unsigned char old_sha1[20];
+	struct object_id new_oid, old_oid;
 	int have_old;
 
 	refname = parse_refname(input, &next);
 	if (!refname)
 		die("update: missing <ref>");
 
-	if (parse_next_sha1(input, &next, new_sha1, "update", refname,
-			    PARSE_SHA1_ALLOW_EMPTY))
+	if (parse_next_oid(input, &next, &new_oid, "update", refname,
+			   PARSE_SHA1_ALLOW_EMPTY))
 		die("update %s: missing <newvalue>", refname);
 
-	have_old = !parse_next_sha1(input, &next, old_sha1, "update", refname,
-				    PARSE_SHA1_OLD);
+	have_old = !parse_next_oid(input, &next, &old_oid, "update", refname,
+				   PARSE_SHA1_OLD);
 
 	if (*next != line_termination)
 		die("update %s: extra input: %s", refname, next);
 
 	if (ref_transaction_update(transaction, refname,
-				   new_sha1, have_old ? old_sha1 : NULL,
+				   new_oid.hash, have_old ? old_oid.hash : NULL,
 				   update_flags | create_reflog_flag,
 				   msg, &err))
 		die("%s", err.buf);
@@ -218,22 +217,22 @@ static const char *parse_cmd_create(struct ref_transaction *transaction,
 {
 	struct strbuf err = STRBUF_INIT;
 	char *refname;
-	unsigned char new_sha1[20];
+	struct object_id new_oid;
 
 	refname = parse_refname(input, &next);
 	if (!refname)
 		die("create: missing <ref>");
 
-	if (parse_next_sha1(input, &next, new_sha1, "create", refname, 0))
+	if (parse_next_oid(input, &next, &new_oid, "create", refname, 0))
 		die("create %s: missing <newvalue>", refname);
 
-	if (is_null_sha1(new_sha1))
+	if (is_null_oid(&new_oid))
 		die("create %s: zero <newvalue>", refname);
 
 	if (*next != line_termination)
 		die("create %s: extra input: %s", refname, next);
 
-	if (ref_transaction_create(transaction, refname, new_sha1,
+	if (ref_transaction_create(transaction, refname, new_oid.hash,
 				   update_flags | create_reflog_flag,
 				   msg, &err))
 		die("%s", err.buf);
@@ -250,18 +249,18 @@ static const char *parse_cmd_delete(struct ref_transaction *transaction,
 {
 	struct strbuf err = STRBUF_INIT;
 	char *refname;
-	unsigned char old_sha1[20];
+	struct object_id old_oid;
 	int have_old;
 
 	refname = parse_refname(input, &next);
 	if (!refname)
 		die("delete: missing <ref>");
 
-	if (parse_next_sha1(input, &next, old_sha1, "delete", refname,
-			    PARSE_SHA1_OLD)) {
+	if (parse_next_oid(input, &next, &old_oid, "delete", refname,
+			   PARSE_SHA1_OLD)) {
 		have_old = 0;
 	} else {
-		if (is_null_sha1(old_sha1))
+		if (is_null_oid(&old_oid))
 			die("delete %s: zero <oldvalue>", refname);
 		have_old = 1;
 	}
@@ -270,7 +269,7 @@ static const char *parse_cmd_delete(struct ref_transaction *transaction,
 		die("delete %s: extra input: %s", refname, next);
 
 	if (ref_transaction_delete(transaction, refname,
-				   have_old ? old_sha1 : NULL,
+				   have_old ? old_oid.hash : NULL,
 				   update_flags, msg, &err))
 		die("%s", err.buf);
 
@@ -286,20 +285,20 @@ static const char *parse_cmd_verify(struct ref_transaction *transaction,
 {
 	struct strbuf err = STRBUF_INIT;
 	char *refname;
-	unsigned char old_sha1[20];
+	struct object_id old_oid;
 
 	refname = parse_refname(input, &next);
 	if (!refname)
 		die("verify: missing <ref>");
 
-	if (parse_next_sha1(input, &next, old_sha1, "verify", refname,
-			    PARSE_SHA1_OLD))
-		hashclr(old_sha1);
+	if (parse_next_oid(input, &next, &old_oid, "verify", refname,
+			   PARSE_SHA1_OLD))
+		oidclr(&old_oid);
 
 	if (*next != line_termination)
 		die("verify %s: extra input: %s", refname, next);
 
-	if (ref_transaction_verify(transaction, refname, old_sha1,
+	if (ref_transaction_verify(transaction, refname, old_oid.hash,
 				   update_flags, &err))
 		die("%s", err.buf);
 
@@ -355,7 +354,7 @@ static void update_refs_stdin(struct ref_transaction *transaction)
 int cmd_update_ref(int argc, const char **argv, const char *prefix)
 {
 	const char *refname, *oldval;
-	unsigned char sha1[20], oldsha1[20];
+	struct object_id oid, oldoid;
 	int delete = 0, no_deref = 0, read_stdin = 0, end_null = 0;
 	unsigned int flags = 0;
 	int create_reflog = 0;
@@ -412,7 +411,7 @@ int cmd_update_ref(int argc, const char **argv, const char *prefix)
 		refname = argv[0];
 		value = argv[1];
 		oldval = argv[2];
-		if (get_sha1(value, sha1))
+		if (get_oid(value, &oid))
 			die("%s: not a valid SHA1", value);
 	}
 
@@ -422,8 +421,8 @@ int cmd_update_ref(int argc, const char **argv, const char *prefix)
 			 * The empty string implies that the reference
 			 * must not already exist:
 			 */
-			hashclr(oldsha1);
-		else if (get_sha1(oldval, oldsha1))
+			oidclr(&oldoid);
+		else if (get_oid(oldval, &oldoid))
 			die("%s: not a valid old SHA1", oldval);
 	}
 
@@ -435,10 +434,10 @@ int cmd_update_ref(int argc, const char **argv, const char *prefix)
 		 * NULL_SHA1 as "don't care" here:
 		 */
 		return delete_ref(msg, refname,
-				  (oldval && !is_null_sha1(oldsha1)) ? oldsha1 : NULL,
+				  (oldval && !is_null_oid(&oldoid)) ? oldoid.hash : NULL,
 				  flags);
 	else
-		return update_ref(msg, refname, sha1, oldval ? oldsha1 : NULL,
+		return update_ref(msg, refname, oid.hash, oldval ? oldoid.hash : NULL,
 				  flags | create_reflog_flag,
 				  UPDATE_REFS_DIE_ON_ERR);
 }

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH 07/12] bisect: convert bisect_checkout to struct object_id
  2017-07-03 18:55 [PATCH 00/12] object_id part 9 brian m. carlson
                   ` (5 preceding siblings ...)
  2017-07-03 18:55 ` [PATCH 06/12] builtin/update_ref: " brian m. carlson
@ 2017-07-03 18:55 ` brian m. carlson
  2017-07-03 18:55 ` [PATCH 08/12] builtin/unpack-file: convert " brian m. carlson
                   ` (5 subsequent siblings)
  12 siblings, 0 replies; 20+ messages in thread
From: brian m. carlson @ 2017-07-03 18:55 UTC (permalink / raw)
  To: git; +Cc: Brandon Williams, Stefan Beller, Jeff King

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

diff --git a/bisect.c b/bisect.c
index a9fd9fbc6..2549eaf7b 100644
--- a/bisect.c
+++ b/bisect.c
@@ -680,16 +680,16 @@ static int is_expected_rev(const struct object_id *oid)
 	return res;
 }
 
-static int bisect_checkout(const unsigned char *bisect_rev, int no_checkout)
+static int bisect_checkout(const struct object_id *bisect_rev, int no_checkout)
 {
 	char bisect_rev_hex[GIT_MAX_HEXSZ + 1];
 
-	memcpy(bisect_rev_hex, sha1_to_hex(bisect_rev), GIT_SHA1_HEXSZ + 1);
-	update_ref(NULL, "BISECT_EXPECTED_REV", bisect_rev, NULL, 0, UPDATE_REFS_DIE_ON_ERR);
+	memcpy(bisect_rev_hex, oid_to_hex(bisect_rev), GIT_SHA1_HEXSZ + 1);
+	update_ref(NULL, "BISECT_EXPECTED_REV", bisect_rev->hash, NULL, 0, UPDATE_REFS_DIE_ON_ERR);
 
 	argv_checkout[2] = bisect_rev_hex;
 	if (no_checkout) {
-		update_ref(NULL, "BISECT_HEAD", bisect_rev, NULL, 0, UPDATE_REFS_DIE_ON_ERR);
+		update_ref(NULL, "BISECT_HEAD", bisect_rev->hash, NULL, 0, UPDATE_REFS_DIE_ON_ERR);
 	} else {
 		int res;
 		res = run_command_v_opt(argv_checkout, RUN_GIT_CMD);
@@ -796,7 +796,7 @@ static void check_merge_bases(int no_checkout)
 			handle_skipped_merge_base(mb);
 		} else {
 			printf(_("Bisecting: a merge base must be tested\n"));
-			exit(bisect_checkout(mb->hash, no_checkout));
+			exit(bisect_checkout(mb, no_checkout));
 		}
 	}
 
@@ -939,7 +939,7 @@ int bisect_next_all(const char *prefix, int no_checkout)
 	struct rev_info revs;
 	struct commit_list *tried;
 	int reaches = 0, all = 0, nr, steps;
-	const unsigned char *bisect_rev;
+	struct object_id *bisect_rev;
 	char *steps_msg;
 
 	read_bisect_terms(&term_bad, &term_good);
@@ -977,11 +977,11 @@ int bisect_next_all(const char *prefix, int no_checkout)
 		exit(4);
 	}
 
-	bisect_rev = revs.commits->item->object.oid.hash;
+	bisect_rev = &revs.commits->item->object.oid;
 
-	if (!hashcmp(bisect_rev, current_bad_oid->hash)) {
+	if (!oidcmp(bisect_rev, current_bad_oid)) {
 		exit_if_skipped_commits(tried, current_bad_oid);
-		printf("%s is the first %s commit\n", sha1_to_hex(bisect_rev),
+		printf("%s is the first %s commit\n", oid_to_hex(bisect_rev),
 			term_bad);
 		show_diff_tree(prefix, revs.commits->item);
 		/* This means the bisection process succeeded. */

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH 08/12] builtin/unpack-file: convert to struct object_id
  2017-07-03 18:55 [PATCH 00/12] object_id part 9 brian m. carlson
                   ` (6 preceding siblings ...)
  2017-07-03 18:55 ` [PATCH 07/12] bisect: convert bisect_checkout " brian m. carlson
@ 2017-07-03 18:55 ` brian m. carlson
  2017-07-03 18:55 ` [PATCH 09/12] builtin/verify-tag: " brian m. carlson
                   ` (4 subsequent siblings)
  12 siblings, 0 replies; 20+ messages in thread
From: brian m. carlson @ 2017-07-03 18:55 UTC (permalink / raw)
  To: git; +Cc: Brandon Williams, Stefan Beller, Jeff King

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

diff --git a/builtin/unpack-file.c b/builtin/unpack-file.c
index 73f133419..281ca1db6 100644
--- a/builtin/unpack-file.c
+++ b/builtin/unpack-file.c
@@ -1,7 +1,7 @@
 #include "builtin.h"
 #include "config.h"
 
-static char *create_temp_file(unsigned char *sha1)
+static char *create_temp_file(struct object_id *oid)
 {
 	static char path[50];
 	void *buf;
@@ -9,9 +9,9 @@ static char *create_temp_file(unsigned char *sha1)
 	unsigned long size;
 	int fd;
 
-	buf = read_sha1_file(sha1, &type, &size);
+	buf = read_sha1_file(oid->hash, &type, &size);
 	if (!buf || type != OBJ_BLOB)
-		die("unable to read blob object %s", sha1_to_hex(sha1));
+		die("unable to read blob object %s", oid_to_hex(oid));
 
 	xsnprintf(path, sizeof(path), ".merge_file_XXXXXX");
 	fd = xmkstemp(path);
@@ -23,15 +23,15 @@ static char *create_temp_file(unsigned char *sha1)
 
 int cmd_unpack_file(int argc, const char **argv, const char *prefix)
 {
-	unsigned char sha1[20];
+	struct object_id oid;
 
 	if (argc != 2 || !strcmp(argv[1], "-h"))
 		usage("git unpack-file <sha1>");
-	if (get_sha1(argv[1], sha1))
+	if (get_oid(argv[1], &oid))
 		die("Not a valid object name %s", argv[1]);
 
 	git_config(git_default_config, NULL);
 
-	puts(create_temp_file(sha1));
+	puts(create_temp_file(&oid));
 	return 0;
 }

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH 09/12] builtin/verify-tag: convert to struct object_id
  2017-07-03 18:55 [PATCH 00/12] object_id part 9 brian m. carlson
                   ` (7 preceding siblings ...)
  2017-07-03 18:55 ` [PATCH 08/12] builtin/unpack-file: convert " brian m. carlson
@ 2017-07-03 18:55 ` brian m. carlson
  2017-07-03 18:55 ` [PATCH 10/12] Convert remaining callers of get_sha1 to get_oid brian m. carlson
                   ` (3 subsequent siblings)
  12 siblings, 0 replies; 20+ messages in thread
From: brian m. carlson @ 2017-07-03 18:55 UTC (permalink / raw)
  To: git; +Cc: Brandon Williams, Stefan Beller, Jeff King

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

diff --git a/builtin/verify-tag.c b/builtin/verify-tag.c
index f9a5f7535..30e4c826e 100644
--- a/builtin/verify-tag.c
+++ b/builtin/verify-tag.c
@@ -56,20 +56,20 @@ int cmd_verify_tag(int argc, const char **argv, const char *prefix)
 	}
 
 	while (i < argc) {
-		unsigned char sha1[20];
+		struct object_id oid;
 		const char *name = argv[i++];
-		if (get_sha1(name, sha1)) {
+		if (get_oid(name, &oid)) {
 			had_error = !!error("tag '%s' not found.", name);
 			continue;
 		}
 
-		if (gpg_verify_tag(sha1, name, flags)) {
+		if (gpg_verify_tag(oid.hash, name, flags)) {
 			had_error = 1;
 			continue;
 		}
 
 		if (fmt_pretty)
-			pretty_print_ref(name, sha1, fmt_pretty);
+			pretty_print_ref(name, oid.hash, fmt_pretty);
 	}
 	return had_error;
 }

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH 10/12] Convert remaining callers of get_sha1 to get_oid.
  2017-07-03 18:55 [PATCH 00/12] object_id part 9 brian m. carlson
                   ` (8 preceding siblings ...)
  2017-07-03 18:55 ` [PATCH 09/12] builtin/verify-tag: " brian m. carlson
@ 2017-07-03 18:55 ` brian m. carlson
  2017-07-03 18:55 ` [PATCH 11/12] sha1_name: convert get_sha1* to get_oid* brian m. carlson
                   ` (2 subsequent siblings)
  12 siblings, 0 replies; 20+ messages in thread
From: brian m. carlson @ 2017-07-03 18:55 UTC (permalink / raw)
  To: git; +Cc: Brandon Williams, Stefan Beller, Jeff King

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 builtin/receive-pack.c | 4 ++--
 mailmap.c              | 6 +++---
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index 71c0c768d..1efa48fec 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -919,9 +919,9 @@ static int update_shallow_ref(struct command *cmd, struct shallow_info *si)
  */
 static int head_has_history(void)
 {
-	unsigned char sha1[20];
+	struct object_id oid;
 
-	return !get_sha1("HEAD", sha1);
+	return !get_oid("HEAD", &oid);
 }
 
 static const char *push_to_deploy(unsigned char *sha1,
diff --git a/mailmap.c b/mailmap.c
index c1a79c100..cb921b4db 100644
--- a/mailmap.c
+++ b/mailmap.c
@@ -214,17 +214,17 @@ static int read_mailmap_blob(struct string_list *map,
 			     const char *name,
 			     char **repo_abbrev)
 {
-	unsigned char sha1[20];
+	struct object_id oid;
 	char *buf;
 	unsigned long size;
 	enum object_type type;
 
 	if (!name)
 		return 0;
-	if (get_sha1(name, sha1) < 0)
+	if (get_oid(name, &oid) < 0)
 		return 0;
 
-	buf = read_sha1_file(sha1, &type, &size);
+	buf = read_sha1_file(oid.hash, &type, &size);
 	if (!buf)
 		return error("unable to read mailmap object at %s", name);
 	if (type != OBJ_BLOB)

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH 11/12] sha1_name: convert get_sha1* to get_oid*
  2017-07-03 18:55 [PATCH 00/12] object_id part 9 brian m. carlson
                   ` (9 preceding siblings ...)
  2017-07-03 18:55 ` [PATCH 10/12] Convert remaining callers of get_sha1 to get_oid brian m. carlson
@ 2017-07-03 18:55 ` brian m. carlson
  2017-07-05 18:01   ` Stefan Beller
  2017-07-03 18:55 ` [PATCH 12/12] sha1_name: convert GET_SHA1* flags to GET_OID* brian m. carlson
  2017-07-05  4:10 ` [PATCH 00/12] object_id part 9 Junio C Hamano
  12 siblings, 1 reply; 20+ messages in thread
From: brian m. carlson @ 2017-07-03 18:55 UTC (permalink / raw)
  To: git; +Cc: Brandon Williams, Stefan Beller, Jeff King

Now that all the callers of get_sha1 directly or indirectly use struct
object_id, rename the functions starting with get_sha1 to start with
get_oid.  Convert the internals in sha1_name.c to use struct object_id
as well, and eliminate explicit length checks where possible.

Outside of sha1_name.c and cache.h, this transition was made with the
following semantic patch:

@@
expression E1, E2;
@@
- get_sha1(E1, E2.hash)
+ get_oid(E1, &E2)

@@
expression E1, E2;
@@
- get_sha1(E1, E2->hash)
+ get_oid(E1, E2)

@@
expression E1, E2;
@@
- get_sha1_committish(E1, E2.hash)
+ get_oid_committish(E1, &E2)

@@
expression E1, E2;
@@
- get_sha1_committish(E1, E2->hash)
+ get_oid_committish(E1, E2)

@@
expression E1, E2;
@@
- get_sha1_treeish(E1, E2.hash)
+ get_oid_treeish(E1, &E2)

@@
expression E1, E2;
@@
- get_sha1_treeish(E1, E2->hash)
+ get_oid_treeish(E1, E2)

@@
expression E1, E2;
@@
- get_sha1_commit(E1, E2.hash)
+ get_oid_commit(E1, &E2)

@@
expression E1, E2;
@@
- get_sha1_commit(E1, E2->hash)
+ get_oid_commit(E1, E2)

@@
expression E1, E2;
@@
- get_sha1_tree(E1, E2.hash)
+ get_oid_tree(E1, &E2)

@@
expression E1, E2;
@@
- get_sha1_tree(E1, E2->hash)
+ get_oid_tree(E1, E2)

@@
expression E1, E2;
@@
- get_sha1_blob(E1, E2.hash)
+ get_oid_blob(E1, &E2)

@@
expression E1, E2;
@@
- get_sha1_blob(E1, E2->hash)
+ get_oid_blob(E1, E2)

@@
expression E1, E2, E3, E4;
@@
- get_sha1_with_context(E1, E2, E3.hash, E4)
+ get_oid_with_context(E1, E2, &E3, E4)

@@
expression E1, E2, E3, E4;
@@
- get_sha1_with_context(E1, E2, E3->hash, E4)
+ get_oid_with_context(E1, E2, E3, E4)

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 apply.c               |   4 +-
 archive.c             |   2 +-
 builtin/am.c          |   6 +-
 builtin/cat-file.c    |   6 +-
 builtin/commit-tree.c |   4 +-
 builtin/commit.c      |   8 +--
 builtin/grep.c        |   4 +-
 builtin/log.c         |   4 +-
 builtin/replace.c     |   4 +-
 builtin/reset.c       |  10 +--
 builtin/rev-parse.c   |   6 +-
 builtin/show-branch.c |   8 +--
 cache.h               |  17 +++--
 commit.c              |   4 +-
 notes.c               |   2 +-
 remote.c              |   2 +-
 revision.c            |  10 +--
 sequencer.c           |   6 +-
 sha1_name.c           | 190 ++++++++++++++++++++++++--------------------------
 transport-helper.c    |   2 +-
 20 files changed, 145 insertions(+), 154 deletions(-)

diff --git a/apply.c b/apply.c
index c442b8932..58d7d5dc5 100644
--- a/apply.c
+++ b/apply.c
@@ -3553,7 +3553,7 @@ static int try_threeway(struct apply_state *state,
 	/* Preimage the patch was prepared for */
 	if (patch->is_new)
 		write_sha1_file("", 0, blob_type, pre_oid.hash);
-	else if (get_sha1(patch->old_sha1_prefix, pre_oid.hash) ||
+	else if (get_oid(patch->old_sha1_prefix, &pre_oid) ||
 		 read_blob_object(&buf, &pre_oid, patch->old_mode))
 		return error(_("repository lacks the necessary blob to fall back on 3-way merge."));
 
@@ -4077,7 +4077,7 @@ static int build_fake_ancestor(struct apply_state *state, struct patch *list)
 			else
 				return error(_("sha1 information is lacking or "
 					       "useless for submodule %s"), name);
-		} else if (!get_sha1_blob(patch->old_sha1_prefix, oid.hash)) {
+		} else if (!get_oid_blob(patch->old_sha1_prefix, &oid)) {
 			; /* ok */
 		} else if (!patch->lines_added && !patch->lines_deleted) {
 			/* mode-only change: update the current */
diff --git a/archive.c b/archive.c
index 60b3035a7..557dd2db8 100644
--- a/archive.c
+++ b/archive.c
@@ -358,7 +358,7 @@ static void parse_treeish_arg(const char **argv,
 		free(ref);
 	}
 
-	if (get_sha1(name, oid.hash))
+	if (get_oid(name, &oid))
 		die("Not a valid object name");
 
 	commit = lookup_commit_reference_gently(&oid, 1);
diff --git a/builtin/am.c b/builtin/am.c
index c973bd96d..40cc6d6fe 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -1131,7 +1131,7 @@ static int index_has_changes(struct strbuf *sb)
 	struct object_id head;
 	int i;
 
-	if (!get_sha1_tree("HEAD", head.hash)) {
+	if (!get_oid_tree("HEAD", &head)) {
 		struct diff_options opt;
 
 		diff_setup(&opt);
@@ -1432,7 +1432,7 @@ static void write_index_patch(const struct am_state *state)
 	struct rev_info rev_info;
 	FILE *fp;
 
-	if (!get_sha1_tree("HEAD", head.hash))
+	if (!get_oid_tree("HEAD", &head))
 		tree = lookup_tree(&head);
 	else
 		tree = lookup_tree(&empty_tree_oid);
@@ -1661,7 +1661,7 @@ static void do_commit(const struct am_state *state)
 	if (write_cache_as_tree(tree.hash, 0, NULL))
 		die(_("git write-tree failed to write a tree"));
 
-	if (!get_sha1_commit("HEAD", parent.hash)) {
+	if (!get_oid_commit("HEAD", &parent)) {
 		old_oid = &parent;
 		commit_list_insert(lookup_commit(&parent), &parents);
 	} else {
diff --git a/builtin/cat-file.c b/builtin/cat-file.c
index 7efbc4019..695168a98 100644
--- a/builtin/cat-file.c
+++ b/builtin/cat-file.c
@@ -63,8 +63,8 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
 	if (unknown_type)
 		flags |= LOOKUP_UNKNOWN_OBJECT;
 
-	if (get_sha1_with_context(obj_name, GET_SHA1_RECORD_PATH,
-				  oid.hash, &obj_context))
+	if (get_oid_with_context(obj_name, GET_SHA1_RECORD_PATH,
+				 &oid, &obj_context))
 		die("Not a valid object name %s", obj_name);
 
 	if (!path)
@@ -363,7 +363,7 @@ static void batch_one_object(const char *obj_name, struct batch_options *opt,
 	int flags = opt->follow_symlinks ? GET_SHA1_FOLLOW_SYMLINKS : 0;
 	enum follow_symlinks_result result;
 
-	result = get_sha1_with_context(obj_name, flags, data->oid.hash, &ctx);
+	result = get_oid_with_context(obj_name, flags, &data->oid, &ctx);
 	if (result != FOUND) {
 		switch (result) {
 		case MISSING_OBJECT:
diff --git a/builtin/commit-tree.c b/builtin/commit-tree.c
index a4a923d7c..19e898fa4 100644
--- a/builtin/commit-tree.c
+++ b/builtin/commit-tree.c
@@ -56,7 +56,7 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix)
 			struct object_id oid;
 			if (argc <= ++i)
 				usage(commit_tree_usage);
-			if (get_sha1_commit(argv[i], oid.hash))
+			if (get_oid_commit(argv[i], &oid))
 				die("Not a valid object name %s", argv[i]);
 			assert_sha1_type(oid.hash, OBJ_COMMIT);
 			new_parent(lookup_commit(&oid), &parents);
@@ -106,7 +106,7 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix)
 			continue;
 		}
 
-		if (get_sha1_tree(arg, tree_oid.hash))
+		if (get_oid_tree(arg, &tree_oid))
 			die("Not a valid object name %s", arg);
 		if (got_tree)
 			die("Cannot give more than one trees");
diff --git a/builtin/commit.c b/builtin/commit.c
index 03b97c644..3bbff350f 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -511,7 +511,7 @@ static int run_status(FILE *fp, const char *index_file, const char *prefix, int
 	s->index_file = index_file;
 	s->fp = fp;
 	s->nowarn = nowarn;
-	s->is_initial = get_sha1(s->reference, oid.hash) ? 1 : 0;
+	s->is_initial = get_oid(s->reference, &oid) ? 1 : 0;
 	if (!s->is_initial)
 		hashcpy(s->sha1_commit, oid.hash);
 	s->status_format = status_format;
@@ -896,7 +896,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
 		if (amend)
 			parent = "HEAD^1";
 
-		if (get_sha1(parent, oid.hash)) {
+		if (get_oid(parent, &oid)) {
 			int i, ita_nr = 0;
 
 			for (i = 0; i < active_nr; i++)
@@ -1394,7 +1394,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
 
 	fd = hold_locked_index(&index_lock, 0);
 
-	s.is_initial = get_sha1(s.reference, oid.hash) ? 1 : 0;
+	s.is_initial = get_oid(s.reference, &oid) ? 1 : 0;
 	if (!s.is_initial)
 		hashcpy(s.sha1_commit, oid.hash);
 
@@ -1664,7 +1664,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
 	status_format = STATUS_FORMAT_NONE; /* Ignore status.short */
 	s.colopts = 0;
 
-	if (get_sha1("HEAD", oid.hash))
+	if (get_oid("HEAD", &oid))
 		current_head = NULL;
 	else {
 		current_head = lookup_commit_or_die(&oid, "HEAD");
diff --git a/builtin/grep.c b/builtin/grep.c
index 397b5f049..a309ab7c2 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -1206,8 +1206,8 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
 			break;
 		}
 
-		if (get_sha1_with_context(arg, GET_SHA1_RECORD_PATH,
-					  oid.hash, &oc)) {
+		if (get_oid_with_context(arg, GET_SHA1_RECORD_PATH,
+					 &oid, &oc)) {
 			if (seen_dashdash)
 				die(_("unable to resolve revision: %s"), arg);
 			break;
diff --git a/builtin/log.c b/builtin/log.c
index 8ca1de989..60fac9d4d 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -484,8 +484,8 @@ static int show_blob_object(const struct object_id *oid, struct rev_info *rev, c
 	    !DIFF_OPT_TST(&rev->diffopt, ALLOW_TEXTCONV))
 		return stream_blob_to_fd(1, oid, NULL, 0);
 
-	if (get_sha1_with_context(obj_name, GET_SHA1_RECORD_PATH,
-				  oidc.hash, &obj_context))
+	if (get_oid_with_context(obj_name, GET_SHA1_RECORD_PATH,
+				 &oidc, &obj_context))
 		die(_("Not a valid object name %s"), obj_name);
 	if (!obj_context.path ||
 	    !textconv_object(obj_context.path, obj_context.mode, &oidc, 1, &buf, &size)) {
diff --git a/builtin/replace.c b/builtin/replace.c
index 80a15cf35..210d930c8 100644
--- a/builtin/replace.c
+++ b/builtin/replace.c
@@ -50,7 +50,7 @@ static int show_reference(const char *refname, const struct object_id *oid,
 			struct object_id object;
 			enum object_type obj_type, repl_type;
 
-			if (get_sha1(refname, object.hash))
+			if (get_oid(refname, &object))
 				return error("Failed to resolve '%s' as a valid ref.", refname);
 
 			obj_type = sha1_object_info(object.hash, NULL);
@@ -365,7 +365,7 @@ static void check_one_mergetag(struct commit *commit,
 	/* iterate over new parents */
 	for (i = 1; i < mergetag_data->argc; i++) {
 		struct object_id oid;
-		if (get_sha1(mergetag_data->argv[i], oid.hash) < 0)
+		if (get_oid(mergetag_data->argv[i], &oid) < 0)
 			die(_("Not a valid object name: '%s'"), mergetag_data->argv[i]);
 		if (!oidcmp(&tag->tagged->oid, &oid))
 			return; /* found */
diff --git a/builtin/reset.c b/builtin/reset.c
index 7aeaea273..046403ed6 100644
--- a/builtin/reset.c
+++ b/builtin/reset.c
@@ -219,8 +219,8 @@ static void parse_args(struct pathspec *pathspec,
 		 * has to be unambiguous. If there is a single argument, it
 		 * can not be a tree
 		 */
-		else if ((!argv[1] && !get_sha1_committish(argv[0], unused.hash)) ||
-			 (argv[1] && !get_sha1_treeish(argv[0], unused.hash))) {
+		else if ((!argv[1] && !get_oid_committish(argv[0], &unused)) ||
+			 (argv[1] && !get_oid_treeish(argv[0], &unused))) {
 			/*
 			 * Ok, argv[0] looks like a commit/tree; it should not
 			 * be a filename.
@@ -310,13 +310,13 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
 
 	load_submodule_cache();
 
-	unborn = !strcmp(rev, "HEAD") && get_sha1("HEAD", oid.hash);
+	unborn = !strcmp(rev, "HEAD") && get_oid("HEAD", &oid);
 	if (unborn) {
 		/* reset on unborn branch: treat as reset to empty tree */
 		hashcpy(oid.hash, EMPTY_TREE_SHA1_BIN);
 	} else if (!pathspec.nr) {
 		struct commit *commit;
-		if (get_sha1_committish(rev, oid.hash))
+		if (get_oid_committish(rev, &oid))
 			die(_("Failed to resolve '%s' as a valid revision."), rev);
 		commit = lookup_commit_reference(&oid);
 		if (!commit)
@@ -324,7 +324,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
 		oidcpy(&oid, &commit->object.oid);
 	} else {
 		struct tree *tree;
-		if (get_sha1_treeish(rev, oid.hash))
+		if (get_oid_treeish(rev, &oid))
 			die(_("Failed to resolve '%s' as a valid tree."), rev);
 		tree = parse_tree_indirect(&oid);
 		if (!tree)
diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c
index c78b7b33d..041b7898c 100644
--- a/builtin/rev-parse.c
+++ b/builtin/rev-parse.c
@@ -274,7 +274,7 @@ static int try_difference(const char *arg)
 		return 0;
 	}
 
-	if (!get_sha1_committish(this, oid.hash) && !get_sha1_committish(next, end.hash)) {
+	if (!get_oid_committish(this, &oid) && !get_oid_committish(next, &end)) {
 		show_rev(NORMAL, &end, next);
 		show_rev(symmetric ? NORMAL : REVERSED, &oid, this);
 		if (symmetric) {
@@ -328,7 +328,7 @@ static int try_parent_shorthands(const char *arg)
 		return 0;
 
 	*dotdot = 0;
-	if (get_sha1_committish(arg, oid.hash)) {
+	if (get_oid_committish(arg, &oid)) {
 		*dotdot = '^';
 		return 0;
 	}
@@ -911,7 +911,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
 			name++;
 			type = REVERSED;
 		}
-		if (!get_sha1_with_context(name, flags, oid.hash, &unused)) {
+		if (!get_oid_with_context(name, flags, &oid, &unused)) {
 			if (verify)
 				revs_count++;
 			else
diff --git a/builtin/show-branch.c b/builtin/show-branch.c
index 527f69e28..c2a399985 100644
--- a/builtin/show-branch.c
+++ b/builtin/show-branch.c
@@ -393,7 +393,7 @@ static int append_head_ref(const char *refname, const struct object_id *oid,
 	/* If both heads/foo and tags/foo exists, get_sha1 would
 	 * get confused.
 	 */
-	if (get_sha1(refname + ofs, tmp.hash) || oidcmp(&tmp, oid))
+	if (get_oid(refname + ofs, &tmp) || oidcmp(&tmp, oid))
 		ofs = 5;
 	return append_ref(refname + ofs, oid, 0);
 }
@@ -408,7 +408,7 @@ static int append_remote_ref(const char *refname, const struct object_id *oid,
 	/* If both heads/foo and tags/foo exists, get_sha1 would
 	 * get confused.
 	 */
-	if (get_sha1(refname + ofs, tmp.hash) || oidcmp(&tmp, oid))
+	if (get_oid(refname + ofs, &tmp) || oidcmp(&tmp, oid))
 		ofs = 5;
 	return append_ref(refname + ofs, oid, 0);
 }
@@ -514,7 +514,7 @@ static int show_independent(struct commit **rev,
 static void append_one_rev(const char *av)
 {
 	struct object_id revkey;
-	if (!get_sha1(av, revkey.hash)) {
+	if (!get_oid(av, &revkey)) {
 		append_ref(av, &revkey, 0);
 		return;
 	}
@@ -808,7 +808,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
 			die(Q_("cannot handle more than %d rev.",
 			       "cannot handle more than %d revs.",
 			       MAX_REVS), MAX_REVS);
-		if (get_sha1(ref_name[num_rev], revkey.hash))
+		if (get_oid(ref_name[num_rev], &revkey))
 			die(_("'%s' is not a valid ref."), ref_name[num_rev]);
 		commit = lookup_commit_reference(&revkey);
 		if (!commit)
diff --git a/cache.h b/cache.h
index 96055c222..c68f44e10 100644
--- a/cache.h
+++ b/cache.h
@@ -1373,16 +1373,15 @@ struct object_context {
 	GET_SHA1_TREE | GET_SHA1_TREEISH | \
 	GET_SHA1_BLOB)
 
-extern int get_sha1(const char *str, unsigned char *sha1);
-extern int get_sha1_commit(const char *str, unsigned char *sha1);
-extern int get_sha1_committish(const char *str, unsigned char *sha1);
-extern int get_sha1_tree(const char *str, unsigned char *sha1);
-extern int get_sha1_treeish(const char *str, unsigned char *sha1);
-extern int get_sha1_blob(const char *str, unsigned char *sha1);
-extern void maybe_die_on_misspelt_object_name(const char *name, const char *prefix);
-extern int get_sha1_with_context(const char *str, unsigned flags, unsigned char *sha1, struct object_context *oc);
-
 extern int get_oid(const char *str, struct object_id *oid);
+extern int get_oid_commit(const char *str, struct object_id *oid);
+extern int get_oid_committish(const char *str, struct object_id *oid);
+extern int get_oid_tree(const char *str, struct object_id *oid);
+extern int get_oid_treeish(const char *str, struct object_id *oid);
+extern int get_oid_blob(const char *str, struct object_id *oid);
+extern void maybe_die_on_misspelt_object_name(const char *name, const char *prefix);
+extern int get_oid_with_context(const char *str, unsigned flags, struct object_id *oid, struct object_context *oc);
+
 
 typedef int each_abbrev_fn(const struct object_id *oid, void *);
 extern int for_each_abbrev(const char *prefix, each_abbrev_fn, void *);
diff --git a/commit.c b/commit.c
index cbfd68993..d29c997e7 100644
--- a/commit.c
+++ b/commit.c
@@ -59,7 +59,7 @@ struct commit *lookup_commit_reference_by_name(const char *name)
 	struct object_id oid;
 	struct commit *commit;
 
-	if (get_sha1_committish(name, oid.hash))
+	if (get_oid_committish(name, &oid))
 		return NULL;
 	commit = lookup_commit_reference(&oid);
 	if (parse_commit(commit))
@@ -1587,7 +1587,7 @@ struct commit *get_merge_parent(const char *name)
 	struct object *obj;
 	struct commit *commit;
 	struct object_id oid;
-	if (get_sha1(name, oid.hash))
+	if (get_oid(name, &oid))
 		return NULL;
 	obj = parse_object(&oid);
 	commit = (struct commit *)peel_to_type(name, 0, obj, OBJ_COMMIT);
diff --git a/notes.c b/notes.c
index 8f47c202c..503754d79 100644
--- a/notes.c
+++ b/notes.c
@@ -1026,7 +1026,7 @@ void init_notes(struct notes_tree *t, const char *notes_ref,
 	t->dirty = 0;
 
 	if (flags & NOTES_INIT_EMPTY || !notes_ref ||
-	    get_sha1_treeish(notes_ref, object_oid.hash))
+	    get_oid_treeish(notes_ref, &object_oid))
 		return;
 	if (flags & NOTES_INIT_WRITABLE && read_ref(notes_ref, object_oid.hash))
 		die("Cannot use notes ref %s", notes_ref);
diff --git a/remote.c b/remote.c
index 9da9040bf..2fb0895e4 100644
--- a/remote.c
+++ b/remote.c
@@ -1078,7 +1078,7 @@ static int try_explicit_object_name(const char *name,
 		return 0;
 	}
 
-	if (get_sha1(name, oid.hash))
+	if (get_oid(name, &oid))
 		return -1;
 
 	if (match) {
diff --git a/revision.c b/revision.c
index e181ad1b7..4813d8f0a 100644
--- a/revision.c
+++ b/revision.c
@@ -1303,7 +1303,7 @@ static int add_parents_only(struct rev_info *revs, const char *arg_, int flags,
 		flags ^= UNINTERESTING | BOTTOM;
 		arg++;
 	}
-	if (get_sha1_committish(arg, oid.hash))
+	if (get_oid_committish(arg, &oid))
 		return 0;
 	while (1) {
 		it = get_reference(revs, arg, &oid, 0);
@@ -1467,8 +1467,8 @@ static int handle_dotdot_1(const char *arg, char *dotdot,
 	if (!*b_name)
 		b_name = "HEAD";
 
-	if (get_sha1_with_context(a_name, oc_flags, a_oid.hash, a_oc) ||
-	    get_sha1_with_context(b_name, oc_flags, b_oid.hash, b_oc))
+	if (get_oid_with_context(a_name, oc_flags, &a_oid, a_oc) ||
+	    get_oid_with_context(b_name, oc_flags, &b_oid, b_oc))
 		return -1;
 
 	if (!cant_be_filename) {
@@ -1602,7 +1602,7 @@ int handle_revision_arg(const char *arg_, struct rev_info *revs, int flags, unsi
 	if (revarg_opt & REVARG_COMMITTISH)
 		get_sha1_flags |= GET_SHA1_COMMITTISH;
 
-	if (get_sha1_with_context(arg, get_sha1_flags, oid.hash, &oc))
+	if (get_oid_with_context(arg, get_sha1_flags, &oid, &oc))
 		return revs->ignore_missing ? 0 : -1;
 	if (!cant_be_filename)
 		verify_non_filename(revs->prefix, arg);
@@ -2321,7 +2321,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
 		struct object_id oid;
 		struct object *object;
 		struct object_context oc;
-		if (get_sha1_with_context(revs->def, 0, oid.hash, &oc))
+		if (get_oid_with_context(revs->def, 0, &oid, &oc))
 			diagnose_missing_default(revs->def);
 		object = get_reference(revs, revs->def, &oid, 0);
 		add_pending_object_with_mode(revs, object, revs->def, oc.mode);
diff --git a/sequencer.c b/sequencer.c
index 16d48a4fb..f5e85a398 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -2130,8 +2130,8 @@ static int pick_commits(struct todo_list *todo_list, struct replay_opts *opts)
 			log_tree_opt.disable_stdin = 1;
 
 			if (read_oneliner(&buf, rebase_path_orig_head(), 0) &&
-			    !get_sha1(buf.buf, orig.hash) &&
-			    !get_sha1("HEAD", head.hash)) {
+			    !get_oid(buf.buf, &orig) &&
+			    !get_oid("HEAD", &head)) {
 				diff_tree_oid(&orig, &head, "",
 					      &log_tree_opt.diffopt);
 				log_tree_diff_flush(&log_tree_opt);
@@ -2267,7 +2267,7 @@ int sequencer_continue(struct replay_opts *opts)
 		struct object_id oid;
 
 		if (read_oneliner(&buf, rebase_path_stopped_sha(), 1) &&
-		    !get_sha1_committish(buf.buf, oid.hash))
+		    !get_oid_committish(buf.buf, &oid))
 			record_in_rewritten(&oid, peek_command(&todo_list, 0));
 		strbuf_release(&buf);
 	}
diff --git a/sha1_name.c b/sha1_name.c
index d2d732c19..ec8dd9a8d 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -10,7 +10,7 @@
 #include "dir.h"
 #include "sha1-array.h"
 
-static int get_sha1_oneline(const char *, unsigned char *, struct commit_list *);
+static int get_oid_oneline(const char *, struct object_id *, struct commit_list *);
 
 typedef int (*disambiguate_hint_fn)(const struct object_id *, void *);
 
@@ -191,7 +191,7 @@ static void find_short_packed_object(struct disambiguate_state *ds)
 #define SHORT_NAME_AMBIGUOUS (-2)
 
 static int finish_object_disambiguation(struct disambiguate_state *ds,
-					unsigned char *sha1)
+					struct object_id *oid)
 {
 	if (ds->ambiguous)
 		return SHORT_NAME_AMBIGUOUS;
@@ -220,7 +220,7 @@ static int finish_object_disambiguation(struct disambiguate_state *ds,
 	if (!ds->candidate_ok)
 		return SHORT_NAME_AMBIGUOUS;
 
-	hashcpy(sha1, ds->candidate.hash);
+	oidcpy(oid, &ds->candidate);
 	return 0;
 }
 
@@ -376,7 +376,7 @@ static int show_ambiguous_object(const struct object_id *oid, void *data)
 	return 0;
 }
 
-static int get_short_sha1(const char *name, int len, unsigned char *sha1,
+static int get_short_oid(const char *name, int len, struct object_id *oid,
 			  unsigned flags)
 {
 	int status;
@@ -387,7 +387,7 @@ static int get_short_sha1(const char *name, int len, unsigned char *sha1,
 		return -1;
 
 	if (HAS_MULTI_BITS(flags & GET_SHA1_DISAMBIGUATORS))
-		die("BUG: multiple get_short_sha1 disambiguator flags");
+		die("BUG: multiple get_short_oid disambiguator flags");
 
 	if (flags & GET_SHA1_COMMIT)
 		ds.fn = disambiguate_commit_only;
@@ -404,7 +404,7 @@ static int get_short_sha1(const char *name, int len, unsigned char *sha1,
 
 	find_short_object_filename(&ds);
 	find_short_packed_object(&ds);
-	status = finish_object_disambiguation(&ds, sha1);
+	status = finish_object_disambiguation(&ds, oid);
 
 	if (!quietly && (status == SHORT_NAME_AMBIGUOUS)) {
 		error(_("short SHA1 %s is ambiguous"), ds.hex_pfx);
@@ -496,8 +496,8 @@ int find_unique_abbrev_r(char *hex, const unsigned char *sha1, int len)
 		return 40;
 	exists = has_sha1_file(sha1);
 	while (len < 40) {
-		unsigned char sha1_ret[20];
-		status = get_short_sha1(hex, len, sha1_ret, GET_SHA1_QUIETLY);
+		struct object_id oid_ret;
+		status = get_short_oid(hex, len, &oid_ret, GET_SHA1_QUIETLY);
 		if (exists
 		    ? !status
 		    : status == SHORT_NAME_NOT_FOUND) {
@@ -570,10 +570,10 @@ static inline int push_mark(const char *string, int len)
 	return at_mark(string, len, suffix, ARRAY_SIZE(suffix));
 }
 
-static int get_sha1_1(const char *name, int len, unsigned char *sha1, unsigned lookup_flags);
+static int get_oid_1(const char *name, int len, struct object_id *oid, unsigned lookup_flags);
 static int interpret_nth_prior_checkout(const char *name, int namelen, struct strbuf *buf);
 
-static int get_sha1_basic(const char *str, int len, unsigned char *sha1,
+static int get_oid_basic(const char *str, int len, struct object_id *oid,
 			  unsigned int flags)
 {
 	static const char *warn_msg = "refname '%.*s' is ambiguous.";
@@ -587,14 +587,14 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1,
 	"where \"$br\" is somehow empty and a 40-hex ref is created. Please\n"
 	"examine these refs and maybe delete them. Turn this message off by\n"
 	"running \"git config advice.objectNameWarning false\"");
-	unsigned char tmp_sha1[20];
+	struct object_id tmp_oid;
 	char *real_ref = NULL;
 	int refs_found = 0;
 	int at, reflog_len, nth_prior = 0;
 
-	if (len == 40 && !get_sha1_hex(str, sha1)) {
+	if (len == GIT_SHA1_HEXSZ && !get_oid_hex(str, oid)) {
 		if (warn_ambiguous_refs && warn_on_object_refname_ambiguity) {
-			refs_found = dwim_ref(str, len, tmp_sha1, &real_ref);
+			refs_found = dwim_ref(str, len, tmp_oid.hash, &real_ref);
 			if (refs_found > 0) {
 				warning(warn_msg, len, str);
 				if (advice_object_name_warning)
@@ -636,7 +636,7 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1,
 		int detached;
 
 		if (interpret_nth_prior_checkout(str, len, &buf) > 0) {
-			detached = (buf.len == 40 && !get_sha1_hex(buf.buf, sha1));
+			detached = (!get_oid_hex(buf.buf, oid));
 			strbuf_release(&buf);
 			if (detached)
 				return 0;
@@ -645,18 +645,18 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1,
 
 	if (!len && reflog_len)
 		/* allow "@{...}" to mean the current branch reflog */
-		refs_found = dwim_ref("HEAD", 4, sha1, &real_ref);
+		refs_found = dwim_ref("HEAD", 4, oid->hash, &real_ref);
 	else if (reflog_len)
-		refs_found = dwim_log(str, len, sha1, &real_ref);
+		refs_found = dwim_log(str, len, oid->hash, &real_ref);
 	else
-		refs_found = dwim_ref(str, len, sha1, &real_ref);
+		refs_found = dwim_ref(str, len, oid->hash, &real_ref);
 
 	if (!refs_found)
 		return -1;
 
 	if (warn_ambiguous_refs && !(flags & GET_SHA1_QUIETLY) &&
 	    (refs_found > 1 ||
-	     !get_short_sha1(str, len, tmp_sha1, GET_SHA1_QUIETLY)))
+	     !get_short_oid(str, len, &tmp_oid, GET_SHA1_QUIETLY)))
 		warning(warn_msg, len, str);
 
 	if (reflog_len) {
@@ -688,7 +688,7 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1,
 				return -1;
 			}
 		}
-		if (read_ref_at(real_ref, flags, at_time, nth, sha1, NULL,
+		if (read_ref_at(real_ref, flags, at_time, nth, oid->hash, NULL,
 				&co_time, &co_tz, &co_cnt)) {
 			if (!len) {
 				if (starts_with(real_ref, "refs/heads/")) {
@@ -721,10 +721,10 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1,
 }
 
 static int get_parent(const char *name, int len,
-		      unsigned char *result, int idx)
+		      struct object_id *result, int idx)
 {
 	struct object_id oid;
-	int ret = get_sha1_1(name, len, oid.hash, GET_SHA1_COMMITTISH);
+	int ret = get_oid_1(name, len, &oid, GET_SHA1_COMMITTISH);
 	struct commit *commit;
 	struct commit_list *p;
 
@@ -734,13 +734,13 @@ static int get_parent(const char *name, int len,
 	if (parse_commit(commit))
 		return -1;
 	if (!idx) {
-		hashcpy(result, commit->object.oid.hash);
+		oidcpy(result, &commit->object.oid);
 		return 0;
 	}
 	p = commit->parents;
 	while (p) {
 		if (!--idx) {
-			hashcpy(result, p->item->object.oid.hash);
+			oidcpy(result, &p->item->object.oid);
 			return 0;
 		}
 		p = p->next;
@@ -749,13 +749,13 @@ static int get_parent(const char *name, int len,
 }
 
 static int get_nth_ancestor(const char *name, int len,
-			    unsigned char *result, int generation)
+			    struct object_id *result, int generation)
 {
 	struct object_id oid;
 	struct commit *commit;
 	int ret;
 
-	ret = get_sha1_1(name, len, oid.hash, GET_SHA1_COMMITTISH);
+	ret = get_oid_1(name, len, &oid, GET_SHA1_COMMITTISH);
 	if (ret)
 		return ret;
 	commit = lookup_commit_reference(&oid);
@@ -767,7 +767,7 @@ static int get_nth_ancestor(const char *name, int len,
 			return -1;
 		commit = commit->parents->item;
 	}
-	hashcpy(result, commit->object.oid.hash);
+	oidcpy(result, &commit->object.oid);
 	return 0;
 }
 
@@ -796,7 +796,7 @@ struct object *peel_to_type(const char *name, int namelen,
 	}
 }
 
-static int peel_onion(const char *name, int len, unsigned char *sha1,
+static int peel_onion(const char *name, int len, struct object_id *oid,
 		      unsigned lookup_flags)
 {
 	struct object_id outer;
@@ -847,7 +847,7 @@ static int peel_onion(const char *name, int len, unsigned char *sha1,
 	else if (expected_type == OBJ_TREE)
 		lookup_flags |= GET_SHA1_TREEISH;
 
-	if (get_sha1_1(name, sp - name - 2, outer.hash, lookup_flags))
+	if (get_oid_1(name, sp - name - 2, &outer, lookup_flags))
 		return -1;
 
 	o = parse_object(&outer);
@@ -857,7 +857,7 @@ static int peel_onion(const char *name, int len, unsigned char *sha1,
 		o = deref_tag(o, name, sp - name - 2);
 		if (!o || (!o->parsed && !parse_object(&o->oid)))
 			return -1;
-		hashcpy(sha1, o->oid.hash);
+		oidcpy(oid, &o->oid);
 		return 0;
 	}
 
@@ -870,7 +870,7 @@ static int peel_onion(const char *name, int len, unsigned char *sha1,
 	if (!o)
 		return -1;
 
-	hashcpy(sha1, o->oid.hash);
+	oidcpy(oid, &o->oid);
 	if (sp[0] == '/') {
 		/* "$commit^{/foo}" */
 		char *prefix;
@@ -886,14 +886,14 @@ static int peel_onion(const char *name, int len, unsigned char *sha1,
 
 		prefix = xstrndup(sp + 1, name + len - 1 - (sp + 1));
 		commit_list_insert((struct commit *)o, &list);
-		ret = get_sha1_oneline(prefix, sha1, list);
+		ret = get_oid_oneline(prefix, oid, list);
 		free(prefix);
 		return ret;
 	}
 	return 0;
 }
 
-static int get_describe_name(const char *name, int len, unsigned char *sha1)
+static int get_describe_name(const char *name, int len, struct object_id *oid)
 {
 	const char *cp;
 	unsigned flags = GET_SHA1_QUIETLY | GET_SHA1_COMMIT;
@@ -907,14 +907,14 @@ static int get_describe_name(const char *name, int len, unsigned char *sha1)
 			if (ch == 'g' && cp[-1] == '-') {
 				cp++;
 				len -= cp - name;
-				return get_short_sha1(cp, len, sha1, flags);
+				return get_short_oid(cp, len, oid, flags);
 			}
 		}
 	}
 	return -1;
 }
 
-static int get_sha1_1(const char *name, int len, unsigned char *sha1, unsigned lookup_flags)
+static int get_oid_1(const char *name, int len, struct object_id *oid, unsigned lookup_flags)
 {
 	int ret, has_suffix;
 	const char *cp;
@@ -941,25 +941,25 @@ static int get_sha1_1(const char *name, int len, unsigned char *sha1, unsigned l
 		if (!num && len1 == len - 1)
 			num = 1;
 		if (has_suffix == '^')
-			return get_parent(name, len1, sha1, num);
+			return get_parent(name, len1, oid, num);
 		/* else if (has_suffix == '~') -- goes without saying */
-		return get_nth_ancestor(name, len1, sha1, num);
+		return get_nth_ancestor(name, len1, oid, num);
 	}
 
-	ret = peel_onion(name, len, sha1, lookup_flags);
+	ret = peel_onion(name, len, oid, lookup_flags);
 	if (!ret)
 		return 0;
 
-	ret = get_sha1_basic(name, len, sha1, lookup_flags);
+	ret = get_oid_basic(name, len, oid, lookup_flags);
 	if (!ret)
 		return 0;
 
 	/* It could be describe output that is "SOMETHING-gXXXX" */
-	ret = get_describe_name(name, len, sha1);
+	ret = get_describe_name(name, len, oid);
 	if (!ret)
 		return 0;
 
-	return get_short_sha1(name, len, sha1, lookup_flags);
+	return get_short_oid(name, len, oid, lookup_flags);
 }
 
 /*
@@ -996,7 +996,7 @@ static int handle_one_ref(const char *path, const struct object_id *oid,
 	return 0;
 }
 
-static int get_sha1_oneline(const char *prefix, unsigned char *sha1,
+static int get_oid_oneline(const char *prefix, struct object_id *oid,
 			    struct commit_list *list)
 {
 	struct commit_list *backup = NULL, *l;
@@ -1036,7 +1036,7 @@ static int get_sha1_oneline(const char *prefix, unsigned char *sha1,
 		unuse_commit_buffer(commit, buf);
 
 		if (matches) {
-			hashcpy(sha1, commit->object.oid.hash);
+			oidcpy(oid, &commit->object.oid);
 			found = 1;
 			break;
 		}
@@ -1132,7 +1132,7 @@ int get_oid_mb(const char *name, struct object_id *oid)
 		struct strbuf sb;
 		strbuf_init(&sb, dots - name);
 		strbuf_add(&sb, name, dots - name);
-		st = get_sha1_committish(sb.buf, oid_tmp.hash);
+		st = get_oid_committish(sb.buf, &oid_tmp);
 		strbuf_release(&sb);
 	}
 	if (st)
@@ -1141,7 +1141,7 @@ int get_oid_mb(const char *name, struct object_id *oid)
 	if (!one)
 		return -1;
 
-	if (get_sha1_committish(dots[3] ? (dots + 3) : "HEAD", oid_tmp.hash))
+	if (get_oid_committish(dots[3] ? (dots + 3) : "HEAD", &oid_tmp))
 		return -1;
 	two = lookup_commit_reference_gently(&oid_tmp, 0);
 	if (!two)
@@ -1330,21 +1330,13 @@ int strbuf_check_branch_ref(struct strbuf *sb, const char *name)
 }
 
 /*
- * This is like "get_sha1_basic()", except it allows "sha1 expressions",
+ * This is like "get_oid_basic()", except it allows "object ID expressions",
  * notably "xyz^" for "parent of xyz"
  */
-int get_sha1(const char *name, unsigned char *sha1)
-{
-	struct object_context unused;
-	return get_sha1_with_context(name, 0, sha1, &unused);
-}
-
-/*
- * This is like "get_sha1()", but for struct object_id.
- */
 int get_oid(const char *name, struct object_id *oid)
 {
-	return get_sha1(name, oid->hash);
+	struct object_context unused;
+	return get_oid_with_context(name, 0, oid, &unused);
 }
 
 
@@ -1358,49 +1350,49 @@ int get_oid(const char *name, struct object_id *oid)
  * commit-ish. It is merely to give a hint to the disambiguation
  * machinery.
  */
-int get_sha1_committish(const char *name, unsigned char *sha1)
+int get_oid_committish(const char *name, struct object_id *oid)
 {
 	struct object_context unused;
-	return get_sha1_with_context(name, GET_SHA1_COMMITTISH,
-				     sha1, &unused);
+	return get_oid_with_context(name, GET_SHA1_COMMITTISH,
+				    oid, &unused);
 }
 
-int get_sha1_treeish(const char *name, unsigned char *sha1)
+int get_oid_treeish(const char *name, struct object_id *oid)
 {
 	struct object_context unused;
-	return get_sha1_with_context(name, GET_SHA1_TREEISH,
-				     sha1, &unused);
+	return get_oid_with_context(name, GET_SHA1_TREEISH,
+				    oid, &unused);
 }
 
-int get_sha1_commit(const char *name, unsigned char *sha1)
+int get_oid_commit(const char *name, struct object_id *oid)
 {
 	struct object_context unused;
-	return get_sha1_with_context(name, GET_SHA1_COMMIT,
-				     sha1, &unused);
+	return get_oid_with_context(name, GET_SHA1_COMMIT,
+				    oid, &unused);
 }
 
-int get_sha1_tree(const char *name, unsigned char *sha1)
+int get_oid_tree(const char *name, struct object_id *oid)
 {
 	struct object_context unused;
-	return get_sha1_with_context(name, GET_SHA1_TREE,
-				     sha1, &unused);
+	return get_oid_with_context(name, GET_SHA1_TREE,
+				    oid, &unused);
 }
 
-int get_sha1_blob(const char *name, unsigned char *sha1)
+int get_oid_blob(const char *name, struct object_id *oid)
 {
 	struct object_context unused;
-	return get_sha1_with_context(name, GET_SHA1_BLOB,
-				     sha1, &unused);
+	return get_oid_with_context(name, GET_SHA1_BLOB,
+				    oid, &unused);
 }
 
 /* Must be called only when object_name:filename doesn't exist. */
-static void diagnose_invalid_sha1_path(const char *prefix,
-				       const char *filename,
-				       const unsigned char *tree_sha1,
-				       const char *object_name,
-				       int object_name_len)
+static void diagnose_invalid_oid_path(const char *prefix,
+				      const char *filename,
+				      const struct object_id *tree_oid,
+				      const char *object_name,
+				      int object_name_len)
 {
-	unsigned char sha1[20];
+	struct object_id oid;
 	unsigned mode;
 
 	if (!prefix)
@@ -1412,8 +1404,8 @@ static void diagnose_invalid_sha1_path(const char *prefix,
 	if (is_missing_file_error(errno)) {
 		char *fullname = xstrfmt("%s%s", prefix, filename);
 
-		if (!get_tree_entry(tree_sha1, fullname,
-				    sha1, &mode)) {
+		if (!get_tree_entry(tree_oid->hash, fullname,
+				    oid.hash, &mode)) {
 			die("Path '%s' exists, but not '%s'.\n"
 			    "Did you mean '%.*s:%s' aka '%.*s:./%s'?",
 			    fullname,
@@ -1496,11 +1488,11 @@ static char *resolve_relative_path(const char *rel)
 			   rel);
 }
 
-static int get_sha1_with_context_1(const char *name,
-				   unsigned flags,
-				   const char *prefix,
-				   unsigned char *sha1,
-				   struct object_context *oc)
+static int get_oid_with_context_1(const char *name,
+				  unsigned flags,
+				  const char *prefix,
+				  struct object_id *oid,
+				  struct object_context *oc)
 {
 	int ret, bracket_depth;
 	int namelen = strlen(name);
@@ -1513,7 +1505,7 @@ static int get_sha1_with_context_1(const char *name,
 	memset(oc, 0, sizeof(*oc));
 	oc->mode = S_IFINVALID;
 	strbuf_init(&oc->symlink_path, 0);
-	ret = get_sha1_1(name, namelen, sha1, flags);
+	ret = get_oid_1(name, namelen, oid, flags);
 	if (!ret)
 		return ret;
 	/*
@@ -1533,7 +1525,7 @@ static int get_sha1_with_context_1(const char *name,
 
 			for_each_ref(handle_one_ref, &list);
 			commit_list_sort_by_date(&list);
-			return get_sha1_oneline(name + 2, sha1, list);
+			return get_oid_oneline(name + 2, oid, list);
 		}
 		if (namelen < 3 ||
 		    name[2] != ':' ||
@@ -1565,7 +1557,7 @@ static int get_sha1_with_context_1(const char *name,
 			    memcmp(ce->name, cp, namelen))
 				break;
 			if (ce_stage(ce) == stage) {
-				hashcpy(sha1, ce->oid.hash);
+				oidcpy(oid, &ce->oid);
 				oc->mode = ce->ce_mode;
 				free(new_path);
 				return 0;
@@ -1586,14 +1578,14 @@ static int get_sha1_with_context_1(const char *name,
 			break;
 	}
 	if (*cp == ':') {
-		unsigned char tree_sha1[20];
+		struct object_id tree_oid;
 		int len = cp - name;
 		unsigned sub_flags = flags;
 
 		sub_flags &= ~GET_SHA1_DISAMBIGUATORS;
 		sub_flags |= GET_SHA1_TREEISH;
 
-		if (!get_sha1_1(name, len, tree_sha1, sub_flags)) {
+		if (!get_oid_1(name, len, &tree_oid, sub_flags)) {
 			const char *filename = cp+1;
 			char *new_filename = NULL;
 
@@ -1601,20 +1593,20 @@ static int get_sha1_with_context_1(const char *name,
 			if (new_filename)
 				filename = new_filename;
 			if (flags & GET_SHA1_FOLLOW_SYMLINKS) {
-				ret = get_tree_entry_follow_symlinks(tree_sha1,
-					filename, sha1, &oc->symlink_path,
+				ret = get_tree_entry_follow_symlinks(tree_oid.hash,
+					filename, oid->hash, &oc->symlink_path,
 					&oc->mode);
 			} else {
-				ret = get_tree_entry(tree_sha1, filename,
-						     sha1, &oc->mode);
+				ret = get_tree_entry(tree_oid.hash, filename,
+						     oid->hash, &oc->mode);
 				if (ret && only_to_die) {
-					diagnose_invalid_sha1_path(prefix,
+					diagnose_invalid_oid_path(prefix,
 								   filename,
-								   tree_sha1,
+								   &tree_oid,
 								   name, len);
 				}
 			}
-			hashcpy(oc->tree, tree_sha1);
+			hashcpy(oc->tree, tree_oid.hash);
 			if (flags & GET_SHA1_RECORD_PATH)
 				oc->path = xstrdup(filename);
 
@@ -1638,13 +1630,13 @@ static int get_sha1_with_context_1(const char *name,
 void maybe_die_on_misspelt_object_name(const char *name, const char *prefix)
 {
 	struct object_context oc;
-	unsigned char sha1[20];
-	get_sha1_with_context_1(name, GET_SHA1_ONLY_TO_DIE, prefix, sha1, &oc);
+	struct object_id oid;
+	get_oid_with_context_1(name, GET_SHA1_ONLY_TO_DIE, prefix, &oid, &oc);
 }
 
-int get_sha1_with_context(const char *str, unsigned flags, unsigned char *sha1, struct object_context *oc)
+int get_oid_with_context(const char *str, unsigned flags, struct object_id *oid, struct object_context *oc)
 {
 	if (flags & GET_SHA1_FOLLOW_SYMLINKS && flags & GET_SHA1_ONLY_TO_DIE)
 		die("BUG: incompatible flags for get_sha1_with_context");
-	return get_sha1_with_context_1(str, flags, NULL, sha1, oc);
+	return get_oid_with_context_1(str, flags, NULL, oid, oc);
 }
diff --git a/transport-helper.c b/transport-helper.c
index 33cff38cc..8f68d69a8 100644
--- a/transport-helper.c
+++ b/transport-helper.c
@@ -927,7 +927,7 @@ static int push_refs_with_export(struct transport *transport,
 		struct object_id oid;
 
 		private = apply_refspecs(data->refspecs, data->refspec_nr, ref->name);
-		if (private && !get_sha1(private, oid.hash)) {
+		if (private && !get_oid(private, &oid)) {
 			strbuf_addf(&buf, "^%s", private);
 			string_list_append(&revlist_args, strbuf_detach(&buf, NULL));
 			oidcpy(&ref->old_oid, &oid);

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH 12/12] sha1_name: convert GET_SHA1* flags to GET_OID*
  2017-07-03 18:55 [PATCH 00/12] object_id part 9 brian m. carlson
                   ` (10 preceding siblings ...)
  2017-07-03 18:55 ` [PATCH 11/12] sha1_name: convert get_sha1* to get_oid* brian m. carlson
@ 2017-07-03 18:55 ` brian m. carlson
  2017-07-05  4:10 ` [PATCH 00/12] object_id part 9 Junio C Hamano
  12 siblings, 0 replies; 20+ messages in thread
From: brian m. carlson @ 2017-07-03 18:55 UTC (permalink / raw)
  To: git; +Cc: Brandon Williams, Stefan Beller, Jeff King

Convert the flags for get_oid_with_context and friends to use "OID"
instead of "SHA1" in their names.

This transform was made by running the following one-liner on the
affected files:

  perl -pi -e 's/GET_SHA1/GET_OID/g'

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 builtin/cat-file.c  |  4 ++--
 builtin/grep.c      |  2 +-
 builtin/log.c       |  2 +-
 builtin/rev-parse.c |  2 +-
 cache.h             | 28 +++++++++++------------
 refs.c              |  2 +-
 revision.c          |  6 ++---
 sha1_name.c         | 64 ++++++++++++++++++++++++++---------------------------
 8 files changed, 55 insertions(+), 55 deletions(-)

diff --git a/builtin/cat-file.c b/builtin/cat-file.c
index 695168a98..823608bef 100644
--- a/builtin/cat-file.c
+++ b/builtin/cat-file.c
@@ -63,7 +63,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
 	if (unknown_type)
 		flags |= LOOKUP_UNKNOWN_OBJECT;
 
-	if (get_oid_with_context(obj_name, GET_SHA1_RECORD_PATH,
+	if (get_oid_with_context(obj_name, GET_OID_RECORD_PATH,
 				 &oid, &obj_context))
 		die("Not a valid object name %s", obj_name);
 
@@ -360,7 +360,7 @@ static void batch_one_object(const char *obj_name, struct batch_options *opt,
 			     struct expand_data *data)
 {
 	struct object_context ctx;
-	int flags = opt->follow_symlinks ? GET_SHA1_FOLLOW_SYMLINKS : 0;
+	int flags = opt->follow_symlinks ? GET_OID_FOLLOW_SYMLINKS : 0;
 	enum follow_symlinks_result result;
 
 	result = get_oid_with_context(obj_name, flags, &data->oid, &ctx);
diff --git a/builtin/grep.c b/builtin/grep.c
index a309ab7c2..48aa39f99 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -1206,7 +1206,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
 			break;
 		}
 
-		if (get_oid_with_context(arg, GET_SHA1_RECORD_PATH,
+		if (get_oid_with_context(arg, GET_OID_RECORD_PATH,
 					 &oid, &oc)) {
 			if (seen_dashdash)
 				die(_("unable to resolve revision: %s"), arg);
diff --git a/builtin/log.c b/builtin/log.c
index 60fac9d4d..3dbdf8cad 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -484,7 +484,7 @@ static int show_blob_object(const struct object_id *oid, struct rev_info *rev, c
 	    !DIFF_OPT_TST(&rev->diffopt, ALLOW_TEXTCONV))
 		return stream_blob_to_fd(1, oid, NULL, 0);
 
-	if (get_oid_with_context(obj_name, GET_SHA1_RECORD_PATH,
+	if (get_oid_with_context(obj_name, GET_OID_RECORD_PATH,
 				 &oidc, &obj_context))
 		die(_("Not a valid object name %s"), obj_name);
 	if (!obj_context.path ||
diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c
index 041b7898c..2bd28d3c0 100644
--- a/builtin/rev-parse.c
+++ b/builtin/rev-parse.c
@@ -702,7 +702,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
 			}
 			if (!strcmp(arg, "--quiet") || !strcmp(arg, "-q")) {
 				quiet = 1;
-				flags |= GET_SHA1_QUIETLY;
+				flags |= GET_OID_QUIETLY;
 				continue;
 			}
 			if (opt_with_value(arg, "--short", &arg)) {
diff --git a/cache.h b/cache.h
index c68f44e10..c14351cba 100644
--- a/cache.h
+++ b/cache.h
@@ -1351,27 +1351,27 @@ struct object_context {
 	 */
 	struct strbuf symlink_path;
 	/*
-	 * If GET_SHA1_RECORD_PATH is set, this will record path (if any)
+	 * If GET_OID_RECORD_PATH is set, this will record path (if any)
 	 * found when resolving the name. The caller is responsible for
 	 * releasing the memory.
 	 */
 	char *path;
 };
 
-#define GET_SHA1_QUIETLY           01
-#define GET_SHA1_COMMIT            02
-#define GET_SHA1_COMMITTISH        04
-#define GET_SHA1_TREE             010
-#define GET_SHA1_TREEISH          020
-#define GET_SHA1_BLOB             040
-#define GET_SHA1_FOLLOW_SYMLINKS 0100
-#define GET_SHA1_RECORD_PATH     0200
-#define GET_SHA1_ONLY_TO_DIE    04000
+#define GET_OID_QUIETLY           01
+#define GET_OID_COMMIT            02
+#define GET_OID_COMMITTISH        04
+#define GET_OID_TREE             010
+#define GET_OID_TREEISH          020
+#define GET_OID_BLOB             040
+#define GET_OID_FOLLOW_SYMLINKS 0100
+#define GET_OID_RECORD_PATH     0200
+#define GET_OID_ONLY_TO_DIE    04000
 
-#define GET_SHA1_DISAMBIGUATORS \
-	(GET_SHA1_COMMIT | GET_SHA1_COMMITTISH | \
-	GET_SHA1_TREE | GET_SHA1_TREEISH | \
-	GET_SHA1_BLOB)
+#define GET_OID_DISAMBIGUATORS \
+	(GET_OID_COMMIT | GET_OID_COMMITTISH | \
+	GET_OID_TREE | GET_OID_TREEISH | \
+	GET_OID_BLOB)
 
 extern int get_oid(const char *str, struct object_id *oid);
 extern int get_oid_commit(const char *str, struct object_id *oid);
diff --git a/refs.c b/refs.c
index 88658ba76..90ecb1d4a 100644
--- a/refs.c
+++ b/refs.c
@@ -818,7 +818,7 @@ int read_ref_at(const char *refname, unsigned int flags, timestamp_t at_time, in
 	for_each_reflog_ent_reverse(refname, read_ref_at_ent, &cb);
 
 	if (!cb.reccnt) {
-		if (flags & GET_SHA1_QUIETLY)
+		if (flags & GET_OID_QUIETLY)
 			exit(128);
 		else
 			die("Log for %s is empty.", refname);
diff --git a/revision.c b/revision.c
index 4813d8f0a..08caf8bb0 100644
--- a/revision.c
+++ b/revision.c
@@ -1453,7 +1453,7 @@ static int handle_dotdot_1(const char *arg, char *dotdot,
 	unsigned int a_flags, b_flags;
 	int symmetric = 0;
 	unsigned int flags_exclude = flags ^ (UNINTERESTING | BOTTOM);
-	unsigned int oc_flags = GET_SHA1_COMMITTISH | GET_SHA1_RECORD_PATH;
+	unsigned int oc_flags = GET_OID_COMMITTISH | GET_OID_RECORD_PATH;
 
 	a_name = arg;
 	if (!*a_name)
@@ -1549,7 +1549,7 @@ int handle_revision_arg(const char *arg_, struct rev_info *revs, int flags, unsi
 	int local_flags;
 	const char *arg = arg_;
 	int cant_be_filename = revarg_opt & REVARG_CANNOT_BE_FILENAME;
-	unsigned get_sha1_flags = GET_SHA1_RECORD_PATH;
+	unsigned get_sha1_flags = GET_OID_RECORD_PATH;
 
 	flags = flags & UNINTERESTING ? flags | BOTTOM : flags & ~BOTTOM;
 
@@ -1600,7 +1600,7 @@ int handle_revision_arg(const char *arg_, struct rev_info *revs, int flags, unsi
 	}
 
 	if (revarg_opt & REVARG_COMMITTISH)
-		get_sha1_flags |= GET_SHA1_COMMITTISH;
+		get_sha1_flags |= GET_OID_COMMITTISH;
 
 	if (get_oid_with_context(arg, get_sha1_flags, &oid, &oc))
 		return revs->ignore_missing ? 0 : -1;
diff --git a/sha1_name.c b/sha1_name.c
index ec8dd9a8d..f7fad38c9 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -381,23 +381,23 @@ static int get_short_oid(const char *name, int len, struct object_id *oid,
 {
 	int status;
 	struct disambiguate_state ds;
-	int quietly = !!(flags & GET_SHA1_QUIETLY);
+	int quietly = !!(flags & GET_OID_QUIETLY);
 
 	if (init_object_disambiguation(name, len, &ds) < 0)
 		return -1;
 
-	if (HAS_MULTI_BITS(flags & GET_SHA1_DISAMBIGUATORS))
+	if (HAS_MULTI_BITS(flags & GET_OID_DISAMBIGUATORS))
 		die("BUG: multiple get_short_oid disambiguator flags");
 
-	if (flags & GET_SHA1_COMMIT)
+	if (flags & GET_OID_COMMIT)
 		ds.fn = disambiguate_commit_only;
-	else if (flags & GET_SHA1_COMMITTISH)
+	else if (flags & GET_OID_COMMITTISH)
 		ds.fn = disambiguate_committish_only;
-	else if (flags & GET_SHA1_TREE)
+	else if (flags & GET_OID_TREE)
 		ds.fn = disambiguate_tree_only;
-	else if (flags & GET_SHA1_TREEISH)
+	else if (flags & GET_OID_TREEISH)
 		ds.fn = disambiguate_treeish_only;
-	else if (flags & GET_SHA1_BLOB)
+	else if (flags & GET_OID_BLOB)
 		ds.fn = disambiguate_blob_only;
 	else
 		ds.fn = default_disambiguate_hint;
@@ -497,7 +497,7 @@ int find_unique_abbrev_r(char *hex, const unsigned char *sha1, int len)
 	exists = has_sha1_file(sha1);
 	while (len < 40) {
 		struct object_id oid_ret;
-		status = get_short_oid(hex, len, &oid_ret, GET_SHA1_QUIETLY);
+		status = get_short_oid(hex, len, &oid_ret, GET_OID_QUIETLY);
 		if (exists
 		    ? !status
 		    : status == SHORT_NAME_NOT_FOUND) {
@@ -654,9 +654,9 @@ static int get_oid_basic(const char *str, int len, struct object_id *oid,
 	if (!refs_found)
 		return -1;
 
-	if (warn_ambiguous_refs && !(flags & GET_SHA1_QUIETLY) &&
+	if (warn_ambiguous_refs && !(flags & GET_OID_QUIETLY) &&
 	    (refs_found > 1 ||
-	     !get_short_oid(str, len, &tmp_oid, GET_SHA1_QUIETLY)))
+	     !get_short_oid(str, len, &tmp_oid, GET_OID_QUIETLY)))
 		warning(warn_msg, len, str);
 
 	if (reflog_len) {
@@ -701,13 +701,13 @@ static int get_oid_basic(const char *str, int len, struct object_id *oid,
 				}
 			}
 			if (at_time) {
-				if (!(flags & GET_SHA1_QUIETLY)) {
+				if (!(flags & GET_OID_QUIETLY)) {
 					warning("Log for '%.*s' only goes "
 						"back to %s.", len, str,
 						show_date(co_time, co_tz, DATE_MODE(RFC2822)));
 				}
 			} else {
-				if (flags & GET_SHA1_QUIETLY) {
+				if (flags & GET_OID_QUIETLY) {
 					exit(128);
 				}
 				die("Log for '%.*s' only has %d entries.",
@@ -724,7 +724,7 @@ static int get_parent(const char *name, int len,
 		      struct object_id *result, int idx)
 {
 	struct object_id oid;
-	int ret = get_oid_1(name, len, &oid, GET_SHA1_COMMITTISH);
+	int ret = get_oid_1(name, len, &oid, GET_OID_COMMITTISH);
 	struct commit *commit;
 	struct commit_list *p;
 
@@ -755,7 +755,7 @@ static int get_nth_ancestor(const char *name, int len,
 	struct commit *commit;
 	int ret;
 
-	ret = get_oid_1(name, len, &oid, GET_SHA1_COMMITTISH);
+	ret = get_oid_1(name, len, &oid, GET_OID_COMMITTISH);
 	if (ret)
 		return ret;
 	commit = lookup_commit_reference(&oid);
@@ -841,11 +841,11 @@ static int peel_onion(const char *name, int len, struct object_id *oid,
 	else
 		return -1;
 
-	lookup_flags &= ~GET_SHA1_DISAMBIGUATORS;
+	lookup_flags &= ~GET_OID_DISAMBIGUATORS;
 	if (expected_type == OBJ_COMMIT)
-		lookup_flags |= GET_SHA1_COMMITTISH;
+		lookup_flags |= GET_OID_COMMITTISH;
 	else if (expected_type == OBJ_TREE)
-		lookup_flags |= GET_SHA1_TREEISH;
+		lookup_flags |= GET_OID_TREEISH;
 
 	if (get_oid_1(name, sp - name - 2, &outer, lookup_flags))
 		return -1;
@@ -896,7 +896,7 @@ static int peel_onion(const char *name, int len, struct object_id *oid,
 static int get_describe_name(const char *name, int len, struct object_id *oid)
 {
 	const char *cp;
-	unsigned flags = GET_SHA1_QUIETLY | GET_SHA1_COMMIT;
+	unsigned flags = GET_OID_QUIETLY | GET_OID_COMMIT;
 
 	for (cp = name + len - 1; name + 2 <= cp; cp--) {
 		char ch = *cp;
@@ -1353,35 +1353,35 @@ int get_oid(const char *name, struct object_id *oid)
 int get_oid_committish(const char *name, struct object_id *oid)
 {
 	struct object_context unused;
-	return get_oid_with_context(name, GET_SHA1_COMMITTISH,
+	return get_oid_with_context(name, GET_OID_COMMITTISH,
 				    oid, &unused);
 }
 
 int get_oid_treeish(const char *name, struct object_id *oid)
 {
 	struct object_context unused;
-	return get_oid_with_context(name, GET_SHA1_TREEISH,
+	return get_oid_with_context(name, GET_OID_TREEISH,
 				    oid, &unused);
 }
 
 int get_oid_commit(const char *name, struct object_id *oid)
 {
 	struct object_context unused;
-	return get_oid_with_context(name, GET_SHA1_COMMIT,
+	return get_oid_with_context(name, GET_OID_COMMIT,
 				    oid, &unused);
 }
 
 int get_oid_tree(const char *name, struct object_id *oid)
 {
 	struct object_context unused;
-	return get_oid_with_context(name, GET_SHA1_TREE,
+	return get_oid_with_context(name, GET_OID_TREE,
 				    oid, &unused);
 }
 
 int get_oid_blob(const char *name, struct object_id *oid)
 {
 	struct object_context unused;
-	return get_oid_with_context(name, GET_SHA1_BLOB,
+	return get_oid_with_context(name, GET_OID_BLOB,
 				    oid, &unused);
 }
 
@@ -1497,10 +1497,10 @@ static int get_oid_with_context_1(const char *name,
 	int ret, bracket_depth;
 	int namelen = strlen(name);
 	const char *cp;
-	int only_to_die = flags & GET_SHA1_ONLY_TO_DIE;
+	int only_to_die = flags & GET_OID_ONLY_TO_DIE;
 
 	if (only_to_die)
-		flags |= GET_SHA1_QUIETLY;
+		flags |= GET_OID_QUIETLY;
 
 	memset(oc, 0, sizeof(*oc));
 	oc->mode = S_IFINVALID;
@@ -1543,7 +1543,7 @@ static int get_oid_with_context_1(const char *name,
 			namelen = strlen(cp);
 		}
 
-		if (flags & GET_SHA1_RECORD_PATH)
+		if (flags & GET_OID_RECORD_PATH)
 			oc->path = xstrdup(cp);
 
 		if (!active_cache)
@@ -1582,8 +1582,8 @@ static int get_oid_with_context_1(const char *name,
 		int len = cp - name;
 		unsigned sub_flags = flags;
 
-		sub_flags &= ~GET_SHA1_DISAMBIGUATORS;
-		sub_flags |= GET_SHA1_TREEISH;
+		sub_flags &= ~GET_OID_DISAMBIGUATORS;
+		sub_flags |= GET_OID_TREEISH;
 
 		if (!get_oid_1(name, len, &tree_oid, sub_flags)) {
 			const char *filename = cp+1;
@@ -1592,7 +1592,7 @@ static int get_oid_with_context_1(const char *name,
 			new_filename = resolve_relative_path(filename);
 			if (new_filename)
 				filename = new_filename;
-			if (flags & GET_SHA1_FOLLOW_SYMLINKS) {
+			if (flags & GET_OID_FOLLOW_SYMLINKS) {
 				ret = get_tree_entry_follow_symlinks(tree_oid.hash,
 					filename, oid->hash, &oc->symlink_path,
 					&oc->mode);
@@ -1607,7 +1607,7 @@ static int get_oid_with_context_1(const char *name,
 				}
 			}
 			hashcpy(oc->tree, tree_oid.hash);
-			if (flags & GET_SHA1_RECORD_PATH)
+			if (flags & GET_OID_RECORD_PATH)
 				oc->path = xstrdup(filename);
 
 			free(new_filename);
@@ -1631,12 +1631,12 @@ void maybe_die_on_misspelt_object_name(const char *name, const char *prefix)
 {
 	struct object_context oc;
 	struct object_id oid;
-	get_oid_with_context_1(name, GET_SHA1_ONLY_TO_DIE, prefix, &oid, &oc);
+	get_oid_with_context_1(name, GET_OID_ONLY_TO_DIE, prefix, &oid, &oc);
 }
 
 int get_oid_with_context(const char *str, unsigned flags, struct object_id *oid, struct object_context *oc)
 {
-	if (flags & GET_SHA1_FOLLOW_SYMLINKS && flags & GET_SHA1_ONLY_TO_DIE)
+	if (flags & GET_OID_FOLLOW_SYMLINKS && flags & GET_OID_ONLY_TO_DIE)
 		die("BUG: incompatible flags for get_sha1_with_context");
 	return get_oid_with_context_1(str, flags, NULL, oid, oc);
 }

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* Re: [PATCH 06/12] builtin/update_ref: convert to struct object_id
  2017-07-03 18:55 ` [PATCH 06/12] builtin/update_ref: " brian m. carlson
@ 2017-07-03 20:49   ` Ævar Arnfjörð Bjarmason
  2017-07-04 14:45     ` brian m. carlson
  0 siblings, 1 reply; 20+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2017-07-03 20:49 UTC (permalink / raw)
  To: brian m. carlson; +Cc: git, Brandon Williams, Stefan Beller, Jeff King


On Mon, Jul 03 2017, brian m. carlson jotted:

> Convert the uses of unsigned char * to struct object_id.

I read all of this over (but didn't apply/test it) and it looks good to
me, Just a small nit:

> [...]
>  1 file changed, 34 insertions(+), 35 deletions(-)
> [...]
>  	struct strbuf err = STRBUF_INIT;
>  	char *refname;
> -	unsigned char new_sha1[20];
> -	unsigned char old_sha1[20];
> +	struct object_id new_oid, old_oid;
> [...]

It's easier to skim these when you leave changes in the number of lines
to separate commits which do more than just rename boilerplate code,
e.g. as in 05/12 where `const char *p` is introduced.

Thanks for working on this.

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH 06/12] builtin/update_ref: convert to struct object_id
  2017-07-03 20:49   ` Ævar Arnfjörð Bjarmason
@ 2017-07-04 14:45     ` brian m. carlson
  0 siblings, 0 replies; 20+ messages in thread
From: brian m. carlson @ 2017-07-04 14:45 UTC (permalink / raw)
  To: Ævar Arnfjörð Bjarmason
  Cc: git, Brandon Williams, Stefan Beller, Jeff King

[-- Attachment #1: Type: text/plain, Size: 995 bytes --]

On Mon, Jul 03, 2017 at 10:49:39PM +0200, Ævar Arnfjörð Bjarmason wrote:
> On Mon, Jul 03 2017, brian m. carlson jotted:
> > [...]
> >  1 file changed, 34 insertions(+), 35 deletions(-)
> > [...]
> >  	struct strbuf err = STRBUF_INIT;
> >  	char *refname;
> > -	unsigned char new_sha1[20];
> > -	unsigned char old_sha1[20];
> > +	struct object_id new_oid, old_oid;
> > [...]
> 
> It's easier to skim these when you leave changes in the number of lines
> to separate commits which do more than just rename boilerplate code,
> e.g. as in 05/12 where `const char *p` is introduced.

I can do that in the future.  I've received feedback in the past that I
could coalesce them into one line instead of needing multiple lines, but
since I don't have a preference either way, I'm happy to do whatever
makes review easier.
-- 
brian m. carlson / brian with sandals: Houston, Texas, US
https://www.crustytoothpaste.net/~bmc | My opinion only
OpenPGP: https://keybase.io/bk2204

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 868 bytes --]

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH 00/12] object_id part 9
  2017-07-03 18:55 [PATCH 00/12] object_id part 9 brian m. carlson
                   ` (11 preceding siblings ...)
  2017-07-03 18:55 ` [PATCH 12/12] sha1_name: convert GET_SHA1* flags to GET_OID* brian m. carlson
@ 2017-07-05  4:10 ` Junio C Hamano
  2017-07-05 18:02   ` Stefan Beller
  12 siblings, 1 reply; 20+ messages in thread
From: Junio C Hamano @ 2017-07-05  4:10 UTC (permalink / raw)
  To: brian m. carlson; +Cc: git, Brandon Williams, Stefan Beller, Jeff King

"brian m. carlson" <sandals@crustytoothpaste.net> writes:

> It is possible there will be some other conflicts with in flight topics,
> as get_sha1 is commonly used in the codebase.  This is unavoidable to
> some extent, but should be kept in mind.  My experience is that usually
> the required changes for conversion are minimal.

Thanks. 

It did have a few conflicts in submodule area and sequencer, but
they were (hopefully) trivial to resolve.  The result is queued at
the tip of 'pu'.  It seems to pass the tests locally and also at
Travis.



^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH 11/12] sha1_name: convert get_sha1* to get_oid*
  2017-07-03 18:55 ` [PATCH 11/12] sha1_name: convert get_sha1* to get_oid* brian m. carlson
@ 2017-07-05 18:01   ` Stefan Beller
  2017-07-05 18:38     ` Junio C Hamano
  0 siblings, 1 reply; 20+ messages in thread
From: Stefan Beller @ 2017-07-05 18:01 UTC (permalink / raw)
  To: brian m. carlson
  Cc: git@vger.kernel.org, Brandon Williams, Stefan Beller, Jeff King

> @@ -496,8 +496,8 @@ int find_unique_abbrev_r(char *hex, const unsigned char *sha1, int len)
>                 return 40;
>         exists = has_sha1_file(sha1);
>         while (len < 40) {

Here are two prime candidates for GIT_SHA1_HEXSZ, too.

> @@ -636,7 +636,7 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1,
>                 int detached;
>
>                 if (interpret_nth_prior_checkout(str, len, &buf) > 0) {
> -                       detached = (buf.len == 40 && !get_sha1_hex(buf.buf, sha1));
> +                       detached = (!get_oid_hex(buf.buf, oid));

omitting the length check here?

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH 00/12] object_id part 9
  2017-07-05  4:10 ` [PATCH 00/12] object_id part 9 Junio C Hamano
@ 2017-07-05 18:02   ` Stefan Beller
  0 siblings, 0 replies; 20+ messages in thread
From: Stefan Beller @ 2017-07-05 18:02 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: brian m. carlson, git@vger.kernel.org, Brandon Williams,
	Stefan Beller, Jeff King

On Tue, Jul 4, 2017 at 9:10 PM, Junio C Hamano <gitster@pobox.com> wrote:
> "brian m. carlson" <sandals@crustytoothpaste.net> writes:
>
>> It is possible there will be some other conflicts with in flight topics,
>> as get_sha1 is commonly used in the codebase.  This is unavoidable to
>> some extent, but should be kept in mind.  My experience is that usually
>> the required changes for conversion are minimal.
>
> Thanks.
>
> It did have a few conflicts in submodule area and sequencer, but
> they were (hopefully) trivial to resolve.  The result is queued at
> the tip of 'pu'.  It seems to pass the tests locally and also at
> Travis.

The series as queued (modulo 2 minor nits/questions asked in
patch 11/12) as well as the conflict resolution look good to me.

Thanks,
Stefan

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH 11/12] sha1_name: convert get_sha1* to get_oid*
  2017-07-05 18:01   ` Stefan Beller
@ 2017-07-05 18:38     ` Junio C Hamano
  2017-07-07 21:22       ` brian m. carlson
  0 siblings, 1 reply; 20+ messages in thread
From: Junio C Hamano @ 2017-07-05 18:38 UTC (permalink / raw)
  To: Stefan Beller
  Cc: brian m. carlson, git@vger.kernel.org, Brandon Williams,
	Stefan Beller, Jeff King

Stefan Beller <sbeller@google.com> writes:

>> @@ -636,7 +636,7 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1,
>>                 int detached;
>>
>>                 if (interpret_nth_prior_checkout(str, len, &buf) > 0) {
>> -                       detached = (buf.len == 40 && !get_sha1_hex(buf.buf, sha1));
>> +                       detached = (!get_oid_hex(buf.buf, oid));
>
> omitting the length check here?

Good eyes.  It probably should check with the possible oid lengths.

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH 11/12] sha1_name: convert get_sha1* to get_oid*
  2017-07-05 18:38     ` Junio C Hamano
@ 2017-07-07 21:22       ` brian m. carlson
  0 siblings, 0 replies; 20+ messages in thread
From: brian m. carlson @ 2017-07-07 21:22 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: Stefan Beller, git@vger.kernel.org, Brandon Williams,
	Stefan Beller, Jeff King

[-- Attachment #1: Type: text/plain, Size: 843 bytes --]

On Wed, Jul 05, 2017 at 11:38:51AM -0700, Junio C Hamano wrote:
> Stefan Beller <sbeller@google.com> writes:
> 
> >> @@ -636,7 +636,7 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1,
> >>                 int detached;
> >>
> >>                 if (interpret_nth_prior_checkout(str, len, &buf) > 0) {
> >> -                       detached = (buf.len == 40 && !get_sha1_hex(buf.buf, sha1));
> >> +                       detached = (!get_oid_hex(buf.buf, oid));
> >
> > omitting the length check here?
> 
> Good eyes.  It probably should check with the possible oid lengths.

I'll reroll.  This may have been a bad conflict resolution on my part.
-- 
brian m. carlson / brian with sandals: Houston, Texas, US
https://www.crustytoothpaste.net/~bmc | My opinion only
OpenPGP: https://keybase.io/bk2204

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 868 bytes --]

^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2017-07-07 21:22 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-07-03 18:55 [PATCH 00/12] object_id part 9 brian m. carlson
2017-07-03 18:55 ` [PATCH 01/12] builtin/fsck: convert remaining caller of get_sha1 to object_id brian m. carlson
2017-07-03 18:55 ` [PATCH 02/12] builtin/merge-tree: " brian m. carlson
2017-07-03 18:55 ` [PATCH 03/12] submodule: convert submodule config lookup to use object_id brian m. carlson
2017-07-03 18:55 ` [PATCH 04/12] remote: convert struct push_cas to struct object_id brian m. carlson
2017-07-03 18:55 ` [PATCH 05/12] sequencer: convert " brian m. carlson
2017-07-03 18:55 ` [PATCH 06/12] builtin/update_ref: " brian m. carlson
2017-07-03 20:49   ` Ævar Arnfjörð Bjarmason
2017-07-04 14:45     ` brian m. carlson
2017-07-03 18:55 ` [PATCH 07/12] bisect: convert bisect_checkout " brian m. carlson
2017-07-03 18:55 ` [PATCH 08/12] builtin/unpack-file: convert " brian m. carlson
2017-07-03 18:55 ` [PATCH 09/12] builtin/verify-tag: " brian m. carlson
2017-07-03 18:55 ` [PATCH 10/12] Convert remaining callers of get_sha1 to get_oid brian m. carlson
2017-07-03 18:55 ` [PATCH 11/12] sha1_name: convert get_sha1* to get_oid* brian m. carlson
2017-07-05 18:01   ` Stefan Beller
2017-07-05 18:38     ` Junio C Hamano
2017-07-07 21:22       ` brian m. carlson
2017-07-03 18:55 ` [PATCH 12/12] sha1_name: convert GET_SHA1* flags to GET_OID* brian m. carlson
2017-07-05  4:10 ` [PATCH 00/12] object_id part 9 Junio C Hamano
2017-07-05 18:02   ` Stefan Beller

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).