@matheusbsbs / matheus-bagliano / commits / 37a8768f83
Fork 0

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 <spearce@spearce.org> CC: Daniel Barkalow <barkalow@iabervon.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Shawn O. Pearce committed Oct 30, 2009 at 17:47 UTC 37a8768f83d5932ca66202f9cc4977c20b022e17
1 file changed +14 -10
remote-curl.c
+14 -10
@@ -5,7 +5,17 @@
5 #include "http.h"
6 #include "exec_cmd.h"
7
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)
19 {
20 struct strbuf buffer = STRBUF_INIT;
21 char *data, *start, *mid;
@@ -21,6 +31,7 @@ static struct ref *get_refs(struct walker *walker, const char *url)
31 refs_url = xmalloc(strlen(url) + 11);
32 sprintf(refs_url, "%s/info/refs", url);
33
34 + init_walker();
35 http_ret = http_get_strbuf(refs_url, &buffer, HTTP_NO_CACHE);
36 switch (http_ret) {
37 case HTTP_OK:
@@ -78,10 +89,7 @@ static struct ref *get_refs(struct walker *walker, const char *url)
89
90 int main(int argc, const char **argv)
91 {
81 - struct remote *remote;
92 struct strbuf buf = STRBUF_INIT;
83 - const char *url;
84 - struct walker *walker = NULL;
93
94 git_extract_argv0_path(argv[0]);
95 setup_git_directory();
@@ -103,8 +111,7 @@ int main(int argc, const char **argv)
111 break;
112 if (!prefixcmp(buf.buf, "fetch ")) {
113 char *obj = buf.buf + strlen("fetch ");
106 - if (!walker)
107 - walker = get_http_walker(url, remote);
114 + init_walker();
115 walker->get_all = 1;
116 walker->get_tree = 1;
117 walker->get_history = 1;
@@ -115,11 +122,8 @@ int main(int argc, const char **argv)
122 printf("\n");
123 fflush(stdout);
124 } else if (!strcmp(buf.buf, "list")) {
118 - struct ref *refs;
125 + struct ref *refs = get_refs();
126 struct ref *posn;
120 - if (!walker)
121 - walker = get_http_walker(url, remote);
122 - refs = get_refs(walker, url);
127 for (posn = refs; posn; posn = posn->next) {
128 if (posn->symref)
129 printf("@%s %s\n", posn->symref, posn->name);