7 #include "run-command.h"
10 #include "argv-array.h"
11 #include "credential.h"
13 static struct remote
*remote
;
14 /* always ends with a trailing slash */
15 static struct strbuf url
= STRBUF_INIT
;
20 unsigned progress
: 1,
25 static struct options options
;
27 static int set_option(const char *name
, const char *value
)
29 if (!strcmp(name
, "verbosity")) {
31 int v
= strtol(value
, &end
, 10);
32 if (value
== end
|| *end
)
34 options
.verbosity
= v
;
37 else if (!strcmp(name
, "progress")) {
38 if (!strcmp(value
, "true"))
40 else if (!strcmp(value
, "false"))
46 else if (!strcmp(name
, "depth")) {
48 unsigned long v
= strtoul(value
, &end
, 10);
49 if (value
== end
|| *end
)
54 else if (!strcmp(name
, "followtags")) {
55 if (!strcmp(value
, "true"))
56 options
.followtags
= 1;
57 else if (!strcmp(value
, "false"))
58 options
.followtags
= 0;
63 else if (!strcmp(name
, "dry-run")) {
64 if (!strcmp(value
, "true"))
66 else if (!strcmp(value
, "false"))
73 return 1 /* unsupported */;
83 unsigned proto_git
: 1;
85 static struct discovery
*last_discovery
;
87 static struct ref
*parse_git_refs(struct discovery
*heads
, int for_push
)
89 struct ref
*list
= NULL
;
90 get_remote_heads(-1, heads
->buf
, heads
->len
, &list
,
91 for_push
? REF_NORMAL
: 0, NULL
);
95 static struct ref
*parse_info_refs(struct discovery
*heads
)
97 char *data
, *start
, *mid
;
101 struct ref
*refs
= NULL
;
102 struct ref
*ref
= NULL
;
103 struct ref
*last_ref
= NULL
;
108 while (i
< heads
->len
) {
114 if (data
[i
] == '\n') {
115 if (mid
- start
!= 40)
116 die("%sinfo/refs not valid: is this a git repository?",
120 ref
= xmalloc(sizeof(struct ref
) +
121 strlen(ref_name
) + 1);
122 memset(ref
, 0, sizeof(struct ref
));
123 strcpy(ref
->name
, ref_name
);
124 get_sha1_hex(start
, ref
->old_sha1
);
128 last_ref
->next
= ref
;
135 ref
= alloc_ref("HEAD");
136 if (!http_fetch_ref(url
.buf
, ref
) &&
137 !resolve_remote_symref(ref
, refs
)) {
147 static void free_discovery(struct discovery
*d
)
150 if (d
== last_discovery
)
151 last_discovery
= NULL
;
158 static int show_http_message(struct strbuf
*type
, struct strbuf
*msg
)
163 * We only show text/plain parts, as other types are likely
164 * to be ugly to look at on the user's terminal.
166 * TODO should handle "; charset=XXX", and re-encode into
169 if (strcasecmp(type
->buf
, "text/plain"))
178 eol
= strchrnul(p
, '\n');
179 fprintf(stderr
, "remote: %.*s\n", (int)(eol
- p
), p
);
185 static struct discovery
* discover_refs(const char *service
, int for_push
)
187 struct strbuf exp
= STRBUF_INIT
;
188 struct strbuf type
= STRBUF_INIT
;
189 struct strbuf buffer
= STRBUF_INIT
;
190 struct strbuf refs_url
= STRBUF_INIT
;
191 struct strbuf effective_url
= STRBUF_INIT
;
192 struct discovery
*last
= last_discovery
;
193 int http_ret
, maybe_smart
= 0;
194 struct http_get_options options
;
196 if (last
&& !strcmp(service
, last
->service
))
198 free_discovery(last
);
200 strbuf_addf(&refs_url
, "%sinfo/refs", url
.buf
);
201 if ((!prefixcmp(url
.buf
, "http://") || !prefixcmp(url
.buf
, "https://")) &&
202 git_env_bool("GIT_SMART_HTTP", 1)) {
204 if (!strchr(url
.buf
, '?'))
205 strbuf_addch(&refs_url
, '?');
207 strbuf_addch(&refs_url
, '&');
208 strbuf_addf(&refs_url
, "service=%s", service
);
211 memset(&options
, 0, sizeof(options
));
212 options
.content_type
= &type
;
213 options
.effective_url
= &effective_url
;
214 options
.base_url
= &url
;
215 options
.no_cache
= 1;
216 options
.keep_error
= 1;
218 http_ret
= http_get_strbuf(refs_url
.buf
, &buffer
, &options
);
222 case HTTP_MISSING_TARGET
:
223 show_http_message(&type
, &buffer
);
224 die("repository '%s' not found", url
.buf
);
226 show_http_message(&type
, &buffer
);
227 die("Authentication failed for '%s'", url
.buf
);
229 show_http_message(&type
, &buffer
);
230 die("unable to access '%s': %s", url
.buf
, curl_errorstr
);
233 last
= xcalloc(1, sizeof(*last_discovery
));
234 last
->service
= service
;
235 last
->buf_alloc
= strbuf_detach(&buffer
, &last
->len
);
236 last
->buf
= last
->buf_alloc
;
238 strbuf_addf(&exp
, "application/x-%s-advertisement", service
);
240 (5 <= last
->len
&& last
->buf
[4] == '#') &&
241 !strbuf_cmp(&exp
, &type
)) {
245 * smart HTTP response; validate that the service
246 * pkt-line matches our request.
248 line
= packet_read_line_buf(&last
->buf
, &last
->len
, NULL
);
251 strbuf_addf(&exp
, "# service=%s", service
);
252 if (strcmp(line
, exp
.buf
))
253 die("invalid server response; got '%s'", line
);
254 strbuf_release(&exp
);
256 /* The header can include additional metadata lines, up
257 * until a packet flush marker. Ignore these now, but
258 * in the future we might start to scan them.
260 while (packet_read_line_buf(&last
->buf
, &last
->len
, NULL
))
267 last
->refs
= parse_git_refs(last
, for_push
);
269 last
->refs
= parse_info_refs(last
);
271 strbuf_release(&refs_url
);
272 strbuf_release(&exp
);
273 strbuf_release(&type
);
274 strbuf_release(&effective_url
);
275 strbuf_release(&buffer
);
276 last_discovery
= last
;
280 static struct ref
*get_refs(int for_push
)
282 struct discovery
*heads
;
285 heads
= discover_refs("git-receive-pack", for_push
);
287 heads
= discover_refs("git-upload-pack", for_push
);
292 static void output_refs(struct ref
*refs
)
295 for (posn
= refs
; posn
; posn
= posn
->next
) {
297 printf("@%s %s\n", posn
->symref
, posn
->name
);
299 printf("%s %s\n", sha1_to_hex(posn
->old_sha1
), posn
->name
);
306 const char *service_name
;
308 struct strbuf
*stdin_preamble
;
310 char *hdr_content_type
;
318 struct strbuf result
;
319 unsigned gzip_request
: 1;
320 unsigned initial_buffer
: 1;
323 static size_t rpc_out(void *ptr
, size_t eltsize
,
324 size_t nmemb
, void *buffer_
)
326 size_t max
= eltsize
* nmemb
;
327 struct rpc_state
*rpc
= buffer_
;
328 size_t avail
= rpc
->len
- rpc
->pos
;
331 rpc
->initial_buffer
= 0;
332 avail
= packet_read(rpc
->out
, NULL
, NULL
, rpc
->buf
, rpc
->alloc
, 0);
341 memcpy(ptr
, rpc
->buf
+ rpc
->pos
, avail
);
346 #ifndef NO_CURL_IOCTL
347 static curlioerr
rpc_ioctl(CURL
*handle
, int cmd
, void *clientp
)
349 struct rpc_state
*rpc
= clientp
;
355 case CURLIOCMD_RESTARTREAD
:
356 if (rpc
->initial_buffer
) {
360 fprintf(stderr
, "Unable to rewind rpc post data - try increasing http.postBuffer\n");
361 return CURLIOE_FAILRESTART
;
364 return CURLIOE_UNKNOWNCMD
;
369 static size_t rpc_in(char *ptr
, size_t eltsize
,
370 size_t nmemb
, void *buffer_
)
372 size_t size
= eltsize
* nmemb
;
373 struct rpc_state
*rpc
= buffer_
;
374 write_or_die(rpc
->in
, ptr
, size
);
378 static int run_slot(struct active_request_slot
*slot
)
381 struct slot_results results
;
383 slot
->results
= &results
;
384 slot
->curl_result
= curl_easy_perform(slot
->curl
);
385 finish_active_slot(slot
);
387 err
= handle_curl_result(&results
);
388 if (err
!= HTTP_OK
&& err
!= HTTP_REAUTH
) {
389 error("RPC failed; result=%d, HTTP code = %ld",
390 results
.curl_result
, results
.http_code
);
396 static int probe_rpc(struct rpc_state
*rpc
)
398 struct active_request_slot
*slot
;
399 struct curl_slist
*headers
= NULL
;
400 struct strbuf buf
= STRBUF_INIT
;
403 slot
= get_active_slot();
405 headers
= curl_slist_append(headers
, rpc
->hdr_content_type
);
406 headers
= curl_slist_append(headers
, rpc
->hdr_accept
);
408 curl_easy_setopt(slot
->curl
, CURLOPT_NOBODY
, 0);
409 curl_easy_setopt(slot
->curl
, CURLOPT_POST
, 1);
410 curl_easy_setopt(slot
->curl
, CURLOPT_URL
, rpc
->service_url
);
411 curl_easy_setopt(slot
->curl
, CURLOPT_ENCODING
, NULL
);
412 curl_easy_setopt(slot
->curl
, CURLOPT_POSTFIELDS
, "0000");
413 curl_easy_setopt(slot
->curl
, CURLOPT_POSTFIELDSIZE
, 4);
414 curl_easy_setopt(slot
->curl
, CURLOPT_HTTPHEADER
, headers
);
415 curl_easy_setopt(slot
->curl
, CURLOPT_WRITEFUNCTION
, fwrite_buffer
);
416 curl_easy_setopt(slot
->curl
, CURLOPT_FILE
, &buf
);
418 err
= run_slot(slot
);
420 curl_slist_free_all(headers
);
421 strbuf_release(&buf
);
425 static int post_rpc(struct rpc_state
*rpc
)
427 struct active_request_slot
*slot
;
428 struct curl_slist
*headers
= NULL
;
429 int use_gzip
= rpc
->gzip_request
;
430 char *gzip_body
= NULL
;
431 size_t gzip_size
= 0;
432 int err
, large_request
= 0;
434 /* Try to load the entire request, if we can fit it into the
435 * allocated buffer space we can use HTTP/1.0 and avoid the
436 * chunked encoding mess.
439 size_t left
= rpc
->alloc
- rpc
->len
;
440 char *buf
= rpc
->buf
+ rpc
->len
;
443 if (left
< LARGE_PACKET_MAX
) {
449 n
= packet_read(rpc
->out
, NULL
, NULL
, buf
, left
, 0);
457 err
= probe_rpc(rpc
);
458 if (err
== HTTP_REAUTH
)
459 credential_fill(&http_auth
);
460 } while (err
== HTTP_REAUTH
);
465 headers
= curl_slist_append(headers
, rpc
->hdr_content_type
);
466 headers
= curl_slist_append(headers
, rpc
->hdr_accept
);
467 headers
= curl_slist_append(headers
, "Expect:");
470 slot
= get_active_slot();
472 curl_easy_setopt(slot
->curl
, CURLOPT_NOBODY
, 0);
473 curl_easy_setopt(slot
->curl
, CURLOPT_POST
, 1);
474 curl_easy_setopt(slot
->curl
, CURLOPT_URL
, rpc
->service_url
);
475 curl_easy_setopt(slot
->curl
, CURLOPT_ENCODING
, "gzip");
478 /* The request body is large and the size cannot be predicted.
479 * We must use chunked encoding to send it.
481 headers
= curl_slist_append(headers
, "Transfer-Encoding: chunked");
482 rpc
->initial_buffer
= 1;
483 curl_easy_setopt(slot
->curl
, CURLOPT_READFUNCTION
, rpc_out
);
484 curl_easy_setopt(slot
->curl
, CURLOPT_INFILE
, rpc
);
485 #ifndef NO_CURL_IOCTL
486 curl_easy_setopt(slot
->curl
, CURLOPT_IOCTLFUNCTION
, rpc_ioctl
);
487 curl_easy_setopt(slot
->curl
, CURLOPT_IOCTLDATA
, rpc
);
489 if (options
.verbosity
> 1) {
490 fprintf(stderr
, "POST %s (chunked)\n", rpc
->service_name
);
494 } else if (gzip_body
) {
496 * If we are looping to retry authentication, then the previous
497 * run will have set up the headers and gzip buffer already,
498 * and we just need to send it.
500 curl_easy_setopt(slot
->curl
, CURLOPT_POSTFIELDS
, gzip_body
);
501 curl_easy_setopt(slot
->curl
, CURLOPT_POSTFIELDSIZE
, gzip_size
);
503 } else if (use_gzip
&& 1024 < rpc
->len
) {
504 /* The client backend isn't giving us compressed data so
505 * we can try to deflate it ourselves, this may save on.
511 memset(&stream
, 0, sizeof(stream
));
512 git_deflate_init_gzip(&stream
, Z_BEST_COMPRESSION
);
513 gzip_size
= git_deflate_bound(&stream
, rpc
->len
);
514 gzip_body
= xmalloc(gzip_size
);
516 stream
.next_in
= (unsigned char *)rpc
->buf
;
517 stream
.avail_in
= rpc
->len
;
518 stream
.next_out
= (unsigned char *)gzip_body
;
519 stream
.avail_out
= gzip_size
;
521 ret
= git_deflate(&stream
, Z_FINISH
);
522 if (ret
!= Z_STREAM_END
)
523 die("cannot deflate request; zlib deflate error %d", ret
);
525 ret
= git_deflate_end_gently(&stream
);
527 die("cannot deflate request; zlib end error %d", ret
);
529 gzip_size
= stream
.total_out
;
531 headers
= curl_slist_append(headers
, "Content-Encoding: gzip");
532 curl_easy_setopt(slot
->curl
, CURLOPT_POSTFIELDS
, gzip_body
);
533 curl_easy_setopt(slot
->curl
, CURLOPT_POSTFIELDSIZE
, gzip_size
);
535 if (options
.verbosity
> 1) {
536 fprintf(stderr
, "POST %s (gzip %lu to %lu bytes)\n",
538 (unsigned long)rpc
->len
, (unsigned long)gzip_size
);
542 /* We know the complete request size in advance, use the
543 * more normal Content-Length approach.
545 curl_easy_setopt(slot
->curl
, CURLOPT_POSTFIELDS
, rpc
->buf
);
546 curl_easy_setopt(slot
->curl
, CURLOPT_POSTFIELDSIZE
, rpc
->len
);
547 if (options
.verbosity
> 1) {
548 fprintf(stderr
, "POST %s (%lu bytes)\n",
549 rpc
->service_name
, (unsigned long)rpc
->len
);
554 curl_easy_setopt(slot
->curl
, CURLOPT_HTTPHEADER
, headers
);
555 curl_easy_setopt(slot
->curl
, CURLOPT_WRITEFUNCTION
, rpc_in
);
556 curl_easy_setopt(slot
->curl
, CURLOPT_FILE
, rpc
);
558 err
= run_slot(slot
);
559 if (err
== HTTP_REAUTH
&& !large_request
) {
560 credential_fill(&http_auth
);
566 curl_slist_free_all(headers
);
571 static int rpc_service(struct rpc_state
*rpc
, struct discovery
*heads
)
573 const char *svc
= rpc
->service_name
;
574 struct strbuf buf
= STRBUF_INIT
;
575 struct strbuf
*preamble
= rpc
->stdin_preamble
;
576 struct child_process client
;
579 memset(&client
, 0, sizeof(client
));
583 client
.argv
= rpc
->argv
;
584 if (start_command(&client
))
587 write_or_die(client
.in
, preamble
->buf
, preamble
->len
);
589 write_or_die(client
.in
, heads
->buf
, heads
->len
);
591 rpc
->alloc
= http_post_buffer
;
592 rpc
->buf
= xmalloc(rpc
->alloc
);
594 rpc
->out
= client
.out
;
595 strbuf_init(&rpc
->result
, 0);
597 strbuf_addf(&buf
, "%s%s", url
.buf
, svc
);
598 rpc
->service_url
= strbuf_detach(&buf
, NULL
);
600 strbuf_addf(&buf
, "Content-Type: application/x-%s-request", svc
);
601 rpc
->hdr_content_type
= strbuf_detach(&buf
, NULL
);
603 strbuf_addf(&buf
, "Accept: application/x-%s-result", svc
);
604 rpc
->hdr_accept
= strbuf_detach(&buf
, NULL
);
607 int n
= packet_read(rpc
->out
, NULL
, NULL
, rpc
->buf
, rpc
->alloc
, 0);
612 err
|= post_rpc(rpc
);
618 strbuf_read(&rpc
->result
, client
.out
, 0);
622 if (xread(client
.out
, buf
, sizeof(buf
)) <= 0)
629 err
|= finish_command(&client
);
630 free(rpc
->service_url
);
631 free(rpc
->hdr_content_type
);
632 free(rpc
->hdr_accept
);
634 strbuf_release(&buf
);
638 static int fetch_dumb(int nr_heads
, struct ref
**to_fetch
)
640 struct walker
*walker
;
641 char **targets
= xmalloc(nr_heads
* sizeof(char*));
645 die("dumb http transport does not support --depth");
646 for (i
= 0; i
< nr_heads
; i
++)
647 targets
[i
] = xstrdup(sha1_to_hex(to_fetch
[i
]->old_sha1
));
649 walker
= get_http_walker(url
.buf
);
651 walker
->get_tree
= 1;
652 walker
->get_history
= 1;
653 walker
->get_verbosely
= options
.verbosity
>= 3;
654 walker
->get_recover
= 0;
655 ret
= walker_fetch(walker
, nr_heads
, targets
, NULL
, NULL
);
658 for (i
= 0; i
< nr_heads
; i
++)
662 return ret
? error("Fetch failed.") : 0;
665 static int fetch_git(struct discovery
*heads
,
666 int nr_heads
, struct ref
**to_fetch
)
668 struct rpc_state rpc
;
669 struct strbuf preamble
= STRBUF_INIT
;
670 char *depth_arg
= NULL
;
671 int argc
= 0, i
, err
;
672 const char *argv
[15];
674 argv
[argc
++] = "fetch-pack";
675 argv
[argc
++] = "--stateless-rpc";
676 argv
[argc
++] = "--stdin";
677 argv
[argc
++] = "--lock-pack";
678 if (options
.followtags
)
679 argv
[argc
++] = "--include-tag";
681 argv
[argc
++] = "--thin";
682 if (options
.verbosity
>= 3) {
686 if (!options
.progress
)
687 argv
[argc
++] = "--no-progress";
689 struct strbuf buf
= STRBUF_INIT
;
690 strbuf_addf(&buf
, "--depth=%lu", options
.depth
);
691 depth_arg
= strbuf_detach(&buf
, NULL
);
692 argv
[argc
++] = depth_arg
;
694 argv
[argc
++] = url
.buf
;
697 for (i
= 0; i
< nr_heads
; i
++) {
698 struct ref
*ref
= to_fetch
[i
];
699 if (!ref
->name
|| !*ref
->name
)
700 die("cannot fetch by sha1 over smart http");
701 packet_buf_write(&preamble
, "%s\n", ref
->name
);
703 packet_buf_flush(&preamble
);
705 memset(&rpc
, 0, sizeof(rpc
));
706 rpc
.service_name
= "git-upload-pack",
708 rpc
.stdin_preamble
= &preamble
;
709 rpc
.gzip_request
= 1;
711 err
= rpc_service(&rpc
, heads
);
713 write_or_die(1, rpc
.result
.buf
, rpc
.result
.len
);
714 strbuf_release(&rpc
.result
);
715 strbuf_release(&preamble
);
720 static int fetch(int nr_heads
, struct ref
**to_fetch
)
722 struct discovery
*d
= discover_refs("git-upload-pack", 0);
724 return fetch_git(d
, nr_heads
, to_fetch
);
726 return fetch_dumb(nr_heads
, to_fetch
);
729 static void parse_fetch(struct strbuf
*buf
)
731 struct ref
**to_fetch
= NULL
;
732 struct ref
*list_head
= NULL
;
733 struct ref
**list
= &list_head
;
734 int alloc_heads
= 0, nr_heads
= 0;
737 if (!prefixcmp(buf
->buf
, "fetch ")) {
738 char *p
= buf
->buf
+ strlen("fetch ");
741 unsigned char old_sha1
[20];
743 if (strlen(p
) < 40 || get_sha1_hex(p
, old_sha1
))
744 die("protocol error: expected sha/ref, got %s'", p
);
750 die("protocol error: expected sha/ref, got %s'", p
);
752 ref
= alloc_ref(name
);
753 hashcpy(ref
->old_sha1
, old_sha1
);
758 ALLOC_GROW(to_fetch
, nr_heads
+ 1, alloc_heads
);
759 to_fetch
[nr_heads
++] = ref
;
762 die("http transport does not support %s", buf
->buf
);
765 if (strbuf_getline(buf
, stdin
, '\n') == EOF
)
771 if (fetch(nr_heads
, to_fetch
))
772 exit(128); /* error already reported */
773 free_refs(list_head
);
781 static int push_dav(int nr_spec
, char **specs
)
783 const char **argv
= xmalloc((10 + nr_spec
) * sizeof(char*));
786 argv
[argc
++] = "http-push";
787 argv
[argc
++] = "--helper-status";
789 argv
[argc
++] = "--dry-run";
790 if (options
.verbosity
> 1)
791 argv
[argc
++] = "--verbose";
792 argv
[argc
++] = url
.buf
;
793 for (i
= 0; i
< nr_spec
; i
++)
794 argv
[argc
++] = specs
[i
];
797 if (run_command_v_opt(argv
, RUN_GIT_CMD
))
798 die("git-%s failed", argv
[0]);
803 static int push_git(struct discovery
*heads
, int nr_spec
, char **specs
)
805 struct rpc_state rpc
;
807 struct argv_array args
;
809 argv_array_init(&args
);
810 argv_array_pushl(&args
, "send-pack", "--stateless-rpc", "--helper-status",
814 argv_array_push(&args
, "--thin");
816 argv_array_push(&args
, "--dry-run");
817 if (options
.verbosity
== 0)
818 argv_array_push(&args
, "--quiet");
819 else if (options
.verbosity
> 1)
820 argv_array_push(&args
, "--verbose");
821 argv_array_push(&args
, options
.progress
? "--progress" : "--no-progress");
822 argv_array_push(&args
, url
.buf
);
823 for (i
= 0; i
< nr_spec
; i
++)
824 argv_array_push(&args
, specs
[i
]);
826 memset(&rpc
, 0, sizeof(rpc
));
827 rpc
.service_name
= "git-receive-pack",
828 rpc
.argv
= args
.argv
;
830 err
= rpc_service(&rpc
, heads
);
832 write_or_die(1, rpc
.result
.buf
, rpc
.result
.len
);
833 strbuf_release(&rpc
.result
);
834 argv_array_clear(&args
);
838 static int push(int nr_spec
, char **specs
)
840 struct discovery
*heads
= discover_refs("git-receive-pack", 1);
843 if (heads
->proto_git
)
844 ret
= push_git(heads
, nr_spec
, specs
);
846 ret
= push_dav(nr_spec
, specs
);
847 free_discovery(heads
);
851 static void parse_push(struct strbuf
*buf
)
854 int alloc_spec
= 0, nr_spec
= 0, i
, ret
;
857 if (!prefixcmp(buf
->buf
, "push ")) {
858 ALLOC_GROW(specs
, nr_spec
+ 1, alloc_spec
);
859 specs
[nr_spec
++] = xstrdup(buf
->buf
+ 5);
862 die("http transport does not support %s", buf
->buf
);
865 if (strbuf_getline(buf
, stdin
, '\n') == EOF
)
871 ret
= push(nr_spec
, specs
);
876 exit(128); /* error already reported */
879 for (i
= 0; i
< nr_spec
; i
++)
884 int main(int argc
, const char **argv
)
886 struct strbuf buf
= STRBUF_INIT
;
889 git_extract_argv0_path(argv
[0]);
890 setup_git_directory_gently(&nongit
);
892 fprintf(stderr
, "Remote needed\n");
896 options
.verbosity
= 1;
897 options
.progress
= !!isatty(2);
900 remote
= remote_get(argv
[1]);
903 end_url_with_slash(&url
, argv
[2]);
905 end_url_with_slash(&url
, remote
->url
[0]);
908 http_init(remote
, url
.buf
, 0);
911 if (strbuf_getline(&buf
, stdin
, '\n') == EOF
) {
913 fprintf(stderr
, "Error reading command stream\n");
915 fprintf(stderr
, "Unexpected end of command stream\n");
920 if (!prefixcmp(buf
.buf
, "fetch ")) {
922 die("Fetch attempted without a local repo");
925 } else if (!strcmp(buf
.buf
, "list") || !prefixcmp(buf
.buf
, "list ")) {
926 int for_push
= !!strstr(buf
.buf
+ 4, "for-push");
927 output_refs(get_refs(for_push
));
929 } else if (!prefixcmp(buf
.buf
, "push ")) {
932 } else if (!prefixcmp(buf
.buf
, "option ")) {
933 char *name
= buf
.buf
+ strlen("option ");
934 char *value
= strchr(name
, ' ');
942 result
= set_option(name
, value
);
946 printf("error invalid value\n");
948 printf("unsupported\n");
951 } else if (!strcmp(buf
.buf
, "capabilities")) {
958 fprintf(stderr
, "Unknown command '%s'\n", buf
.buf
);