8 static struct ref *get_refs(struct walker *walker, const char *url)
10 struct strbuf buffer = STRBUF_INIT;
11 char *data, *start, *mid;
17 struct ref *refs = NULL;
18 struct ref *ref = NULL;
19 struct ref *last_ref = NULL;
21 refs_url = xmalloc(strlen(url) + 11);
22 sprintf(refs_url, "%s/info/refs", url);
24 http_ret = http_get_strbuf(refs_url, &buffer, HTTP_NO_CACHE);
28 case HTTP_MISSING_TARGET:
29 die("%s not found: did you run git update-server-info on the"
30 " server?", refs_url);
32 http_error(refs_url, http_ret);
33 die("HTTP request failed");
39 while (i < buffer.len) {
45 if (data[i] == '\n') {
48 ref = xmalloc(sizeof(struct ref) +
49 strlen(ref_name) + 1);
50 memset(ref, 0, sizeof(struct ref));
51 strcpy(ref->name, ref_name);
52 get_sha1_hex(start, ref->old_sha1);
63 strbuf_release(&buffer);
65 ref = alloc_ref("HEAD");
66 if (!walker->fetch_ref(walker, ref) &&
67 !resolve_remote_symref(ref, refs)) {
74 strbuf_release(&buffer);
79 int main(int argc, const char **argv)
81 struct remote *remote;
82 struct strbuf buf = STRBUF_INIT;
84 struct walker *walker = NULL;
87 git_extract_argv0_path(argv[0]);
88 setup_git_directory_gently(&nongit);
90 fprintf(stderr, "Remote needed\n");
94 remote = remote_get(argv[1]);
103 if (strbuf_getline(&buf, stdin, '\n') == EOF)
105 if (!prefixcmp(buf.buf, "fetch ")) {
106 char *obj = buf.buf + strlen("fetch ");
108 die("Fetch attempted without a local repo");
110 walker = get_http_walker(url, remote);
112 walker->get_tree = 1;
113 walker->get_history = 1;
114 walker->get_verbosely = 0;
115 walker->get_recover = 0;
116 if (walker_fetch(walker, 1, &obj, NULL, NULL))
117 die("Fetch failed.");
120 } else if (!strcmp(buf.buf, "list")) {
124 walker = get_http_walker(url, remote);
125 refs = get_refs(walker, url);
126 for (posn = refs; posn; posn = posn->next) {
128 printf("@%s %s\n", posn->symref, posn->name);
130 printf("%s %s\n", sha1_to_hex(posn->old_sha1), posn->name);
134 } else if (!strcmp(buf.buf, "capabilities")) {