1 #define USE_THE_REPOSITORY_VARIABLE
3 #include "git-compat-util.h"
4 #include "git-curl-compat.h"
6 #include "environment.h"
14 #include "run-command.h"
16 #include "string-list.h"
18 #include "credential.h"
19 #include "oid-array.h"
20 #include "send-pack.h"
25 #include "transport.h"
27 #include "write-or-die.h"
29 static struct remote
*remote
;
30 /* always ends with a trailing slash */
31 static struct strbuf url
= STRBUF_INIT
;
37 struct string_list deepen_not
;
38 struct string_list push_options
;
40 unsigned progress
: 1,
41 check_self_contained_and_connected
: 1,
47 /* One of the SEND_PACK_PUSH_CERT_* constants. */
51 /* see documentation of corresponding flag in fetch-pack.h */
57 force_if_includes
: 1;
58 const struct git_hash_algo
*hash_algo
;
60 static struct options options
;
61 static struct string_list cas_options
= STRING_LIST_INIT_DUP
;
63 static int set_option(const char *name
, size_t namelen
, const char *value
)
65 if (!strncmp(name
, "verbosity", namelen
)) {
67 int v
= strtol(value
, &end
, 10);
68 if (value
== end
|| *end
)
70 options
.verbosity
= v
;
73 else if (!strncmp(name
, "progress", namelen
)) {
74 if (!strcmp(value
, "true"))
76 else if (!strcmp(value
, "false"))
82 else if (!strncmp(name
, "depth", namelen
)) {
84 unsigned long v
= strtoul(value
, &end
, 10);
85 if (value
== end
|| *end
)
90 else if (!strncmp(name
, "deepen-since", namelen
)) {
91 options
.deepen_since
= xstrdup(value
);
94 else if (!strncmp(name
, "deepen-not", namelen
)) {
95 string_list_append(&options
.deepen_not
, value
);
98 else if (!strncmp(name
, "deepen-relative", namelen
)) {
99 if (!strcmp(value
, "true"))
100 options
.deepen_relative
= 1;
101 else if (!strcmp(value
, "false"))
102 options
.deepen_relative
= 0;
107 else if (!strncmp(name
, "followtags", namelen
)) {
108 if (!strcmp(value
, "true"))
109 options
.followtags
= 1;
110 else if (!strcmp(value
, "false"))
111 options
.followtags
= 0;
116 else if (!strncmp(name
, "dry-run", namelen
)) {
117 if (!strcmp(value
, "true"))
119 else if (!strcmp(value
, "false"))
125 else if (!strncmp(name
, "check-connectivity", namelen
)) {
126 if (!strcmp(value
, "true"))
127 options
.check_self_contained_and_connected
= 1;
128 else if (!strcmp(value
, "false"))
129 options
.check_self_contained_and_connected
= 0;
134 else if (!strncmp(name
, "cas", namelen
)) {
135 struct strbuf val
= STRBUF_INIT
;
136 strbuf_addstr(&val
, "--force-with-lease=");
138 strbuf_addstr(&val
, value
);
139 else if (unquote_c_style(&val
, value
, NULL
))
141 string_list_append(&cas_options
, val
.buf
);
142 strbuf_release(&val
);
144 } else if (!strncmp(name
, TRANS_OPT_FORCE_IF_INCLUDES
, namelen
)) {
145 if (!strcmp(value
, "true"))
146 options
.force_if_includes
= 1;
147 else if (!strcmp(value
, "false"))
148 options
.force_if_includes
= 0;
152 } else if (!strncmp(name
, "cloning", namelen
)) {
153 if (!strcmp(value
, "true"))
155 else if (!strcmp(value
, "false"))
160 } else if (!strncmp(name
, "update-shallow", namelen
)) {
161 if (!strcmp(value
, "true"))
162 options
.update_shallow
= 1;
163 else if (!strcmp(value
, "false"))
164 options
.update_shallow
= 0;
168 } else if (!strncmp(name
, "pushcert", namelen
)) {
169 if (!strcmp(value
, "true"))
170 options
.push_cert
= SEND_PACK_PUSH_CERT_ALWAYS
;
171 else if (!strcmp(value
, "false"))
172 options
.push_cert
= SEND_PACK_PUSH_CERT_NEVER
;
173 else if (!strcmp(value
, "if-asked"))
174 options
.push_cert
= SEND_PACK_PUSH_CERT_IF_ASKED
;
178 } else if (!strncmp(name
, "atomic", namelen
)) {
179 if (!strcmp(value
, "true"))
181 else if (!strcmp(value
, "false"))
186 } else if (!strncmp(name
, "push-option", namelen
)) {
188 string_list_append(&options
.push_options
, value
);
190 struct strbuf unquoted
= STRBUF_INIT
;
191 if (unquote_c_style(&unquoted
, value
, NULL
) < 0)
192 die(_("invalid quoting in push-option value: '%s'"), value
);
193 string_list_append_nodup(&options
.push_options
,
194 strbuf_detach(&unquoted
, NULL
));
197 } else if (!strncmp(name
, "family", namelen
)) {
198 if (!strcmp(value
, "ipv4"))
199 git_curl_ipresolve
= CURL_IPRESOLVE_V4
;
200 else if (!strcmp(value
, "ipv6"))
201 git_curl_ipresolve
= CURL_IPRESOLVE_V6
;
202 else if (!strcmp(value
, "all"))
203 git_curl_ipresolve
= CURL_IPRESOLVE_WHATEVER
;
207 } else if (!strncmp(name
, "from-promisor", namelen
)) {
208 options
.from_promisor
= 1;
210 } else if (!strncmp(name
, "refetch", namelen
)) {
213 } else if (!strncmp(name
, "filter", namelen
)) {
214 options
.filter
= xstrdup(value
);
216 } else if (!strncmp(name
, "object-format", namelen
)) {
217 options
.object_format
= 1;
218 if (strcmp(value
, "true"))
219 die(_("unknown value for object-format: %s"), value
);
222 return 1 /* unsupported */;
232 struct oid_array shallow
;
233 enum protocol_version version
;
234 unsigned proto_git
: 1;
236 static struct discovery
*last_discovery
;
238 static struct ref
*parse_git_refs(struct discovery
*heads
, int for_push
)
240 struct ref
*list
= NULL
;
241 struct packet_reader reader
;
243 packet_reader_init(&reader
, -1, heads
->buf
, heads
->len
,
244 PACKET_READ_CHOMP_NEWLINE
|
245 PACKET_READ_GENTLE_ON_EOF
|
246 PACKET_READ_DIE_ON_ERR_PACKET
);
248 heads
->version
= discover_version(&reader
);
249 switch (heads
->version
) {
252 * Do nothing. This isn't a list of refs but rather a
253 * capability advertisement. Client would have run
254 * 'stateless-connect' so we'll dump this capability listing
255 * and let them request the refs themselves.
260 get_remote_heads(&reader
, &list
, for_push
? REF_NORMAL
: 0,
261 NULL
, &heads
->shallow
);
262 options
.hash_algo
= reader
.hash_algo
;
264 case protocol_unknown_version
:
265 BUG("unknown protocol version");
272 * Try to detect the hash algorithm used by the remote repository when using
273 * the dumb HTTP transport. As dumb transports cannot tell us the object hash
274 * directly have to derive it from the advertised ref lengths.
276 static const struct git_hash_algo
*detect_hash_algo(struct discovery
*heads
)
278 const char *p
= memchr(heads
->buf
, '\t', heads
->len
);
282 * In case the remote has no refs we have no way to reliably determine
283 * the object hash used by that repository. In that case we simply fall
284 * back to SHA1, which may or may not be correct.
287 return &hash_algos
[GIT_HASH_SHA1
];
289 algo
= hash_algo_by_length((p
- heads
->buf
) / 2);
290 if (algo
== GIT_HASH_UNKNOWN
)
292 return &hash_algos
[algo
];
295 static struct ref
*parse_info_refs(struct discovery
*heads
)
297 char *data
, *start
, *mid
;
301 struct ref
*refs
= NULL
;
302 struct ref
*ref
= NULL
;
303 struct ref
*last_ref
= NULL
;
305 options
.hash_algo
= detect_hash_algo(heads
);
306 if (!options
.hash_algo
)
307 die("%sinfo/refs not valid: could not determine hash algorithm; "
308 "is this a git repository?",
309 transport_anonymize_url(url
.buf
));
312 * Set the repository's hash algo to whatever we have just detected.
313 * This ensures that we can correctly parse the remote references.
315 repo_set_hash_algo(the_repository
, hash_algo_by_ptr(options
.hash_algo
));
320 while (i
< heads
->len
) {
326 if (data
[i
] == '\n') {
327 if (mid
- start
!= options
.hash_algo
->hexsz
)
328 die(_("%sinfo/refs not valid: is this a git repository?"),
329 transport_anonymize_url(url
.buf
));
332 ref
= alloc_ref(ref_name
);
333 get_oid_hex_algop(start
, &ref
->old_oid
, options
.hash_algo
);
337 last_ref
->next
= ref
;
344 ref
= alloc_ref("HEAD");
345 if (!http_fetch_ref(url
.buf
, ref
) &&
346 !resolve_remote_symref(ref
, refs
)) {
356 static void free_discovery(struct discovery
*d
)
359 if (d
== last_discovery
)
360 last_discovery
= NULL
;
361 free(d
->shallow
.oid
);
369 static int show_http_message(struct strbuf
*type
, struct strbuf
*charset
,
375 * We only show text/plain parts, as other types are likely
376 * to be ugly to look at on the user's terminal.
378 if (strcmp(type
->buf
, "text/plain"))
381 strbuf_reencode(msg
, charset
->buf
, get_log_output_encoding());
389 eol
= strchrnul(p
, '\n');
390 fprintf(stderr
, "remote: %.*s\n", (int)(eol
- p
), p
);
396 static int get_protocol_http_header(enum protocol_version version
,
397 struct strbuf
*header
)
400 strbuf_addf(header
, GIT_PROTOCOL_HEADER
": version=%d",
409 static void check_smart_http(struct discovery
*d
, const char *service
,
413 struct packet_reader reader
;
416 * If we don't see x-$service-advertisement, then it's not smart-http.
417 * But once we do, we commit to it and assume any other protocol
418 * violations are hard errors.
420 if (!skip_prefix(type
->buf
, "application/x-", &p
) ||
421 !skip_prefix(p
, service
, &p
) ||
422 strcmp(p
, "-advertisement"))
425 packet_reader_init(&reader
, -1, d
->buf
, d
->len
,
426 PACKET_READ_CHOMP_NEWLINE
|
427 PACKET_READ_DIE_ON_ERR_PACKET
);
428 if (packet_reader_read(&reader
) != PACKET_READ_NORMAL
)
429 die(_("invalid server response; expected service, got flush packet"));
431 if (skip_prefix(reader
.line
, "# service=", &p
) && !strcmp(p
, service
)) {
433 * The header can include additional metadata lines, up
434 * until a packet flush marker. Ignore these now, but
435 * in the future we might start to scan them.
438 packet_reader_read(&reader
);
439 if (reader
.pktlen
<= 0) {
445 * v0 smart http; callers expect us to soak up the
446 * service and header packets
448 d
->buf
= reader
.src_buffer
;
449 d
->len
= reader
.src_len
;
452 } else if (!strcmp(reader
.line
, "version 2")) {
454 * v2 smart http; do not consume version packet, which will
455 * be handled elsewhere.
460 die(_("invalid server response; got '%s'"), reader
.line
);
464 static struct discovery
*discover_refs(const char *service
, int for_push
)
466 struct strbuf type
= STRBUF_INIT
;
467 struct strbuf charset
= STRBUF_INIT
;
468 struct strbuf buffer
= STRBUF_INIT
;
469 struct strbuf refs_url
= STRBUF_INIT
;
470 struct strbuf effective_url
= STRBUF_INIT
;
471 struct strbuf protocol_header
= STRBUF_INIT
;
472 struct string_list extra_headers
= STRING_LIST_INIT_DUP
;
473 struct discovery
*last
= last_discovery
;
474 int http_ret
, maybe_smart
= 0;
475 struct http_get_options http_options
;
476 enum protocol_version version
= get_protocol_version_config();
478 if (last
&& !strcmp(service
, last
->service
))
480 free_discovery(last
);
482 strbuf_addf(&refs_url
, "%sinfo/refs", url
.buf
);
483 if ((starts_with(url
.buf
, "http://") || starts_with(url
.buf
, "https://")) &&
484 git_env_bool("GIT_SMART_HTTP", 1)) {
486 if (!strchr(url
.buf
, '?'))
487 strbuf_addch(&refs_url
, '?');
489 strbuf_addch(&refs_url
, '&');
490 strbuf_addf(&refs_url
, "service=%s", service
);
494 * NEEDSWORK: If we are trying to use protocol v2 and we are planning
495 * to perform any operation that doesn't involve upload-pack (i.e., a
496 * fetch, ls-remote, etc), then fallback to v0 since we don't know how
497 * to do anything else (like push or remote archive) via v2.
499 if (version
== protocol_v2
&& strcmp("git-upload-pack", service
))
500 version
= protocol_v0
;
502 /* Add the extra Git-Protocol header */
503 if (get_protocol_http_header(version
, &protocol_header
))
504 string_list_append(&extra_headers
, protocol_header
.buf
);
506 memset(&http_options
, 0, sizeof(http_options
));
507 http_options
.content_type
= &type
;
508 http_options
.charset
= &charset
;
509 http_options
.effective_url
= &effective_url
;
510 http_options
.base_url
= &url
;
511 http_options
.extra_headers
= &extra_headers
;
512 http_options
.initial_request
= 1;
513 http_options
.no_cache
= 1;
515 http_ret
= http_get_strbuf(refs_url
.buf
, &buffer
, &http_options
);
519 case HTTP_MISSING_TARGET
:
520 show_http_message(&type
, &charset
, &buffer
);
521 die(_("repository '%s' not found"),
522 transport_anonymize_url(url
.buf
));
524 show_http_message(&type
, &charset
, &buffer
);
525 die(_("Authentication failed for '%s'"),
526 transport_anonymize_url(url
.buf
));
527 case HTTP_NOMATCHPUBLICKEY
:
528 show_http_message(&type
, &charset
, &buffer
);
529 die(_("unable to access '%s' with http.pinnedPubkey configuration: %s"),
530 transport_anonymize_url(url
.buf
), curl_errorstr
);
532 show_http_message(&type
, &charset
, &buffer
);
533 die(_("unable to access '%s': %s"),
534 transport_anonymize_url(url
.buf
), curl_errorstr
);
537 if (options
.verbosity
&& !starts_with(refs_url
.buf
, url
.buf
)) {
538 char *u
= transport_anonymize_url(url
.buf
);
539 warning(_("redirecting to %s"), u
);
543 last
= xcalloc(1, sizeof(*last_discovery
));
544 last
->service
= xstrdup(service
);
545 last
->buf_alloc
= strbuf_detach(&buffer
, &last
->len
);
546 last
->buf
= last
->buf_alloc
;
549 check_smart_http(last
, service
, &type
);
552 last
->refs
= parse_git_refs(last
, for_push
);
554 last
->refs
= parse_info_refs(last
);
556 strbuf_release(&refs_url
);
557 strbuf_release(&type
);
558 strbuf_release(&charset
);
559 strbuf_release(&effective_url
);
560 strbuf_release(&buffer
);
561 strbuf_release(&protocol_header
);
562 string_list_clear(&extra_headers
, 0);
563 last_discovery
= last
;
567 static struct ref
*get_refs(int for_push
)
569 struct discovery
*heads
;
572 heads
= discover_refs("git-receive-pack", for_push
);
574 heads
= discover_refs("git-upload-pack", for_push
);
579 static void output_refs(struct ref
*refs
)
582 if (options
.object_format
&& options
.hash_algo
) {
583 printf(":object-format %s\n", options
.hash_algo
->name
);
584 repo_set_hash_algo(the_repository
,
585 hash_algo_by_ptr(options
.hash_algo
));
587 for (posn
= refs
; posn
; posn
= posn
->next
) {
589 printf("@%s %s\n", posn
->symref
, posn
->name
);
591 printf("%s %s\n", hash_to_hex_algop(posn
->old_oid
.hash
,
600 const char *service_name
;
602 char *hdr_content_type
;
604 char *hdr_accept_language
;
605 char *protocol_header
;
613 unsigned gzip_request
: 1;
614 unsigned initial_buffer
: 1;
617 * Whenever a pkt-line is read into buf, append the 4 characters
618 * denoting its length before appending the payload.
620 unsigned write_line_lengths
: 1;
623 * Used by rpc_out; initialize to 0. This is true if a flush has been
624 * read, but the corresponding line length (if write_line_lengths is
625 * true) and EOF have not been sent to libcurl. Since each flush marks
626 * the end of a request, each flush must be completely sent before any
627 * further reading occurs.
629 unsigned flush_read_but_not_sent
: 1;
632 #define RPC_STATE_INIT { 0 }
635 * Appends the result of reading from rpc->out to the string represented by
636 * rpc->buf and rpc->len if there is enough space. Returns 1 if there was
637 * enough space, 0 otherwise.
639 * If rpc->write_line_lengths is true, appends the line length as a 4-byte
640 * hexadecimal string before appending the result described above.
642 * Writes the total number of bytes appended into appended.
644 static int rpc_read_from_out(struct rpc_state
*rpc
, int options
,
646 enum packet_read_status
*status
) {
651 if (rpc
->write_line_lengths
) {
652 left
= rpc
->alloc
- rpc
->len
- 4;
653 buf
= rpc
->buf
+ rpc
->len
+ 4;
655 left
= rpc
->alloc
- rpc
->len
;
656 buf
= rpc
->buf
+ rpc
->len
;
659 if (left
< LARGE_PACKET_MAX
)
662 *status
= packet_read_with_status(rpc
->out
, NULL
, NULL
, buf
,
663 left
, &pktlen_raw
, options
);
664 if (*status
!= PACKET_READ_EOF
) {
665 *appended
= pktlen_raw
+ (rpc
->write_line_lengths
? 4 : 0);
666 rpc
->len
+= *appended
;
669 if (rpc
->write_line_lengths
) {
671 case PACKET_READ_EOF
:
672 if (!(options
& PACKET_READ_GENTLE_ON_EOF
))
673 die(_("shouldn't have EOF when not gentle on EOF"));
675 case PACKET_READ_NORMAL
:
676 set_packet_header(buf
- 4, *appended
);
678 case PACKET_READ_DELIM
:
679 memcpy(buf
- 4, "0001", 4);
681 case PACKET_READ_FLUSH
:
682 memcpy(buf
- 4, "0000", 4);
684 case PACKET_READ_RESPONSE_END
:
685 die(_("remote server sent unexpected response end packet"));
692 static size_t rpc_out(void *ptr
, size_t eltsize
,
693 size_t nmemb
, void *buffer_
)
695 size_t max
= eltsize
* nmemb
;
696 struct rpc_state
*rpc
= buffer_
;
697 size_t avail
= rpc
->len
- rpc
->pos
;
698 enum packet_read_status status
;
701 rpc
->initial_buffer
= 0;
704 if (!rpc
->flush_read_but_not_sent
) {
705 if (!rpc_read_from_out(rpc
, 0, &avail
, &status
))
706 BUG("The entire rpc->buf should be larger than LARGE_PACKET_MAX");
707 if (status
== PACKET_READ_FLUSH
)
708 rpc
->flush_read_but_not_sent
= 1;
711 * If flush_read_but_not_sent is true, we have already read one
712 * full request but have not fully sent it + EOF, which is why
713 * we need to refrain from reading.
716 if (rpc
->flush_read_but_not_sent
) {
719 * The line length either does not need to be sent at
720 * all or has already been completely sent. Now we can
721 * return 0, indicating EOF, meaning that the flush has
724 rpc
->flush_read_but_not_sent
= 0;
728 * If avail is non-zero, the line length for the flush still
729 * hasn't been fully sent. Proceed with sending the line
736 memcpy(ptr
, rpc
->buf
+ rpc
->pos
, avail
);
741 static int rpc_seek(void *clientp
, curl_off_t offset
, int origin
)
743 struct rpc_state
*rpc
= clientp
;
745 if (origin
!= SEEK_SET
)
746 BUG("rpc_seek only handles SEEK_SET, not %d", origin
);
748 if (rpc
->initial_buffer
) {
749 if (offset
< 0 || offset
> rpc
->len
) {
750 error("curl seek would be outside of rpc buffer");
751 return CURL_SEEKFUNC_FAIL
;
754 return CURL_SEEKFUNC_OK
;
756 error(_("unable to rewind rpc post data - try increasing http.postBuffer"));
757 return CURL_SEEKFUNC_FAIL
;
760 struct check_pktline_state
{
766 static void check_pktline(struct check_pktline_state
*state
, const char *ptr
, size_t size
)
769 if (!state
->remaining
) {
770 int digits_remaining
= 4 - state
->len_filled
;
771 if (digits_remaining
> size
)
772 digits_remaining
= size
;
773 memcpy(&state
->len_buf
[state
->len_filled
], ptr
, digits_remaining
);
774 state
->len_filled
+= digits_remaining
;
775 ptr
+= digits_remaining
;
776 size
-= digits_remaining
;
778 if (state
->len_filled
== 4) {
779 state
->remaining
= packet_length(state
->len_buf
,
780 sizeof(state
->len_buf
));
781 if (state
->remaining
< 0) {
782 die(_("remote-curl: bad line length character: %.4s"), state
->len_buf
);
783 } else if (state
->remaining
== 2) {
784 die(_("remote-curl: unexpected response end packet"));
785 } else if (state
->remaining
< 4) {
786 state
->remaining
= 0;
788 state
->remaining
-= 4;
790 state
->len_filled
= 0;
794 if (state
->remaining
) {
795 int remaining
= state
->remaining
;
796 if (remaining
> size
)
800 state
->remaining
-= remaining
;
806 struct rpc_state
*rpc
;
807 struct active_request_slot
*slot
;
809 struct check_pktline_state pktline_state
;
813 * A callback for CURLOPT_WRITEFUNCTION. The return value is the bytes consumed
816 static size_t rpc_in(char *ptr
, size_t eltsize
,
817 size_t nmemb
, void *buffer_
)
819 size_t size
= eltsize
* nmemb
;
820 struct rpc_in_data
*data
= buffer_
;
823 if (curl_easy_getinfo(data
->slot
->curl
, CURLINFO_RESPONSE_CODE
,
824 &response_code
) != CURLE_OK
)
826 if (response_code
>= 300)
829 data
->rpc
->any_written
= 1;
830 if (data
->check_pktline
)
831 check_pktline(&data
->pktline_state
, ptr
, size
);
832 write_or_die(data
->rpc
->in
, ptr
, size
);
836 static int run_slot(struct active_request_slot
*slot
,
837 struct slot_results
*results
)
840 struct slot_results results_buf
;
843 results
= &results_buf
;
845 err
= run_one_slot(slot
, results
);
847 if (err
!= HTTP_OK
&& err
!= HTTP_REAUTH
) {
848 struct strbuf msg
= STRBUF_INIT
;
849 if (results
->http_code
&& results
->http_code
!= 200)
850 strbuf_addf(&msg
, "HTTP %ld", results
->http_code
);
851 if (results
->curl_result
!= CURLE_OK
) {
853 strbuf_addch(&msg
, ' ');
854 strbuf_addf(&msg
, "curl %d", results
->curl_result
);
855 if (curl_errorstr
[0]) {
856 strbuf_addch(&msg
, ' ');
857 strbuf_addstr(&msg
, curl_errorstr
);
860 error(_("RPC failed; %s"), msg
.buf
);
861 strbuf_release(&msg
);
867 static int probe_rpc(struct rpc_state
*rpc
, struct slot_results
*results
)
869 struct active_request_slot
*slot
;
870 struct curl_slist
*headers
= http_copy_default_headers();
871 struct strbuf buf
= STRBUF_INIT
;
874 slot
= get_active_slot();
876 headers
= curl_slist_append(headers
, rpc
->hdr_content_type
);
877 headers
= curl_slist_append(headers
, rpc
->hdr_accept
);
879 curl_easy_setopt(slot
->curl
, CURLOPT_NOBODY
, 0);
880 curl_easy_setopt(slot
->curl
, CURLOPT_POST
, 1);
881 curl_easy_setopt(slot
->curl
, CURLOPT_URL
, rpc
->service_url
);
882 curl_easy_setopt(slot
->curl
, CURLOPT_ENCODING
, NULL
);
883 curl_easy_setopt(slot
->curl
, CURLOPT_POSTFIELDS
, "0000");
884 curl_easy_setopt(slot
->curl
, CURLOPT_POSTFIELDSIZE
, 4);
885 curl_easy_setopt(slot
->curl
, CURLOPT_HTTPHEADER
, headers
);
886 curl_easy_setopt(slot
->curl
, CURLOPT_WRITEFUNCTION
, fwrite_buffer
);
887 curl_easy_setopt(slot
->curl
, CURLOPT_WRITEDATA
, &buf
);
889 err
= run_slot(slot
, results
);
891 curl_slist_free_all(headers
);
892 strbuf_release(&buf
);
896 static curl_off_t
xcurl_off_t(size_t len
)
898 uintmax_t size
= len
;
899 if (size
> maximum_signed_value_of_type(curl_off_t
))
900 die(_("cannot handle pushes this big"));
901 return (curl_off_t
)size
;
905 * If flush_received is true, do not attempt to read any more; just use what's
908 static int post_rpc(struct rpc_state
*rpc
, int stateless_connect
, int flush_received
)
910 struct active_request_slot
*slot
;
911 struct curl_slist
*headers
= NULL
;
912 int use_gzip
= rpc
->gzip_request
;
913 char *gzip_body
= NULL
;
914 size_t gzip_size
= 0;
915 int err
, large_request
= 0;
916 int needs_100_continue
= 0;
917 struct rpc_in_data rpc_in_data
;
919 /* Try to load the entire request, if we can fit it into the
920 * allocated buffer space we can use HTTP/1.0 and avoid the
921 * chunked encoding mess.
923 if (!flush_received
) {
926 enum packet_read_status status
;
928 if (!rpc_read_from_out(rpc
, 0, &n
, &status
)) {
933 if (status
== PACKET_READ_FLUSH
)
939 struct slot_results results
;
942 err
= probe_rpc(rpc
, &results
);
943 if (err
== HTTP_REAUTH
)
944 credential_fill(&http_auth
, 0);
945 } while (err
== HTTP_REAUTH
);
949 if (results
.auth_avail
& CURLAUTH_GSSNEGOTIATE
|| http_auth
.authtype
)
950 needs_100_continue
= 1;
954 headers
= http_copy_default_headers();
955 headers
= curl_slist_append(headers
, rpc
->hdr_content_type
);
956 headers
= curl_slist_append(headers
, rpc
->hdr_accept
);
957 headers
= curl_slist_append(headers
, needs_100_continue
?
958 "Expect: 100-continue" : "Expect:");
960 headers
= http_append_auth_header(&http_auth
, headers
);
962 /* Add Accept-Language header */
963 if (rpc
->hdr_accept_language
)
964 headers
= curl_slist_append(headers
, rpc
->hdr_accept_language
);
966 /* Add the extra Git-Protocol header */
967 if (rpc
->protocol_header
)
968 headers
= curl_slist_append(headers
, rpc
->protocol_header
);
970 slot
= get_active_slot();
972 curl_easy_setopt(slot
->curl
, CURLOPT_NOBODY
, 0);
973 curl_easy_setopt(slot
->curl
, CURLOPT_POST
, 1);
974 curl_easy_setopt(slot
->curl
, CURLOPT_URL
, rpc
->service_url
);
975 curl_easy_setopt(slot
->curl
, CURLOPT_ENCODING
, "");
978 /* The request body is large and the size cannot be predicted.
979 * We must use chunked encoding to send it.
981 #ifdef GIT_CURL_NEED_TRANSFER_ENCODING_HEADER
982 headers
= curl_slist_append(headers
, "Transfer-Encoding: chunked");
984 rpc
->initial_buffer
= 1;
985 curl_easy_setopt(slot
->curl
, CURLOPT_READFUNCTION
, rpc_out
);
986 curl_easy_setopt(slot
->curl
, CURLOPT_INFILE
, rpc
);
987 curl_easy_setopt(slot
->curl
, CURLOPT_SEEKFUNCTION
, rpc_seek
);
988 curl_easy_setopt(slot
->curl
, CURLOPT_SEEKDATA
, rpc
);
989 if (options
.verbosity
> 1) {
990 fprintf(stderr
, "POST %s (chunked)\n", rpc
->service_name
);
994 } else if (gzip_body
) {
996 * If we are looping to retry authentication, then the previous
997 * run will have set up the headers and gzip buffer already,
998 * and we just need to send it.
1000 curl_easy_setopt(slot
->curl
, CURLOPT_POSTFIELDS
, gzip_body
);
1001 curl_easy_setopt(slot
->curl
, CURLOPT_POSTFIELDSIZE_LARGE
, xcurl_off_t(gzip_size
));
1003 } else if (use_gzip
&& 1024 < rpc
->len
) {
1004 /* The client backend isn't giving us compressed data so
1005 * we can try to deflate it ourselves, this may save on
1006 * the transfer time.
1011 git_deflate_init_gzip(&stream
, Z_BEST_COMPRESSION
);
1012 gzip_size
= git_deflate_bound(&stream
, rpc
->len
);
1013 gzip_body
= xmalloc(gzip_size
);
1015 stream
.next_in
= (unsigned char *)rpc
->buf
;
1016 stream
.avail_in
= rpc
->len
;
1017 stream
.next_out
= (unsigned char *)gzip_body
;
1018 stream
.avail_out
= gzip_size
;
1020 ret
= git_deflate(&stream
, Z_FINISH
);
1021 if (ret
!= Z_STREAM_END
)
1022 die(_("cannot deflate request; zlib deflate error %d"), ret
);
1024 ret
= git_deflate_end_gently(&stream
);
1026 die(_("cannot deflate request; zlib end error %d"), ret
);
1028 gzip_size
= stream
.total_out
;
1030 headers
= curl_slist_append(headers
, "Content-Encoding: gzip");
1031 curl_easy_setopt(slot
->curl
, CURLOPT_POSTFIELDS
, gzip_body
);
1032 curl_easy_setopt(slot
->curl
, CURLOPT_POSTFIELDSIZE_LARGE
, xcurl_off_t(gzip_size
));
1034 if (options
.verbosity
> 1) {
1035 fprintf(stderr
, "POST %s (gzip %lu to %lu bytes)\n",
1037 (unsigned long)rpc
->len
, (unsigned long)gzip_size
);
1041 /* We know the complete request size in advance, use the
1042 * more normal Content-Length approach.
1044 curl_easy_setopt(slot
->curl
, CURLOPT_POSTFIELDS
, rpc
->buf
);
1045 curl_easy_setopt(slot
->curl
, CURLOPT_POSTFIELDSIZE_LARGE
, xcurl_off_t(rpc
->len
));
1046 if (options
.verbosity
> 1) {
1047 fprintf(stderr
, "POST %s (%lu bytes)\n",
1048 rpc
->service_name
, (unsigned long)rpc
->len
);
1053 curl_easy_setopt(slot
->curl
, CURLOPT_HTTPHEADER
, headers
);
1054 curl_easy_setopt(slot
->curl
, CURLOPT_WRITEFUNCTION
, rpc_in
);
1055 rpc_in_data
.rpc
= rpc
;
1056 rpc_in_data
.slot
= slot
;
1057 rpc_in_data
.check_pktline
= stateless_connect
;
1058 memset(&rpc_in_data
.pktline_state
, 0, sizeof(rpc_in_data
.pktline_state
));
1059 curl_easy_setopt(slot
->curl
, CURLOPT_WRITEDATA
, &rpc_in_data
);
1060 curl_easy_setopt(slot
->curl
, CURLOPT_FAILONERROR
, 0);
1063 rpc
->any_written
= 0;
1064 err
= run_slot(slot
, NULL
);
1065 if (err
== HTTP_REAUTH
&& !large_request
) {
1066 credential_fill(&http_auth
, 0);
1067 curl_slist_free_all(headers
);
1073 if (!rpc
->any_written
)
1076 if (rpc_in_data
.pktline_state
.len_filled
)
1077 err
= error(_("%d bytes of length header were received"), rpc_in_data
.pktline_state
.len_filled
);
1078 if (rpc_in_data
.pktline_state
.remaining
)
1079 err
= error(_("%d bytes of body are still expected"), rpc_in_data
.pktline_state
.remaining
);
1081 if (stateless_connect
)
1082 packet_response_end(rpc
->in
);
1084 curl_slist_free_all(headers
);
1089 static int rpc_service(struct rpc_state
*rpc
, struct discovery
*heads
,
1090 const char **client_argv
, const struct strbuf
*preamble
,
1091 struct strbuf
*rpc_result
)
1093 const char *svc
= rpc
->service_name
;
1094 struct strbuf buf
= STRBUF_INIT
;
1095 struct child_process client
= CHILD_PROCESS_INIT
;
1101 strvec_pushv(&client
.args
, client_argv
);
1102 if (start_command(&client
))
1104 write_or_die(client
.in
, preamble
->buf
, preamble
->len
);
1106 write_or_die(client
.in
, heads
->buf
, heads
->len
);
1108 rpc
->alloc
= http_post_buffer
;
1109 rpc
->buf
= xmalloc(rpc
->alloc
);
1110 rpc
->in
= client
.in
;
1111 rpc
->out
= client
.out
;
1113 strbuf_addf(&buf
, "%s%s", url
.buf
, svc
);
1114 rpc
->service_url
= strbuf_detach(&buf
, NULL
);
1116 rpc
->hdr_accept_language
= xstrdup_or_null(http_get_accept_language_header());
1118 strbuf_addf(&buf
, "Content-Type: application/x-%s-request", svc
);
1119 rpc
->hdr_content_type
= strbuf_detach(&buf
, NULL
);
1121 strbuf_addf(&buf
, "Accept: application/x-%s-result", svc
);
1122 rpc
->hdr_accept
= strbuf_detach(&buf
, NULL
);
1124 if (get_protocol_http_header(heads
->version
, &buf
))
1125 rpc
->protocol_header
= strbuf_detach(&buf
, NULL
);
1127 rpc
->protocol_header
= NULL
;
1130 int n
= packet_read(rpc
->out
, rpc
->buf
, rpc
->alloc
, 0);
1135 err
|= post_rpc(rpc
, 0, 0);
1141 strbuf_read(rpc_result
, client
.out
, 0);
1145 if (xread(client
.out
, buf
, sizeof(buf
)) <= 0)
1152 err
|= finish_command(&client
);
1153 free(rpc
->service_url
);
1154 free(rpc
->hdr_content_type
);
1155 free(rpc
->hdr_accept
);
1156 free(rpc
->hdr_accept_language
);
1157 free(rpc
->protocol_header
);
1159 strbuf_release(&buf
);
1163 static int fetch_dumb(int nr_heads
, struct ref
**to_fetch
)
1165 struct walker
*walker
;
1169 ALLOC_ARRAY(targets
, nr_heads
);
1170 if (options
.depth
|| options
.deepen_since
)
1171 die(_("dumb http transport does not support shallow capabilities"));
1172 for (i
= 0; i
< nr_heads
; i
++)
1173 targets
[i
] = xstrdup(oid_to_hex(&to_fetch
[i
]->old_oid
));
1175 walker
= get_http_walker(url
.buf
);
1176 walker
->get_verbosely
= options
.verbosity
>= 3;
1177 walker
->get_progress
= options
.progress
;
1178 walker
->get_recover
= 0;
1179 ret
= walker_fetch(walker
, nr_heads
, targets
, NULL
, NULL
);
1180 walker_free(walker
);
1182 for (i
= 0; i
< nr_heads
; i
++)
1186 return ret
? error(_("fetch failed.")) : 0;
1189 static int fetch_git(struct discovery
*heads
,
1190 int nr_heads
, struct ref
**to_fetch
)
1192 struct rpc_state rpc
= RPC_STATE_INIT
;
1193 struct strbuf preamble
= STRBUF_INIT
;
1195 struct strvec args
= STRVEC_INIT
;
1196 struct strbuf rpc_result
= STRBUF_INIT
;
1198 strvec_pushl(&args
, "fetch-pack", "--stateless-rpc",
1199 "--stdin", "--lock-pack", NULL
);
1200 if (options
.followtags
)
1201 strvec_push(&args
, "--include-tag");
1203 strvec_push(&args
, "--thin");
1204 if (options
.verbosity
>= 3)
1205 strvec_pushl(&args
, "-v", "-v", NULL
);
1206 if (options
.check_self_contained_and_connected
)
1207 strvec_push(&args
, "--check-self-contained-and-connected");
1208 if (options
.cloning
)
1209 strvec_push(&args
, "--cloning");
1210 if (options
.update_shallow
)
1211 strvec_push(&args
, "--update-shallow");
1212 if (!options
.progress
)
1213 strvec_push(&args
, "--no-progress");
1215 strvec_pushf(&args
, "--depth=%lu", options
.depth
);
1216 if (options
.deepen_since
)
1217 strvec_pushf(&args
, "--shallow-since=%s", options
.deepen_since
);
1218 for (i
= 0; i
< options
.deepen_not
.nr
; i
++)
1219 strvec_pushf(&args
, "--shallow-exclude=%s",
1220 options
.deepen_not
.items
[i
].string
);
1221 if (options
.deepen_relative
&& options
.depth
)
1222 strvec_push(&args
, "--deepen-relative");
1223 if (options
.from_promisor
)
1224 strvec_push(&args
, "--from-promisor");
1225 if (options
.refetch
)
1226 strvec_push(&args
, "--refetch");
1228 strvec_pushf(&args
, "--filter=%s", options
.filter
);
1229 strvec_push(&args
, url
.buf
);
1231 for (i
= 0; i
< nr_heads
; i
++) {
1232 struct ref
*ref
= to_fetch
[i
];
1234 die(_("cannot fetch by sha1 over smart http"));
1235 packet_buf_write(&preamble
, "%s %s\n",
1236 oid_to_hex(&ref
->old_oid
), ref
->name
);
1238 packet_buf_flush(&preamble
);
1240 memset(&rpc
, 0, sizeof(rpc
));
1241 rpc
.service_name
= "git-upload-pack",
1242 rpc
.gzip_request
= 1;
1244 err
= rpc_service(&rpc
, heads
, args
.v
, &preamble
, &rpc_result
);
1246 write_or_die(1, rpc_result
.buf
, rpc_result
.len
);
1247 strbuf_release(&rpc_result
);
1248 strbuf_release(&preamble
);
1249 strvec_clear(&args
);
1253 static int fetch(int nr_heads
, struct ref
**to_fetch
)
1255 struct discovery
*d
= discover_refs("git-upload-pack", 0);
1257 return fetch_git(d
, nr_heads
, to_fetch
);
1259 return fetch_dumb(nr_heads
, to_fetch
);
1262 static void parse_fetch(struct strbuf
*buf
)
1264 struct ref
**to_fetch
= NULL
;
1265 struct ref
*list_head
= NULL
;
1266 struct ref
**list
= &list_head
;
1267 int alloc_heads
= 0, nr_heads
= 0;
1271 if (skip_prefix(buf
->buf
, "fetch ", &p
)) {
1274 struct object_id old_oid
;
1277 if (parse_oid_hex(p
, &old_oid
, &q
))
1278 die(_("protocol error: expected sha/ref, got '%s'"), p
);
1284 die(_("protocol error: expected sha/ref, got '%s'"), p
);
1286 ref
= alloc_ref(name
);
1287 oidcpy(&ref
->old_oid
, &old_oid
);
1292 ALLOC_GROW(to_fetch
, nr_heads
+ 1, alloc_heads
);
1293 to_fetch
[nr_heads
++] = ref
;
1296 die(_("http transport does not support %s"), buf
->buf
);
1299 if (strbuf_getline_lf(buf
, stdin
) == EOF
)
1305 if (fetch(nr_heads
, to_fetch
))
1306 exit(128); /* error already reported */
1307 free_refs(list_head
);
1315 static void parse_get(const char *arg
)
1317 struct strbuf url
= STRBUF_INIT
;
1318 struct strbuf path
= STRBUF_INIT
;
1321 space
= strchr(arg
, ' ');
1324 die(_("protocol error: expected '<url> <path>', missing space"));
1326 strbuf_add(&url
, arg
, space
- arg
);
1327 strbuf_addstr(&path
, space
+ 1);
1329 if (http_get_file(url
.buf
, path
.buf
, NULL
))
1330 die(_("failed to download file at URL '%s'"), url
.buf
);
1332 strbuf_release(&url
);
1333 strbuf_release(&path
);
1338 static int push_dav(int nr_spec
, const char **specs
)
1340 struct child_process child
= CHILD_PROCESS_INIT
;
1344 strvec_push(&child
.args
, "http-push");
1345 strvec_push(&child
.args
, "--helper-status");
1346 if (options
.dry_run
)
1347 strvec_push(&child
.args
, "--dry-run");
1348 if (options
.verbosity
> 1)
1349 strvec_push(&child
.args
, "--verbose");
1350 strvec_push(&child
.args
, url
.buf
);
1351 for (i
= 0; i
< nr_spec
; i
++)
1352 strvec_push(&child
.args
, specs
[i
]);
1354 if (run_command(&child
))
1355 die(_("git-http-push failed"));
1359 static int push_git(struct discovery
*heads
, int nr_spec
, const char **specs
)
1361 struct rpc_state rpc
= RPC_STATE_INIT
;
1364 struct string_list_item
*cas_option
;
1365 struct strbuf preamble
= STRBUF_INIT
;
1366 struct strbuf rpc_result
= STRBUF_INIT
;
1369 strvec_pushl(&args
, "send-pack", "--stateless-rpc", "--helper-status",
1373 strvec_push(&args
, "--thin");
1374 if (options
.dry_run
)
1375 strvec_push(&args
, "--dry-run");
1376 if (options
.push_cert
== SEND_PACK_PUSH_CERT_ALWAYS
)
1377 strvec_push(&args
, "--signed=yes");
1378 else if (options
.push_cert
== SEND_PACK_PUSH_CERT_IF_ASKED
)
1379 strvec_push(&args
, "--signed=if-asked");
1381 strvec_push(&args
, "--atomic");
1382 if (options
.verbosity
== 0)
1383 strvec_push(&args
, "--quiet");
1384 else if (options
.verbosity
> 1)
1385 strvec_push(&args
, "--verbose");
1386 for (i
= 0; i
< options
.push_options
.nr
; i
++)
1387 strvec_pushf(&args
, "--push-option=%s",
1388 options
.push_options
.items
[i
].string
);
1389 strvec_push(&args
, options
.progress
? "--progress" : "--no-progress");
1390 for_each_string_list_item(cas_option
, &cas_options
)
1391 strvec_push(&args
, cas_option
->string
);
1392 strvec_push(&args
, url
.buf
);
1394 if (options
.force_if_includes
)
1395 strvec_push(&args
, "--force-if-includes");
1397 strvec_push(&args
, "--stdin");
1398 for (i
= 0; i
< nr_spec
; i
++)
1399 packet_buf_write(&preamble
, "%s\n", specs
[i
]);
1400 packet_buf_flush(&preamble
);
1402 memset(&rpc
, 0, sizeof(rpc
));
1403 rpc
.service_name
= "git-receive-pack",
1405 err
= rpc_service(&rpc
, heads
, args
.v
, &preamble
, &rpc_result
);
1407 write_or_die(1, rpc_result
.buf
, rpc_result
.len
);
1408 strbuf_release(&rpc_result
);
1409 strbuf_release(&preamble
);
1410 strvec_clear(&args
);
1414 static int push(int nr_spec
, const char **specs
)
1416 struct discovery
*heads
= discover_refs("git-receive-pack", 1);
1419 if (heads
->proto_git
)
1420 ret
= push_git(heads
, nr_spec
, specs
);
1422 ret
= push_dav(nr_spec
, specs
);
1423 free_discovery(heads
);
1427 static void parse_push(struct strbuf
*buf
)
1429 struct strvec specs
= STRVEC_INIT
;
1434 if (skip_prefix(buf
->buf
, "push ", &arg
))
1435 strvec_push(&specs
, arg
);
1437 die(_("http transport does not support %s"), buf
->buf
);
1440 if (strbuf_getline_lf(buf
, stdin
) == EOF
)
1446 ret
= push(specs
.nr
, specs
.v
);
1451 exit(128); /* error already reported */
1454 strvec_clear(&specs
);
1457 static int stateless_connect(const char *service_name
)
1459 struct discovery
*discover
;
1460 struct rpc_state rpc
= RPC_STATE_INIT
;
1461 struct strbuf buf
= STRBUF_INIT
;
1462 const char *accept_language
;
1465 * Run the info/refs request and see if the server supports protocol
1466 * v2. If and only if the server supports v2 can we successfully
1467 * establish a stateless connection, otherwise we need to tell the
1468 * client to fallback to using other transport helper functions to
1469 * complete their request.
1471 * The "git-upload-archive" service is a read-only operation. Fallback
1472 * to use "git-upload-pack" service to discover protocol version.
1474 if (!strcmp(service_name
, "git-upload-archive"))
1475 discover
= discover_refs("git-upload-pack", 0);
1477 discover
= discover_refs(service_name
, 0);
1478 if (discover
->version
!= protocol_v2
) {
1479 printf("fallback\n");
1483 /* Stateless Connection established */
1487 accept_language
= http_get_accept_language_header();
1488 if (accept_language
)
1489 rpc
.hdr_accept_language
= xstrfmt("%s", accept_language
);
1491 rpc
.service_name
= service_name
;
1492 rpc
.service_url
= xstrfmt("%s%s", url
.buf
, rpc
.service_name
);
1493 rpc
.hdr_content_type
= xstrfmt("Content-Type: application/x-%s-request", rpc
.service_name
);
1494 rpc
.hdr_accept
= xstrfmt("Accept: application/x-%s-result", rpc
.service_name
);
1495 if (get_protocol_http_header(discover
->version
, &buf
)) {
1496 rpc
.protocol_header
= strbuf_detach(&buf
, NULL
);
1498 rpc
.protocol_header
= NULL
;
1499 strbuf_release(&buf
);
1501 rpc
.buf
= xmalloc(http_post_buffer
);
1502 rpc
.alloc
= http_post_buffer
;
1507 rpc
.any_written
= 0;
1508 rpc
.gzip_request
= 1;
1509 rpc
.initial_buffer
= 0;
1510 rpc
.write_line_lengths
= 1;
1511 rpc
.flush_read_but_not_sent
= 0;
1514 * Dump the capability listing that we got from the server earlier
1515 * during the info/refs request. This does not work with the
1516 * "git-upload-archive" service.
1518 if (strcmp(service_name
, "git-upload-archive"))
1519 write_or_die(rpc
.in
, discover
->buf
, discover
->len
);
1521 /* Until we see EOF keep sending POSTs */
1524 enum packet_read_status status
;
1526 if (!rpc_read_from_out(&rpc
, PACKET_READ_GENTLE_ON_EOF
, &avail
,
1528 BUG("The entire rpc->buf should be larger than LARGE_PACKET_MAX");
1529 if (status
== PACKET_READ_EOF
)
1531 if (post_rpc(&rpc
, 1, status
== PACKET_READ_FLUSH
))
1532 /* We would have an err here */
1534 /* Reset the buffer for next request */
1538 free(rpc
.service_url
);
1539 free(rpc
.hdr_content_type
);
1540 free(rpc
.hdr_accept
);
1541 free(rpc
.hdr_accept_language
);
1542 free(rpc
.protocol_header
);
1544 strbuf_release(&buf
);
1549 int cmd_main(int argc
, const char **argv
)
1551 struct strbuf buf
= STRBUF_INIT
;
1555 setup_git_directory_gently(&nongit
);
1557 error(_("remote-curl: usage: git remote-curl <remote> [<url>]"));
1561 options
.verbosity
= 1;
1562 options
.progress
= !!isatty(2);
1564 string_list_init_dup(&options
.deepen_not
);
1565 string_list_init_dup(&options
.push_options
);
1568 * Just report "remote-curl" here (folding all the various aliases
1569 * ("git-remote-http", "git-remote-https", and etc.) here since they
1570 * are all just copies of the same actual executable.
1572 trace2_cmd_name("remote-curl");
1574 remote
= remote_get(argv
[1]);
1577 end_url_with_slash(&url
, argv
[2]);
1579 end_url_with_slash(&url
, remote
->url
.v
[0]);
1582 http_init(remote
, url
.buf
, 0);
1587 if (strbuf_getline_lf(&buf
, stdin
) == EOF
) {
1589 error(_("remote-curl: error reading command stream from git"));
1594 if (starts_with(buf
.buf
, "fetch ")) {
1596 setup_git_directory_gently(&nongit
);
1598 die(_("remote-curl: fetch attempted without a local repo"));
1602 } else if (!strcmp(buf
.buf
, "list") || starts_with(buf
.buf
, "list ")) {
1603 int for_push
= !!strstr(buf
.buf
+ 4, "for-push");
1604 output_refs(get_refs(for_push
));
1606 } else if (starts_with(buf
.buf
, "push ")) {
1609 } else if (skip_prefix(buf
.buf
, "option ", &arg
)) {
1610 const char *value
= strchrnul(arg
, ' ');
1611 size_t arglen
= value
- arg
;
1615 value
++; /* skip over SP */
1619 result
= set_option(arg
, arglen
, value
);
1622 else if (result
< 0)
1623 printf("error invalid value\n");
1625 printf("unsupported\n");
1628 } else if (skip_prefix(buf
.buf
, "get ", &arg
)) {
1632 } else if (!strcmp(buf
.buf
, "capabilities")) {
1633 printf("stateless-connect\n");
1638 printf("check-connectivity\n");
1639 printf("object-format\n");
1642 } else if (skip_prefix(buf
.buf
, "stateless-connect ", &arg
)) {
1643 if (!stateless_connect(arg
))
1646 error(_("remote-curl: unknown command '%s' from git"), buf
.buf
);
1655 strbuf_release(&buf
);