8 static struct remote *remote;
9 static const char *url;
10 static struct walker *walker;
12 static void init_walker(void)
15 walker = get_http_walker(url, remote);
18 static struct ref *get_refs(void)
20 struct strbuf buffer = STRBUF_INIT;
21 char *data, *start, *mid;
27 struct ref *refs = NULL;
28 struct ref *ref = NULL;
29 struct ref *last_ref = NULL;
31 refs_url = xmalloc(strlen(url) + 11);
32 sprintf(refs_url, "%s/info/refs", url);
35 http_ret = http_get_strbuf(refs_url, &buffer, HTTP_NO_CACHE);
39 case HTTP_MISSING_TARGET:
40 die("%s not found: did you run git update-server-info on the"
41 " server?", refs_url);
43 http_error(refs_url, http_ret);
44 die("HTTP request failed");
50 while (i < buffer.len) {
56 if (data[i] == '\n') {
59 ref = xmalloc(sizeof(struct ref) +
60 strlen(ref_name) + 1);
61 memset(ref, 0, sizeof(struct ref));
62 strcpy(ref->name, ref_name);
63 get_sha1_hex(start, ref->old_sha1);
74 strbuf_release(&buffer);
76 ref = alloc_ref("HEAD");
77 if (!walker->fetch_ref(walker, ref) &&
78 !resolve_remote_symref(ref, refs)) {
85 strbuf_release(&buffer);
90 int main(int argc, const char **argv)
92 struct strbuf buf = STRBUF_INIT;
94 git_extract_argv0_path(argv[0]);
95 setup_git_directory();
97 fprintf(stderr, "Remote needed\n");
101 remote = remote_get(argv[1]);
106 url = remote->url[0];
110 if (strbuf_getline(&buf, stdin, '\n') == EOF)
112 if (!prefixcmp(buf.buf, "fetch ")) {
113 char *obj = buf.buf + strlen("fetch ");
116 walker->get_tree = 1;
117 walker->get_history = 1;
118 walker->get_verbosely = 0;
119 walker->get_recover = 0;
120 if (walker_fetch(walker, 1, &obj, NULL, NULL))
121 die("Fetch failed.");
124 } else if (!strcmp(buf.buf, "list")) {
125 struct ref *refs = get_refs();
127 for (posn = refs; posn; posn = posn->next) {
129 printf("@%s %s\n", posn->symref, posn->name);
131 printf("%s %s\n", sha1_to_hex(posn->old_sha1), posn->name);
135 } else if (!strcmp(buf.buf, "capabilities")) {