transport: convert get_refs_list to take a list of ref prefixes
Convert the 'struct transport' virtual function 'get_refs_list()' to optionally take an argv_array of ref prefixes. When communicating with a server using protocol v2 these ref prefixes can be sent when requesting a listing of their refs allowing the server to filter the refs it sends based on the sent prefixes. This list will be ignored when not using protocol v2. Signed-off-by: Brandon Williams <bmwill@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Brandon Williams committed
Mar 15, 2018 at 10:31 UTC
834cf34b26035abc58f7c2b0f2afd5527e93c30d
3 files changed
+24
-10
transport-helper.c
+3
-2
@@ -1026,7 +1026,8 @@ static int has_attribute(const char *attrs, const char *attr) {
1026
}
1027
}
1028
1029
-static struct ref *get_refs_list(struct transport *transport, int for_push)
1029
+static struct ref *get_refs_list(struct transport *transport, int for_push,
1030
+ const struct argv_array *ref_prefixes)
1031
{
1032
struct helper_data *data = transport->data;
1033
struct child_process *helper;
@@ -1039,7 +1040,7 @@ static struct ref *get_refs_list(struct transport *transport, int for_push)
1040
1041
if (process_connect(transport, for_push)) {
1042
do_take_over(transport);
1042
- return transport->vtable->get_refs_list(transport, for_push);
1043
+ return transport->vtable->get_refs_list(transport, for_push, ref_prefixes);
1044
}
1045
1046
if (data->push && for_push)
transport-internal.h
+10
-1
@@ -3,6 +3,7 @@
3
4
struct ref;
5
struct transport;
6
+struct argv_array;
7
8
struct transport_vtable {
9
/**
@@ -17,11 +18,19 @@ struct transport_vtable {
18
* the transport to try to share connections, for_push is a
19
* hint as to whether the ultimate operation is a push or a fetch.
20
*
21
+ * If communicating using protocol v2 a list of prefixes can be
22
+ * provided to be sent to the server to enable it to limit the ref
23
+ * advertisement. Since ref filtering is done on the server's end, and
24
+ * only when using protocol v2, this list will be ignored when not
25
+ * using protocol v2 meaning this function can return refs which don't
26
+ * match the provided ref_prefixes.
27
+ *
28
* If the transport is able to determine the remote hash for
29
* the ref without a huge amount of effort, it should store it
30
* in the ref's old_sha1 field; otherwise it should be all 0.
31
**/
24
- struct ref *(*get_refs_list)(struct transport *transport, int for_push);
32
+ struct ref *(*get_refs_list)(struct transport *transport, int for_push,
33
+ const struct argv_array *ref_prefixes);
34
35
/**
36
* Fetch the objects for the given refs. Note that this gets
transport.c
+11
-7
@@ -72,7 +72,9 @@ struct bundle_transport_data {
72
struct bundle_header header;
73
};
74
75
-static struct ref *get_refs_from_bundle(struct transport *transport, int for_push)
75
+static struct ref *get_refs_from_bundle(struct transport *transport,
76
+ int for_push,
77
+ const struct argv_array *ref_prefixes)
78
{
79
struct bundle_transport_data *data = transport->data;
80
struct ref *result = NULL;
@@ -189,7 +191,8 @@ static int connect_setup(struct transport *transport, int for_push)
191
return 0;
192
}
193
192
-static struct ref *get_refs_via_connect(struct transport *transport, int for_push)
194
+static struct ref *get_refs_via_connect(struct transport *transport, int for_push,
195
+ const struct argv_array *ref_prefixes)
196
{
197
struct git_transport_data *data = transport->data;
198
struct ref *refs = NULL;
@@ -204,7 +207,8 @@ static struct ref *get_refs_via_connect(struct transport *transport, int for_pus
207
data->version = discover_version(&reader);
208
switch (data->version) {
209
case protocol_v2:
207
- get_remote_refs(data->fd[1], &reader, &refs, for_push, NULL);
210
+ get_remote_refs(data->fd[1], &reader, &refs, for_push,
211
+ ref_prefixes);
212
break;
213
case protocol_v1:
214
case protocol_v0:
@@ -250,7 +254,7 @@ static int fetch_refs_via_pack(struct transport *transport,
254
args.update_shallow = data->options.update_shallow;
255
256
if (!data->got_remote_heads)
253
- refs_tmp = get_refs_via_connect(transport, 0);
257
+ refs_tmp = get_refs_via_connect(transport, 0, NULL);
258
259
switch (data->version) {
260
case protocol_v2:
@@ -568,7 +572,7 @@ static int git_transport_push(struct transport *transport, struct ref *remote_re
572
int ret = 0;
573
574
if (!data->got_remote_heads)
571
- get_refs_via_connect(transport, 1);
575
+ get_refs_via_connect(transport, 1, NULL);
576
577
memset(&args, 0, sizeof(args));
578
args.send_mirror = !!(flags & TRANSPORT_PUSH_MIRROR);
@@ -1028,7 +1032,7 @@ int transport_push(struct transport *transport,
1032
if (check_push_refs(local_refs, refspec_nr, refspec) < 0)
1033
return -1;
1034
1031
- remote_refs = transport->vtable->get_refs_list(transport, 1);
1035
+ remote_refs = transport->vtable->get_refs_list(transport, 1, NULL);
1036
1037
if (flags & TRANSPORT_PUSH_ALL)
1038
match_flags |= MATCH_REFS_ALL;
@@ -1137,7 +1141,7 @@ int transport_push(struct transport *transport,
1141
const struct ref *transport_get_remote_refs(struct transport *transport)
1142
{
1143
if (!transport->got_remote_refs) {
1140
- transport->remote_refs = transport->vtable->get_refs_list(transport, 0);
1144
+ transport->remote_refs = transport->vtable->get_refs_list(transport, 0, NULL);
1145
transport->got_remote_refs = 1;
1146
}
1147