269
struct ref *ref_map = NULL;
270
struct ref **tail = &ref_map;
271
272
- const struct ref *remote_refs = transport_get_remote_refs(transport);
272
+ /* opportunistically-updated references: */
273
+ struct ref *orefs = NULL, **oref_tail = &orefs;
274
274
- if (refspec_count || tags == TAGS_SET) {
275
- /* opportunistically-updated references: */
276
- struct ref *orefs = NULL, **oref_tail = &orefs;
275
+ const struct ref *remote_refs = transport_get_remote_refs(transport);
276
277
+ if (refspec_count) {
278
for (i = 0; i < refspec_count; i++) {
279
get_fetch_map(remote_refs, &refspecs[i], &tail, 0);
280
if (refspecs[i].dst && refspecs[i].dst[0])
310
311
if (tags == TAGS_SET)
312
get_fetch_map(remote_refs, tag_refspec, &tail, 0);
313
-
314
- *tail = orefs;
315
- for (rm = orefs; rm; rm = rm->next) {
316
- rm->fetch_head_status = FETCH_HEAD_IGNORE;
317
- tail = &rm->next;
318
- }
313
} else {
314
/* Use the defaults */
315
struct remote *remote = transport->remote;
347
}
348
}
349
356
- if (tags == TAGS_DEFAULT && *autotags)
350
+ if (tags == TAGS_SET)
351
+ /* also fetch all tags */
352
+ get_fetch_map(remote_refs, tag_refspec, &tail, 0);
353
+ else if (tags == TAGS_DEFAULT && *autotags)
354
find_non_local_tags(transport, &ref_map, &tail);
355
356
+ /* Now append any refs to be updated opportunistically: */
357
+ *tail = orefs;
358
+ for (rm = orefs; rm; rm = rm->next) {
359
+ rm->fetch_head_status = FETCH_HEAD_IGNORE;
360
+ tail = &rm->next;
361
+ }
362
+
363
ref_remove_duplicates(ref_map);
364
365
return ref_map;
850
goto cleanup;
851
}
852
if (prune) {
849
- /*
850
- * If --tags was specified, pretend that the user gave us
851
- * the canonical tags refspec
852
- */
853
+ struct refspec *prune_refspecs;
854
+ int prune_refspec_count;
855
+
856
+ if (ref_count) {
857
+ prune_refspecs = refs;
858
+ prune_refspec_count = ref_count;
859
+ } else {
860
+ prune_refspecs = transport->remote->fetch;
861
+ prune_refspec_count = transport->remote->fetch_refspec_nr;
862
+ }
863
+
864
if (tags == TAGS_SET) {
865
+ /*
866
+ * --tags was specified. Pretend that the user also
867
+ * gave us the canonical tags refspec
868
+ */
869
const char *tags_str = "refs/tags/*:refs/tags/*";
870
struct refspec *tags_refspec, *refspec;
871
872
/* Copy the refspec and add the tags to it */
858
- refspec = xcalloc(ref_count + 1, sizeof(struct refspec));
873
+ refspec = xcalloc(prune_refspec_count + 1, sizeof(*refspec));
874
tags_refspec = parse_fetch_refspec(1, &tags_str);
860
- memcpy(refspec, refs, ref_count * sizeof(struct refspec));
861
- memcpy(&refspec[ref_count], tags_refspec, sizeof(struct refspec));
862
- ref_count++;
875
+ memcpy(refspec, prune_refspecs, prune_refspec_count * sizeof(*refspec));
876
+ memcpy(&refspec[prune_refspec_count], tags_refspec, sizeof(*refspec));
877
864
- prune_refs(refspec, ref_count, ref_map);
878
+ prune_refs(refspec, prune_refspec_count + 1, ref_map);
879
866
- ref_count--;
880
/* The rest of the strings belong to fetch_one */
881
free_refspec(1, tags_refspec);
882
free(refspec);
870
- } else if (ref_count) {
871
- prune_refs(refs, ref_count, ref_map);
883
} else {
873
- prune_refs(transport->remote->fetch, transport->remote->fetch_refspec_nr, ref_map);
884
+ prune_refs(prune_refspecs, prune_refspec_count, ref_map);
885
}
886
}
887
free_refs(ref_map);