Skip to content

Commit 834cf34

Browse files
bmwillgitster
authored andcommitted
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>
1 parent e52449b commit 834cf34

File tree

3 files changed

+24
-10
lines changed

3 files changed

+24
-10
lines changed

transport-helper.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,7 +1026,8 @@ static int has_attribute(const char *attrs, const char *attr) {
10261026
}
10271027
}
10281028

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)
10301031
{
10311032
struct helper_data *data = transport->data;
10321033
struct child_process *helper;
@@ -1039,7 +1040,7 @@ static struct ref *get_refs_list(struct transport *transport, int for_push)
10391040

10401041
if (process_connect(transport, for_push)) {
10411042
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);
10431044
}
10441045

10451046
if (data->push && for_push)

transport-internal.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
struct ref;
55
struct transport;
6+
struct argv_array;
67

78
struct transport_vtable {
89
/**
@@ -17,11 +18,19 @@ struct transport_vtable {
1718
* the transport to try to share connections, for_push is a
1819
* hint as to whether the ultimate operation is a push or a fetch.
1920
*
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+
*
2028
* If the transport is able to determine the remote hash for
2129
* the ref without a huge amount of effort, it should store it
2230
* in the ref's old_sha1 field; otherwise it should be all 0.
2331
**/
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);
2534

2635
/**
2736
* Fetch the objects for the given refs. Note that this gets

transport.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ struct bundle_transport_data {
7272
struct bundle_header header;
7373
};
7474

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)
7678
{
7779
struct bundle_transport_data *data = transport->data;
7880
struct ref *result = NULL;
@@ -189,7 +191,8 @@ static int connect_setup(struct transport *transport, int for_push)
189191
return 0;
190192
}
191193

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)
193196
{
194197
struct git_transport_data *data = transport->data;
195198
struct ref *refs = NULL;
@@ -204,7 +207,8 @@ static struct ref *get_refs_via_connect(struct transport *transport, int for_pus
204207
data->version = discover_version(&reader);
205208
switch (data->version) {
206209
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);
208212
break;
209213
case protocol_v1:
210214
case protocol_v0:
@@ -250,7 +254,7 @@ static int fetch_refs_via_pack(struct transport *transport,
250254
args.update_shallow = data->options.update_shallow;
251255

252256
if (!data->got_remote_heads)
253-
refs_tmp = get_refs_via_connect(transport, 0);
257+
refs_tmp = get_refs_via_connect(transport, 0, NULL);
254258

255259
switch (data->version) {
256260
case protocol_v2:
@@ -568,7 +572,7 @@ static int git_transport_push(struct transport *transport, struct ref *remote_re
568572
int ret = 0;
569573

570574
if (!data->got_remote_heads)
571-
get_refs_via_connect(transport, 1);
575+
get_refs_via_connect(transport, 1, NULL);
572576

573577
memset(&args, 0, sizeof(args));
574578
args.send_mirror = !!(flags & TRANSPORT_PUSH_MIRROR);
@@ -1028,7 +1032,7 @@ int transport_push(struct transport *transport,
10281032
if (check_push_refs(local_refs, refspec_nr, refspec) < 0)
10291033
return -1;
10301034

1031-
remote_refs = transport->vtable->get_refs_list(transport, 1);
1035+
remote_refs = transport->vtable->get_refs_list(transport, 1, NULL);
10321036

10331037
if (flags & TRANSPORT_PUSH_ALL)
10341038
match_flags |= MATCH_REFS_ALL;
@@ -1137,7 +1141,7 @@ int transport_push(struct transport *transport,
11371141
const struct ref *transport_get_remote_refs(struct transport *transport)
11381142
{
11391143
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);
11411145
transport->got_remote_refs = 1;
11421146
}
11431147

0 commit comments

Comments
 (0)