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>
This commit is contained in:
parent
e52449b672
commit
834cf34b26
@ -1026,7 +1026,8 @@ static int has_attribute(const char *attrs, const char *attr) {
|
||||
}
|
||||
}
|
||||
|
||||
static struct ref *get_refs_list(struct transport *transport, int for_push)
|
||||
static struct ref *get_refs_list(struct transport *transport, int for_push,
|
||||
const struct argv_array *ref_prefixes)
|
||||
{
|
||||
struct helper_data *data = transport->data;
|
||||
struct child_process *helper;
|
||||
@ -1039,7 +1040,7 @@ static struct ref *get_refs_list(struct transport *transport, int for_push)
|
||||
|
||||
if (process_connect(transport, for_push)) {
|
||||
do_take_over(transport);
|
||||
return transport->vtable->get_refs_list(transport, for_push);
|
||||
return transport->vtable->get_refs_list(transport, for_push, ref_prefixes);
|
||||
}
|
||||
|
||||
if (data->push && for_push)
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
struct ref;
|
||||
struct transport;
|
||||
struct argv_array;
|
||||
|
||||
struct transport_vtable {
|
||||
/**
|
||||
@ -17,11 +18,19 @@ struct transport_vtable {
|
||||
* the transport to try to share connections, for_push is a
|
||||
* hint as to whether the ultimate operation is a push or a fetch.
|
||||
*
|
||||
* If communicating using protocol v2 a list of prefixes can be
|
||||
* provided to be sent to the server to enable it to limit the ref
|
||||
* advertisement. Since ref filtering is done on the server's end, and
|
||||
* only when using protocol v2, this list will be ignored when not
|
||||
* using protocol v2 meaning this function can return refs which don't
|
||||
* match the provided ref_prefixes.
|
||||
*
|
||||
* If the transport is able to determine the remote hash for
|
||||
* the ref without a huge amount of effort, it should store it
|
||||
* in the ref's old_sha1 field; otherwise it should be all 0.
|
||||
**/
|
||||
struct ref *(*get_refs_list)(struct transport *transport, int for_push);
|
||||
struct ref *(*get_refs_list)(struct transport *transport, int for_push,
|
||||
const struct argv_array *ref_prefixes);
|
||||
|
||||
/**
|
||||
* Fetch the objects for the given refs. Note that this gets
|
||||
|
18
transport.c
18
transport.c
@ -72,7 +72,9 @@ struct bundle_transport_data {
|
||||
struct bundle_header header;
|
||||
};
|
||||
|
||||
static struct ref *get_refs_from_bundle(struct transport *transport, int for_push)
|
||||
static struct ref *get_refs_from_bundle(struct transport *transport,
|
||||
int for_push,
|
||||
const struct argv_array *ref_prefixes)
|
||||
{
|
||||
struct bundle_transport_data *data = transport->data;
|
||||
struct ref *result = NULL;
|
||||
@ -189,7 +191,8 @@ static int connect_setup(struct transport *transport, int for_push)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct ref *get_refs_via_connect(struct transport *transport, int for_push)
|
||||
static struct ref *get_refs_via_connect(struct transport *transport, int for_push,
|
||||
const struct argv_array *ref_prefixes)
|
||||
{
|
||||
struct git_transport_data *data = transport->data;
|
||||
struct ref *refs = NULL;
|
||||
@ -204,7 +207,8 @@ static struct ref *get_refs_via_connect(struct transport *transport, int for_pus
|
||||
data->version = discover_version(&reader);
|
||||
switch (data->version) {
|
||||
case protocol_v2:
|
||||
get_remote_refs(data->fd[1], &reader, &refs, for_push, NULL);
|
||||
get_remote_refs(data->fd[1], &reader, &refs, for_push,
|
||||
ref_prefixes);
|
||||
break;
|
||||
case protocol_v1:
|
||||
case protocol_v0:
|
||||
@ -250,7 +254,7 @@ static int fetch_refs_via_pack(struct transport *transport,
|
||||
args.update_shallow = data->options.update_shallow;
|
||||
|
||||
if (!data->got_remote_heads)
|
||||
refs_tmp = get_refs_via_connect(transport, 0);
|
||||
refs_tmp = get_refs_via_connect(transport, 0, NULL);
|
||||
|
||||
switch (data->version) {
|
||||
case protocol_v2:
|
||||
@ -568,7 +572,7 @@ static int git_transport_push(struct transport *transport, struct ref *remote_re
|
||||
int ret = 0;
|
||||
|
||||
if (!data->got_remote_heads)
|
||||
get_refs_via_connect(transport, 1);
|
||||
get_refs_via_connect(transport, 1, NULL);
|
||||
|
||||
memset(&args, 0, sizeof(args));
|
||||
args.send_mirror = !!(flags & TRANSPORT_PUSH_MIRROR);
|
||||
@ -1028,7 +1032,7 @@ int transport_push(struct transport *transport,
|
||||
if (check_push_refs(local_refs, refspec_nr, refspec) < 0)
|
||||
return -1;
|
||||
|
||||
remote_refs = transport->vtable->get_refs_list(transport, 1);
|
||||
remote_refs = transport->vtable->get_refs_list(transport, 1, NULL);
|
||||
|
||||
if (flags & TRANSPORT_PUSH_ALL)
|
||||
match_flags |= MATCH_REFS_ALL;
|
||||
@ -1137,7 +1141,7 @@ int transport_push(struct transport *transport,
|
||||
const struct ref *transport_get_remote_refs(struct transport *transport)
|
||||
{
|
||||
if (!transport->got_remote_refs) {
|
||||
transport->remote_refs = transport->vtable->get_refs_list(transport, 0);
|
||||
transport->remote_refs = transport->vtable->get_refs_list(transport, 0, NULL);
|
||||
transport->got_remote_refs = 1;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user