]> git.ipfire.org Git - thirdparty/git.git/blobdiff - builtin/fetch.c
Merge branch 'tf/string-list-init'
[thirdparty/git.git] / builtin / fetch.c
index 1b67f5fda55896635e91852657259b47e722c889..ea14d5dc6b00b475b8817768b7d35d0bb54d5236 100644 (file)
@@ -544,40 +544,14 @@ static int will_fetch(struct ref **head, const unsigned char *sha1)
        return 0;
 }
 
-struct tag_data {
-       struct ref **head;
-       struct ref ***tail;
-};
-
-static int add_to_tail(struct string_list_item *item, void *cb_data)
-{
-       struct tag_data *data = (struct tag_data *)cb_data;
-       struct ref *rm = NULL;
-
-       /* We have already decided to ignore this item */
-       if (!item->util)
-               return 0;
-
-       rm = alloc_ref(item->string);
-       rm->peer_ref = alloc_ref(item->string);
-       hashcpy(rm->old_sha1, item->util);
-
-       **data->tail = rm;
-       *data->tail = &rm->next;
-
-       return 0;
-}
-
 static void find_non_local_tags(struct transport *transport,
                        struct ref **head,
                        struct ref ***tail)
 {
-       struct string_list existing_refs = { NULL, 0, 0, 0 };
-       struct string_list remote_refs = { NULL, 0, 0, 0 };
-       struct tag_data data;
+       struct string_list existing_refs = STRING_LIST_INIT_NODUP;
+       struct string_list remote_refs = STRING_LIST_INIT_NODUP;
        const struct ref *ref;
        struct string_list_item *item = NULL;
-       data.head = head; data.tail = tail;
 
        for_each_ref(add_existing, &existing_refs);
        for (ref = transport_get_remote_refs(transport); ref; ref = ref->next) {
@@ -631,10 +605,20 @@ static void find_non_local_tags(struct transport *transport,
                item->util = NULL;
 
        /*
-        * For all the tags in the remote_refs string list, call
-        * add_to_tail to add them to the list of refs to be fetched
+        * For all the tags in the remote_refs string list,
+        * add them to the list of refs to be fetched
         */
-       for_each_string_list(&remote_refs, add_to_tail, &data);
+       for_each_string_list_item(item, &remote_refs) {
+               /* Unless we have already decided to ignore this item... */
+               if (item->util)
+               {
+                       struct ref *rm = alloc_ref(item->string);
+                       rm->peer_ref = alloc_ref(item->string);
+                       hashcpy(rm->old_sha1, item->util);
+                       **tail = rm;
+                       *tail = &rm->next;
+               }
+       }
 
        string_list_clear(&remote_refs, 0);
 }
@@ -667,7 +651,7 @@ static int truncate_fetch_head(void)
 static int do_fetch(struct transport *transport,
                    struct refspec *refs, int ref_count)
 {
-       struct string_list existing_refs = { NULL, 0, 0, 0 };
+       struct string_list existing_refs = STRING_LIST_INIT_NODUP;
        struct string_list_item *peer_item = NULL;
        struct ref *ref_map;
        struct ref *rm;
@@ -891,7 +875,7 @@ static int fetch_one(struct remote *remote, int argc, const char **argv)
 int cmd_fetch(int argc, const char **argv, const char *prefix)
 {
        int i;
-       struct string_list list = { NULL, 0, 0, 0 };
+       struct string_list list = STRING_LIST_INIT_NODUP;
        struct remote *remote;
        int result = 0;