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 static int fetch_dumb(int nr_heads
, struct ref
**to_fetch
)
92 char **targets
= xmalloc(nr_heads
* sizeof(char*));
95 for (i
= 0; i
< nr_heads
; i
++)
96 targets
[i
] = xstrdup(sha1_to_hex(to_fetch
[i
]->old_sha1
));
100 walker
->get_tree
= 1;
101 walker
->get_history
= 1;
102 walker
->get_verbosely
= 0;
103 walker
->get_recover
= 0;
104 ret
= walker_fetch(walker
, nr_heads
, targets
, NULL
, NULL
);
106 for (i
= 0; i
< nr_heads
; i
++)
110 return ret
? error("Fetch failed.") : 0;
113 static void parse_fetch(struct strbuf
*buf
)
115 struct ref
**to_fetch
= NULL
;
116 struct ref
*list_head
= NULL
;
117 struct ref
**list
= &list_head
;
118 int alloc_heads
= 0, nr_heads
= 0;
121 if (!prefixcmp(buf
->buf
, "fetch ")) {
122 char *p
= buf
->buf
+ strlen("fetch ");
125 unsigned char old_sha1
[20];
127 if (strlen(p
) < 40 || get_sha1_hex(p
, old_sha1
))
128 die("protocol error: expected sha/ref, got %s'", p
);
134 die("protocol error: expected sha/ref, got %s'", p
);
136 ref
= alloc_ref(name
);
137 hashcpy(ref
->old_sha1
, old_sha1
);
142 ALLOC_GROW(to_fetch
, nr_heads
+ 1, alloc_heads
);
143 to_fetch
[nr_heads
++] = ref
;
146 die("http transport does not support %s", buf
->buf
);
149 if (strbuf_getline(buf
, stdin
, '\n') == EOF
)
155 if (fetch_dumb(nr_heads
, to_fetch
))
156 exit(128); /* error already reported */
157 free_refs(list_head
);
165 int main(int argc
, const char **argv
)
167 struct strbuf buf
= STRBUF_INIT
;
169 git_extract_argv0_path(argv
[0]);
170 setup_git_directory();
172 fprintf(stderr
, "Remote needed\n");
176 remote
= remote_get(argv
[1]);
181 url
= remote
->url
[0];
185 if (strbuf_getline(&buf
, stdin
, '\n') == EOF
)
187 if (!prefixcmp(buf
.buf
, "fetch ")) {
190 } else if (!strcmp(buf
.buf
, "list")) {
191 struct ref
*refs
= get_refs();
193 for (posn
= refs
; posn
; posn
= posn
->next
) {
195 printf("@%s %s\n", posn
->symref
, posn
->name
);
197 printf("%s %s\n", sha1_to_hex(posn
->old_sha1
), posn
->name
);
201 } else if (!strcmp(buf
.buf
, "capabilities")) {