mirror of
https://github.com/git/git
synced 2024-08-27 19:49:21 +00:00
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
This commit is contained in:
commit
f67bf53300
|
@ -83,4 +83,15 @@ test_expect_success 'failed bundle creation does not leave cruft' '
|
|||
test_path_is_missing fail.bundle.lock
|
||||
'
|
||||
|
||||
test_expect_success 'fetch SHA-1 from bundle' '
|
||||
test_create_repo foo &&
|
||||
test_commit -C foo x &&
|
||||
git -C foo bundle create tip.bundle -1 master &&
|
||||
git -C foo rev-parse HEAD >hash &&
|
||||
|
||||
# Exercise to ensure that fetching a SHA-1 from a bundle works with no
|
||||
# errors
|
||||
git fetch --no-tags foo/tip.bundle "$(cat hash)"
|
||||
'
|
||||
|
||||
test_done
|
||||
|
|
|
@ -631,6 +631,19 @@ test_expect_success 'fetch with http:// using protocol v2' '
|
|||
grep "git< version 2" log
|
||||
'
|
||||
|
||||
test_expect_success 'fetch with http:// by hash without tag following with protocol v2 does not list refs' '
|
||||
test_when_finished "rm -f log" &&
|
||||
|
||||
test_commit -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" two_a &&
|
||||
git -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" rev-parse two_a >two_a_hash &&
|
||||
|
||||
GIT_TRACE_PACKET="$(pwd)/log" git -C http_child -c protocol.version=2 \
|
||||
fetch --no-tags origin $(cat two_a_hash) &&
|
||||
|
||||
grep "fetch< version 2" log &&
|
||||
! grep "fetch> command=ls-refs" log
|
||||
'
|
||||
|
||||
test_expect_success 'fetch from namespaced repo respects namespaces' '
|
||||
test_when_finished "rm -f log" &&
|
||||
|
||||
|
|
|
@ -33,6 +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 @@ static int connect_helper(struct transport *transport, const char *name,
|
|||
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))
|
||||
|
@ -1054,6 +1072,19 @@ static int has_attribute(const char *attrs, const char *attr)
|
|||
|
||||
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 +1093,9 @@ static struct ref *get_refs_list(struct transport *transport, int for_push,
|
|||
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 +1142,6 @@ static struct ref *get_refs_list(struct transport *transport, int for_push,
|
|||
}
|
||||
|
||||
static struct transport_vtable vtable = {
|
||||
0,
|
||||
set_helper_option,
|
||||
get_refs_list,
|
||||
fetch,
|
||||
|
|
|
@ -6,12 +6,6 @@ struct transport;
|
|||
struct argv_array;
|
||||
|
||||
struct transport_vtable {
|
||||
/**
|
||||
* This transport supports the fetch() function being called
|
||||
* without get_refs_list() first being called.
|
||||
*/
|
||||
unsigned fetch_without_list : 1;
|
||||
|
||||
/**
|
||||
* Returns 0 if successful, positive if the option is not
|
||||
* recognized or is inapplicable, and negative if the option
|
||||
|
|
18
transport.c
18
transport.c
|
@ -122,6 +122,7 @@ static void set_upstreams(struct transport *transport, struct ref *refs,
|
|||
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 @@ static struct ref *get_refs_from_bundle(struct transport *transport,
|
|||
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 @@ static int fetch_refs_from_bundle(struct transport *transport,
|
|||
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);
|
||||
}
|
||||
|
@ -743,7 +749,6 @@ static int disconnect_git(struct transport *transport)
|
|||
}
|
||||
|
||||
static struct transport_vtable taken_over_vtable = {
|
||||
1,
|
||||
NULL,
|
||||
get_refs_via_connect,
|
||||
fetch_refs_via_pack,
|
||||
|
@ -893,7 +898,6 @@ void transport_check_allowed(const char *type)
|
|||
}
|
||||
|
||||
static struct transport_vtable bundle_vtable = {
|
||||
0,
|
||||
NULL,
|
||||
get_refs_from_bundle,
|
||||
fetch_refs_from_bundle,
|
||||
|
@ -903,7 +907,6 @@ static struct transport_vtable bundle_vtable = {
|
|||
};
|
||||
|
||||
static struct transport_vtable builtin_smart_vtable = {
|
||||
1,
|
||||
NULL,
|
||||
get_refs_via_connect,
|
||||
fetch_refs_via_pack,
|
||||
|
@ -1286,15 +1289,6 @@ int transport_fetch_refs(struct transport *transport, struct ref *refs)
|
|||
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 &&
|
||||
|
|
Loading…
Reference in a new issue