refs: convert peel_ref to struct object_id

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> Signed-off-by: Junio C Hamano <gitster@pobox.com>

brian m. carlson committed Oct 15, 2017 at 22:07 UTC b420d90980a31246836680b68ca15e0239a8b696
7 files changed +17 -17
builtin/describe.c
+1 -1
@@ -181,7 +181,7 @@ static int get_name(const char *path, const struct object_id *oid, int flag, voi
181 }
182
183 /* Is it annotated? */
184 - if (!peel_ref(path, peeled.hash)) {
184 + if (!peel_ref(path, &peeled)) {
185 is_annotated = !!oidcmp(oid, &peeled);
186 } else {
187 oidcpy(&peeled, oid);
builtin/pack-objects.c
+2 -2
@@ -562,7 +562,7 @@ static int mark_tagged(const char *path, const struct object_id *oid, int flag,
562
563 if (entry)
564 entry->tagged = 1;
565 - if (!peel_ref(path, peeled.hash)) {
565 + if (!peel_ref(path, &peeled)) {
566 entry = packlist_find(&to_pack, peeled.hash, NULL);
567 if (entry)
568 entry->tagged = 1;
@@ -2371,7 +2371,7 @@ static int add_ref_tag(const char *path, const struct object_id *oid, int flag,
2371 struct object_id peeled;
2372
2373 if (starts_with(path, "refs/tags/") && /* is a tag? */
2374 - !peel_ref(path, peeled.hash) && /* peelable? */
2374 + !peel_ref(path, &peeled) && /* peelable? */
2375 packlist_find(&to_pack, peeled.hash, NULL)) /* object packed? */
2376 add_tag_chain(oid);
2377 return 0;
builtin/show-ref.c
+1 -1
@@ -38,7 +38,7 @@ static void show_one(const char *refname, const struct object_id *oid)
38 if (!deref_tags)
39 return;
40
41 - if (!peel_ref(refname, peeled.hash)) {
41 + if (!peel_ref(refname, &peeled)) {
42 hex = find_unique_abbrev(peeled.hash, abbrev);
43 printf("%s %s^{}\n", hex, refname);
44 }
refs.c
+5 -5
@@ -1697,7 +1697,7 @@ int refs_pack_refs(struct ref_store *refs, unsigned int flags)
1697 }
1698
1699 int refs_peel_ref(struct ref_store *refs, const char *refname,
1700 - unsigned char *sha1)
1700 + struct object_id *oid)
1701 {
1702 int flag;
1703 struct object_id base;
@@ -1707,7 +1707,7 @@ int refs_peel_ref(struct ref_store *refs, const char *refname,
1707
1708 if (ref_iterator_peel(current_ref_iter, &peeled))
1709 return -1;
1710 - hashcpy(sha1, peeled.hash);
1710 + oidcpy(oid, &peeled);
1711 return 0;
1712 }
1713
@@ -1715,12 +1715,12 @@ int refs_peel_ref(struct ref_store *refs, const char *refname,
1715 RESOLVE_REF_READING, &base, &flag))
1716 return -1;
1717
1718 - return peel_object(base.hash, sha1);
1718 + return peel_object(base.hash, oid->hash);
1719 }
1720
1721 -int peel_ref(const char *refname, unsigned char *sha1)
1721 +int peel_ref(const char *refname, struct object_id *oid)
1722 {
1723 - return refs_peel_ref(get_main_ref_store(), refname, sha1);
1723 + return refs_peel_ref(get_main_ref_store(), refname, oid);
1724 }
1725
1726 int refs_create_symref(struct ref_store *refs,
refs.h
+4 -4
@@ -114,14 +114,14 @@ extern int refs_init_db(struct strbuf *err);
114 /*
115 * If refname is a non-symbolic reference that refers to a tag object,
116 * and the tag can be (recursively) dereferenced to a non-tag object,
117 - * store the SHA1 of the referred-to object to sha1 and return 0. If
118 - * any of these conditions are not met, return a non-zero value.
117 + * store the object ID of the referred-to object to oid and return 0.
118 + * If any of these conditions are not met, return a non-zero value.
119 * Symbolic references are considered unpeelable, even if they
120 * ultimately resolve to a peelable tag.
121 */
122 int refs_peel_ref(struct ref_store *refs, const char *refname,
123 - unsigned char *sha1);
124 -int peel_ref(const char *refname, unsigned char *sha1);
123 + struct object_id *oid);
124 +int peel_ref(const char *refname, struct object_id *oid);
125
126 /**
127 * Resolve refname in the nested "gitlink" repository in the specified
t/helper/test-ref-store.c
+3 -3
@@ -72,12 +72,12 @@ static int cmd_pack_refs(struct ref_store *refs, const char **argv)
72 static int cmd_peel_ref(struct ref_store *refs, const char **argv)
73 {
74 const char *refname = notnull(*argv++, "refname");
75 - unsigned char sha1[20];
75 + struct object_id oid;
76 int ret;
77
78 - ret = refs_peel_ref(refs, refname, sha1);
78 + ret = refs_peel_ref(refs, refname, &oid);
79 if (!ret)
80 - puts(sha1_to_hex(sha1));
80 + puts(oid_to_hex(&oid));
81 return ret;
82 }
83
upload-pack.c
+1 -1
@@ -955,7 +955,7 @@ static int send_ref(const char *refname, const struct object_id *oid,
955 packet_write_fmt(1, "%s %s\n", oid_to_hex(oid), refname_nons);
956 }
957 capabilities = NULL;
958 - if (!peel_ref(refname, peeled.hash))
958 + if (!peel_ref(refname, &peeled))
959 packet_write_fmt(1, "%s %s^{}\n", oid_to_hex(&peeled), refname_nons);
960 return 0;
961 }