Skip to content

Commit 26e1e0b

Browse files
rctaygitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent aec4975 commit 26e1e0b

File tree

1 file changed

+3
-10
lines changed

1 file changed

+3
-10
lines changed

remote-curl.c

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
static struct remote *remote;
1212
static const char *url;
13-
static struct walker *walker;
1413

1514
struct options {
1615
int verbosity;
@@ -22,12 +21,6 @@ struct options {
2221
};
2322
static struct options options;
2423

25-
static void init_walker(void)
26-
{
27-
if (!walker)
28-
walker = get_http_walker(url);
29-
}
30-
3124
static int set_option(const char *name, const char *value)
3225
{
3326
if (!strcmp(name, "verbosity")) {
@@ -119,7 +112,6 @@ static struct discovery* discover_refs(const char *service)
119112
}
120113
refs_url = strbuf_detach(&buffer, NULL);
121114

122-
init_walker();
123115
http_ret = http_get_strbuf(refs_url, &buffer, HTTP_NO_CACHE);
124116

125117
/* try again with "plain" url (no ? or & appended) */
@@ -500,7 +492,6 @@ static int rpc_service(struct rpc_state *rpc, struct discovery *heads)
500492
struct child_process client;
501493
int err = 0;
502494

503-
init_walker();
504495
memset(&client, 0, sizeof(client));
505496
client.in = -1;
506497
client.out = -1;
@@ -552,6 +543,7 @@ static int rpc_service(struct rpc_state *rpc, struct discovery *heads)
552543

553544
static int fetch_dumb(int nr_heads, struct ref **to_fetch)
554545
{
546+
struct walker *walker;
555547
char **targets = xmalloc(nr_heads * sizeof(char*));
556548
int ret, i;
557549

@@ -560,13 +552,14 @@ static int fetch_dumb(int nr_heads, struct ref **to_fetch)
560552
for (i = 0; i < nr_heads; i++)
561553
targets[i] = xstrdup(sha1_to_hex(to_fetch[i]->old_sha1));
562554

563-
init_walker();
555+
walker = get_http_walker(url);
564556
walker->get_all = 1;
565557
walker->get_tree = 1;
566558
walker->get_history = 1;
567559
walker->get_verbosely = options.verbosity >= 3;
568560
walker->get_recover = 0;
569561
ret = walker_fetch(walker, nr_heads, targets, NULL, NULL);
562+
walker_free(walker);
570563

571564
for (i = 0; i < nr_heads; i++)
572565
free(targets[i]);

0 commit comments

Comments
 (0)