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
;
86 git_extract_argv0_path(argv
[0]);
87 setup_git_directory();
89 fprintf(stderr
, "Remote needed\n");
93 remote
= remote_get(argv
[1]);
102 if (strbuf_getline(&buf
, stdin
, '\n') == EOF
)
104 if (!prefixcmp(buf
.buf
, "fetch ")) {
105 char *obj
= buf
.buf
+ strlen("fetch ");
107 walker
= get_http_walker(url
, remote
);
109 walker
->get_tree
= 1;
110 walker
->get_history
= 1;
111 walker
->get_verbosely
= 0;
112 walker
->get_recover
= 0;
113 if (walker_fetch(walker
, 1, &obj
, NULL
, NULL
))
114 die("Fetch failed.");
117 } else if (!strcmp(buf
.buf
, "list")) {
121 walker
= get_http_walker(url
, remote
);
122 refs
= get_refs(walker
, url
);
123 for (posn
= refs
; posn
; posn
= posn
->next
) {
125 printf("@%s %s\n", posn
->symref
, posn
->name
);
127 printf("%s %s\n", sha1_to_hex(posn
->old_sha1
), posn
->name
);
131 } else if (!strcmp(buf
.buf
, "capabilities")) {