builtin/fetch: rewrite to take an object_id argument

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Michael Haggerty committed May 25, 2015 at 18:38 UTC 0e0b7de4c78427deeb58860519e6a93d4b52e3cd
1 file changed +11 -12
builtin/fetch.c
+11 -12
@@ -179,13 +179,15 @@ static void add_merge_config(struct ref **head,
179 }
180 }
181
182 -static int add_existing(const char *refname, const unsigned char *sha1,
182 +static int add_existing(const char *refname, const struct object_id *oid,
183 int flag, void *cbdata)
184 {
185 struct string_list *list = (struct string_list *)cbdata;
186 struct string_list_item *item = string_list_insert(list, refname);
187 - item->util = xmalloc(20);
188 - hashcpy(item->util, sha1);
187 + struct object_id *old_oid = xmalloc(sizeof(*old_oid));
188 +
189 + oidcpy(old_oid, oid);
190 + item->util = old_oid;
191 return 0;
192 }
193
@@ -208,10 +210,8 @@ static void find_non_local_tags(struct transport *transport,
210 struct string_list remote_refs = STRING_LIST_INIT_NODUP;
211 const struct ref *ref;
212 struct string_list_item *item = NULL;
211 - struct each_ref_fn_sha1_adapter wrapped_add_existing =
212 - {add_existing, &existing_refs};
213
214 - for_each_ref(each_ref_fn_adapter, &wrapped_add_existing);
214 + for_each_ref(add_existing, &existing_refs);
215 for (ref = transport_get_remote_refs(transport); ref; ref = ref->next) {
216 if (!starts_with(ref->name, "refs/tags/"))
217 continue;
@@ -886,10 +886,8 @@ static int do_fetch(struct transport *transport,
886 struct ref *rm;
887 int autotags = (transport->remote->fetch_tags == 1);
888 int retcode = 0;
889 - struct each_ref_fn_sha1_adapter wrapped_add_existing =
890 - {add_existing, &existing_refs};
889
892 - for_each_ref(each_ref_fn_adapter, &wrapped_add_existing);
890 + for_each_ref(add_existing, &existing_refs);
891
892 if (tags == TAGS_DEFAULT) {
893 if (transport->remote->fetch_tags == 2)
@@ -917,9 +915,10 @@ static int do_fetch(struct transport *transport,
915 struct string_list_item *peer_item =
916 string_list_lookup(&existing_refs,
917 rm->peer_ref->name);
920 - if (peer_item)
921 - hashcpy(rm->peer_ref->old_sha1,
922 - peer_item->util);
918 + if (peer_item) {
919 + struct object_id *old_oid = peer_item->util;
920 + hashcpy(rm->peer_ref->old_sha1, old_oid->hash);
921 + }
922 }
923 }
924