]>
Commit | Line | Data |
---|---|---|
a2d725b7 DB |
1 | #include "cache.h" |
2 | #include "remote.h" | |
3 | #include "strbuf.h" | |
4 | #include "walker.h" | |
5 | #include "http.h" | |
d01a8e32 | 6 | #include "exec_cmd.h" |
ae4efe19 | 7 | #include "run-command.h" |
97cc7bc4 | 8 | #include "pkt-line.h" |
05c1eb10 | 9 | #include "string-list.h" |
de1a2fdd | 10 | #include "sideband.h" |
222b1212 | 11 | #include "argv-array.h" |
2501aff8 | 12 | #include "credential.h" |
16094885 | 13 | #include "sha1-array.h" |
30261094 | 14 | #include "send-pack.h" |
a2d725b7 | 15 | |
37a8768f | 16 | static struct remote *remote; |
b227bbc4 JK |
17 | /* always ends with a trailing slash */ |
18 | static struct strbuf url = STRBUF_INIT; | |
37a8768f | 19 | |
ef08ef9e SP |
20 | struct options { |
21 | int verbosity; | |
22 | unsigned long depth; | |
23 | unsigned progress : 1, | |
9ba38048 | 24 | check_self_contained_and_connected : 1, |
16094885 NTND |
25 | cloning : 1, |
26 | update_shallow : 1, | |
ae4efe19 | 27 | followtags : 1, |
de1a2fdd | 28 | dry_run : 1, |
0ea47f9d | 29 | thin : 1, |
30261094 DB |
30 | /* One of the SEND_PACK_PUSH_CERT_* constants. */ |
31 | push_cert : 2; | |
ef08ef9e SP |
32 | }; |
33 | static struct options options; | |
05c1eb10 | 34 | static struct string_list cas_options = STRING_LIST_INIT_DUP; |
ef08ef9e | 35 | |
ef08ef9e SP |
36 | static int set_option(const char *name, const char *value) |
37 | { | |
38 | if (!strcmp(name, "verbosity")) { | |
39 | char *end; | |
40 | int v = strtol(value, &end, 10); | |
41 | if (value == end || *end) | |
42 | return -1; | |
43 | options.verbosity = v; | |
44 | return 0; | |
45 | } | |
46 | else if (!strcmp(name, "progress")) { | |
47 | if (!strcmp(value, "true")) | |
48 | options.progress = 1; | |
49 | else if (!strcmp(value, "false")) | |
50 | options.progress = 0; | |
51 | else | |
52 | return -1; | |
249b2004 | 53 | return 0; |
ef08ef9e SP |
54 | } |
55 | else if (!strcmp(name, "depth")) { | |
56 | char *end; | |
57 | unsigned long v = strtoul(value, &end, 10); | |
58 | if (value == end || *end) | |
59 | return -1; | |
60 | options.depth = v; | |
249b2004 | 61 | return 0; |
ef08ef9e SP |
62 | } |
63 | else if (!strcmp(name, "followtags")) { | |
64 | if (!strcmp(value, "true")) | |
65 | options.followtags = 1; | |
66 | else if (!strcmp(value, "false")) | |
67 | options.followtags = 0; | |
68 | else | |
69 | return -1; | |
249b2004 | 70 | return 0; |
ef08ef9e | 71 | } |
ae4efe19 SP |
72 | else if (!strcmp(name, "dry-run")) { |
73 | if (!strcmp(value, "true")) | |
74 | options.dry_run = 1; | |
75 | else if (!strcmp(value, "false")) | |
76 | options.dry_run = 0; | |
77 | else | |
78 | return -1; | |
79 | return 0; | |
80 | } | |
9ba38048 NTND |
81 | else if (!strcmp(name, "check-connectivity")) { |
82 | if (!strcmp(value, "true")) | |
83 | options.check_self_contained_and_connected = 1; | |
84 | else if (!strcmp(value, "false")) | |
85 | options.check_self_contained_and_connected = 0; | |
86 | else | |
87 | return -1; | |
88 | return 0; | |
89 | } | |
05c1eb10 JH |
90 | else if (!strcmp(name, "cas")) { |
91 | struct strbuf val = STRBUF_INIT; | |
92 | strbuf_addf(&val, "--" CAS_OPT_NAME "=%s", value); | |
93 | string_list_append(&cas_options, val.buf); | |
94 | strbuf_release(&val); | |
95 | return 0; | |
16094885 NTND |
96 | } else if (!strcmp(name, "cloning")) { |
97 | if (!strcmp(value, "true")) | |
98 | options.cloning = 1; | |
99 | else if (!strcmp(value, "false")) | |
100 | options.cloning = 0; | |
101 | else | |
102 | return -1; | |
103 | return 0; | |
104 | } else if (!strcmp(name, "update-shallow")) { | |
105 | if (!strcmp(value, "true")) | |
106 | options.update_shallow = 1; | |
107 | else if (!strcmp(value, "false")) | |
108 | options.update_shallow = 0; | |
109 | else | |
110 | return -1; | |
111 | return 0; | |
0ea47f9d JH |
112 | } else if (!strcmp(name, "pushcert")) { |
113 | if (!strcmp(value, "true")) | |
30261094 | 114 | options.push_cert = SEND_PACK_PUSH_CERT_ALWAYS; |
0ea47f9d | 115 | else if (!strcmp(value, "false")) |
30261094 DB |
116 | options.push_cert = SEND_PACK_PUSH_CERT_NEVER; |
117 | else if (!strcmp(value, "if-asked")) | |
118 | options.push_cert = SEND_PACK_PUSH_CERT_IF_ASKED; | |
0ea47f9d JH |
119 | else |
120 | return -1; | |
121 | return 0; | |
16094885 | 122 | } else { |
ef08ef9e SP |
123 | return 1 /* unsupported */; |
124 | } | |
125 | } | |
126 | ||
97cc7bc4 SP |
127 | struct discovery { |
128 | const char *service; | |
129 | char *buf_alloc; | |
130 | char *buf; | |
131 | size_t len; | |
2a455202 | 132 | struct ref *refs; |
16094885 | 133 | struct sha1_array shallow; |
97cc7bc4 SP |
134 | unsigned proto_git : 1; |
135 | }; | |
136 | static struct discovery *last_discovery; | |
137 | ||
b8054bbe JK |
138 | static struct ref *parse_git_refs(struct discovery *heads, int for_push) |
139 | { | |
140 | struct ref *list = NULL; | |
141 | get_remote_heads(-1, heads->buf, heads->len, &list, | |
16094885 | 142 | for_push ? REF_NORMAL : 0, NULL, &heads->shallow); |
b8054bbe JK |
143 | return list; |
144 | } | |
145 | ||
146 | static struct ref *parse_info_refs(struct discovery *heads) | |
147 | { | |
148 | char *data, *start, *mid; | |
149 | char *ref_name; | |
150 | int i = 0; | |
151 | ||
152 | struct ref *refs = NULL; | |
153 | struct ref *ref = NULL; | |
154 | struct ref *last_ref = NULL; | |
155 | ||
156 | data = heads->buf; | |
157 | start = NULL; | |
158 | mid = data; | |
159 | while (i < heads->len) { | |
160 | if (!start) { | |
161 | start = &data[i]; | |
162 | } | |
163 | if (data[i] == '\t') | |
164 | mid = &data[i]; | |
165 | if (data[i] == '\n') { | |
166 | if (mid - start != 40) | |
b227bbc4 JK |
167 | die("%sinfo/refs not valid: is this a git repository?", |
168 | url.buf); | |
b8054bbe JK |
169 | data[i] = 0; |
170 | ref_name = mid + 1; | |
6f687c21 | 171 | ref = alloc_ref(ref_name); |
f4e54d02 | 172 | get_oid_hex(start, &ref->old_oid); |
b8054bbe JK |
173 | if (!refs) |
174 | refs = ref; | |
175 | if (last_ref) | |
176 | last_ref->next = ref; | |
177 | last_ref = ref; | |
178 | start = NULL; | |
179 | } | |
180 | i++; | |
181 | } | |
182 | ||
183 | ref = alloc_ref("HEAD"); | |
b227bbc4 | 184 | if (!http_fetch_ref(url.buf, ref) && |
b8054bbe JK |
185 | !resolve_remote_symref(ref, refs)) { |
186 | ref->next = refs; | |
187 | refs = ref; | |
188 | } else { | |
189 | free(ref); | |
190 | } | |
191 | ||
192 | return refs; | |
193 | } | |
194 | ||
97cc7bc4 SP |
195 | static void free_discovery(struct discovery *d) |
196 | { | |
197 | if (d) { | |
198 | if (d == last_discovery) | |
199 | last_discovery = NULL; | |
16094885 | 200 | free(d->shallow.sha1); |
97cc7bc4 | 201 | free(d->buf_alloc); |
2a455202 | 202 | free_refs(d->refs); |
97cc7bc4 SP |
203 | free(d); |
204 | } | |
205 | } | |
206 | ||
fc1b774c JK |
207 | static int show_http_message(struct strbuf *type, struct strbuf *charset, |
208 | struct strbuf *msg) | |
426e70d4 JK |
209 | { |
210 | const char *p, *eol; | |
211 | ||
212 | /* | |
213 | * We only show text/plain parts, as other types are likely | |
214 | * to be ugly to look at on the user's terminal. | |
426e70d4 | 215 | */ |
bf197fd7 | 216 | if (strcmp(type->buf, "text/plain")) |
426e70d4 | 217 | return -1; |
fc1b774c JK |
218 | if (charset->len) |
219 | strbuf_reencode(msg, charset->buf, get_log_output_encoding()); | |
426e70d4 JK |
220 | |
221 | strbuf_trim(msg); | |
222 | if (!msg->len) | |
223 | return -1; | |
224 | ||
225 | p = msg->buf; | |
226 | do { | |
227 | eol = strchrnul(p, '\n'); | |
228 | fprintf(stderr, "remote: %.*s\n", (int)(eol - p), p); | |
229 | p = eol + 1; | |
230 | } while(*eol); | |
231 | return 0; | |
232 | } | |
233 | ||
24d36f14 | 234 | static struct discovery *discover_refs(const char *service, int for_push) |
a2d725b7 | 235 | { |
4656bf47 SP |
236 | struct strbuf exp = STRBUF_INIT; |
237 | struct strbuf type = STRBUF_INIT; | |
fc1b774c | 238 | struct strbuf charset = STRBUF_INIT; |
a2d725b7 | 239 | struct strbuf buffer = STRBUF_INIT; |
c65d5692 | 240 | struct strbuf refs_url = STRBUF_INIT; |
050ef365 | 241 | struct strbuf effective_url = STRBUF_INIT; |
97cc7bc4 | 242 | struct discovery *last = last_discovery; |
243c329c | 243 | int http_ret, maybe_smart = 0; |
1bbcc224 | 244 | struct http_get_options options; |
a2d725b7 | 245 | |
97cc7bc4 SP |
246 | if (last && !strcmp(service, last->service)) |
247 | return last; | |
248 | free_discovery(last); | |
a2d725b7 | 249 | |
b227bbc4 | 250 | strbuf_addf(&refs_url, "%sinfo/refs", url.buf); |
59556548 | 251 | if ((starts_with(url.buf, "http://") || starts_with(url.buf, "https://")) && |
02572c2e | 252 | git_env_bool("GIT_SMART_HTTP", 1)) { |
243c329c | 253 | maybe_smart = 1; |
b227bbc4 | 254 | if (!strchr(url.buf, '?')) |
c65d5692 | 255 | strbuf_addch(&refs_url, '?'); |
97cc7bc4 | 256 | else |
c65d5692 JK |
257 | strbuf_addch(&refs_url, '&'); |
258 | strbuf_addf(&refs_url, "service=%s", service); | |
97cc7bc4 | 259 | } |
a2d725b7 | 260 | |
1bbcc224 JK |
261 | memset(&options, 0, sizeof(options)); |
262 | options.content_type = &type; | |
fc1b774c | 263 | options.charset = &charset; |
050ef365 JK |
264 | options.effective_url = &effective_url; |
265 | options.base_url = &url; | |
1bbcc224 JK |
266 | options.no_cache = 1; |
267 | options.keep_error = 1; | |
268 | ||
c65d5692 | 269 | http_ret = http_get_strbuf(refs_url.buf, &buffer, &options); |
a2d725b7 DB |
270 | switch (http_ret) { |
271 | case HTTP_OK: | |
272 | break; | |
273 | case HTTP_MISSING_TARGET: | |
fc1b774c | 274 | show_http_message(&type, &charset, &buffer); |
b227bbc4 | 275 | die("repository '%s' not found", url.buf); |
42653c09 | 276 | case HTTP_NOAUTH: |
fc1b774c | 277 | show_http_message(&type, &charset, &buffer); |
b227bbc4 | 278 | die("Authentication failed for '%s'", url.buf); |
a2d725b7 | 279 | default: |
fc1b774c | 280 | show_http_message(&type, &charset, &buffer); |
b227bbc4 | 281 | die("unable to access '%s': %s", url.buf, curl_errorstr); |
a2d725b7 DB |
282 | } |
283 | ||
97cc7bc4 SP |
284 | last= xcalloc(1, sizeof(*last_discovery)); |
285 | last->service = service; | |
286 | last->buf_alloc = strbuf_detach(&buffer, &last->len); | |
287 | last->buf = last->buf_alloc; | |
288 | ||
4656bf47 SP |
289 | strbuf_addf(&exp, "application/x-%s-advertisement", service); |
290 | if (maybe_smart && | |
291 | (5 <= last->len && last->buf[4] == '#') && | |
292 | !strbuf_cmp(&exp, &type)) { | |
4981fe75 JK |
293 | char *line; |
294 | ||
4656bf47 SP |
295 | /* |
296 | * smart HTTP response; validate that the service | |
97cc7bc4 SP |
297 | * pkt-line matches our request. |
298 | */ | |
4981fe75 | 299 | line = packet_read_line_buf(&last->buf, &last->len, NULL); |
97cc7bc4 | 300 | |
4656bf47 | 301 | strbuf_reset(&exp); |
97cc7bc4 | 302 | strbuf_addf(&exp, "# service=%s", service); |
4981fe75 JK |
303 | if (strcmp(line, exp.buf)) |
304 | die("invalid server response; got '%s'", line); | |
97cc7bc4 SP |
305 | strbuf_release(&exp); |
306 | ||
307 | /* The header can include additional metadata lines, up | |
308 | * until a packet flush marker. Ignore these now, but | |
309 | * in the future we might start to scan them. | |
310 | */ | |
4981fe75 JK |
311 | while (packet_read_line_buf(&last->buf, &last->len, NULL)) |
312 | ; | |
97cc7bc4 SP |
313 | |
314 | last->proto_git = 1; | |
315 | } | |
316 | ||
2a455202 JK |
317 | if (last->proto_git) |
318 | last->refs = parse_git_refs(last, for_push); | |
319 | else | |
320 | last->refs = parse_info_refs(last); | |
321 | ||
c65d5692 | 322 | strbuf_release(&refs_url); |
4656bf47 SP |
323 | strbuf_release(&exp); |
324 | strbuf_release(&type); | |
fc1b774c | 325 | strbuf_release(&charset); |
050ef365 | 326 | strbuf_release(&effective_url); |
97cc7bc4 SP |
327 | strbuf_release(&buffer); |
328 | last_discovery = last; | |
329 | return last; | |
330 | } | |
331 | ||
97cc7bc4 SP |
332 | static struct ref *get_refs(int for_push) |
333 | { | |
334 | struct discovery *heads; | |
335 | ||
336 | if (for_push) | |
2a455202 | 337 | heads = discover_refs("git-receive-pack", for_push); |
97cc7bc4 | 338 | else |
2a455202 | 339 | heads = discover_refs("git-upload-pack", for_push); |
97cc7bc4 | 340 | |
2a455202 | 341 | return heads->refs; |
97cc7bc4 SP |
342 | } |
343 | ||
ae4efe19 SP |
344 | static void output_refs(struct ref *refs) |
345 | { | |
346 | struct ref *posn; | |
347 | for (posn = refs; posn; posn = posn->next) { | |
348 | if (posn->symref) | |
349 | printf("@%s %s\n", posn->symref, posn->name); | |
350 | else | |
f4e54d02 | 351 | printf("%s %s\n", oid_to_hex(&posn->old_oid), posn->name); |
ae4efe19 SP |
352 | } |
353 | printf("\n"); | |
354 | fflush(stdout); | |
ae4efe19 SP |
355 | } |
356 | ||
de1a2fdd SP |
357 | struct rpc_state { |
358 | const char *service_name; | |
359 | const char **argv; | |
8150749d | 360 | struct strbuf *stdin_preamble; |
de1a2fdd SP |
361 | char *service_url; |
362 | char *hdr_content_type; | |
363 | char *hdr_accept; | |
364 | char *buf; | |
365 | size_t alloc; | |
366 | size_t len; | |
367 | size_t pos; | |
368 | int in; | |
369 | int out; | |
370 | struct strbuf result; | |
b8538603 | 371 | unsigned gzip_request : 1; |
6c81a990 | 372 | unsigned initial_buffer : 1; |
de1a2fdd SP |
373 | }; |
374 | ||
375 | static size_t rpc_out(void *ptr, size_t eltsize, | |
376 | size_t nmemb, void *buffer_) | |
377 | { | |
378 | size_t max = eltsize * nmemb; | |
379 | struct rpc_state *rpc = buffer_; | |
380 | size_t avail = rpc->len - rpc->pos; | |
381 | ||
382 | if (!avail) { | |
6c81a990 | 383 | rpc->initial_buffer = 0; |
4981fe75 | 384 | avail = packet_read(rpc->out, NULL, NULL, rpc->buf, rpc->alloc, 0); |
de1a2fdd SP |
385 | if (!avail) |
386 | return 0; | |
387 | rpc->pos = 0; | |
388 | rpc->len = avail; | |
389 | } | |
390 | ||
48310608 | 391 | if (max < avail) |
de1a2fdd SP |
392 | avail = max; |
393 | memcpy(ptr, rpc->buf + rpc->pos, avail); | |
394 | rpc->pos += avail; | |
395 | return avail; | |
396 | } | |
397 | ||
6c81a990 | 398 | #ifndef NO_CURL_IOCTL |
5092d3ec | 399 | static curlioerr rpc_ioctl(CURL *handle, int cmd, void *clientp) |
6c81a990 MS |
400 | { |
401 | struct rpc_state *rpc = clientp; | |
402 | ||
403 | switch (cmd) { | |
404 | case CURLIOCMD_NOP: | |
405 | return CURLIOE_OK; | |
406 | ||
407 | case CURLIOCMD_RESTARTREAD: | |
408 | if (rpc->initial_buffer) { | |
409 | rpc->pos = 0; | |
410 | return CURLIOE_OK; | |
411 | } | |
b725b270 | 412 | error("unable to rewind rpc post data - try increasing http.postBuffer"); |
6c81a990 MS |
413 | return CURLIOE_FAILRESTART; |
414 | ||
415 | default: | |
416 | return CURLIOE_UNKNOWNCMD; | |
417 | } | |
418 | } | |
419 | #endif | |
420 | ||
a04ff3ec | 421 | static size_t rpc_in(char *ptr, size_t eltsize, |
de1a2fdd SP |
422 | size_t nmemb, void *buffer_) |
423 | { | |
424 | size_t size = eltsize * nmemb; | |
425 | struct rpc_state *rpc = buffer_; | |
426 | write_or_die(rpc->in, ptr, size); | |
427 | return size; | |
428 | } | |
429 | ||
3a347ed7 JK |
430 | static int run_slot(struct active_request_slot *slot, |
431 | struct slot_results *results) | |
206b099d | 432 | { |
b81401c1 | 433 | int err; |
3a347ed7 | 434 | struct slot_results results_buf; |
206b099d | 435 | |
3a347ed7 JK |
436 | if (!results) |
437 | results = &results_buf; | |
438 | ||
beed336c | 439 | err = run_one_slot(slot, results); |
206b099d | 440 | |
b81401c1 | 441 | if (err != HTTP_OK && err != HTTP_REAUTH) { |
00540458 SP |
442 | struct strbuf msg = STRBUF_INIT; |
443 | if (results->http_code && results->http_code != 200) | |
444 | strbuf_addf(&msg, "HTTP %ld", results->http_code); | |
445 | if (results->curl_result != CURLE_OK) { | |
446 | if (msg.len) | |
447 | strbuf_addch(&msg, ' '); | |
448 | strbuf_addf(&msg, "curl %d", results->curl_result); | |
449 | if (curl_errorstr[0]) { | |
450 | strbuf_addch(&msg, ' '); | |
451 | strbuf_addstr(&msg, curl_errorstr); | |
452 | } | |
453 | } | |
454 | error("RPC failed; %s", msg.buf); | |
455 | strbuf_release(&msg); | |
206b099d SP |
456 | } |
457 | ||
458 | return err; | |
459 | } | |
460 | ||
3a347ed7 | 461 | static int probe_rpc(struct rpc_state *rpc, struct slot_results *results) |
206b099d SP |
462 | { |
463 | struct active_request_slot *slot; | |
464 | struct curl_slist *headers = NULL; | |
465 | struct strbuf buf = STRBUF_INIT; | |
466 | int err; | |
467 | ||
468 | slot = get_active_slot(); | |
469 | ||
470 | headers = curl_slist_append(headers, rpc->hdr_content_type); | |
471 | headers = curl_slist_append(headers, rpc->hdr_accept); | |
472 | ||
473 | curl_easy_setopt(slot->curl, CURLOPT_NOBODY, 0); | |
474 | curl_easy_setopt(slot->curl, CURLOPT_POST, 1); | |
475 | curl_easy_setopt(slot->curl, CURLOPT_URL, rpc->service_url); | |
aa90b969 | 476 | curl_easy_setopt(slot->curl, CURLOPT_ENCODING, NULL); |
206b099d SP |
477 | curl_easy_setopt(slot->curl, CURLOPT_POSTFIELDS, "0000"); |
478 | curl_easy_setopt(slot->curl, CURLOPT_POSTFIELDSIZE, 4); | |
479 | curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, headers); | |
480 | curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_buffer); | |
481 | curl_easy_setopt(slot->curl, CURLOPT_FILE, &buf); | |
482 | ||
3a347ed7 | 483 | err = run_slot(slot, results); |
206b099d SP |
484 | |
485 | curl_slist_free_all(headers); | |
486 | strbuf_release(&buf); | |
487 | return err; | |
488 | } | |
489 | ||
de1a2fdd SP |
490 | static int post_rpc(struct rpc_state *rpc) |
491 | { | |
492 | struct active_request_slot *slot; | |
de1a2fdd | 493 | struct curl_slist *headers = NULL; |
b8538603 SP |
494 | int use_gzip = rpc->gzip_request; |
495 | char *gzip_body = NULL; | |
37711549 | 496 | size_t gzip_size = 0; |
206b099d | 497 | int err, large_request = 0; |
c80d96ca | 498 | int needs_100_continue = 0; |
de1a2fdd SP |
499 | |
500 | /* Try to load the entire request, if we can fit it into the | |
501 | * allocated buffer space we can use HTTP/1.0 and avoid the | |
502 | * chunked encoding mess. | |
503 | */ | |
504 | while (1) { | |
505 | size_t left = rpc->alloc - rpc->len; | |
506 | char *buf = rpc->buf + rpc->len; | |
507 | int n; | |
508 | ||
509 | if (left < LARGE_PACKET_MAX) { | |
510 | large_request = 1; | |
b8538603 | 511 | use_gzip = 0; |
de1a2fdd SP |
512 | break; |
513 | } | |
514 | ||
4981fe75 | 515 | n = packet_read(rpc->out, NULL, NULL, buf, left, 0); |
de1a2fdd SP |
516 | if (!n) |
517 | break; | |
518 | rpc->len += n; | |
519 | } | |
520 | ||
206b099d | 521 | if (large_request) { |
c80d96ca | 522 | struct slot_results results; |
523 | ||
b81401c1 | 524 | do { |
c80d96ca | 525 | err = probe_rpc(rpc, &results); |
2501aff8 JK |
526 | if (err == HTTP_REAUTH) |
527 | credential_fill(&http_auth); | |
b81401c1 JK |
528 | } while (err == HTTP_REAUTH); |
529 | if (err != HTTP_OK) | |
530 | return -1; | |
c80d96ca | 531 | |
532 | if (results.auth_avail & CURLAUTH_GSSNEGOTIATE) | |
533 | needs_100_continue = 1; | |
206b099d SP |
534 | } |
535 | ||
abf8df86 JK |
536 | headers = curl_slist_append(headers, rpc->hdr_content_type); |
537 | headers = curl_slist_append(headers, rpc->hdr_accept); | |
c80d96ca | 538 | headers = curl_slist_append(headers, needs_100_continue ? |
539 | "Expect: 100-continue" : "Expect:"); | |
abf8df86 JK |
540 | |
541 | retry: | |
de1a2fdd | 542 | slot = get_active_slot(); |
de1a2fdd | 543 | |
de1a2fdd | 544 | curl_easy_setopt(slot->curl, CURLOPT_NOBODY, 0); |
d21f9794 | 545 | curl_easy_setopt(slot->curl, CURLOPT_POST, 1); |
de1a2fdd | 546 | curl_easy_setopt(slot->curl, CURLOPT_URL, rpc->service_url); |
aa90b969 | 547 | curl_easy_setopt(slot->curl, CURLOPT_ENCODING, "gzip"); |
de1a2fdd | 548 | |
de1a2fdd SP |
549 | if (large_request) { |
550 | /* The request body is large and the size cannot be predicted. | |
551 | * We must use chunked encoding to send it. | |
552 | */ | |
de1a2fdd | 553 | headers = curl_slist_append(headers, "Transfer-Encoding: chunked"); |
6c81a990 | 554 | rpc->initial_buffer = 1; |
de1a2fdd SP |
555 | curl_easy_setopt(slot->curl, CURLOPT_READFUNCTION, rpc_out); |
556 | curl_easy_setopt(slot->curl, CURLOPT_INFILE, rpc); | |
6c81a990 MS |
557 | #ifndef NO_CURL_IOCTL |
558 | curl_easy_setopt(slot->curl, CURLOPT_IOCTLFUNCTION, rpc_ioctl); | |
559 | curl_easy_setopt(slot->curl, CURLOPT_IOCTLDATA, rpc); | |
560 | #endif | |
de1a2fdd SP |
561 | if (options.verbosity > 1) { |
562 | fprintf(stderr, "POST %s (chunked)\n", rpc->service_name); | |
563 | fflush(stderr); | |
564 | } | |
565 | ||
2e736fd5 JK |
566 | } else if (gzip_body) { |
567 | /* | |
568 | * If we are looping to retry authentication, then the previous | |
569 | * run will have set up the headers and gzip buffer already, | |
570 | * and we just need to send it. | |
571 | */ | |
572 | curl_easy_setopt(slot->curl, CURLOPT_POSTFIELDS, gzip_body); | |
573 | curl_easy_setopt(slot->curl, CURLOPT_POSTFIELDSIZE, gzip_size); | |
574 | ||
b8538603 SP |
575 | } else if (use_gzip && 1024 < rpc->len) { |
576 | /* The client backend isn't giving us compressed data so | |
577 | * we can try to deflate it ourselves, this may save on. | |
578 | * the transfer time. | |
579 | */ | |
ef49a7a0 | 580 | git_zstream stream; |
b8538603 SP |
581 | int ret; |
582 | ||
55bb5c91 | 583 | git_deflate_init_gzip(&stream, Z_BEST_COMPRESSION); |
df126e10 JK |
584 | gzip_size = git_deflate_bound(&stream, rpc->len); |
585 | gzip_body = xmalloc(gzip_size); | |
b8538603 SP |
586 | |
587 | stream.next_in = (unsigned char *)rpc->buf; | |
588 | stream.avail_in = rpc->len; | |
589 | stream.next_out = (unsigned char *)gzip_body; | |
df126e10 | 590 | stream.avail_out = gzip_size; |
b8538603 | 591 | |
55bb5c91 | 592 | ret = git_deflate(&stream, Z_FINISH); |
b8538603 SP |
593 | if (ret != Z_STREAM_END) |
594 | die("cannot deflate request; zlib deflate error %d", ret); | |
595 | ||
55bb5c91 | 596 | ret = git_deflate_end_gently(&stream); |
b8538603 SP |
597 | if (ret != Z_OK) |
598 | die("cannot deflate request; zlib end error %d", ret); | |
599 | ||
df126e10 | 600 | gzip_size = stream.total_out; |
b8538603 SP |
601 | |
602 | headers = curl_slist_append(headers, "Content-Encoding: gzip"); | |
603 | curl_easy_setopt(slot->curl, CURLOPT_POSTFIELDS, gzip_body); | |
df126e10 | 604 | curl_easy_setopt(slot->curl, CURLOPT_POSTFIELDSIZE, gzip_size); |
b8538603 SP |
605 | |
606 | if (options.verbosity > 1) { | |
607 | fprintf(stderr, "POST %s (gzip %lu to %lu bytes)\n", | |
608 | rpc->service_name, | |
df126e10 | 609 | (unsigned long)rpc->len, (unsigned long)gzip_size); |
b8538603 SP |
610 | fflush(stderr); |
611 | } | |
de1a2fdd SP |
612 | } else { |
613 | /* We know the complete request size in advance, use the | |
614 | * more normal Content-Length approach. | |
615 | */ | |
616 | curl_easy_setopt(slot->curl, CURLOPT_POSTFIELDS, rpc->buf); | |
617 | curl_easy_setopt(slot->curl, CURLOPT_POSTFIELDSIZE, rpc->len); | |
618 | if (options.verbosity > 1) { | |
619 | fprintf(stderr, "POST %s (%lu bytes)\n", | |
620 | rpc->service_name, (unsigned long)rpc->len); | |
621 | fflush(stderr); | |
622 | } | |
623 | } | |
624 | ||
625 | curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, headers); | |
626 | curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, rpc_in); | |
627 | curl_easy_setopt(slot->curl, CURLOPT_FILE, rpc); | |
628 | ||
3a347ed7 | 629 | err = run_slot(slot, NULL); |
2501aff8 JK |
630 | if (err == HTTP_REAUTH && !large_request) { |
631 | credential_fill(&http_auth); | |
abf8df86 | 632 | goto retry; |
2501aff8 | 633 | } |
b81401c1 JK |
634 | if (err != HTTP_OK) |
635 | err = -1; | |
de1a2fdd SP |
636 | |
637 | curl_slist_free_all(headers); | |
b8538603 | 638 | free(gzip_body); |
de1a2fdd SP |
639 | return err; |
640 | } | |
641 | ||
642 | static int rpc_service(struct rpc_state *rpc, struct discovery *heads) | |
643 | { | |
644 | const char *svc = rpc->service_name; | |
645 | struct strbuf buf = STRBUF_INIT; | |
8150749d | 646 | struct strbuf *preamble = rpc->stdin_preamble; |
d3180279 | 647 | struct child_process client = CHILD_PROCESS_INIT; |
de1a2fdd SP |
648 | int err = 0; |
649 | ||
de1a2fdd SP |
650 | client.in = -1; |
651 | client.out = -1; | |
652 | client.git_cmd = 1; | |
653 | client.argv = rpc->argv; | |
654 | if (start_command(&client)) | |
655 | exit(1); | |
8150749d IT |
656 | if (preamble) |
657 | write_or_die(client.in, preamble->buf, preamble->len); | |
de1a2fdd SP |
658 | if (heads) |
659 | write_or_die(client.in, heads->buf, heads->len); | |
660 | ||
661 | rpc->alloc = http_post_buffer; | |
662 | rpc->buf = xmalloc(rpc->alloc); | |
663 | rpc->in = client.in; | |
664 | rpc->out = client.out; | |
665 | strbuf_init(&rpc->result, 0); | |
666 | ||
b227bbc4 | 667 | strbuf_addf(&buf, "%s%s", url.buf, svc); |
de1a2fdd SP |
668 | rpc->service_url = strbuf_detach(&buf, NULL); |
669 | ||
670 | strbuf_addf(&buf, "Content-Type: application/x-%s-request", svc); | |
671 | rpc->hdr_content_type = strbuf_detach(&buf, NULL); | |
672 | ||
8efa5f62 | 673 | strbuf_addf(&buf, "Accept: application/x-%s-result", svc); |
de1a2fdd SP |
674 | rpc->hdr_accept = strbuf_detach(&buf, NULL); |
675 | ||
676 | while (!err) { | |
4981fe75 | 677 | int n = packet_read(rpc->out, NULL, NULL, rpc->buf, rpc->alloc, 0); |
de1a2fdd SP |
678 | if (!n) |
679 | break; | |
680 | rpc->pos = 0; | |
681 | rpc->len = n; | |
682 | err |= post_rpc(rpc); | |
683 | } | |
de1a2fdd SP |
684 | |
685 | close(client.in); | |
de1a2fdd | 686 | client.in = -1; |
6cdf0223 SP |
687 | if (!err) { |
688 | strbuf_read(&rpc->result, client.out, 0); | |
689 | } else { | |
690 | char buf[4096]; | |
691 | for (;;) | |
692 | if (xread(client.out, buf, sizeof(buf)) <= 0) | |
693 | break; | |
694 | } | |
b4ee10f6 SP |
695 | |
696 | close(client.out); | |
de1a2fdd SP |
697 | client.out = -1; |
698 | ||
699 | err |= finish_command(&client); | |
700 | free(rpc->service_url); | |
701 | free(rpc->hdr_content_type); | |
702 | free(rpc->hdr_accept); | |
703 | free(rpc->buf); | |
704 | strbuf_release(&buf); | |
705 | return err; | |
706 | } | |
707 | ||
292ce46b SP |
708 | static int fetch_dumb(int nr_heads, struct ref **to_fetch) |
709 | { | |
26e1e0b2 | 710 | struct walker *walker; |
b32fa95f | 711 | char **targets; |
292ce46b SP |
712 | int ret, i; |
713 | ||
b32fa95f | 714 | ALLOC_ARRAY(targets, nr_heads); |
249b2004 SP |
715 | if (options.depth) |
716 | die("dumb http transport does not support --depth"); | |
292ce46b | 717 | for (i = 0; i < nr_heads; i++) |
f4e54d02 | 718 | targets[i] = xstrdup(oid_to_hex(&to_fetch[i]->old_oid)); |
292ce46b | 719 | |
b227bbc4 | 720 | walker = get_http_walker(url.buf); |
292ce46b SP |
721 | walker->get_all = 1; |
722 | walker->get_tree = 1; | |
723 | walker->get_history = 1; | |
ef08ef9e | 724 | walker->get_verbosely = options.verbosity >= 3; |
292ce46b SP |
725 | walker->get_recover = 0; |
726 | ret = walker_fetch(walker, nr_heads, targets, NULL, NULL); | |
26e1e0b2 | 727 | walker_free(walker); |
292ce46b SP |
728 | |
729 | for (i = 0; i < nr_heads; i++) | |
730 | free(targets[i]); | |
731 | free(targets); | |
732 | ||
b725b270 | 733 | return ret ? error("fetch failed.") : 0; |
292ce46b SP |
734 | } |
735 | ||
249b2004 SP |
736 | static int fetch_git(struct discovery *heads, |
737 | int nr_heads, struct ref **to_fetch) | |
738 | { | |
739 | struct rpc_state rpc; | |
8150749d | 740 | struct strbuf preamble = STRBUF_INIT; |
249b2004 | 741 | char *depth_arg = NULL; |
249b2004 | 742 | int argc = 0, i, err; |
16094885 | 743 | const char *argv[17]; |
249b2004 | 744 | |
249b2004 SP |
745 | argv[argc++] = "fetch-pack"; |
746 | argv[argc++] = "--stateless-rpc"; | |
8150749d | 747 | argv[argc++] = "--stdin"; |
249b2004 SP |
748 | argv[argc++] = "--lock-pack"; |
749 | if (options.followtags) | |
750 | argv[argc++] = "--include-tag"; | |
751 | if (options.thin) | |
752 | argv[argc++] = "--thin"; | |
753 | if (options.verbosity >= 3) { | |
754 | argv[argc++] = "-v"; | |
755 | argv[argc++] = "-v"; | |
756 | } | |
9ba38048 NTND |
757 | if (options.check_self_contained_and_connected) |
758 | argv[argc++] = "--check-self-contained-and-connected"; | |
16094885 NTND |
759 | if (options.cloning) |
760 | argv[argc++] = "--cloning"; | |
761 | if (options.update_shallow) | |
762 | argv[argc++] = "--update-shallow"; | |
249b2004 SP |
763 | if (!options.progress) |
764 | argv[argc++] = "--no-progress"; | |
765 | if (options.depth) { | |
766 | struct strbuf buf = STRBUF_INIT; | |
767 | strbuf_addf(&buf, "--depth=%lu", options.depth); | |
768 | depth_arg = strbuf_detach(&buf, NULL); | |
769 | argv[argc++] = depth_arg; | |
770 | } | |
b227bbc4 | 771 | argv[argc++] = url.buf; |
8150749d IT |
772 | argv[argc++] = NULL; |
773 | ||
249b2004 SP |
774 | for (i = 0; i < nr_heads; i++) { |
775 | struct ref *ref = to_fetch[i]; | |
94ee8e2c | 776 | if (!*ref->name) |
249b2004 | 777 | die("cannot fetch by sha1 over smart http"); |
58f2ed05 | 778 | packet_buf_write(&preamble, "%s %s\n", |
f4e54d02 | 779 | oid_to_hex(&ref->old_oid), ref->name); |
249b2004 | 780 | } |
8150749d | 781 | packet_buf_flush(&preamble); |
249b2004 SP |
782 | |
783 | memset(&rpc, 0, sizeof(rpc)); | |
784 | rpc.service_name = "git-upload-pack", | |
785 | rpc.argv = argv; | |
8150749d | 786 | rpc.stdin_preamble = &preamble; |
b8538603 | 787 | rpc.gzip_request = 1; |
249b2004 SP |
788 | |
789 | err = rpc_service(&rpc, heads); | |
790 | if (rpc.result.len) | |
cdf4fb8e | 791 | write_or_die(1, rpc.result.buf, rpc.result.len); |
249b2004 | 792 | strbuf_release(&rpc.result); |
8150749d | 793 | strbuf_release(&preamble); |
249b2004 SP |
794 | free(depth_arg); |
795 | return err; | |
796 | } | |
797 | ||
798 | static int fetch(int nr_heads, struct ref **to_fetch) | |
799 | { | |
2a455202 | 800 | struct discovery *d = discover_refs("git-upload-pack", 0); |
249b2004 SP |
801 | if (d->proto_git) |
802 | return fetch_git(d, nr_heads, to_fetch); | |
803 | else | |
804 | return fetch_dumb(nr_heads, to_fetch); | |
805 | } | |
806 | ||
292ce46b SP |
807 | static void parse_fetch(struct strbuf *buf) |
808 | { | |
809 | struct ref **to_fetch = NULL; | |
810 | struct ref *list_head = NULL; | |
811 | struct ref **list = &list_head; | |
812 | int alloc_heads = 0, nr_heads = 0; | |
813 | ||
814 | do { | |
95b567c7 JK |
815 | const char *p; |
816 | if (skip_prefix(buf->buf, "fetch ", &p)) { | |
817 | const char *name; | |
292ce46b | 818 | struct ref *ref; |
8338c911 | 819 | struct object_id old_oid; |
292ce46b | 820 | |
8338c911 | 821 | if (get_oid_hex(p, &old_oid)) |
292ce46b | 822 | die("protocol error: expected sha/ref, got %s'", p); |
8338c911 | 823 | if (p[GIT_SHA1_HEXSZ] == ' ') |
824 | name = p + GIT_SHA1_HEXSZ + 1; | |
825 | else if (!p[GIT_SHA1_HEXSZ]) | |
292ce46b SP |
826 | name = ""; |
827 | else | |
828 | die("protocol error: expected sha/ref, got %s'", p); | |
829 | ||
830 | ref = alloc_ref(name); | |
8338c911 | 831 | oidcpy(&ref->old_oid, &old_oid); |
292ce46b SP |
832 | |
833 | *list = ref; | |
834 | list = &ref->next; | |
835 | ||
836 | ALLOC_GROW(to_fetch, nr_heads + 1, alloc_heads); | |
837 | to_fetch[nr_heads++] = ref; | |
838 | } | |
839 | else | |
840 | die("http transport does not support %s", buf->buf); | |
841 | ||
842 | strbuf_reset(buf); | |
843 | if (strbuf_getline(buf, stdin, '\n') == EOF) | |
844 | return; | |
845 | if (!*buf->buf) | |
846 | break; | |
847 | } while (1); | |
848 | ||
249b2004 | 849 | if (fetch(nr_heads, to_fetch)) |
292ce46b SP |
850 | exit(128); /* error already reported */ |
851 | free_refs(list_head); | |
852 | free(to_fetch); | |
853 | ||
854 | printf("\n"); | |
855 | fflush(stdout); | |
856 | strbuf_reset(buf); | |
857 | } | |
858 | ||
ae4efe19 SP |
859 | static int push_dav(int nr_spec, char **specs) |
860 | { | |
850d2fec JK |
861 | struct child_process child = CHILD_PROCESS_INIT; |
862 | size_t i; | |
ae4efe19 | 863 | |
850d2fec JK |
864 | child.git_cmd = 1; |
865 | argv_array_push(&child.args, "http-push"); | |
866 | argv_array_push(&child.args, "--helper-status"); | |
ae4efe19 | 867 | if (options.dry_run) |
850d2fec | 868 | argv_array_push(&child.args, "--dry-run"); |
ae4efe19 | 869 | if (options.verbosity > 1) |
850d2fec JK |
870 | argv_array_push(&child.args, "--verbose"); |
871 | argv_array_push(&child.args, url.buf); | |
ae4efe19 | 872 | for (i = 0; i < nr_spec; i++) |
850d2fec | 873 | argv_array_push(&child.args, specs[i]); |
ae4efe19 | 874 | |
850d2fec JK |
875 | if (run_command(&child)) |
876 | die("git-http-push failed"); | |
ae4efe19 SP |
877 | return 0; |
878 | } | |
879 | ||
de1a2fdd SP |
880 | static int push_git(struct discovery *heads, int nr_spec, char **specs) |
881 | { | |
882 | struct rpc_state rpc; | |
222b1212 JH |
883 | int i, err; |
884 | struct argv_array args; | |
05c1eb10 | 885 | struct string_list_item *cas_option; |
26be19ba | 886 | struct strbuf preamble = STRBUF_INIT; |
222b1212 JH |
887 | |
888 | argv_array_init(&args); | |
889 | argv_array_pushl(&args, "send-pack", "--stateless-rpc", "--helper-status", | |
890 | NULL); | |
de1a2fdd | 891 | |
de1a2fdd | 892 | if (options.thin) |
222b1212 | 893 | argv_array_push(&args, "--thin"); |
de1a2fdd | 894 | if (options.dry_run) |
222b1212 | 895 | argv_array_push(&args, "--dry-run"); |
30261094 DB |
896 | if (options.push_cert == SEND_PACK_PUSH_CERT_ALWAYS) |
897 | argv_array_push(&args, "--signed=yes"); | |
898 | else if (options.push_cert == SEND_PACK_PUSH_CERT_IF_ASKED) | |
899 | argv_array_push(&args, "--signed=if-asked"); | |
c207e34f | 900 | if (options.verbosity == 0) |
222b1212 | 901 | argv_array_push(&args, "--quiet"); |
c207e34f | 902 | else if (options.verbosity > 1) |
222b1212 JH |
903 | argv_array_push(&args, "--verbose"); |
904 | argv_array_push(&args, options.progress ? "--progress" : "--no-progress"); | |
05c1eb10 | 905 | for_each_string_list_item(cas_option, &cas_options) |
2233ad45 | 906 | argv_array_push(&args, cas_option->string); |
b227bbc4 | 907 | argv_array_push(&args, url.buf); |
26be19ba JK |
908 | |
909 | argv_array_push(&args, "--stdin"); | |
de1a2fdd | 910 | for (i = 0; i < nr_spec; i++) |
26be19ba JK |
911 | packet_buf_write(&preamble, "%s\n", specs[i]); |
912 | packet_buf_flush(&preamble); | |
de1a2fdd SP |
913 | |
914 | memset(&rpc, 0, sizeof(rpc)); | |
915 | rpc.service_name = "git-receive-pack", | |
222b1212 | 916 | rpc.argv = args.argv; |
26be19ba | 917 | rpc.stdin_preamble = &preamble; |
de1a2fdd SP |
918 | |
919 | err = rpc_service(&rpc, heads); | |
920 | if (rpc.result.len) | |
cdf4fb8e | 921 | write_or_die(1, rpc.result.buf, rpc.result.len); |
de1a2fdd | 922 | strbuf_release(&rpc.result); |
26be19ba | 923 | strbuf_release(&preamble); |
222b1212 | 924 | argv_array_clear(&args); |
de1a2fdd SP |
925 | return err; |
926 | } | |
927 | ||
928 | static int push(int nr_spec, char **specs) | |
929 | { | |
2a455202 | 930 | struct discovery *heads = discover_refs("git-receive-pack", 1); |
de1a2fdd SP |
931 | int ret; |
932 | ||
933 | if (heads->proto_git) | |
934 | ret = push_git(heads, nr_spec, specs); | |
935 | else | |
936 | ret = push_dav(nr_spec, specs); | |
937 | free_discovery(heads); | |
938 | return ret; | |
939 | } | |
940 | ||
ae4efe19 SP |
941 | static void parse_push(struct strbuf *buf) |
942 | { | |
943 | char **specs = NULL; | |
5238cbf6 | 944 | int alloc_spec = 0, nr_spec = 0, i, ret; |
ae4efe19 SP |
945 | |
946 | do { | |
59556548 | 947 | if (starts_with(buf->buf, "push ")) { |
ae4efe19 SP |
948 | ALLOC_GROW(specs, nr_spec + 1, alloc_spec); |
949 | specs[nr_spec++] = xstrdup(buf->buf + 5); | |
950 | } | |
951 | else | |
952 | die("http transport does not support %s", buf->buf); | |
953 | ||
954 | strbuf_reset(buf); | |
955 | if (strbuf_getline(buf, stdin, '\n') == EOF) | |
dc4cd767 | 956 | goto free_specs; |
ae4efe19 SP |
957 | if (!*buf->buf) |
958 | break; | |
959 | } while (1); | |
960 | ||
5238cbf6 | 961 | ret = push(nr_spec, specs); |
ae4efe19 SP |
962 | printf("\n"); |
963 | fflush(stdout); | |
dc4cd767 | 964 | |
5238cbf6 SP |
965 | if (ret) |
966 | exit(128); /* error already reported */ | |
967 | ||
dc4cd767 JM |
968 | free_specs: |
969 | for (i = 0; i < nr_spec; i++) | |
970 | free(specs[i]); | |
971 | free(specs); | |
ae4efe19 SP |
972 | } |
973 | ||
a2d725b7 DB |
974 | int main(int argc, const char **argv) |
975 | { | |
a2d725b7 | 976 | struct strbuf buf = STRBUF_INIT; |
a45d3d7e | 977 | int nongit; |
a2d725b7 | 978 | |
f18604bb YE |
979 | git_setup_gettext(); |
980 | ||
c6dfb399 | 981 | git_extract_argv0_path(argv[0]); |
a45d3d7e | 982 | setup_git_directory_gently(&nongit); |
a2d725b7 | 983 | if (argc < 2) { |
cdaa4e98 | 984 | error("remote-curl: usage: git remote-curl <remote> [<url>]"); |
a2d725b7 DB |
985 | return 1; |
986 | } | |
987 | ||
ef08ef9e SP |
988 | options.verbosity = 1; |
989 | options.progress = !!isatty(2); | |
de1a2fdd | 990 | options.thin = 1; |
ef08ef9e | 991 | |
a2d725b7 DB |
992 | remote = remote_get(argv[1]); |
993 | ||
994 | if (argc > 2) { | |
b227bbc4 | 995 | end_url_with_slash(&url, argv[2]); |
a2d725b7 | 996 | } else { |
b227bbc4 | 997 | end_url_with_slash(&url, remote->url[0]); |
a2d725b7 DB |
998 | } |
999 | ||
b227bbc4 | 1000 | http_init(remote, url.buf, 0); |
888692b7 | 1001 | |
a2d725b7 | 1002 | do { |
95b567c7 JK |
1003 | const char *arg; |
1004 | ||
1843f0ce SR |
1005 | if (strbuf_getline(&buf, stdin, '\n') == EOF) { |
1006 | if (ferror(stdin)) | |
cdaa4e98 | 1007 | error("remote-curl: error reading command stream from git"); |
1843f0ce SR |
1008 | return 1; |
1009 | } | |
1010 | if (buf.len == 0) | |
a2d725b7 | 1011 | break; |
59556548 | 1012 | if (starts_with(buf.buf, "fetch ")) { |
a45d3d7e | 1013 | if (nongit) |
cdaa4e98 | 1014 | die("remote-curl: fetch attempted without a local repo"); |
292ce46b SP |
1015 | parse_fetch(&buf); |
1016 | ||
59556548 | 1017 | } else if (!strcmp(buf.buf, "list") || starts_with(buf.buf, "list ")) { |
97cc7bc4 SP |
1018 | int for_push = !!strstr(buf.buf + 4, "for-push"); |
1019 | output_refs(get_refs(for_push)); | |
ae4efe19 | 1020 | |
59556548 | 1021 | } else if (starts_with(buf.buf, "push ")) { |
ae4efe19 SP |
1022 | parse_push(&buf); |
1023 | ||
95b567c7 JK |
1024 | } else if (skip_prefix(buf.buf, "option ", &arg)) { |
1025 | char *value = strchr(arg, ' '); | |
ef08ef9e SP |
1026 | int result; |
1027 | ||
1028 | if (value) | |
1029 | *value++ = '\0'; | |
1030 | else | |
1031 | value = "true"; | |
1032 | ||
95b567c7 | 1033 | result = set_option(arg, value); |
ef08ef9e SP |
1034 | if (!result) |
1035 | printf("ok\n"); | |
1036 | else if (result < 0) | |
1037 | printf("error invalid value\n"); | |
1038 | else | |
1039 | printf("unsupported\n"); | |
a2d725b7 | 1040 | fflush(stdout); |
ef08ef9e | 1041 | |
a2d725b7 DB |
1042 | } else if (!strcmp(buf.buf, "capabilities")) { |
1043 | printf("fetch\n"); | |
ef08ef9e | 1044 | printf("option\n"); |
ae4efe19 | 1045 | printf("push\n"); |
9ba38048 | 1046 | printf("check-connectivity\n"); |
a2d725b7 DB |
1047 | printf("\n"); |
1048 | fflush(stdout); | |
1049 | } else { | |
cdaa4e98 | 1050 | error("remote-curl: unknown command '%s' from git", buf.buf); |
a2d725b7 DB |
1051 | return 1; |
1052 | } | |
1053 | strbuf_reset(&buf); | |
1054 | } while (1); | |
888692b7 TRC |
1055 | |
1056 | http_cleanup(); | |
1057 | ||
a2d725b7 DB |
1058 | return 0; |
1059 | } |