From ec0cb496553ac82f97205a415ca77618406b30e3 Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Wed, 16 May 2018 15:57:48 -0700 Subject: refspec: move refspec parsing logic into its own file In preparation for performing a refactor on refspec related code, move the refspec parsing logic into its own file. Signed-off-by: Brandon Williams Signed-off-by: Junio C Hamano --- builtin/clone.c | 1 + builtin/fast-export.c | 1 + builtin/fetch.c | 1 + builtin/merge.c | 1 + builtin/pull.c | 1 + builtin/push.c | 1 + builtin/remote.c | 1 + builtin/submodule--helper.c | 1 + 8 files changed, 8 insertions(+) (limited to 'builtin') diff --git a/builtin/clone.c b/builtin/clone.c index 84f1473d19..6d1614ed37 100644 --- a/builtin/clone.c +++ b/builtin/clone.c @@ -14,6 +14,7 @@ #include "parse-options.h" #include "fetch-pack.h" #include "refs.h" +#include "refspec.h" #include "tree.h" #include "tree-walk.h" #include "unpack-trees.h" diff --git a/builtin/fast-export.c b/builtin/fast-export.c index 530df12f05..a13b7c8ef3 100644 --- a/builtin/fast-export.c +++ b/builtin/fast-export.c @@ -7,6 +7,7 @@ #include "cache.h" #include "config.h" #include "refs.h" +#include "refspec.h" #include "commit.h" #include "object.h" #include "tag.h" diff --git a/builtin/fetch.c b/builtin/fetch.c index 7ee83ac0f8..1fce68e9ac 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -5,6 +5,7 @@ #include "config.h" #include "repository.h" #include "refs.h" +#include "refspec.h" #include "commit.h" #include "builtin.h" #include "string-list.h" diff --git a/builtin/merge.c b/builtin/merge.c index 9db5a2cf16..c362cfe90d 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -14,6 +14,7 @@ #include "run-command.h" #include "diff.h" #include "refs.h" +#include "refspec.h" #include "commit.h" #include "diffcore.h" #include "revision.h" diff --git a/builtin/pull.c b/builtin/pull.c index 71aac5005e..6247c956d7 100644 --- a/builtin/pull.c +++ b/builtin/pull.c @@ -15,6 +15,7 @@ #include "remote.h" #include "dir.h" #include "refs.h" +#include "refspec.h" #include "revision.h" #include "submodule.h" #include "submodule-config.h" diff --git a/builtin/push.c b/builtin/push.c index ac3705370e..fa65999b27 100644 --- a/builtin/push.c +++ b/builtin/push.c @@ -4,6 +4,7 @@ #include "cache.h" #include "config.h" #include "refs.h" +#include "refspec.h" #include "run-command.h" #include "builtin.h" #include "remote.h" diff --git a/builtin/remote.c b/builtin/remote.c index 8708e584e9..c495139954 100644 --- a/builtin/remote.c +++ b/builtin/remote.c @@ -7,6 +7,7 @@ #include "strbuf.h" #include "run-command.h" #include "refs.h" +#include "refspec.h" #include "argv-array.h" static const char * const builtin_remote_usage[] = { diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index c2403a915f..6ab032acb1 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -12,6 +12,7 @@ #include "run-command.h" #include "remote.h" #include "refs.h" +#include "refspec.h" #include "connect.h" #include "revision.h" #include "diffcore.h" -- cgit v1.2.1 From 0ad4a5ff50dbc839ae26aa60c03b55bf416b6000 Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Wed, 16 May 2018 15:57:49 -0700 Subject: refspec: rename struct refspec to struct refspec_item In preparation for introducing an abstraction around a collection of refspecs (much like how a 'struct pathspec' is a collection of 'struct pathspec_item's) rename the existing 'struct refspec' to 'struct refspec_item'. Signed-off-by: Brandon Williams Signed-off-by: Junio C Hamano --- builtin/clone.c | 4 ++-- builtin/fast-export.c | 4 ++-- builtin/fetch.c | 12 ++++++------ builtin/pull.c | 2 +- builtin/push.c | 4 ++-- builtin/remote.c | 8 ++++---- builtin/submodule--helper.c | 4 ++-- 7 files changed, 19 insertions(+), 19 deletions(-) (limited to 'builtin') diff --git a/builtin/clone.c b/builtin/clone.c index 6d1614ed37..854088a3a2 100644 --- a/builtin/clone.c +++ b/builtin/clone.c @@ -547,7 +547,7 @@ static struct ref *find_remote_branch(const struct ref *refs, const char *branch } static struct ref *wanted_peer_refs(const struct ref *refs, - struct refspec *refspec) + struct refspec_item *refspec) { struct ref *head = copy_ref(find_ref_by_name(refs, "HEAD")); struct ref *local_refs = head; @@ -895,7 +895,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix) int err = 0, complete_refs_before_fetch = 1; int submodule_progress; - struct refspec *refspec; + struct refspec_item *refspec; const char *fetch_pattern; fetch_if_missing = 0; diff --git a/builtin/fast-export.c b/builtin/fast-export.c index a13b7c8ef3..6f105dc798 100644 --- a/builtin/fast-export.c +++ b/builtin/fast-export.c @@ -36,7 +36,7 @@ static int use_done_feature; static int no_data; static int full_tree; static struct string_list extra_refs = STRING_LIST_INIT_NODUP; -static struct refspec *refspecs; +static struct refspec_item *refspecs; static int refspecs_nr; static int anonymize; @@ -979,7 +979,7 @@ static void handle_deletes(void) { int i; for (i = 0; i < refspecs_nr; i++) { - struct refspec *refspec = &refspecs[i]; + struct refspec_item *refspec = &refspecs[i]; if (*refspec->src) continue; diff --git a/builtin/fetch.c b/builtin/fetch.c index 1fce68e9ac..745020a108 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -203,7 +203,7 @@ static void add_merge_config(struct ref **head, for (i = 0; i < branch->merge_nr; i++) { struct ref *rm, **old_tail = *tail; - struct refspec refspec; + struct refspec_item refspec; for (rm = *head; rm; rm = rm->next) { if (branch_merge_matches(branch, i, rm->name)) { @@ -340,7 +340,7 @@ static void find_non_local_tags(struct transport *transport, } static struct ref *get_ref_map(struct transport *transport, - struct refspec *refspecs, int refspec_count, + struct refspec_item *refspecs, int refspec_count, int tags, int *autotags) { int i; @@ -371,7 +371,7 @@ static struct ref *get_ref_map(struct transport *transport, argv_array_clear(&ref_prefixes); if (refspec_count) { - struct refspec *fetch_refspec; + struct refspec_item *fetch_refspec; int fetch_refspec_nr; for (i = 0; i < refspec_count; i++) { @@ -965,7 +965,7 @@ static int fetch_refs(struct transport *transport, struct ref *ref_map) return ret; } -static int prune_refs(struct refspec *refs, int ref_count, struct ref *ref_map, +static int prune_refs(struct refspec_item *refs, int ref_count, struct ref *ref_map, const char *raw_url) { int url_len, i, result = 0; @@ -1115,7 +1115,7 @@ static void backfill_tags(struct transport *transport, struct ref *ref_map) } static int do_fetch(struct transport *transport, - struct refspec *refs, int ref_count) + struct refspec_item *refs, int ref_count) { struct string_list existing_refs = STRING_LIST_INIT_DUP; struct ref *ref_map; @@ -1357,7 +1357,7 @@ 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 const char **refs = NULL; - struct refspec *refspec; + struct refspec_item *refspec; int ref_nr = 0; int j = 0; int exit_code; diff --git a/builtin/pull.c b/builtin/pull.c index 6247c956d7..5a79deae5d 100644 --- a/builtin/pull.c +++ b/builtin/pull.c @@ -676,7 +676,7 @@ static const char *get_upstream_branch(const char *remote) */ static const char *get_tracking_branch(const char *remote, const char *refspec) { - struct refspec *spec; + struct refspec_item *spec; const char *spec_src; const char *merge_branch; diff --git a/builtin/push.c b/builtin/push.c index fa65999b27..00d81fb1dd 100644 --- a/builtin/push.c +++ b/builtin/push.c @@ -80,8 +80,8 @@ static const char *map_refspec(const char *ref, return ref; if (remote->push) { - struct refspec query; - memset(&query, 0, sizeof(struct refspec)); + struct refspec_item query; + memset(&query, 0, sizeof(struct refspec_item)); query.src = matched->name; if (!query_refspecs(remote->push, remote->push_refspec_nr, &query) && query.dst) { diff --git a/builtin/remote.c b/builtin/remote.c index c495139954..d9da82dc81 100644 --- a/builtin/remote.c +++ b/builtin/remote.c @@ -442,7 +442,7 @@ static int get_push_ref_states_noquery(struct ref_states *states) info->dest = xstrdup(item->string); } for (i = 0; i < remote->push_refspec_nr; i++) { - struct refspec *spec = remote->push + i; + struct refspec_item *spec = remote->push + i; if (spec->matching) item = string_list_append(&states->push, _("(matching)")); else if (strlen(spec->src)) @@ -462,7 +462,7 @@ static int get_head_names(const struct ref *remote_refs, struct ref_states *stat { struct ref *ref, *matches; struct ref *fetch_map = NULL, **fetch_map_tail = &fetch_map; - struct refspec refspec; + struct refspec_item refspec; refspec.force = 0; refspec.pattern = 1; @@ -515,7 +515,7 @@ static int add_branch_for_removal(const char *refname, const struct object_id *oid, int flags, void *cb_data) { struct branches_for_remote *branches = cb_data; - struct refspec refspec; + struct refspec_item refspec; struct known_remote *kr; memset(&refspec, 0, sizeof(refspec)); @@ -834,7 +834,7 @@ static int append_ref_to_tracked_list(const char *refname, const struct object_id *oid, int flags, void *cb_data) { struct ref_states *states = cb_data; - struct refspec refspec; + struct refspec_item refspec; if (flags & REF_ISSYMREF) return 0; diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 6ab032acb1..c0c4db0073 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -1746,11 +1746,11 @@ static int push_check(int argc, const char **argv, const char *prefix) if (argc > 2) { int i, refspec_nr = argc - 2; struct ref *local_refs = get_local_heads(); - struct refspec *refspec = parse_push_refspec(refspec_nr, + struct refspec_item *refspec = parse_push_refspec(refspec_nr, argv + 2); for (i = 0; i < refspec_nr; i++) { - struct refspec *rs = refspec + i; + struct refspec_item *rs = refspec + i; if (rs->pattern || rs->matching) continue; -- cgit v1.2.1 From 9c8361b289dea10dcb8d2f0cd7c95840340455dd Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Wed, 16 May 2018 15:57:53 -0700 Subject: submodule--helper: convert push_check to use struct refspec Convert 'push_check()' to use 'struct refspec'. Signed-off-by: Brandon Williams Signed-off-by: Junio C Hamano --- builtin/submodule--helper.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'builtin') diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index c0c4db0073..88a149a2c3 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -1744,13 +1744,14 @@ static int push_check(int argc, const char **argv, const char *prefix) /* Check the refspec */ if (argc > 2) { - int i, refspec_nr = argc - 2; + int i; struct ref *local_refs = get_local_heads(); - struct refspec_item *refspec = parse_push_refspec(refspec_nr, - argv + 2); + struct refspec refspec = REFSPEC_INIT_PUSH; - for (i = 0; i < refspec_nr; i++) { - struct refspec_item *rs = refspec + i; + refspec_appendn(&refspec, argv + 2, argc - 2); + + for (i = 0; i < refspec.nr; i++) { + const struct refspec_item *rs = &refspec.items[i]; if (rs->pattern || rs->matching) continue; @@ -1777,7 +1778,7 @@ static int push_check(int argc, const char **argv, const char *prefix) rs->src); } } - free_refspec(refspec_nr, refspec); + refspec_clear(&refspec); } free(head); -- cgit v1.2.1 From 895d3912582360a9f1ab805c75883f9fcf5f5c3c Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Wed, 16 May 2018 15:57:54 -0700 Subject: pull: convert get_tracking_branch to use refspec_item_init Convert 'get_tracking_branch()' to use 'refspec_item_init()' instead of the old 'parse_fetch_refspec()' function. Signed-off-by: Brandon Williams Signed-off-by: Junio C Hamano --- builtin/pull.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'builtin') diff --git a/builtin/pull.c b/builtin/pull.c index 5a79deae5d..09575fd23c 100644 --- a/builtin/pull.c +++ b/builtin/pull.c @@ -676,12 +676,12 @@ static const char *get_upstream_branch(const char *remote) */ static const char *get_tracking_branch(const char *remote, const char *refspec) { - struct refspec_item *spec; + struct refspec_item spec; const char *spec_src; const char *merge_branch; - spec = parse_fetch_refspec(1, &refspec); - spec_src = spec->src; + refspec_item_init(&spec, refspec, REFSPEC_FETCH); + spec_src = spec.src; if (!*spec_src || !strcmp(spec_src, "HEAD")) spec_src = "HEAD"; else if (skip_prefix(spec_src, "heads/", &spec_src)) @@ -701,7 +701,7 @@ static const char *get_tracking_branch(const char *remote, const char *refspec) } else merge_branch = NULL; - free_refspec(1, spec); + refspec_item_clear(&spec); return merge_branch; } -- cgit v1.2.1 From eace274df8c63ccdbc5329a830ba3a5f04779051 Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Wed, 16 May 2018 15:57:58 -0700 Subject: clone: convert cmd_clone to use refspec_item_init Convert 'cmd_clone()' to use 'refspec_item_init()' instead of relying on the old 'parse_fetch_refspec()' to initialize a single refspec item. Signed-off-by: Brandon Williams Signed-off-by: Junio C Hamano --- builtin/clone.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'builtin') diff --git a/builtin/clone.c b/builtin/clone.c index 854088a3a2..8c5f4d8f07 100644 --- a/builtin/clone.c +++ b/builtin/clone.c @@ -895,8 +895,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix) int err = 0, complete_refs_before_fetch = 1; int submodule_progress; - struct refspec_item *refspec; - const char *fetch_pattern; + struct refspec_item refspec; fetch_if_missing = 0; @@ -1078,8 +1077,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix) if (option_required_reference.nr || option_optional_reference.nr) setup_reference(); - fetch_pattern = value.buf; - refspec = parse_fetch_refspec(1, &fetch_pattern); + refspec_item_init(&refspec, value.buf, REFSPEC_FETCH); strbuf_reset(&value); @@ -1139,7 +1137,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix) refs = transport_get_remote_refs(transport, NULL); if (refs) { - mapped_refs = wanted_peer_refs(refs, refspec); + mapped_refs = wanted_peer_refs(refs, &refspec); /* * transport_get_remote_refs() may return refs with null sha-1 * in mapped_refs (see struct transport->get_refs_list @@ -1233,6 +1231,6 @@ int cmd_clone(int argc, const char **argv, const char *prefix) strbuf_release(&value); junk_mode = JUNK_LEAVE_ALL; - free(refspec); + refspec_item_clear(&refspec); return err; } -- cgit v1.2.1 From 16eefc8eb37dfb26c83bbd0a393b494e3734cb97 Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Wed, 16 May 2018 15:57:59 -0700 Subject: fast-export: convert to use struct refspec Convert fast-export to use 'struct refspec' instead of using a list of refspec_item's. Signed-off-by: Brandon Williams Signed-off-by: Junio C Hamano --- builtin/fast-export.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) (limited to 'builtin') diff --git a/builtin/fast-export.c b/builtin/fast-export.c index 6f105dc798..143999738e 100644 --- a/builtin/fast-export.c +++ b/builtin/fast-export.c @@ -36,8 +36,7 @@ static int use_done_feature; static int no_data; static int full_tree; static struct string_list extra_refs = STRING_LIST_INIT_NODUP; -static struct refspec_item *refspecs; -static int refspecs_nr; +static struct refspec refspecs = REFSPEC_INIT_FETCH; static int anonymize; static int parse_opt_signed_tag_mode(const struct option *opt, @@ -830,9 +829,9 @@ static void get_tags_and_duplicates(struct rev_cmdline_info *info) if (dwim_ref(e->name, strlen(e->name), &oid, &full_name) != 1) continue; - if (refspecs) { + if (refspecs.nr) { char *private; - private = apply_refspecs(refspecs, refspecs_nr, full_name); + private = apply_refspecs(refspecs.items, refspecs.nr, full_name); if (private) { free(full_name); full_name = private; @@ -978,8 +977,8 @@ static void import_marks(char *input_file) static void handle_deletes(void) { int i; - for (i = 0; i < refspecs_nr; i++) { - struct refspec_item *refspec = &refspecs[i]; + for (i = 0; i < refspecs.nr; i++) { + struct refspec_item *refspec = &refspecs.items[i]; if (*refspec->src) continue; @@ -1040,18 +1039,12 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix) usage_with_options (fast_export_usage, options); if (refspecs_list.nr) { - const char **refspecs_str; int i; - ALLOC_ARRAY(refspecs_str, refspecs_list.nr); for (i = 0; i < refspecs_list.nr; i++) - refspecs_str[i] = refspecs_list.items[i].string; - - refspecs_nr = refspecs_list.nr; - refspecs = parse_fetch_refspec(refspecs_nr, refspecs_str); + refspec_append(&refspecs, refspecs_list.items[i].string); string_list_clear(&refspecs_list, 1); - free(refspecs_str); } if (use_done_feature) @@ -1090,7 +1083,7 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix) if (use_done_feature) printf("done\n"); - free_refspec(refspecs_nr, refspecs); + refspec_clear(&refspecs); return 0; } -- cgit v1.2.1 From 6bdb304b106db32b1cff185f2fa1b79e9c2c919c Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Wed, 16 May 2018 15:58:00 -0700 Subject: remote: convert push refspecs to struct refspec Convert the set of push refspecs stored in 'struct remote' to use 'struct refspec'. Signed-off-by: Brandon Williams Signed-off-by: Junio C Hamano --- builtin/push.c | 10 +++++----- builtin/remote.c | 14 +++++++------- 2 files changed, 12 insertions(+), 12 deletions(-) (limited to 'builtin') diff --git a/builtin/push.c b/builtin/push.c index 00d81fb1dd..509dc66772 100644 --- a/builtin/push.c +++ b/builtin/push.c @@ -79,11 +79,11 @@ static const char *map_refspec(const char *ref, if (count_refspec_match(ref, local_refs, &matched) != 1) return ref; - if (remote->push) { + if (remote->push.nr) { struct refspec_item query; memset(&query, 0, sizeof(struct refspec_item)); query.src = matched->name; - if (!query_refspecs(remote->push, remote->push_refspec_nr, &query) && + if (!query_refspecs(remote->push.items, remote->push.nr, &query) && query.dst) { struct strbuf buf = STRBUF_INIT; strbuf_addf(&buf, "%s%s:%s", @@ -436,9 +436,9 @@ static int do_push(const char *repo, int flags, } if (!refspec && !(flags & TRANSPORT_PUSH_ALL)) { - if (remote->push_refspec_nr) { - refspec = remote->push_refspec; - refspec_nr = remote->push_refspec_nr; + if (remote->push.raw_nr) { + refspec = remote->push.raw; + refspec_nr = remote->push.raw_nr; } else if (!(flags & TRANSPORT_PUSH_MIRROR)) setup_default_push_refspecs(remote); } diff --git a/builtin/remote.c b/builtin/remote.c index d9da82dc81..fb84729d6b 100644 --- a/builtin/remote.c +++ b/builtin/remote.c @@ -388,8 +388,8 @@ static int get_push_ref_states(const struct ref *remote_refs, local_refs = get_local_heads(); push_map = copy_ref_list(remote_refs); - match_push_refs(local_refs, &push_map, remote->push_refspec_nr, - remote->push_refspec, MATCH_REFS_NONE); + match_push_refs(local_refs, &push_map, remote->push.raw_nr, + remote->push.raw, MATCH_REFS_NONE); states->push.strdup_strings = 1; for (ref = push_map; ref; ref = ref->next) { @@ -435,14 +435,14 @@ static int get_push_ref_states_noquery(struct ref_states *states) return 0; states->push.strdup_strings = 1; - if (!remote->push_refspec_nr) { + if (!remote->push.nr) { item = string_list_append(&states->push, _("(matching)")); info = item->util = xcalloc(1, sizeof(struct push_info)); info->status = PUSH_STATUS_NOTQUERIED; info->dest = xstrdup(item->string); } - for (i = 0; i < remote->push_refspec_nr; i++) { - struct refspec_item *spec = remote->push + i; + for (i = 0; i < remote->push.nr; i++) { + const struct refspec_item *spec = &remote->push.items[i]; if (spec->matching) item = string_list_append(&states->push, _("(matching)")); else if (strlen(spec->src)) @@ -586,8 +586,8 @@ static int migrate_file(struct remote *remote) git_config_set_multivar(buf.buf, remote->url[i], "^$", 0); strbuf_reset(&buf); strbuf_addf(&buf, "remote.%s.push", remote->name); - for (i = 0; i < remote->push_refspec_nr; i++) - git_config_set_multivar(buf.buf, remote->push_refspec[i], "^$", 0); + for (i = 0; i < remote->push.raw_nr; i++) + git_config_set_multivar(buf.buf, remote->push.raw[i], "^$", 0); strbuf_reset(&buf); strbuf_addf(&buf, "remote.%s.fetch", remote->name); for (i = 0; i < remote->fetch_refspec_nr; i++) -- cgit v1.2.1 From e5349abf93dfde8052bbcabb4be1dba77feb7053 Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Wed, 16 May 2018 15:58:01 -0700 Subject: remote: convert fetch refspecs to struct refspec Convert the set of fetch refspecs stored in 'struct remote' to use 'struct refspec'. Signed-off-by: Brandon Williams Signed-off-by: Junio C Hamano --- builtin/fetch.c | 20 ++++++++++---------- builtin/remote.c | 18 +++++++++--------- 2 files changed, 19 insertions(+), 19 deletions(-) (limited to 'builtin') diff --git a/builtin/fetch.c b/builtin/fetch.c index 745020a108..30083d4bc2 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -407,8 +407,8 @@ static struct ref *get_ref_map(struct transport *transport, fetch_refspec = parse_fetch_refspec(refmap_nr, refmap_array); fetch_refspec_nr = refmap_nr; } else { - fetch_refspec = transport->remote->fetch; - fetch_refspec_nr = transport->remote->fetch_refspec_nr; + fetch_refspec = transport->remote->fetch.items; + fetch_refspec_nr = transport->remote->fetch.nr; } for (i = 0; i < fetch_refspec_nr; i++) @@ -421,16 +421,16 @@ static struct ref *get_ref_map(struct transport *transport, struct branch *branch = branch_get(NULL); int has_merge = branch_has_merge_config(branch); if (remote && - (remote->fetch_refspec_nr || + (remote->fetch.nr || /* Note: has_merge implies non-NULL branch->remote_name */ (has_merge && !strcmp(branch->remote_name, remote->name)))) { - for (i = 0; i < remote->fetch_refspec_nr; i++) { - get_fetch_map(remote_refs, &remote->fetch[i], &tail, 0); - if (remote->fetch[i].dst && - remote->fetch[i].dst[0]) + for (i = 0; i < remote->fetch.nr; i++) { + get_fetch_map(remote_refs, &remote->fetch.items[i], &tail, 0); + if (remote->fetch.items[i].dst && + remote->fetch.items[i].dst[0]) *autotags = 1; if (!i && !has_merge && ref_map && - !remote->fetch[0].pattern) + !remote->fetch.items[0].pattern) ref_map->fetch_head_status = FETCH_HEAD_MERGE; } /* @@ -1166,8 +1166,8 @@ static int do_fetch(struct transport *transport, if (ref_count) { prune_refs(refs, ref_count, ref_map, transport->url); } else { - prune_refs(transport->remote->fetch, - transport->remote->fetch_refspec_nr, + prune_refs(transport->remote->fetch.items, + transport->remote->fetch.nr, ref_map, transport->url); } diff --git a/builtin/remote.c b/builtin/remote.c index fb84729d6b..94dfcb78b2 100644 --- a/builtin/remote.c +++ b/builtin/remote.c @@ -333,10 +333,10 @@ static int get_ref_states(const struct ref *remote_refs, struct ref_states *stat struct ref *ref, *stale_refs; int i; - for (i = 0; i < states->remote->fetch_refspec_nr; i++) - if (get_fetch_map(remote_refs, states->remote->fetch + i, &tail, 1)) + for (i = 0; i < states->remote->fetch.nr; i++) + if (get_fetch_map(remote_refs, &states->remote->fetch.items[i], &tail, 1)) die(_("Could not get fetch map for refspec %s"), - states->remote->fetch_refspec[i]); + states->remote->fetch.raw[i]); states->new_refs.strdup_strings = 1; states->tracked.strdup_strings = 1; @@ -347,8 +347,8 @@ static int get_ref_states(const struct ref *remote_refs, struct ref_states *stat else string_list_append(&states->tracked, abbrev_branch(ref->name)); } - stale_refs = get_stale_heads(states->remote->fetch, - states->remote->fetch_refspec_nr, fetch_map); + stale_refs = get_stale_heads(states->remote->fetch.items, + states->remote->fetch.nr, fetch_map); for (ref = stale_refs; ref; ref = ref->next) { struct string_list_item *item = string_list_append(&states->stale, abbrev_branch(ref->name)); @@ -590,8 +590,8 @@ static int migrate_file(struct remote *remote) git_config_set_multivar(buf.buf, remote->push.raw[i], "^$", 0); strbuf_reset(&buf); strbuf_addf(&buf, "remote.%s.fetch", remote->name); - for (i = 0; i < remote->fetch_refspec_nr; i++) - git_config_set_multivar(buf.buf, remote->fetch_refspec[i], "^$", 0); + for (i = 0; i < remote->fetch.raw_nr; i++) + git_config_set_multivar(buf.buf, remote->fetch.raw[i], "^$", 0); if (remote->origin == REMOTE_REMOTES) unlink_or_warn(git_path("remotes/%s", remote->name)); else if (remote->origin == REMOTE_BRANCHES) @@ -646,11 +646,11 @@ static int mv(int argc, const char **argv) strbuf_addf(&buf, "remote.%s.fetch", rename.new_name); git_config_set_multivar(buf.buf, NULL, NULL, 1); strbuf_addf(&old_remote_context, ":refs/remotes/%s/", rename.old_name); - for (i = 0; i < oldremote->fetch_refspec_nr; i++) { + for (i = 0; i < oldremote->fetch.raw_nr; i++) { char *ptr; strbuf_reset(&buf2); - strbuf_addstr(&buf2, oldremote->fetch_refspec[i]); + strbuf_addstr(&buf2, oldremote->fetch.raw[i]); ptr = strstr(buf2.buf, old_remote_context.buf); if (ptr) { refspec_updated = 1; -- cgit v1.2.1 From 953035009601a971137ecc2c7d5e662189cfda50 Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Wed, 16 May 2018 15:58:02 -0700 Subject: remote: remove add_prune_tags_to_fetch_refspec Remove 'add_prune_tags_to_fetch_refspec()' function and instead have the only caller directly add the tag refspec using 'refspec_append()'. Signed-off-by: Brandon Williams Signed-off-by: Junio C Hamano --- builtin/fetch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'builtin') diff --git a/builtin/fetch.c b/builtin/fetch.c index 30083d4bc2..7a1637d35e 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -1392,7 +1392,7 @@ static int fetch_one(struct remote *remote, int argc, const char **argv, int pru maybe_prune_tags = prune_tags_ok && prune_tags; if (maybe_prune_tags && remote_via_config) - add_prune_tags_to_fetch_refspec(remote); + refspec_append(&remote->fetch, TAG_REFSPEC); if (argc > 0 || (maybe_prune_tags && !remote_via_config)) { size_t nr_alloc = st_add3(argc, maybe_prune_tags, 1); -- cgit v1.2.1 From d7c8e30716ae6226fec5d04cfd7cb45619b6c2fb Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Wed, 16 May 2018 15:58:04 -0700 Subject: fetch: convert fetch_one to use struct refspec Convert 'fetch_one()' to use 'struct refspec'. Signed-off-by: Brandon Williams Signed-off-by: Junio C Hamano --- builtin/fetch.c | 46 +++++++++++++++++++--------------------------- 1 file changed, 19 insertions(+), 27 deletions(-) (limited to 'builtin') diff --git a/builtin/fetch.c b/builtin/fetch.c index 7a1637d35e..18704c6cd6 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -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 const char **refs = NULL; - struct refspec_item *refspec; - int ref_nr = 0; - int j = 0; + struct refspec rs = REFSPEC_INIT_FETCH; + int i; int exit_code; int maybe_prune_tags; 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) refspec_append(&remote->fetch, TAG_REFSPEC); - if (argc > 0 || (maybe_prune_tags && !remote_via_config)) { - size_t nr_alloc = st_add3(argc, maybe_prune_tags, 1); - refs = xcalloc(nr_alloc, sizeof(const char *)); - if (maybe_prune_tags) { - refs[j++] = xstrdup("refs/tags/*:refs/tags/*"); - ref_nr++; - } - } + if (maybe_prune_tags && (argc || !remote_via_config)) + refspec_append(&rs, TAG_REFSPEC); - if (argc > 0) { - int i; - for (i = 0; i < argc; i++) { - if (!strcmp(argv[i], "tag")) { - i++; - if (i >= argc) - die(_("You need to specify a tag name.")); - refs[j++] = xstrfmt("refs/tags/%s:refs/tags/%s", - argv[i], argv[i]); - } else - refs[j++] = argv[i]; - ref_nr++; + for (i = 0; i < argc; i++) { + if (!strcmp(argv[i], "tag")) { + char *tag; + i++; + if (i >= argc) + die(_("You need to specify a tag name.")); + + tag = xstrfmt("refs/tags/%s:refs/tags/%s", + argv[i], argv[i]); + refspec_append(&rs, tag); + free(tag); + } else { + refspec_append(&rs, argv[i]); } } sigchain_push_common(unlock_pack_on_signal); atexit(unlock_pack); - refspec = parse_fetch_refspec(ref_nr, refs); - exit_code = do_fetch(gtransport, refspec, ref_nr); - free_refspec(ref_nr, refspec); + exit_code = do_fetch(gtransport, rs.items, rs.nr); + refspec_clear(&rs); transport_disconnect(gtransport); gtransport = NULL; return exit_code; -- cgit v1.2.1 From e4cffacc8047d675983ecdbc7c7c284276514fe1 Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Wed, 16 May 2018 15:58:05 -0700 Subject: 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 Signed-off-by: Junio C Hamano --- builtin/fetch.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'builtin') diff --git a/builtin/fetch.c b/builtin/fetch.c index 18704c6cd6..6b909cd5bf 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -60,8 +60,7 @@ static const char *submodule_prefix = ""; static int recurse_submodules = RECURSE_SUBMODULES_DEFAULT; static int recurse_submodules_default = RECURSE_SUBMODULES_ON_DEMAND; static int shown_url = 0; -static int refmap_alloc, refmap_nr; -static const char **refmap_array; +static struct refspec refmap = REFSPEC_INIT_FETCH; static struct list_objects_filter_options filter_options; 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) static int parse_refmap_arg(const struct option *opt, const char *arg, int unset) { - ALLOC_GROW(refmap_array, refmap_nr + 1, refmap_alloc); - /* * "git fetch --refmap='' origin foo" * can be used to tell the command not to store anywhere */ - if (*arg) - refmap_array[refmap_nr++] = arg; + refspec_append(&refmap, arg); + return 0; } @@ -403,9 +400,9 @@ static struct ref *get_ref_map(struct transport *transport, * by ref_remove_duplicates() in favor of one of these * opportunistic entries with FETCH_HEAD_IGNORE. */ - if (refmap_array) { - fetch_refspec = parse_fetch_refspec(refmap_nr, refmap_array); - fetch_refspec_nr = refmap_nr; + if (refmap.nr) { + fetch_refspec = refmap.items; + fetch_refspec_nr = refmap.nr; } else { fetch_refspec = transport->remote->fetch.items; fetch_refspec_nr = transport->remote->fetch.nr; @@ -413,7 +410,7 @@ static struct ref *get_ref_map(struct transport *transport, for (i = 0; i < fetch_refspec_nr; i++) get_fetch_map(ref_map, &fetch_refspec[i], &oref_tail, 1); - } else if (refmap_array) { + } else if (refmap.nr) { die("--refmap option is only meaningful with command-line refspec(s)."); } else { /* Use the defaults */ -- cgit v1.2.1 From 65a1301f2e01b454777bb15328f8071282bee702 Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Wed, 16 May 2018 15:58:07 -0700 Subject: fetch: convert do_fetch to take a struct refspec Convert 'do_fetch()' to take a 'struct refspec' as a parameter instead of a list of 'struct refspec_item'. Signed-off-by: Brandon Williams Signed-off-by: Junio C Hamano --- builtin/fetch.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'builtin') diff --git a/builtin/fetch.c b/builtin/fetch.c index 6b909cd5bf..ec54b1dfe1 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -1112,7 +1112,7 @@ static void backfill_tags(struct transport *transport, struct ref *ref_map) } static int do_fetch(struct transport *transport, - struct refspec_item *refs, int ref_count) + struct refspec *rs) { struct string_list existing_refs = STRING_LIST_INIT_DUP; struct ref *ref_map; @@ -1136,7 +1136,7 @@ static int do_fetch(struct transport *transport, goto cleanup; } - ref_map = get_ref_map(transport, refs, ref_count, tags, &autotags); + ref_map = get_ref_map(transport, rs->items, rs->nr, tags, &autotags); if (!update_head_ok) check_not_current_branch(ref_map); @@ -1160,8 +1160,8 @@ static int do_fetch(struct transport *transport, * explicitly (via command line or configuration); we * don't care whether --tags was specified. */ - if (ref_count) { - prune_refs(refs, ref_count, ref_map, transport->url); + if (rs->nr) { + prune_refs(rs->items, rs->nr, ref_map, transport->url); } else { prune_refs(transport->remote->fetch.items, transport->remote->fetch.nr, @@ -1410,7 +1410,7 @@ static int fetch_one(struct remote *remote, int argc, const char **argv, int pru sigchain_push_common(unlock_pack_on_signal); atexit(unlock_pack); - exit_code = do_fetch(gtransport, rs.items, rs.nr); + exit_code = do_fetch(gtransport, &rs); refspec_clear(&rs); transport_disconnect(gtransport); gtransport = NULL; -- cgit v1.2.1 From 65d96c8b7dd78aad623d833c2c8dec625b8e00b6 Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Wed, 16 May 2018 15:58:08 -0700 Subject: fetch: convert get_ref_map to take a struct refspec Convert 'get_ref_map()' to take a 'struct refspec' as a parameter instead of a list of 'struct refspec_item'. Signed-off-by: Brandon Williams Signed-off-by: Junio C Hamano --- builtin/fetch.c | 43 ++++++++++++++++++++----------------------- 1 file changed, 20 insertions(+), 23 deletions(-) (limited to 'builtin') diff --git a/builtin/fetch.c b/builtin/fetch.c index ec54b1dfe1..836eb7545c 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -337,7 +337,7 @@ static void find_non_local_tags(struct transport *transport, } static struct ref *get_ref_map(struct transport *transport, - struct refspec_item *refspecs, int refspec_count, + struct refspec *rs, int tags, int *autotags) { int i; @@ -351,15 +351,16 @@ static struct ref *get_ref_map(struct transport *transport, const struct ref *remote_refs; - for (i = 0; i < refspec_count; i++) { - if (!refspecs[i].exact_sha1) { - const char *glob = strchr(refspecs[i].src, '*'); + for (i = 0; i < rs->nr; i++) { + const struct refspec_item *item = &rs->items[i]; + if (!item->exact_sha1) { + const char *glob = strchr(item->src, '*'); if (glob) argv_array_pushf(&ref_prefixes, "%.*s", - (int)(glob - refspecs[i].src), - refspecs[i].src); + (int)(glob - item->src), + item->src); else - expand_ref_prefix(&ref_prefixes, refspecs[i].src); + expand_ref_prefix(&ref_prefixes, item->src); } } @@ -367,13 +368,12 @@ static struct ref *get_ref_map(struct transport *transport, argv_array_clear(&ref_prefixes); - if (refspec_count) { - struct refspec_item *fetch_refspec; - int fetch_refspec_nr; + if (rs->nr) { + struct refspec *fetch_refspec; - for (i = 0; i < refspec_count; i++) { - get_fetch_map(remote_refs, &refspecs[i], &tail, 0); - if (refspecs[i].dst && refspecs[i].dst[0]) + for (i = 0; i < rs->nr; i++) { + get_fetch_map(remote_refs, &rs->items[i], &tail, 0); + if (rs->items[i].dst && rs->items[i].dst[0]) *autotags = 1; } /* Merge everything on the command line (but not --tags) */ @@ -400,16 +400,13 @@ static struct ref *get_ref_map(struct transport *transport, * by ref_remove_duplicates() in favor of one of these * opportunistic entries with FETCH_HEAD_IGNORE. */ - if (refmap.nr) { - fetch_refspec = refmap.items; - fetch_refspec_nr = refmap.nr; - } else { - fetch_refspec = transport->remote->fetch.items; - fetch_refspec_nr = transport->remote->fetch.nr; - } + if (refmap.nr) + fetch_refspec = &refmap; + else + fetch_refspec = &transport->remote->fetch; - for (i = 0; i < fetch_refspec_nr; i++) - get_fetch_map(ref_map, &fetch_refspec[i], &oref_tail, 1); + for (i = 0; i < fetch_refspec->nr; i++) + get_fetch_map(ref_map, &fetch_refspec->items[i], &oref_tail, 1); } else if (refmap.nr) { die("--refmap option is only meaningful with command-line refspec(s)."); } else { @@ -1136,7 +1133,7 @@ static int do_fetch(struct transport *transport, goto cleanup; } - ref_map = get_ref_map(transport, rs->items, rs->nr, tags, &autotags); + ref_map = get_ref_map(transport, rs, tags, &autotags); if (!update_head_ok) check_not_current_branch(ref_map); -- cgit v1.2.1 From def11e71932a908bf9e1339f05235d9ba39a2774 Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Wed, 16 May 2018 15:58:09 -0700 Subject: fetch: convert prune_refs to take a struct refspec Convert 'prune_refs()' to take a 'struct refspec' as a parameter instead of a list of 'struct refspec_item'. Signed-off-by: Brandon Williams Signed-off-by: Junio C Hamano --- builtin/fetch.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'builtin') diff --git a/builtin/fetch.c b/builtin/fetch.c index 836eb7545c..5e46df70cc 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -959,11 +959,11 @@ static int fetch_refs(struct transport *transport, struct ref *ref_map) return ret; } -static int prune_refs(struct refspec_item *refs, int ref_count, struct ref *ref_map, - const char *raw_url) +static int prune_refs(struct refspec *rs, struct ref *ref_map, + const char *raw_url) { int url_len, i, result = 0; - struct ref *ref, *stale_refs = get_stale_heads(refs, ref_count, ref_map); + struct ref *ref, *stale_refs = get_stale_heads(rs->items, rs->nr, ref_map); char *url; int summary_width = transport_summary_width(stale_refs); const char *dangling_msg = dry_run @@ -1158,10 +1158,9 @@ static int do_fetch(struct transport *transport, * don't care whether --tags was specified. */ if (rs->nr) { - prune_refs(rs->items, rs->nr, ref_map, transport->url); + prune_refs(rs, ref_map, transport->url); } else { - prune_refs(transport->remote->fetch.items, - transport->remote->fetch.nr, + prune_refs(&transport->remote->fetch, ref_map, transport->url); } -- cgit v1.2.1 From a2ac50cbfd232b5739bafaf6bfdb80c13633b732 Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Wed, 16 May 2018 15:58:10 -0700 Subject: remote: convert get_stale_heads to take a struct refspec Convert 'get_stale_heads()' to take a 'struct refspec' as a parameter instead of a list of 'struct refspec_item'. Signed-off-by: Brandon Williams Signed-off-by: Junio C Hamano --- builtin/fetch.c | 2 +- builtin/remote.c | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) (limited to 'builtin') diff --git a/builtin/fetch.c b/builtin/fetch.c index 5e46df70cc..3fad1f0db9 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -963,7 +963,7 @@ static int prune_refs(struct refspec *rs, struct ref *ref_map, const char *raw_url) { int url_len, i, result = 0; - struct ref *ref, *stale_refs = get_stale_heads(rs->items, rs->nr, ref_map); + struct ref *ref, *stale_refs = get_stale_heads(rs, ref_map); char *url; int summary_width = transport_summary_width(stale_refs); const char *dangling_msg = dry_run diff --git a/builtin/remote.c b/builtin/remote.c index 94dfcb78b2..b8e66589f1 100644 --- a/builtin/remote.c +++ b/builtin/remote.c @@ -347,8 +347,7 @@ static int get_ref_states(const struct ref *remote_refs, struct ref_states *stat else string_list_append(&states->tracked, abbrev_branch(ref->name)); } - stale_refs = get_stale_heads(states->remote->fetch.items, - states->remote->fetch.nr, fetch_map); + stale_refs = get_stale_heads(&states->remote->fetch, fetch_map); for (ref = stale_refs; ref; ref = ref->next) { struct string_list_item *item = string_list_append(&states->stale, abbrev_branch(ref->name)); -- cgit v1.2.1 From d000414e26654f6f13526e4b83c648d7119586f0 Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Wed, 16 May 2018 15:58:11 -0700 Subject: remote: convert apply_refspecs to take a struct refspec Convert 'apply_refspecs()' to take a 'struct refspec' as a parameter instead of a list of 'struct refspec_item'. Signed-off-by: Brandon Williams Signed-off-by: Junio C Hamano --- builtin/fast-export.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'builtin') diff --git a/builtin/fast-export.c b/builtin/fast-export.c index 143999738e..41fe49e4d6 100644 --- a/builtin/fast-export.c +++ b/builtin/fast-export.c @@ -831,7 +831,7 @@ static void get_tags_and_duplicates(struct rev_cmdline_info *info) if (refspecs.nr) { char *private; - private = apply_refspecs(refspecs.items, refspecs.nr, full_name); + private = apply_refspecs(&refspecs, full_name); if (private) { free(full_name); full_name = private; -- cgit v1.2.1 From 86baf82521de70184182972b96bbf1859f097366 Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Wed, 16 May 2018 15:58:12 -0700 Subject: remote: convert query_refspecs to take a struct refspec Convert 'query_refspecs()' to take a 'struct refspec' as a parameter instead of a list of 'struct refspec_item'. Signed-off-by: Brandon Williams Signed-off-by: Junio C Hamano --- builtin/push.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'builtin') diff --git a/builtin/push.c b/builtin/push.c index 509dc66772..6b7e458907 100644 --- a/builtin/push.c +++ b/builtin/push.c @@ -83,8 +83,7 @@ static const char *map_refspec(const char *ref, struct refspec_item query; memset(&query, 0, sizeof(struct refspec_item)); query.src = matched->name; - if (!query_refspecs(remote->push.items, remote->push.nr, &query) && - query.dst) { + if (!query_refspecs(&remote->push, &query) && query.dst) { struct strbuf buf = STRBUF_INIT; strbuf_addf(&buf, "%s%s:%s", query.force ? "+" : "", -- cgit v1.2.1 From 800a4ab399e954b8970897076b327bf1cf18c0ac Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Wed, 16 May 2018 15:58:15 -0700 Subject: push: check for errors earlier Move the error checking for using the "--mirror", "--all", and "--tags" options earlier and explicitly check for the presence of the flags instead of checking for a side-effect of the flag. Signed-off-by: Brandon Williams Signed-off-by: Junio C Hamano --- builtin/push.c | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) (limited to 'builtin') diff --git a/builtin/push.c b/builtin/push.c index 6b7e458907..df5df6c0dc 100644 --- a/builtin/push.c +++ b/builtin/push.c @@ -417,23 +417,6 @@ static int do_push(const char *repo, int flags, if (push_options->nr) flags |= TRANSPORT_PUSH_OPTIONS; - if ((flags & TRANSPORT_PUSH_ALL) && refspec) { - if (!strcmp(*refspec, "refs/tags/*")) - return error(_("--all and --tags are incompatible")); - return error(_("--all can't be combined with refspecs")); - } - - if ((flags & TRANSPORT_PUSH_MIRROR) && refspec) { - if (!strcmp(*refspec, "refs/tags/*")) - return error(_("--mirror and --tags are incompatible")); - return error(_("--mirror can't be combined with refspecs")); - } - - if ((flags & (TRANSPORT_PUSH_ALL|TRANSPORT_PUSH_MIRROR)) == - (TRANSPORT_PUSH_ALL|TRANSPORT_PUSH_MIRROR)) { - return error(_("--all and --mirror are incompatible")); - } - if (!refspec && !(flags & TRANSPORT_PUSH_ALL)) { if (remote->push.raw_nr) { refspec = remote->push.raw; @@ -625,6 +608,20 @@ int cmd_push(int argc, const char **argv, const char *prefix) die(_("--delete is incompatible with --all, --mirror and --tags")); if (deleterefs && argc < 2) die(_("--delete doesn't make sense without any refs")); + if (flags & TRANSPORT_PUSH_ALL) { + if (tags) + die(_("--all and --tags are incompatible")); + if (argc >= 2) + die(_("--all can't be combined with refspecs")); + } + if (flags & TRANSPORT_PUSH_MIRROR) { + if (tags) + die(_("--mirror and --tags are incompatible")); + if (argc >= 2) + die(_("--mirror can't be combined with refspecs")); + } + if ((flags & TRANSPORT_PUSH_ALL) && (flags & TRANSPORT_PUSH_MIRROR)) + die(_("--all and --mirror are incompatible")); if (recurse_submodules == RECURSE_SUBMODULES_CHECK) flags |= TRANSPORT_RECURSE_SUBMODULES_CHECK; -- cgit v1.2.1 From aa40289ce9438890368aa1c667d1ed6e3184213c Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Wed, 16 May 2018 15:58:16 -0700 Subject: push: convert to use struct refspec Convert the refspecs in builtin/push.c to be stored in a 'struct refspec' instead of being stored in a list of 'struct refspec_item's. Signed-off-by: Brandon Williams Signed-off-by: Junio C Hamano --- builtin/push.c | 38 +++++++++++++++----------------------- 1 file changed, 15 insertions(+), 23 deletions(-) (limited to 'builtin') diff --git a/builtin/push.c b/builtin/push.c index df5df6c0dc..ef42979d1e 100644 --- a/builtin/push.c +++ b/builtin/push.c @@ -57,19 +57,10 @@ static enum transport_family family; static struct push_cas_option cas; -static const char **refspec; -static int refspec_nr; -static int refspec_alloc; +static struct refspec rs = REFSPEC_INIT_PUSH; static struct string_list push_options_config = STRING_LIST_INIT_DUP; -static void add_refspec(const char *ref) -{ - refspec_nr++; - ALLOC_GROW(refspec, refspec_nr, refspec_alloc); - refspec[refspec_nr-1] = ref; -} - static const char *map_refspec(const char *ref, struct remote *remote, struct ref *local_refs) { @@ -138,7 +129,7 @@ static void set_refspecs(const char **refs, int nr, const char *repo) } ref = map_refspec(ref, remote, local_refs); } - add_refspec(ref); + refspec_append(&rs, ref); } } @@ -226,7 +217,7 @@ static void setup_push_upstream(struct remote *remote, struct branch *branch, } strbuf_addf(&refspec, "%s:%s", branch->refname, branch->merge[0]->src); - add_refspec(refspec.buf); + refspec_append(&rs, refspec.buf); } static void setup_push_current(struct remote *remote, struct branch *branch) @@ -236,7 +227,7 @@ static void setup_push_current(struct remote *remote, struct branch *branch) if (!branch) die(_(message_detached_head_die), remote->name); strbuf_addf(&refspec, "%s:%s", branch->refname, branch->refname); - add_refspec(refspec.buf); + refspec_append(&rs, refspec.buf); } static int is_workflow_triangular(struct remote *remote) @@ -253,7 +244,7 @@ static void setup_default_push_refspecs(struct remote *remote) switch (push_default) { default: case PUSH_DEFAULT_MATCHING: - add_refspec(":"); + refspec_append(&rs, ":"); break; case PUSH_DEFAULT_UNSPECIFIED: @@ -341,7 +332,8 @@ static void advise_ref_needs_force(void) advise(_(message_advice_ref_needs_force)); } -static int push_with_options(struct transport *transport, int flags) +static int push_with_options(struct transport *transport, struct refspec *rs, + int flags) { int err; unsigned int reject_reasons; @@ -363,7 +355,7 @@ static int push_with_options(struct transport *transport, int flags) if (verbosity > 0) fprintf(stderr, _("Pushing to %s\n"), transport->url); - err = transport_push(transport, refspec_nr, refspec, flags, + err = transport_push(transport, rs->raw_nr, rs->raw, flags, &reject_reasons); if (err != 0) { fprintf(stderr, "%s", push_get_color(PUSH_COLOR_ERROR)); @@ -397,6 +389,7 @@ static int do_push(const char *repo, int flags, struct remote *remote = pushremote_get(repo); const char **url; int url_nr; + struct refspec *push_refspec = &rs; if (!remote) { if (repo) @@ -417,10 +410,9 @@ static int do_push(const char *repo, int flags, if (push_options->nr) flags |= TRANSPORT_PUSH_OPTIONS; - if (!refspec && !(flags & TRANSPORT_PUSH_ALL)) { - if (remote->push.raw_nr) { - refspec = remote->push.raw; - refspec_nr = remote->push.raw_nr; + if (!push_refspec->nr && !(flags & TRANSPORT_PUSH_ALL)) { + if (remote->push.nr) { + push_refspec = &remote->push; } else if (!(flags & TRANSPORT_PUSH_MIRROR)) setup_default_push_refspecs(remote); } @@ -432,7 +424,7 @@ static int do_push(const char *repo, int flags, transport_get(remote, url[i]); if (flags & TRANSPORT_PUSH_OPTIONS) transport->push_options = push_options; - if (push_with_options(transport, flags)) + if (push_with_options(transport, push_refspec, flags)) errs++; } } else { @@ -440,7 +432,7 @@ static int do_push(const char *repo, int flags, transport_get(remote, NULL); if (flags & TRANSPORT_PUSH_OPTIONS) transport->push_options = push_options; - if (push_with_options(transport, flags)) + if (push_with_options(transport, push_refspec, flags)) errs++; } return !!errs; @@ -631,7 +623,7 @@ int cmd_push(int argc, const char **argv, const char *prefix) flags |= TRANSPORT_RECURSE_SUBMODULES_ONLY; if (tags) - add_refspec("refs/tags/*"); + refspec_append(&rs, "refs/tags/*"); if (argc > 0) { repo = argv[0]; -- cgit v1.2.1 From 306f22dbc8f43feeed735905276c48a96c63b9e5 Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Wed, 16 May 2018 15:58:17 -0700 Subject: transport: convert transport_push to take a struct refspec Convert 'transport_push()' to take a 'struct refspec' as a parameter instead of an array of strings which represent refspecs. Signed-off-by: Brandon Williams Signed-off-by: Junio C Hamano --- builtin/push.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'builtin') diff --git a/builtin/push.c b/builtin/push.c index ef42979d1e..9cd8e8cd56 100644 --- a/builtin/push.c +++ b/builtin/push.c @@ -355,8 +355,7 @@ static int push_with_options(struct transport *transport, struct refspec *rs, if (verbosity > 0) fprintf(stderr, _("Pushing to %s\n"), transport->url); - err = transport_push(transport, rs->raw_nr, rs->raw, flags, - &reject_reasons); + err = transport_push(transport, rs, flags, &reject_reasons); if (err != 0) { fprintf(stderr, "%s", push_get_color(PUSH_COLOR_ERROR)); error(_("failed to push some refs to '%s'"), transport->url); -- cgit v1.2.1 From 168dba68c9ee2f35b40ec306a7b984e90cce2648 Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Wed, 16 May 2018 15:58:18 -0700 Subject: send-pack: store refspecs in a struct refspec Convert send-pack.c to store refspecs in a 'struct refspec' instead of as an array of 'const char *'. Signed-off-by: Brandon Williams Signed-off-by: Junio C Hamano --- builtin/send-pack.c | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) (limited to 'builtin') diff --git a/builtin/send-pack.c b/builtin/send-pack.c index b5427f75e3..ef512616f3 100644 --- a/builtin/send-pack.c +++ b/builtin/send-pack.c @@ -126,8 +126,7 @@ static int send_pack_config(const char *k, const char *v, void *cb) int cmd_send_pack(int argc, const char **argv, const char *prefix) { - int i, nr_refspecs = 0; - const char **refspecs = NULL; + struct refspec rs = REFSPEC_INIT_PUSH; const char *remote_name = NULL; struct remote *remote = NULL; const char *dest = NULL; @@ -189,8 +188,7 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix) argc = parse_options(argc, argv, prefix, options, send_pack_usage, 0); if (argc > 0) { dest = argv[0]; - refspecs = (const char **)(argv + 1); - nr_refspecs = argc - 1; + refspec_appendn(&rs, argv + 1, argc - 1); } if (!dest) @@ -209,31 +207,23 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix) args.push_options = push_options.nr ? &push_options : NULL; if (from_stdin) { - struct argv_array all_refspecs = ARGV_ARRAY_INIT; - - for (i = 0; i < nr_refspecs; i++) - argv_array_push(&all_refspecs, refspecs[i]); - if (args.stateless_rpc) { const char *buf; while ((buf = packet_read_line(0, NULL))) - argv_array_push(&all_refspecs, buf); + refspec_append(&rs, buf); } else { struct strbuf line = STRBUF_INIT; while (strbuf_getline(&line, stdin) != EOF) - argv_array_push(&all_refspecs, line.buf); + refspec_append(&rs, line.buf); strbuf_release(&line); } - - refspecs = all_refspecs.argv; - nr_refspecs = all_refspecs.argc; } /* * --all and --mirror are incompatible; neither makes sense * with any refspecs. */ - if ((nr_refspecs > 0 && (send_all || args.send_mirror)) || + if ((rs.nr > 0 && (send_all || args.send_mirror)) || (send_all && args.send_mirror)) usage_with_options(send_pack_usage, options); @@ -275,7 +265,7 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix) BUG("unknown protocol version"); } - transport_verify_remote_names(nr_refspecs, refspecs); + transport_verify_remote_names(rs.raw_nr, rs.raw); local_refs = get_local_heads(); @@ -287,7 +277,7 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix) flags |= MATCH_REFS_MIRROR; /* match them up */ - if (match_push_refs(local_refs, &remote_refs, nr_refspecs, refspecs, flags)) + if (match_push_refs(local_refs, &remote_refs, rs.raw_nr, rs.raw, flags)) return -1; if (!is_empty_cas(&cas)) -- cgit v1.2.1 From 7a78a82b6c3bb2a6ebaddf3354b6d97939bdb2ab Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Wed, 16 May 2018 15:58:19 -0700 Subject: transport: remove transport_verify_remote_names Remove 'transprot_verify_remote_names()' because all callers have migrated to using 'struct refspec' which performs the same checks in 'parse_refspec()'. Signed-off-by: Brandon Williams Signed-off-by: Junio C Hamano --- builtin/send-pack.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'builtin') diff --git a/builtin/send-pack.c b/builtin/send-pack.c index ef512616f3..7c34bf467e 100644 --- a/builtin/send-pack.c +++ b/builtin/send-pack.c @@ -265,8 +265,6 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix) BUG("unknown protocol version"); } - transport_verify_remote_names(rs.raw_nr, rs.raw); - local_refs = get_local_heads(); flags = MATCH_REFS_NONE; -- cgit v1.2.1 From 5c7ec8462d8706f9731f0d54ea3fdfe810d60a88 Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Wed, 16 May 2018 15:58:21 -0700 Subject: remote: convert match_push_refs to take a struct refspec Convert 'match_push_refs()' to take a 'struct refspec' as a parameter instead of an array of 'const char *'. Signed-off-by: Brandon Williams Signed-off-by: Junio C Hamano --- builtin/remote.c | 3 +-- builtin/send-pack.c | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) (limited to 'builtin') diff --git a/builtin/remote.c b/builtin/remote.c index b8e66589f1..b84175cc6c 100644 --- a/builtin/remote.c +++ b/builtin/remote.c @@ -387,8 +387,7 @@ static int get_push_ref_states(const struct ref *remote_refs, local_refs = get_local_heads(); push_map = copy_ref_list(remote_refs); - match_push_refs(local_refs, &push_map, remote->push.raw_nr, - remote->push.raw, MATCH_REFS_NONE); + match_push_refs(local_refs, &push_map, &remote->push, MATCH_REFS_NONE); states->push.strdup_strings = 1; for (ref = push_map; ref; ref = ref->next) { diff --git a/builtin/send-pack.c b/builtin/send-pack.c index 7c34bf467e..4923b1058c 100644 --- a/builtin/send-pack.c +++ b/builtin/send-pack.c @@ -275,7 +275,7 @@ int cmd_send_pack(int argc, const char **argv, const char *prefix) flags |= MATCH_REFS_MIRROR; /* match them up */ - if (match_push_refs(local_refs, &remote_refs, rs.raw_nr, rs.raw, flags)) + if (match_push_refs(local_refs, &remote_refs, &rs, flags)) return -1; if (!is_empty_cas(&cas)) -- cgit v1.2.1 From 6373cb598e1a4e0340583ad75d5abba01ff79774 Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Wed, 16 May 2018 16:48:21 -0700 Subject: refspec: consolidate ref-prefix generation logic When using protocol v2 a client constructs a list of ref-prefixes which are sent across the wire so that the server can do server-side filtering of the ref-advertisement. The logic that does this exists for both fetch and push (even though no push support for v2 currently exists yet) and is roughly the same so lets consolidate this logic and make it general enough that it can be used for both the push and fetch cases. Signed-off-by: Brandon Williams Signed-off-by: Junio C Hamano --- builtin/fetch.c | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) (limited to 'builtin') diff --git a/builtin/fetch.c b/builtin/fetch.c index 3fad1f0db9..80bb143707 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -351,18 +351,7 @@ static struct ref *get_ref_map(struct transport *transport, const struct ref *remote_refs; - for (i = 0; i < rs->nr; i++) { - const struct refspec_item *item = &rs->items[i]; - if (!item->exact_sha1) { - const char *glob = strchr(item->src, '*'); - if (glob) - argv_array_pushf(&ref_prefixes, "%.*s", - (int)(glob - item->src), - item->src); - else - expand_ref_prefix(&ref_prefixes, item->src); - } - } + refspec_ref_prefixes(rs, &ref_prefixes); remote_refs = transport_get_remote_refs(transport, &ref_prefixes); -- cgit v1.2.1 From dcc73cf7ffd17e68bda05fff4c139465580aff28 Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Wed, 16 May 2018 16:48:22 -0700 Subject: fetch: generate ref-prefixes when using a configured refspec Teach fetch to generate ref-prefixes, to be used for server-side filtering of the ref-advertisement, based on the configured fetch refspec ('remote..fetch') when no user provided refspec exists. Signed-off-by: Brandon Williams Signed-off-by: Junio C Hamano --- builtin/fetch.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'builtin') diff --git a/builtin/fetch.c b/builtin/fetch.c index 80bb143707..7cc7a52dee 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -351,7 +351,15 @@ static struct ref *get_ref_map(struct transport *transport, const struct ref *remote_refs; - refspec_ref_prefixes(rs, &ref_prefixes); + if (rs->nr) + refspec_ref_prefixes(rs, &ref_prefixes); + else if (transport->remote && transport->remote->fetch.nr) + refspec_ref_prefixes(&transport->remote->fetch, &ref_prefixes); + + if (ref_prefixes.argc && + (tags == TAGS_SET || (tags == TAGS_DEFAULT && !rs->nr))) { + argv_array_push(&ref_prefixes, "refs/tags/"); + } remote_refs = transport_get_remote_refs(transport, &ref_prefixes); -- cgit v1.2.1