1 #define USE_THE_REPOSITORY_VARIABLE
2 #define DISABLE_SIGN_COMPARE_WARNINGS
4 #include "git-compat-util.h"
5 #include "git-curl-compat.h"
7 #include "environment.h"
15 #include "run-command.h"
17 #include "string-list.h"
19 #include "credential.h"
20 #include "oid-array.h"
21 #include "send-pack.h"
26 #include "transport.h"
28 #include "write-or-die.h"
30 static struct remote
*remote
;
31 /* always ends with a trailing slash */
32 static struct strbuf url
= STRBUF_INIT
;
38 struct string_list deepen_not
;
39 struct string_list push_options
;
41 unsigned progress
: 1,
42 check_self_contained_and_connected
: 1,
48 /* One of the SEND_PACK_PUSH_CERT_* constants. */
52 /* see documentation of corresponding flag in fetch-pack.h */
58 force_if_includes
: 1;
59 const struct git_hash_algo
*hash_algo
;
61 static struct options options
;
62 static struct string_list cas_options
= STRING_LIST_INIT_DUP
;
64 static int set_option(const char *name
, size_t namelen
, const char *value
)
66 if (!strncmp(name
, "verbosity", namelen
)) {
68 int v
= strtol(value
, &end
, 10);
69 if (value
== end
|| *end
)
71 options
.verbosity
= v
;
74 else if (!strncmp(name
, "progress", namelen
)) {
75 if (!strcmp(value
, "true"))
77 else if (!strcmp(value
, "false"))
83 else if (!strncmp(name
, "depth", namelen
)) {
85 unsigned long v
= strtoul(value
, &end
, 10);
86 if (value
== end
|| *end
)
91 else if (!strncmp(name
, "deepen-since", namelen
)) {
92 options
.deepen_since
= xstrdup(value
);
95 else if (!strncmp(name
, "deepen-not", namelen
)) {
96 string_list_append(&options
.deepen_not
, value
);
99 else if (!strncmp(name
, "deepen-relative", namelen
)) {
100 if (!strcmp(value
, "true"))
101 options
.deepen_relative
= 1;
102 else if (!strcmp(value
, "false"))
103 options
.deepen_relative
= 0;
108 else if (!strncmp(name
, "followtags", namelen
)) {
109 if (!strcmp(value
, "true"))
110 options
.followtags
= 1;
111 else if (!strcmp(value
, "false"))
112 options
.followtags
= 0;
117 else if (!strncmp(name
, "dry-run", namelen
)) {
118 if (!strcmp(value
, "true"))
120 else if (!strcmp(value
, "false"))
126 else if (!strncmp(name
, "check-connectivity", namelen
)) {
127 if (!strcmp(value
, "true"))
128 options
.check_self_contained_and_connected
= 1;
129 else if (!strcmp(value
, "false"))
130 options
.check_self_contained_and_connected
= 0;
135 else if (!strncmp(name
, "cas", namelen
)) {
136 struct strbuf val
= STRBUF_INIT
;
137 strbuf_addstr(&val
, "--force-with-lease=");
139 strbuf_addstr(&val
, value
);
140 else if (unquote_c_style(&val
, value
, NULL
))
142 string_list_append(&cas_options
, val
.buf
);
143 strbuf_release(&val
);
145 } else if (!strncmp(name
, TRANS_OPT_FORCE_IF_INCLUDES
, namelen
)) {
146 if (!strcmp(value
, "true"))
147 options
.force_if_includes
= 1;
148 else if (!strcmp(value
, "false"))
149 options
.force_if_includes
= 0;
153 } else if (!strncmp(name
, "cloning", namelen
)) {
154 if (!strcmp(value
, "true"))
156 else if (!strcmp(value
, "false"))
161 } else if (!strncmp(name
, "update-shallow", namelen
)) {
162 if (!strcmp(value
, "true"))
163 options
.update_shallow
= 1;
164 else if (!strcmp(value
, "false"))
165 options
.update_shallow
= 0;
169 } else if (!strncmp(name
, "pushcert", namelen
)) {
170 if (!strcmp(value
, "true"))
171 options
.push_cert
= SEND_PACK_PUSH_CERT_ALWAYS
;
172 else if (!strcmp(value
, "false"))
173 options
.push_cert
= SEND_PACK_PUSH_CERT_NEVER
;
174 else if (!strcmp(value
, "if-asked"))
175 options
.push_cert
= SEND_PACK_PUSH_CERT_IF_ASKED
;
179 } else if (!strncmp(name
, "atomic", namelen
)) {
180 if (!strcmp(value
, "true"))
182 else if (!strcmp(value
, "false"))
187 } else if (!strncmp(name
, "push-option", namelen
)) {
189 string_list_append(&options
.push_options
, value
);
191 struct strbuf unquoted
= STRBUF_INIT
;
192 if (unquote_c_style(&unquoted
, value
, NULL
) < 0)
193 die(_("invalid quoting in push-option value: '%s'"), value
);
194 string_list_append_nodup(&options
.push_options
,
195 strbuf_detach(&unquoted
, NULL
));
198 } else if (!strncmp(name
, "family", namelen
)) {
199 if (!strcmp(value
, "ipv4"))
200 git_curl_ipresolve
= CURL_IPRESOLVE_V4
;
201 else if (!strcmp(value
, "ipv6"))
202 git_curl_ipresolve
= CURL_IPRESOLVE_V6
;
203 else if (!strcmp(value
, "all"))
204 git_curl_ipresolve
= CURL_IPRESOLVE_WHATEVER
;
208 } else if (!strncmp(name
, "from-promisor", namelen
)) {
209 options
.from_promisor
= 1;
211 } else if (!strncmp(name
, "refetch", namelen
)) {
214 } else if (!strncmp(name
, "filter", namelen
)) {
215 options
.filter
= xstrdup(value
);
217 } else if (!strncmp(name
, "object-format", namelen
)) {
218 options
.object_format
= 1;
219 if (strcmp(value
, "true"))
220 die(_("unknown value for object-format: %s"), value
);
223 return 1 /* unsupported */;
233 struct oid_array shallow
;
234 enum protocol_version version
;
235 unsigned proto_git
: 1;
237 static struct discovery
*last_discovery
;
239 static struct ref
*parse_git_refs(struct discovery
*heads
, int for_push
)
241 struct ref
*list
= NULL
;
242 struct packet_reader reader
;
244 packet_reader_init(&reader
, -1, heads
->buf
, heads
->len
,
245 PACKET_READ_CHOMP_NEWLINE
|
246 PACKET_READ_GENTLE_ON_EOF
|
247 PACKET_READ_DIE_ON_ERR_PACKET
);
249 heads
->version
= discover_version(&reader
);
250 switch (heads
->version
) {
253 * Do nothing. This isn't a list of refs but rather a
254 * capability advertisement. Client would have run
255 * 'stateless-connect' so we'll dump this capability listing
256 * and let them request the refs themselves.
261 get_remote_heads(&reader
, &list
, for_push
? REF_NORMAL
: 0,
262 NULL
, &heads
->shallow
);
263 options
.hash_algo
= reader
.hash_algo
;
265 case protocol_unknown_version
:
266 BUG("unknown protocol version");
273 * Try to detect the hash algorithm used by the remote repository when using
274 * the dumb HTTP transport. As dumb transports cannot tell us the object hash
275 * directly have to derive it from the advertised ref lengths.
277 static const struct git_hash_algo
*detect_hash_algo(struct discovery
*heads
)
279 const char *p
= memchr(heads
->buf
, '\t', heads
->len
);
283 * In case the remote has no refs we have no way to reliably determine
284 * the object hash used by that repository. In that case we simply fall
285 * back to SHA1, which may or may not be correct.
288 return &hash_algos
[GIT_HASH_SHA1
];
290 algo
= hash_algo_by_length((p
- heads
->buf
) / 2);
291 if (algo
== GIT_HASH_UNKNOWN
)
293 return &hash_algos
[algo
];
296 static struct ref
*parse_info_refs(struct discovery
*heads
)
298 char *data
, *start
, *mid
;
302 struct ref
*refs
= NULL
;
303 struct ref
*ref
= NULL
;
304 struct ref
*last_ref
= NULL
;
306 options
.hash_algo
= detect_hash_algo(heads
);
307 if (!options
.hash_algo
)
308 die("%sinfo/refs not valid: could not determine hash algorithm; "
309 "is this a git repository?",
310 transport_anonymize_url(url
.buf
));
313 * Set the repository's hash algo to whatever we have just detected.
314 * This ensures that we can correctly parse the remote references.
316 repo_set_hash_algo(the_repository
, hash_algo_by_ptr(options
.hash_algo
));
321 while (i
< heads
->len
) {
327 if (data
[i
] == '\n') {
328 if (mid
- start
!= options
.hash_algo
->hexsz
)
329 die(_("%sinfo/refs not valid: is this a git repository?"),
330 transport_anonymize_url(url
.buf
));
333 ref
= alloc_ref(ref_name
);
334 get_oid_hex_algop(start
, &ref
->old_oid
, options
.hash_algo
);
338 last_ref
->next
= ref
;
345 ref
= alloc_ref("HEAD");
346 if (!http_fetch_ref(url
.buf
, ref
) &&
347 !resolve_remote_symref(ref
, refs
)) {
357 static void free_discovery(struct discovery
*d
)
360 if (d
== last_discovery
)
361 last_discovery
= NULL
;
362 free(d
->shallow
.oid
);
370 static int show_http_message(struct strbuf
*type
, struct strbuf
*charset
,
376 * We only show text/plain parts, as other types are likely
377 * to be ugly to look at on the user's terminal.
379 if (strcmp(type
->buf
, "text/plain"))
382 strbuf_reencode(msg
, charset
->buf
, get_log_output_encoding());
390 eol
= strchrnul(p
, '\n');
391 fprintf(stderr
, "remote: %.*s\n", (int)(eol
- p
), p
);
397 static int get_protocol_http_header(enum protocol_version version
,
398 struct strbuf
*header
)
401 strbuf_addf(header
, GIT_PROTOCOL_HEADER
": version=%d",
410 static void check_smart_http(struct discovery
*d
, const char *service
,
414 struct packet_reader reader
;
417 * If we don't see x-$service-advertisement, then it's not smart-http.
418 * But once we do, we commit to it and assume any other protocol
419 * violations are hard errors.
421 if (!skip_prefix(type
->buf
, "application/x-", &p
) ||
422 !skip_prefix(p
, service
, &p
) ||
423 strcmp(p
, "-advertisement"))
426 packet_reader_init(&reader
, -1, d
->buf
, d
->len
,
427 PACKET_READ_CHOMP_NEWLINE
|
428 PACKET_READ_DIE_ON_ERR_PACKET
);
429 if (packet_reader_read(&reader
) != PACKET_READ_NORMAL
)
430 die(_("invalid server response; expected service, got flush packet"));
432 if (skip_prefix(reader
.line
, "# service=", &p
) && !strcmp(p
, service
)) {
434 * The header can include additional metadata lines, up
435 * until a packet flush marker. Ignore these now, but
436 * in the future we might start to scan them.
439 packet_reader_read(&reader
);
440 if (reader
.pktlen
<= 0) {
446 * v0 smart http; callers expect us to soak up the
447 * service and header packets
449 d
->buf
= reader
.src_buffer
;
450 d
->len
= reader
.src_len
;
453 } else if (!strcmp(reader
.line
, "version 2")) {
455 * v2 smart http; do not consume version packet, which will
456 * be handled elsewhere.
461 die(_("invalid server response; got '%s'"), reader
.line
);
465 static struct discovery
*discover_refs(const char *service
, int for_push
)
467 struct strbuf type
= STRBUF_INIT
;
468 struct strbuf charset
= STRBUF_INIT
;
469 struct strbuf buffer
= STRBUF_INIT
;
470 struct strbuf refs_url
= STRBUF_INIT
;
471 struct strbuf effective_url
= STRBUF_INIT
;
472 struct strbuf protocol_header
= STRBUF_INIT
;
473 struct string_list extra_headers
= STRING_LIST_INIT_DUP
;
474 struct discovery
*last
= last_discovery
;
475 int http_ret
, maybe_smart
= 0;
476 struct http_get_options http_options
;
477 enum protocol_version version
= get_protocol_version_config();
479 if (last
&& !strcmp(service
, last
->service
))
481 free_discovery(last
);
483 strbuf_addf(&refs_url
, "%sinfo/refs", url
.buf
);
484 if ((starts_with(url
.buf
, "http://") || starts_with(url
.buf
, "https://")) &&
485 git_env_bool("GIT_SMART_HTTP", 1)) {
487 if (!strchr(url
.buf
, '?'))
488 strbuf_addch(&refs_url
, '?');
490 strbuf_addch(&refs_url
, '&');
491 strbuf_addf(&refs_url
, "service=%s", service
);
495 * NEEDSWORK: If we are trying to use protocol v2 and we are planning
496 * to perform any operation that doesn't involve upload-pack (i.e., a
497 * fetch, ls-remote, etc), then fallback to v0 since we don't know how
498 * to do anything else (like push or remote archive) via v2.
500 if (version
== protocol_v2
&& strcmp("git-upload-pack", service
))
501 version
= protocol_v0
;
503 /* Add the extra Git-Protocol header */
504 if (get_protocol_http_header(version
, &protocol_header
))
505 string_list_append(&extra_headers
, protocol_header
.buf
);
507 memset(&http_options
, 0, sizeof(http_options
));
508 http_options
.content_type
= &type
;
509 http_options
.charset
= &charset
;
510 http_options
.effective_url
= &effective_url
;
511 http_options
.base_url
= &url
;
512 http_options
.extra_headers
= &extra_headers
;
513 http_options
.initial_request
= 1;
514 http_options
.no_cache
= 1;
516 http_ret
= http_get_strbuf(refs_url
.buf
, &buffer
, &http_options
);
520 case HTTP_MISSING_TARGET
:
521 show_http_message(&type
, &charset
, &buffer
);
522 die(_("repository '%s' not found"),
523 transport_anonymize_url(url
.buf
));
525 show_http_message(&type
, &charset
, &buffer
);
526 die(_("Authentication failed for '%s'"),
527 transport_anonymize_url(url
.buf
));
528 case HTTP_NOMATCHPUBLICKEY
:
529 show_http_message(&type
, &charset
, &buffer
);
530 die(_("unable to access '%s' with http.pinnedPubkey configuration: %s"),
531 transport_anonymize_url(url
.buf
), curl_errorstr
);
533 show_http_message(&type
, &charset
, &buffer
);
534 die(_("unable to access '%s': %s"),
535 transport_anonymize_url(url
.buf
), curl_errorstr
);
538 if (options
.verbosity
&& !starts_with(refs_url
.buf
, url
.buf
)) {
539 char *u
= transport_anonymize_url(url
.buf
);
540 warning(_("redirecting to %s"), u
);
544 last
= xcalloc(1, sizeof(*last_discovery
));
545 last
->service
= xstrdup(service
);
546 last
->buf_alloc
= strbuf_detach(&buffer
, &last
->len
);
547 last
->buf
= last
->buf_alloc
;
550 check_smart_http(last
, service
, &type
);
553 last
->refs
= parse_git_refs(last
, for_push
);
555 last
->refs
= parse_info_refs(last
);
557 strbuf_release(&refs_url
);
558 strbuf_release(&type
);
559 strbuf_release(&charset
);
560 strbuf_release(&effective_url
);
561 strbuf_release(&buffer
);
562 strbuf_release(&protocol_header
);
563 string_list_clear(&extra_headers
, 0);
564 last_discovery
= last
;
568 static struct ref
*get_refs(int for_push
)
570 struct discovery
*heads
;
573 heads
= discover_refs("git-receive-pack", for_push
);
575 heads
= discover_refs("git-upload-pack", for_push
);
580 static void output_refs(struct ref
*refs
)
583 if (options
.object_format
&& options
.hash_algo
) {
584 printf(":object-format %s\n", options
.hash_algo
->name
);
585 repo_set_hash_algo(the_repository
,
586 hash_algo_by_ptr(options
.hash_algo
));
588 for (posn
= refs
; posn
; posn
= posn
->next
) {
590 printf("@%s %s\n", posn
->symref
, posn
->name
);
592 printf("%s %s\n", hash_to_hex_algop(posn
->old_oid
.hash
,
601 const char *service_name
;
603 char *hdr_content_type
;
605 char *hdr_accept_language
;
606 char *protocol_header
;
614 unsigned gzip_request
: 1;
615 unsigned initial_buffer
: 1;
618 * Whenever a pkt-line is read into buf, append the 4 characters
619 * denoting its length before appending the payload.
621 unsigned write_line_lengths
: 1;
624 * Used by rpc_out; initialize to 0. This is true if a flush has been
625 * read, but the corresponding line length (if write_line_lengths is
626 * true) and EOF have not been sent to libcurl. Since each flush marks
627 * the end of a request, each flush must be completely sent before any
628 * further reading occurs.
630 unsigned flush_read_but_not_sent
: 1;
633 #define RPC_STATE_INIT { 0 }
636 * Appends the result of reading from rpc->out to the string represented by
637 * rpc->buf and rpc->len if there is enough space. Returns 1 if there was
638 * enough space, 0 otherwise.
640 * If rpc->write_line_lengths is true, appends the line length as a 4-byte
641 * hexadecimal string before appending the result described above.
643 * Writes the total number of bytes appended into appended.
645 static int rpc_read_from_out(struct rpc_state
*rpc
, int options
,
647 enum packet_read_status
*status
) {
652 if (rpc
->write_line_lengths
) {
653 left
= rpc
->alloc
- rpc
->len
- 4;
654 buf
= rpc
->buf
+ rpc
->len
+ 4;
656 left
= rpc
->alloc
- rpc
->len
;
657 buf
= rpc
->buf
+ rpc
->len
;
660 if (left
< LARGE_PACKET_MAX
)
663 *status
= packet_read_with_status(rpc
->out
, NULL
, NULL
, buf
,
664 left
, &pktlen_raw
, options
);
665 if (*status
!= PACKET_READ_EOF
) {
666 *appended
= pktlen_raw
+ (rpc
->write_line_lengths
? 4 : 0);
667 rpc
->len
+= *appended
;
670 if (rpc
->write_line_lengths
) {
672 case PACKET_READ_EOF
:
673 if (!(options
& PACKET_READ_GENTLE_ON_EOF
))
674 die(_("shouldn't have EOF when not gentle on EOF"));
676 case PACKET_READ_NORMAL
:
677 set_packet_header(buf
- 4, *appended
);
679 case PACKET_READ_DELIM
:
680 memcpy(buf
- 4, "0001", 4);
682 case PACKET_READ_FLUSH
:
683 memcpy(buf
- 4, "0000", 4);
685 case PACKET_READ_RESPONSE_END
:
686 die(_("remote server sent unexpected response end packet"));
693 static size_t rpc_out(void *ptr
, size_t eltsize
,
694 size_t nmemb
, void *buffer_
)
696 size_t max
= eltsize
* nmemb
;
697 struct rpc_state
*rpc
= buffer_
;
698 size_t avail
= rpc
->len
- rpc
->pos
;
699 enum packet_read_status status
;
702 rpc
->initial_buffer
= 0;
705 if (!rpc
->flush_read_but_not_sent
) {
706 if (!rpc_read_from_out(rpc
, 0, &avail
, &status
))
707 BUG("The entire rpc->buf should be larger than LARGE_PACKET_MAX");
708 if (status
== PACKET_READ_FLUSH
)
709 rpc
->flush_read_but_not_sent
= 1;
712 * If flush_read_but_not_sent is true, we have already read one
713 * full request but have not fully sent it + EOF, which is why
714 * we need to refrain from reading.
717 if (rpc
->flush_read_but_not_sent
) {
720 * The line length either does not need to be sent at
721 * all or has already been completely sent. Now we can
722 * return 0, indicating EOF, meaning that the flush has
725 rpc
->flush_read_but_not_sent
= 0;
729 * If avail is non-zero, the line length for the flush still
730 * hasn't been fully sent. Proceed with sending the line
737 memcpy(ptr
, rpc
->buf
+ rpc
->pos
, avail
);
742 static int rpc_seek(void *clientp
, curl_off_t offset
, int origin
)
744 struct rpc_state
*rpc
= clientp
;
746 if (origin
!= SEEK_SET
)
747 BUG("rpc_seek only handles SEEK_SET, not %d", origin
);
749 if (rpc
->initial_buffer
) {
750 if (offset
< 0 || offset
> rpc
->len
) {
751 error("curl seek would be outside of rpc buffer");
752 return CURL_SEEKFUNC_FAIL
;
755 return CURL_SEEKFUNC_OK
;
757 error(_("unable to rewind rpc post data - try increasing http.postBuffer"));
758 return CURL_SEEKFUNC_FAIL
;
761 struct check_pktline_state
{
767 static void check_pktline(struct check_pktline_state
*state
, const char *ptr
, size_t size
)
770 if (!state
->remaining
) {
771 int digits_remaining
= 4 - state
->len_filled
;
772 if (digits_remaining
> size
)
773 digits_remaining
= size
;
774 memcpy(&state
->len_buf
[state
->len_filled
], ptr
, digits_remaining
);
775 state
->len_filled
+= digits_remaining
;
776 ptr
+= digits_remaining
;
777 size
-= digits_remaining
;
779 if (state
->len_filled
== 4) {
780 state
->remaining
= packet_length(state
->len_buf
,
781 sizeof(state
->len_buf
));
782 if (state
->remaining
< 0) {
783 die(_("remote-curl: bad line length character: %.4s"), state
->len_buf
);
784 } else if (state
->remaining
== 2) {
785 die(_("remote-curl: unexpected response end packet"));
786 } else if (state
->remaining
< 4) {
787 state
->remaining
= 0;
789 state
->remaining
-= 4;
791 state
->len_filled
= 0;
795 if (state
->remaining
) {
796 int remaining
= state
->remaining
;
797 if (remaining
> size
)
801 state
->remaining
-= remaining
;
807 struct rpc_state
*rpc
;
808 struct active_request_slot
*slot
;
810 struct check_pktline_state pktline_state
;
814 * A callback for CURLOPT_WRITEFUNCTION. The return value is the bytes consumed
817 static size_t rpc_in(char *ptr
, size_t eltsize
,
818 size_t nmemb
, void *buffer_
)
820 size_t size
= eltsize
* nmemb
;
821 struct rpc_in_data
*data
= buffer_
;
824 if (curl_easy_getinfo(data
->slot
->curl
, CURLINFO_RESPONSE_CODE
,
825 &response_code
) != CURLE_OK
)
827 if (response_code
>= 300)
830 data
->rpc
->any_written
= 1;
831 if (data
->check_pktline
)
832 check_pktline(&data
->pktline_state
, ptr
, size
);
833 write_or_die(data
->rpc
->in
, ptr
, size
);
837 static int run_slot(struct active_request_slot
*slot
,
838 struct slot_results
*results
)
841 struct slot_results results_buf
;
844 results
= &results_buf
;
846 err
= run_one_slot(slot
, results
);
848 if (err
!= HTTP_OK
&& err
!= HTTP_REAUTH
) {
849 struct strbuf msg
= STRBUF_INIT
;
850 if (results
->http_code
&& results
->http_code
!= 200)
851 strbuf_addf(&msg
, "HTTP %ld", results
->http_code
);
852 if (results
->curl_result
!= CURLE_OK
) {
854 strbuf_addch(&msg
, ' ');
855 strbuf_addf(&msg
, "curl %d", results
->curl_result
);
856 if (curl_errorstr
[0]) {
857 strbuf_addch(&msg
, ' ');
858 strbuf_addstr(&msg
, curl_errorstr
);
861 error(_("RPC failed; %s"), msg
.buf
);
862 strbuf_release(&msg
);
868 static int probe_rpc(struct rpc_state
*rpc
, struct slot_results
*results
)
870 struct active_request_slot
*slot
;
871 struct curl_slist
*headers
= http_copy_default_headers();
872 struct strbuf buf
= STRBUF_INIT
;
875 slot
= get_active_slot();
877 headers
= curl_slist_append(headers
, rpc
->hdr_content_type
);
878 headers
= curl_slist_append(headers
, rpc
->hdr_accept
);
880 curl_easy_setopt(slot
->curl
, CURLOPT_NOBODY
, 0);
881 curl_easy_setopt(slot
->curl
, CURLOPT_POST
, 1);
882 curl_easy_setopt(slot
->curl
, CURLOPT_URL
, rpc
->service_url
);
883 curl_easy_setopt(slot
->curl
, CURLOPT_ENCODING
, NULL
);
884 curl_easy_setopt(slot
->curl
, CURLOPT_POSTFIELDS
, "0000");
885 curl_easy_setopt(slot
->curl
, CURLOPT_POSTFIELDSIZE
, 4);
886 curl_easy_setopt(slot
->curl
, CURLOPT_HTTPHEADER
, headers
);
887 curl_easy_setopt(slot
->curl
, CURLOPT_WRITEFUNCTION
, fwrite_buffer
);
888 curl_easy_setopt(slot
->curl
, CURLOPT_WRITEDATA
, &buf
);
890 err
= run_slot(slot
, results
);
892 curl_slist_free_all(headers
);
893 strbuf_release(&buf
);
897 static curl_off_t
xcurl_off_t(size_t len
)
899 uintmax_t size
= len
;
900 if (size
> maximum_signed_value_of_type(curl_off_t
))
901 die(_("cannot handle pushes this big"));
902 return (curl_off_t
)size
;
906 * If flush_received is true, do not attempt to read any more; just use what's
909 static int post_rpc(struct rpc_state
*rpc
, int stateless_connect
, int flush_received
)
911 struct active_request_slot
*slot
;
912 struct curl_slist
*headers
= NULL
;
913 int use_gzip
= rpc
->gzip_request
;
914 char *gzip_body
= NULL
;
915 size_t gzip_size
= 0;
916 int err
, large_request
= 0;
917 int needs_100_continue
= 0;
918 struct rpc_in_data rpc_in_data
;
920 /* Try to load the entire request, if we can fit it into the
921 * allocated buffer space we can use HTTP/1.0 and avoid the
922 * chunked encoding mess.
924 if (!flush_received
) {
927 enum packet_read_status status
;
929 if (!rpc_read_from_out(rpc
, 0, &n
, &status
)) {
934 if (status
== PACKET_READ_FLUSH
)
940 struct slot_results results
;
943 err
= probe_rpc(rpc
, &results
);
944 if (err
== HTTP_REAUTH
)
945 credential_fill(the_repository
, &http_auth
, 0);
946 } while (err
== HTTP_REAUTH
);
950 if (results
.auth_avail
& CURLAUTH_GSSNEGOTIATE
|| http_auth
.authtype
)
951 needs_100_continue
= 1;
955 headers
= http_copy_default_headers();
956 headers
= curl_slist_append(headers
, rpc
->hdr_content_type
);
957 headers
= curl_slist_append(headers
, rpc
->hdr_accept
);
958 headers
= curl_slist_append(headers
, needs_100_continue
?
959 "Expect: 100-continue" : "Expect:");
961 headers
= http_append_auth_header(&http_auth
, headers
);
963 /* Add Accept-Language header */
964 if (rpc
->hdr_accept_language
)
965 headers
= curl_slist_append(headers
, rpc
->hdr_accept_language
);
967 /* Add the extra Git-Protocol header */
968 if (rpc
->protocol_header
)
969 headers
= curl_slist_append(headers
, rpc
->protocol_header
);
971 slot
= get_active_slot();
973 curl_easy_setopt(slot
->curl
, CURLOPT_NOBODY
, 0);
974 curl_easy_setopt(slot
->curl
, CURLOPT_POST
, 1);
975 curl_easy_setopt(slot
->curl
, CURLOPT_URL
, rpc
->service_url
);
976 curl_easy_setopt(slot
->curl
, CURLOPT_ENCODING
, "");
979 /* The request body is large and the size cannot be predicted.
980 * We must use chunked encoding to send it.
982 #ifdef GIT_CURL_NEED_TRANSFER_ENCODING_HEADER
983 headers
= curl_slist_append(headers
, "Transfer-Encoding: chunked");
985 rpc
->initial_buffer
= 1;
986 curl_easy_setopt(slot
->curl
, CURLOPT_READFUNCTION
, rpc_out
);
987 curl_easy_setopt(slot
->curl
, CURLOPT_INFILE
, rpc
);
988 curl_easy_setopt(slot
->curl
, CURLOPT_SEEKFUNCTION
, rpc_seek
);
989 curl_easy_setopt(slot
->curl
, CURLOPT_SEEKDATA
, rpc
);
990 if (options
.verbosity
> 1) {
991 fprintf(stderr
, "POST %s (chunked)\n", rpc
->service_name
);
995 } else if (gzip_body
) {
997 * If we are looping to retry authentication, then the previous
998 * run will have set up the headers and gzip buffer already,
999 * and we just need to send it.
1001 curl_easy_setopt(slot
->curl
, CURLOPT_POSTFIELDS
, gzip_body
);
1002 curl_easy_setopt(slot
->curl
, CURLOPT_POSTFIELDSIZE_LARGE
, xcurl_off_t(gzip_size
));
1004 } else if (use_gzip
&& 1024 < rpc
->len
) {
1005 /* The client backend isn't giving us compressed data so
1006 * we can try to deflate it ourselves, this may save on
1007 * the transfer time.
1012 git_deflate_init_gzip(&stream
, Z_BEST_COMPRESSION
);
1013 gzip_size
= git_deflate_bound(&stream
, rpc
->len
);
1014 gzip_body
= xmalloc(gzip_size
);
1016 stream
.next_in
= (unsigned char *)rpc
->buf
;
1017 stream
.avail_in
= rpc
->len
;
1018 stream
.next_out
= (unsigned char *)gzip_body
;
1019 stream
.avail_out
= gzip_size
;
1021 ret
= git_deflate(&stream
, Z_FINISH
);
1022 if (ret
!= Z_STREAM_END
)
1023 die(_("cannot deflate request; zlib deflate error %d"), ret
);
1025 ret
= git_deflate_end_gently(&stream
);
1027 die(_("cannot deflate request; zlib end error %d"), ret
);
1029 gzip_size
= stream
.total_out
;
1031 headers
= curl_slist_append(headers
, "Content-Encoding: gzip");
1032 curl_easy_setopt(slot
->curl
, CURLOPT_POSTFIELDS
, gzip_body
);
1033 curl_easy_setopt(slot
->curl
, CURLOPT_POSTFIELDSIZE_LARGE
, xcurl_off_t(gzip_size
));
1035 if (options
.verbosity
> 1) {
1036 fprintf(stderr
, "POST %s (gzip %lu to %lu bytes)\n",
1038 (unsigned long)rpc
->len
, (unsigned long)gzip_size
);
1042 /* We know the complete request size in advance, use the
1043 * more normal Content-Length approach.
1045 curl_easy_setopt(slot
->curl
, CURLOPT_POSTFIELDS
, rpc
->buf
);
1046 curl_easy_setopt(slot
->curl
, CURLOPT_POSTFIELDSIZE_LARGE
, xcurl_off_t(rpc
->len
));
1047 if (options
.verbosity
> 1) {
1048 fprintf(stderr
, "POST %s (%lu bytes)\n",
1049 rpc
->service_name
, (unsigned long)rpc
->len
);
1054 curl_easy_setopt(slot
->curl
, CURLOPT_HTTPHEADER
, headers
);
1055 curl_easy_setopt(slot
->curl
, CURLOPT_WRITEFUNCTION
, rpc_in
);
1056 rpc_in_data
.rpc
= rpc
;
1057 rpc_in_data
.slot
= slot
;
1058 rpc_in_data
.check_pktline
= stateless_connect
;
1059 memset(&rpc_in_data
.pktline_state
, 0, sizeof(rpc_in_data
.pktline_state
));
1060 curl_easy_setopt(slot
->curl
, CURLOPT_WRITEDATA
, &rpc_in_data
);
1061 curl_easy_setopt(slot
->curl
, CURLOPT_FAILONERROR
, 0);
1064 rpc
->any_written
= 0;
1065 err
= run_slot(slot
, NULL
);
1066 if (err
== HTTP_REAUTH
&& !large_request
) {
1067 credential_fill(the_repository
, &http_auth
, 0);
1068 curl_slist_free_all(headers
);
1074 if (!rpc
->any_written
)
1077 if (rpc_in_data
.pktline_state
.len_filled
)
1078 err
= error(_("%d bytes of length header were received"), rpc_in_data
.pktline_state
.len_filled
);
1079 if (rpc_in_data
.pktline_state
.remaining
)
1080 err
= error(_("%d bytes of body are still expected"), rpc_in_data
.pktline_state
.remaining
);
1082 if (stateless_connect
)
1083 packet_response_end(rpc
->in
);
1085 curl_slist_free_all(headers
);
1090 static int rpc_service(struct rpc_state
*rpc
, struct discovery
*heads
,
1091 const char **client_argv
, const struct strbuf
*preamble
,
1092 struct strbuf
*rpc_result
)
1094 const char *svc
= rpc
->service_name
;
1095 struct strbuf buf
= STRBUF_INIT
;
1096 struct child_process client
= CHILD_PROCESS_INIT
;
1102 strvec_pushv(&client
.args
, client_argv
);
1103 if (start_command(&client
))
1105 write_or_die(client
.in
, preamble
->buf
, preamble
->len
);
1107 write_or_die(client
.in
, heads
->buf
, heads
->len
);
1109 rpc
->alloc
= http_post_buffer
;
1110 rpc
->buf
= xmalloc(rpc
->alloc
);
1111 rpc
->in
= client
.in
;
1112 rpc
->out
= client
.out
;
1114 strbuf_addf(&buf
, "%s%s", url
.buf
, svc
);
1115 rpc
->service_url
= strbuf_detach(&buf
, NULL
);
1117 rpc
->hdr_accept_language
= xstrdup_or_null(http_get_accept_language_header());
1119 strbuf_addf(&buf
, "Content-Type: application/x-%s-request", svc
);
1120 rpc
->hdr_content_type
= strbuf_detach(&buf
, NULL
);
1122 strbuf_addf(&buf
, "Accept: application/x-%s-result", svc
);
1123 rpc
->hdr_accept
= strbuf_detach(&buf
, NULL
);
1125 if (get_protocol_http_header(heads
->version
, &buf
))
1126 rpc
->protocol_header
= strbuf_detach(&buf
, NULL
);
1128 rpc
->protocol_header
= NULL
;
1131 int n
= packet_read(rpc
->out
, rpc
->buf
, rpc
->alloc
, 0);
1136 err
|= post_rpc(rpc
, 0, 0);
1142 strbuf_read(rpc_result
, client
.out
, 0);
1146 if (xread(client
.out
, buf
, sizeof(buf
)) <= 0)
1153 err
|= finish_command(&client
);
1154 free(rpc
->service_url
);
1155 free(rpc
->hdr_content_type
);
1156 free(rpc
->hdr_accept
);
1157 free(rpc
->hdr_accept_language
);
1158 free(rpc
->protocol_header
);
1160 strbuf_release(&buf
);
1164 static int fetch_dumb(int nr_heads
, struct ref
**to_fetch
)
1166 struct walker
*walker
;
1170 ALLOC_ARRAY(targets
, nr_heads
);
1171 if (options
.depth
|| options
.deepen_since
)
1172 die(_("dumb http transport does not support shallow capabilities"));
1173 for (i
= 0; i
< nr_heads
; i
++)
1174 targets
[i
] = xstrdup(oid_to_hex(&to_fetch
[i
]->old_oid
));
1176 walker
= get_http_walker(url
.buf
);
1177 walker
->get_verbosely
= options
.verbosity
>= 3;
1178 walker
->get_progress
= options
.progress
;
1179 walker
->get_recover
= 0;
1180 ret
= walker_fetch(walker
, nr_heads
, targets
, NULL
, NULL
);
1181 walker_free(walker
);
1183 for (i
= 0; i
< nr_heads
; i
++)
1187 return ret
? error(_("fetch failed.")) : 0;
1190 static int fetch_git(struct discovery
*heads
,
1191 int nr_heads
, struct ref
**to_fetch
)
1193 struct rpc_state rpc
= RPC_STATE_INIT
;
1194 struct strbuf preamble
= STRBUF_INIT
;
1196 struct strvec args
= STRVEC_INIT
;
1197 struct strbuf rpc_result
= STRBUF_INIT
;
1199 strvec_pushl(&args
, "fetch-pack", "--stateless-rpc",
1200 "--stdin", "--lock-pack", NULL
);
1201 if (options
.followtags
)
1202 strvec_push(&args
, "--include-tag");
1204 strvec_push(&args
, "--thin");
1205 if (options
.verbosity
>= 3)
1206 strvec_pushl(&args
, "-v", "-v", NULL
);
1207 if (options
.check_self_contained_and_connected
)
1208 strvec_push(&args
, "--check-self-contained-and-connected");
1209 if (options
.cloning
)
1210 strvec_push(&args
, "--cloning");
1211 if (options
.update_shallow
)
1212 strvec_push(&args
, "--update-shallow");
1213 if (!options
.progress
)
1214 strvec_push(&args
, "--no-progress");
1216 strvec_pushf(&args
, "--depth=%lu", options
.depth
);
1217 if (options
.deepen_since
)
1218 strvec_pushf(&args
, "--shallow-since=%s", options
.deepen_since
);
1219 for (i
= 0; i
< options
.deepen_not
.nr
; i
++)
1220 strvec_pushf(&args
, "--shallow-exclude=%s",
1221 options
.deepen_not
.items
[i
].string
);
1222 if (options
.deepen_relative
&& options
.depth
)
1223 strvec_push(&args
, "--deepen-relative");
1224 if (options
.from_promisor
)
1225 strvec_push(&args
, "--from-promisor");
1226 if (options
.refetch
)
1227 strvec_push(&args
, "--refetch");
1229 strvec_pushf(&args
, "--filter=%s", options
.filter
);
1230 strvec_push(&args
, url
.buf
);
1232 for (i
= 0; i
< nr_heads
; i
++) {
1233 struct ref
*ref
= to_fetch
[i
];
1235 die(_("cannot fetch by sha1 over smart http"));
1236 packet_buf_write(&preamble
, "%s %s\n",
1237 oid_to_hex(&ref
->old_oid
), ref
->name
);
1239 packet_buf_flush(&preamble
);
1241 memset(&rpc
, 0, sizeof(rpc
));
1242 rpc
.service_name
= "git-upload-pack",
1243 rpc
.gzip_request
= 1;
1245 err
= rpc_service(&rpc
, heads
, args
.v
, &preamble
, &rpc_result
);
1247 write_or_die(1, rpc_result
.buf
, rpc_result
.len
);
1248 strbuf_release(&rpc_result
);
1249 strbuf_release(&preamble
);
1250 strvec_clear(&args
);
1254 static int fetch(int nr_heads
, struct ref
**to_fetch
)
1256 struct discovery
*d
= discover_refs("git-upload-pack", 0);
1258 return fetch_git(d
, nr_heads
, to_fetch
);
1260 return fetch_dumb(nr_heads
, to_fetch
);
1263 static void parse_fetch(struct strbuf
*buf
)
1265 struct ref
**to_fetch
= NULL
;
1266 struct ref
*list_head
= NULL
;
1267 struct ref
**list
= &list_head
;
1268 int alloc_heads
= 0, nr_heads
= 0;
1272 if (skip_prefix(buf
->buf
, "fetch ", &p
)) {
1275 struct object_id old_oid
;
1278 if (parse_oid_hex(p
, &old_oid
, &q
))
1279 die(_("protocol error: expected sha/ref, got '%s'"), p
);
1285 die(_("protocol error: expected sha/ref, got '%s'"), p
);
1287 ref
= alloc_ref(name
);
1288 oidcpy(&ref
->old_oid
, &old_oid
);
1293 ALLOC_GROW(to_fetch
, nr_heads
+ 1, alloc_heads
);
1294 to_fetch
[nr_heads
++] = ref
;
1297 die(_("http transport does not support %s"), buf
->buf
);
1300 if (strbuf_getline_lf(buf
, stdin
) == EOF
)
1306 if (fetch(nr_heads
, to_fetch
))
1307 exit(128); /* error already reported */
1308 free_refs(list_head
);
1316 static void parse_get(const char *arg
)
1318 struct strbuf url
= STRBUF_INIT
;
1319 struct strbuf path
= STRBUF_INIT
;
1322 space
= strchr(arg
, ' ');
1325 die(_("protocol error: expected '<url> <path>', missing space"));
1327 strbuf_add(&url
, arg
, space
- arg
);
1328 strbuf_addstr(&path
, space
+ 1);
1330 if (http_get_file(url
.buf
, path
.buf
, NULL
))
1331 die(_("failed to download file at URL '%s'"), url
.buf
);
1333 strbuf_release(&url
);
1334 strbuf_release(&path
);
1339 static int push_dav(int nr_spec
, const char **specs
)
1341 struct child_process child
= CHILD_PROCESS_INIT
;
1345 strvec_push(&child
.args
, "http-push");
1346 strvec_push(&child
.args
, "--helper-status");
1347 if (options
.dry_run
)
1348 strvec_push(&child
.args
, "--dry-run");
1349 if (options
.verbosity
> 1)
1350 strvec_push(&child
.args
, "--verbose");
1351 strvec_push(&child
.args
, url
.buf
);
1352 for (i
= 0; i
< nr_spec
; i
++)
1353 strvec_push(&child
.args
, specs
[i
]);
1355 if (run_command(&child
))
1356 die(_("git-http-push failed"));
1360 static int push_git(struct discovery
*heads
, int nr_spec
, const char **specs
)
1362 struct rpc_state rpc
= RPC_STATE_INIT
;
1365 struct string_list_item
*cas_option
;
1366 struct strbuf preamble
= STRBUF_INIT
;
1367 struct strbuf rpc_result
= STRBUF_INIT
;
1370 strvec_pushl(&args
, "send-pack", "--stateless-rpc", "--helper-status",
1374 strvec_push(&args
, "--thin");
1375 if (options
.dry_run
)
1376 strvec_push(&args
, "--dry-run");
1377 if (options
.push_cert
== SEND_PACK_PUSH_CERT_ALWAYS
)
1378 strvec_push(&args
, "--signed=yes");
1379 else if (options
.push_cert
== SEND_PACK_PUSH_CERT_IF_ASKED
)
1380 strvec_push(&args
, "--signed=if-asked");
1382 strvec_push(&args
, "--atomic");
1383 if (options
.verbosity
== 0)
1384 strvec_push(&args
, "--quiet");
1385 else if (options
.verbosity
> 1)
1386 strvec_push(&args
, "--verbose");
1387 for (i
= 0; i
< options
.push_options
.nr
; i
++)
1388 strvec_pushf(&args
, "--push-option=%s",
1389 options
.push_options
.items
[i
].string
);
1390 strvec_push(&args
, options
.progress
? "--progress" : "--no-progress");
1391 for_each_string_list_item(cas_option
, &cas_options
)
1392 strvec_push(&args
, cas_option
->string
);
1393 strvec_push(&args
, url
.buf
);
1395 if (options
.force_if_includes
)
1396 strvec_push(&args
, "--force-if-includes");
1398 strvec_push(&args
, "--stdin");
1399 for (i
= 0; i
< nr_spec
; i
++)
1400 packet_buf_write(&preamble
, "%s\n", specs
[i
]);
1401 packet_buf_flush(&preamble
);
1403 memset(&rpc
, 0, sizeof(rpc
));
1404 rpc
.service_name
= "git-receive-pack",
1406 err
= rpc_service(&rpc
, heads
, args
.v
, &preamble
, &rpc_result
);
1408 write_or_die(1, rpc_result
.buf
, rpc_result
.len
);
1409 strbuf_release(&rpc_result
);
1410 strbuf_release(&preamble
);
1411 strvec_clear(&args
);
1415 static int push(int nr_spec
, const char **specs
)
1417 struct discovery
*heads
= discover_refs("git-receive-pack", 1);
1420 if (heads
->proto_git
)
1421 ret
= push_git(heads
, nr_spec
, specs
);
1423 ret
= push_dav(nr_spec
, specs
);
1424 free_discovery(heads
);
1428 static void parse_push(struct strbuf
*buf
)
1430 struct strvec specs
= STRVEC_INIT
;
1435 if (skip_prefix(buf
->buf
, "push ", &arg
))
1436 strvec_push(&specs
, arg
);
1438 die(_("http transport does not support %s"), buf
->buf
);
1441 if (strbuf_getline_lf(buf
, stdin
) == EOF
)
1447 ret
= push(specs
.nr
, specs
.v
);
1452 exit(128); /* error already reported */
1455 strvec_clear(&specs
);
1458 static int stateless_connect(const char *service_name
)
1460 struct discovery
*discover
;
1461 struct rpc_state rpc
= RPC_STATE_INIT
;
1462 struct strbuf buf
= STRBUF_INIT
;
1463 const char *accept_language
;
1466 * Run the info/refs request and see if the server supports protocol
1467 * v2. If and only if the server supports v2 can we successfully
1468 * establish a stateless connection, otherwise we need to tell the
1469 * client to fallback to using other transport helper functions to
1470 * complete their request.
1472 * The "git-upload-archive" service is a read-only operation. Fallback
1473 * to use "git-upload-pack" service to discover protocol version.
1475 if (!strcmp(service_name
, "git-upload-archive"))
1476 discover
= discover_refs("git-upload-pack", 0);
1478 discover
= discover_refs(service_name
, 0);
1479 if (discover
->version
!= protocol_v2
) {
1480 printf("fallback\n");
1484 /* Stateless Connection established */
1488 accept_language
= http_get_accept_language_header();
1489 if (accept_language
)
1490 rpc
.hdr_accept_language
= xstrfmt("%s", accept_language
);
1492 rpc
.service_name
= service_name
;
1493 rpc
.service_url
= xstrfmt("%s%s", url
.buf
, rpc
.service_name
);
1494 rpc
.hdr_content_type
= xstrfmt("Content-Type: application/x-%s-request", rpc
.service_name
);
1495 rpc
.hdr_accept
= xstrfmt("Accept: application/x-%s-result", rpc
.service_name
);
1496 if (get_protocol_http_header(discover
->version
, &buf
)) {
1497 rpc
.protocol_header
= strbuf_detach(&buf
, NULL
);
1499 rpc
.protocol_header
= NULL
;
1500 strbuf_release(&buf
);
1502 rpc
.buf
= xmalloc(http_post_buffer
);
1503 rpc
.alloc
= http_post_buffer
;
1508 rpc
.any_written
= 0;
1509 rpc
.gzip_request
= 1;
1510 rpc
.initial_buffer
= 0;
1511 rpc
.write_line_lengths
= 1;
1512 rpc
.flush_read_but_not_sent
= 0;
1515 * Dump the capability listing that we got from the server earlier
1516 * during the info/refs request. This does not work with the
1517 * "git-upload-archive" service.
1519 if (strcmp(service_name
, "git-upload-archive"))
1520 write_or_die(rpc
.in
, discover
->buf
, discover
->len
);
1522 /* Until we see EOF keep sending POSTs */
1525 enum packet_read_status status
;
1527 if (!rpc_read_from_out(&rpc
, PACKET_READ_GENTLE_ON_EOF
, &avail
,
1529 BUG("The entire rpc->buf should be larger than LARGE_PACKET_MAX");
1530 if (status
== PACKET_READ_EOF
)
1532 if (post_rpc(&rpc
, 1, status
== PACKET_READ_FLUSH
))
1533 /* We would have an err here */
1535 /* Reset the buffer for next request */
1539 free(rpc
.service_url
);
1540 free(rpc
.hdr_content_type
);
1541 free(rpc
.hdr_accept
);
1542 free(rpc
.hdr_accept_language
);
1543 free(rpc
.protocol_header
);
1545 strbuf_release(&buf
);
1550 int cmd_main(int argc
, const char **argv
)
1552 struct strbuf buf
= STRBUF_INIT
;
1556 setup_git_directory_gently(&nongit
);
1558 error(_("remote-curl: usage: git remote-curl <remote> [<url>]"));
1562 options
.verbosity
= 1;
1563 options
.progress
= !!isatty(2);
1565 string_list_init_dup(&options
.deepen_not
);
1566 string_list_init_dup(&options
.push_options
);
1569 * Just report "remote-curl" here (folding all the various aliases
1570 * ("git-remote-http", "git-remote-https", and etc.) here since they
1571 * are all just copies of the same actual executable.
1573 trace2_cmd_name("remote-curl");
1575 remote
= remote_get(argv
[1]);
1578 end_url_with_slash(&url
, argv
[2]);
1580 end_url_with_slash(&url
, remote
->url
.v
[0]);
1583 http_init(remote
, url
.buf
, 0);
1588 if (strbuf_getline_lf(&buf
, stdin
) == EOF
) {
1590 error(_("remote-curl: error reading command stream from git"));
1595 if (starts_with(buf
.buf
, "fetch ")) {
1597 setup_git_directory_gently(&nongit
);
1599 die(_("remote-curl: fetch attempted without a local repo"));
1603 } else if (!strcmp(buf
.buf
, "list") || starts_with(buf
.buf
, "list ")) {
1604 int for_push
= !!strstr(buf
.buf
+ 4, "for-push");
1605 output_refs(get_refs(for_push
));
1607 } else if (starts_with(buf
.buf
, "push ")) {
1610 } else if (skip_prefix(buf
.buf
, "option ", &arg
)) {
1611 const char *value
= strchrnul(arg
, ' ');
1612 size_t arglen
= value
- arg
;
1616 value
++; /* skip over SP */
1620 result
= set_option(arg
, arglen
, value
);
1623 else if (result
< 0)
1624 printf("error invalid value\n");
1626 printf("unsupported\n");
1629 } else if (skip_prefix(buf
.buf
, "get ", &arg
)) {
1633 } else if (!strcmp(buf
.buf
, "capabilities")) {
1634 printf("stateless-connect\n");
1639 printf("check-connectivity\n");
1640 printf("object-format\n");
1643 } else if (skip_prefix(buf
.buf
, "stateless-connect ", &arg
)) {
1644 if (!stateless_connect(arg
))
1647 error(_("remote-curl: unknown command '%s' from git"), buf
.buf
);
1656 strbuf_release(&buf
);