Skip to content

Commit f67bf53

Browse files
committed
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
2 parents 627b826 + fddf2eb commit f67bf53

5 files changed

+62
-24
lines changed

t/t5607-clone-bundle.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,15 @@ test_expect_success 'failed bundle creation does not leave cruft' '
8383
test_path_is_missing fail.bundle.lock
8484
'
8585

86+
test_expect_success 'fetch SHA-1 from bundle' '
87+
test_create_repo foo &&
88+
test_commit -C foo x &&
89+
git -C foo bundle create tip.bundle -1 master &&
90+
git -C foo rev-parse HEAD >hash &&
91+
92+
# Exercise to ensure that fetching a SHA-1 from a bundle works with no
93+
# errors
94+
git fetch --no-tags foo/tip.bundle "$(cat hash)"
95+
'
96+
8697
test_done

t/t5702-protocol-v2.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,19 @@ test_expect_success 'fetch with http:// using protocol v2' '
631631
grep "git< version 2" log
632632
'
633633

634+
test_expect_success 'fetch with http:// by hash without tag following with protocol v2 does not list refs' '
635+
test_when_finished "rm -f log" &&
636+
637+
test_commit -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" two_a &&
638+
git -C "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" rev-parse two_a >two_a_hash &&
639+
640+
GIT_TRACE_PACKET="$(pwd)/log" git -C http_child -c protocol.version=2 \
641+
fetch --no-tags origin $(cat two_a_hash) &&
642+
643+
grep "fetch< version 2" log &&
644+
! grep "fetch> command=ls-refs" log
645+
'
646+
634647
test_expect_success 'fetch from namespaced repo respects namespaces' '
635648
test_when_finished "rm -f log" &&
636649

transport-helper.c

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,16 @@ struct helper_data {
3333
check_connectivity : 1,
3434
no_disconnect_req : 1,
3535
no_private_update : 1;
36+
37+
/*
38+
* As an optimization, the transport code may invoke fetch before
39+
* get_refs_list. If this happens, and if the transport helper doesn't
40+
* support connect or stateless_connect, we need to invoke
41+
* get_refs_list ourselves if we haven't already done so. Keep track of
42+
* whether we have invoked get_refs_list.
43+
*/
44+
unsigned get_refs_list_called : 1;
45+
3646
char *export_marks;
3747
char *import_marks;
3848
/* 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,
652662
return 0;
653663
}
654664

665+
static struct ref *get_refs_list_using_list(struct transport *transport,
666+
int for_push);
667+
655668
static int fetch(struct transport *transport,
656669
int nr_heads, struct ref **to_fetch)
657670
{
658671
struct helper_data *data = transport->data;
659672
int i, count;
660673

674+
get_helper(transport);
675+
661676
if (process_connect(transport, 0)) {
662677
do_take_over(transport);
663678
return transport->vtable->fetch(transport, nr_heads, to_fetch);
664679
}
665680

681+
if (!data->get_refs_list_called)
682+
get_refs_list_using_list(transport, 0);
683+
666684
count = 0;
667685
for (i = 0; i < nr_heads; i++)
668686
if (!(to_fetch[i]->status & REF_STATUS_UPTODATE))
@@ -1054,6 +1072,19 @@ static int has_attribute(const char *attrs, const char *attr)
10541072

10551073
static struct ref *get_refs_list(struct transport *transport, int for_push,
10561074
const struct argv_array *ref_prefixes)
1075+
{
1076+
get_helper(transport);
1077+
1078+
if (process_connect(transport, for_push)) {
1079+
do_take_over(transport);
1080+
return transport->vtable->get_refs_list(transport, for_push, ref_prefixes);
1081+
}
1082+
1083+
return get_refs_list_using_list(transport, for_push);
1084+
}
1085+
1086+
static struct ref *get_refs_list_using_list(struct transport *transport,
1087+
int for_push)
10571088
{
10581089
struct helper_data *data = transport->data;
10591090
struct child_process *helper;
@@ -1062,13 +1093,9 @@ static struct ref *get_refs_list(struct transport *transport, int for_push,
10621093
struct ref *posn;
10631094
struct strbuf buf = STRBUF_INIT;
10641095

1096+
data->get_refs_list_called = 1;
10651097
helper = get_helper(transport);
10661098

1067-
if (process_connect(transport, for_push)) {
1068-
do_take_over(transport);
1069-
return transport->vtable->get_refs_list(transport, for_push, ref_prefixes);
1070-
}
1071-
10721099
if (data->push && for_push)
10731100
write_str_in_full(helper->in, "list for-push\n");
10741101
else
@@ -1115,7 +1142,6 @@ static struct ref *get_refs_list(struct transport *transport, int for_push,
11151142
}
11161143

11171144
static struct transport_vtable vtable = {
1118-
0,
11191145
set_helper_option,
11201146
get_refs_list,
11211147
fetch,

transport-internal.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,6 @@ struct transport;
66
struct argv_array;
77

88
struct transport_vtable {
9-
/**
10-
* This transport supports the fetch() function being called
11-
* without get_refs_list() first being called.
12-
*/
13-
unsigned fetch_without_list : 1;
14-
159
/**
1610
* Returns 0 if successful, positive if the option is not
1711
* recognized or is inapplicable, and negative if the option

transport.c

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ static void set_upstreams(struct transport *transport, struct ref *refs,
122122
struct bundle_transport_data {
123123
int fd;
124124
struct bundle_header header;
125+
unsigned get_refs_from_bundle_called : 1;
125126
};
126127

127128
static struct ref *get_refs_from_bundle(struct transport *transport,
@@ -135,6 +136,8 @@ static struct ref *get_refs_from_bundle(struct transport *transport,
135136
if (for_push)
136137
return NULL;
137138

139+
data->get_refs_from_bundle_called = 1;
140+
138141
if (data->fd > 0)
139142
close(data->fd);
140143
data->fd = read_bundle_header(transport->url, &data->header);
@@ -154,6 +157,9 @@ static int fetch_refs_from_bundle(struct transport *transport,
154157
int nr_heads, struct ref **to_fetch)
155158
{
156159
struct bundle_transport_data *data = transport->data;
160+
161+
if (!data->get_refs_from_bundle_called)
162+
get_refs_from_bundle(transport, 0, NULL);
157163
return unbundle(the_repository, &data->header, data->fd,
158164
transport->progress ? BUNDLE_VERBOSE : 0);
159165
}
@@ -743,7 +749,6 @@ static int disconnect_git(struct transport *transport)
743749
}
744750

745751
static struct transport_vtable taken_over_vtable = {
746-
1,
747752
NULL,
748753
get_refs_via_connect,
749754
fetch_refs_via_pack,
@@ -893,7 +898,6 @@ void transport_check_allowed(const char *type)
893898
}
894899

895900
static struct transport_vtable bundle_vtable = {
896-
0,
897901
NULL,
898902
get_refs_from_bundle,
899903
fetch_refs_from_bundle,
@@ -903,7 +907,6 @@ static struct transport_vtable bundle_vtable = {
903907
};
904908

905909
static struct transport_vtable builtin_smart_vtable = {
906-
1,
907910
NULL,
908911
get_refs_via_connect,
909912
fetch_refs_via_pack,
@@ -1286,15 +1289,6 @@ int transport_fetch_refs(struct transport *transport, struct ref *refs)
12861289
struct ref **heads = NULL;
12871290
struct ref *rm;
12881291

1289-
if (!transport->vtable->fetch_without_list)
1290-
/*
1291-
* Some transports (e.g. the built-in bundle transport and the
1292-
* transport helper interface) do not work when fetching is
1293-
* done immediately after transport creation. List the remote
1294-
* refs anyway (if not already listed) as a workaround.
1295-
*/
1296-
transport_get_remote_refs(transport, NULL);
1297-
12981292
for (rm = refs; rm; rm = rm->next) {
12991293
nr_refs++;
13001294
if (rm->peer_ref &&

0 commit comments

Comments
 (0)