Skip to content

Commit d7c8e30

Browse files
bmwillgitster
authored andcommitted
fetch: convert fetch_one to use struct refspec
Convert 'fetch_one()' to use 'struct refspec'. Signed-off-by: Brandon Williams <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 57f32ac commit d7c8e30

File tree

1 file changed

+19
-27
lines changed

1 file changed

+19
-27
lines changed

builtin/fetch.c

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1356,10 +1356,8 @@ static inline void fetch_one_setup_partial(struct remote *remote)
13561356

13571357
static int fetch_one(struct remote *remote, int argc, const char **argv, int prune_tags_ok)
13581358
{
1359-
static const char **refs = NULL;
1360-
struct refspec_item *refspec;
1361-
int ref_nr = 0;
1362-
int j = 0;
1359+
struct refspec rs = REFSPEC_INIT_FETCH;
1360+
int i;
13631361
int exit_code;
13641362
int maybe_prune_tags;
13651363
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
13941392
if (maybe_prune_tags && remote_via_config)
13951393
refspec_append(&remote->fetch, TAG_REFSPEC);
13961394

1397-
if (argc > 0 || (maybe_prune_tags && !remote_via_config)) {
1398-
size_t nr_alloc = st_add3(argc, maybe_prune_tags, 1);
1399-
refs = xcalloc(nr_alloc, sizeof(const char *));
1400-
if (maybe_prune_tags) {
1401-
refs[j++] = xstrdup("refs/tags/*:refs/tags/*");
1402-
ref_nr++;
1403-
}
1404-
}
1395+
if (maybe_prune_tags && (argc || !remote_via_config))
1396+
refspec_append(&rs, TAG_REFSPEC);
14051397

1406-
if (argc > 0) {
1407-
int i;
1408-
for (i = 0; i < argc; i++) {
1409-
if (!strcmp(argv[i], "tag")) {
1410-
i++;
1411-
if (i >= argc)
1412-
die(_("You need to specify a tag name."));
1413-
refs[j++] = xstrfmt("refs/tags/%s:refs/tags/%s",
1414-
argv[i], argv[i]);
1415-
} else
1416-
refs[j++] = argv[i];
1417-
ref_nr++;
1398+
for (i = 0; i < argc; i++) {
1399+
if (!strcmp(argv[i], "tag")) {
1400+
char *tag;
1401+
i++;
1402+
if (i >= argc)
1403+
die(_("You need to specify a tag name."));
1404+
1405+
tag = xstrfmt("refs/tags/%s:refs/tags/%s",
1406+
argv[i], argv[i]);
1407+
refspec_append(&rs, tag);
1408+
free(tag);
1409+
} else {
1410+
refspec_append(&rs, argv[i]);
14181411
}
14191412
}
14201413

14211414
sigchain_push_common(unlock_pack_on_signal);
14221415
atexit(unlock_pack);
1423-
refspec = parse_fetch_refspec(ref_nr, refs);
1424-
exit_code = do_fetch(gtransport, refspec, ref_nr);
1425-
free_refspec(ref_nr, refspec);
1416+
exit_code = do_fetch(gtransport, rs.items, rs.nr);
1417+
refspec_clear(&rs);
14261418
transport_disconnect(gtransport);
14271419
gtransport = NULL;
14281420
return exit_code;

0 commit comments

Comments
 (0)