Skip to content

Commit

Permalink
Remove unnecessary 'fetch' argument from transport_get API
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Shawn O. Pearce authored and Junio C Hamano committed Sep 19, 2007
1 parent be6042c commit e5f4e21
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 11 deletions.
2 changes: 1 addition & 1 deletion builtin-fetch.c
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
else
remote = remote_get(argv[i++]);

transport = transport_get(remote, remote->uri[0], 1);
transport = transport_get(remote, remote->uri[0]);
if (verbose >= 2)
transport->verbose = 1;
if (quiet)
Expand Down
2 changes: 1 addition & 1 deletion builtin-push.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ static int do_push(const char *repo, int flags)
errs = 0;
for (i = 0; i < remote->uri_nr; i++) {
struct transport *transport =
transport_get(remote, remote->uri[i], 0);
transport_get(remote, remote->uri[i]);
int err;
if (receivepack)
transport_set_option(transport,
Expand Down
23 changes: 17 additions & 6 deletions transport.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,14 @@ static struct ref *get_refs_via_curl(const struct transport *transport)
return refs;
}

static int fetch_objs_via_curl(struct transport *transport,
int nr_objs, struct ref **to_fetch)
{
if (!transport->data)
transport->data = get_http_walker(transport->url);
return fetch_objs_via_walker(transport, nr_objs, to_fetch);
}

#else

static struct ref *get_refs_via_curl(const struct transport *transport)
Expand All @@ -182,12 +190,19 @@ static struct ref *get_refs_via_curl(const struct transport *transport)
return NULL;
}

static int fetch_objs_via_curl(struct transport *transport,
int nr_objs, struct ref **to_fetch)
{
die("Cannot fetch from '%s' without curl ...", transport->url);
return -1;
}

#endif

static const struct transport_ops curl_transport = {
/* set_option */ NULL,
/* get_refs_list */ get_refs_via_curl,
/* fetch */ fetch_objs_via_walker,
/* fetch */ fetch_objs_via_curl,
/* push */ curl_transport_push,
/* disconnect */ disconnect_walker
};
Expand Down Expand Up @@ -408,23 +423,19 @@ static int is_file(const char *url)
return S_ISREG(buf.st_mode);
}

struct transport *transport_get(struct remote *remote, const char *url,
int fetch)
struct transport *transport_get(struct remote *remote, const char *url)
{
struct transport *ret = xcalloc(1, sizeof(*ret));

ret->remote = remote;
ret->url = url;
ret->fetch = !!fetch;

if (!prefixcmp(url, "rsync://")) {
ret->ops = &rsync_transport;
} else if (!prefixcmp(url, "http://")
|| !prefixcmp(url, "https://")
|| !prefixcmp(url, "ftp://")) {
ret->ops = &curl_transport;
if (fetch)
ret->data = get_http_walker(url);
} else if (is_local(url) && is_file(url)) {
struct bundle_transport_data *data = xcalloc(1, sizeof(*data));
ret->data = data;
Expand Down
4 changes: 1 addition & 3 deletions transport.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

struct transport {
unsigned verbose : 1;
unsigned fetch : 1;
struct remote *remote;
const char *url;

Expand Down Expand Up @@ -38,8 +37,7 @@ struct transport_ops {
};

/* Returns a transport suitable for the url */
struct transport *transport_get(struct remote *remote, const char *url,
int fetch);
struct transport *transport_get(struct remote *, const char *);

/* Transport options which apply to git:// and scp-style URLs */

Expand Down

0 comments on commit e5f4e21

Please sign in to comment.