From 888692b733b3109874bb570bb0680e93287ed338 Mon Sep 17 00:00:00 2001 From: Tay Ray Chuan Date: Tue, 2 Mar 2010 18:49:29 +0800 Subject: http: init and cleanup separately from http-walker Previously, all our http operations were done with http-walker. With the new remote-curl helper, we find ourselves using http methods outside of http-walker - for example, fetching info/refs. Accomodate this by separating http_init() and http_cleanup() invocations from http-walker. Signed-off-by: Tay Ray Chuan Signed-off-by: Junio C Hamano --- remote-curl.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'remote-curl.c') diff --git a/remote-curl.c b/remote-curl.c index a904164e4..e8485d155 100644 --- a/remote-curl.c +++ b/remote-curl.c @@ -25,7 +25,7 @@ static struct options options; static void init_walker(void) { if (!walker) - walker = get_http_walker(url, remote); + walker = get_http_walker(url); } static int set_option(const char *name, const char *value) @@ -810,6 +810,8 @@ int main(int argc, const char **argv) url = remote->url[0]; } + http_init(remote); + do { if (strbuf_getline(&buf, stdin, '\n') == EOF) break; @@ -855,5 +857,8 @@ int main(int argc, const char **argv) } strbuf_reset(&buf); } while (1); + + http_cleanup(); + return 0; } -- cgit v1.2.1 From aec49756020d20bd073e4daeaa5d7b4fed1fe300 Mon Sep 17 00:00:00 2001 From: Tay Ray Chuan Date: Tue, 2 Mar 2010 18:49:30 +0800 Subject: remote-curl: use http_fetch_ref() instead of walker wrapper The http-walker implementation of walker->fetch_ref() doesn't do anything special compared to http_fetch_ref() anyway. Remove init_walker() invocation before fetching the ref, since we aren't using the walker wrapper and don't need a walker instance anymore. Signed-off-by: Tay Ray Chuan Signed-off-by: Junio C Hamano --- remote-curl.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'remote-curl.c') diff --git a/remote-curl.c b/remote-curl.c index e8485d155..aa9f27901 100644 --- a/remote-curl.c +++ b/remote-curl.c @@ -249,9 +249,8 @@ static struct ref *parse_info_refs(struct discovery *heads) i++; } - init_walker(); ref = alloc_ref("HEAD"); - if (!walker->fetch_ref(walker, ref) && + if (!http_fetch_ref(url, ref) && !resolve_remote_symref(ref, refs)) { ref->next = refs; refs = ref; -- cgit v1.2.1 From 26e1e0b23a1d145f9fee699538c11bbbb996d558 Mon Sep 17 00:00:00 2001 From: Tay Ray Chuan Date: Tue, 2 Mar 2010 18:49:31 +0800 Subject: remote-curl: init walker only when needed Invoke get_http_walker() only when fetching with the dumb protocol. Additionally, add an invocation to walker_free() after we're done using the walker. Signed-off-by: Tay Ray Chuan Signed-off-by: Junio C Hamano --- remote-curl.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) (limited to 'remote-curl.c') diff --git a/remote-curl.c b/remote-curl.c index aa9f27901..1f8bc2db7 100644 --- a/remote-curl.c +++ b/remote-curl.c @@ -10,7 +10,6 @@ static struct remote *remote; static const char *url; -static struct walker *walker; struct options { int verbosity; @@ -22,12 +21,6 @@ struct options { }; static struct options options; -static void init_walker(void) -{ - if (!walker) - walker = get_http_walker(url); -} - static int set_option(const char *name, const char *value) { if (!strcmp(name, "verbosity")) { @@ -119,7 +112,6 @@ static struct discovery* discover_refs(const char *service) } refs_url = strbuf_detach(&buffer, NULL); - init_walker(); http_ret = http_get_strbuf(refs_url, &buffer, HTTP_NO_CACHE); /* try again with "plain" url (no ? or & appended) */ @@ -500,7 +492,6 @@ static int rpc_service(struct rpc_state *rpc, struct discovery *heads) struct child_process client; int err = 0; - init_walker(); memset(&client, 0, sizeof(client)); client.in = -1; client.out = -1; @@ -552,6 +543,7 @@ static int rpc_service(struct rpc_state *rpc, struct discovery *heads) static int fetch_dumb(int nr_heads, struct ref **to_fetch) { + struct walker *walker; char **targets = xmalloc(nr_heads * sizeof(char*)); int ret, i; @@ -560,13 +552,14 @@ static int fetch_dumb(int nr_heads, struct ref **to_fetch) for (i = 0; i < nr_heads; i++) targets[i] = xstrdup(sha1_to_hex(to_fetch[i]->old_sha1)); - init_walker(); + walker = get_http_walker(url); walker->get_all = 1; walker->get_tree = 1; walker->get_history = 1; walker->get_verbosely = options.verbosity >= 3; walker->get_recover = 0; ret = walker_fetch(walker, nr_heads, targets, NULL, NULL); + walker_free(walker); for (i = 0; i < nr_heads; i++) free(targets[i]); -- cgit v1.2.1