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;
24 struct string_list deepen_not;
25 unsigned progress : 1,
26 check_self_contained_and_connected : 1,
32 /* One of the SEND_PACK_PUSH_CERT_* constants. */
36 static struct options options;
37 static struct string_list cas_options = STRING_LIST_INIT_DUP;
39 static int set_option(const char *name, const char *value)
41 if (!strcmp(name, "verbosity")) {
43 int v = strtol(value, &end, 10);
44 if (value == end || *end)
46 options.verbosity = v;
49 else if (!strcmp(name, "progress")) {
50 if (!strcmp(value, "true"))
52 else if (!strcmp(value, "false"))
58 else if (!strcmp(name, "depth")) {
60 unsigned long v = strtoul(value, &end, 10);
61 if (value == end || *end)
66 else if (!strcmp(name, "deepen-since")) {
67 options.deepen_since = xstrdup(value);
70 else if (!strcmp(name, "deepen-not")) {
71 string_list_append(&options.deepen_not, value);
74 else if (!strcmp(name, "deepen-relative")) {
75 if (!strcmp(value, "true"))
76 options.deepen_relative = 1;
77 else if (!strcmp(value, "false"))
78 options.deepen_relative = 0;
83 else if (!strcmp(name, "followtags")) {
84 if (!strcmp(value, "true"))
85 options.followtags = 1;
86 else if (!strcmp(value, "false"))
87 options.followtags = 0;
92 else if (!strcmp(name, "dry-run")) {
93 if (!strcmp(value, "true"))
95 else if (!strcmp(value, "false"))
101 else if (!strcmp(name, "check-connectivity")) {
102 if (!strcmp(value, "true"))
103 options.check_self_contained_and_connected = 1;
104 else if (!strcmp(value, "false"))
105 options.check_self_contained_and_connected = 0;
110 else if (!strcmp(name, "cas")) {
111 struct strbuf val = STRBUF_INIT;
112 strbuf_addf(&val, "--" CAS_OPT_NAME "=%s", value);
113 string_list_append(&cas_options, val.buf);
114 strbuf_release(&val);
116 } else if (!strcmp(name, "cloning")) {
117 if (!strcmp(value, "true"))
119 else if (!strcmp(value, "false"))
124 } else if (!strcmp(name, "update-shallow")) {
125 if (!strcmp(value, "true"))
126 options.update_shallow = 1;
127 else if (!strcmp(value, "false"))
128 options.update_shallow = 0;
132 } else if (!strcmp(name, "pushcert")) {
133 if (!strcmp(value, "true"))
134 options.push_cert = SEND_PACK_PUSH_CERT_ALWAYS;
135 else if (!strcmp(value, "false"))
136 options.push_cert = SEND_PACK_PUSH_CERT_NEVER;
137 else if (!strcmp(value, "if-asked"))
138 options.push_cert = SEND_PACK_PUSH_CERT_IF_ASKED;
143 return 1 /* unsupported */;
153 struct sha1_array shallow;
154 unsigned proto_git : 1;
156 static struct discovery *last_discovery;
158 static struct ref *parse_git_refs(struct discovery *heads, int for_push)
160 struct ref *list = NULL;
161 get_remote_heads(-1, heads->buf, heads->len, &list,
162 for_push ? REF_NORMAL : 0, NULL, &heads->shallow);
166 static struct ref *parse_info_refs(struct discovery *heads)
168 char *data, *start, *mid;
172 struct ref *refs = NULL;
173 struct ref *ref = NULL;
174 struct ref *last_ref = NULL;
179 while (i < heads->len) {
185 if (data[i] == '\n') {
186 if (mid - start != 40)
187 die("%sinfo/refs not valid: is this a git repository?",
191 ref = alloc_ref(ref_name);
192 get_oid_hex(start, &ref->old_oid);
196 last_ref->next = ref;
203 ref = alloc_ref("HEAD");
204 if (!http_fetch_ref(url.buf, ref) &&
205 !resolve_remote_symref(ref, refs)) {
215 static void free_discovery(struct discovery *d)
218 if (d == last_discovery)
219 last_discovery = NULL;
220 free(d->shallow.sha1);
227 static int show_http_message(struct strbuf *type, struct strbuf *charset,
233 * We only show text/plain parts, as other types are likely
234 * to be ugly to look at on the user's terminal.
236 if (strcmp(type->buf, "text/plain"))
239 strbuf_reencode(msg, charset->buf, get_log_output_encoding());
247 eol = strchrnul(p, '\n');
248 fprintf(stderr, "remote: %.*s\n", (int)(eol - p), p);
254 static struct discovery *discover_refs(const char *service, int for_push)
256 struct strbuf exp = STRBUF_INIT;
257 struct strbuf type = STRBUF_INIT;
258 struct strbuf charset = STRBUF_INIT;
259 struct strbuf buffer = STRBUF_INIT;
260 struct strbuf refs_url = STRBUF_INIT;
261 struct strbuf effective_url = STRBUF_INIT;
262 struct discovery *last = last_discovery;
263 int http_ret, maybe_smart = 0;
264 struct http_get_options options;
266 if (last && !strcmp(service, last->service))
268 free_discovery(last);
270 strbuf_addf(&refs_url, "%sinfo/refs", url.buf);
271 if ((starts_with(url.buf, "http://") || starts_with(url.buf, "https://")) &&
272 git_env_bool("GIT_SMART_HTTP", 1)) {
274 if (!strchr(url.buf, '?'))
275 strbuf_addch(&refs_url, '?');
277 strbuf_addch(&refs_url, '&');
278 strbuf_addf(&refs_url, "service=%s", service);
281 memset(&options, 0, sizeof(options));
282 options.content_type = &type;
283 options.charset = &charset;
284 options.effective_url = &effective_url;
285 options.base_url = &url;
286 options.no_cache = 1;
287 options.keep_error = 1;
289 http_ret = http_get_strbuf(refs_url.buf, &buffer, &options);
293 case HTTP_MISSING_TARGET:
294 show_http_message(&type, &charset, &buffer);
295 die("repository '%s' not found", url.buf);
297 show_http_message(&type, &charset, &buffer);
298 die("Authentication failed for '%s'", url.buf);
300 show_http_message(&type, &charset, &buffer);
301 die("unable to access '%s': %s", url.buf, curl_errorstr);
304 last= xcalloc(1, sizeof(*last_discovery));
305 last->service = service;
306 last->buf_alloc = strbuf_detach(&buffer, &last->len);
307 last->buf = last->buf_alloc;
309 strbuf_addf(&exp, "application/x-%s-advertisement", service);
311 (5 <= last->len && last->buf[4] == '#') &&
312 !strbuf_cmp(&exp, &type)) {
316 * smart HTTP response; validate that the service
317 * pkt-line matches our request.
319 line = packet_read_line_buf(&last->buf, &last->len, NULL);
322 strbuf_addf(&exp, "# service=%s", service);
323 if (strcmp(line, exp.buf))
324 die("invalid server response; got '%s'", line);
325 strbuf_release(&exp);
327 /* The header can include additional metadata lines, up
328 * until a packet flush marker. Ignore these now, but
329 * in the future we might start to scan them.
331 while (packet_read_line_buf(&last->buf, &last->len, NULL))
338 last->refs = parse_git_refs(last, for_push);
340 last->refs = parse_info_refs(last);
342 strbuf_release(&refs_url);
343 strbuf_release(&exp);
344 strbuf_release(&type);
345 strbuf_release(&charset);
346 strbuf_release(&effective_url);
347 strbuf_release(&buffer);
348 last_discovery = last;
352 static struct ref *get_refs(int for_push)
354 struct discovery *heads;
357 heads = discover_refs("git-receive-pack", for_push);
359 heads = discover_refs("git-upload-pack", for_push);
364 static void output_refs(struct ref *refs)
367 for (posn = refs; posn; posn = posn->next) {
369 printf("@%s %s\n", posn->symref, posn->name);
371 printf("%s %s\n", oid_to_hex(&posn->old_oid), posn->name);
378 const char *service_name;
380 struct strbuf *stdin_preamble;
382 char *hdr_content_type;
390 struct strbuf result;
391 unsigned gzip_request : 1;
392 unsigned initial_buffer : 1;
395 static size_t rpc_out(void *ptr, size_t eltsize,
396 size_t nmemb, void *buffer_)
398 size_t max = eltsize * nmemb;
399 struct rpc_state *rpc = buffer_;
400 size_t avail = rpc->len - rpc->pos;
403 rpc->initial_buffer = 0;
404 avail = packet_read(rpc->out, NULL, NULL, rpc->buf, rpc->alloc, 0);
413 memcpy(ptr, rpc->buf + rpc->pos, avail);
418 #ifndef NO_CURL_IOCTL
419 static curlioerr rpc_ioctl(CURL *handle, int cmd, void *clientp)
421 struct rpc_state *rpc = clientp;
427 case CURLIOCMD_RESTARTREAD:
428 if (rpc->initial_buffer) {
432 error("unable to rewind rpc post data - try increasing http.postBuffer");
433 return CURLIOE_FAILRESTART;
436 return CURLIOE_UNKNOWNCMD;
441 static size_t rpc_in(char *ptr, size_t eltsize,
442 size_t nmemb, void *buffer_)
444 size_t size = eltsize * nmemb;
445 struct rpc_state *rpc = buffer_;
446 write_or_die(rpc->in, ptr, size);
450 static int run_slot(struct active_request_slot *slot,
451 struct slot_results *results)
454 struct slot_results results_buf;
457 results = &results_buf;
459 err = run_one_slot(slot, results);
461 if (err != HTTP_OK && err != HTTP_REAUTH) {
462 error("RPC failed; result=%d, HTTP code = %ld",
463 results->curl_result, results->http_code);
469 static int probe_rpc(struct rpc_state *rpc, struct slot_results *results)
471 struct active_request_slot *slot;
472 struct curl_slist *headers = NULL;
473 struct strbuf buf = STRBUF_INIT;
476 slot = get_active_slot();
478 headers = curl_slist_append(headers, rpc->hdr_content_type);
479 headers = curl_slist_append(headers, rpc->hdr_accept);
481 curl_easy_setopt(slot->curl, CURLOPT_NOBODY, 0);
482 curl_easy_setopt(slot->curl, CURLOPT_POST, 1);
483 curl_easy_setopt(slot->curl, CURLOPT_URL, rpc->service_url);
484 curl_easy_setopt(slot->curl, CURLOPT_ENCODING, NULL);
485 curl_easy_setopt(slot->curl, CURLOPT_POSTFIELDS, "0000");
486 curl_easy_setopt(slot->curl, CURLOPT_POSTFIELDSIZE, 4);
487 curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, headers);
488 curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_buffer);
489 curl_easy_setopt(slot->curl, CURLOPT_FILE, &buf);
491 err = run_slot(slot, results);
493 curl_slist_free_all(headers);
494 strbuf_release(&buf);
498 static int post_rpc(struct rpc_state *rpc)
500 struct active_request_slot *slot;
501 struct curl_slist *headers = NULL;
502 int use_gzip = rpc->gzip_request;
503 char *gzip_body = NULL;
504 size_t gzip_size = 0;
505 int err, large_request = 0;
506 int needs_100_continue = 0;
508 /* Try to load the entire request, if we can fit it into the
509 * allocated buffer space we can use HTTP/1.0 and avoid the
510 * chunked encoding mess.
513 size_t left = rpc->alloc - rpc->len;
514 char *buf = rpc->buf + rpc->len;
517 if (left < LARGE_PACKET_MAX) {
523 n = packet_read(rpc->out, NULL, NULL, buf, left, 0);
530 struct slot_results results;
533 err = probe_rpc(rpc, &results);
534 if (err == HTTP_REAUTH)
535 credential_fill(&http_auth);
536 } while (err == HTTP_REAUTH);
540 if (results.auth_avail & CURLAUTH_GSSNEGOTIATE)
541 needs_100_continue = 1;
544 headers = curl_slist_append(headers, rpc->hdr_content_type);
545 headers = curl_slist_append(headers, rpc->hdr_accept);
546 headers = curl_slist_append(headers, needs_100_continue ?
547 "Expect: 100-continue" : "Expect:");
550 slot = get_active_slot();
552 curl_easy_setopt(slot->curl, CURLOPT_NOBODY, 0);
553 curl_easy_setopt(slot->curl, CURLOPT_POST, 1);
554 curl_easy_setopt(slot->curl, CURLOPT_URL, rpc->service_url);
555 curl_easy_setopt(slot->curl, CURLOPT_ENCODING, "gzip");
558 /* The request body is large and the size cannot be predicted.
559 * We must use chunked encoding to send it.
561 headers = curl_slist_append(headers, "Transfer-Encoding: chunked");
562 rpc->initial_buffer = 1;
563 curl_easy_setopt(slot->curl, CURLOPT_READFUNCTION, rpc_out);
564 curl_easy_setopt(slot->curl, CURLOPT_INFILE, rpc);
565 #ifndef NO_CURL_IOCTL
566 curl_easy_setopt(slot->curl, CURLOPT_IOCTLFUNCTION, rpc_ioctl);
567 curl_easy_setopt(slot->curl, CURLOPT_IOCTLDATA, rpc);
569 if (options.verbosity > 1) {
570 fprintf(stderr, "POST %s (chunked)\n", rpc->service_name);
574 } else if (gzip_body) {
576 * If we are looping to retry authentication, then the previous
577 * run will have set up the headers and gzip buffer already,
578 * and we just need to send it.
580 curl_easy_setopt(slot->curl, CURLOPT_POSTFIELDS, gzip_body);
581 curl_easy_setopt(slot->curl, CURLOPT_POSTFIELDSIZE, gzip_size);
583 } else if (use_gzip && 1024 < rpc->len) {
584 /* The client backend isn't giving us compressed data so
585 * we can try to deflate it ourselves, this may save on.
591 git_deflate_init_gzip(&stream, Z_BEST_COMPRESSION);
592 gzip_size = git_deflate_bound(&stream, rpc->len);
593 gzip_body = xmalloc(gzip_size);
595 stream.next_in = (unsigned char *)rpc->buf;
596 stream.avail_in = rpc->len;
597 stream.next_out = (unsigned char *)gzip_body;
598 stream.avail_out = gzip_size;
600 ret = git_deflate(&stream, Z_FINISH);
601 if (ret != Z_STREAM_END)
602 die("cannot deflate request; zlib deflate error %d", ret);
604 ret = git_deflate_end_gently(&stream);
606 die("cannot deflate request; zlib end error %d", ret);
608 gzip_size = stream.total_out;
610 headers = curl_slist_append(headers, "Content-Encoding: gzip");
611 curl_easy_setopt(slot->curl, CURLOPT_POSTFIELDS, gzip_body);
612 curl_easy_setopt(slot->curl, CURLOPT_POSTFIELDSIZE, gzip_size);
614 if (options.verbosity > 1) {
615 fprintf(stderr, "POST %s (gzip %lu to %lu bytes)\n",
617 (unsigned long)rpc->len, (unsigned long)gzip_size);
621 /* We know the complete request size in advance, use the
622 * more normal Content-Length approach.
624 curl_easy_setopt(slot->curl, CURLOPT_POSTFIELDS, rpc->buf);
625 curl_easy_setopt(slot->curl, CURLOPT_POSTFIELDSIZE, rpc->len);
626 if (options.verbosity > 1) {
627 fprintf(stderr, "POST %s (%lu bytes)\n",
628 rpc->service_name, (unsigned long)rpc->len);
633 curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, headers);
634 curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, rpc_in);
635 curl_easy_setopt(slot->curl, CURLOPT_FILE, rpc);
637 err = run_slot(slot, NULL);
638 if (err == HTTP_REAUTH && !large_request) {
639 credential_fill(&http_auth);
645 curl_slist_free_all(headers);
650 static int rpc_service(struct rpc_state *rpc, struct discovery *heads)
652 const char *svc = rpc->service_name;
653 struct strbuf buf = STRBUF_INIT;
654 struct strbuf *preamble = rpc->stdin_preamble;
655 struct child_process client = CHILD_PROCESS_INIT;
661 client.argv = rpc->argv;
662 if (start_command(&client))
665 write_or_die(client.in, preamble->buf, preamble->len);
667 write_or_die(client.in, heads->buf, heads->len);
669 rpc->alloc = http_post_buffer;
670 rpc->buf = xmalloc(rpc->alloc);
672 rpc->out = client.out;
673 strbuf_init(&rpc->result, 0);
675 strbuf_addf(&buf, "%s%s", url.buf, svc);
676 rpc->service_url = strbuf_detach(&buf, NULL);
678 strbuf_addf(&buf, "Content-Type: application/x-%s-request", svc);
679 rpc->hdr_content_type = strbuf_detach(&buf, NULL);
681 strbuf_addf(&buf, "Accept: application/x-%s-result", svc);
682 rpc->hdr_accept = strbuf_detach(&buf, NULL);
685 int n = packet_read(rpc->out, NULL, NULL, rpc->buf, rpc->alloc, 0);
690 err |= post_rpc(rpc);
696 strbuf_read(&rpc->result, client.out, 0);
700 if (xread(client.out, buf, sizeof(buf)) <= 0)
707 err |= finish_command(&client);
708 free(rpc->service_url);
709 free(rpc->hdr_content_type);
710 free(rpc->hdr_accept);
712 strbuf_release(&buf);
716 static int fetch_dumb(int nr_heads, struct ref **to_fetch)
718 struct walker *walker;
719 char **targets = xmalloc(nr_heads * sizeof(char*));
722 if (options.depth || options.deepen_since)
723 die("dumb http transport does not support shallow capabilities");
724 for (i = 0; i < nr_heads; i++)
725 targets[i] = xstrdup(oid_to_hex(&to_fetch[i]->old_oid));
727 walker = get_http_walker(url.buf);
729 walker->get_tree = 1;
730 walker->get_history = 1;
731 walker->get_verbosely = options.verbosity >= 3;
732 walker->get_recover = 0;
733 ret = walker_fetch(walker, nr_heads, targets, NULL, NULL);
736 for (i = 0; i < nr_heads; i++)
740 return ret ? error("fetch failed.") : 0;
743 static int fetch_git(struct discovery *heads,
744 int nr_heads, struct ref **to_fetch)
746 struct rpc_state rpc;
747 struct strbuf preamble = STRBUF_INIT;
749 struct argv_array args = ARGV_ARRAY_INIT;
751 argv_array_pushl(&args, "fetch-pack", "--stateless-rpc",
752 "--stdin", "--lock-pack", NULL);
753 if (options.followtags)
754 argv_array_push(&args, "--include-tag");
756 argv_array_push(&args, "--thin");
757 if (options.verbosity >= 3)
758 argv_array_pushl(&args, "-v", "-v", NULL);
759 if (options.check_self_contained_and_connected)
760 argv_array_push(&args, "--check-self-contained-and-connected");
762 argv_array_push(&args, "--cloning");
763 if (options.update_shallow)
764 argv_array_push(&args, "--update-shallow");
765 if (!options.progress)
766 argv_array_push(&args, "--no-progress");
768 argv_array_pushf(&args, "--depth=%lu", options.depth);
769 if (options.deepen_since)
770 argv_array_pushf(&args, "--shallow-since=%s", options.deepen_since);
771 for (i = 0; i < options.deepen_not.nr; i++)
772 argv_array_pushf(&args, "--shallow-exclude=%s",
773 options.deepen_not.items[i].string);
774 if (options.deepen_relative && options.depth)
775 argv_array_push(&args, "--deepen-relative");
776 argv_array_push(&args, url.buf);
778 for (i = 0; i < nr_heads; i++) {
779 struct ref *ref = to_fetch[i];
781 die("cannot fetch by sha1 over smart http");
782 packet_buf_write(&preamble, "%s %s\n",
783 oid_to_hex(&ref->old_oid), ref->name);
785 packet_buf_flush(&preamble);
787 memset(&rpc, 0, sizeof(rpc));
788 rpc.service_name = "git-upload-pack",
789 rpc.argv = args.argv;
790 rpc.stdin_preamble = &preamble;
791 rpc.gzip_request = 1;
793 err = rpc_service(&rpc, heads);
795 write_or_die(1, rpc.result.buf, rpc.result.len);
796 strbuf_release(&rpc.result);
797 strbuf_release(&preamble);
798 argv_array_clear(&args);
802 static int fetch(int nr_heads, struct ref **to_fetch)
804 struct discovery *d = discover_refs("git-upload-pack", 0);
806 return fetch_git(d, nr_heads, to_fetch);
808 return fetch_dumb(nr_heads, to_fetch);
811 static void parse_fetch(struct strbuf *buf)
813 struct ref **to_fetch = NULL;
814 struct ref *list_head = NULL;
815 struct ref **list = &list_head;
816 int alloc_heads = 0, nr_heads = 0;
820 if (skip_prefix(buf->buf, "fetch ", &p)) {
823 struct object_id old_oid;
825 if (get_oid_hex(p, &old_oid))
826 die("protocol error: expected sha/ref, got %s'", p);
827 if (p[GIT_SHA1_HEXSZ] == ' ')
828 name = p + GIT_SHA1_HEXSZ + 1;
829 else if (!p[GIT_SHA1_HEXSZ])
832 die("protocol error: expected sha/ref, got %s'", p);
834 ref = alloc_ref(name);
835 oidcpy(&ref->old_oid, &old_oid);
840 ALLOC_GROW(to_fetch, nr_heads + 1, alloc_heads);
841 to_fetch[nr_heads++] = ref;
844 die("http transport does not support %s", buf->buf);
847 if (strbuf_getline_lf(buf, stdin) == EOF)
853 if (fetch(nr_heads, to_fetch))
854 exit(128); /* error already reported */
855 free_refs(list_head);
863 static int push_dav(int nr_spec, char **specs)
865 const char **argv = xmalloc((10 + nr_spec) * sizeof(char*));
868 argv[argc++] = "http-push";
869 argv[argc++] = "--helper-status";
871 argv[argc++] = "--dry-run";
872 if (options.verbosity > 1)
873 argv[argc++] = "--verbose";
874 argv[argc++] = url.buf;
875 for (i = 0; i < nr_spec; i++)
876 argv[argc++] = specs[i];
879 if (run_command_v_opt(argv, RUN_GIT_CMD))
880 die("git-%s failed", argv[0]);
885 static int push_git(struct discovery *heads, int nr_spec, char **specs)
887 struct rpc_state rpc;
889 struct argv_array args;
890 struct string_list_item *cas_option;
891 struct strbuf preamble = STRBUF_INIT;
893 argv_array_init(&args);
894 argv_array_pushl(&args, "send-pack", "--stateless-rpc", "--helper-status",
898 argv_array_push(&args, "--thin");
900 argv_array_push(&args, "--dry-run");
901 if (options.push_cert == SEND_PACK_PUSH_CERT_ALWAYS)
902 argv_array_push(&args, "--signed=yes");
903 else if (options.push_cert == SEND_PACK_PUSH_CERT_IF_ASKED)
904 argv_array_push(&args, "--signed=if-asked");
905 if (options.verbosity == 0)
906 argv_array_push(&args, "--quiet");
907 else if (options.verbosity > 1)
908 argv_array_push(&args, "--verbose");
909 argv_array_push(&args, options.progress ? "--progress" : "--no-progress");
910 for_each_string_list_item(cas_option, &cas_options)
911 argv_array_push(&args, cas_option->string);
912 argv_array_push(&args, url.buf);
914 argv_array_push(&args, "--stdin");
915 for (i = 0; i < nr_spec; i++)
916 packet_buf_write(&preamble, "%s\n", specs[i]);
917 packet_buf_flush(&preamble);
919 memset(&rpc, 0, sizeof(rpc));
920 rpc.service_name = "git-receive-pack",
921 rpc.argv = args.argv;
922 rpc.stdin_preamble = &preamble;
924 err = rpc_service(&rpc, heads);
926 write_or_die(1, rpc.result.buf, rpc.result.len);
927 strbuf_release(&rpc.result);
928 strbuf_release(&preamble);
929 argv_array_clear(&args);
933 static int push(int nr_spec, char **specs)
935 struct discovery *heads = discover_refs("git-receive-pack", 1);
938 if (heads->proto_git)
939 ret = push_git(heads, nr_spec, specs);
941 ret = push_dav(nr_spec, specs);
942 free_discovery(heads);
946 static void parse_push(struct strbuf *buf)
949 int alloc_spec = 0, nr_spec = 0, i, ret;
952 if (starts_with(buf->buf, "push ")) {
953 ALLOC_GROW(specs, nr_spec + 1, alloc_spec);
954 specs[nr_spec++] = xstrdup(buf->buf + 5);
957 die("http transport does not support %s", buf->buf);
960 if (strbuf_getline_lf(buf, stdin) == EOF)
966 ret = push(nr_spec, specs);
971 exit(128); /* error already reported */
974 for (i = 0; i < nr_spec; i++)
979 int main(int argc, const char **argv)
981 struct strbuf buf = STRBUF_INIT;
986 git_extract_argv0_path(argv[0]);
987 setup_git_directory_gently(&nongit);
989 error("remote-curl: usage: git remote-curl <remote> [<url>]");
993 options.verbosity = 1;
994 options.progress = !!isatty(2);
996 string_list_init(&options.deepen_not, 1);
998 remote = remote_get(argv[1]);
1001 end_url_with_slash(&url, argv[2]);
1003 end_url_with_slash(&url, remote->url[0]);
1006 http_init(remote, url.buf, 0);
1011 if (strbuf_getline_lf(&buf, stdin) == EOF) {
1013 error("remote-curl: error reading command stream from git");
1018 if (starts_with(buf.buf, "fetch ")) {
1020 die("remote-curl: fetch attempted without a local repo");
1023 } else if (!strcmp(buf.buf, "list") || starts_with(buf.buf, "list ")) {
1024 int for_push = !!strstr(buf.buf + 4, "for-push");
1025 output_refs(get_refs(for_push));
1027 } else if (starts_with(buf.buf, "push ")) {
1030 } else if (skip_prefix(buf.buf, "option ", &arg)) {
1031 char *value = strchr(arg, ' ');
1039 result = set_option(arg, value);
1042 else if (result < 0)
1043 printf("error invalid value\n");
1045 printf("unsupported\n");
1048 } else if (!strcmp(buf.buf, "capabilities")) {
1052 printf("check-connectivity\n");
1056 error("remote-curl: unknown command '%s' from git", buf.buf);