17
#include "string-list.h"
18
#include "sha1-array.h"
19
#include "sigchain.h"
20
+#include "transport-internal.h"
21
22
static void set_upstreams(struct transport *transport, struct ref *refs,
23
int pretend)
608
return 0;
609
}
610
611
+static struct transport_vtable taken_over_vtable = {
612
+ NULL,
613
+ get_refs_via_connect,
614
+ fetch_refs_via_pack,
615
+ git_transport_push,
616
+ NULL,
617
+ disconnect_git
618
+};
619
+
620
void transport_take_over(struct transport *transport,
621
struct child_process *child)
622
{
634
data->got_remote_heads = 0;
635
transport->data = data;
636
627
- transport->set_option = NULL;
628
- transport->get_refs_list = get_refs_via_connect;
629
- transport->fetch = fetch_refs_via_pack;
630
- transport->push_refs = git_transport_push;
631
- transport->disconnect = disconnect_git;
637
+ transport->vtable = &taken_over_vtable;
638
transport->smart_options = &(data->options);
639
640
transport->cannot_reuse = 1;
757
die("transport '%s' not allowed", type);
758
}
759
760
+static struct transport_vtable bundle_vtable = {
761
+ NULL,
762
+ get_refs_from_bundle,
763
+ fetch_refs_from_bundle,
764
+ NULL,
765
+ NULL,
766
+ close_bundle
767
+};
768
+
769
+static struct transport_vtable builtin_smart_vtable = {
770
+ NULL,
771
+ get_refs_via_connect,
772
+ fetch_refs_via_pack,
773
+ git_transport_push,
774
+ connect_git,
775
+ disconnect_git
776
+};
777
+
778
struct transport *transport_get(struct remote *remote, const char *url)
779
{
780
const char *helper;
811
struct bundle_transport_data *data = xcalloc(1, sizeof(*data));
812
transport_check_allowed("file");
813
ret->data = data;
790
- ret->get_refs_list = get_refs_from_bundle;
791
- ret->fetch = fetch_refs_from_bundle;
792
- ret->disconnect = close_bundle;
814
+ ret->vtable = &bundle_vtable;
815
ret->smart_options = NULL;
816
} else if (!is_url(url)
817
|| starts_with(url, "file://")
826
*/
827
struct git_transport_data *data = xcalloc(1, sizeof(*data));
828
ret->data = data;
807
- ret->set_option = NULL;
808
- ret->get_refs_list = get_refs_via_connect;
809
- ret->fetch = fetch_refs_via_pack;
810
- ret->push_refs = git_transport_push;
811
- ret->connect = connect_git;
812
- ret->disconnect = disconnect_git;
829
+ ret->vtable = &builtin_smart_vtable;
830
ret->smart_options = &(data->options);
831
832
data->conn = NULL;
860
git_reports = set_git_option(transport->smart_options,
861
name, value);
862
846
- if (transport->set_option)
847
- protocol_reports = transport->set_option(transport, name,
848
- value);
863
+ if (transport->vtable->set_option)
864
+ protocol_reports = transport->vtable->set_option(transport,
865
+ name, value);
866
867
/* If either report is 0, report 0 (success). */
868
if (!git_reports || !protocol_reports)
985
*reject_reasons = 0;
986
transport_verify_remote_names(refspec_nr, refspec);
987
971
- if (transport->push_refs) {
988
+ if (transport->vtable->push_refs) {
989
struct ref *remote_refs;
990
struct ref *local_refs = get_local_heads();
991
int match_flags = MATCH_REFS_NONE;
998
if (check_push_refs(local_refs, refspec_nr, refspec) < 0)
999
return -1;
1000
984
- remote_refs = transport->get_refs_list(transport, 1);
1001
+ remote_refs = transport->vtable->get_refs_list(transport, 1);
1002
1003
if (flags & TRANSPORT_PUSH_ALL)
1004
match_flags |= MATCH_REFS_ALL;
1073
}
1074
1075
if (!(flags & TRANSPORT_RECURSE_SUBMODULES_ONLY))
1059
- push_ret = transport->push_refs(transport, remote_refs, flags);
1076
+ push_ret = transport->vtable->push_refs(transport, remote_refs, flags);
1077
else
1078
push_ret = 0;
1079
err = push_had_errors(remote_refs);
1107
const struct ref *transport_get_remote_refs(struct transport *transport)
1108
{
1109
if (!transport->got_remote_refs) {
1093
- transport->remote_refs = transport->get_refs_list(transport, 0);
1110
+ transport->remote_refs = transport->vtable->get_refs_list(transport, 0);
1111
transport->got_remote_refs = 1;
1112
}
1113
1144
heads[nr_heads++] = rm;
1145
}
1146
1130
- rc = transport->fetch(transport, nr_heads, heads);
1147
+ rc = transport->vtable->fetch(transport, nr_heads, heads);
1148
1149
free(heads);
1150
return rc;
1161
int transport_connect(struct transport *transport, const char *name,
1162
const char *exec, int fd[2])
1163
{
1147
- if (transport->connect)
1148
- return transport->connect(transport, name, exec, fd);
1164
+ if (transport->vtable->connect)
1165
+ return transport->vtable->connect(transport, name, exec, fd);
1166
else
1167
die("Operation not supported by protocol");
1168
}
1170
int transport_disconnect(struct transport *transport)
1171
{
1172
int ret = 0;
1156
- if (transport->disconnect)
1157
- ret = transport->disconnect(transport);
1173
+ if (transport->vtable->disconnect)
1174
+ ret = transport->vtable->disconnect(transport);
1175
free(transport);
1176
return ret;
1177
}