@matheusbsbs / matheus-bagliano / commits / 26e1e0b23a
Fork 0

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 <rctay89@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Tay Ray Chuan committed Mar 2, 2010 at 18:49 UTC 26e1e0b23a1d145f9fee699538c11bbbb996d558
1 file changed +3 -10
remote-curl.c
+3 -10
@@ -10,7 +10,6 @@
10
11 static struct remote *remote;
12 static const char *url;
13 -static struct walker *walker;
13
14 struct options {
15 int verbosity;
@@ -22,12 +21,6 @@ struct options {
21 };
22 static struct options options;
23
25 -static void init_walker(void)
26 -{
27 - if (!walker)
28 - walker = get_http_walker(url);
29 -}
30 -
24 static int set_option(const char *name, const char *value)
25 {
26 if (!strcmp(name, "verbosity")) {
@@ -119,7 +112,6 @@ static struct discovery* discover_refs(const char *service)
112 }
113 refs_url = strbuf_detach(&buffer, NULL);
114
122 - init_walker();
115 http_ret = http_get_strbuf(refs_url, &buffer, HTTP_NO_CACHE);
116
117 /* try again with "plain" url (no ? or & appended) */
@@ -500,7 +492,6 @@ static int rpc_service(struct rpc_state *rpc, struct discovery *heads)
492 struct child_process client;
493 int err = 0;
494
503 - init_walker();
495 memset(&client, 0, sizeof(client));
496 client.in = -1;
497 client.out = -1;
@@ -552,6 +543,7 @@ static int rpc_service(struct rpc_state *rpc, struct discovery *heads)
543
544 static int fetch_dumb(int nr_heads, struct ref **to_fetch)
545 {
546 + struct walker *walker;
547 char **targets = xmalloc(nr_heads * sizeof(char*));
548 int ret, i;
549
@@ -560,13 +552,14 @@ static int fetch_dumb(int nr_heads, struct ref **to_fetch)
552 for (i = 0; i < nr_heads; i++)
553 targets[i] = xstrdup(sha1_to_hex(to_fetch[i]->old_sha1));
554
563 - init_walker();
555 + walker = get_http_walker(url);
556 walker->get_all = 1;
557 walker->get_tree = 1;
558 walker->get_history = 1;
559 walker->get_verbosely = options.verbosity >= 3;
560 walker->get_recover = 0;
561 ret = walker_fetch(walker, nr_heads, targets, NULL, NULL);
562 + walker_free(walker);
563
564 for (i = 0; i < nr_heads; i++)
565 free(targets[i]);