Skip to content

Commit e4cffac

Browse files
bmwillgitster
authored andcommitted
fetch: convert refmap to use struct refspec
Convert the refmap in builtin/fetch.c to be stored in a 'struct refspec'. Signed-off-by: Brandon Williams <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d7c8e30 commit e4cffac

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

builtin/fetch.c

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ static const char *submodule_prefix = "";
6060
static int recurse_submodules = RECURSE_SUBMODULES_DEFAULT;
6161
static int recurse_submodules_default = RECURSE_SUBMODULES_ON_DEMAND;
6262
static int shown_url = 0;
63-
static int refmap_alloc, refmap_nr;
64-
static const char **refmap_array;
63+
static struct refspec refmap = REFSPEC_INIT_FETCH;
6564
static struct list_objects_filter_options filter_options;
6665

6766
static int git_fetch_config(const char *k, const char *v, void *cb)
@@ -108,14 +107,12 @@ static int gitmodules_fetch_config(const char *var, const char *value, void *cb)
108107

109108
static int parse_refmap_arg(const struct option *opt, const char *arg, int unset)
110109
{
111-
ALLOC_GROW(refmap_array, refmap_nr + 1, refmap_alloc);
112-
113110
/*
114111
* "git fetch --refmap='' origin foo"
115112
* can be used to tell the command not to store anywhere
116113
*/
117-
if (*arg)
118-
refmap_array[refmap_nr++] = arg;
114+
refspec_append(&refmap, arg);
115+
119116
return 0;
120117
}
121118

@@ -403,17 +400,17 @@ static struct ref *get_ref_map(struct transport *transport,
403400
* by ref_remove_duplicates() in favor of one of these
404401
* opportunistic entries with FETCH_HEAD_IGNORE.
405402
*/
406-
if (refmap_array) {
407-
fetch_refspec = parse_fetch_refspec(refmap_nr, refmap_array);
408-
fetch_refspec_nr = refmap_nr;
403+
if (refmap.nr) {
404+
fetch_refspec = refmap.items;
405+
fetch_refspec_nr = refmap.nr;
409406
} else {
410407
fetch_refspec = transport->remote->fetch.items;
411408
fetch_refspec_nr = transport->remote->fetch.nr;
412409
}
413410

414411
for (i = 0; i < fetch_refspec_nr; i++)
415412
get_fetch_map(ref_map, &fetch_refspec[i], &oref_tail, 1);
416-
} else if (refmap_array) {
413+
} else if (refmap.nr) {
417414
die("--refmap option is only meaningful with command-line refspec(s).");
418415
} else {
419416
/* Use the defaults */

0 commit comments

Comments
 (0)