Skip to content

Commit 37a8768

Browse files
spearcegitster
authored andcommitted
remote-curl: Refactor walker initialization
We will need the walker, url and remote in other functions as the code grows larger to support smart HTTP. Extract this out into a set of globals we can easily reference once configured. Signed-off-by: Shawn O. Pearce <[email protected]> CC: Daniel Barkalow <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 78affc4 commit 37a8768

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

remote-curl.c

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,17 @@
55
#include "http.h"
66
#include "exec_cmd.h"
77

8-
static struct ref *get_refs(struct walker *walker, const char *url)
8+
static struct remote *remote;
9+
static const char *url;
10+
static struct walker *walker;
11+
12+
static void init_walker(void)
13+
{
14+
if (!walker)
15+
walker = get_http_walker(url, remote);
16+
}
17+
18+
static struct ref *get_refs(void)
919
{
1020
struct strbuf buffer = STRBUF_INIT;
1121
char *data, *start, *mid;
@@ -21,6 +31,7 @@ static struct ref *get_refs(struct walker *walker, const char *url)
2131
refs_url = xmalloc(strlen(url) + 11);
2232
sprintf(refs_url, "%s/info/refs", url);
2333

34+
init_walker();
2435
http_ret = http_get_strbuf(refs_url, &buffer, HTTP_NO_CACHE);
2536
switch (http_ret) {
2637
case HTTP_OK:
@@ -78,10 +89,7 @@ static struct ref *get_refs(struct walker *walker, const char *url)
7889

7990
int main(int argc, const char **argv)
8091
{
81-
struct remote *remote;
8292
struct strbuf buf = STRBUF_INIT;
83-
const char *url;
84-
struct walker *walker = NULL;
8593

8694
git_extract_argv0_path(argv[0]);
8795
setup_git_directory();
@@ -103,8 +111,7 @@ int main(int argc, const char **argv)
103111
break;
104112
if (!prefixcmp(buf.buf, "fetch ")) {
105113
char *obj = buf.buf + strlen("fetch ");
106-
if (!walker)
107-
walker = get_http_walker(url, remote);
114+
init_walker();
108115
walker->get_all = 1;
109116
walker->get_tree = 1;
110117
walker->get_history = 1;
@@ -115,11 +122,8 @@ int main(int argc, const char **argv)
115122
printf("\n");
116123
fflush(stdout);
117124
} else if (!strcmp(buf.buf, "list")) {
118-
struct ref *refs;
125+
struct ref *refs = get_refs();
119126
struct ref *posn;
120-
if (!walker)
121-
walker = get_http_walker(url, remote);
122-
refs = get_refs(walker, url);
123127
for (posn = refs; posn; posn = posn->next) {
124128
if (posn->symref)
125129
printf("@%s %s\n", posn->symref, posn->name);

0 commit comments

Comments
 (0)