From: Junio C Hamano Date: Wed, 18 Sep 2019 18:50:10 +0000 (-0700) Subject: Merge branch 'jt/avoid-ls-refs-with-http' X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/f67bf53300ac7bd57a593a3ec2338050ea8343f1?hp=-c Merge branch 'jt/avoid-ls-refs-with-http' The http transport lacked some optimization the native transports learned to avoid unnecessary ref advertisement, which has been corrected. * jt/avoid-ls-refs-with-http: transport: teach all vtables to allow fetch first transport-helper: skip ls-refs if unnecessary --- f67bf53300ac7bd57a593a3ec2338050ea8343f1 diff --combined transport-helper.c index 3169111772,96955d4004..9e1279b928 --- a/transport-helper.c +++ b/transport-helper.c @@@ -33,6 -33,16 +33,16 @@@ struct helper_data check_connectivity : 1, no_disconnect_req : 1, no_private_update : 1; + + /* + * As an optimization, the transport code may invoke fetch before + * get_refs_list. If this happens, and if the transport helper doesn't + * support connect or stateless_connect, we need to invoke + * get_refs_list ourselves if we haven't already done so. Keep track of + * whether we have invoked get_refs_list. + */ + unsigned get_refs_list_called : 1; + char *export_marks; char *import_marks; /* These go from remote name (as in "list") to private name */ @@@ -652,17 -662,25 +662,25 @@@ static int connect_helper(struct transp return 0; } + static struct ref *get_refs_list_using_list(struct transport *transport, + int for_push); + static int fetch(struct transport *transport, int nr_heads, struct ref **to_fetch) { struct helper_data *data = transport->data; int i, count; + get_helper(transport); + if (process_connect(transport, 0)) { do_take_over(transport); return transport->vtable->fetch(transport, nr_heads, to_fetch); } + if (!data->get_refs_list_called) + get_refs_list_using_list(transport, 0); + count = 0; for (i = 0; i < nr_heads; i++) if (!(to_fetch[i]->status & REF_STATUS_UPTODATE)) @@@ -682,9 -700,13 +700,9 @@@ set_helper_option(transport, "update-shallow", "true"); if (data->transport_options.filter_options.choice) { - struct strbuf expanded_filter_spec = STRBUF_INIT; - expand_list_objects_filter_spec( - &data->transport_options.filter_options, - &expanded_filter_spec); - set_helper_option(transport, "filter", - expanded_filter_spec.buf); - strbuf_release(&expanded_filter_spec); + const char *spec = expand_list_objects_filter_spec( + &data->transport_options.filter_options); + set_helper_option(transport, "filter", spec); } if (data->transport_options.negotiation_tips) @@@ -1054,6 -1076,19 +1072,19 @@@ static int has_attribute(const char *at static struct ref *get_refs_list(struct transport *transport, int for_push, const struct argv_array *ref_prefixes) + { + get_helper(transport); + + if (process_connect(transport, for_push)) { + do_take_over(transport); + return transport->vtable->get_refs_list(transport, for_push, ref_prefixes); + } + + return get_refs_list_using_list(transport, for_push); + } + + static struct ref *get_refs_list_using_list(struct transport *transport, + int for_push) { struct helper_data *data = transport->data; struct child_process *helper; @@@ -1062,13 -1097,9 +1093,9 @@@ struct ref *posn; struct strbuf buf = STRBUF_INIT; + data->get_refs_list_called = 1; helper = get_helper(transport); - if (process_connect(transport, for_push)) { - do_take_over(transport); - return transport->vtable->get_refs_list(transport, for_push, ref_prefixes); - } - if (data->push && for_push) write_str_in_full(helper->in, "list for-push\n"); else @@@ -1115,7 -1146,6 +1142,6 @@@ } static struct transport_vtable vtable = { - 0, set_helper_option, get_refs_list, fetch, diff --combined transport.c index 6324cfc482,662a2d9ae0..ae558af944 --- a/transport.c +++ b/transport.c @@@ -122,6 -122,7 +122,7 @@@ static void set_upstreams(struct transp struct bundle_transport_data { int fd; struct bundle_header header; + unsigned get_refs_from_bundle_called : 1; }; static struct ref *get_refs_from_bundle(struct transport *transport, @@@ -135,6 -136,8 +136,8 @@@ if (for_push) return NULL; + data->get_refs_from_bundle_called = 1; + if (data->fd > 0) close(data->fd); data->fd = read_bundle_header(transport->url, &data->header); @@@ -154,6 -157,9 +157,9 @@@ static int fetch_refs_from_bundle(struc int nr_heads, struct ref **to_fetch) { struct bundle_transport_data *data = transport->data; + + if (!data->get_refs_from_bundle_called) + get_refs_from_bundle(transport, 0, NULL); return unbundle(the_repository, &data->header, data->fd, transport->progress ? BUNDLE_VERBOSE : 0); } @@@ -224,7 -230,6 +230,7 @@@ static int set_git_option(struct git_tr opts->no_dependents = !!value; return 0; } else if (!strcmp(name, TRANS_OPT_LIST_OBJECTS_FILTER)) { + list_objects_filter_die_if_populated(&opts->filter_options); parse_list_objects_filter(&opts->filter_options, value); return 0; } @@@ -743,7 -748,6 +749,6 @@@ static int disconnect_git(struct transp } static struct transport_vtable taken_over_vtable = { - 1, NULL, get_refs_via_connect, fetch_refs_via_pack, @@@ -893,7 -897,6 +898,6 @@@ void transport_check_allowed(const cha } static struct transport_vtable bundle_vtable = { - 0, NULL, get_refs_from_bundle, fetch_refs_from_bundle, @@@ -903,7 -906,6 +907,6 @@@ }; static struct transport_vtable builtin_smart_vtable = { - 1, NULL, get_refs_via_connect, fetch_refs_via_pack, @@@ -1286,15 -1288,6 +1289,6 @@@ int transport_fetch_refs(struct transpo struct ref **heads = NULL; struct ref *rm; - if (!transport->vtable->fetch_without_list) - /* - * Some transports (e.g. the built-in bundle transport and the - * transport helper interface) do not work when fetching is - * done immediately after transport creation. List the remote - * refs anyway (if not already listed) as a workaround. - */ - transport_get_remote_refs(transport, NULL); - for (rm = refs; rm; rm = rm->next) { nr_refs++; if (rm->peer_ref &&