X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=builtin%2Ffetch.c;h=91731b909aeb22bf8d4e366b8b92281ac0f9ac0c;hb=1e7ba0f9caf1993491aa4c5cbd796cd31cb0f4af;hp=1adf6c176f31b2ece263bc1f07eee8c7e0b40098;hpb=8d3c0cb08dff78dfa36544f6bc720ac46cf743aa;p=git.git diff --git a/builtin/fetch.c b/builtin/fetch.c index 1adf6c176..91731b909 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -510,10 +510,10 @@ static int fetch_refs(struct transport *transport, struct ref *ref_map) return ret; } -static int prune_refs(struct transport *transport, struct ref *ref_map) +static int prune_refs(struct refspec *refs, int ref_count, struct ref *ref_map) { int result = 0; - struct ref *ref, *stale_refs = get_stale_heads(transport->remote, ref_map); + struct ref *ref, *stale_refs = get_stale_heads(refs, ref_count, ref_map); const char *dangling_msg = dry_run ? _(" (%s will become dangling)\n") : _(" (%s has become dangling)\n"); @@ -704,8 +704,31 @@ static int do_fetch(struct transport *transport, free_refs(ref_map); return 1; } - if (prune) - prune_refs(transport, ref_map); + if (prune) { + /* If --tags was specified, pretend the user gave us the canonical tags refspec */ + if (tags == TAGS_SET) { + const char *tags_str = "refs/tags/*:refs/tags/*"; + struct refspec *tags_refspec, *refspec; + + /* Copy the refspec and add the tags to it */ + refspec = xcalloc(ref_count + 1, sizeof(struct refspec)); + tags_refspec = parse_fetch_refspec(1, &tags_str); + memcpy(refspec, refs, ref_count * sizeof(struct refspec)); + memcpy(&refspec[ref_count], tags_refspec, sizeof(struct refspec)); + ref_count++; + + prune_refs(refspec, ref_count, ref_map); + + ref_count--; + /* The rest of the strings belong to fetch_one */ + free_refspec(1, tags_refspec); + free(refspec); + } else if (ref_count) { + prune_refs(refs, ref_count, ref_map); + } else { + prune_refs(transport->remote->fetch, transport->remote->fetch_refspec_nr, ref_map); + } + } free_refs(ref_map); /* if neither --no-tags nor --tags was specified, do automated tag @@ -888,7 +911,7 @@ static int fetch_one(struct remote *remote, int argc, const char **argv) atexit(unlock_pack); refspec = parse_fetch_refspec(ref_nr, refs); exit_code = do_fetch(transport, refspec, ref_nr); - free(refspec); + free_refspec(ref_nr, refspec); transport_disconnect(transport); transport = NULL; return exit_code;