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 return 1 /* unsupported */;
133 struct sha1_array shallow;
134 unsigned proto_git : 1;
136 static struct discovery *last_discovery;
138 static struct ref *parse_git_refs(struct discovery *heads, int for_push)
140 struct ref *list = NULL;
141 get_remote_heads(-1, heads->buf, heads->len, &list,
142 for_push ? REF_NORMAL : 0, NULL, &heads->shallow);
146 static struct ref *parse_info_refs(struct discovery *heads)
148 char *data, *start, *mid;
152 struct ref *refs = NULL;
153 struct ref *ref = NULL;
154 struct ref *last_ref = NULL;
159 while (i < heads->len) {
165 if (data[i] == '\n') {
166 if (mid - start != 40)
167 die("%sinfo/refs not valid: is this a git repository?",
171 ref = alloc_ref(ref_name);
172 get_oid_hex(start, &ref->old_oid);
176 last_ref->next = ref;
183 ref = alloc_ref("HEAD");
184 if (!http_fetch_ref(url.buf, ref) &&
185 !resolve_remote_symref(ref, refs)) {
195 static void free_discovery(struct discovery *d)
198 if (d == last_discovery)
199 last_discovery = NULL;
200 free(d->shallow.sha1);
207 static int show_http_message(struct strbuf *type, struct strbuf *charset,
213 * We only show text/plain parts, as other types are likely
214 * to be ugly to look at on the user's terminal.
216 if (strcmp(type->buf, "text/plain"))
219 strbuf_reencode(msg, charset->buf, get_log_output_encoding());
227 eol = strchrnul(p, '\n');
228 fprintf(stderr, "remote: %.*s\n", (int)(eol - p), p);
234 static struct discovery *discover_refs(const char *service, int for_push)
236 struct strbuf exp = STRBUF_INIT;
237 struct strbuf type = STRBUF_INIT;
238 struct strbuf charset = STRBUF_INIT;
239 struct strbuf buffer = STRBUF_INIT;
240 struct strbuf refs_url = STRBUF_INIT;
241 struct strbuf effective_url = STRBUF_INIT;
242 struct discovery *last = last_discovery;
243 int http_ret, maybe_smart = 0;
244 struct http_get_options options;
246 if (last && !strcmp(service, last->service))
248 free_discovery(last);
250 strbuf_addf(&refs_url, "%sinfo/refs", url.buf);
251 if ((starts_with(url.buf, "http://") || starts_with(url.buf, "https://")) &&
252 git_env_bool("GIT_SMART_HTTP", 1)) {
254 if (!strchr(url.buf, '?'))
255 strbuf_addch(&refs_url, '?');
257 strbuf_addch(&refs_url, '&');
258 strbuf_addf(&refs_url, "service=%s", service);
261 memset(&options, 0, sizeof(options));
262 options.content_type = &type;
263 options.charset = &charset;
264 options.effective_url = &effective_url;
265 options.base_url = &url;
266 options.no_cache = 1;
267 options.keep_error = 1;
269 http_ret = http_get_strbuf(refs_url.buf, &buffer, &options);
273 case HTTP_MISSING_TARGET:
274 show_http_message(&type, &charset, &buffer);
275 die("repository '%s' not found", url.buf);
277 show_http_message(&type, &charset, &buffer);
278 die("Authentication failed for '%s'", url.buf);
280 show_http_message(&type, &charset, &buffer);
281 die("unable to access '%s': %s", url.buf, curl_errorstr);
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;
289 strbuf_addf(&exp, "application/x-%s-advertisement", service);
291 (5 <= last->len && last->buf[4] == '#') &&
292 !strbuf_cmp(&exp, &type)) {
296 * smart HTTP response; validate that the service
297 * pkt-line matches our request.
299 line = packet_read_line_buf(&last->buf, &last->len, NULL);
302 strbuf_addf(&exp, "# service=%s", service);
303 if (strcmp(line, exp.buf))
304 die("invalid server response; got '%s'", line);
305 strbuf_release(&exp);
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.
311 while (packet_read_line_buf(&last->buf, &last->len, NULL))
318 last->refs = parse_git_refs(last, for_push);
320 last->refs = parse_info_refs(last);
322 strbuf_release(&refs_url);
323 strbuf_release(&exp);
324 strbuf_release(&type);
325 strbuf_release(&charset);
326 strbuf_release(&effective_url);
327 strbuf_release(&buffer);
328 last_discovery = last;
332 static struct ref *get_refs(int for_push)
334 struct discovery *heads;
337 heads = discover_refs("git-receive-pack", for_push);
339 heads = discover_refs("git-upload-pack", for_push);
344 static void output_refs(struct ref *refs)
347 for (posn = refs; posn; posn = posn->next) {
349 printf("@%s %s\n", posn->symref, posn->name);
351 printf("%s %s\n", oid_to_hex(&posn->old_oid), posn->name);
358 const char *service_name;
360 struct strbuf *stdin_preamble;
362 char *hdr_content_type;
370 struct strbuf result;
371 unsigned gzip_request : 1;
372 unsigned initial_buffer : 1;
375 static size_t rpc_out(void *ptr, size_t eltsize,
376 size_t nmemb, void *buffer_)
378 size_t max = eltsize * nmemb;
379 struct rpc_state *rpc = buffer_;
380 size_t avail = rpc->len - rpc->pos;
383 rpc->initial_buffer = 0;
384 avail = packet_read(rpc->out, NULL, NULL, rpc->buf, rpc->alloc, 0);
393 memcpy(ptr, rpc->buf + rpc->pos, avail);
398 #ifndef NO_CURL_IOCTL
399 static curlioerr rpc_ioctl(CURL *handle, int cmd, void *clientp)
401 struct rpc_state *rpc = clientp;
407 case CURLIOCMD_RESTARTREAD:
408 if (rpc->initial_buffer) {
412 error("unable to rewind rpc post data - try increasing http.postBuffer");
413 return CURLIOE_FAILRESTART;
416 return CURLIOE_UNKNOWNCMD;
421 static size_t rpc_in(char *ptr, size_t eltsize,
422 size_t nmemb, void *buffer_)
424 size_t size = eltsize * nmemb;
425 struct rpc_state *rpc = buffer_;
426 write_or_die(rpc->in, ptr, size);
430 static int run_slot(struct active_request_slot *slot,
431 struct slot_results *results)
434 struct slot_results results_buf;
437 results = &results_buf;
439 err = run_one_slot(slot, results);
441 if (err != HTTP_OK && err != HTTP_REAUTH) {
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) {
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);
454 error("RPC failed; %s", msg.buf);
455 strbuf_release(&msg);
461 static int probe_rpc(struct rpc_state *rpc, struct slot_results *results)
463 struct active_request_slot *slot;
464 struct curl_slist *headers = NULL;
465 struct strbuf buf = STRBUF_INIT;
468 slot = get_active_slot();
470 headers = curl_slist_append(headers, rpc->hdr_content_type);
471 headers = curl_slist_append(headers, rpc->hdr_accept);
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);
476 curl_easy_setopt(slot->curl, CURLOPT_ENCODING, NULL);
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);
483 err = run_slot(slot, results);
485 curl_slist_free_all(headers);
486 strbuf_release(&buf);
490 static int post_rpc(struct rpc_state *rpc)
492 struct active_request_slot *slot;
493 struct curl_slist *headers = NULL;
494 int use_gzip = rpc->gzip_request;
495 char *gzip_body = NULL;
496 size_t gzip_size = 0;
497 int err, large_request = 0;
498 int needs_100_continue = 0;
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.
505 size_t left = rpc->alloc - rpc->len;
506 char *buf = rpc->buf + rpc->len;
509 if (left < LARGE_PACKET_MAX) {
515 n = packet_read(rpc->out, NULL, NULL, buf, left, 0);
522 struct slot_results results;
525 err = probe_rpc(rpc, &results);
526 if (err == HTTP_REAUTH)
527 credential_fill(&http_auth);
528 } while (err == HTTP_REAUTH);
532 if (results.auth_avail & CURLAUTH_GSSNEGOTIATE)
533 needs_100_continue = 1;
536 headers = curl_slist_append(headers, rpc->hdr_content_type);
537 headers = curl_slist_append(headers, rpc->hdr_accept);
538 headers = curl_slist_append(headers, needs_100_continue ?
539 "Expect: 100-continue" : "Expect:");
542 slot = get_active_slot();
544 curl_easy_setopt(slot->curl, CURLOPT_NOBODY, 0);
545 curl_easy_setopt(slot->curl, CURLOPT_POST, 1);
546 curl_easy_setopt(slot->curl, CURLOPT_URL, rpc->service_url);
547 curl_easy_setopt(slot->curl, CURLOPT_ENCODING, "gzip");
550 /* The request body is large and the size cannot be predicted.
551 * We must use chunked encoding to send it.
553 headers = curl_slist_append(headers, "Transfer-Encoding: chunked");
554 rpc->initial_buffer = 1;
555 curl_easy_setopt(slot->curl, CURLOPT_READFUNCTION, rpc_out);
556 curl_easy_setopt(slot->curl, CURLOPT_INFILE, rpc);
557 #ifndef NO_CURL_IOCTL
558 curl_easy_setopt(slot->curl, CURLOPT_IOCTLFUNCTION, rpc_ioctl);
559 curl_easy_setopt(slot->curl, CURLOPT_IOCTLDATA, rpc);
561 if (options.verbosity > 1) {
562 fprintf(stderr, "POST %s (chunked)\n", rpc->service_name);
566 } else if (gzip_body) {
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.
572 curl_easy_setopt(slot->curl, CURLOPT_POSTFIELDS, gzip_body);
573 curl_easy_setopt(slot->curl, CURLOPT_POSTFIELDSIZE, gzip_size);
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.
583 git_deflate_init_gzip(&stream, Z_BEST_COMPRESSION);
584 gzip_size = git_deflate_bound(&stream, rpc->len);
585 gzip_body = xmalloc(gzip_size);
587 stream.next_in = (unsigned char *)rpc->buf;
588 stream.avail_in = rpc->len;
589 stream.next_out = (unsigned char *)gzip_body;
590 stream.avail_out = gzip_size;
592 ret = git_deflate(&stream, Z_FINISH);
593 if (ret != Z_STREAM_END)
594 die("cannot deflate request; zlib deflate error %d", ret);
596 ret = git_deflate_end_gently(&stream);
598 die("cannot deflate request; zlib end error %d", ret);
600 gzip_size = stream.total_out;
602 headers = curl_slist_append(headers, "Content-Encoding: gzip");
603 curl_easy_setopt(slot->curl, CURLOPT_POSTFIELDS, gzip_body);
604 curl_easy_setopt(slot->curl, CURLOPT_POSTFIELDSIZE, gzip_size);
606 if (options.verbosity > 1) {
607 fprintf(stderr, "POST %s (gzip %lu to %lu bytes)\n",
609 (unsigned long)rpc->len, (unsigned long)gzip_size);
613 /* We know the complete request size in advance, use the
614 * more normal Content-Length approach.
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);
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);
629 err = run_slot(slot, NULL);
630 if (err == HTTP_REAUTH && !large_request) {
631 credential_fill(&http_auth);
637 curl_slist_free_all(headers);
642 static int rpc_service(struct rpc_state *rpc, struct discovery *heads)
644 const char *svc = rpc->service_name;
645 struct strbuf buf = STRBUF_INIT;
646 struct strbuf *preamble = rpc->stdin_preamble;
647 struct child_process client = CHILD_PROCESS_INIT;
653 client.argv = rpc->argv;
654 if (start_command(&client))
657 write_or_die(client.in, preamble->buf, preamble->len);
659 write_or_die(client.in, heads->buf, heads->len);
661 rpc->alloc = http_post_buffer;
662 rpc->buf = xmalloc(rpc->alloc);
664 rpc->out = client.out;
665 strbuf_init(&rpc->result, 0);
667 strbuf_addf(&buf, "%s%s", url.buf, svc);
668 rpc->service_url = strbuf_detach(&buf, NULL);
670 strbuf_addf(&buf, "Content-Type: application/x-%s-request", svc);
671 rpc->hdr_content_type = strbuf_detach(&buf, NULL);
673 strbuf_addf(&buf, "Accept: application/x-%s-result", svc);
674 rpc->hdr_accept = strbuf_detach(&buf, NULL);
677 int n = packet_read(rpc->out, NULL, NULL, rpc->buf, rpc->alloc, 0);
682 err |= post_rpc(rpc);
688 strbuf_read(&rpc->result, client.out, 0);
692 if (xread(client.out, buf, sizeof(buf)) <= 0)
699 err |= finish_command(&client);
700 free(rpc->service_url);
701 free(rpc->hdr_content_type);
702 free(rpc->hdr_accept);
704 strbuf_release(&buf);
708 static int fetch_dumb(int nr_heads, struct ref **to_fetch)
710 struct walker *walker;
714 ALLOC_ARRAY(targets, nr_heads);
716 die("dumb http transport does not support --depth");
717 for (i = 0; i < nr_heads; i++)
718 targets[i] = xstrdup(oid_to_hex(&to_fetch[i]->old_oid));
720 walker = get_http_walker(url.buf);
722 walker->get_tree = 1;
723 walker->get_history = 1;
724 walker->get_verbosely = options.verbosity >= 3;
725 walker->get_recover = 0;
726 ret = walker_fetch(walker, nr_heads, targets, NULL, NULL);
729 for (i = 0; i < nr_heads; i++)
733 return ret ? error("fetch failed.") : 0;
736 static int fetch_git(struct discovery *heads,
737 int nr_heads, struct ref **to_fetch)
739 struct rpc_state rpc;
740 struct strbuf preamble = STRBUF_INIT;
741 char *depth_arg = NULL;
742 int argc = 0, i, err;
743 const char *argv[17];
745 argv[argc++] = "fetch-pack";
746 argv[argc++] = "--stateless-rpc";
747 argv[argc++] = "--stdin";
748 argv[argc++] = "--lock-pack";
749 if (options.followtags)
750 argv[argc++] = "--include-tag";
752 argv[argc++] = "--thin";
753 if (options.verbosity >= 3) {
757 if (options.check_self_contained_and_connected)
758 argv[argc++] = "--check-self-contained-and-connected";
760 argv[argc++] = "--cloning";
761 if (options.update_shallow)
762 argv[argc++] = "--update-shallow";
763 if (!options.progress)
764 argv[argc++] = "--no-progress";
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;
771 argv[argc++] = url.buf;
774 for (i = 0; i < nr_heads; i++) {
775 struct ref *ref = to_fetch[i];
777 die("cannot fetch by sha1 over smart http");
778 packet_buf_write(&preamble, "%s %s\n",
779 oid_to_hex(&ref->old_oid), ref->name);
781 packet_buf_flush(&preamble);
783 memset(&rpc, 0, sizeof(rpc));
784 rpc.service_name = "git-upload-pack",
786 rpc.stdin_preamble = &preamble;
787 rpc.gzip_request = 1;
789 err = rpc_service(&rpc, heads);
791 write_or_die(1, rpc.result.buf, rpc.result.len);
792 strbuf_release(&rpc.result);
793 strbuf_release(&preamble);
798 static int fetch(int nr_heads, struct ref **to_fetch)
800 struct discovery *d = discover_refs("git-upload-pack", 0);
802 return fetch_git(d, nr_heads, to_fetch);
804 return fetch_dumb(nr_heads, to_fetch);
807 static void parse_fetch(struct strbuf *buf)
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;
816 if (skip_prefix(buf->buf, "fetch ", &p)) {
819 struct object_id old_oid;
821 if (get_oid_hex(p, &old_oid))
822 die("protocol error: expected sha/ref, got %s'", p);
823 if (p[GIT_SHA1_HEXSZ] == ' ')
824 name = p + GIT_SHA1_HEXSZ + 1;
825 else if (!p[GIT_SHA1_HEXSZ])
828 die("protocol error: expected sha/ref, got %s'", p);
830 ref = alloc_ref(name);
831 oidcpy(&ref->old_oid, &old_oid);
836 ALLOC_GROW(to_fetch, nr_heads + 1, alloc_heads);
837 to_fetch[nr_heads++] = ref;
840 die("http transport does not support %s", buf->buf);
843 if (strbuf_getline(buf, stdin, '\n') == EOF)
849 if (fetch(nr_heads, to_fetch))
850 exit(128); /* error already reported */
851 free_refs(list_head);
859 static int push_dav(int nr_spec, char **specs)
861 struct child_process child = CHILD_PROCESS_INIT;
865 argv_array_push(&child.args, "http-push");
866 argv_array_push(&child.args, "--helper-status");
868 argv_array_push(&child.args, "--dry-run");
869 if (options.verbosity > 1)
870 argv_array_push(&child.args, "--verbose");
871 argv_array_push(&child.args, url.buf);
872 for (i = 0; i < nr_spec; i++)
873 argv_array_push(&child.args, specs[i]);
875 if (run_command(&child))
876 die("git-http-push failed");
880 static int push_git(struct discovery *heads, int nr_spec, char **specs)
882 struct rpc_state rpc;
884 struct argv_array args;
885 struct string_list_item *cas_option;
886 struct strbuf preamble = STRBUF_INIT;
888 argv_array_init(&args);
889 argv_array_pushl(&args, "send-pack", "--stateless-rpc", "--helper-status",
893 argv_array_push(&args, "--thin");
895 argv_array_push(&args, "--dry-run");
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");
900 if (options.verbosity == 0)
901 argv_array_push(&args, "--quiet");
902 else if (options.verbosity > 1)
903 argv_array_push(&args, "--verbose");
904 argv_array_push(&args, options.progress ? "--progress" : "--no-progress");
905 for_each_string_list_item(cas_option, &cas_options)
906 argv_array_push(&args, cas_option->string);
907 argv_array_push(&args, url.buf);
909 argv_array_push(&args, "--stdin");
910 for (i = 0; i < nr_spec; i++)
911 packet_buf_write(&preamble, "%s\n", specs[i]);
912 packet_buf_flush(&preamble);
914 memset(&rpc, 0, sizeof(rpc));
915 rpc.service_name = "git-receive-pack",
916 rpc.argv = args.argv;
917 rpc.stdin_preamble = &preamble;
919 err = rpc_service(&rpc, heads);
921 write_or_die(1, rpc.result.buf, rpc.result.len);
922 strbuf_release(&rpc.result);
923 strbuf_release(&preamble);
924 argv_array_clear(&args);
928 static int push(int nr_spec, char **specs)
930 struct discovery *heads = discover_refs("git-receive-pack", 1);
933 if (heads->proto_git)
934 ret = push_git(heads, nr_spec, specs);
936 ret = push_dav(nr_spec, specs);
937 free_discovery(heads);
941 static void parse_push(struct strbuf *buf)
944 int alloc_spec = 0, nr_spec = 0, i, ret;
947 if (starts_with(buf->buf, "push ")) {
948 ALLOC_GROW(specs, nr_spec + 1, alloc_spec);
949 specs[nr_spec++] = xstrdup(buf->buf + 5);
952 die("http transport does not support %s", buf->buf);
955 if (strbuf_getline(buf, stdin, '\n') == EOF)
961 ret = push(nr_spec, specs);
966 exit(128); /* error already reported */
969 for (i = 0; i < nr_spec; i++)
974 int main(int argc, const char **argv)
976 struct strbuf buf = STRBUF_INIT;
981 git_extract_argv0_path(argv[0]);
982 setup_git_directory_gently(&nongit);
984 error("remote-curl: usage: git remote-curl <remote> [<url>]");
988 options.verbosity = 1;
989 options.progress = !!isatty(2);
992 remote = remote_get(argv[1]);
995 end_url_with_slash(&url, argv[2]);
997 end_url_with_slash(&url, remote->url[0]);
1000 http_init(remote, url.buf, 0);
1005 if (strbuf_getline(&buf, stdin, '\n') == EOF) {
1007 error("remote-curl: error reading command stream from git");
1012 if (starts_with(buf.buf, "fetch ")) {
1014 die("remote-curl: fetch attempted without a local repo");
1017 } else if (!strcmp(buf.buf, "list") || starts_with(buf.buf, "list ")) {
1018 int for_push = !!strstr(buf.buf + 4, "for-push");
1019 output_refs(get_refs(for_push));
1021 } else if (starts_with(buf.buf, "push ")) {
1024 } else if (skip_prefix(buf.buf, "option ", &arg)) {
1025 char *value = strchr(arg, ' ');
1033 result = set_option(arg, value);
1036 else if (result < 0)
1037 printf("error invalid value\n");
1039 printf("unsupported\n");
1042 } else if (!strcmp(buf.buf, "capabilities")) {
1046 printf("check-connectivity\n");
1050 error("remote-curl: unknown command '%s' from git", buf.buf);