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 --- remote.c | 165 +-------------------------------------------------------------- 1 file changed, 1 insertion(+), 164 deletions(-) (limited to 'remote.c') diff --git a/remote.c b/remote.c index 91eb010ca9..4d67c061a0 100644 --- a/remote.c +++ b/remote.c @@ -2,6 +2,7 @@ #include "config.h" #include "remote.h" #include "refs.h" +#include "refspec.h" #include "commit.h" #include "diff.h" #include "revision.h" @@ -13,18 +14,6 @@ enum map_direction { FROM_SRC, FROM_DST }; -static struct refspec s_tag_refspec = { - 0, - 1, - 0, - 0, - "refs/tags/*", - "refs/tags/*" -}; - -/* See TAG_REFSPEC for the string version */ -const struct refspec *tag_refspec = &s_tag_refspec; - struct counted_string { size_t len; const char *s; @@ -499,158 +488,6 @@ static void read_config(void) alias_all_urls(); } -static struct refspec *parse_refspec_internal(int nr_refspec, const char **refspec, int fetch, int verify) -{ - int i; - struct refspec *rs = xcalloc(nr_refspec, sizeof(*rs)); - - for (i = 0; i < nr_refspec; i++) { - size_t llen; - int is_glob; - const char *lhs, *rhs; - int flags; - - is_glob = 0; - - lhs = refspec[i]; - if (*lhs == '+') { - rs[i].force = 1; - lhs++; - } - - rhs = strrchr(lhs, ':'); - - /* - * Before going on, special case ":" (or "+:") as a refspec - * for pushing matching refs. - */ - if (!fetch && rhs == lhs && rhs[1] == '\0') { - rs[i].matching = 1; - continue; - } - - if (rhs) { - size_t rlen = strlen(++rhs); - is_glob = (1 <= rlen && strchr(rhs, '*')); - rs[i].dst = xstrndup(rhs, rlen); - } - - llen = (rhs ? (rhs - lhs - 1) : strlen(lhs)); - if (1 <= llen && memchr(lhs, '*', llen)) { - if ((rhs && !is_glob) || (!rhs && fetch)) - goto invalid; - is_glob = 1; - } else if (rhs && is_glob) { - goto invalid; - } - - rs[i].pattern = is_glob; - rs[i].src = xstrndup(lhs, llen); - flags = REFNAME_ALLOW_ONELEVEL | (is_glob ? REFNAME_REFSPEC_PATTERN : 0); - - if (fetch) { - struct object_id unused; - - /* LHS */ - if (!*rs[i].src) - ; /* empty is ok; it means "HEAD" */ - else if (llen == GIT_SHA1_HEXSZ && !get_oid_hex(rs[i].src, &unused)) - rs[i].exact_sha1 = 1; /* ok */ - else if (!check_refname_format(rs[i].src, flags)) - ; /* valid looking ref is ok */ - else - goto invalid; - /* RHS */ - if (!rs[i].dst) - ; /* missing is ok; it is the same as empty */ - else if (!*rs[i].dst) - ; /* empty is ok; it means "do not store" */ - else if (!check_refname_format(rs[i].dst, flags)) - ; /* valid looking ref is ok */ - else - goto invalid; - } else { - /* - * LHS - * - empty is allowed; it means delete. - * - when wildcarded, it must be a valid looking ref. - * - otherwise, it must be an extended SHA-1, but - * there is no existing way to validate this. - */ - if (!*rs[i].src) - ; /* empty is ok */ - else if (is_glob) { - if (check_refname_format(rs[i].src, flags)) - goto invalid; - } - else - ; /* anything goes, for now */ - /* - * RHS - * - missing is allowed, but LHS then must be a - * valid looking ref. - * - empty is not allowed. - * - otherwise it must be a valid looking ref. - */ - if (!rs[i].dst) { - if (check_refname_format(rs[i].src, flags)) - goto invalid; - } else if (!*rs[i].dst) { - goto invalid; - } else { - if (check_refname_format(rs[i].dst, flags)) - goto invalid; - } - } - } - return rs; - - invalid: - if (verify) { - /* - * nr_refspec must be greater than zero and i must be valid - * since it is only possible to reach this point from within - * the for loop above. - */ - free_refspec(i+1, rs); - return NULL; - } - die("Invalid refspec '%s'", refspec[i]); -} - -int valid_fetch_refspec(const char *fetch_refspec_str) -{ - struct refspec *refspec; - - refspec = parse_refspec_internal(1, &fetch_refspec_str, 1, 1); - free_refspec(1, refspec); - return !!refspec; -} - -struct refspec *parse_fetch_refspec(int nr_refspec, const char **refspec) -{ - return parse_refspec_internal(nr_refspec, refspec, 1, 0); -} - -struct refspec *parse_push_refspec(int nr_refspec, const char **refspec) -{ - return parse_refspec_internal(nr_refspec, refspec, 0, 0); -} - -void free_refspec(int nr_refspec, struct refspec *refspec) -{ - int i; - - if (!refspec) - return; - - for (i = 0; i < nr_refspec; i++) { - free(refspec[i].src); - free(refspec[i].dst); - } - free(refspec); -} - static int valid_remote_nick(const char *name) { if (!name[0] || is_dot_or_dotdot(name)) -- cgit v1.2.3 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 --- branch.c | 6 +++--- 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 ++-- checkout.c | 4 ++-- refspec.c | 16 +++++++-------- refspec.h | 10 ++++----- remote.c | 50 ++++++++++++++++++++++----------------------- remote.h | 16 +++++++-------- transport-helper.c | 2 +- transport.c | 4 ++-- 15 files changed, 73 insertions(+), 73 deletions(-) (limited to 'remote.c') diff --git a/branch.c b/branch.c index 32ccefc6b5..f967c98f63 100644 --- a/branch.c +++ b/branch.c @@ -9,7 +9,7 @@ #include "worktree.h" struct tracking { - struct refspec spec; + struct refspec_item spec; char *src; const char *remote; int matches; @@ -219,8 +219,8 @@ int validate_new_branchname(const char *name, struct strbuf *ref, int force) static int check_tracking_branch(struct remote *remote, void *cb_data) { char *tracking_branch = cb_data; - struct refspec query; - memset(&query, 0, sizeof(struct refspec)); + struct refspec_item query; + memset(&query, 0, sizeof(struct refspec_item)); query.dst = tracking_branch; return !remote_find_tracking(remote, &query); } 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; diff --git a/checkout.c b/checkout.c index 193ba85675..bdefc888ba 100644 --- a/checkout.c +++ b/checkout.c @@ -13,8 +13,8 @@ struct tracking_name_data { static int check_tracking_name(struct remote *remote, void *cb_data) { struct tracking_name_data *cb = cb_data; - struct refspec query; - memset(&query, 0, sizeof(struct refspec)); + struct refspec_item query; + memset(&query, 0, sizeof(struct refspec_item)); query.src = cb->src_ref; if (remote_find_tracking(remote, &query) || get_oid(query.dst, cb->dst_oid)) { diff --git a/refspec.c b/refspec.c index 50892f864c..22188f0106 100644 --- a/refspec.c +++ b/refspec.c @@ -2,7 +2,7 @@ #include "refs.h" #include "refspec.h" -static struct refspec s_tag_refspec = { +static struct refspec_item s_tag_refspec = { 0, 1, 0, @@ -12,12 +12,12 @@ static struct refspec s_tag_refspec = { }; /* See TAG_REFSPEC for the string version */ -const struct refspec *tag_refspec = &s_tag_refspec; +const struct refspec_item *tag_refspec = &s_tag_refspec; -static struct refspec *parse_refspec_internal(int nr_refspec, const char **refspec, int fetch, int verify) +static struct refspec_item *parse_refspec_internal(int nr_refspec, const char **refspec, int fetch, int verify) { int i; - struct refspec *rs = xcalloc(nr_refspec, sizeof(*rs)); + struct refspec_item *rs = xcalloc(nr_refspec, sizeof(*rs)); for (i = 0; i < nr_refspec; i++) { size_t llen; @@ -135,24 +135,24 @@ static struct refspec *parse_refspec_internal(int nr_refspec, const char **refsp int valid_fetch_refspec(const char *fetch_refspec_str) { - struct refspec *refspec; + struct refspec_item *refspec; refspec = parse_refspec_internal(1, &fetch_refspec_str, 1, 1); free_refspec(1, refspec); return !!refspec; } -struct refspec *parse_fetch_refspec(int nr_refspec, const char **refspec) +struct refspec_item *parse_fetch_refspec(int nr_refspec, const char **refspec) { return parse_refspec_internal(nr_refspec, refspec, 1, 0); } -struct refspec *parse_push_refspec(int nr_refspec, const char **refspec) +struct refspec_item *parse_push_refspec(int nr_refspec, const char **refspec) { return parse_refspec_internal(nr_refspec, refspec, 0, 0); } -void free_refspec(int nr_refspec, struct refspec *refspec) +void free_refspec(int nr_refspec, struct refspec_item *refspec) { int i; diff --git a/refspec.h b/refspec.h index 62625c23a3..fc9c1af775 100644 --- a/refspec.h +++ b/refspec.h @@ -2,9 +2,9 @@ #define REFSPEC_H #define TAG_REFSPEC "refs/tags/*:refs/tags/*" -extern const struct refspec *tag_refspec; +extern const struct refspec_item *tag_refspec; -struct refspec { +struct refspec_item { unsigned force : 1; unsigned pattern : 1; unsigned matching : 1; @@ -15,9 +15,9 @@ struct refspec { }; int valid_fetch_refspec(const char *refspec); -struct refspec *parse_fetch_refspec(int nr_refspec, const char **refspec); -struct refspec *parse_push_refspec(int nr_refspec, const char **refspec); +struct refspec_item *parse_fetch_refspec(int nr_refspec, const char **refspec); +struct refspec_item *parse_push_refspec(int nr_refspec, const char **refspec); -void free_refspec(int nr_refspec, struct refspec *refspec); +void free_refspec(int nr_refspec, struct refspec_item *refspec); #endif /* REFSPEC_H */ diff --git a/remote.c b/remote.c index 4d67c061a0..89820c4769 100644 --- a/remote.c +++ b/remote.c @@ -97,7 +97,7 @@ void add_prune_tags_to_fetch_refspec(struct remote *remote) { int nr = remote->fetch_refspec_nr; int bufsize = nr + 1; - int size = sizeof(struct refspec); + int size = sizeof(struct refspec_item); remote->fetch = xrealloc(remote->fetch, size * bufsize); memcpy(&remote->fetch[nr], tag_refspec, size); @@ -724,7 +724,7 @@ static int match_name_with_pattern(const char *key, const char *name, return ret; } -static void query_refspecs_multiple(struct refspec *refs, int ref_count, struct refspec *query, struct string_list *results) +static void query_refspecs_multiple(struct refspec_item *refs, int ref_count, struct refspec_item *query, struct string_list *results) { int i; int find_src = !query->src; @@ -733,7 +733,7 @@ static void query_refspecs_multiple(struct refspec *refs, int ref_count, struct error("query_refspecs_multiple: need either src or dst"); for (i = 0; i < ref_count; i++) { - struct refspec *refspec = &refs[i]; + struct refspec_item *refspec = &refs[i]; const char *key = find_src ? refspec->dst : refspec->src; const char *value = find_src ? refspec->src : refspec->dst; const char *needle = find_src ? query->dst : query->src; @@ -750,7 +750,7 @@ static void query_refspecs_multiple(struct refspec *refs, int ref_count, struct } } -int query_refspecs(struct refspec *refs, int ref_count, struct refspec *query) +int query_refspecs(struct refspec_item *refs, int ref_count, struct refspec_item *query) { int i; int find_src = !query->src; @@ -761,7 +761,7 @@ int query_refspecs(struct refspec *refs, int ref_count, struct refspec *query) return error("query_refspecs: need either src or dst"); for (i = 0; i < ref_count; i++) { - struct refspec *refspec = &refs[i]; + struct refspec_item *refspec = &refs[i]; const char *key = find_src ? refspec->dst : refspec->src; const char *value = find_src ? refspec->src : refspec->dst; @@ -781,12 +781,12 @@ int query_refspecs(struct refspec *refs, int ref_count, struct refspec *query) return -1; } -char *apply_refspecs(struct refspec *refspecs, int nr_refspec, +char *apply_refspecs(struct refspec_item *refspecs, int nr_refspec, const char *name) { - struct refspec query; + struct refspec_item query; - memset(&query, 0, sizeof(struct refspec)); + memset(&query, 0, sizeof(struct refspec_item)); query.src = (char *)name; if (query_refspecs(refspecs, nr_refspec, &query)) @@ -795,7 +795,7 @@ char *apply_refspecs(struct refspec *refspecs, int nr_refspec, return query.dst; } -int remote_find_tracking(struct remote *remote, struct refspec *refspec) +int remote_find_tracking(struct remote *remote, struct refspec_item *refspec) { return query_refspecs(remote->fetch, remote->fetch_refspec_nr, refspec); } @@ -1004,7 +1004,7 @@ static char *guess_ref(const char *name, struct ref *peer) } static int match_explicit_lhs(struct ref *src, - struct refspec *rs, + struct refspec_item *rs, struct ref **match, int *allocated_match) { @@ -1030,7 +1030,7 @@ static int match_explicit_lhs(struct ref *src, static int match_explicit(struct ref *src, struct ref *dst, struct ref ***dst_tail, - struct refspec *rs) + struct refspec_item *rs) { struct ref *matched_src, *matched_dst; int allocated_src; @@ -1099,7 +1099,7 @@ static int match_explicit(struct ref *src, struct ref *dst, } static int match_explicit_refs(struct ref *src, struct ref *dst, - struct ref ***dst_tail, struct refspec *rs, + struct ref ***dst_tail, struct refspec_item *rs, int rs_nr) { int i, errs; @@ -1108,10 +1108,10 @@ static int match_explicit_refs(struct ref *src, struct ref *dst, return errs; } -static char *get_ref_match(const struct refspec *rs, int rs_nr, const struct ref *ref, - int send_mirror, int direction, const struct refspec **ret_pat) +static char *get_ref_match(const struct refspec_item *rs, int rs_nr, const struct ref *ref, + int send_mirror, int direction, const struct refspec_item **ret_pat) { - const struct refspec *pat; + const struct refspec_item *pat; char *name; int i; int matching_refs = -1; @@ -1282,12 +1282,12 @@ static void prepare_ref_index(struct string_list *ref_index, struct ref *ref) */ int check_push_refs(struct ref *src, int nr_refspec, const char **refspec_names) { - struct refspec *refspec = parse_push_refspec(nr_refspec, refspec_names); + struct refspec_item *refspec = parse_push_refspec(nr_refspec, refspec_names); int ret = 0; int i; for (i = 0; i < nr_refspec; i++) { - struct refspec *rs = refspec + i; + struct refspec_item *rs = refspec + i; if (rs->pattern || rs->matching) continue; @@ -1310,7 +1310,7 @@ int check_push_refs(struct ref *src, int nr_refspec, const char **refspec_names) int match_push_refs(struct ref *src, struct ref **dst, int nr_refspec, const char **refspec, int flags) { - struct refspec *rs; + struct refspec_item *rs; int send_all = flags & MATCH_REFS_ALL; int send_mirror = flags & MATCH_REFS_MIRROR; int send_prune = flags & MATCH_REFS_PRUNE; @@ -1330,7 +1330,7 @@ int match_push_refs(struct ref *src, struct ref **dst, for (ref = src; ref; ref = ref->next) { struct string_list_item *dst_item; struct ref *dst_peer; - const struct refspec *pat = NULL; + const struct refspec_item *pat = NULL; char *dst_name; dst_name = get_ref_match(rs, nr_refspec, ref, send_mirror, FROM_SRC, &pat); @@ -1686,7 +1686,7 @@ static int ignore_symref_update(const char *refname) * local symbolic ref. */ static struct ref *get_expanded_map(const struct ref *remote_refs, - const struct refspec *refspec) + const struct refspec_item *refspec) { const struct ref *ref; struct ref *ret = NULL; @@ -1751,7 +1751,7 @@ static struct ref *get_local_ref(const char *name) } int get_fetch_map(const struct ref *remote_refs, - const struct refspec *refspec, + const struct refspec_item *refspec, struct ref ***tail, int missing_ok) { @@ -2089,7 +2089,7 @@ struct ref *guess_remote_head(const struct ref *head, struct stale_heads_info { struct string_list *ref_names; struct ref **stale_refs_tail; - struct refspec *refs; + struct refspec_item *refs; int ref_count; }; @@ -2098,9 +2098,9 @@ static int get_stale_heads_cb(const char *refname, const struct object_id *oid, { struct stale_heads_info *info = cb_data; struct string_list matches = STRING_LIST_INIT_DUP; - struct refspec query; + struct refspec_item query; int i, stale = 1; - memset(&query, 0, sizeof(struct refspec)); + memset(&query, 0, sizeof(struct refspec_item)); query.dst = (char *)refname; query_refspecs_multiple(info->refs, info->ref_count, &query, &matches); @@ -2131,7 +2131,7 @@ clean_exit: return 0; } -struct ref *get_stale_heads(struct refspec *refs, int ref_count, struct ref *fetch_map) +struct ref *get_stale_heads(struct refspec_item *refs, int ref_count, struct ref *fetch_map) { struct ref *ref, *stale_refs = NULL; struct string_list ref_names = STRING_LIST_INIT_NODUP; diff --git a/remote.h b/remote.h index 386ced9012..3657bd43d1 100644 --- a/remote.h +++ b/remote.h @@ -28,12 +28,12 @@ struct remote { int pushurl_alloc; const char **push_refspec; - struct refspec *push; + struct refspec_item *push; int push_refspec_nr; int push_refspec_alloc; const char **fetch_refspec; - struct refspec *fetch; + struct refspec_item *fetch; int fetch_refspec_nr; int fetch_refspec_alloc; @@ -163,8 +163,8 @@ int ref_newer(const struct object_id *new_oid, const struct object_id *old_oid); */ struct ref *ref_remove_duplicates(struct ref *ref_map); -extern int query_refspecs(struct refspec *specs, int nr, struct refspec *query); -char *apply_refspecs(struct refspec *refspecs, int nr_refspec, +extern int query_refspecs(struct refspec_item *specs, int nr, struct refspec_item *query); +char *apply_refspecs(struct refspec_item *refspecs, int nr_refspec, const char *name); int check_push_refs(struct ref *src, int nr_refspec, const char **refspec); @@ -185,7 +185,7 @@ void set_ref_status_for_push(struct ref *remote_refs, int send_mirror, * missing_ok is usually false, but when we are adding branch.$name.merge * it is Ok if the branch is not at the remote anymore. */ -int get_fetch_map(const struct ref *remote_refs, const struct refspec *refspec, +int get_fetch_map(const struct ref *remote_refs, const struct refspec_item *refspec, struct ref ***tail, int missing_ok); struct ref *get_remote_ref(const struct ref *remote_refs, const char *name); @@ -193,7 +193,7 @@ struct ref *get_remote_ref(const struct ref *remote_refs, const char *name); /* * For the given remote, reads the refspec's src and sets the other fields. */ -int remote_find_tracking(struct remote *remote, struct refspec *refspec); +int remote_find_tracking(struct remote *remote, struct refspec_item *refspec); struct branch { const char *name; @@ -203,7 +203,7 @@ struct branch { const char *pushremote_name; const char **merge_name; - struct refspec **merge; + struct refspec_item **merge; int merge_nr; int merge_alloc; @@ -272,7 +272,7 @@ struct ref *guess_remote_head(const struct ref *head, int all); /* Return refs which no longer exist on remote */ -struct ref *get_stale_heads(struct refspec *refs, int ref_count, struct ref *fetch_map); +struct ref *get_stale_heads(struct refspec_item *refs, int ref_count, struct ref *fetch_map); /* * Compare-and-swap diff --git a/transport-helper.c b/transport-helper.c index b99e1cce9e..b156a37e7d 100644 --- a/transport-helper.c +++ b/transport-helper.c @@ -36,7 +36,7 @@ struct helper_data { char *export_marks; char *import_marks; /* These go from remote name (as in "list") to private name */ - struct refspec *refspecs; + struct refspec_item *refspecs; int refspec_nr; /* Transport options for fetch-pack/send-pack (should one of * those be invoked). diff --git a/transport.c b/transport.c index 2cf63d18b7..3ad4d37dc0 100644 --- a/transport.c +++ b/transport.c @@ -390,7 +390,7 @@ int transport_refs_pushed(struct ref *ref) void transport_update_tracking_ref(struct remote *remote, struct ref *ref, int verbose) { - struct refspec rs; + struct refspec_item rs; if (ref->status != REF_STATUS_OK && ref->status != REF_STATUS_UPTODATE) return; @@ -1111,7 +1111,7 @@ int transport_push(struct transport *transport, int porcelain = flags & TRANSPORT_PUSH_PORCELAIN; int pretend = flags & TRANSPORT_PUSH_DRY_RUN; int push_ret, ret, err; - struct refspec *tmp_rs; + struct refspec_item *tmp_rs; struct argv_array ref_prefixes = ARGV_ARRAY_INIT; int i; -- cgit v1.2.3 From 0460f4727793663b34fbf0711f60394de730f833 Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Wed, 16 May 2018 15:57:56 -0700 Subject: remote: convert check_push_refs to use struct refspec Convert 'check_push_refs()' to use 'struct refspec'. Signed-off-by: Brandon Williams Signed-off-by: Junio C Hamano --- remote.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'remote.c') diff --git a/remote.c b/remote.c index 89820c4769..1918551182 100644 --- a/remote.c +++ b/remote.c @@ -1282,12 +1282,14 @@ static void prepare_ref_index(struct string_list *ref_index, struct ref *ref) */ int check_push_refs(struct ref *src, int nr_refspec, const char **refspec_names) { - struct refspec_item *refspec = parse_push_refspec(nr_refspec, refspec_names); + struct refspec refspec = REFSPEC_INIT_PUSH; int ret = 0; int i; - for (i = 0; i < nr_refspec; i++) { - struct refspec_item *rs = refspec + i; + refspec_appendn(&refspec, refspec_names, nr_refspec); + + for (i = 0; i < refspec.nr; i++) { + struct refspec_item *rs = &refspec.items[i]; if (rs->pattern || rs->matching) continue; @@ -1295,7 +1297,7 @@ int check_push_refs(struct ref *src, int nr_refspec, const char **refspec_names) ret |= match_explicit_lhs(src, rs, NULL, NULL); } - free_refspec(nr_refspec, refspec); + refspec_clear(&refspec); return ret; } -- cgit v1.2.3 From 8ca69370c890b52d751402034524da5384c5dd9a Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Wed, 16 May 2018 15:57:57 -0700 Subject: remote: convert match_push_refs to use struct refspec Convert 'match_push_refs()' to use struct refspec. Signed-off-by: Brandon Williams Signed-off-by: Junio C Hamano --- remote.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'remote.c') diff --git a/remote.c b/remote.c index 1918551182..bce6e7ce4c 100644 --- a/remote.c +++ b/remote.c @@ -1312,7 +1312,7 @@ int check_push_refs(struct ref *src, int nr_refspec, const char **refspec_names) int match_push_refs(struct ref *src, struct ref **dst, int nr_refspec, const char **refspec, int flags) { - struct refspec_item *rs; + struct refspec rs = REFSPEC_INIT_PUSH; int send_all = flags & MATCH_REFS_ALL; int send_mirror = flags & MATCH_REFS_MIRROR; int send_prune = flags & MATCH_REFS_PRUNE; @@ -1325,8 +1325,8 @@ int match_push_refs(struct ref *src, struct ref **dst, nr_refspec = 1; refspec = default_refspec; } - rs = parse_push_refspec(nr_refspec, (const char **) refspec); - errs = match_explicit_refs(src, *dst, &dst_tail, rs, nr_refspec); + refspec_appendn(&rs, refspec, nr_refspec); + errs = match_explicit_refs(src, *dst, &dst_tail, rs.items, rs.nr); /* pick the remainder */ for (ref = src; ref; ref = ref->next) { @@ -1335,7 +1335,7 @@ int match_push_refs(struct ref *src, struct ref **dst, const struct refspec_item *pat = NULL; char *dst_name; - dst_name = get_ref_match(rs, nr_refspec, ref, send_mirror, FROM_SRC, &pat); + dst_name = get_ref_match(rs.items, rs.nr, ref, send_mirror, FROM_SRC, &pat); if (!dst_name) continue; @@ -1384,7 +1384,7 @@ int match_push_refs(struct ref *src, struct ref **dst, /* We're already sending something to this ref. */ continue; - src_name = get_ref_match(rs, nr_refspec, ref, send_mirror, FROM_DST, NULL); + src_name = get_ref_match(rs.items, rs.nr, ref, send_mirror, FROM_DST, NULL); if (src_name) { if (!src_ref_index.nr) prepare_ref_index(&src_ref_index, src); @@ -1396,6 +1396,9 @@ int match_push_refs(struct ref *src, struct ref **dst, } string_list_clear(&src_ref_index, 0); } + + refspec_clear(&rs); + if (errs) return -1; return 0; -- cgit v1.2.3 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 +++++++------- remote.c | 35 ++++++++++++++--------------------- remote.h | 6 ++---- 4 files changed, 28 insertions(+), 37 deletions(-) (limited to 'remote.c') 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++) diff --git a/remote.c b/remote.c index bce6e7ce4c..1b7258f77e 100644 --- a/remote.c +++ b/remote.c @@ -77,14 +77,6 @@ static const char *alias_url(const char *url, struct rewrites *r) return xstrfmt("%s%s", r->rewrite[longest_i]->base, url + longest->len); } -static void add_push_refspec(struct remote *remote, const char *ref) -{ - ALLOC_GROW(remote->push_refspec, - remote->push_refspec_nr + 1, - remote->push_refspec_alloc); - remote->push_refspec[remote->push_refspec_nr++] = ref; -} - static void add_fetch_refspec(struct remote *remote, const char *ref) { ALLOC_GROW(remote->fetch_refspec, @@ -175,9 +167,11 @@ static struct remote *make_remote(const char *name, int len) ret = xcalloc(1, sizeof(struct remote)); ret->prune = -1; /* unspecified */ ret->prune_tags = -1; /* unspecified */ + ret->name = xstrndup(name, len); + refspec_init(&ret->push, REFSPEC_PUSH); + ALLOC_GROW(remotes, remotes_nr + 1, remotes_alloc); remotes[remotes_nr++] = ret; - ret->name = xstrndup(name, len); hashmap_entry_init(ret, lookup_entry.hash); replaced = hashmap_put(&remotes_hash, ret); @@ -275,7 +269,7 @@ static void read_remotes_file(struct remote *remote) if (skip_prefix(buf.buf, "URL:", &v)) add_url_alias(remote, xstrdup(skip_spaces(v))); else if (skip_prefix(buf.buf, "Push:", &v)) - add_push_refspec(remote, xstrdup(skip_spaces(v))); + refspec_append(&remote->push, skip_spaces(v)); else if (skip_prefix(buf.buf, "Pull:", &v)) add_fetch_refspec(remote, xstrdup(skip_spaces(v))); } @@ -323,8 +317,10 @@ static void read_branches_file(struct remote *remote) * Cogito compatible push: push current HEAD to remote #branch * (master if missing) */ - add_push_refspec(remote, xstrfmt("HEAD:refs/heads/%s", frag)); + strbuf_addf(&buf, "HEAD:refs/heads/%s", frag); + refspec_append(&remote->push, buf.buf); remote->fetch_tags = 1; /* always auto-follow */ + strbuf_release(&buf); } static int handle_config(const char *key, const char *value, void *cb) @@ -409,7 +405,8 @@ static int handle_config(const char *key, const char *value, void *cb) const char *v; if (git_config_string(&v, key, value)) return -1; - add_push_refspec(remote, v); + refspec_append(&remote->push, v); + free((char *)v); } else if (!strcmp(subkey, "fetch")) { const char *v; if (git_config_string(&v, key, value)) @@ -542,9 +539,9 @@ const char *remote_ref_for_branch(struct branch *branch, int for_push, pushremote_for_branch(branch, NULL); struct remote *remote = remote_get(remote_name); - if (remote && remote->push_refspec_nr && - (dst = apply_refspecs(remote->push, - remote->push_refspec_nr, + if (remote && remote->push.nr && + (dst = apply_refspecs(remote->push.items, + remote->push.nr, branch->refname))) { if (explicit) *explicit = 1; @@ -582,7 +579,6 @@ static struct remote *remote_get_1(const char *name, if (!valid_remote(ret)) return NULL; ret->fetch = parse_fetch_refspec(ret->fetch_refspec_nr, ret->fetch_refspec); - ret->push = parse_push_refspec(ret->push_refspec_nr, ret->push_refspec); return ret; } @@ -616,9 +612,6 @@ int for_each_remote(each_remote_fn fn, void *priv) if (!r->fetch) r->fetch = parse_fetch_refspec(r->fetch_refspec_nr, r->fetch_refspec); - if (!r->push) - r->push = parse_push_refspec(r->push_refspec_nr, - r->push_refspec); result = fn(r, priv); } return result; @@ -1613,11 +1606,11 @@ static const char *branch_get_push_1(struct branch *branch, struct strbuf *err) _("branch '%s' has no remote for pushing"), branch->name); - if (remote->push_refspec_nr) { + if (remote->push.nr) { char *dst; const char *ret; - dst = apply_refspecs(remote->push, remote->push_refspec_nr, + dst = apply_refspecs(remote->push.items, remote->push.nr, branch->refname); if (!dst) return error_buf(err, diff --git a/remote.h b/remote.h index 3657bd43d1..637fc5d0c3 100644 --- a/remote.h +++ b/remote.h @@ -3,6 +3,7 @@ #include "parse-options.h" #include "hashmap.h" +#include "refspec.h" enum { REMOTE_UNCONFIGURED = 0, @@ -27,10 +28,7 @@ struct remote { int pushurl_nr; int pushurl_alloc; - const char **push_refspec; - struct refspec_item *push; - int push_refspec_nr; - int push_refspec_alloc; + struct refspec push; const char **fetch_refspec; struct refspec_item *fetch; -- cgit v1.2.3 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 +++++++++--------- remote.c | 38 ++++++++++++-------------------------- remote.h | 5 +---- 4 files changed, 32 insertions(+), 49 deletions(-) (limited to 'remote.c') 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; diff --git a/remote.c b/remote.c index 1b7258f77e..26842ce37f 100644 --- a/remote.c +++ b/remote.c @@ -77,23 +77,9 @@ static const char *alias_url(const char *url, struct rewrites *r) return xstrfmt("%s%s", r->rewrite[longest_i]->base, url + longest->len); } -static void add_fetch_refspec(struct remote *remote, const char *ref) -{ - ALLOC_GROW(remote->fetch_refspec, - remote->fetch_refspec_nr + 1, - remote->fetch_refspec_alloc); - remote->fetch_refspec[remote->fetch_refspec_nr++] = ref; -} - void add_prune_tags_to_fetch_refspec(struct remote *remote) { - int nr = remote->fetch_refspec_nr; - int bufsize = nr + 1; - int size = sizeof(struct refspec_item); - - remote->fetch = xrealloc(remote->fetch, size * bufsize); - memcpy(&remote->fetch[nr], tag_refspec, size); - add_fetch_refspec(remote, xstrdup(TAG_REFSPEC)); + refspec_append(&remote->fetch, TAG_REFSPEC); } static void add_url(struct remote *remote, const char *url) @@ -169,6 +155,7 @@ static struct remote *make_remote(const char *name, int len) ret->prune_tags = -1; /* unspecified */ ret->name = xstrndup(name, len); refspec_init(&ret->push, REFSPEC_PUSH); + refspec_init(&ret->fetch, REFSPEC_FETCH); ALLOC_GROW(remotes, remotes_nr + 1, remotes_alloc); remotes[remotes_nr++] = ret; @@ -271,7 +258,7 @@ static void read_remotes_file(struct remote *remote) else if (skip_prefix(buf.buf, "Push:", &v)) refspec_append(&remote->push, skip_spaces(v)); else if (skip_prefix(buf.buf, "Pull:", &v)) - add_fetch_refspec(remote, xstrdup(skip_spaces(v))); + refspec_append(&remote->fetch, skip_spaces(v)); } strbuf_release(&buf); fclose(f); @@ -310,13 +297,15 @@ static void read_branches_file(struct remote *remote) frag = "master"; add_url_alias(remote, strbuf_detach(&buf, NULL)); - add_fetch_refspec(remote, xstrfmt("refs/heads/%s:refs/heads/%s", - frag, remote->name)); + strbuf_addf(&buf, "refs/heads/%s:refs/heads/%s", + frag, remote->name); + refspec_append(&remote->fetch, buf.buf); /* * Cogito compatible push: push current HEAD to remote #branch * (master if missing) */ + strbuf_reset(&buf); strbuf_addf(&buf, "HEAD:refs/heads/%s", frag); refspec_append(&remote->push, buf.buf); remote->fetch_tags = 1; /* always auto-follow */ @@ -411,7 +400,8 @@ static int handle_config(const char *key, const char *value, void *cb) const char *v; if (git_config_string(&v, key, value)) return -1; - add_fetch_refspec(remote, v); + refspec_append(&remote->fetch, v); + free((char *)v); } else if (!strcmp(subkey, "receivepack")) { const char *v; if (git_config_string(&v, key, value)) @@ -578,7 +568,6 @@ static struct remote *remote_get_1(const char *name, add_url_alias(ret, name); if (!valid_remote(ret)) return NULL; - ret->fetch = parse_fetch_refspec(ret->fetch_refspec_nr, ret->fetch_refspec); return ret; } @@ -609,9 +598,6 @@ int for_each_remote(each_remote_fn fn, void *priv) struct remote *r = remotes[i]; if (!r) continue; - if (!r->fetch) - r->fetch = parse_fetch_refspec(r->fetch_refspec_nr, - r->fetch_refspec); result = fn(r, priv); } return result; @@ -790,7 +776,7 @@ char *apply_refspecs(struct refspec_item *refspecs, int nr_refspec, int remote_find_tracking(struct remote *remote, struct refspec_item *refspec) { - return query_refspecs(remote->fetch, remote->fetch_refspec_nr, refspec); + return query_refspecs(remote->fetch.items, remote->fetch.nr, refspec); } static struct ref *alloc_ref_with_prefix(const char *prefix, size_t prefixlen, @@ -1588,7 +1574,7 @@ static const char *tracking_for_push_dest(struct remote *remote, { char *ret; - ret = apply_refspecs(remote->fetch, remote->fetch_refspec_nr, refname); + ret = apply_refspecs(remote->fetch.items, remote->fetch.nr, refname); if (!ret) return error_buf(err, _("push destination '%s' on remote '%s' has no local tracking branch"), @@ -2222,7 +2208,7 @@ static int remote_tracking(struct remote *remote, const char *refname, { char *dst; - dst = apply_refspecs(remote->fetch, remote->fetch_refspec_nr, refname); + dst = apply_refspecs(remote->fetch.items, remote->fetch.nr, refname); if (!dst) return -1; /* no tracking ref for refname at remote */ if (read_ref(dst, oid)) diff --git a/remote.h b/remote.h index 637fc5d0c3..e7d00fe2a3 100644 --- a/remote.h +++ b/remote.h @@ -30,10 +30,7 @@ struct remote { struct refspec push; - const char **fetch_refspec; - struct refspec_item *fetch; - int fetch_refspec_nr; - int fetch_refspec_alloc; + struct refspec fetch; /* * -1 to never fetch tags -- cgit v1.2.3 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 +- remote.c | 5 ----- remote.h | 2 -- 3 files changed, 1 insertion(+), 8 deletions(-) (limited to 'remote.c') 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); diff --git a/remote.c b/remote.c index 26842ce37f..4a9bddf0d7 100644 --- a/remote.c +++ b/remote.c @@ -77,11 +77,6 @@ static const char *alias_url(const char *url, struct rewrites *r) return xstrfmt("%s%s", r->rewrite[longest_i]->base, url + longest->len); } -void add_prune_tags_to_fetch_refspec(struct remote *remote) -{ - refspec_append(&remote->fetch, TAG_REFSPEC); -} - static void add_url(struct remote *remote, const char *url) { ALLOC_GROW(remote->url, remote->url_nr + 1, remote->url_alloc); diff --git a/remote.h b/remote.h index e7d00fe2a3..4ffbc0082d 100644 --- a/remote.h +++ b/remote.h @@ -290,6 +290,4 @@ extern int parseopt_push_cas_option(const struct option *, const char *arg, int extern int is_empty_cas(const struct push_cas_option *); void apply_push_cas(struct push_cas_option *, struct remote *, struct ref *); -void add_prune_tags_to_fetch_refspec(struct remote *remote); - #endif -- cgit v1.2.3 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 +-- remote.c | 18 +++++++++--------- remote.h | 2 +- 4 files changed, 12 insertions(+), 13 deletions(-) (limited to 'remote.c') 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)); diff --git a/remote.c b/remote.c index 4a9bddf0d7..358442e4b5 100644 --- a/remote.c +++ b/remote.c @@ -698,7 +698,9 @@ static int match_name_with_pattern(const char *key, const char *name, return ret; } -static void query_refspecs_multiple(struct refspec_item *refs, int ref_count, struct refspec_item *query, struct string_list *results) +static void query_refspecs_multiple(struct refspec *rs, + struct refspec_item *query, + struct string_list *results) { int i; int find_src = !query->src; @@ -706,8 +708,8 @@ static void query_refspecs_multiple(struct refspec_item *refs, int ref_count, st if (find_src && !query->dst) error("query_refspecs_multiple: need either src or dst"); - for (i = 0; i < ref_count; i++) { - struct refspec_item *refspec = &refs[i]; + for (i = 0; i < rs->nr; i++) { + struct refspec_item *refspec = &rs->items[i]; const char *key = find_src ? refspec->dst : refspec->src; const char *value = find_src ? refspec->src : refspec->dst; const char *needle = find_src ? query->dst : query->src; @@ -2068,8 +2070,7 @@ struct ref *guess_remote_head(const struct ref *head, struct stale_heads_info { struct string_list *ref_names; struct ref **stale_refs_tail; - struct refspec_item *refs; - int ref_count; + struct refspec *rs; }; static int get_stale_heads_cb(const char *refname, const struct object_id *oid, @@ -2082,7 +2083,7 @@ static int get_stale_heads_cb(const char *refname, const struct object_id *oid, memset(&query, 0, sizeof(struct refspec_item)); query.dst = (char *)refname; - query_refspecs_multiple(info->refs, info->ref_count, &query, &matches); + query_refspecs_multiple(info->rs, &query, &matches); if (matches.nr == 0) goto clean_exit; /* No matches */ @@ -2110,7 +2111,7 @@ clean_exit: return 0; } -struct ref *get_stale_heads(struct refspec_item *refs, int ref_count, struct ref *fetch_map) +struct ref *get_stale_heads(struct refspec *rs, struct ref *fetch_map) { struct ref *ref, *stale_refs = NULL; struct string_list ref_names = STRING_LIST_INIT_NODUP; @@ -2118,8 +2119,7 @@ struct ref *get_stale_heads(struct refspec_item *refs, int ref_count, struct ref info.ref_names = &ref_names; info.stale_refs_tail = &stale_refs; - info.refs = refs; - info.ref_count = ref_count; + info.rs = rs; for (ref = fetch_map; ref; ref = ref->next) string_list_append(&ref_names, ref->name); string_list_sort(&ref_names); diff --git a/remote.h b/remote.h index 4ffbc0082d..1a45542cdb 100644 --- a/remote.h +++ b/remote.h @@ -267,7 +267,7 @@ struct ref *guess_remote_head(const struct ref *head, int all); /* Return refs which no longer exist on remote */ -struct ref *get_stale_heads(struct refspec_item *refs, int ref_count, struct ref *fetch_map); +struct ref *get_stale_heads(struct refspec *rs, struct ref *fetch_map); /* * Compare-and-swap -- cgit v1.2.3 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 +- remote.c | 15 ++++++--------- remote.h | 3 +-- transport-helper.c | 6 +++--- 4 files changed, 11 insertions(+), 15 deletions(-) (limited to 'remote.c') 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; diff --git a/remote.c b/remote.c index 358442e4b5..89415a2631 100644 --- a/remote.c +++ b/remote.c @@ -525,8 +525,7 @@ const char *remote_ref_for_branch(struct branch *branch, int for_push, struct remote *remote = remote_get(remote_name); if (remote && remote->push.nr && - (dst = apply_refspecs(remote->push.items, - remote->push.nr, + (dst = apply_refspecs(&remote->push, branch->refname))) { if (explicit) *explicit = 1; @@ -757,15 +756,14 @@ int query_refspecs(struct refspec_item *refs, int ref_count, struct refspec_item return -1; } -char *apply_refspecs(struct refspec_item *refspecs, int nr_refspec, - const char *name) +char *apply_refspecs(struct refspec *rs, const char *name) { struct refspec_item query; memset(&query, 0, sizeof(struct refspec_item)); query.src = (char *)name; - if (query_refspecs(refspecs, nr_refspec, &query)) + if (query_refspecs(rs->items, rs->nr, &query)) return NULL; return query.dst; @@ -1571,7 +1569,7 @@ static const char *tracking_for_push_dest(struct remote *remote, { char *ret; - ret = apply_refspecs(remote->fetch.items, remote->fetch.nr, refname); + ret = apply_refspecs(&remote->fetch, refname); if (!ret) return error_buf(err, _("push destination '%s' on remote '%s' has no local tracking branch"), @@ -1593,8 +1591,7 @@ static const char *branch_get_push_1(struct branch *branch, struct strbuf *err) char *dst; const char *ret; - dst = apply_refspecs(remote->push.items, remote->push.nr, - branch->refname); + dst = apply_refspecs(&remote->push, branch->refname); if (!dst) return error_buf(err, _("push refspecs for '%s' do not include '%s'"), @@ -2203,7 +2200,7 @@ static int remote_tracking(struct remote *remote, const char *refname, { char *dst; - dst = apply_refspecs(remote->fetch.items, remote->fetch.nr, refname); + dst = apply_refspecs(&remote->fetch, refname); if (!dst) return -1; /* no tracking ref for refname at remote */ if (read_ref(dst, oid)) diff --git a/remote.h b/remote.h index 1a45542cdb..0b1fcc051d 100644 --- a/remote.h +++ b/remote.h @@ -159,8 +159,7 @@ int ref_newer(const struct object_id *new_oid, const struct object_id *old_oid); struct ref *ref_remove_duplicates(struct ref *ref_map); extern int query_refspecs(struct refspec_item *specs, int nr, struct refspec_item *query); -char *apply_refspecs(struct refspec_item *refspecs, int nr_refspec, - const char *name); +char *apply_refspecs(struct refspec *rs, const char *name); int check_push_refs(struct ref *src, int nr_refspec, const char **refspec); int match_push_refs(struct ref *src, struct ref **dst, diff --git a/transport-helper.c b/transport-helper.c index 33f51ebfc0..1f8ff7e942 100644 --- a/transport-helper.c +++ b/transport-helper.c @@ -523,7 +523,7 @@ static int fetch_with_import(struct transport *transport, continue; name = posn->symref ? posn->symref : posn->name; if (data->rs.nr) - private = apply_refspecs(data->rs.items, data->rs.nr, name); + private = apply_refspecs(&data->rs, name); else private = xstrdup(name); if (private) { @@ -805,7 +805,7 @@ static int push_update_refs_status(struct helper_data *data, continue; /* propagate back the update to the remote namespace */ - private = apply_refspecs(data->rs.items, data->rs.nr, ref->name); + private = apply_refspecs(&data->rs, ref->name); if (!private) continue; update_ref("update by helper", private, &ref->new_oid, NULL, @@ -942,7 +942,7 @@ static int push_refs_with_export(struct transport *transport, char *private; struct object_id oid; - private = apply_refspecs(data->rs.items, data->rs.nr, ref->name); + private = apply_refspecs(&data->rs, ref->name); if (private && !get_oid(private, &oid)) { strbuf_addf(&buf, "^%s", private); string_list_append_nodup(&revlist_args, -- cgit v1.2.3 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 +-- remote.c | 10 +++++----- remote.h | 2 +- 3 files changed, 7 insertions(+), 8 deletions(-) (limited to 'remote.c') 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 ? "+" : "", diff --git a/remote.c b/remote.c index 89415a2631..dd68e6b22d 100644 --- a/remote.c +++ b/remote.c @@ -725,7 +725,7 @@ static void query_refspecs_multiple(struct refspec *rs, } } -int query_refspecs(struct refspec_item *refs, int ref_count, struct refspec_item *query) +int query_refspecs(struct refspec *rs, struct refspec_item *query) { int i; int find_src = !query->src; @@ -735,8 +735,8 @@ int query_refspecs(struct refspec_item *refs, int ref_count, struct refspec_item if (find_src && !query->dst) return error("query_refspecs: need either src or dst"); - for (i = 0; i < ref_count; i++) { - struct refspec_item *refspec = &refs[i]; + for (i = 0; i < rs->nr; i++) { + struct refspec_item *refspec = &rs->items[i]; const char *key = find_src ? refspec->dst : refspec->src; const char *value = find_src ? refspec->src : refspec->dst; @@ -763,7 +763,7 @@ char *apply_refspecs(struct refspec *rs, const char *name) memset(&query, 0, sizeof(struct refspec_item)); query.src = (char *)name; - if (query_refspecs(rs->items, rs->nr, &query)) + if (query_refspecs(rs, &query)) return NULL; return query.dst; @@ -771,7 +771,7 @@ char *apply_refspecs(struct refspec *rs, const char *name) int remote_find_tracking(struct remote *remote, struct refspec_item *refspec) { - return query_refspecs(remote->fetch.items, remote->fetch.nr, refspec); + return query_refspecs(&remote->fetch, refspec); } static struct ref *alloc_ref_with_prefix(const char *prefix, size_t prefixlen, diff --git a/remote.h b/remote.h index 0b1fcc051d..9050ff75ac 100644 --- a/remote.h +++ b/remote.h @@ -158,7 +158,7 @@ int ref_newer(const struct object_id *new_oid, const struct object_id *old_oid); */ struct ref *ref_remove_duplicates(struct ref *ref_map); -extern int query_refspecs(struct refspec_item *specs, int nr, struct refspec_item *query); +int query_refspecs(struct refspec *rs, struct refspec_item *query); char *apply_refspecs(struct refspec *rs, const char *name); int check_push_refs(struct ref *src, int nr_refspec, const char **refspec); -- cgit v1.2.3 From f3acb8309f2ef229f9e1af3abe1ab9631e643fbc Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Wed, 16 May 2018 15:58:13 -0700 Subject: remote: convert get_ref_match to take a struct refspec Convert 'get_ref_match()' 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 --- remote.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) (limited to 'remote.c') diff --git a/remote.c b/remote.c index dd68e6b22d..9eb79ea197 100644 --- a/remote.c +++ b/remote.c @@ -1082,27 +1082,29 @@ static int match_explicit_refs(struct ref *src, struct ref *dst, return errs; } -static char *get_ref_match(const struct refspec_item *rs, int rs_nr, const struct ref *ref, - int send_mirror, int direction, const struct refspec_item **ret_pat) +static char *get_ref_match(const struct refspec *rs, const struct ref *ref, + int send_mirror, int direction, + const struct refspec_item **ret_pat) { const struct refspec_item *pat; char *name; int i; int matching_refs = -1; - for (i = 0; i < rs_nr; i++) { - if (rs[i].matching && - (matching_refs == -1 || rs[i].force)) { + for (i = 0; i < rs->nr; i++) { + const struct refspec_item *item = &rs->items[i]; + if (item->matching && + (matching_refs == -1 || item->force)) { matching_refs = i; continue; } - if (rs[i].pattern) { - const char *dst_side = rs[i].dst ? rs[i].dst : rs[i].src; + if (item->pattern) { + const char *dst_side = item->dst ? item->dst : item->src; int match; if (direction == FROM_SRC) - match = match_name_with_pattern(rs[i].src, ref->name, dst_side, &name); + match = match_name_with_pattern(item->src, ref->name, dst_side, &name); else - match = match_name_with_pattern(dst_side, ref->name, rs[i].src, &name); + match = match_name_with_pattern(dst_side, ref->name, item->src, &name); if (match) { matching_refs = i; break; @@ -1112,7 +1114,7 @@ static char *get_ref_match(const struct refspec_item *rs, int rs_nr, const struc if (matching_refs == -1) return NULL; - pat = rs + matching_refs; + pat = &rs->items[matching_refs]; if (pat->matching) { /* * "matching refs"; traditionally we pushed everything @@ -1309,7 +1311,7 @@ int match_push_refs(struct ref *src, struct ref **dst, const struct refspec_item *pat = NULL; char *dst_name; - dst_name = get_ref_match(rs.items, rs.nr, ref, send_mirror, FROM_SRC, &pat); + dst_name = get_ref_match(&rs, ref, send_mirror, FROM_SRC, &pat); if (!dst_name) continue; @@ -1358,7 +1360,7 @@ int match_push_refs(struct ref *src, struct ref **dst, /* We're already sending something to this ref. */ continue; - src_name = get_ref_match(rs.items, rs.nr, ref, send_mirror, FROM_DST, NULL); + src_name = get_ref_match(&rs, ref, send_mirror, FROM_DST, NULL); if (src_name) { if (!src_ref_index.nr) prepare_ref_index(&src_ref_index, src); -- cgit v1.2.3 From 9fa2e5e8534519f07d1a93878fde6341fb012a6e Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Wed, 16 May 2018 15:58:14 -0700 Subject: remote: convert match_explicit_refs to take a struct refspec Convert 'match_explicit_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 --- remote.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'remote.c') diff --git a/remote.c b/remote.c index 9eb79ea197..84dda3fd08 100644 --- a/remote.c +++ b/remote.c @@ -1073,12 +1073,11 @@ static int match_explicit(struct ref *src, struct ref *dst, } static int match_explicit_refs(struct ref *src, struct ref *dst, - struct ref ***dst_tail, struct refspec_item *rs, - int rs_nr) + struct ref ***dst_tail, struct refspec *rs) { int i, errs; - for (i = errs = 0; i < rs_nr; i++) - errs += match_explicit(src, dst, dst_tail, &rs[i]); + for (i = errs = 0; i < rs->nr; i++) + errs += match_explicit(src, dst, dst_tail, &rs->items[i]); return errs; } @@ -1302,7 +1301,7 @@ int match_push_refs(struct ref *src, struct ref **dst, refspec = default_refspec; } refspec_appendn(&rs, refspec, nr_refspec); - errs = match_explicit_refs(src, *dst, &dst_tail, rs.items, rs.nr); + errs = match_explicit_refs(src, *dst, &dst_tail, &rs); /* pick the remainder */ for (ref = src; ref; ref = ref->next) { -- cgit v1.2.3 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 +- http-push.c | 3 +-- remote.c | 21 ++++++++------------- remote.h | 2 +- transport.c | 4 +--- 6 files changed, 13 insertions(+), 22 deletions(-) (limited to 'remote.c') 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)) diff --git a/http-push.c b/http-push.c index a724ef03f9..ea5af6227e 100644 --- a/http-push.c +++ b/http-push.c @@ -1823,8 +1823,7 @@ int cmd_main(int argc, const char **argv) } /* match them up */ - if (match_push_refs(local_refs, &remote_refs, - rs.raw_nr, rs.raw, push_all)) { + if (match_push_refs(local_refs, &remote_refs, &rs, push_all)) { rc = -1; goto cleanup; } diff --git a/remote.c b/remote.c index 84dda3fd08..0046d4e28f 100644 --- a/remote.c +++ b/remote.c @@ -1285,23 +1285,20 @@ int check_push_refs(struct ref *src, int nr_refspec, const char **refspec_names) * dst (e.g. pushing to a new branch, done in match_explicit_refs). */ int match_push_refs(struct ref *src, struct ref **dst, - int nr_refspec, const char **refspec, int flags) + struct refspec *rs, int flags) { - struct refspec rs = REFSPEC_INIT_PUSH; int send_all = flags & MATCH_REFS_ALL; int send_mirror = flags & MATCH_REFS_MIRROR; int send_prune = flags & MATCH_REFS_PRUNE; int errs; - static const char *default_refspec[] = { ":", NULL }; struct ref *ref, **dst_tail = tail_ref(dst); struct string_list dst_ref_index = STRING_LIST_INIT_NODUP; - if (!nr_refspec) { - nr_refspec = 1; - refspec = default_refspec; - } - refspec_appendn(&rs, refspec, nr_refspec); - errs = match_explicit_refs(src, *dst, &dst_tail, &rs); + /* If no refspec is provided, use the default ":" */ + if (!rs->nr) + refspec_append(rs, ":"); + + errs = match_explicit_refs(src, *dst, &dst_tail, rs); /* pick the remainder */ for (ref = src; ref; ref = ref->next) { @@ -1310,7 +1307,7 @@ int match_push_refs(struct ref *src, struct ref **dst, const struct refspec_item *pat = NULL; char *dst_name; - dst_name = get_ref_match(&rs, ref, send_mirror, FROM_SRC, &pat); + dst_name = get_ref_match(rs, ref, send_mirror, FROM_SRC, &pat); if (!dst_name) continue; @@ -1359,7 +1356,7 @@ int match_push_refs(struct ref *src, struct ref **dst, /* We're already sending something to this ref. */ continue; - src_name = get_ref_match(&rs, ref, send_mirror, FROM_DST, NULL); + src_name = get_ref_match(rs, ref, send_mirror, FROM_DST, NULL); if (src_name) { if (!src_ref_index.nr) prepare_ref_index(&src_ref_index, src); @@ -1372,8 +1369,6 @@ int match_push_refs(struct ref *src, struct ref **dst, string_list_clear(&src_ref_index, 0); } - refspec_clear(&rs); - if (errs) return -1; return 0; diff --git a/remote.h b/remote.h index 9050ff75ac..74c5574578 100644 --- a/remote.h +++ b/remote.h @@ -163,7 +163,7 @@ char *apply_refspecs(struct refspec *rs, const char *name); int check_push_refs(struct ref *src, int nr_refspec, const char **refspec); int match_push_refs(struct ref *src, struct ref **dst, - int nr_refspec, const char **refspec, int all); + struct refspec *rs, int flags); void set_ref_status_for_push(struct ref *remote_refs, int send_mirror, int force_update); diff --git a/transport.c b/transport.c index fe96c0b807..24a97d9e8d 100644 --- a/transport.c +++ b/transport.c @@ -1127,10 +1127,8 @@ int transport_push(struct transport *transport, if (flags & TRANSPORT_PUSH_FOLLOW_TAGS) match_flags |= MATCH_REFS_FOLLOW_TAGS; - if (match_push_refs(local_refs, &remote_refs, - rs->raw_nr, rs->raw, match_flags)) { + if (match_push_refs(local_refs, &remote_refs, rs, match_flags)) return -1; - } if (transport->smart_options && transport->smart_options->cas && -- cgit v1.2.3 From afb1aed403de404c1e09fae5b8028f6b8f6982d3 Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Wed, 16 May 2018 15:58:22 -0700 Subject: remote: convert check_push_refs to take a struct refspec Convert 'check_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 --- remote.c | 14 +++++--------- remote.h | 2 +- transport.c | 2 +- 3 files changed, 7 insertions(+), 11 deletions(-) (limited to 'remote.c') diff --git a/remote.c b/remote.c index 0046d4e28f..0d1a3d07f8 100644 --- a/remote.c +++ b/remote.c @@ -1255,24 +1255,20 @@ static void prepare_ref_index(struct string_list *ref_index, struct ref *ref) * but we can catch some errors early before even talking to the * remote side. */ -int check_push_refs(struct ref *src, int nr_refspec, const char **refspec_names) +int check_push_refs(struct ref *src, struct refspec *rs) { - struct refspec refspec = REFSPEC_INIT_PUSH; int ret = 0; int i; - refspec_appendn(&refspec, refspec_names, nr_refspec); - - for (i = 0; i < refspec.nr; i++) { - struct refspec_item *rs = &refspec.items[i]; + for (i = 0; i < rs->nr; i++) { + struct refspec_item *item = &rs->items[i]; - if (rs->pattern || rs->matching) + if (item->pattern || item->matching) continue; - ret |= match_explicit_lhs(src, rs, NULL, NULL); + ret |= match_explicit_lhs(src, item, NULL, NULL); } - refspec_clear(&refspec); return ret; } diff --git a/remote.h b/remote.h index 74c5574578..62a6566594 100644 --- a/remote.h +++ b/remote.h @@ -161,7 +161,7 @@ struct ref *ref_remove_duplicates(struct ref *ref_map); int query_refspecs(struct refspec *rs, struct refspec_item *query); char *apply_refspecs(struct refspec *rs, const char *name); -int check_push_refs(struct ref *src, int nr_refspec, const char **refspec); +int check_push_refs(struct ref *src, struct refspec *rs); int match_push_refs(struct ref *src, struct ref **dst, struct refspec *rs, int flags); void set_ref_status_for_push(struct ref *remote_refs, int send_mirror, diff --git a/transport.c b/transport.c index 24a97d9e8d..e32bc320cf 100644 --- a/transport.c +++ b/transport.c @@ -1090,7 +1090,7 @@ int transport_push(struct transport *transport, struct argv_array ref_prefixes = ARGV_ARRAY_INIT; int i; - if (check_push_refs(local_refs, rs->raw_nr, rs->raw) < 0) + if (check_push_refs(local_refs, rs) < 0) return -1; for (i = 0; i < rs->nr; i++) { -- cgit v1.2.3