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>
This commit is contained in:
Shawn O. Pearce 2009-10-30 17:47:26 -07:00 committed by Junio C Hamano
parent 78affc49de
commit 37a8768f83

View File

@ -5,7 +5,17 @@
#include "http.h" #include "http.h"
#include "exec_cmd.h" #include "exec_cmd.h"
static struct ref *get_refs(struct walker *walker, const char *url) static struct remote *remote;
static const char *url;
static struct walker *walker;
static void init_walker(void)
{
if (!walker)
walker = get_http_walker(url, remote);
}
static struct ref *get_refs(void)
{ {
struct strbuf buffer = STRBUF_INIT; struct strbuf buffer = STRBUF_INIT;
char *data, *start, *mid; char *data, *start, *mid;
@ -21,6 +31,7 @@ static struct ref *get_refs(struct walker *walker, const char *url)
refs_url = xmalloc(strlen(url) + 11); refs_url = xmalloc(strlen(url) + 11);
sprintf(refs_url, "%s/info/refs", url); sprintf(refs_url, "%s/info/refs", url);
init_walker();
http_ret = http_get_strbuf(refs_url, &buffer, HTTP_NO_CACHE); http_ret = http_get_strbuf(refs_url, &buffer, HTTP_NO_CACHE);
switch (http_ret) { switch (http_ret) {
case HTTP_OK: case HTTP_OK:
@ -78,10 +89,7 @@ static struct ref *get_refs(struct walker *walker, const char *url)
int main(int argc, const char **argv) int main(int argc, const char **argv)
{ {
struct remote *remote;
struct strbuf buf = STRBUF_INIT; struct strbuf buf = STRBUF_INIT;
const char *url;
struct walker *walker = NULL;
git_extract_argv0_path(argv[0]); git_extract_argv0_path(argv[0]);
setup_git_directory(); setup_git_directory();
@ -103,8 +111,7 @@ int main(int argc, const char **argv)
break; break;
if (!prefixcmp(buf.buf, "fetch ")) { if (!prefixcmp(buf.buf, "fetch ")) {
char *obj = buf.buf + strlen("fetch "); char *obj = buf.buf + strlen("fetch ");
if (!walker) init_walker();
walker = get_http_walker(url, remote);
walker->get_all = 1; walker->get_all = 1;
walker->get_tree = 1; walker->get_tree = 1;
walker->get_history = 1; walker->get_history = 1;
@ -115,11 +122,8 @@ int main(int argc, const char **argv)
printf("\n"); printf("\n");
fflush(stdout); fflush(stdout);
} else if (!strcmp(buf.buf, "list")) { } else if (!strcmp(buf.buf, "list")) {
struct ref *refs; struct ref *refs = get_refs();
struct ref *posn; struct ref *posn;
if (!walker)
walker = get_http_walker(url, remote);
refs = get_refs(walker, url);
for (posn = refs; posn; posn = posn->next) { for (posn = refs; posn; posn = posn->next) {
if (posn->symref) if (posn->symref)
printf("@%s %s\n", posn->symref, posn->name); printf("@%s %s\n", posn->symref, posn->name);