fetch: convert fetch_one to use struct refspec
Convert 'fetch_one()' to use 'struct refspec'. Signed-off-by: Brandon Williams <bmwill@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
57f32ac2a5
commit
d7c8e30716
@ -1356,10 +1356,8 @@ static inline void fetch_one_setup_partial(struct remote *remote)
|
|||||||
|
|
||||||
static int fetch_one(struct remote *remote, int argc, const char **argv, int prune_tags_ok)
|
static int fetch_one(struct remote *remote, int argc, const char **argv, int prune_tags_ok)
|
||||||
{
|
{
|
||||||
static const char **refs = NULL;
|
struct refspec rs = REFSPEC_INIT_FETCH;
|
||||||
struct refspec_item *refspec;
|
int i;
|
||||||
int ref_nr = 0;
|
|
||||||
int j = 0;
|
|
||||||
int exit_code;
|
int exit_code;
|
||||||
int maybe_prune_tags;
|
int maybe_prune_tags;
|
||||||
int remote_via_config = remote_is_configured(remote, 0);
|
int remote_via_config = remote_is_configured(remote, 0);
|
||||||
@ -1394,35 +1392,29 @@ static int fetch_one(struct remote *remote, int argc, const char **argv, int pru
|
|||||||
if (maybe_prune_tags && remote_via_config)
|
if (maybe_prune_tags && remote_via_config)
|
||||||
refspec_append(&remote->fetch, TAG_REFSPEC);
|
refspec_append(&remote->fetch, TAG_REFSPEC);
|
||||||
|
|
||||||
if (argc > 0 || (maybe_prune_tags && !remote_via_config)) {
|
if (maybe_prune_tags && (argc || !remote_via_config))
|
||||||
size_t nr_alloc = st_add3(argc, maybe_prune_tags, 1);
|
refspec_append(&rs, TAG_REFSPEC);
|
||||||
refs = xcalloc(nr_alloc, sizeof(const char *));
|
|
||||||
if (maybe_prune_tags) {
|
|
||||||
refs[j++] = xstrdup("refs/tags/*:refs/tags/*");
|
|
||||||
ref_nr++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (argc > 0) {
|
|
||||||
int i;
|
|
||||||
for (i = 0; i < argc; i++) {
|
for (i = 0; i < argc; i++) {
|
||||||
if (!strcmp(argv[i], "tag")) {
|
if (!strcmp(argv[i], "tag")) {
|
||||||
|
char *tag;
|
||||||
i++;
|
i++;
|
||||||
if (i >= argc)
|
if (i >= argc)
|
||||||
die(_("You need to specify a tag name."));
|
die(_("You need to specify a tag name."));
|
||||||
refs[j++] = xstrfmt("refs/tags/%s:refs/tags/%s",
|
|
||||||
|
tag = xstrfmt("refs/tags/%s:refs/tags/%s",
|
||||||
argv[i], argv[i]);
|
argv[i], argv[i]);
|
||||||
} else
|
refspec_append(&rs, tag);
|
||||||
refs[j++] = argv[i];
|
free(tag);
|
||||||
ref_nr++;
|
} else {
|
||||||
|
refspec_append(&rs, argv[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sigchain_push_common(unlock_pack_on_signal);
|
sigchain_push_common(unlock_pack_on_signal);
|
||||||
atexit(unlock_pack);
|
atexit(unlock_pack);
|
||||||
refspec = parse_fetch_refspec(ref_nr, refs);
|
exit_code = do_fetch(gtransport, rs.items, rs.nr);
|
||||||
exit_code = do_fetch(gtransport, refspec, ref_nr);
|
refspec_clear(&rs);
|
||||||
free_refspec(ref_nr, refspec);
|
|
||||||
transport_disconnect(gtransport);
|
transport_disconnect(gtransport);
|
||||||
gtransport = NULL;
|
gtransport = NULL;
|
||||||
return exit_code;
|
return exit_code;
|
||||||
|
Loading…
Reference in New Issue
Block a user