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

[PATCH v3 15/25] refs: convert peel_ref to struct object_id

From
brian m. carlson <sandals@crustytoothpaste.net>
Date
Oct 15, 2017, 22:07 UTC
Message-ID
<20171015220712.97308-16-sandals@crustytoothpaste.net>
In-Reply-To
<20171015220712.97308-1-sandals@crustytoothpaste.net>
Convert peel_ref (and its corresponding backend) to struct object_id.

This transformation was done with an update to the declaration, definition, comments, and test helper and the following semantic patch:

@@
expression E1, E2;
@@
- peel_ref(E1, E2.hash)
+ peel_ref(E1, &E2)
@@
expression E1, E2;
@@
- peel_ref(E1, E2->hash)
+ peel_ref(E1, E2)
Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 builtin/describe.c        |  2 +-
 builtin/pack-objects.c    |  4 ++--
 builtin/show-ref.c        |  2 +-
 refs.c                    | 10 +++++-----
 refs.h                    |  8 ++++----
 t/helper/test-ref-store.c |  6 +++---
 upload-pack.c             |  2 +-
 7 files changed, 17 insertions(+), 17 deletions(-)
diff --git a/builtin/describe.c b/builtin/describe.c
index 29075dbd0f..352f8821fd 100644
--- a/builtin/describe.c
+++ b/builtin/describe.c
@@ -181,7 +181,7 @@ static int get_name(const char *path, const struct object_id *oid, int flag, voi
 	}
 
 	/* Is it annotated? */
-	if (!peel_ref(path, peeled.hash)) {
+	if (!peel_ref(path, &peeled)) {
 		is_annotated = !!oidcmp(oid, &peeled);
 	} else {
 		oidcpy(&peeled, oid);
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index 9c6b224973..631de28761 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -562,7 +562,7 @@ static int mark_tagged(const char *path, const struct object_id *oid, int flag,
 
 	if (entry)
 		entry->tagged = 1;
-	if (!peel_ref(path, peeled.hash)) {
+	if (!peel_ref(path, &peeled)) {
 		entry = packlist_find(&to_pack, peeled.hash, NULL);
 		if (entry)
 			entry->tagged = 1;
@@ -2371,7 +2371,7 @@ static int add_ref_tag(const char *path, const struct object_id *oid, int flag,
 	struct object_id peeled;
 
 	if (starts_with(path, "refs/tags/") && /* is a tag? */
-	    !peel_ref(path, peeled.hash)    && /* peelable? */
+	    !peel_ref(path, &peeled)    && /* peelable? */
 	    packlist_find(&to_pack, peeled.hash, NULL))      /* object packed? */
 		add_tag_chain(oid);
 	return 0;
diff --git a/builtin/show-ref.c b/builtin/show-ref.c
index cbb8cfc7d2..41e5e71cad 100644
--- a/builtin/show-ref.c
+++ b/builtin/show-ref.c
@@ -38,7 +38,7 @@ static void show_one(const char *refname, const struct object_id *oid)
 	if (!deref_tags)
 		return;
 
-	if (!peel_ref(refname, peeled.hash)) {
+	if (!peel_ref(refname, &peeled)) {
 		hex = find_unique_abbrev(peeled.hash, abbrev);
 		printf("%s %s^{}\n", hex, refname);
 	}
diff --git a/refs.c b/refs.c
index ecb43a113e..f8a2d98666 100644
--- a/refs.c
+++ b/refs.c
@@ -1697,7 +1697,7 @@ int refs_pack_refs(struct ref_store *refs, unsigned int flags)
 }
 
 int refs_peel_ref(struct ref_store *refs, const char *refname,
-		  unsigned char *sha1)
+		  struct object_id *oid)
 {
 	int flag;
 	struct object_id base;
@@ -1707,7 +1707,7 @@ int refs_peel_ref(struct ref_store *refs, const char *refname,
 
 		if (ref_iterator_peel(current_ref_iter, &peeled))
 			return -1;
-		hashcpy(sha1, peeled.hash);
+		oidcpy(oid, &peeled);
 		return 0;
 	}
 
@@ -1715,12 +1715,12 @@ int refs_peel_ref(struct ref_store *refs, const char *refname,
 			       RESOLVE_REF_READING, &base, &flag))
 		return -1;
 
-	return peel_object(base.hash, sha1);
+	return peel_object(base.hash, oid->hash);
 }
 
-int peel_ref(const char *refname, unsigned char *sha1)
+int peel_ref(const char *refname, struct object_id *oid)
 {
-	return refs_peel_ref(get_main_ref_store(), refname, sha1);
+	return refs_peel_ref(get_main_ref_store(), refname, oid);
 }
 
 int refs_create_symref(struct ref_store *refs,
diff --git a/refs.h b/refs.h
index 9d59c414aa..89f28d482d 100644
--- a/refs.h
+++ b/refs.h
@@ -114,14 +114,14 @@ extern int refs_init_db(struct strbuf *err);
 /*
  * If refname is a non-symbolic reference that refers to a tag object,
  * and the tag can be (recursively) dereferenced to a non-tag object,
- * store the SHA1 of the referred-to object to sha1 and return 0.  If
- * any of these conditions are not met, return a non-zero value.
+ * store the object ID of the referred-to object to oid and return 0.
+ * If any of these conditions are not met, return a non-zero value.
  * Symbolic references are considered unpeelable, even if they
  * ultimately resolve to a peelable tag.
  */
 int refs_peel_ref(struct ref_store *refs, const char *refname,
-		  unsigned char *sha1);
-int peel_ref(const char *refname, unsigned char *sha1);
+		  struct object_id *oid);
+int peel_ref(const char *refname, struct object_id *oid);
 
 /**
  * Resolve refname in the nested "gitlink" repository in the specified
diff --git a/t/helper/test-ref-store.c b/t/helper/test-ref-store.c
index af8dba9560..cea3285ada 100644
--- a/t/helper/test-ref-store.c
+++ b/t/helper/test-ref-store.c
@@ -72,12 +72,12 @@ static int cmd_pack_refs(struct ref_store *refs, const char **argv)
 static int cmd_peel_ref(struct ref_store *refs, const char **argv)
 {
 	const char *refname = notnull(*argv++, "refname");
-	unsigned char sha1[20];
+	struct object_id oid;
 	int ret;
 
-	ret = refs_peel_ref(refs, refname, sha1);
+	ret = refs_peel_ref(refs, refname, &oid);
 	if (!ret)
-		puts(sha1_to_hex(sha1));
+		puts(oid_to_hex(&oid));
 	return ret;
 }
 
diff --git a/upload-pack.c b/upload-pack.c
index 030eba5a0c..6d5f3c0d39 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -955,7 +955,7 @@ static int send_ref(const char *refname, const struct object_id *oid,
 		packet_write_fmt(1, "%s %s\n", oid_to_hex(oid), refname_nons);
 	}
 	capabilities = NULL;
-	if (!peel_ref(refname, peeled.hash))
+	if (!peel_ref(refname, &peeled))
 		packet_write_fmt(1, "%s %s^{}\n", oid_to_hex(&peeled), refname_nons);
 	return 0;
 }
-- 
2.15.0.rc0.271.g36b669edcc
Previous: brian m. carlsonNext: brian m. carlson
Message 9 of 30 in “object_id part 10”
  1. 00/25 object_id part 10brian m. carlson, Oct 15, 2017
  2. 02/25 refs/files-backend: convert struct ref_to_prune to object_idbrian m. carlson, Oct 15, 2017
  3. 05/25 refs: prevent accidental NULL dereference in write_pseudorefbrian m. carlson, Oct 15, 2017
  4. 06/25 refs: update ref transactions to use struct object_idbrian m. carlson, Oct 15, 2017
  5. 07/25 Convert check_connected to use struct object_idbrian m. carlson, Oct 15, 2017
  6. 08/25 refs: convert resolve_refdup and refs_resolve_refdup to struct object_idbrian m. carlson, Oct 15, 2017
  7. 10/25 refs: convert dwim_ref and expand_ref to struct object_idbrian m. carlson, Oct 15, 2017
  8. 11/25 builtin/reflog: convert remaining unsigned char uses to object_idbrian m. carlson, Oct 15, 2017
  9. 15/25 refs: convert peel_ref to struct object_idbrian m. carlson, Oct 15, 2017
  10. 14/25 builtin/pack-objects: convert to struct object_idbrian m. carlson, Oct 15, 2017
  11. 18/25 sha1_file: convert index_path and index_fd to struct object_idbrian m. carlson, Oct 15, 2017
  12. 23/25 refs: convert peel_object to struct object_idbrian m. carlson, Oct 15, 2017
  13. 24/25 refs: convert read_raw_ref backends to struct object_idbrian m. carlson, Oct 15, 2017
  14. 19/25 Convert remaining callers of resolve_gitlink_ref to object_idbrian m. carlson, Oct 15, 2017
  15. 25/25 refs/files-backend: convert static functions to object_idbrian m. carlson, Oct 15, 2017
  16. 20/25 refs: convert resolve_gitlink_ref to struct object_idbrian m. carlson, Oct 15, 2017
  17. 21/25 worktree: convert struct worktree to object_idbrian m. carlson, Oct 15, 2017
  18. 17/25 refs: convert reflog_expire parameter to struct object_idbrian m. carlson, Oct 15, 2017
  19. 22/25 refs: convert resolve_ref_unsafe to struct object_idbrian m. carlson, Oct 15, 2017
  20. 16/25 refs: convert read_ref_at to struct object_idbrian m. carlson, Oct 15, 2017
  21. 13/25 pack-bitmap: convert traverse_bitmap_commit_list to object_idbrian m. carlson, Oct 15, 2017
  22. 09/25 refs: convert read_ref and read_ref_full to object_idbrian m. carlson, Oct 15, 2017
  23. 12/25 refs: convert dwim_log to struct object_idbrian m. carlson, Oct 15, 2017
  24. 01/25 walker: convert to struct object_idbrian m. carlson, Oct 15, 2017
  25. 03/25 refs: convert delete_ref and refs_delete_ref to struct object_idbrian m. carlson, Oct 15, 2017
  26. 04/25 refs: convert update_ref and refs_update_ref to use struct object_idbrian m. carlson, Oct 15, 2017
  27. Junio C HamanoOct 16, 2017
  28. brian m. carlsonOct 16, 2017
  29. Kevin DaudtOct 16, 2017
  30. Junio C HamanoOct 17, 2017

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.