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 --- transport.c | 1 + 1 file changed, 1 insertion(+) (limited to 'transport.c') diff --git a/transport.c b/transport.c index 37410d8aad..2cf63d18b7 100644 --- a/transport.c +++ b/transport.c @@ -11,6 +11,7 @@ #include "bundle.h" #include "dir.h" #include "refs.h" +#include "refspec.h" #include "branch.h" #include "url.h" #include "submodule.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 --- transport.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'transport.c') 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.1 From e03c4e084d89f31dd4569b085d88b60758a54cd1 Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Wed, 16 May 2018 15:57:55 -0700 Subject: transport: convert transport_push to use struct refspec Convert the logic in 'transport_push()' which calculates a list of ref-prefixes to use 'struct refspec'. Signed-off-by: Brandon Williams Signed-off-by: Junio C Hamano --- transport.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'transport.c') diff --git a/transport.c b/transport.c index 3ad4d37dc0..181db4d4d0 100644 --- a/transport.c +++ b/transport.c @@ -1111,21 +1111,22 @@ 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_item *tmp_rs; + struct refspec tmp_rs = REFSPEC_INIT_PUSH; struct argv_array ref_prefixes = ARGV_ARRAY_INIT; int i; if (check_push_refs(local_refs, refspec_nr, refspec) < 0) return -1; - tmp_rs = parse_push_refspec(refspec_nr, refspec); - for (i = 0; i < refspec_nr; i++) { + refspec_appendn(&tmp_rs, refspec, refspec_nr); + for (i = 0; i < tmp_rs.nr; i++) { + const struct refspec_item *item = &tmp_rs.items[i]; const char *prefix = NULL; - if (tmp_rs[i].dst) - prefix = tmp_rs[i].dst; - else if (tmp_rs[i].src && !tmp_rs[i].exact_sha1) - prefix = tmp_rs[i].src; + if (item->dst) + prefix = item->dst; + else if (item->src && !item->exact_sha1) + prefix = item->src; if (prefix) { const char *glob = strchr(prefix, '*'); @@ -1142,7 +1143,7 @@ int transport_push(struct transport *transport, &ref_prefixes); argv_array_clear(&ref_prefixes); - free_refspec(refspec_nr, tmp_rs); + refspec_clear(&tmp_rs); if (flags & TRANSPORT_PUSH_ALL) match_flags |= MATCH_REFS_ALL; -- 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 --- transport.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'transport.c') diff --git a/transport.c b/transport.c index 181db4d4d0..a89f17744f 100644 --- a/transport.c +++ b/transport.c @@ -1093,11 +1093,11 @@ static int run_pre_push_hook(struct transport *transport, } int transport_push(struct transport *transport, - int refspec_nr, const char **refspec, int flags, + struct refspec *rs, int flags, unsigned int *reject_reasons) { *reject_reasons = 0; - transport_verify_remote_names(refspec_nr, refspec); + transport_verify_remote_names(rs->raw_nr, rs->raw); if (transport_color_config() < 0) return -1; @@ -1111,16 +1111,14 @@ 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 = REFSPEC_INIT_PUSH; struct argv_array ref_prefixes = ARGV_ARRAY_INIT; int i; - if (check_push_refs(local_refs, refspec_nr, refspec) < 0) + if (check_push_refs(local_refs, rs->raw_nr, rs->raw) < 0) return -1; - refspec_appendn(&tmp_rs, refspec, refspec_nr); - for (i = 0; i < tmp_rs.nr; i++) { - const struct refspec_item *item = &tmp_rs.items[i]; + for (i = 0; i < rs->nr; i++) { + const struct refspec_item *item = &rs->items[i]; const char *prefix = NULL; if (item->dst) @@ -1143,7 +1141,6 @@ int transport_push(struct transport *transport, &ref_prefixes); argv_array_clear(&ref_prefixes); - refspec_clear(&tmp_rs); if (flags & TRANSPORT_PUSH_ALL) match_flags |= MATCH_REFS_ALL; @@ -1155,7 +1152,7 @@ int transport_push(struct transport *transport, match_flags |= MATCH_REFS_FOLLOW_TAGS; if (match_push_refs(local_refs, &remote_refs, - refspec_nr, refspec, match_flags)) { + rs->raw_nr, rs->raw, match_flags)) { return -1; } @@ -1186,7 +1183,7 @@ int transport_push(struct transport *transport, if (!push_unpushed_submodules(&commits, transport->remote, - refspec, refspec_nr, + rs->raw, rs->raw_nr, transport->push_options, pretend)) { oid_array_clear(&commits); -- 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 --- transport.c | 24 ------------------------ 1 file changed, 24 deletions(-) (limited to 'transport.c') diff --git a/transport.c b/transport.c index a89f17744f..fe96c0b807 100644 --- a/transport.c +++ b/transport.c @@ -619,29 +619,6 @@ void transport_print_push_status(const char *dest, struct ref *refs, free(head); } -void transport_verify_remote_names(int nr_heads, const char **heads) -{ - int i; - - for (i = 0; i < nr_heads; i++) { - const char *local = heads[i]; - const char *remote = strrchr(heads[i], ':'); - - if (*local == '+') - local++; - - /* A matching refspec is okay. */ - if (remote == local && remote[1] == '\0') - continue; - - remote = remote ? (remote + 1) : local; - if (check_refname_format(remote, - REFNAME_ALLOW_ONELEVEL|REFNAME_REFSPEC_PATTERN)) - die("remote part of refspec is not a valid name in %s", - heads[i]); - } -} - static int git_transport_push(struct transport *transport, struct ref *remote_refs, int flags) { struct git_transport_data *data = transport->data; @@ -1097,7 +1074,6 @@ int transport_push(struct transport *transport, unsigned int *reject_reasons) { *reject_reasons = 0; - transport_verify_remote_names(rs->raw_nr, rs->raw); if (transport_color_config() < 0) return -1; -- 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 --- transport.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'transport.c') 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.1 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 --- transport.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'transport.c') 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.1 From 60fba4bf1670e6eabd61b04ebf86efedff866a50 Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Wed, 16 May 2018 15:58:23 -0700 Subject: submodule: convert push_unpushed_submodules to take a struct refspec Convert 'push_unpushed_submodules()' 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 --- transport.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'transport.c') diff --git a/transport.c b/transport.c index e32bc320cf..7e0b9abba3 100644 --- a/transport.c +++ b/transport.c @@ -1157,7 +1157,7 @@ int transport_push(struct transport *transport, if (!push_unpushed_submodules(&commits, transport->remote, - rs->raw, rs->raw_nr, + rs, transport->push_options, pretend)) { oid_array_clear(&commits); -- 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 --- transport.c | 21 +-------------------- 1 file changed, 1 insertion(+), 20 deletions(-) (limited to 'transport.c') diff --git a/transport.c b/transport.c index 7e0b9abba3..cbf0044c3e 100644 --- a/transport.c +++ b/transport.c @@ -1088,30 +1088,11 @@ int transport_push(struct transport *transport, int pretend = flags & TRANSPORT_PUSH_DRY_RUN; int push_ret, ret, err; struct argv_array ref_prefixes = ARGV_ARRAY_INIT; - int i; if (check_push_refs(local_refs, rs) < 0) return -1; - for (i = 0; i < rs->nr; i++) { - const struct refspec_item *item = &rs->items[i]; - const char *prefix = NULL; - - if (item->dst) - prefix = item->dst; - else if (item->src && !item->exact_sha1) - prefix = item->src; - - if (prefix) { - const char *glob = strchr(prefix, '*'); - if (glob) - argv_array_pushf(&ref_prefixes, "%.*s", - (int)(glob - prefix), - prefix); - else - expand_ref_prefix(&ref_prefixes, prefix); - } - } + refspec_ref_prefixes(rs, &ref_prefixes); remote_refs = transport->vtable->get_refs_list(transport, 1, &ref_prefixes); -- cgit v1.2.1