1717#include "string-list.h"
1818#include "sha1-array.h"
1919#include "sigchain.h"
20+ #include "transport-internal.h"
2021
2122static void set_upstreams (struct transport * transport , struct ref * refs ,
2223 int pretend )
@@ -607,6 +608,15 @@ static int disconnect_git(struct transport *transport)
607608 return 0 ;
608609}
609610
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+
610620void transport_take_over (struct transport * transport ,
611621 struct child_process * child )
612622{
@@ -624,11 +634,7 @@ void transport_take_over(struct transport *transport,
624634 data -> got_remote_heads = 0 ;
625635 transport -> data = data ;
626636
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 ;
632638 transport -> smart_options = & (data -> options );
633639
634640 transport -> cannot_reuse = 1 ;
@@ -751,6 +757,24 @@ void transport_check_allowed(const char *type)
751757 die ("transport '%s' not allowed" , type );
752758}
753759
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+
754778struct transport * transport_get (struct remote * remote , const char * url )
755779{
756780 const char * helper ;
@@ -787,9 +811,7 @@ struct transport *transport_get(struct remote *remote, const char *url)
787811 struct bundle_transport_data * data = xcalloc (1 , sizeof (* data ));
788812 transport_check_allowed ("file" );
789813 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 ;
793815 ret -> smart_options = NULL ;
794816 } else if (!is_url (url )
795817 || starts_with (url , "file://" )
@@ -804,12 +826,7 @@ struct transport *transport_get(struct remote *remote, const char *url)
804826 */
805827 struct git_transport_data * data = xcalloc (1 , sizeof (* data ));
806828 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 ;
813830 ret -> smart_options = & (data -> options );
814831
815832 data -> conn = NULL ;
@@ -843,9 +860,9 @@ int transport_set_option(struct transport *transport,
843860 git_reports = set_git_option (transport -> smart_options ,
844861 name , value );
845862
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 );
849866
850867 /* If either report is 0, report 0 (success). */
851868 if (!git_reports || !protocol_reports )
@@ -968,7 +985,7 @@ int transport_push(struct transport *transport,
968985 * reject_reasons = 0 ;
969986 transport_verify_remote_names (refspec_nr , refspec );
970987
971- if (transport -> push_refs ) {
988+ if (transport -> vtable -> push_refs ) {
972989 struct ref * remote_refs ;
973990 struct ref * local_refs = get_local_heads ();
974991 int match_flags = MATCH_REFS_NONE ;
@@ -981,7 +998,7 @@ int transport_push(struct transport *transport,
981998 if (check_push_refs (local_refs , refspec_nr , refspec ) < 0 )
982999 return -1 ;
9831000
984- remote_refs = transport -> get_refs_list (transport , 1 );
1001+ remote_refs = transport -> vtable -> get_refs_list (transport , 1 );
9851002
9861003 if (flags & TRANSPORT_PUSH_ALL )
9871004 match_flags |= MATCH_REFS_ALL ;
@@ -1056,7 +1073,7 @@ int transport_push(struct transport *transport,
10561073 }
10571074
10581075 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 );
10601077 else
10611078 push_ret = 0 ;
10621079 err = push_had_errors (remote_refs );
@@ -1090,7 +1107,7 @@ int transport_push(struct transport *transport,
10901107const struct ref * transport_get_remote_refs (struct transport * transport )
10911108{
10921109 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 );
10941111 transport -> got_remote_refs = 1 ;
10951112 }
10961113
@@ -1127,7 +1144,7 @@ int transport_fetch_refs(struct transport *transport, struct ref *refs)
11271144 heads [nr_heads ++ ] = rm ;
11281145 }
11291146
1130- rc = transport -> fetch (transport , nr_heads , heads );
1147+ rc = transport -> vtable -> fetch (transport , nr_heads , heads );
11311148
11321149 free (heads );
11331150 return rc ;
@@ -1144,17 +1161,17 @@ void transport_unlock_pack(struct transport *transport)
11441161int transport_connect (struct transport * transport , const char * name ,
11451162 const char * exec , int fd [2 ])
11461163{
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 );
11491166 else
11501167 die ("Operation not supported by protocol" );
11511168}
11521169
11531170int transport_disconnect (struct transport * transport )
11541171{
11551172 int ret = 0 ;
1156- if (transport -> disconnect )
1157- ret = transport -> disconnect (transport );
1173+ if (transport -> vtable -> disconnect )
1174+ ret = transport -> vtable -> disconnect (transport );
11581175 free (transport );
11591176 return ret ;
11601177}
0 commit comments