Merge branch 'cn/fetch-prune'
* cn/fetch-prune: fetch: treat --tags like refs/tags/*:refs/tags/* when pruning fetch: honor the user-provided refspecs when pruning refs remote: separate out the remote_find_tracking logic into query_refspecs t5510: add tests for fetch --prune fetch: free all the additional refspecs Conflicts: remote.c
This commit is contained in:
@ -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;
|
||||
|
Reference in New Issue
Block a user