Refactor struct transport_ops inlined into struct transport
PATCH 2/5 Refactor struct transport_ops inlined into struct transport
Aside from reducing the code by 20 lines this refactoring removes a level of indirection when trying to access the operations of a given transport "instance", making the code clearer and easier to follow.
It also has the nice effect of giving us the benefits of C99 style struct initialization (namely ".fetch = X") without requiring that level of language support from our compiler. We don't need to worry about new operation methods being added as they will now be NULL'd out automatically by the xcalloc() we use to create the new struct transport we supply to the caller.
This pattern already exists in struct walker, so we already have a precedent for it in Git. We also don't really need to worry about any sort of performance decreases that may occur as a result of filling out 4-8 op pointers when we make a "struct transport". The extra few CPU cycles this requires over filling in the "struct transport_ops" is killed by the time it will take Git to actually *use* one of those functions, as most transport operations are going over the wire or will be copying object data locally between two directories.
--- builtin-fetch.c | 3 +- transport.c | 62 +++++++++++++++++++++--------------------------------- transport.h | 16 ++++--------- 3 files changed, 30 insertions(+), 51 deletions(-)
builtin-fetch.c +1 -2
@@ -392,8 +392,7 @@ static int do_fetch(struct transport *transport,if (transport->remote->fetch_tags ==-1 ) no_tags =1 ; -if (!transport->ops || !transport->ops->get_refs_list || - !transport->ops->fetch) +if (!transport->get_refs_list || !transport->fetch)die ("Don't know how to fetch from %s" , transport->url);/* if not appending, truncate FETCH_HEAD */
transport.c +24 -38
137 lines not on this page · raw message
transport.h +5 -11
@@ -5,22 +5,11 @@#include "remote.h" struct transport { -unsigned verbose :1 ;struct remote *remote;const char *url; -void *data; -struct ref *remote_refs; -const struct transport_ops *ops; -char *pack_lockfile; -}; - -#define TRANSPORT_PUSH_ALL 1 -#define TRANSPORT_PUSH_FORCE 2 - -struct transport_ops {/** * Returns 0 if successful, positive if the option is not * recognized or is inapplicable, and negative if the option
@@ -34,8 +23,13 @@ struct transport_ops {int (*push)(struct transport *connection,int refspec_nr,const char **refspec,int flags);int (*disconnect)(struct transport *connection); +char *pack_lockfile; + unsigned verbose : 1; }; +#define TRANSPORT_PUSH_ALL 1 +#define TRANSPORT_PUSH_FORCE 2 +/* Returns a transport suitable for the url */ struct transport *transport_get (struct remote *,const char *);
Signature · 1 line
1.5.3.1.195.gadd6
Hi,
Quoted 14 lines · Shawn O. Pearce
transport.c +0
-2@@ -44,8 +44,6 @@ static int disconnect_walker(struct transport *transport)return 0 ; } -static const struct transport_ops rsync_transport; -static int curl_transport_push (struct transport *transport,int refspec_nr,const char **refspec,int flags) {const char **argv;int argc;
transport.c struct transport *transport_get(struct remote *remote, const char *url) · line 410
Quoted 6 lines
transport.c +2
-1@@ -431,18 +406,31 @@ struct transport *transport_get(struct remote *remote, const char *url) ret->url = url;if (!prefixcmp (url,"rsync://" )) { - ret->ops = &rsync_transport; +/* not supported; don't populate any ops */ +
That is sneaky. What are the reasons to remove rsync support? I know it is deprecated, but I'd still like to have it, especially for initial clones on small-RAMed machines.
Ciao,
Dscho
Quoted 20 lines · Johannes Schindelin
Hi,
Quoted 16 lines · Shawn O. Pearce
transport.c +0
-2@@ -44,8 +44,6 @@ static int disconnect_walker(struct transport *transport)return 0 ; } -static const struct transport_ops rsync_transport; -static int curl_transport_push (struct transport *transport,int refspec_nr,const char **refspec,int flags) {const char **argv;int argc;@@ -431,18 +406,31 @@ struct transport *transport_get(struct remote *remote, const char *url) ret->url = url;
Quoted 8 lines
transport.c struct transport *transport_get(struct remote *remote, const char *url) · line 410
Quoted 4 lines
transport.c +2
-1if (!prefixcmp (url,"rsync://" )) { - ret->ops = &rsync_transport; +/* not supported; don't populate any ops */ +That is sneaky. What are the reasons to remove rsync support? I know it is deprecated, but I'd still like to have it, especially for initial clones on small-RAMed machines.
It never got implemented in a way called from C. This is just removing the pointer to the empty struct where support would go. If anybody knows enough about interfacing with rsync to write the necessary functions, it can be restored.
-Daniel
*This .sig left intentionally blank*
Hi,
Quoted 29 lines · Daniel Barkalow
Quoted 18 lines · Johannes Schindelin
Quoted 16 lines · Shawn O. Pearce
transport.c +0
-2@@ -44,8 +44,6 @@ static int disconnect_walker(struct transport *transport)return 0 ; } -static const struct transport_ops rsync_transport; -static int curl_transport_push (struct transport *transport,int refspec_nr,const char **refspec,int flags) {const char **argv;int argc;@@ -431,18 +406,31 @@ struct transport *transport_get(struct remote *remote, const char *url) ret->url = url;Quoted 8 lines
transport.c struct transport *transport_get(struct remote *remote, const char *url) · line 410
Quoted 4 lines
transport.c +2
-1if (!prefixcmp (url,"rsync://" )) { - ret->ops = &rsync_transport; +/* not supported; don't populate any ops */ +That is sneaky. What are the reasons to remove rsync support? I know it is deprecated, but I'd still like to have it, especially for initial clones on small-RAMed machines.
Quoted 4 lines
It never got implemented in a way called from C. This is just removing the pointer to the empty struct where support would go. If anybody knows enough about interfacing with rsync to write the necessary functions, it can be restored.
Okay, will do once I find the time.
Ciao,
Dscho