summaryrefslogtreecommitdiff
path: root/transport-helper.c
diff options
context:
space:
mode:
authorJonathan Tan <jonathantanmy@google.com>2017-12-14 13:44:45 -0800
committerJunio C Hamano <gitster@pobox.com>2017-12-14 14:28:04 -0800
commite967ca38473a05abf3e8f7a025c6b9bee487aa4f (patch)
tree1954c9a0a80d1f44f9e5d5c2a75d042f7591b99d /transport-helper.c
parent245abe34ac0622b349470b89d4b76a082a133cab (diff)
downloadgit-e967ca38473a05abf3e8f7a025c6b9bee487aa4f.tar.gz
transport: make transport vtable more privatejt/transport-hide-vtable
Move the definition of the transport-specific functions provided by transports, whether declared in transport.c or transport-helper.c, into an internal header. This means that transport-using code (as opposed to transport-declaring code) can no longer access these functions (without importing the internal header themselves), making it clear that they should use the transport_*() functions instead, and also allowing the interface between the transport mechanism and an individual transport to independently evolve. This is superficially a reversal of commit 824d5776c3f2 ("Refactor struct transport_ops inlined into struct transport", 2007-09-19). However, the scope of the involved variables was neither affected nor discussed in that commit, and I think that the advantages in making those functions more private outweigh the advantages described in that commit's commit message. A minor additional point is that the code has gotten more complicated since then, in that the function-pointer variables are potentially mutated twice (once initially and once if transport_take_over() is invoked), increasing the value of corralling them into their own struct. Signed-off-by: Jonathan Tan <jonathantanmy@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'transport-helper.c')
-rw-r--r--transport-helper.c23
1 files changed, 14 insertions, 9 deletions
diff --git a/transport-helper.c b/transport-helper.c
index c948d5215c..1a4b43ff15 100644
--- a/transport-helper.c
+++ b/transport-helper.c
@@ -11,6 +11,7 @@
#include "sigchain.h"
#include "argv-array.h"
#include "refs.h"
+#include "transport-internal.h"
static int debug;
@@ -650,7 +651,7 @@ static int fetch(struct transport *transport,
if (process_connect(transport, 0)) {
do_take_over(transport);
- return transport->fetch(transport, nr_heads, to_fetch);
+ return transport->vtable->fetch(transport, nr_heads, to_fetch);
}
count = 0;
@@ -987,7 +988,7 @@ static int push_refs(struct transport *transport,
if (process_connect(transport, 1)) {
do_take_over(transport);
- return transport->push_refs(transport, remote_refs, flags);
+ return transport->vtable->push_refs(transport, remote_refs, flags);
}
if (!remote_refs) {
@@ -1035,7 +1036,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->get_refs_list(transport, for_push);
+ return transport->vtable->get_refs_list(transport, for_push);
}
if (data->push && for_push)
@@ -1084,6 +1085,15 @@ static struct ref *get_refs_list(struct transport *transport, int for_push)
return ret;
}
+static struct transport_vtable vtable = {
+ set_helper_option,
+ get_refs_list,
+ fetch,
+ push_refs,
+ connect_helper,
+ release_helper
+};
+
int transport_helper_init(struct transport *transport, const char *name)
{
struct helper_data *data = xcalloc(1, sizeof(*data));
@@ -1095,12 +1105,7 @@ int transport_helper_init(struct transport *transport, const char *name)
debug = 1;
transport->data = data;
- transport->set_option = set_helper_option;
- transport->get_refs_list = get_refs_list;
- transport->fetch = fetch;
- transport->push_refs = push_refs;
- transport->disconnect = release_helper;
- transport->connect = connect_helper;
+ transport->vtable = &vtable;
transport->smart_options = &(data->transport_options);
return 0;
}