Code

git-pack-objects: Automatically pack annotated tags if object was packed
[git.git] / builtin-fetch.c
index 320e235682340f07cb28b0a4de0c39b6bd9da383..26c3d74b76de701a8e1a5e0c7031751599c1487f 100644 (file)
@@ -101,6 +101,10 @@ static void add_merge_config(struct ref **head,
        }
 }
 
+static void find_non_local_tags(struct transport *transport,
+                       struct ref **head,
+                       struct ref ***tail);
+
 static struct ref *get_ref_map(struct transport *transport,
                               struct refspec *refs, int ref_count, int tags,
                               int *autotags)
@@ -157,8 +161,11 @@ static struct ref *get_ref_map(struct transport *transport,
                        if (!ref_map)
                                die("Couldn't find remote ref HEAD");
                        ref_map->merge = 1;
+                       tail = &ref_map->next;
                }
        }
+       if (tags == TAGS_DEFAULT && *autotags)
+               find_non_local_tags(transport, &ref_map, &tail);
        ref_remove_duplicates(ref_map);
 
        return ref_map;
@@ -452,18 +459,28 @@ static int add_existing(const char *refname, const unsigned char *sha1,
        return 0;
 }
 
-static struct ref *find_non_local_tags(struct transport *transport,
-                                      struct ref *fetch_map)
+static int will_fetch(struct ref **head, const unsigned char *sha1)
+{
+       struct ref *rm = *head;
+       while (rm) {
+               if (!hashcmp(rm->old_sha1, sha1))
+                       return 1;
+               rm = rm->next;
+       }
+       return 0;
+}
+
+static void find_non_local_tags(struct transport *transport,
+                       struct ref **head,
+                       struct ref ***tail)
 {
-       static struct path_list existing_refs = { NULL, 0, 0, 0 };
+       struct path_list existing_refs = { NULL, 0, 0, 0 };
        struct path_list new_refs = { NULL, 0, 0, 1 };
        char *ref_name;
        int ref_name_len;
        const unsigned char *ref_sha1;
        const struct ref *tag_ref;
        struct ref *rm = NULL;
-       struct ref *ref_map = NULL;
-       struct ref **tail = &ref_map;
        const struct ref *ref;
 
        for_each_ref(add_existing, &existing_refs);
@@ -489,7 +506,8 @@ static struct ref *find_non_local_tags(struct transport *transport,
 
                if (!path_list_has_path(&existing_refs, ref_name) &&
                    !path_list_has_path(&new_refs, ref_name) &&
-                   has_sha1_file(ref->old_sha1)) {
+                   (has_sha1_file(ref->old_sha1) ||
+                    will_fetch(head, ref->old_sha1))) {
                        path_list_insert(ref_name, &new_refs);
 
                        rm = alloc_ref(strlen(ref_name) + 1);
@@ -498,19 +516,19 @@ static struct ref *find_non_local_tags(struct transport *transport,
                        strcpy(rm->peer_ref->name, ref_name);
                        hashcpy(rm->old_sha1, ref_sha1);
 
-                       *tail = rm;
-                       tail = &rm->next;
+                       **tail = rm;
+                       *tail = &rm->next;
                }
                free(ref_name);
        }
-
-       return ref_map;
+       path_list_clear(&existing_refs, 0);
+       path_list_clear(&new_refs, 0);
 }
 
 static int do_fetch(struct transport *transport,
                    struct refspec *refs, int ref_count)
 {
-       struct ref *ref_map, *fetch_map;
+       struct ref *ref_map;
        struct ref *rm;
        int autotags = (transport->remote->fetch_tags == 1);
        if (transport->remote->fetch_tags == 2 && tags != TAGS_UNSET)
@@ -541,13 +559,14 @@ static int do_fetch(struct transport *transport,
                free_refs(ref_map);
                return 1;
        }
-
-       fetch_map = ref_map;
+       free_refs(ref_map);
 
        /* if neither --no-tags nor --tags was specified, do automated tag
         * following ... */
        if (tags == TAGS_DEFAULT && autotags) {
-               ref_map = find_non_local_tags(transport, fetch_map);
+               struct ref **tail = &ref_map;
+               ref_map = NULL;
+               find_non_local_tags(transport, &ref_map, &tail);
                if (ref_map) {
                        transport_set_option(transport, TRANS_OPT_DEPTH, "0");
                        fetch_refs(transport, ref_map);
@@ -555,7 +574,7 @@ static int do_fetch(struct transport *transport,
                free_refs(ref_map);
        }
 
-       free_refs(fetch_map);
+       transport_disconnect(transport);
 
        return 0;
 }