@matheusbsbs / matheus-bagliano / commits / e5f4e21463
Fork 0

Remove unnecessary 'fetch' argument from transport_get API

We don't actually need to know at the time of transport_get if the caller wants to fetch, push, or do both on the returned object. It is easier to just delay the initialization of the HTTP walker until we know we will need it by providing a CURL specific fetch function in the curl_transport that makes sure the walker instance is initialized before use. Signed-off-by: Shawn O. Pearce <spearce@spearce.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Shawn O. Pearce committed Sep 15, 2007 at 03:23 UTC e5f4e214636f9c9bd36c2897634108d5ad5587a1
4 files changed +20 -11
builtin-fetch.c
+1 -1
@@ -496,7 +496,7 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
496 else
497 remote = remote_get(argv[i++]);
498
499 - transport = transport_get(remote, remote->uri[0], 1);
499 + transport = transport_get(remote, remote->uri[0]);
500 if (verbose >= 2)
501 transport->verbose = 1;
502 if (quiet)
builtin-push.c
+1 -1
@@ -59,7 +59,7 @@ static int do_push(const char *repo, int flags)
59 errs = 0;
60 for (i = 0; i < remote->uri_nr; i++) {
61 struct transport *transport =
62 - transport_get(remote, remote->uri[i], 0);
62 + transport_get(remote, remote->uri[i]);
63 int err;
64 if (receivepack)
65 transport_set_option(transport,
transport.c
+17 -6
@@ -174,6 +174,14 @@ static struct ref *get_refs_via_curl(const struct transport *transport)
174 return refs;
175 }
176
177 +static int fetch_objs_via_curl(struct transport *transport,
178 + int nr_objs, struct ref **to_fetch)
179 +{
180 + if (!transport->data)
181 + transport->data = get_http_walker(transport->url);
182 + return fetch_objs_via_walker(transport, nr_objs, to_fetch);
183 +}
184 +
185 #else
186
187 static struct ref *get_refs_via_curl(const struct transport *transport)
@@ -182,12 +190,19 @@ static struct ref *get_refs_via_curl(const struct transport *transport)
190 return NULL;
191 }
192
193 +static int fetch_objs_via_curl(struct transport *transport,
194 + int nr_objs, struct ref **to_fetch)
195 +{
196 + die("Cannot fetch from '%s' without curl ...", transport->url);
197 + return -1;
198 +}
199 +
200 #endif
201
202 static const struct transport_ops curl_transport = {
203 /* set_option */ NULL,
204 /* get_refs_list */ get_refs_via_curl,
190 - /* fetch */ fetch_objs_via_walker,
205 + /* fetch */ fetch_objs_via_curl,
206 /* push */ curl_transport_push,
207 /* disconnect */ disconnect_walker
208 };
@@ -408,14 +423,12 @@ static int is_file(const char *url)
423 return S_ISREG(buf.st_mode);
424 }
425
411 -struct transport *transport_get(struct remote *remote, const char *url,
412 - int fetch)
426 +struct transport *transport_get(struct remote *remote, const char *url)
427 {
428 struct transport *ret = xcalloc(1, sizeof(*ret));
429
430 ret->remote = remote;
431 ret->url = url;
418 - ret->fetch = !!fetch;
432
433 if (!prefixcmp(url, "rsync://")) {
434 ret->ops = &rsync_transport;
@@ -423,8 +436,6 @@ struct transport *transport_get(struct remote *remote, const char *url,
436 || !prefixcmp(url, "https://")
437 || !prefixcmp(url, "ftp://")) {
438 ret->ops = &curl_transport;
426 - if (fetch)
427 - ret->data = get_http_walker(url);
439 } else if (is_local(url) && is_file(url)) {
440 struct bundle_transport_data *data = xcalloc(1, sizeof(*data));
441 ret->data = data;
transport.h
+1 -3
@@ -6,7 +6,6 @@
6
7 struct transport {
8 unsigned verbose : 1;
9 - unsigned fetch : 1;
9 struct remote *remote;
10 const char *url;
11
@@ -38,8 +37,7 @@ struct transport_ops {
37 };
38
39 /* Returns a transport suitable for the url */
41 -struct transport *transport_get(struct remote *remote, const char *url,
42 - int fetch);
40 +struct transport *transport_get(struct remote *, const char *);
41
42 /* Transport options which apply to git:// and scp-style URLs */
43