git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 03/16] refs: convert remaining users of for_each_ref_in to object_id

From
brian m. carlson <sandals@crustytoothpaste.net>
Date
Apr 22, 2015, 23:24 UTC
Message-ID
<1429745061-295908-4-git-send-email-sandals@crustytoothpaste.net>
In-Reply-To
<1429745061-295908-1-git-send-email-sandals@crustytoothpaste.net>

Remove the temporary for_each_ref_in_oid function and update the users of it. Convert the users of for_each_branch_ref and for_each_remote_ref (which use for_each_ref_in under the hood) as well.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 bisect.c            |  8 ++++----
 builtin/rev-parse.c | 10 +++++-----
 refs.c              | 13 ++++---------
 refs.h              |  6 +++---
 4 files changed, 16 insertions(+), 21 deletions(-)
diff --git a/bisect.c b/bisect.c
index 10f5e57..03d5cd9 100644
--- a/bisect.c
+++ b/bisect.c
@@ -400,16 +400,16 @@ struct commit_list *find_bisection(struct commit_list *list,
 	return best;
 }
 
-static int register_ref(const char *refname, const unsigned char *sha1,
+static int register_ref(const char *refname, const struct object_id *oid,
 			int flags, void *cb_data)
 {
 	if (!strcmp(refname, "bad")) {
 		current_bad_oid = xmalloc(sizeof(*current_bad_oid));
-		hashcpy(current_bad_oid->hash, sha1);
+		oidcpy(current_bad_oid, oid);
 	} else if (starts_with(refname, "good-")) {
-		sha1_array_append(&good_revs, sha1);
+		sha1_array_append(&good_revs, oid->hash);
 	} else if (starts_with(refname, "skip-")) {
-		sha1_array_append(&skipped_revs, sha1);
+		sha1_array_append(&skipped_revs, oid->hash);
 	}
 
 	return 0;
diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c
index 7b70650..c9f2c93 100644
--- a/builtin/rev-parse.c
+++ b/builtin/rev-parse.c
@@ -203,9 +203,9 @@ static int show_reference_oid(const char *refname, const struct object_id *oid,
 	return show_reference(refname, oid->hash, flag, cb_data);
 }
 
-static int anti_reference(const char *refname, const unsigned char *sha1, int flag, void *cb_data)
+static int anti_reference(const char *refname, const struct object_id *oid, int flag, void *cb_data)
 {
-	show_rev(REVERSED, sha1, refname);
+	show_rev(REVERSED, oid->hash, refname);
 	return 0;
 }
 
@@ -665,7 +665,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
 				continue;
 			}
 			if (!strcmp(arg, "--bisect")) {
-				for_each_ref_in("refs/bisect/bad", show_reference, NULL);
+				for_each_ref_in("refs/bisect/bad", show_reference_oid, NULL);
 				for_each_ref_in("refs/bisect/good", anti_reference, NULL);
 				continue;
 			}
@@ -676,7 +676,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
 				continue;
 			}
 			if (!strcmp(arg, "--branches")) {
-				for_each_branch_ref(show_reference, NULL);
+				for_each_branch_ref(show_reference_oid, NULL);
 				clear_ref_exclusion(&ref_excludes);
 				continue;
 			}
@@ -703,7 +703,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
 				continue;
 			}
 			if (!strcmp(arg, "--remotes")) {
-				for_each_remote_ref(show_reference, NULL);
+				for_each_remote_ref(show_reference_oid, NULL);
 				clear_ref_exclusion(&ref_excludes);
 				continue;
 			}
diff --git a/refs.c b/refs.c
index 95863f2..a81c301 100644
--- a/refs.c
+++ b/refs.c
@@ -2019,16 +2019,11 @@ int for_each_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data)
 	return do_for_each_ref(get_ref_cache(submodule), "", fn, 0, 0, cb_data);
 }
 
-static int for_each_ref_in_oid(const char *prefix, each_ref_fn_oid fn, void *cb_data)
+int for_each_ref_in(const char *prefix, each_ref_fn_oid fn, void *cb_data)
 {
 	return do_for_each_ref_oid(&ref_cache, prefix, fn, strlen(prefix), 0, cb_data);
 }
 
-int for_each_ref_in(const char *prefix, each_ref_fn fn, void *cb_data)
-{
-	return do_for_each_ref(&ref_cache, prefix, fn, strlen(prefix), 0, cb_data);
-}
-
 int for_each_ref_in_submodule(const char *submodule, const char *prefix,
 		each_ref_fn fn, void *cb_data)
 {
@@ -2037,7 +2032,7 @@ int for_each_ref_in_submodule(const char *submodule, const char *prefix,
 
 int for_each_tag_ref(each_ref_fn_oid fn, void *cb_data)
 {
-	return for_each_ref_in_oid("refs/tags/", fn, cb_data);
+	return for_each_ref_in("refs/tags/", fn, cb_data);
 }
 
 int for_each_tag_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data)
@@ -2045,7 +2040,7 @@ int for_each_tag_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_d
 	return for_each_ref_in_submodule(submodule, "refs/tags/", fn, cb_data);
 }
 
-int for_each_branch_ref(each_ref_fn fn, void *cb_data)
+int for_each_branch_ref(each_ref_fn_oid fn, void *cb_data)
 {
 	return for_each_ref_in("refs/heads/", fn, cb_data);
 }
@@ -2055,7 +2050,7 @@ int for_each_branch_ref_submodule(const char *submodule, each_ref_fn fn, void *c
 	return for_each_ref_in_submodule(submodule, "refs/heads/", fn, cb_data);
 }
 
-int for_each_remote_ref(each_ref_fn fn, void *cb_data)
+int for_each_remote_ref(each_ref_fn_oid fn, void *cb_data)
 {
 	return for_each_ref_in("refs/remotes/", fn, cb_data);
 }
diff --git a/refs.h b/refs.h
index b83529b..d6ef917 100644
--- a/refs.h
+++ b/refs.h
@@ -88,10 +88,10 @@ typedef int each_ref_fn_oid(const char *refname,
  */
 extern int head_ref(each_ref_fn, void *);
 extern int for_each_ref(each_ref_fn, void *);
-extern int for_each_ref_in(const char *, each_ref_fn, void *);
+extern int for_each_ref_in(const char *, each_ref_fn_oid, void *);
 extern int for_each_tag_ref(each_ref_fn_oid, void *);
-extern int for_each_branch_ref(each_ref_fn, void *);
-extern int for_each_remote_ref(each_ref_fn, void *);
+extern int for_each_branch_ref(each_ref_fn_oid, void *);
+extern int for_each_remote_ref(each_ref_fn_oid, void *);
 extern int for_each_replace_ref(each_ref_fn, void *);
 extern int for_each_glob_ref(each_ref_fn, const char *pattern, void *);
 extern int for_each_glob_ref_in(each_ref_fn, const char *pattern, const char* prefix, void *);
-- 
2.3.5
Previous: brian m. carlsonNext: brian m. carlson
Message 9 of 24 in “Convert parts of refs.c to struct object_id”
  1. 00/16 Convert parts of refs.c to struct object_idbrian m. carlson, Apr 22, 2015
  2. 01/16 refs: convert struct ref_entry to use struct object_idbrian m. carlson, Apr 22, 2015
  3. Stefan BellerApr 23, 2015
  4. brian m. carlsonApr 24, 2015
  5. 02/16 refs: convert for_each_tag_ref to struct object_idbrian m. carlson, Apr 22, 2015
  6. Stefan BellerApr 23, 2015
  7. Jeff KingApr 23, 2015
  8. brian m. carlsonApr 24, 2015
  9. 03/16 refs: convert remaining users of for_each_ref_in to object_idbrian m. carlson, Apr 22, 2015
  10. 04/16 refs: convert for_each_ref_in_submodule to object_idbrian m. carlson, Apr 22, 2015
  11. 05/16 refs: convert head_ref to struct object_idbrian m. carlson, Apr 22, 2015
  12. 06/16 refs: convert for_each_ref_submodule to struct object_idbrian m. carlson, Apr 22, 2015
  13. 07/16 revision: remove unused _oid helper.brian m. carlson, Apr 22, 2015
  14. 08/16 refs: convert for_each_ref to struct object_idbrian m. carlson, Apr 22, 2015
  15. 09/16 refs: convert for_each_replace_ref to struct object_idbrian m. carlson, Apr 22, 2015
  16. 10/16 refs: convert namespaced ref iteration functions to object_idbrian m. carlson, Apr 22, 2015
  17. 11/16 refs: convert for_each_rawref to struct object_id.brian m. carlson, Apr 22, 2015
  18. 12/16 refs: rename do_for_each_ref_oid to do_for_each_refbrian m. carlson, Apr 22, 2015
  19. 13/16 refs: convert for_each_reflog to struct object_idbrian m. carlson, Apr 22, 2015
  20. 14/16 refs: rename each_ref_fn_oid to each_ref_fnbrian m. carlson, Apr 22, 2015
  21. 15/16 Remove unneeded *_oid functions.brian m. carlson, Apr 22, 2015
  22. 16/16 refs: convert struct ref_lock to struct object_idbrian m. carlson, Apr 22, 2015
  23. Michael HaggertyApr 26, 2015
  24. brian m. carlsonMay 3, 2015

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.