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 unsigned progress
: 1,
25 check_self_contained_and_connected
: 1,
31 /* One of the SEND_PACK_PUSH_CERT_* constants. */
34 static struct options options
;
35 static struct string_list cas_options
= STRING_LIST_INIT_DUP
;
37 static int set_option(const char *name
, const char *value
)
39 if (!strcmp(name
, "verbosity")) {
41 int v
= strtol(value
, &end
, 10);
42 if (value
== end
|| *end
)
44 options
.verbosity
= v
;
47 else if (!strcmp(name
, "progress")) {
48 if (!strcmp(value
, "true"))
50 else if (!strcmp(value
, "false"))
56 else if (!strcmp(name
, "depth")) {
58 unsigned long v
= strtoul(value
, &end
, 10);
59 if (value
== end
|| *end
)
64 else if (!strcmp(name
, "deepen-since")) {
65 options
.deepen_since
= xstrdup(value
);
68 else if (!strcmp(name
, "followtags")) {
69 if (!strcmp(value
, "true"))
70 options
.followtags
= 1;
71 else if (!strcmp(value
, "false"))
72 options
.followtags
= 0;
77 else if (!strcmp(name
, "dry-run")) {
78 if (!strcmp(value
, "true"))
80 else if (!strcmp(value
, "false"))
86 else if (!strcmp(name
, "check-connectivity")) {
87 if (!strcmp(value
, "true"))
88 options
.check_self_contained_and_connected
= 1;
89 else if (!strcmp(value
, "false"))
90 options
.check_self_contained_and_connected
= 0;
95 else if (!strcmp(name
, "cas")) {
96 struct strbuf val
= STRBUF_INIT
;
97 strbuf_addf(&val
, "--" CAS_OPT_NAME
"=%s", value
);
98 string_list_append(&cas_options
, val
.buf
);
101 } else if (!strcmp(name
, "cloning")) {
102 if (!strcmp(value
, "true"))
104 else if (!strcmp(value
, "false"))
109 } else if (!strcmp(name
, "update-shallow")) {
110 if (!strcmp(value
, "true"))
111 options
.update_shallow
= 1;
112 else if (!strcmp(value
, "false"))
113 options
.update_shallow
= 0;
117 } else if (!strcmp(name
, "pushcert")) {
118 if (!strcmp(value
, "true"))
119 options
.push_cert
= SEND_PACK_PUSH_CERT_ALWAYS
;
120 else if (!strcmp(value
, "false"))
121 options
.push_cert
= SEND_PACK_PUSH_CERT_NEVER
;
122 else if (!strcmp(value
, "if-asked"))
123 options
.push_cert
= SEND_PACK_PUSH_CERT_IF_ASKED
;
128 return 1 /* unsupported */;
138 struct sha1_array shallow
;
139 unsigned proto_git
: 1;
141 static struct discovery
*last_discovery
;
143 static struct ref
*parse_git_refs(struct discovery
*heads
, int for_push
)
145 struct ref
*list
= NULL
;
146 get_remote_heads(-1, heads
->buf
, heads
->len
, &list
,
147 for_push
? REF_NORMAL
: 0, NULL
, &heads
->shallow
);
151 static struct ref
*parse_info_refs(struct discovery
*heads
)
153 char *data
, *start
, *mid
;
157 struct ref
*refs
= NULL
;
158 struct ref
*ref
= NULL
;
159 struct ref
*last_ref
= NULL
;
164 while (i
< heads
->len
) {
170 if (data
[i
] == '\n') {
171 if (mid
- start
!= 40)
172 die("%sinfo/refs not valid: is this a git repository?",
176 ref
= alloc_ref(ref_name
);
177 get_oid_hex(start
, &ref
->old_oid
);
181 last_ref
->next
= ref
;
188 ref
= alloc_ref("HEAD");
189 if (!http_fetch_ref(url
.buf
, ref
) &&
190 !resolve_remote_symref(ref
, refs
)) {
200 static void free_discovery(struct discovery
*d
)
203 if (d
== last_discovery
)
204 last_discovery
= NULL
;
205 free(d
->shallow
.sha1
);
212 static int show_http_message(struct strbuf
*type
, struct strbuf
*charset
,
218 * We only show text/plain parts, as other types are likely
219 * to be ugly to look at on the user's terminal.
221 if (strcmp(type
->buf
, "text/plain"))
224 strbuf_reencode(msg
, charset
->buf
, get_log_output_encoding());
232 eol
= strchrnul(p
, '\n');
233 fprintf(stderr
, "remote: %.*s\n", (int)(eol
- p
), p
);
239 static struct discovery
*discover_refs(const char *service
, int for_push
)
241 struct strbuf exp
= STRBUF_INIT
;
242 struct strbuf type
= STRBUF_INIT
;
243 struct strbuf charset
= STRBUF_INIT
;
244 struct strbuf buffer
= STRBUF_INIT
;
245 struct strbuf refs_url
= STRBUF_INIT
;
246 struct strbuf effective_url
= STRBUF_INIT
;
247 struct discovery
*last
= last_discovery
;
248 int http_ret
, maybe_smart
= 0;
249 struct http_get_options options
;
251 if (last
&& !strcmp(service
, last
->service
))
253 free_discovery(last
);
255 strbuf_addf(&refs_url
, "%sinfo/refs", url
.buf
);
256 if ((starts_with(url
.buf
, "http://") || starts_with(url
.buf
, "https://")) &&
257 git_env_bool("GIT_SMART_HTTP", 1)) {
259 if (!strchr(url
.buf
, '?'))
260 strbuf_addch(&refs_url
, '?');
262 strbuf_addch(&refs_url
, '&');
263 strbuf_addf(&refs_url
, "service=%s", service
);
266 memset(&options
, 0, sizeof(options
));
267 options
.content_type
= &type
;
268 options
.charset
= &charset
;
269 options
.effective_url
= &effective_url
;
270 options
.base_url
= &url
;
271 options
.no_cache
= 1;
272 options
.keep_error
= 1;
274 http_ret
= http_get_strbuf(refs_url
.buf
, &buffer
, &options
);
278 case HTTP_MISSING_TARGET
:
279 show_http_message(&type
, &charset
, &buffer
);
280 die("repository '%s' not found", url
.buf
);
282 show_http_message(&type
, &charset
, &buffer
);
283 die("Authentication failed for '%s'", url
.buf
);
285 show_http_message(&type
, &charset
, &buffer
);
286 die("unable to access '%s': %s", url
.buf
, curl_errorstr
);
289 last
= xcalloc(1, sizeof(*last_discovery
));
290 last
->service
= service
;
291 last
->buf_alloc
= strbuf_detach(&buffer
, &last
->len
);
292 last
->buf
= last
->buf_alloc
;
294 strbuf_addf(&exp
, "application/x-%s-advertisement", service
);
296 (5 <= last
->len
&& last
->buf
[4] == '#') &&
297 !strbuf_cmp(&exp
, &type
)) {
301 * smart HTTP response; validate that the service
302 * pkt-line matches our request.
304 line
= packet_read_line_buf(&last
->buf
, &last
->len
, NULL
);
307 strbuf_addf(&exp
, "# service=%s", service
);
308 if (strcmp(line
, exp
.buf
))
309 die("invalid server response; got '%s'", line
);
310 strbuf_release(&exp
);
312 /* The header can include additional metadata lines, up
313 * until a packet flush marker. Ignore these now, but
314 * in the future we might start to scan them.
316 while (packet_read_line_buf(&last
->buf
, &last
->len
, NULL
))
323 last
->refs
= parse_git_refs(last
, for_push
);
325 last
->refs
= parse_info_refs(last
);
327 strbuf_release(&refs_url
);
328 strbuf_release(&exp
);
329 strbuf_release(&type
);
330 strbuf_release(&charset
);
331 strbuf_release(&effective_url
);
332 strbuf_release(&buffer
);
333 last_discovery
= last
;
337 static struct ref
*get_refs(int for_push
)
339 struct discovery
*heads
;
342 heads
= discover_refs("git-receive-pack", for_push
);
344 heads
= discover_refs("git-upload-pack", for_push
);
349 static void output_refs(struct ref
*refs
)
352 for (posn
= refs
; posn
; posn
= posn
->next
) {
354 printf("@%s %s\n", posn
->symref
, posn
->name
);
356 printf("%s %s\n", oid_to_hex(&posn
->old_oid
), posn
->name
);
363 const char *service_name
;
365 struct strbuf
*stdin_preamble
;
367 char *hdr_content_type
;
375 struct strbuf result
;
376 unsigned gzip_request
: 1;
377 unsigned initial_buffer
: 1;
380 static size_t rpc_out(void *ptr
, size_t eltsize
,
381 size_t nmemb
, void *buffer_
)
383 size_t max
= eltsize
* nmemb
;
384 struct rpc_state
*rpc
= buffer_
;
385 size_t avail
= rpc
->len
- rpc
->pos
;
388 rpc
->initial_buffer
= 0;
389 avail
= packet_read(rpc
->out
, NULL
, NULL
, rpc
->buf
, rpc
->alloc
, 0);
398 memcpy(ptr
, rpc
->buf
+ rpc
->pos
, avail
);
403 #ifndef NO_CURL_IOCTL
404 static curlioerr
rpc_ioctl(CURL
*handle
, int cmd
, void *clientp
)
406 struct rpc_state
*rpc
= clientp
;
412 case CURLIOCMD_RESTARTREAD
:
413 if (rpc
->initial_buffer
) {
417 error("unable to rewind rpc post data - try increasing http.postBuffer");
418 return CURLIOE_FAILRESTART
;
421 return CURLIOE_UNKNOWNCMD
;
426 static size_t rpc_in(char *ptr
, size_t eltsize
,
427 size_t nmemb
, void *buffer_
)
429 size_t size
= eltsize
* nmemb
;
430 struct rpc_state
*rpc
= buffer_
;
431 write_or_die(rpc
->in
, ptr
, size
);
435 static int run_slot(struct active_request_slot
*slot
,
436 struct slot_results
*results
)
439 struct slot_results results_buf
;
442 results
= &results_buf
;
444 err
= run_one_slot(slot
, results
);
446 if (err
!= HTTP_OK
&& err
!= HTTP_REAUTH
) {
447 error("RPC failed; result=%d, HTTP code = %ld",
448 results
->curl_result
, results
->http_code
);
454 static int probe_rpc(struct rpc_state
*rpc
, struct slot_results
*results
)
456 struct active_request_slot
*slot
;
457 struct curl_slist
*headers
= NULL
;
458 struct strbuf buf
= STRBUF_INIT
;
461 slot
= get_active_slot();
463 headers
= curl_slist_append(headers
, rpc
->hdr_content_type
);
464 headers
= curl_slist_append(headers
, rpc
->hdr_accept
);
466 curl_easy_setopt(slot
->curl
, CURLOPT_NOBODY
, 0);
467 curl_easy_setopt(slot
->curl
, CURLOPT_POST
, 1);
468 curl_easy_setopt(slot
->curl
, CURLOPT_URL
, rpc
->service_url
);
469 curl_easy_setopt(slot
->curl
, CURLOPT_ENCODING
, NULL
);
470 curl_easy_setopt(slot
->curl
, CURLOPT_POSTFIELDS
, "0000");
471 curl_easy_setopt(slot
->curl
, CURLOPT_POSTFIELDSIZE
, 4);
472 curl_easy_setopt(slot
->curl
, CURLOPT_HTTPHEADER
, headers
);
473 curl_easy_setopt(slot
->curl
, CURLOPT_WRITEFUNCTION
, fwrite_buffer
);
474 curl_easy_setopt(slot
->curl
, CURLOPT_FILE
, &buf
);
476 err
= run_slot(slot
, results
);
478 curl_slist_free_all(headers
);
479 strbuf_release(&buf
);
483 static int post_rpc(struct rpc_state
*rpc
)
485 struct active_request_slot
*slot
;
486 struct curl_slist
*headers
= NULL
;
487 int use_gzip
= rpc
->gzip_request
;
488 char *gzip_body
= NULL
;
489 size_t gzip_size
= 0;
490 int err
, large_request
= 0;
491 int needs_100_continue
= 0;
493 /* Try to load the entire request, if we can fit it into the
494 * allocated buffer space we can use HTTP/1.0 and avoid the
495 * chunked encoding mess.
498 size_t left
= rpc
->alloc
- rpc
->len
;
499 char *buf
= rpc
->buf
+ rpc
->len
;
502 if (left
< LARGE_PACKET_MAX
) {
508 n
= packet_read(rpc
->out
, NULL
, NULL
, buf
, left
, 0);
515 struct slot_results results
;
518 err
= probe_rpc(rpc
, &results
);
519 if (err
== HTTP_REAUTH
)
520 credential_fill(&http_auth
);
521 } while (err
== HTTP_REAUTH
);
525 if (results
.auth_avail
& CURLAUTH_GSSNEGOTIATE
)
526 needs_100_continue
= 1;
529 headers
= curl_slist_append(headers
, rpc
->hdr_content_type
);
530 headers
= curl_slist_append(headers
, rpc
->hdr_accept
);
531 headers
= curl_slist_append(headers
, needs_100_continue
?
532 "Expect: 100-continue" : "Expect:");
535 slot
= get_active_slot();
537 curl_easy_setopt(slot
->curl
, CURLOPT_NOBODY
, 0);
538 curl_easy_setopt(slot
->curl
, CURLOPT_POST
, 1);
539 curl_easy_setopt(slot
->curl
, CURLOPT_URL
, rpc
->service_url
);
540 curl_easy_setopt(slot
->curl
, CURLOPT_ENCODING
, "gzip");
543 /* The request body is large and the size cannot be predicted.
544 * We must use chunked encoding to send it.
546 headers
= curl_slist_append(headers
, "Transfer-Encoding: chunked");
547 rpc
->initial_buffer
= 1;
548 curl_easy_setopt(slot
->curl
, CURLOPT_READFUNCTION
, rpc_out
);
549 curl_easy_setopt(slot
->curl
, CURLOPT_INFILE
, rpc
);
550 #ifndef NO_CURL_IOCTL
551 curl_easy_setopt(slot
->curl
, CURLOPT_IOCTLFUNCTION
, rpc_ioctl
);
552 curl_easy_setopt(slot
->curl
, CURLOPT_IOCTLDATA
, rpc
);
554 if (options
.verbosity
> 1) {
555 fprintf(stderr
, "POST %s (chunked)\n", rpc
->service_name
);
559 } else if (gzip_body
) {
561 * If we are looping to retry authentication, then the previous
562 * run will have set up the headers and gzip buffer already,
563 * and we just need to send it.
565 curl_easy_setopt(slot
->curl
, CURLOPT_POSTFIELDS
, gzip_body
);
566 curl_easy_setopt(slot
->curl
, CURLOPT_POSTFIELDSIZE
, gzip_size
);
568 } else if (use_gzip
&& 1024 < rpc
->len
) {
569 /* The client backend isn't giving us compressed data so
570 * we can try to deflate it ourselves, this may save on.
576 git_deflate_init_gzip(&stream
, Z_BEST_COMPRESSION
);
577 gzip_size
= git_deflate_bound(&stream
, rpc
->len
);
578 gzip_body
= xmalloc(gzip_size
);
580 stream
.next_in
= (unsigned char *)rpc
->buf
;
581 stream
.avail_in
= rpc
->len
;
582 stream
.next_out
= (unsigned char *)gzip_body
;
583 stream
.avail_out
= gzip_size
;
585 ret
= git_deflate(&stream
, Z_FINISH
);
586 if (ret
!= Z_STREAM_END
)
587 die("cannot deflate request; zlib deflate error %d", ret
);
589 ret
= git_deflate_end_gently(&stream
);
591 die("cannot deflate request; zlib end error %d", ret
);
593 gzip_size
= stream
.total_out
;
595 headers
= curl_slist_append(headers
, "Content-Encoding: gzip");
596 curl_easy_setopt(slot
->curl
, CURLOPT_POSTFIELDS
, gzip_body
);
597 curl_easy_setopt(slot
->curl
, CURLOPT_POSTFIELDSIZE
, gzip_size
);
599 if (options
.verbosity
> 1) {
600 fprintf(stderr
, "POST %s (gzip %lu to %lu bytes)\n",
602 (unsigned long)rpc
->len
, (unsigned long)gzip_size
);
606 /* We know the complete request size in advance, use the
607 * more normal Content-Length approach.
609 curl_easy_setopt(slot
->curl
, CURLOPT_POSTFIELDS
, rpc
->buf
);
610 curl_easy_setopt(slot
->curl
, CURLOPT_POSTFIELDSIZE
, rpc
->len
);
611 if (options
.verbosity
> 1) {
612 fprintf(stderr
, "POST %s (%lu bytes)\n",
613 rpc
->service_name
, (unsigned long)rpc
->len
);
618 curl_easy_setopt(slot
->curl
, CURLOPT_HTTPHEADER
, headers
);
619 curl_easy_setopt(slot
->curl
, CURLOPT_WRITEFUNCTION
, rpc_in
);
620 curl_easy_setopt(slot
->curl
, CURLOPT_FILE
, rpc
);
622 err
= run_slot(slot
, NULL
);
623 if (err
== HTTP_REAUTH
&& !large_request
) {
624 credential_fill(&http_auth
);
630 curl_slist_free_all(headers
);
635 static int rpc_service(struct rpc_state
*rpc
, struct discovery
*heads
)
637 const char *svc
= rpc
->service_name
;
638 struct strbuf buf
= STRBUF_INIT
;
639 struct strbuf
*preamble
= rpc
->stdin_preamble
;
640 struct child_process client
= CHILD_PROCESS_INIT
;
646 client
.argv
= rpc
->argv
;
647 if (start_command(&client
))
650 write_or_die(client
.in
, preamble
->buf
, preamble
->len
);
652 write_or_die(client
.in
, heads
->buf
, heads
->len
);
654 rpc
->alloc
= http_post_buffer
;
655 rpc
->buf
= xmalloc(rpc
->alloc
);
657 rpc
->out
= client
.out
;
658 strbuf_init(&rpc
->result
, 0);
660 strbuf_addf(&buf
, "%s%s", url
.buf
, svc
);
661 rpc
->service_url
= strbuf_detach(&buf
, NULL
);
663 strbuf_addf(&buf
, "Content-Type: application/x-%s-request", svc
);
664 rpc
->hdr_content_type
= strbuf_detach(&buf
, NULL
);
666 strbuf_addf(&buf
, "Accept: application/x-%s-result", svc
);
667 rpc
->hdr_accept
= strbuf_detach(&buf
, NULL
);
670 int n
= packet_read(rpc
->out
, NULL
, NULL
, rpc
->buf
, rpc
->alloc
, 0);
675 err
|= post_rpc(rpc
);
681 strbuf_read(&rpc
->result
, client
.out
, 0);
685 if (xread(client
.out
, buf
, sizeof(buf
)) <= 0)
692 err
|= finish_command(&client
);
693 free(rpc
->service_url
);
694 free(rpc
->hdr_content_type
);
695 free(rpc
->hdr_accept
);
697 strbuf_release(&buf
);
701 static int fetch_dumb(int nr_heads
, struct ref
**to_fetch
)
703 struct walker
*walker
;
704 char **targets
= xmalloc(nr_heads
* sizeof(char*));
707 if (options
.depth
|| options
.deepen_since
)
708 die("dumb http transport does not support shallow capabilities");
709 for (i
= 0; i
< nr_heads
; i
++)
710 targets
[i
] = xstrdup(oid_to_hex(&to_fetch
[i
]->old_oid
));
712 walker
= get_http_walker(url
.buf
);
714 walker
->get_tree
= 1;
715 walker
->get_history
= 1;
716 walker
->get_verbosely
= options
.verbosity
>= 3;
717 walker
->get_recover
= 0;
718 ret
= walker_fetch(walker
, nr_heads
, targets
, NULL
, NULL
);
721 for (i
= 0; i
< nr_heads
; i
++)
725 return ret
? error("fetch failed.") : 0;
728 static int fetch_git(struct discovery
*heads
,
729 int nr_heads
, struct ref
**to_fetch
)
731 struct rpc_state rpc
;
732 struct strbuf preamble
= STRBUF_INIT
;
734 struct argv_array args
= ARGV_ARRAY_INIT
;
736 argv_array_pushl(&args
, "fetch-pack", "--stateless-rpc",
737 "--stdin", "--lock-pack", NULL
);
738 if (options
.followtags
)
739 argv_array_push(&args
, "--include-tag");
741 argv_array_push(&args
, "--thin");
742 if (options
.verbosity
>= 3)
743 argv_array_pushl(&args
, "-v", "-v", NULL
);
744 if (options
.check_self_contained_and_connected
)
745 argv_array_push(&args
, "--check-self-contained-and-connected");
747 argv_array_push(&args
, "--cloning");
748 if (options
.update_shallow
)
749 argv_array_push(&args
, "--update-shallow");
750 if (!options
.progress
)
751 argv_array_push(&args
, "--no-progress");
753 argv_array_pushf(&args
, "--depth=%lu", options
.depth
);
754 if (options
.deepen_since
)
755 argv_array_pushf(&args
, "--shallow-since=%s", options
.deepen_since
);
756 argv_array_push(&args
, url
.buf
);
758 for (i
= 0; i
< nr_heads
; i
++) {
759 struct ref
*ref
= to_fetch
[i
];
761 die("cannot fetch by sha1 over smart http");
762 packet_buf_write(&preamble
, "%s %s\n",
763 oid_to_hex(&ref
->old_oid
), ref
->name
);
765 packet_buf_flush(&preamble
);
767 memset(&rpc
, 0, sizeof(rpc
));
768 rpc
.service_name
= "git-upload-pack",
769 rpc
.argv
= args
.argv
;
770 rpc
.stdin_preamble
= &preamble
;
771 rpc
.gzip_request
= 1;
773 err
= rpc_service(&rpc
, heads
);
775 write_or_die(1, rpc
.result
.buf
, rpc
.result
.len
);
776 strbuf_release(&rpc
.result
);
777 strbuf_release(&preamble
);
778 argv_array_clear(&args
);
782 static int fetch(int nr_heads
, struct ref
**to_fetch
)
784 struct discovery
*d
= discover_refs("git-upload-pack", 0);
786 return fetch_git(d
, nr_heads
, to_fetch
);
788 return fetch_dumb(nr_heads
, to_fetch
);
791 static void parse_fetch(struct strbuf
*buf
)
793 struct ref
**to_fetch
= NULL
;
794 struct ref
*list_head
= NULL
;
795 struct ref
**list
= &list_head
;
796 int alloc_heads
= 0, nr_heads
= 0;
800 if (skip_prefix(buf
->buf
, "fetch ", &p
)) {
803 struct object_id old_oid
;
805 if (get_oid_hex(p
, &old_oid
))
806 die("protocol error: expected sha/ref, got %s'", p
);
807 if (p
[GIT_SHA1_HEXSZ
] == ' ')
808 name
= p
+ GIT_SHA1_HEXSZ
+ 1;
809 else if (!p
[GIT_SHA1_HEXSZ
])
812 die("protocol error: expected sha/ref, got %s'", p
);
814 ref
= alloc_ref(name
);
815 oidcpy(&ref
->old_oid
, &old_oid
);
820 ALLOC_GROW(to_fetch
, nr_heads
+ 1, alloc_heads
);
821 to_fetch
[nr_heads
++] = ref
;
824 die("http transport does not support %s", buf
->buf
);
827 if (strbuf_getline_lf(buf
, stdin
) == EOF
)
833 if (fetch(nr_heads
, to_fetch
))
834 exit(128); /* error already reported */
835 free_refs(list_head
);
843 static int push_dav(int nr_spec
, char **specs
)
845 const char **argv
= xmalloc((10 + nr_spec
) * sizeof(char*));
848 argv
[argc
++] = "http-push";
849 argv
[argc
++] = "--helper-status";
851 argv
[argc
++] = "--dry-run";
852 if (options
.verbosity
> 1)
853 argv
[argc
++] = "--verbose";
854 argv
[argc
++] = url
.buf
;
855 for (i
= 0; i
< nr_spec
; i
++)
856 argv
[argc
++] = specs
[i
];
859 if (run_command_v_opt(argv
, RUN_GIT_CMD
))
860 die("git-%s failed", argv
[0]);
865 static int push_git(struct discovery
*heads
, int nr_spec
, char **specs
)
867 struct rpc_state rpc
;
869 struct argv_array args
;
870 struct string_list_item
*cas_option
;
871 struct strbuf preamble
= STRBUF_INIT
;
873 argv_array_init(&args
);
874 argv_array_pushl(&args
, "send-pack", "--stateless-rpc", "--helper-status",
878 argv_array_push(&args
, "--thin");
880 argv_array_push(&args
, "--dry-run");
881 if (options
.push_cert
== SEND_PACK_PUSH_CERT_ALWAYS
)
882 argv_array_push(&args
, "--signed=yes");
883 else if (options
.push_cert
== SEND_PACK_PUSH_CERT_IF_ASKED
)
884 argv_array_push(&args
, "--signed=if-asked");
885 if (options
.verbosity
== 0)
886 argv_array_push(&args
, "--quiet");
887 else if (options
.verbosity
> 1)
888 argv_array_push(&args
, "--verbose");
889 argv_array_push(&args
, options
.progress
? "--progress" : "--no-progress");
890 for_each_string_list_item(cas_option
, &cas_options
)
891 argv_array_push(&args
, cas_option
->string
);
892 argv_array_push(&args
, url
.buf
);
894 argv_array_push(&args
, "--stdin");
895 for (i
= 0; i
< nr_spec
; i
++)
896 packet_buf_write(&preamble
, "%s\n", specs
[i
]);
897 packet_buf_flush(&preamble
);
899 memset(&rpc
, 0, sizeof(rpc
));
900 rpc
.service_name
= "git-receive-pack",
901 rpc
.argv
= args
.argv
;
902 rpc
.stdin_preamble
= &preamble
;
904 err
= rpc_service(&rpc
, heads
);
906 write_or_die(1, rpc
.result
.buf
, rpc
.result
.len
);
907 strbuf_release(&rpc
.result
);
908 strbuf_release(&preamble
);
909 argv_array_clear(&args
);
913 static int push(int nr_spec
, char **specs
)
915 struct discovery
*heads
= discover_refs("git-receive-pack", 1);
918 if (heads
->proto_git
)
919 ret
= push_git(heads
, nr_spec
, specs
);
921 ret
= push_dav(nr_spec
, specs
);
922 free_discovery(heads
);
926 static void parse_push(struct strbuf
*buf
)
929 int alloc_spec
= 0, nr_spec
= 0, i
, ret
;
932 if (starts_with(buf
->buf
, "push ")) {
933 ALLOC_GROW(specs
, nr_spec
+ 1, alloc_spec
);
934 specs
[nr_spec
++] = xstrdup(buf
->buf
+ 5);
937 die("http transport does not support %s", buf
->buf
);
940 if (strbuf_getline_lf(buf
, stdin
) == EOF
)
946 ret
= push(nr_spec
, specs
);
951 exit(128); /* error already reported */
954 for (i
= 0; i
< nr_spec
; i
++)
959 int main(int argc
, const char **argv
)
961 struct strbuf buf
= STRBUF_INIT
;
966 git_extract_argv0_path(argv
[0]);
967 setup_git_directory_gently(&nongit
);
969 error("remote-curl: usage: git remote-curl <remote> [<url>]");
973 options
.verbosity
= 1;
974 options
.progress
= !!isatty(2);
977 remote
= remote_get(argv
[1]);
980 end_url_with_slash(&url
, argv
[2]);
982 end_url_with_slash(&url
, remote
->url
[0]);
985 http_init(remote
, url
.buf
, 0);
990 if (strbuf_getline_lf(&buf
, stdin
) == EOF
) {
992 error("remote-curl: error reading command stream from git");
997 if (starts_with(buf
.buf
, "fetch ")) {
999 die("remote-curl: fetch attempted without a local repo");
1002 } else if (!strcmp(buf
.buf
, "list") || starts_with(buf
.buf
, "list ")) {
1003 int for_push
= !!strstr(buf
.buf
+ 4, "for-push");
1004 output_refs(get_refs(for_push
));
1006 } else if (starts_with(buf
.buf
, "push ")) {
1009 } else if (skip_prefix(buf
.buf
, "option ", &arg
)) {
1010 char *value
= strchr(arg
, ' ');
1018 result
= set_option(arg
, value
);
1021 else if (result
< 0)
1022 printf("error invalid value\n");
1024 printf("unsupported\n");
1027 } else if (!strcmp(buf
.buf
, "capabilities")) {
1031 printf("check-connectivity\n");
1035 error("remote-curl: unknown command '%s' from git", buf
.buf
);