7 #include "run-command.h"
9 #include "string-list.h"
11 #include "argv-array.h"
12 #include "credential.h"
13 #include "sha1-array.h"
15 static struct remote
*remote
;
16 /* always ends with a trailing slash */
17 static struct strbuf url
= STRBUF_INIT
;
22 unsigned progress
: 1,
23 check_self_contained_and_connected
: 1,
31 static struct options options
;
32 static struct string_list cas_options
= STRING_LIST_INIT_DUP
;
34 static int set_option(const char *name
, const char *value
)
36 if (!strcmp(name
, "verbosity")) {
38 int v
= strtol(value
, &end
, 10);
39 if (value
== end
|| *end
)
41 options
.verbosity
= v
;
44 else if (!strcmp(name
, "progress")) {
45 if (!strcmp(value
, "true"))
47 else if (!strcmp(value
, "false"))
53 else if (!strcmp(name
, "depth")) {
55 unsigned long v
= strtoul(value
, &end
, 10);
56 if (value
== end
|| *end
)
61 else if (!strcmp(name
, "followtags")) {
62 if (!strcmp(value
, "true"))
63 options
.followtags
= 1;
64 else if (!strcmp(value
, "false"))
65 options
.followtags
= 0;
70 else if (!strcmp(name
, "dry-run")) {
71 if (!strcmp(value
, "true"))
73 else if (!strcmp(value
, "false"))
79 else if (!strcmp(name
, "check-connectivity")) {
80 if (!strcmp(value
, "true"))
81 options
.check_self_contained_and_connected
= 1;
82 else if (!strcmp(value
, "false"))
83 options
.check_self_contained_and_connected
= 0;
88 else if (!strcmp(name
, "cas")) {
89 struct strbuf val
= STRBUF_INIT
;
90 strbuf_addf(&val
, "--" CAS_OPT_NAME
"=%s", value
);
91 string_list_append(&cas_options
, val
.buf
);
94 } else if (!strcmp(name
, "cloning")) {
95 if (!strcmp(value
, "true"))
97 else if (!strcmp(value
, "false"))
102 } else if (!strcmp(name
, "update-shallow")) {
103 if (!strcmp(value
, "true"))
104 options
.update_shallow
= 1;
105 else if (!strcmp(value
, "false"))
106 options
.update_shallow
= 0;
110 } else if (!strcmp(name
, "pushcert")) {
111 if (!strcmp(value
, "true"))
112 options
.push_cert
= 1;
113 else if (!strcmp(value
, "false"))
114 options
.push_cert
= 0;
119 return 1 /* unsupported */;
129 struct sha1_array shallow
;
130 unsigned proto_git
: 1;
132 static struct discovery
*last_discovery
;
134 static struct ref
*parse_git_refs(struct discovery
*heads
, int for_push
)
136 struct ref
*list
= NULL
;
137 get_remote_heads(-1, heads
->buf
, heads
->len
, &list
,
138 for_push
? REF_NORMAL
: 0, NULL
, &heads
->shallow
);
142 static struct ref
*parse_info_refs(struct discovery
*heads
)
144 char *data
, *start
, *mid
;
148 struct ref
*refs
= NULL
;
149 struct ref
*ref
= NULL
;
150 struct ref
*last_ref
= NULL
;
155 while (i
< heads
->len
) {
161 if (data
[i
] == '\n') {
162 if (mid
- start
!= 40)
163 die("%sinfo/refs not valid: is this a git repository?",
167 ref
= xmalloc(sizeof(struct ref
) +
168 strlen(ref_name
) + 1);
169 memset(ref
, 0, sizeof(struct ref
));
170 strcpy(ref
->name
, ref_name
);
171 get_sha1_hex(start
, ref
->old_sha1
);
175 last_ref
->next
= ref
;
182 ref
= alloc_ref("HEAD");
183 if (!http_fetch_ref(url
.buf
, ref
) &&
184 !resolve_remote_symref(ref
, refs
)) {
194 static void free_discovery(struct discovery
*d
)
197 if (d
== last_discovery
)
198 last_discovery
= NULL
;
199 free(d
->shallow
.sha1
);
206 static int show_http_message(struct strbuf
*type
, struct strbuf
*charset
,
212 * We only show text/plain parts, as other types are likely
213 * to be ugly to look at on the user's terminal.
215 if (strcmp(type
->buf
, "text/plain"))
218 strbuf_reencode(msg
, charset
->buf
, get_log_output_encoding());
226 eol
= strchrnul(p
, '\n');
227 fprintf(stderr
, "remote: %.*s\n", (int)(eol
- p
), p
);
233 static struct discovery
*discover_refs(const char *service
, int for_push
)
235 struct strbuf exp
= STRBUF_INIT
;
236 struct strbuf type
= STRBUF_INIT
;
237 struct strbuf charset
= STRBUF_INIT
;
238 struct strbuf buffer
= STRBUF_INIT
;
239 struct strbuf refs_url
= STRBUF_INIT
;
240 struct strbuf effective_url
= STRBUF_INIT
;
241 struct discovery
*last
= last_discovery
;
242 int http_ret
, maybe_smart
= 0;
243 struct http_get_options options
;
245 if (last
&& !strcmp(service
, last
->service
))
247 free_discovery(last
);
249 strbuf_addf(&refs_url
, "%sinfo/refs", url
.buf
);
250 if ((starts_with(url
.buf
, "http://") || starts_with(url
.buf
, "https://")) &&
251 git_env_bool("GIT_SMART_HTTP", 1)) {
253 if (!strchr(url
.buf
, '?'))
254 strbuf_addch(&refs_url
, '?');
256 strbuf_addch(&refs_url
, '&');
257 strbuf_addf(&refs_url
, "service=%s", service
);
260 memset(&options
, 0, sizeof(options
));
261 options
.content_type
= &type
;
262 options
.charset
= &charset
;
263 options
.effective_url
= &effective_url
;
264 options
.base_url
= &url
;
265 options
.no_cache
= 1;
266 options
.keep_error
= 1;
268 http_ret
= http_get_strbuf(refs_url
.buf
, &buffer
, &options
);
272 case HTTP_MISSING_TARGET
:
273 show_http_message(&type
, &charset
, &buffer
);
274 die("repository '%s' not found", url
.buf
);
276 show_http_message(&type
, &charset
, &buffer
);
277 die("Authentication failed for '%s'", url
.buf
);
279 show_http_message(&type
, &charset
, &buffer
);
280 die("unable to access '%s': %s", url
.buf
, curl_errorstr
);
283 last
= xcalloc(1, sizeof(*last_discovery
));
284 last
->service
= service
;
285 last
->buf_alloc
= strbuf_detach(&buffer
, &last
->len
);
286 last
->buf
= last
->buf_alloc
;
288 strbuf_addf(&exp
, "application/x-%s-advertisement", service
);
290 (5 <= last
->len
&& last
->buf
[4] == '#') &&
291 !strbuf_cmp(&exp
, &type
)) {
295 * smart HTTP response; validate that the service
296 * pkt-line matches our request.
298 line
= packet_read_line_buf(&last
->buf
, &last
->len
, NULL
);
301 strbuf_addf(&exp
, "# service=%s", service
);
302 if (strcmp(line
, exp
.buf
))
303 die("invalid server response; got '%s'", line
);
304 strbuf_release(&exp
);
306 /* The header can include additional metadata lines, up
307 * until a packet flush marker. Ignore these now, but
308 * in the future we might start to scan them.
310 while (packet_read_line_buf(&last
->buf
, &last
->len
, NULL
))
317 last
->refs
= parse_git_refs(last
, for_push
);
319 last
->refs
= parse_info_refs(last
);
321 strbuf_release(&refs_url
);
322 strbuf_release(&exp
);
323 strbuf_release(&type
);
324 strbuf_release(&charset
);
325 strbuf_release(&effective_url
);
326 strbuf_release(&buffer
);
327 last_discovery
= last
;
331 static struct ref
*get_refs(int for_push
)
333 struct discovery
*heads
;
336 heads
= discover_refs("git-receive-pack", for_push
);
338 heads
= discover_refs("git-upload-pack", for_push
);
343 static void output_refs(struct ref
*refs
)
346 for (posn
= refs
; posn
; posn
= posn
->next
) {
348 printf("@%s %s\n", posn
->symref
, posn
->name
);
350 printf("%s %s\n", sha1_to_hex(posn
->old_sha1
), posn
->name
);
357 const char *service_name
;
359 struct strbuf
*stdin_preamble
;
361 char *hdr_content_type
;
369 struct strbuf result
;
370 unsigned gzip_request
: 1;
371 unsigned initial_buffer
: 1;
374 static size_t rpc_out(void *ptr
, size_t eltsize
,
375 size_t nmemb
, void *buffer_
)
377 size_t max
= eltsize
* nmemb
;
378 struct rpc_state
*rpc
= buffer_
;
379 size_t avail
= rpc
->len
- rpc
->pos
;
382 rpc
->initial_buffer
= 0;
383 avail
= packet_read(rpc
->out
, NULL
, NULL
, rpc
->buf
, rpc
->alloc
, 0);
392 memcpy(ptr
, rpc
->buf
+ rpc
->pos
, avail
);
397 #ifndef NO_CURL_IOCTL
398 static curlioerr
rpc_ioctl(CURL
*handle
, int cmd
, void *clientp
)
400 struct rpc_state
*rpc
= clientp
;
406 case CURLIOCMD_RESTARTREAD
:
407 if (rpc
->initial_buffer
) {
411 error("unable to rewind rpc post data - try increasing http.postBuffer");
412 return CURLIOE_FAILRESTART
;
415 return CURLIOE_UNKNOWNCMD
;
420 static size_t rpc_in(char *ptr
, size_t eltsize
,
421 size_t nmemb
, void *buffer_
)
423 size_t size
= eltsize
* nmemb
;
424 struct rpc_state
*rpc
= buffer_
;
425 write_or_die(rpc
->in
, ptr
, size
);
429 static int run_slot(struct active_request_slot
*slot
,
430 struct slot_results
*results
)
433 struct slot_results results_buf
;
436 results
= &results_buf
;
438 err
= run_one_slot(slot
, results
);
440 if (err
!= HTTP_OK
&& err
!= HTTP_REAUTH
) {
441 error("RPC failed; result=%d, HTTP code = %ld",
442 results
->curl_result
, results
->http_code
);
448 static int probe_rpc(struct rpc_state
*rpc
, struct slot_results
*results
)
450 struct active_request_slot
*slot
;
451 struct curl_slist
*headers
= NULL
;
452 struct strbuf buf
= STRBUF_INIT
;
455 slot
= get_active_slot();
457 headers
= curl_slist_append(headers
, rpc
->hdr_content_type
);
458 headers
= curl_slist_append(headers
, rpc
->hdr_accept
);
460 curl_easy_setopt(slot
->curl
, CURLOPT_NOBODY
, 0);
461 curl_easy_setopt(slot
->curl
, CURLOPT_POST
, 1);
462 curl_easy_setopt(slot
->curl
, CURLOPT_URL
, rpc
->service_url
);
463 curl_easy_setopt(slot
->curl
, CURLOPT_ENCODING
, NULL
);
464 curl_easy_setopt(slot
->curl
, CURLOPT_POSTFIELDS
, "0000");
465 curl_easy_setopt(slot
->curl
, CURLOPT_POSTFIELDSIZE
, 4);
466 curl_easy_setopt(slot
->curl
, CURLOPT_HTTPHEADER
, headers
);
467 curl_easy_setopt(slot
->curl
, CURLOPT_WRITEFUNCTION
, fwrite_buffer
);
468 curl_easy_setopt(slot
->curl
, CURLOPT_FILE
, &buf
);
470 err
= run_slot(slot
, results
);
472 curl_slist_free_all(headers
);
473 strbuf_release(&buf
);
477 static int post_rpc(struct rpc_state
*rpc
)
479 struct active_request_slot
*slot
;
480 struct curl_slist
*headers
= NULL
;
481 int use_gzip
= rpc
->gzip_request
;
482 char *gzip_body
= NULL
;
483 size_t gzip_size
= 0;
484 int err
, large_request
= 0;
485 int needs_100_continue
= 0;
487 /* Try to load the entire request, if we can fit it into the
488 * allocated buffer space we can use HTTP/1.0 and avoid the
489 * chunked encoding mess.
492 size_t left
= rpc
->alloc
- rpc
->len
;
493 char *buf
= rpc
->buf
+ rpc
->len
;
496 if (left
< LARGE_PACKET_MAX
) {
502 n
= packet_read(rpc
->out
, NULL
, NULL
, buf
, left
, 0);
509 struct slot_results results
;
512 err
= probe_rpc(rpc
, &results
);
513 if (err
== HTTP_REAUTH
)
514 credential_fill(&http_auth
);
515 } while (err
== HTTP_REAUTH
);
519 if (results
.auth_avail
& CURLAUTH_GSSNEGOTIATE
)
520 needs_100_continue
= 1;
523 headers
= curl_slist_append(headers
, rpc
->hdr_content_type
);
524 headers
= curl_slist_append(headers
, rpc
->hdr_accept
);
525 headers
= curl_slist_append(headers
, needs_100_continue
?
526 "Expect: 100-continue" : "Expect:");
529 slot
= get_active_slot();
531 curl_easy_setopt(slot
->curl
, CURLOPT_NOBODY
, 0);
532 curl_easy_setopt(slot
->curl
, CURLOPT_POST
, 1);
533 curl_easy_setopt(slot
->curl
, CURLOPT_URL
, rpc
->service_url
);
534 curl_easy_setopt(slot
->curl
, CURLOPT_ENCODING
, "gzip");
537 /* The request body is large and the size cannot be predicted.
538 * We must use chunked encoding to send it.
540 headers
= curl_slist_append(headers
, "Transfer-Encoding: chunked");
541 rpc
->initial_buffer
= 1;
542 curl_easy_setopt(slot
->curl
, CURLOPT_READFUNCTION
, rpc_out
);
543 curl_easy_setopt(slot
->curl
, CURLOPT_INFILE
, rpc
);
544 #ifndef NO_CURL_IOCTL
545 curl_easy_setopt(slot
->curl
, CURLOPT_IOCTLFUNCTION
, rpc_ioctl
);
546 curl_easy_setopt(slot
->curl
, CURLOPT_IOCTLDATA
, rpc
);
548 if (options
.verbosity
> 1) {
549 fprintf(stderr
, "POST %s (chunked)\n", rpc
->service_name
);
553 } else if (gzip_body
) {
555 * If we are looping to retry authentication, then the previous
556 * run will have set up the headers and gzip buffer already,
557 * and we just need to send it.
559 curl_easy_setopt(slot
->curl
, CURLOPT_POSTFIELDS
, gzip_body
);
560 curl_easy_setopt(slot
->curl
, CURLOPT_POSTFIELDSIZE
, gzip_size
);
562 } else if (use_gzip
&& 1024 < rpc
->len
) {
563 /* The client backend isn't giving us compressed data so
564 * we can try to deflate it ourselves, this may save on.
570 memset(&stream
, 0, sizeof(stream
));
571 git_deflate_init_gzip(&stream
, Z_BEST_COMPRESSION
);
572 gzip_size
= git_deflate_bound(&stream
, rpc
->len
);
573 gzip_body
= xmalloc(gzip_size
);
575 stream
.next_in
= (unsigned char *)rpc
->buf
;
576 stream
.avail_in
= rpc
->len
;
577 stream
.next_out
= (unsigned char *)gzip_body
;
578 stream
.avail_out
= gzip_size
;
580 ret
= git_deflate(&stream
, Z_FINISH
);
581 if (ret
!= Z_STREAM_END
)
582 die("cannot deflate request; zlib deflate error %d", ret
);
584 ret
= git_deflate_end_gently(&stream
);
586 die("cannot deflate request; zlib end error %d", ret
);
588 gzip_size
= stream
.total_out
;
590 headers
= curl_slist_append(headers
, "Content-Encoding: gzip");
591 curl_easy_setopt(slot
->curl
, CURLOPT_POSTFIELDS
, gzip_body
);
592 curl_easy_setopt(slot
->curl
, CURLOPT_POSTFIELDSIZE
, gzip_size
);
594 if (options
.verbosity
> 1) {
595 fprintf(stderr
, "POST %s (gzip %lu to %lu bytes)\n",
597 (unsigned long)rpc
->len
, (unsigned long)gzip_size
);
601 /* We know the complete request size in advance, use the
602 * more normal Content-Length approach.
604 curl_easy_setopt(slot
->curl
, CURLOPT_POSTFIELDS
, rpc
->buf
);
605 curl_easy_setopt(slot
->curl
, CURLOPT_POSTFIELDSIZE
, rpc
->len
);
606 if (options
.verbosity
> 1) {
607 fprintf(stderr
, "POST %s (%lu bytes)\n",
608 rpc
->service_name
, (unsigned long)rpc
->len
);
613 curl_easy_setopt(slot
->curl
, CURLOPT_HTTPHEADER
, headers
);
614 curl_easy_setopt(slot
->curl
, CURLOPT_WRITEFUNCTION
, rpc_in
);
615 curl_easy_setopt(slot
->curl
, CURLOPT_FILE
, rpc
);
617 err
= run_slot(slot
, NULL
);
618 if (err
== HTTP_REAUTH
&& !large_request
) {
619 credential_fill(&http_auth
);
625 curl_slist_free_all(headers
);
630 static int rpc_service(struct rpc_state
*rpc
, struct discovery
*heads
)
632 const char *svc
= rpc
->service_name
;
633 struct strbuf buf
= STRBUF_INIT
;
634 struct strbuf
*preamble
= rpc
->stdin_preamble
;
635 struct child_process client
= CHILD_PROCESS_INIT
;
641 client
.argv
= rpc
->argv
;
642 if (start_command(&client
))
645 write_or_die(client
.in
, preamble
->buf
, preamble
->len
);
647 write_or_die(client
.in
, heads
->buf
, heads
->len
);
649 rpc
->alloc
= http_post_buffer
;
650 rpc
->buf
= xmalloc(rpc
->alloc
);
652 rpc
->out
= client
.out
;
653 strbuf_init(&rpc
->result
, 0);
655 strbuf_addf(&buf
, "%s%s", url
.buf
, svc
);
656 rpc
->service_url
= strbuf_detach(&buf
, NULL
);
658 strbuf_addf(&buf
, "Content-Type: application/x-%s-request", svc
);
659 rpc
->hdr_content_type
= strbuf_detach(&buf
, NULL
);
661 strbuf_addf(&buf
, "Accept: application/x-%s-result", svc
);
662 rpc
->hdr_accept
= strbuf_detach(&buf
, NULL
);
665 int n
= packet_read(rpc
->out
, NULL
, NULL
, rpc
->buf
, rpc
->alloc
, 0);
670 err
|= post_rpc(rpc
);
676 strbuf_read(&rpc
->result
, client
.out
, 0);
680 if (xread(client
.out
, buf
, sizeof(buf
)) <= 0)
687 err
|= finish_command(&client
);
688 free(rpc
->service_url
);
689 free(rpc
->hdr_content_type
);
690 free(rpc
->hdr_accept
);
692 strbuf_release(&buf
);
696 static int fetch_dumb(int nr_heads
, struct ref
**to_fetch
)
698 struct walker
*walker
;
699 char **targets
= xmalloc(nr_heads
* sizeof(char*));
703 die("dumb http transport does not support --depth");
704 for (i
= 0; i
< nr_heads
; i
++)
705 targets
[i
] = xstrdup(sha1_to_hex(to_fetch
[i
]->old_sha1
));
707 walker
= get_http_walker(url
.buf
);
709 walker
->get_tree
= 1;
710 walker
->get_history
= 1;
711 walker
->get_verbosely
= options
.verbosity
>= 3;
712 walker
->get_recover
= 0;
713 ret
= walker_fetch(walker
, nr_heads
, targets
, NULL
, NULL
);
716 for (i
= 0; i
< nr_heads
; i
++)
720 return ret
? error("fetch failed.") : 0;
723 static int fetch_git(struct discovery
*heads
,
724 int nr_heads
, struct ref
**to_fetch
)
726 struct rpc_state rpc
;
727 struct strbuf preamble
= STRBUF_INIT
;
728 char *depth_arg
= NULL
;
729 int argc
= 0, i
, err
;
730 const char *argv
[17];
732 argv
[argc
++] = "fetch-pack";
733 argv
[argc
++] = "--stateless-rpc";
734 argv
[argc
++] = "--stdin";
735 argv
[argc
++] = "--lock-pack";
736 if (options
.followtags
)
737 argv
[argc
++] = "--include-tag";
739 argv
[argc
++] = "--thin";
740 if (options
.verbosity
>= 3) {
744 if (options
.check_self_contained_and_connected
)
745 argv
[argc
++] = "--check-self-contained-and-connected";
747 argv
[argc
++] = "--cloning";
748 if (options
.update_shallow
)
749 argv
[argc
++] = "--update-shallow";
750 if (!options
.progress
)
751 argv
[argc
++] = "--no-progress";
753 struct strbuf buf
= STRBUF_INIT
;
754 strbuf_addf(&buf
, "--depth=%lu", options
.depth
);
755 depth_arg
= strbuf_detach(&buf
, NULL
);
756 argv
[argc
++] = depth_arg
;
758 argv
[argc
++] = url
.buf
;
761 for (i
= 0; i
< nr_heads
; i
++) {
762 struct ref
*ref
= to_fetch
[i
];
763 if (!ref
->name
|| !*ref
->name
)
764 die("cannot fetch by sha1 over smart http");
765 packet_buf_write(&preamble
, "%s %s\n",
766 sha1_to_hex(ref
->old_sha1
), ref
->name
);
768 packet_buf_flush(&preamble
);
770 memset(&rpc
, 0, sizeof(rpc
));
771 rpc
.service_name
= "git-upload-pack",
773 rpc
.stdin_preamble
= &preamble
;
774 rpc
.gzip_request
= 1;
776 err
= rpc_service(&rpc
, heads
);
778 write_or_die(1, rpc
.result
.buf
, rpc
.result
.len
);
779 strbuf_release(&rpc
.result
);
780 strbuf_release(&preamble
);
785 static int fetch(int nr_heads
, struct ref
**to_fetch
)
787 struct discovery
*d
= discover_refs("git-upload-pack", 0);
789 return fetch_git(d
, nr_heads
, to_fetch
);
791 return fetch_dumb(nr_heads
, to_fetch
);
794 static void parse_fetch(struct strbuf
*buf
)
796 struct ref
**to_fetch
= NULL
;
797 struct ref
*list_head
= NULL
;
798 struct ref
**list
= &list_head
;
799 int alloc_heads
= 0, nr_heads
= 0;
803 if (skip_prefix(buf
->buf
, "fetch ", &p
)) {
806 unsigned char old_sha1
[20];
808 if (strlen(p
) < 40 || get_sha1_hex(p
, old_sha1
))
809 die("protocol error: expected sha/ref, got %s'", p
);
815 die("protocol error: expected sha/ref, got %s'", p
);
817 ref
= alloc_ref(name
);
818 hashcpy(ref
->old_sha1
, old_sha1
);
823 ALLOC_GROW(to_fetch
, nr_heads
+ 1, alloc_heads
);
824 to_fetch
[nr_heads
++] = ref
;
827 die("http transport does not support %s", buf
->buf
);
830 if (strbuf_getline(buf
, stdin
, '\n') == EOF
)
836 if (fetch(nr_heads
, to_fetch
))
837 exit(128); /* error already reported */
838 free_refs(list_head
);
846 static int push_dav(int nr_spec
, char **specs
)
848 const char **argv
= xmalloc((10 + nr_spec
) * sizeof(char*));
851 argv
[argc
++] = "http-push";
852 argv
[argc
++] = "--helper-status";
854 argv
[argc
++] = "--dry-run";
855 if (options
.verbosity
> 1)
856 argv
[argc
++] = "--verbose";
857 argv
[argc
++] = url
.buf
;
858 for (i
= 0; i
< nr_spec
; i
++)
859 argv
[argc
++] = specs
[i
];
862 if (run_command_v_opt(argv
, RUN_GIT_CMD
))
863 die("git-%s failed", argv
[0]);
868 static int push_git(struct discovery
*heads
, int nr_spec
, char **specs
)
870 struct rpc_state rpc
;
872 struct argv_array args
;
873 struct string_list_item
*cas_option
;
874 struct strbuf preamble
= STRBUF_INIT
;
876 argv_array_init(&args
);
877 argv_array_pushl(&args
, "send-pack", "--stateless-rpc", "--helper-status",
881 argv_array_push(&args
, "--thin");
883 argv_array_push(&args
, "--dry-run");
884 if (options
.push_cert
)
885 argv_array_push(&args
, "--signed");
886 if (options
.verbosity
== 0)
887 argv_array_push(&args
, "--quiet");
888 else if (options
.verbosity
> 1)
889 argv_array_push(&args
, "--verbose");
890 argv_array_push(&args
, options
.progress
? "--progress" : "--no-progress");
891 for_each_string_list_item(cas_option
, &cas_options
)
892 argv_array_push(&args
, cas_option
->string
);
893 argv_array_push(&args
, url
.buf
);
895 argv_array_push(&args
, "--stdin");
896 for (i
= 0; i
< nr_spec
; i
++)
897 packet_buf_write(&preamble
, "%s\n", specs
[i
]);
898 packet_buf_flush(&preamble
);
900 memset(&rpc
, 0, sizeof(rpc
));
901 rpc
.service_name
= "git-receive-pack",
902 rpc
.argv
= args
.argv
;
903 rpc
.stdin_preamble
= &preamble
;
905 err
= rpc_service(&rpc
, heads
);
907 write_or_die(1, rpc
.result
.buf
, rpc
.result
.len
);
908 strbuf_release(&rpc
.result
);
909 strbuf_release(&preamble
);
910 argv_array_clear(&args
);
914 static int push(int nr_spec
, char **specs
)
916 struct discovery
*heads
= discover_refs("git-receive-pack", 1);
919 if (heads
->proto_git
)
920 ret
= push_git(heads
, nr_spec
, specs
);
922 ret
= push_dav(nr_spec
, specs
);
923 free_discovery(heads
);
927 static void parse_push(struct strbuf
*buf
)
930 int alloc_spec
= 0, nr_spec
= 0, i
, ret
;
933 if (starts_with(buf
->buf
, "push ")) {
934 ALLOC_GROW(specs
, nr_spec
+ 1, alloc_spec
);
935 specs
[nr_spec
++] = xstrdup(buf
->buf
+ 5);
938 die("http transport does not support %s", buf
->buf
);
941 if (strbuf_getline(buf
, stdin
, '\n') == EOF
)
947 ret
= push(nr_spec
, specs
);
952 exit(128); /* error already reported */
955 for (i
= 0; i
< nr_spec
; i
++)
960 int main(int argc
, const char **argv
)
962 struct strbuf buf
= STRBUF_INIT
;
965 git_extract_argv0_path(argv
[0]);
966 setup_git_directory_gently(&nongit
);
968 error("remote-curl: usage: git remote-curl <remote> [<url>]");
972 options
.verbosity
= 1;
973 options
.progress
= !!isatty(2);
976 remote
= remote_get(argv
[1]);
979 end_url_with_slash(&url
, argv
[2]);
981 end_url_with_slash(&url
, remote
->url
[0]);
984 http_init(remote
, url
.buf
, 0);
989 if (strbuf_getline(&buf
, stdin
, '\n') == EOF
) {
991 error("remote-curl: error reading command stream from git");
996 if (starts_with(buf
.buf
, "fetch ")) {
998 die("remote-curl: fetch attempted without a local repo");
1001 } else if (!strcmp(buf
.buf
, "list") || starts_with(buf
.buf
, "list ")) {
1002 int for_push
= !!strstr(buf
.buf
+ 4, "for-push");
1003 output_refs(get_refs(for_push
));
1005 } else if (starts_with(buf
.buf
, "push ")) {
1008 } else if (skip_prefix(buf
.buf
, "option ", &arg
)) {
1009 char *value
= strchr(arg
, ' ');
1017 result
= set_option(arg
, value
);
1020 else if (result
< 0)
1021 printf("error invalid value\n");
1023 printf("unsupported\n");
1026 } else if (!strcmp(buf
.buf
, "capabilities")) {
1030 printf("check-connectivity\n");
1034 error("remote-curl: unknown command '%s' from git", buf
.buf
);