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
= xmalloc(sizeof(struct ref
) +
172 strlen(ref_name
) + 1);
173 memset(ref
, 0, sizeof(struct ref
));
174 strcpy(ref
->name
, ref_name
);
175 get_sha1_hex(start
, ref
->old_sha1
);
179 last_ref
->next
= ref
;
186 ref
= alloc_ref("HEAD");
187 if (!http_fetch_ref(url
.buf
, ref
) &&
188 !resolve_remote_symref(ref
, refs
)) {
198 static void free_discovery(struct discovery
*d
)
201 if (d
== last_discovery
)
202 last_discovery
= NULL
;
203 free(d
->shallow
.sha1
);
210 static int show_http_message(struct strbuf
*type
, struct strbuf
*charset
,
216 * We only show text/plain parts, as other types are likely
217 * to be ugly to look at on the user's terminal.
219 if (strcmp(type
->buf
, "text/plain"))
222 strbuf_reencode(msg
, charset
->buf
, get_log_output_encoding());
230 eol
= strchrnul(p
, '\n');
231 fprintf(stderr
, "remote: %.*s\n", (int)(eol
- p
), p
);
237 static struct discovery
*discover_refs(const char *service
, int for_push
)
239 struct strbuf exp
= STRBUF_INIT
;
240 struct strbuf type
= STRBUF_INIT
;
241 struct strbuf charset
= STRBUF_INIT
;
242 struct strbuf buffer
= STRBUF_INIT
;
243 struct strbuf refs_url
= STRBUF_INIT
;
244 struct strbuf effective_url
= STRBUF_INIT
;
245 struct discovery
*last
= last_discovery
;
246 int http_ret
, maybe_smart
= 0;
247 struct http_get_options options
;
249 if (last
&& !strcmp(service
, last
->service
))
251 free_discovery(last
);
253 strbuf_addf(&refs_url
, "%sinfo/refs", url
.buf
);
254 if ((starts_with(url
.buf
, "http://") || starts_with(url
.buf
, "https://")) &&
255 git_env_bool("GIT_SMART_HTTP", 1)) {
257 if (!strchr(url
.buf
, '?'))
258 strbuf_addch(&refs_url
, '?');
260 strbuf_addch(&refs_url
, '&');
261 strbuf_addf(&refs_url
, "service=%s", service
);
264 memset(&options
, 0, sizeof(options
));
265 options
.content_type
= &type
;
266 options
.charset
= &charset
;
267 options
.effective_url
= &effective_url
;
268 options
.base_url
= &url
;
269 options
.no_cache
= 1;
270 options
.keep_error
= 1;
272 http_ret
= http_get_strbuf(refs_url
.buf
, &buffer
, &options
);
276 case HTTP_MISSING_TARGET
:
277 show_http_message(&type
, &charset
, &buffer
);
278 die("repository '%s' not found", url
.buf
);
280 show_http_message(&type
, &charset
, &buffer
);
281 die("Authentication failed for '%s'", url
.buf
);
283 show_http_message(&type
, &charset
, &buffer
);
284 die("unable to access '%s': %s", url
.buf
, curl_errorstr
);
287 last
= xcalloc(1, sizeof(*last_discovery
));
288 last
->service
= service
;
289 last
->buf_alloc
= strbuf_detach(&buffer
, &last
->len
);
290 last
->buf
= last
->buf_alloc
;
292 strbuf_addf(&exp
, "application/x-%s-advertisement", service
);
294 (5 <= last
->len
&& last
->buf
[4] == '#') &&
295 !strbuf_cmp(&exp
, &type
)) {
299 * smart HTTP response; validate that the service
300 * pkt-line matches our request.
302 line
= packet_read_line_buf(&last
->buf
, &last
->len
, NULL
);
305 strbuf_addf(&exp
, "# service=%s", service
);
306 if (strcmp(line
, exp
.buf
))
307 die("invalid server response; got '%s'", line
);
308 strbuf_release(&exp
);
310 /* The header can include additional metadata lines, up
311 * until a packet flush marker. Ignore these now, but
312 * in the future we might start to scan them.
314 while (packet_read_line_buf(&last
->buf
, &last
->len
, NULL
))
321 last
->refs
= parse_git_refs(last
, for_push
);
323 last
->refs
= parse_info_refs(last
);
325 strbuf_release(&refs_url
);
326 strbuf_release(&exp
);
327 strbuf_release(&type
);
328 strbuf_release(&charset
);
329 strbuf_release(&effective_url
);
330 strbuf_release(&buffer
);
331 last_discovery
= last
;
335 static struct ref
*get_refs(int for_push
)
337 struct discovery
*heads
;
340 heads
= discover_refs("git-receive-pack", for_push
);
342 heads
= discover_refs("git-upload-pack", for_push
);
347 static void output_refs(struct ref
*refs
)
350 for (posn
= refs
; posn
; posn
= posn
->next
) {
352 printf("@%s %s\n", posn
->symref
, posn
->name
);
354 printf("%s %s\n", sha1_to_hex(posn
->old_sha1
), posn
->name
);
361 const char *service_name
;
363 struct strbuf
*stdin_preamble
;
365 char *hdr_content_type
;
373 struct strbuf result
;
374 unsigned gzip_request
: 1;
375 unsigned initial_buffer
: 1;
378 static size_t rpc_out(void *ptr
, size_t eltsize
,
379 size_t nmemb
, void *buffer_
)
381 size_t max
= eltsize
* nmemb
;
382 struct rpc_state
*rpc
= buffer_
;
383 size_t avail
= rpc
->len
- rpc
->pos
;
386 rpc
->initial_buffer
= 0;
387 avail
= packet_read(rpc
->out
, NULL
, NULL
, rpc
->buf
, rpc
->alloc
, 0);
396 memcpy(ptr
, rpc
->buf
+ rpc
->pos
, avail
);
401 #ifndef NO_CURL_IOCTL
402 static curlioerr
rpc_ioctl(CURL
*handle
, int cmd
, void *clientp
)
404 struct rpc_state
*rpc
= clientp
;
410 case CURLIOCMD_RESTARTREAD
:
411 if (rpc
->initial_buffer
) {
415 error("unable to rewind rpc post data - try increasing http.postBuffer");
416 return CURLIOE_FAILRESTART
;
419 return CURLIOE_UNKNOWNCMD
;
424 static size_t rpc_in(char *ptr
, size_t eltsize
,
425 size_t nmemb
, void *buffer_
)
427 size_t size
= eltsize
* nmemb
;
428 struct rpc_state
*rpc
= buffer_
;
429 write_or_die(rpc
->in
, ptr
, size
);
433 static int run_slot(struct active_request_slot
*slot
,
434 struct slot_results
*results
)
437 struct slot_results results_buf
;
440 results
= &results_buf
;
442 err
= run_one_slot(slot
, results
);
444 if (err
!= HTTP_OK
&& err
!= HTTP_REAUTH
) {
445 error("RPC failed; result=%d, HTTP code = %ld",
446 results
->curl_result
, results
->http_code
);
452 static int probe_rpc(struct rpc_state
*rpc
, struct slot_results
*results
)
454 struct active_request_slot
*slot
;
455 struct curl_slist
*headers
= NULL
;
456 struct strbuf buf
= STRBUF_INIT
;
459 slot
= get_active_slot();
461 headers
= curl_slist_append(headers
, rpc
->hdr_content_type
);
462 headers
= curl_slist_append(headers
, rpc
->hdr_accept
);
464 curl_easy_setopt(slot
->curl
, CURLOPT_NOBODY
, 0);
465 curl_easy_setopt(slot
->curl
, CURLOPT_POST
, 1);
466 curl_easy_setopt(slot
->curl
, CURLOPT_URL
, rpc
->service_url
);
467 curl_easy_setopt(slot
->curl
, CURLOPT_ENCODING
, NULL
);
468 curl_easy_setopt(slot
->curl
, CURLOPT_POSTFIELDS
, "0000");
469 curl_easy_setopt(slot
->curl
, CURLOPT_POSTFIELDSIZE
, 4);
470 curl_easy_setopt(slot
->curl
, CURLOPT_HTTPHEADER
, headers
);
471 curl_easy_setopt(slot
->curl
, CURLOPT_WRITEFUNCTION
, fwrite_buffer
);
472 curl_easy_setopt(slot
->curl
, CURLOPT_FILE
, &buf
);
474 err
= run_slot(slot
, results
);
476 curl_slist_free_all(headers
);
477 strbuf_release(&buf
);
481 static int post_rpc(struct rpc_state
*rpc
)
483 struct active_request_slot
*slot
;
484 struct curl_slist
*headers
= NULL
;
485 int use_gzip
= rpc
->gzip_request
;
486 char *gzip_body
= NULL
;
487 size_t gzip_size
= 0;
488 int err
, large_request
= 0;
489 int needs_100_continue
= 0;
491 /* Try to load the entire request, if we can fit it into the
492 * allocated buffer space we can use HTTP/1.0 and avoid the
493 * chunked encoding mess.
496 size_t left
= rpc
->alloc
- rpc
->len
;
497 char *buf
= rpc
->buf
+ rpc
->len
;
500 if (left
< LARGE_PACKET_MAX
) {
506 n
= packet_read(rpc
->out
, NULL
, NULL
, buf
, left
, 0);
513 struct slot_results results
;
516 err
= probe_rpc(rpc
, &results
);
517 if (err
== HTTP_REAUTH
)
518 credential_fill(&http_auth
);
519 } while (err
== HTTP_REAUTH
);
523 if (results
.auth_avail
& CURLAUTH_GSSNEGOTIATE
)
524 needs_100_continue
= 1;
527 headers
= curl_slist_append(headers
, rpc
->hdr_content_type
);
528 headers
= curl_slist_append(headers
, rpc
->hdr_accept
);
529 headers
= curl_slist_append(headers
, needs_100_continue
?
530 "Expect: 100-continue" : "Expect:");
533 slot
= get_active_slot();
535 curl_easy_setopt(slot
->curl
, CURLOPT_NOBODY
, 0);
536 curl_easy_setopt(slot
->curl
, CURLOPT_POST
, 1);
537 curl_easy_setopt(slot
->curl
, CURLOPT_URL
, rpc
->service_url
);
538 curl_easy_setopt(slot
->curl
, CURLOPT_ENCODING
, "gzip");
541 /* The request body is large and the size cannot be predicted.
542 * We must use chunked encoding to send it.
544 headers
= curl_slist_append(headers
, "Transfer-Encoding: chunked");
545 rpc
->initial_buffer
= 1;
546 curl_easy_setopt(slot
->curl
, CURLOPT_READFUNCTION
, rpc_out
);
547 curl_easy_setopt(slot
->curl
, CURLOPT_INFILE
, rpc
);
548 #ifndef NO_CURL_IOCTL
549 curl_easy_setopt(slot
->curl
, CURLOPT_IOCTLFUNCTION
, rpc_ioctl
);
550 curl_easy_setopt(slot
->curl
, CURLOPT_IOCTLDATA
, rpc
);
552 if (options
.verbosity
> 1) {
553 fprintf(stderr
, "POST %s (chunked)\n", rpc
->service_name
);
557 } else if (gzip_body
) {
559 * If we are looping to retry authentication, then the previous
560 * run will have set up the headers and gzip buffer already,
561 * and we just need to send it.
563 curl_easy_setopt(slot
->curl
, CURLOPT_POSTFIELDS
, gzip_body
);
564 curl_easy_setopt(slot
->curl
, CURLOPT_POSTFIELDSIZE
, gzip_size
);
566 } else if (use_gzip
&& 1024 < rpc
->len
) {
567 /* The client backend isn't giving us compressed data so
568 * we can try to deflate it ourselves, this may save on.
574 git_deflate_init_gzip(&stream
, Z_BEST_COMPRESSION
);
575 gzip_size
= git_deflate_bound(&stream
, rpc
->len
);
576 gzip_body
= xmalloc(gzip_size
);
578 stream
.next_in
= (unsigned char *)rpc
->buf
;
579 stream
.avail_in
= rpc
->len
;
580 stream
.next_out
= (unsigned char *)gzip_body
;
581 stream
.avail_out
= gzip_size
;
583 ret
= git_deflate(&stream
, Z_FINISH
);
584 if (ret
!= Z_STREAM_END
)
585 die("cannot deflate request; zlib deflate error %d", ret
);
587 ret
= git_deflate_end_gently(&stream
);
589 die("cannot deflate request; zlib end error %d", ret
);
591 gzip_size
= stream
.total_out
;
593 headers
= curl_slist_append(headers
, "Content-Encoding: gzip");
594 curl_easy_setopt(slot
->curl
, CURLOPT_POSTFIELDS
, gzip_body
);
595 curl_easy_setopt(slot
->curl
, CURLOPT_POSTFIELDSIZE
, gzip_size
);
597 if (options
.verbosity
> 1) {
598 fprintf(stderr
, "POST %s (gzip %lu to %lu bytes)\n",
600 (unsigned long)rpc
->len
, (unsigned long)gzip_size
);
604 /* We know the complete request size in advance, use the
605 * more normal Content-Length approach.
607 curl_easy_setopt(slot
->curl
, CURLOPT_POSTFIELDS
, rpc
->buf
);
608 curl_easy_setopt(slot
->curl
, CURLOPT_POSTFIELDSIZE
, rpc
->len
);
609 if (options
.verbosity
> 1) {
610 fprintf(stderr
, "POST %s (%lu bytes)\n",
611 rpc
->service_name
, (unsigned long)rpc
->len
);
616 curl_easy_setopt(slot
->curl
, CURLOPT_HTTPHEADER
, headers
);
617 curl_easy_setopt(slot
->curl
, CURLOPT_WRITEFUNCTION
, rpc_in
);
618 curl_easy_setopt(slot
->curl
, CURLOPT_FILE
, rpc
);
620 err
= run_slot(slot
, NULL
);
621 if (err
== HTTP_REAUTH
&& !large_request
) {
622 credential_fill(&http_auth
);
628 curl_slist_free_all(headers
);
633 static int rpc_service(struct rpc_state
*rpc
, struct discovery
*heads
)
635 const char *svc
= rpc
->service_name
;
636 struct strbuf buf
= STRBUF_INIT
;
637 struct strbuf
*preamble
= rpc
->stdin_preamble
;
638 struct child_process client
= CHILD_PROCESS_INIT
;
644 client
.argv
= rpc
->argv
;
645 if (start_command(&client
))
648 write_or_die(client
.in
, preamble
->buf
, preamble
->len
);
650 write_or_die(client
.in
, heads
->buf
, heads
->len
);
652 rpc
->alloc
= http_post_buffer
;
653 rpc
->buf
= xmalloc(rpc
->alloc
);
655 rpc
->out
= client
.out
;
656 strbuf_init(&rpc
->result
, 0);
658 strbuf_addf(&buf
, "%s%s", url
.buf
, svc
);
659 rpc
->service_url
= strbuf_detach(&buf
, NULL
);
661 strbuf_addf(&buf
, "Content-Type: application/x-%s-request", svc
);
662 rpc
->hdr_content_type
= strbuf_detach(&buf
, NULL
);
664 strbuf_addf(&buf
, "Accept: application/x-%s-result", svc
);
665 rpc
->hdr_accept
= strbuf_detach(&buf
, NULL
);
668 int n
= packet_read(rpc
->out
, NULL
, NULL
, rpc
->buf
, rpc
->alloc
, 0);
673 err
|= post_rpc(rpc
);
679 strbuf_read(&rpc
->result
, client
.out
, 0);
683 if (xread(client
.out
, buf
, sizeof(buf
)) <= 0)
690 err
|= finish_command(&client
);
691 free(rpc
->service_url
);
692 free(rpc
->hdr_content_type
);
693 free(rpc
->hdr_accept
);
695 strbuf_release(&buf
);
699 static int fetch_dumb(int nr_heads
, struct ref
**to_fetch
)
701 struct walker
*walker
;
702 char **targets
= xmalloc(nr_heads
* sizeof(char*));
706 die("dumb http transport does not support --depth");
707 for (i
= 0; i
< nr_heads
; i
++)
708 targets
[i
] = xstrdup(sha1_to_hex(to_fetch
[i
]->old_sha1
));
710 walker
= get_http_walker(url
.buf
);
712 walker
->get_tree
= 1;
713 walker
->get_history
= 1;
714 walker
->get_verbosely
= options
.verbosity
>= 3;
715 walker
->get_recover
= 0;
716 ret
= walker_fetch(walker
, nr_heads
, targets
, NULL
, NULL
);
719 for (i
= 0; i
< nr_heads
; i
++)
723 return ret
? error("fetch failed.") : 0;
726 static int fetch_git(struct discovery
*heads
,
727 int nr_heads
, struct ref
**to_fetch
)
729 struct rpc_state rpc
;
730 struct strbuf preamble
= STRBUF_INIT
;
731 char *depth_arg
= NULL
;
732 int argc
= 0, i
, err
;
733 const char *argv
[17];
735 argv
[argc
++] = "fetch-pack";
736 argv
[argc
++] = "--stateless-rpc";
737 argv
[argc
++] = "--stdin";
738 argv
[argc
++] = "--lock-pack";
739 if (options
.followtags
)
740 argv
[argc
++] = "--include-tag";
742 argv
[argc
++] = "--thin";
743 if (options
.verbosity
>= 3) {
747 if (options
.check_self_contained_and_connected
)
748 argv
[argc
++] = "--check-self-contained-and-connected";
750 argv
[argc
++] = "--cloning";
751 if (options
.update_shallow
)
752 argv
[argc
++] = "--update-shallow";
753 if (!options
.progress
)
754 argv
[argc
++] = "--no-progress";
756 struct strbuf buf
= STRBUF_INIT
;
757 strbuf_addf(&buf
, "--depth=%lu", options
.depth
);
758 depth_arg
= strbuf_detach(&buf
, NULL
);
759 argv
[argc
++] = depth_arg
;
761 argv
[argc
++] = url
.buf
;
764 for (i
= 0; i
< nr_heads
; i
++) {
765 struct ref
*ref
= to_fetch
[i
];
767 die("cannot fetch by sha1 over smart http");
768 packet_buf_write(&preamble
, "%s %s\n",
769 sha1_to_hex(ref
->old_sha1
), ref
->name
);
771 packet_buf_flush(&preamble
);
773 memset(&rpc
, 0, sizeof(rpc
));
774 rpc
.service_name
= "git-upload-pack",
776 rpc
.stdin_preamble
= &preamble
;
777 rpc
.gzip_request
= 1;
779 err
= rpc_service(&rpc
, heads
);
781 write_or_die(1, rpc
.result
.buf
, rpc
.result
.len
);
782 strbuf_release(&rpc
.result
);
783 strbuf_release(&preamble
);
788 static int fetch(int nr_heads
, struct ref
**to_fetch
)
790 struct discovery
*d
= discover_refs("git-upload-pack", 0);
792 return fetch_git(d
, nr_heads
, to_fetch
);
794 return fetch_dumb(nr_heads
, to_fetch
);
797 static void parse_fetch(struct strbuf
*buf
)
799 struct ref
**to_fetch
= NULL
;
800 struct ref
*list_head
= NULL
;
801 struct ref
**list
= &list_head
;
802 int alloc_heads
= 0, nr_heads
= 0;
806 if (skip_prefix(buf
->buf
, "fetch ", &p
)) {
809 unsigned char old_sha1
[20];
811 if (strlen(p
) < 40 || get_sha1_hex(p
, old_sha1
))
812 die("protocol error: expected sha/ref, got %s'", p
);
818 die("protocol error: expected sha/ref, got %s'", p
);
820 ref
= alloc_ref(name
);
821 hashcpy(ref
->old_sha1
, old_sha1
);
826 ALLOC_GROW(to_fetch
, nr_heads
+ 1, alloc_heads
);
827 to_fetch
[nr_heads
++] = ref
;
830 die("http transport does not support %s", buf
->buf
);
833 if (strbuf_getline(buf
, stdin
, '\n') == EOF
)
839 if (fetch(nr_heads
, to_fetch
))
840 exit(128); /* error already reported */
841 free_refs(list_head
);
849 static int push_dav(int nr_spec
, char **specs
)
851 const char **argv
= xmalloc((10 + nr_spec
) * sizeof(char*));
854 argv
[argc
++] = "http-push";
855 argv
[argc
++] = "--helper-status";
857 argv
[argc
++] = "--dry-run";
858 if (options
.verbosity
> 1)
859 argv
[argc
++] = "--verbose";
860 argv
[argc
++] = url
.buf
;
861 for (i
= 0; i
< nr_spec
; i
++)
862 argv
[argc
++] = specs
[i
];
865 if (run_command_v_opt(argv
, RUN_GIT_CMD
))
866 die("git-%s failed", argv
[0]);
871 static int push_git(struct discovery
*heads
, int nr_spec
, char **specs
)
873 struct rpc_state rpc
;
875 struct argv_array args
;
876 struct string_list_item
*cas_option
;
877 struct strbuf preamble
= STRBUF_INIT
;
879 argv_array_init(&args
);
880 argv_array_pushl(&args
, "send-pack", "--stateless-rpc", "--helper-status",
884 argv_array_push(&args
, "--thin");
886 argv_array_push(&args
, "--dry-run");
887 if (options
.push_cert
== SEND_PACK_PUSH_CERT_ALWAYS
)
888 argv_array_push(&args
, "--signed=yes");
889 else if (options
.push_cert
== SEND_PACK_PUSH_CERT_IF_ASKED
)
890 argv_array_push(&args
, "--signed=if-asked");
891 if (options
.verbosity
== 0)
892 argv_array_push(&args
, "--quiet");
893 else if (options
.verbosity
> 1)
894 argv_array_push(&args
, "--verbose");
895 argv_array_push(&args
, options
.progress
? "--progress" : "--no-progress");
896 for_each_string_list_item(cas_option
, &cas_options
)
897 argv_array_push(&args
, cas_option
->string
);
898 argv_array_push(&args
, url
.buf
);
900 argv_array_push(&args
, "--stdin");
901 for (i
= 0; i
< nr_spec
; i
++)
902 packet_buf_write(&preamble
, "%s\n", specs
[i
]);
903 packet_buf_flush(&preamble
);
905 memset(&rpc
, 0, sizeof(rpc
));
906 rpc
.service_name
= "git-receive-pack",
907 rpc
.argv
= args
.argv
;
908 rpc
.stdin_preamble
= &preamble
;
910 err
= rpc_service(&rpc
, heads
);
912 write_or_die(1, rpc
.result
.buf
, rpc
.result
.len
);
913 strbuf_release(&rpc
.result
);
914 strbuf_release(&preamble
);
915 argv_array_clear(&args
);
919 static int push(int nr_spec
, char **specs
)
921 struct discovery
*heads
= discover_refs("git-receive-pack", 1);
924 if (heads
->proto_git
)
925 ret
= push_git(heads
, nr_spec
, specs
);
927 ret
= push_dav(nr_spec
, specs
);
928 free_discovery(heads
);
932 static void parse_push(struct strbuf
*buf
)
935 int alloc_spec
= 0, nr_spec
= 0, i
, ret
;
938 if (starts_with(buf
->buf
, "push ")) {
939 ALLOC_GROW(specs
, nr_spec
+ 1, alloc_spec
);
940 specs
[nr_spec
++] = xstrdup(buf
->buf
+ 5);
943 die("http transport does not support %s", buf
->buf
);
946 if (strbuf_getline(buf
, stdin
, '\n') == EOF
)
952 ret
= push(nr_spec
, specs
);
957 exit(128); /* error already reported */
960 for (i
= 0; i
< nr_spec
; i
++)
965 int main(int argc
, const char **argv
)
967 struct strbuf buf
= STRBUF_INIT
;
972 git_extract_argv0_path(argv
[0]);
973 setup_git_directory_gently(&nongit
);
975 error("remote-curl: usage: git remote-curl <remote> [<url>]");
979 options
.verbosity
= 1;
980 options
.progress
= !!isatty(2);
983 remote
= remote_get(argv
[1]);
986 end_url_with_slash(&url
, argv
[2]);
988 end_url_with_slash(&url
, remote
->url
[0]);
991 http_init(remote
, url
.buf
, 0);
996 if (strbuf_getline(&buf
, stdin
, '\n') == EOF
) {
998 error("remote-curl: error reading command stream from git");
1003 if (starts_with(buf
.buf
, "fetch ")) {
1005 die("remote-curl: fetch attempted without a local repo");
1008 } else if (!strcmp(buf
.buf
, "list") || starts_with(buf
.buf
, "list ")) {
1009 int for_push
= !!strstr(buf
.buf
+ 4, "for-push");
1010 output_refs(get_refs(for_push
));
1012 } else if (starts_with(buf
.buf
, "push ")) {
1015 } else if (skip_prefix(buf
.buf
, "option ", &arg
)) {
1016 char *value
= strchr(arg
, ' ');
1024 result
= set_option(arg
, value
);
1027 else if (result
< 0)
1028 printf("error invalid value\n");
1030 printf("unsupported\n");
1033 } else if (!strcmp(buf
.buf
, "capabilities")) {
1037 printf("check-connectivity\n");
1041 error("remote-curl: unknown command '%s' from git", buf
.buf
);