Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Tan <jonathantanmy@google.com>2019-08-22 01:20:09 +0300
committerJunio C Hamano <gitster@pobox.com>2019-08-23 00:20:35 +0300
commitac3fda82bfe1c9e99c5838d052c678c78139ee34 (patch)
treed25670cb823e968103065070b0e6c6c207d99c42 /transport-helper.c
parent745f6812895b31c02b29bdfe4ae8e5498f776c26 (diff)
transport-helper: skip ls-refs if unnecessary
Commit e70a3030e7 ("fetch: do not list refs if fetching only hashes", 2018-10-07) and its ancestors taught Git, as an optimization, to skip the ls-refs step when it is not necessary during a protocol v2 fetch (for example, when lazy fetching a missing object in a partial clone, or when running "git fetch --no-tags <remote> <SHA-1>"). But that was only done for natively supported protocols; in particular, HTTP was not supported. Teach Git to skip ls-refs when using remote helpers that support connect or stateless-connect. To do this, fetch() is made an acceptable entry point. Because fetch() can now be the first function in the vtable called, "get_helper(transport);" has to be added to the beginning of that function to set the transport up (if not yet set up) before process_connect() is invoked. When fetch() is called, the transport could be taken over (this happens if "connect" or "stateless-connect" is successfully run without any "fallback" response), or not. If the transport is taken over, execution continues like execution for natively supported protocols (fetch_refs_via_pack() is executed, which will fetch refs using ls-refs if needed). If not, the remote helper interface will invoke get_refs_list() if it hasn't been invoked yet, preserving existing behavior. Signed-off-by: Jonathan Tan <jonathantanmy@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'transport-helper.c')
-rw-r--r--transport-helper.c39
1 files changed, 33 insertions, 6 deletions
diff --git a/transport-helper.c b/transport-helper.c
index 6b05a88faf..1fb31e1a6e 100644
--- a/transport-helper.c
+++ b/transport-helper.c
@@ -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))
@@ -1059,6 +1077,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;
struct ref *ret = NULL;
@@ -1066,13 +1097,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
@@ -1119,7 +1146,7 @@ static struct ref *get_refs_list(struct transport *transport, int for_push,
}
static struct transport_vtable vtable = {
- 0,
+ 1,
set_helper_option,
get_refs_list,
fetch,