7 #include "run-command.h"
9 #include "string-list.h"
11 #include "argv-array.h"
12 #include "credential.h"
13 #include "sha1-array.h"
14 #include "send-pack.h"
16 static struct remote *remote;
17 /* always ends with a trailing slash */
18 static struct strbuf url = STRBUF_INIT;
23 unsigned progress : 1,
24 check_self_contained_and_connected : 1,
30 /* One of the SEND_PACK_PUSH_CERT_* constants. */
33 static struct options options;
34 static struct string_list cas_options = STRING_LIST_INIT_DUP;
36 static int set_option(const char *name, const char *value)
38 if (!strcmp(name, "verbosity")) {
40 int v = strtol(value, &end, 10);
41 if (value == end || *end)
43 options.verbosity = v;
46 else if (!strcmp(name, "progress")) {
47 if (!strcmp(value, "true"))
49 else if (!strcmp(value, "false"))
55 else if (!strcmp(name, "depth")) {
57 unsigned long v = strtoul(value, &end, 10);
58 if (value == end || *end)
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;
72 else if (!strcmp(name, "dry-run")) {
73 if (!strcmp(value, "true"))
75 else if (!strcmp(value, "false"))
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;
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);
96 } else if (!strcmp(name, "cloning")) {
97 if (!strcmp(value, "true"))
99 else if (!strcmp(value, "false"))
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;
112 } else if (!strcmp(name, "pushcert")) {
113 if (!strcmp(value, "true"))
114 options.push_cert = SEND_PACK_PUSH_CERT_ALWAYS;
115 else if (!strcmp(value, "false"))
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;
123 #if LIBCURL_VERSION_NUM >= 0x070a08
124 } else if (!strcmp(name, "family")) {
125 if (!strcmp(value, "ipv4"))
126 git_curl_ipresolve = CURL_IPRESOLVE_V4;
127 else if (!strcmp(value, "ipv6"))
128 git_curl_ipresolve = CURL_IPRESOLVE_V6;
129 else if (!strcmp(value, "all"))
130 git_curl_ipresolve = CURL_IPRESOLVE_WHATEVER;
134 #endif /* LIBCURL_VERSION_NUM >= 0x070a08 */
136 return 1 /* unsupported */;
146 struct sha1_array shallow;
147 unsigned proto_git : 1;
149 static struct discovery *last_discovery;
151 static struct ref *parse_git_refs(struct discovery *heads, int for_push)
153 struct ref *list = NULL;
154 get_remote_heads(-1, heads->buf, heads->len, &list,
155 for_push ? REF_NORMAL : 0, NULL, &heads->shallow);
159 static struct ref *parse_info_refs(struct discovery *heads)
161 char *data, *start, *mid;
165 struct ref *refs = NULL;
166 struct ref *ref = NULL;
167 struct ref *last_ref = NULL;
172 while (i < heads->len) {
178 if (data[i] == '\n') {
179 if (mid - start != 40)
180 die("%sinfo/refs not valid: is this a git repository?",
184 ref = alloc_ref(ref_name);
185 get_oid_hex(start, &ref->old_oid);
189 last_ref->next = ref;
196 ref = alloc_ref("HEAD");
197 if (!http_fetch_ref(url.buf, ref) &&
198 !resolve_remote_symref(ref, refs)) {
208 static void free_discovery(struct discovery *d)
211 if (d == last_discovery)
212 last_discovery = NULL;
213 free(d->shallow.sha1);
220 static int show_http_message(struct strbuf *type, struct strbuf *charset,
226 * We only show text/plain parts, as other types are likely
227 * to be ugly to look at on the user's terminal.
229 if (strcmp(type->buf, "text/plain"))
232 strbuf_reencode(msg, charset->buf, get_log_output_encoding());
240 eol = strchrnul(p, '\n');
241 fprintf(stderr, "remote: %.*s\n", (int)(eol - p), p);
247 static struct discovery *discover_refs(const char *service, int for_push)
249 struct strbuf exp = STRBUF_INIT;
250 struct strbuf type = STRBUF_INIT;
251 struct strbuf charset = STRBUF_INIT;
252 struct strbuf buffer = STRBUF_INIT;
253 struct strbuf refs_url = STRBUF_INIT;
254 struct strbuf effective_url = STRBUF_INIT;
255 struct discovery *last = last_discovery;
256 int http_ret, maybe_smart = 0;
257 struct http_get_options options;
259 if (last && !strcmp(service, last->service))
261 free_discovery(last);
263 strbuf_addf(&refs_url, "%sinfo/refs", url.buf);
264 if ((starts_with(url.buf, "http://") || starts_with(url.buf, "https://")) &&
265 git_env_bool("GIT_SMART_HTTP", 1)) {
267 if (!strchr(url.buf, '?'))
268 strbuf_addch(&refs_url, '?');
270 strbuf_addch(&refs_url, '&');
271 strbuf_addf(&refs_url, "service=%s", service);
274 memset(&options, 0, sizeof(options));
275 options.content_type = &type;
276 options.charset = &charset;
277 options.effective_url = &effective_url;
278 options.base_url = &url;
279 options.no_cache = 1;
280 options.keep_error = 1;
282 http_ret = http_get_strbuf(refs_url.buf, &buffer, &options);
286 case HTTP_MISSING_TARGET:
287 show_http_message(&type, &charset, &buffer);
288 die("repository '%s' not found", url.buf);
290 show_http_message(&type, &charset, &buffer);
291 die("Authentication failed for '%s'", url.buf);
293 show_http_message(&type, &charset, &buffer);
294 die("unable to access '%s': %s", url.buf, curl_errorstr);
297 last= xcalloc(1, sizeof(*last_discovery));
298 last->service = service;
299 last->buf_alloc = strbuf_detach(&buffer, &last->len);
300 last->buf = last->buf_alloc;
302 strbuf_addf(&exp, "application/x-%s-advertisement", service);
304 (5 <= last->len && last->buf[4] == '#') &&
305 !strbuf_cmp(&exp, &type)) {
309 * smart HTTP response; validate that the service
310 * pkt-line matches our request.
312 line = packet_read_line_buf(&last->buf, &last->len, NULL);
315 strbuf_addf(&exp, "# service=%s", service);
316 if (strcmp(line, exp.buf))
317 die("invalid server response; got '%s'", line);
318 strbuf_release(&exp);
320 /* The header can include additional metadata lines, up
321 * until a packet flush marker. Ignore these now, but
322 * in the future we might start to scan them.
324 while (packet_read_line_buf(&last->buf, &last->len, NULL))
331 last->refs = parse_git_refs(last, for_push);
333 last->refs = parse_info_refs(last);
335 strbuf_release(&refs_url);
336 strbuf_release(&exp);
337 strbuf_release(&type);
338 strbuf_release(&charset);
339 strbuf_release(&effective_url);
340 strbuf_release(&buffer);
341 last_discovery = last;
345 static struct ref *get_refs(int for_push)
347 struct discovery *heads;
350 heads = discover_refs("git-receive-pack", for_push);
352 heads = discover_refs("git-upload-pack", for_push);
357 static void output_refs(struct ref *refs)
360 for (posn = refs; posn; posn = posn->next) {
362 printf("@%s %s\n", posn->symref, posn->name);
364 printf("%s %s\n", oid_to_hex(&posn->old_oid), posn->name);
371 const char *service_name;
373 struct strbuf *stdin_preamble;
375 char *hdr_content_type;
383 struct strbuf result;
384 unsigned gzip_request : 1;
385 unsigned initial_buffer : 1;
388 static size_t rpc_out(void *ptr, size_t eltsize,
389 size_t nmemb, void *buffer_)
391 size_t max = eltsize * nmemb;
392 struct rpc_state *rpc = buffer_;
393 size_t avail = rpc->len - rpc->pos;
396 rpc->initial_buffer = 0;
397 avail = packet_read(rpc->out, NULL, NULL, rpc->buf, rpc->alloc, 0);
406 memcpy(ptr, rpc->buf + rpc->pos, avail);
411 #ifndef NO_CURL_IOCTL
412 static curlioerr rpc_ioctl(CURL *handle, int cmd, void *clientp)
414 struct rpc_state *rpc = clientp;
420 case CURLIOCMD_RESTARTREAD:
421 if (rpc->initial_buffer) {
425 error("unable to rewind rpc post data - try increasing http.postBuffer");
426 return CURLIOE_FAILRESTART;
429 return CURLIOE_UNKNOWNCMD;
434 static size_t rpc_in(char *ptr, size_t eltsize,
435 size_t nmemb, void *buffer_)
437 size_t size = eltsize * nmemb;
438 struct rpc_state *rpc = buffer_;
439 write_or_die(rpc->in, ptr, size);
443 static int run_slot(struct active_request_slot *slot,
444 struct slot_results *results)
447 struct slot_results results_buf;
450 results = &results_buf;
452 err = run_one_slot(slot, results);
454 if (err != HTTP_OK && err != HTTP_REAUTH) {
455 struct strbuf msg = STRBUF_INIT;
456 if (results->http_code && results->http_code != 200)
457 strbuf_addf(&msg, "HTTP %ld", results->http_code);
458 if (results->curl_result != CURLE_OK) {
460 strbuf_addch(&msg, ' ');
461 strbuf_addf(&msg, "curl %d", results->curl_result);
462 if (curl_errorstr[0]) {
463 strbuf_addch(&msg, ' ');
464 strbuf_addstr(&msg, curl_errorstr);
467 error("RPC failed; %s", msg.buf);
468 strbuf_release(&msg);
474 static int probe_rpc(struct rpc_state *rpc, struct slot_results *results)
476 struct active_request_slot *slot;
477 struct curl_slist *headers = http_copy_default_headers();
478 struct strbuf buf = STRBUF_INIT;
481 slot = get_active_slot();
483 headers = curl_slist_append(headers, rpc->hdr_content_type);
484 headers = curl_slist_append(headers, rpc->hdr_accept);
486 curl_easy_setopt(slot->curl, CURLOPT_NOBODY, 0);
487 curl_easy_setopt(slot->curl, CURLOPT_POST, 1);
488 curl_easy_setopt(slot->curl, CURLOPT_URL, rpc->service_url);
489 curl_easy_setopt(slot->curl, CURLOPT_ENCODING, NULL);
490 curl_easy_setopt(slot->curl, CURLOPT_POSTFIELDS, "0000");
491 curl_easy_setopt(slot->curl, CURLOPT_POSTFIELDSIZE, 4);
492 curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, headers);
493 curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_buffer);
494 curl_easy_setopt(slot->curl, CURLOPT_FILE, &buf);
496 err = run_slot(slot, results);
498 curl_slist_free_all(headers);
499 strbuf_release(&buf);
503 static int post_rpc(struct rpc_state *rpc)
505 struct active_request_slot *slot;
506 struct curl_slist *headers = http_copy_default_headers();
507 int use_gzip = rpc->gzip_request;
508 char *gzip_body = NULL;
509 size_t gzip_size = 0;
510 int err, large_request = 0;
511 int needs_100_continue = 0;
513 /* Try to load the entire request, if we can fit it into the
514 * allocated buffer space we can use HTTP/1.0 and avoid the
515 * chunked encoding mess.
518 size_t left = rpc->alloc - rpc->len;
519 char *buf = rpc->buf + rpc->len;
522 if (left < LARGE_PACKET_MAX) {
528 n = packet_read(rpc->out, NULL, NULL, buf, left, 0);
535 struct slot_results results;
538 err = probe_rpc(rpc, &results);
539 if (err == HTTP_REAUTH)
540 credential_fill(&http_auth);
541 } while (err == HTTP_REAUTH);
545 if (results.auth_avail & CURLAUTH_GSSNEGOTIATE)
546 needs_100_continue = 1;
549 headers = curl_slist_append(headers, rpc->hdr_content_type);
550 headers = curl_slist_append(headers, rpc->hdr_accept);
551 headers = curl_slist_append(headers, needs_100_continue ?
552 "Expect: 100-continue" : "Expect:");
555 slot = get_active_slot();
557 curl_easy_setopt(slot->curl, CURLOPT_NOBODY, 0);
558 curl_easy_setopt(slot->curl, CURLOPT_POST, 1);
559 curl_easy_setopt(slot->curl, CURLOPT_URL, rpc->service_url);
560 curl_easy_setopt(slot->curl, CURLOPT_ENCODING, "gzip");
563 /* The request body is large and the size cannot be predicted.
564 * We must use chunked encoding to send it.
566 headers = curl_slist_append(headers, "Transfer-Encoding: chunked");
567 rpc->initial_buffer = 1;
568 curl_easy_setopt(slot->curl, CURLOPT_READFUNCTION, rpc_out);
569 curl_easy_setopt(slot->curl, CURLOPT_INFILE, rpc);
570 #ifndef NO_CURL_IOCTL
571 curl_easy_setopt(slot->curl, CURLOPT_IOCTLFUNCTION, rpc_ioctl);
572 curl_easy_setopt(slot->curl, CURLOPT_IOCTLDATA, rpc);
574 if (options.verbosity > 1) {
575 fprintf(stderr, "POST %s (chunked)\n", rpc->service_name);
579 } else if (gzip_body) {
581 * If we are looping to retry authentication, then the previous
582 * run will have set up the headers and gzip buffer already,
583 * and we just need to send it.
585 curl_easy_setopt(slot->curl, CURLOPT_POSTFIELDS, gzip_body);
586 curl_easy_setopt(slot->curl, CURLOPT_POSTFIELDSIZE, gzip_size);
588 } else if (use_gzip && 1024 < rpc->len) {
589 /* The client backend isn't giving us compressed data so
590 * we can try to deflate it ourselves, this may save on.
596 git_deflate_init_gzip(&stream, Z_BEST_COMPRESSION);
597 gzip_size = git_deflate_bound(&stream, rpc->len);
598 gzip_body = xmalloc(gzip_size);
600 stream.next_in = (unsigned char *)rpc->buf;
601 stream.avail_in = rpc->len;
602 stream.next_out = (unsigned char *)gzip_body;
603 stream.avail_out = gzip_size;
605 ret = git_deflate(&stream, Z_FINISH);
606 if (ret != Z_STREAM_END)
607 die("cannot deflate request; zlib deflate error %d", ret);
609 ret = git_deflate_end_gently(&stream);
611 die("cannot deflate request; zlib end error %d", ret);
613 gzip_size = stream.total_out;
615 headers = curl_slist_append(headers, "Content-Encoding: gzip");
616 curl_easy_setopt(slot->curl, CURLOPT_POSTFIELDS, gzip_body);
617 curl_easy_setopt(slot->curl, CURLOPT_POSTFIELDSIZE, gzip_size);
619 if (options.verbosity > 1) {
620 fprintf(stderr, "POST %s (gzip %lu to %lu bytes)\n",
622 (unsigned long)rpc->len, (unsigned long)gzip_size);
626 /* We know the complete request size in advance, use the
627 * more normal Content-Length approach.
629 curl_easy_setopt(slot->curl, CURLOPT_POSTFIELDS, rpc->buf);
630 curl_easy_setopt(slot->curl, CURLOPT_POSTFIELDSIZE, rpc->len);
631 if (options.verbosity > 1) {
632 fprintf(stderr, "POST %s (%lu bytes)\n",
633 rpc->service_name, (unsigned long)rpc->len);
638 curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, headers);
639 curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, rpc_in);
640 curl_easy_setopt(slot->curl, CURLOPT_FILE, rpc);
642 err = run_slot(slot, NULL);
643 if (err == HTTP_REAUTH && !large_request) {
644 credential_fill(&http_auth);
650 curl_slist_free_all(headers);
655 static int rpc_service(struct rpc_state *rpc, struct discovery *heads)
657 const char *svc = rpc->service_name;
658 struct strbuf buf = STRBUF_INIT;
659 struct strbuf *preamble = rpc->stdin_preamble;
660 struct child_process client = CHILD_PROCESS_INIT;
666 client.argv = rpc->argv;
667 if (start_command(&client))
670 write_or_die(client.in, preamble->buf, preamble->len);
672 write_or_die(client.in, heads->buf, heads->len);
674 rpc->alloc = http_post_buffer;
675 rpc->buf = xmalloc(rpc->alloc);
677 rpc->out = client.out;
678 strbuf_init(&rpc->result, 0);
680 strbuf_addf(&buf, "%s%s", url.buf, svc);
681 rpc->service_url = strbuf_detach(&buf, NULL);
683 strbuf_addf(&buf, "Content-Type: application/x-%s-request", svc);
684 rpc->hdr_content_type = strbuf_detach(&buf, NULL);
686 strbuf_addf(&buf, "Accept: application/x-%s-result", svc);
687 rpc->hdr_accept = strbuf_detach(&buf, NULL);
690 int n = packet_read(rpc->out, NULL, NULL, rpc->buf, rpc->alloc, 0);
695 err |= post_rpc(rpc);
701 strbuf_read(&rpc->result, client.out, 0);
705 if (xread(client.out, buf, sizeof(buf)) <= 0)
712 err |= finish_command(&client);
713 free(rpc->service_url);
714 free(rpc->hdr_content_type);
715 free(rpc->hdr_accept);
717 strbuf_release(&buf);
721 static int fetch_dumb(int nr_heads, struct ref **to_fetch)
723 struct walker *walker;
727 ALLOC_ARRAY(targets, nr_heads);
729 die("dumb http transport does not support --depth");
730 for (i = 0; i < nr_heads; i++)
731 targets[i] = xstrdup(oid_to_hex(&to_fetch[i]->old_oid));
733 walker = get_http_walker(url.buf);
735 walker->get_tree = 1;
736 walker->get_history = 1;
737 walker->get_verbosely = options.verbosity >= 3;
738 walker->get_recover = 0;
739 ret = walker_fetch(walker, nr_heads, targets, NULL, NULL);
742 for (i = 0; i < nr_heads; i++)
746 return ret ? error("fetch failed.") : 0;
749 static int fetch_git(struct discovery *heads,
750 int nr_heads, struct ref **to_fetch)
752 struct rpc_state rpc;
753 struct strbuf preamble = STRBUF_INIT;
754 char *depth_arg = NULL;
755 int argc = 0, i, err;
756 const char *argv[17];
758 argv[argc++] = "fetch-pack";
759 argv[argc++] = "--stateless-rpc";
760 argv[argc++] = "--stdin";
761 argv[argc++] = "--lock-pack";
762 if (options.followtags)
763 argv[argc++] = "--include-tag";
765 argv[argc++] = "--thin";
766 if (options.verbosity >= 3) {
770 if (options.check_self_contained_and_connected)
771 argv[argc++] = "--check-self-contained-and-connected";
773 argv[argc++] = "--cloning";
774 if (options.update_shallow)
775 argv[argc++] = "--update-shallow";
776 if (!options.progress)
777 argv[argc++] = "--no-progress";
779 struct strbuf buf = STRBUF_INIT;
780 strbuf_addf(&buf, "--depth=%lu", options.depth);
781 depth_arg = strbuf_detach(&buf, NULL);
782 argv[argc++] = depth_arg;
784 argv[argc++] = url.buf;
787 for (i = 0; i < nr_heads; i++) {
788 struct ref *ref = to_fetch[i];
790 die("cannot fetch by sha1 over smart http");
791 packet_buf_write(&preamble, "%s %s\n",
792 oid_to_hex(&ref->old_oid), ref->name);
794 packet_buf_flush(&preamble);
796 memset(&rpc, 0, sizeof(rpc));
797 rpc.service_name = "git-upload-pack",
799 rpc.stdin_preamble = &preamble;
800 rpc.gzip_request = 1;
802 err = rpc_service(&rpc, heads);
804 write_or_die(1, rpc.result.buf, rpc.result.len);
805 strbuf_release(&rpc.result);
806 strbuf_release(&preamble);
811 static int fetch(int nr_heads, struct ref **to_fetch)
813 struct discovery *d = discover_refs("git-upload-pack", 0);
815 return fetch_git(d, nr_heads, to_fetch);
817 return fetch_dumb(nr_heads, to_fetch);
820 static void parse_fetch(struct strbuf *buf)
822 struct ref **to_fetch = NULL;
823 struct ref *list_head = NULL;
824 struct ref **list = &list_head;
825 int alloc_heads = 0, nr_heads = 0;
829 if (skip_prefix(buf->buf, "fetch ", &p)) {
832 struct object_id old_oid;
834 if (get_oid_hex(p, &old_oid))
835 die("protocol error: expected sha/ref, got %s'", p);
836 if (p[GIT_SHA1_HEXSZ] == ' ')
837 name = p + GIT_SHA1_HEXSZ + 1;
838 else if (!p[GIT_SHA1_HEXSZ])
841 die("protocol error: expected sha/ref, got %s'", p);
843 ref = alloc_ref(name);
844 oidcpy(&ref->old_oid, &old_oid);
849 ALLOC_GROW(to_fetch, nr_heads + 1, alloc_heads);
850 to_fetch[nr_heads++] = ref;
853 die("http transport does not support %s", buf->buf);
856 if (strbuf_getline_lf(buf, stdin) == EOF)
862 if (fetch(nr_heads, to_fetch))
863 exit(128); /* error already reported */
864 free_refs(list_head);
872 static int push_dav(int nr_spec, char **specs)
874 struct child_process child = CHILD_PROCESS_INIT;
878 argv_array_push(&child.args, "http-push");
879 argv_array_push(&child.args, "--helper-status");
881 argv_array_push(&child.args, "--dry-run");
882 if (options.verbosity > 1)
883 argv_array_push(&child.args, "--verbose");
884 argv_array_push(&child.args, url.buf);
885 for (i = 0; i < nr_spec; i++)
886 argv_array_push(&child.args, specs[i]);
888 if (run_command(&child))
889 die("git-http-push failed");
893 static int push_git(struct discovery *heads, int nr_spec, char **specs)
895 struct rpc_state rpc;
897 struct argv_array args;
898 struct string_list_item *cas_option;
899 struct strbuf preamble = STRBUF_INIT;
901 argv_array_init(&args);
902 argv_array_pushl(&args, "send-pack", "--stateless-rpc", "--helper-status",
906 argv_array_push(&args, "--thin");
908 argv_array_push(&args, "--dry-run");
909 if (options.push_cert == SEND_PACK_PUSH_CERT_ALWAYS)
910 argv_array_push(&args, "--signed=yes");
911 else if (options.push_cert == SEND_PACK_PUSH_CERT_IF_ASKED)
912 argv_array_push(&args, "--signed=if-asked");
913 if (options.verbosity == 0)
914 argv_array_push(&args, "--quiet");
915 else if (options.verbosity > 1)
916 argv_array_push(&args, "--verbose");
917 argv_array_push(&args, options.progress ? "--progress" : "--no-progress");
918 for_each_string_list_item(cas_option, &cas_options)
919 argv_array_push(&args, cas_option->string);
920 argv_array_push(&args, url.buf);
922 argv_array_push(&args, "--stdin");
923 for (i = 0; i < nr_spec; i++)
924 packet_buf_write(&preamble, "%s\n", specs[i]);
925 packet_buf_flush(&preamble);
927 memset(&rpc, 0, sizeof(rpc));
928 rpc.service_name = "git-receive-pack",
929 rpc.argv = args.argv;
930 rpc.stdin_preamble = &preamble;
932 err = rpc_service(&rpc, heads);
934 write_or_die(1, rpc.result.buf, rpc.result.len);
935 strbuf_release(&rpc.result);
936 strbuf_release(&preamble);
937 argv_array_clear(&args);
941 static int push(int nr_spec, char **specs)
943 struct discovery *heads = discover_refs("git-receive-pack", 1);
946 if (heads->proto_git)
947 ret = push_git(heads, nr_spec, specs);
949 ret = push_dav(nr_spec, specs);
950 free_discovery(heads);
954 static void parse_push(struct strbuf *buf)
957 int alloc_spec = 0, nr_spec = 0, i, ret;
960 if (starts_with(buf->buf, "push ")) {
961 ALLOC_GROW(specs, nr_spec + 1, alloc_spec);
962 specs[nr_spec++] = xstrdup(buf->buf + 5);
965 die("http transport does not support %s", buf->buf);
968 if (strbuf_getline_lf(buf, stdin) == EOF)
974 ret = push(nr_spec, specs);
979 exit(128); /* error already reported */
982 for (i = 0; i < nr_spec; i++)
987 int main(int argc, const char **argv)
989 struct strbuf buf = STRBUF_INIT;
994 git_extract_argv0_path(argv[0]);
995 setup_git_directory_gently(&nongit);
997 error("remote-curl: usage: git remote-curl <remote> [<url>]");
1001 options.verbosity = 1;
1002 options.progress = !!isatty(2);
1005 remote = remote_get(argv[1]);
1008 end_url_with_slash(&url, argv[2]);
1010 end_url_with_slash(&url, remote->url[0]);
1013 http_init(remote, url.buf, 0);
1018 if (strbuf_getline_lf(&buf, stdin) == EOF) {
1020 error("remote-curl: error reading command stream from git");
1025 if (starts_with(buf.buf, "fetch ")) {
1027 die("remote-curl: fetch attempted without a local repo");
1030 } else if (!strcmp(buf.buf, "list") || starts_with(buf.buf, "list ")) {
1031 int for_push = !!strstr(buf.buf + 4, "for-push");
1032 output_refs(get_refs(for_push));
1034 } else if (starts_with(buf.buf, "push ")) {
1037 } else if (skip_prefix(buf.buf, "option ", &arg)) {
1038 char *value = strchr(arg, ' ');
1046 result = set_option(arg, value);
1049 else if (result < 0)
1050 printf("error invalid value\n");
1052 printf("unsupported\n");
1055 } else if (!strcmp(buf.buf, "capabilities")) {
1059 printf("check-connectivity\n");
1063 error("remote-curl: unknown command '%s' from git", buf.buf);