git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 00/13] object_id part 9
@ 2017-07-13 23:49 brian m. carlson
  2017-07-13 23:49 ` [PATCH v2 01/13] builtin/fsck: convert remaining caller of get_sha1 to object_id brian m. carlson
                   ` (13 more replies)
  0 siblings, 14 replies; 15+ messages in thread
From: brian m. carlson @ 2017-07-13 23:49 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.

This patch should probably be based Stefan Beller's series, in which case
patch 9 can be dropped.

Changes from v1:
* Restore the check for length in get_sha1_basic.
* Add a patch converting some uses of 40 to GIT_SHA1_HEXSZ as suggested.  This
  is a separate patch because I wanted to minimize the non-automated portions of
  the patch in question.

brian m. carlson (13):
  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*
  sha1_name: convert uses of 40 to GIT_SHA1_HEXSZ

 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 +-
 repository.c                     |   2 +-
 revision.c                       |  16 +--
 sequencer.c                      |  65 +++++------
 sha1_name.c                      | 240 +++++++++++++++++++--------------------
 submodule-config.c               |  38 +++----
 submodule-config.h               |  12 +-
 submodule.c                      |  32 +++---
 submodule.h                      |   2 +-
 t/helper/test-submodule-config.c |  10 +-
 transport-helper.c               |   2 +-
 39 files changed, 351 insertions(+), 360 deletions(-)


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

* [PATCH v2 01/13] builtin/fsck: convert remaining caller of get_sha1 to object_id
  2017-07-13 23:49 [PATCH v2 00/13] object_id part 9 brian m. carlson
@ 2017-07-13 23:49 ` brian m. carlson
  2017-07-13 23:49 ` [PATCH v2 02/13] builtin/merge-tree: " brian m. carlson
                   ` (12 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: brian m. carlson @ 2017-07-13 23:49 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 99dea7adf6..0e5a18e843 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] 15+ messages in thread

* [PATCH v2 02/13] builtin/merge-tree: convert remaining caller of get_sha1 to object_id
  2017-07-13 23:49 [PATCH v2 00/13] object_id part 9 brian m. carlson
  2017-07-13 23:49 ` [PATCH v2 01/13] builtin/fsck: convert remaining caller of get_sha1 to object_id brian m. carlson
@ 2017-07-13 23:49 ` brian m. carlson
  2017-07-13 23:49 ` [PATCH v2 03/13] submodule: convert submodule config lookup to use object_id brian m. carlson
                   ` (11 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: brian m. carlson @ 2017-07-13 23:49 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 bad6735c76..f12da292cf 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] 15+ messages in thread

* [PATCH v2 03/13] submodule: convert submodule config lookup to use object_id
  2017-07-13 23:49 [PATCH v2 00/13] object_id part 9 brian m. carlson
  2017-07-13 23:49 ` [PATCH v2 01/13] builtin/fsck: convert remaining caller of get_sha1 to object_id brian m. carlson
  2017-07-13 23:49 ` [PATCH v2 02/13] builtin/merge-tree: " brian m. carlson
@ 2017-07-13 23:49 ` brian m. carlson
  2017-07-13 23:49 ` [PATCH v2 04/13] remote: convert struct push_cas to struct object_id brian m. carlson
                   ` (10 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: brian m. carlson @ 2017-07-13 23:49 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 ++--
 repository.c                     |  2 +-
 submodule-config.c               | 38 +++++++++++++++++++-------------------
 submodule-config.h               | 12 ++++++------
 submodule.c                      | 32 ++++++++++++++++----------------
 submodule.h                      |  2 +-
 t/helper/test-submodule-config.c | 10 +++++-----
 10 files changed, 62 insertions(+), 62 deletions(-)

diff --git a/builtin/grep.c b/builtin/grep.c
index fa351c49f4..89fcb5b337 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -653,7 +653,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);
 
@@ -862,7 +862,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 6abdad3294..af871f14e7 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 a9356c1383..014151d032 100644
--- a/config.c
+++ b/config.c
@@ -1460,9 +1460,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;
@@ -1470,7 +1470,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) {
@@ -1488,11 +1488,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 0352da117b..827f2b0e4a 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/repository.c b/repository.c
index edca907404..1617467568 100644
--- a/repository.c
+++ b/repository.c
@@ -158,7 +158,7 @@ int repo_submodule_init(struct repository *submodule,
 	struct strbuf worktree = STRBUF_INIT;
 	int ret = 0;
 
-	sub = submodule_from_cache(superproject, null_sha1, path);
+	sub = submodule_from_cache(superproject, &null_oid, path);
 	if (!sub) {
 		ret = -1;
 		goto out;
diff --git a/submodule-config.c b/submodule-config.c
index 37cfcceb95..89de1d6a53 100644
--- a/submodule-config.c
+++ b/submodule-config.c
@@ -417,19 +417,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;
@@ -440,13 +440,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;
@@ -466,28 +466,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);
@@ -496,9 +496,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;
 	}
@@ -540,14 +540,14 @@ int parse_submodule_config_option(const char *var, const char *value)
 	return submodule_config_option(the_repository, var, value);
 }
 
-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)
 {
 	submodule_cache_check_init(the_repository);
 	return config_from(the_repository->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)
 {
 	submodule_cache_check_init(the_repository);
@@ -555,7 +555,7 @@ const struct submodule *submodule_from_path(const unsigned char *treeish_name,
 }
 
 const struct submodule *submodule_from_cache(struct repository *repo,
-					     const unsigned char *treeish_name,
+					     const struct object_id *treeish_name,
 					     const char *key)
 {
 	submodule_cache_check_init(repo);
diff --git a/submodule-config.h b/submodule-config.h
index bc45a25e85..5f52e6567b 100644
--- a/submodule-config.h
+++ b/submodule-config.h
@@ -34,15 +34,15 @@ extern int parse_submodule_config_option(const char *var, const char *value);
 extern int submodule_config_option(struct repository *repo,
 				   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);
+		const struct object_id *commit_or_tree, const char *path);
 extern const struct submodule *submodule_from_cache(struct repository *repo,
-						    const unsigned char *treeish_name,
+						    const struct object_id *treeish_name,
 						    const char *key);
-extern int gitmodule_sha1_from_commit(const unsigned char *commit_sha1,
-				      unsigned char *gitmodules_sha1,
-				      struct strbuf *rev);
+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 da2b484879..f39cb4f6ea 100644
--- a/submodule.c
+++ b/submodule.c
@@ -69,7 +69,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;
@@ -103,7 +103,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;
@@ -147,7 +147,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);
@@ -270,14 +270,14 @@ void repo_read_gitmodules(struct repository *repo)
 	free(gitmodules_path);
 }
 
-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);
 }
@@ -293,7 +293,7 @@ int is_submodule_active(struct repository *repo, const char *path)
 	const struct string_list *sl;
 	const struct submodule *module;
 
-	module = submodule_from_cache(repo, null_sha1, path);
+	module = submodule_from_cache(repo, &null_oid, path);
 
 	/* early return if there isn't a path->module mapping */
 	if (!module)
@@ -738,7 +738,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,
@@ -1166,9 +1166,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) {
@@ -1544,7 +1544,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);
@@ -1826,7 +1826,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);
 
@@ -1882,7 +1882,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,
@@ -2025,7 +2025,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 623ce6ad77..93411bdffd 100644
--- a/submodule.h
+++ b/submodule.h
@@ -48,7 +48,7 @@ int option_parse_recurse_submodules_worktree_updater(const struct option *opt,
 void load_submodule_cache(void);
 extern void gitmodules_config(void);
 extern void repo_read_gitmodules(struct repository *repo);
-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_active(struct repository *repo, 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 c6c57bba0d..e13fbcc1b5 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] 15+ messages in thread

* [PATCH v2 04/13] remote: convert struct push_cas to struct object_id
  2017-07-13 23:49 [PATCH v2 00/13] object_id part 9 brian m. carlson
                   ` (2 preceding siblings ...)
  2017-07-13 23:49 ` [PATCH v2 03/13] submodule: convert submodule config lookup to use object_id brian m. carlson
@ 2017-07-13 23:49 ` brian m. carlson
  2017-07-13 23:49 ` [PATCH v2 05/13] sequencer: convert " brian m. carlson
                   ` (9 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: brian m. carlson @ 2017-07-13 23:49 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 d87482573d..9da9040bf0 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 6c28cd3e4b..2ecf4c8c74 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] 15+ messages in thread

* [PATCH v2 05/13] sequencer: convert to struct object_id
  2017-07-13 23:49 [PATCH v2 00/13] object_id part 9 brian m. carlson
                   ` (3 preceding siblings ...)
  2017-07-13 23:49 ` [PATCH v2 04/13] remote: convert struct push_cas to struct object_id brian m. carlson
@ 2017-07-13 23:49 ` brian m. carlson
  2017-07-13 23:49 ` [PATCH v2 06/13] builtin/update_ref: " brian m. carlson
                   ` (8 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: brian m. carlson @ 2017-07-13 23:49 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 3010faf863..16d48a4fb3 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] 15+ messages in thread

* [PATCH v2 06/13] builtin/update_ref: convert to struct object_id
  2017-07-13 23:49 [PATCH v2 00/13] object_id part 9 brian m. carlson
                   ` (4 preceding siblings ...)
  2017-07-13 23:49 ` [PATCH v2 05/13] sequencer: convert " brian m. carlson
@ 2017-07-13 23:49 ` brian m. carlson
  2017-07-13 23:49 ` [PATCH v2 07/13] bisect: convert bisect_checkout " brian m. carlson
                   ` (7 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: brian m. carlson @ 2017-07-13 23:49 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 40ccfc193b..6b90c5dead 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] 15+ messages in thread

* [PATCH v2 07/13] bisect: convert bisect_checkout to struct object_id
  2017-07-13 23:49 [PATCH v2 00/13] object_id part 9 brian m. carlson
                   ` (5 preceding siblings ...)
  2017-07-13 23:49 ` [PATCH v2 06/13] builtin/update_ref: " brian m. carlson
@ 2017-07-13 23:49 ` brian m. carlson
  2017-07-13 23:49 ` [PATCH v2 08/13] builtin/unpack-file: convert " brian m. carlson
                   ` (6 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: brian m. carlson @ 2017-07-13 23:49 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 a9fd9fbc61..2549eaf7b1 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] 15+ messages in thread

* [PATCH v2 08/13] builtin/unpack-file: convert to struct object_id
  2017-07-13 23:49 [PATCH v2 00/13] object_id part 9 brian m. carlson
                   ` (6 preceding siblings ...)
  2017-07-13 23:49 ` [PATCH v2 07/13] bisect: convert bisect_checkout " brian m. carlson
@ 2017-07-13 23:49 ` brian m. carlson
  2017-07-13 23:49 ` [PATCH v2 09/13] builtin/verify-tag: " brian m. carlson
                   ` (5 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: brian m. carlson @ 2017-07-13 23:49 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 73f1334191..281ca1db6c 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] 15+ messages in thread

* [PATCH v2 09/13] builtin/verify-tag: convert to struct object_id
  2017-07-13 23:49 [PATCH v2 00/13] object_id part 9 brian m. carlson
                   ` (7 preceding siblings ...)
  2017-07-13 23:49 ` [PATCH v2 08/13] builtin/unpack-file: convert " brian m. carlson
@ 2017-07-13 23:49 ` brian m. carlson
  2017-07-13 23:49 ` [PATCH v2 10/13] Convert remaining callers of get_sha1 to get_oid brian m. carlson
                   ` (4 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: brian m. carlson @ 2017-07-13 23:49 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 f9a5f7535a..30e4c826ed 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] 15+ messages in thread

* [PATCH v2 10/13] Convert remaining callers of get_sha1 to get_oid.
  2017-07-13 23:49 [PATCH v2 00/13] object_id part 9 brian m. carlson
                   ` (8 preceding siblings ...)
  2017-07-13 23:49 ` [PATCH v2 09/13] builtin/verify-tag: " brian m. carlson
@ 2017-07-13 23:49 ` brian m. carlson
  2017-07-13 23:49 ` [PATCH v2 11/13] sha1_name: convert get_sha1* to get_oid* brian m. carlson
                   ` (3 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: brian m. carlson @ 2017-07-13 23:49 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 71c0c768db..1efa48fec4 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 c1a79c100c..cb921b4db6 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] 15+ messages in thread

* [PATCH v2 11/13] sha1_name: convert get_sha1* to get_oid*
  2017-07-13 23:49 [PATCH v2 00/13] object_id part 9 brian m. carlson
                   ` (9 preceding siblings ...)
  2017-07-13 23:49 ` [PATCH v2 10/13] Convert remaining callers of get_sha1 to get_oid brian m. carlson
@ 2017-07-13 23:49 ` brian m. carlson
  2017-07-13 23:49 ` [PATCH v2 12/13] sha1_name: convert GET_SHA1* flags to GET_OID* brian m. carlson
                   ` (2 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: brian m. carlson @ 2017-07-13 23:49 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.  Convert a
use of 40 in get_oid_basic to GIT_SHA1_HEXSZ.

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 4050cebcfa..1743fc4a49 100644
--- a/apply.c
+++ b/apply.c
@@ -3552,7 +3552,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."));
 
@@ -4076,7 +4076,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 60b3035a7a..557dd2db85 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 c973bd96dc..40cc6d6fe8 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 96b786e489..1f035fb550 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 |= OBJECT_INFO_ALLOW_UNKNOWN_TYPE;
 
-	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)
@@ -364,7 +364,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 a4a923d7c0..19e898fa4e 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 8e93802511..4bbac014ab 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -510,7 +510,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;
@@ -891,7 +891,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++)
@@ -1387,7 +1387,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);
 
@@ -1657,7 +1657,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 89fcb5b337..8943626e6c 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -1207,8 +1207,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 8ca1de9894..60fac9d4dc 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 fba336a68a..f4a85a165b 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 7aeaea2737..046403ed68 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 c78b7b33d6..041b7898c4 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 7073a3eb97..6fa1f62a88 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 71fe092644..da7ac495ba 100644
--- a/cache.h
+++ b/cache.h
@@ -1305,16 +1305,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 cbfd689939..d29c997e7c 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 8f47c202c5..503754d79e 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 9da9040bf0..2fb0895e4d 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 9ff120b305..34bc81adf4 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 16d48a4fb3..f5e85a398d 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 e7f7b12ceb..208c9b1bcf 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 *);
 
@@ -200,7 +200,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;
@@ -229,7 +229,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;
 }
 
@@ -385,7 +385,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;
@@ -396,7 +396,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;
@@ -413,7 +413,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);
@@ -505,8 +505,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) {
@@ -579,10 +579,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.";
@@ -596,14 +596,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)
@@ -645,7 +645,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 = (buf.len == GIT_SHA1_HEXSZ && !get_oid_hex(buf.buf, oid));
 			strbuf_release(&buf);
 			if (detached)
 				return 0;
@@ -654,18 +654,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) {
@@ -697,7 +697,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/")) {
@@ -730,10 +730,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;
 
@@ -743,13 +743,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;
@@ -758,13 +758,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);
@@ -776,7 +776,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;
 }
 
@@ -805,7 +805,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;
@@ -856,7 +856,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);
@@ -866,7 +866,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;
 	}
 
@@ -879,7 +879,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;
@@ -895,14 +895,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;
@@ -916,14 +916,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;
@@ -950,25 +950,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);
 }
 
 /*
@@ -1005,7 +1005,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;
@@ -1045,7 +1045,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;
 		}
@@ -1141,7 +1141,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)
@@ -1150,7 +1150,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)
@@ -1339,21 +1339,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);
 }
 
 
@@ -1367,49 +1359,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)
@@ -1421,8 +1413,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,
@@ -1505,11 +1497,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);
@@ -1522,7 +1514,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;
 	/*
@@ -1542,7 +1534,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] != ':' ||
@@ -1574,7 +1566,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;
@@ -1595,14 +1587,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;
 
@@ -1610,20 +1602,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);
 
@@ -1647,13 +1639,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 33cff38cc0..8f68d69a86 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] 15+ messages in thread

* [PATCH v2 12/13] sha1_name: convert GET_SHA1* flags to GET_OID*
  2017-07-13 23:49 [PATCH v2 00/13] object_id part 9 brian m. carlson
                   ` (10 preceding siblings ...)
  2017-07-13 23:49 ` [PATCH v2 11/13] sha1_name: convert get_sha1* to get_oid* brian m. carlson
@ 2017-07-13 23:49 ` brian m. carlson
  2017-07-13 23:49 ` [PATCH v2 13/13] sha1_name: convert uses of 40 to GIT_SHA1_HEXSZ brian m. carlson
  2017-07-14 19:35 ` [PATCH v2 00/13] object_id part 9 Brandon Williams
  13 siblings, 0 replies; 15+ messages in thread
From: brian m. carlson @ 2017-07-13 23:49 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 1f035fb550..62c8cf0ebf 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 |= OBJECT_INFO_ALLOW_UNKNOWN_TYPE;
 
-	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);
 
@@ -361,7 +361,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 8943626e6c..1618087a60 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -1207,7 +1207,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 60fac9d4dc..3dbdf8cadd 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 041b7898c4..2bd28d3c08 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 da7ac495ba..cfc3698eba 100644
--- a/cache.h
+++ b/cache.h
@@ -1283,27 +1283,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 7aae78cb55..e1de925155 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 34bc81adf4..913ef8ce32 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 208c9b1bcf..b49303271e 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -390,23 +390,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;
@@ -506,7 +506,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) {
@@ -663,9 +663,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) {
@@ -710,13 +710,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.",
@@ -733,7 +733,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;
 
@@ -764,7 +764,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);
@@ -850,11 +850,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;
@@ -905,7 +905,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;
@@ -1362,35 +1362,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);
 }
 
@@ -1506,10 +1506,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;
@@ -1552,7 +1552,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)
@@ -1591,8 +1591,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;
@@ -1601,7 +1601,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);
@@ -1616,7 +1616,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);
@@ -1640,12 +1640,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] 15+ messages in thread

* [PATCH v2 13/13] sha1_name: convert uses of 40 to GIT_SHA1_HEXSZ
  2017-07-13 23:49 [PATCH v2 00/13] object_id part 9 brian m. carlson
                   ` (11 preceding siblings ...)
  2017-07-13 23:49 ` [PATCH v2 12/13] sha1_name: convert GET_SHA1* flags to GET_OID* brian m. carlson
@ 2017-07-13 23:49 ` brian m. carlson
  2017-07-14 19:35 ` [PATCH v2 00/13] object_id part 9 Brandon Williams
  13 siblings, 0 replies; 15+ messages in thread
From: brian m. carlson @ 2017-07-13 23:49 UTC (permalink / raw)
  To: git; +Cc: Brandon Williams, Stefan Beller, Jeff King

There are several uses of the constant 40 in find_unique_abbrev_r.
Convert them to GIT_SHA1_HEXSZ.

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

diff --git a/sha1_name.c b/sha1_name.c
index b49303271e..8b7fd7e134 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -501,10 +501,10 @@ int find_unique_abbrev_r(char *hex, const unsigned char *sha1, int len)
 	}
 
 	sha1_to_hex_r(hex, sha1);
-	if (len == 40 || !len)
-		return 40;
+	if (len == GIT_SHA1_HEXSZ || !len)
+		return GIT_SHA1_HEXSZ;
 	exists = has_sha1_file(sha1);
-	while (len < 40) {
+	while (len < GIT_SHA1_HEXSZ) {
 		struct object_id oid_ret;
 		status = get_short_oid(hex, len, &oid_ret, GET_OID_QUIETLY);
 		if (exists

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

* Re: [PATCH v2 00/13] object_id part 9
  2017-07-13 23:49 [PATCH v2 00/13] object_id part 9 brian m. carlson
                   ` (12 preceding siblings ...)
  2017-07-13 23:49 ` [PATCH v2 13/13] sha1_name: convert uses of 40 to GIT_SHA1_HEXSZ brian m. carlson
@ 2017-07-14 19:35 ` Brandon Williams
  13 siblings, 0 replies; 15+ messages in thread
From: Brandon Williams @ 2017-07-14 19:35 UTC (permalink / raw)
  To: brian m. carlson; +Cc: git, Stefan Beller, Jeff King

On 07/13, brian m. carlson wrote:
> 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.
> 
> This patch should probably be based Stefan Beller's series, in which case
> patch 9 can be dropped.
> 
> Changes from v1:
> * Restore the check for length in get_sha1_basic.
> * Add a patch converting some uses of 40 to GIT_SHA1_HEXSZ as suggested.  This
>   is a separate patch because I wanted to minimize the non-automated portions of
>   the patch in question.
> 

I've looked through v2 and it looks good to me as nothing crazy stood
out to me.

Thanks!

> brian m. carlson (13):
>   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*
>   sha1_name: convert uses of 40 to GIT_SHA1_HEXSZ
> 
>  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 +-
>  repository.c                     |   2 +-
>  revision.c                       |  16 +--
>  sequencer.c                      |  65 +++++------
>  sha1_name.c                      | 240 +++++++++++++++++++--------------------
>  submodule-config.c               |  38 +++----
>  submodule-config.h               |  12 +-
>  submodule.c                      |  32 +++---
>  submodule.h                      |   2 +-
>  t/helper/test-submodule-config.c |  10 +-
>  transport-helper.c               |   2 +-
>  39 files changed, 351 insertions(+), 360 deletions(-)
> 

-- 
Brandon Williams

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

end of thread, other threads:[~2017-07-14 19:35 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-07-13 23:49 [PATCH v2 00/13] object_id part 9 brian m. carlson
2017-07-13 23:49 ` [PATCH v2 01/13] builtin/fsck: convert remaining caller of get_sha1 to object_id brian m. carlson
2017-07-13 23:49 ` [PATCH v2 02/13] builtin/merge-tree: " brian m. carlson
2017-07-13 23:49 ` [PATCH v2 03/13] submodule: convert submodule config lookup to use object_id brian m. carlson
2017-07-13 23:49 ` [PATCH v2 04/13] remote: convert struct push_cas to struct object_id brian m. carlson
2017-07-13 23:49 ` [PATCH v2 05/13] sequencer: convert " brian m. carlson
2017-07-13 23:49 ` [PATCH v2 06/13] builtin/update_ref: " brian m. carlson
2017-07-13 23:49 ` [PATCH v2 07/13] bisect: convert bisect_checkout " brian m. carlson
2017-07-13 23:49 ` [PATCH v2 08/13] builtin/unpack-file: convert " brian m. carlson
2017-07-13 23:49 ` [PATCH v2 09/13] builtin/verify-tag: " brian m. carlson
2017-07-13 23:49 ` [PATCH v2 10/13] Convert remaining callers of get_sha1 to get_oid brian m. carlson
2017-07-13 23:49 ` [PATCH v2 11/13] sha1_name: convert get_sha1* to get_oid* brian m. carlson
2017-07-13 23:49 ` [PATCH v2 12/13] sha1_name: convert GET_SHA1* flags to GET_OID* brian m. carlson
2017-07-13 23:49 ` [PATCH v2 13/13] sha1_name: convert uses of 40 to GIT_SHA1_HEXSZ brian m. carlson
2017-07-14 19:35 ` [PATCH v2 00/13] object_id part 9 Brandon Williams

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).