@matheusbsbs / matheus-bagliano / commits / 42526b478e
Fork 0

Add stateless RPC options to upload-pack, receive-pack

When --stateless-rpc is passed as a command line parameter to upload-pack or receive-pack the programs now assume they may perform only a single read-write cycle with stdin and stdout. This fits with the HTTP POST request processing model where a program may read the request, write a response, and must exit. When --advertise-refs is passed as a command line parameter only the initial ref advertisement is output, and the program exits immediately. This fits with the HTTP GET request model, where no request content is received but a response must be produced. HTTP headers and/or environment are not processed here, but instead are assumed to be handled by the program invoking either service backend. Signed-off-by: Shawn O. Pearce <spearce@spearce.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Shawn O. Pearce committed Oct 30, 2009 at 17:47 UTC 42526b478e369d7e8c9a95186ad87fae9930eea5
2 files changed +56 -10
builtin-receive-pack.c
+20 -6
@@ -615,6 +615,8 @@ static void add_alternate_refs(void)
615
616 int cmd_receive_pack(int argc, const char **argv, const char *prefix)
617 {
618 + int advertise_refs = 0;
619 + int stateless_rpc = 0;
620 int i;
621 char *dir = NULL;
622
@@ -623,7 +625,15 @@ int cmd_receive_pack(int argc, const char **argv, const char *prefix)
625 const char *arg = *argv++;
626
627 if (*arg == '-') {
626 - /* Do flag handling here */
628 + if (!strcmp(arg, "--advertise-refs")) {
629 + advertise_refs = 1;
630 + continue;
631 + }
632 + if (!strcmp(arg, "--stateless-rpc")) {
633 + stateless_rpc = 1;
634 + continue;
635 + }
636 +
637 usage(receive_pack_usage);
638 }
639 if (dir)
@@ -652,12 +662,16 @@ int cmd_receive_pack(int argc, const char **argv, const char *prefix)
662 " report-status delete-refs ofs-delta " :
663 " report-status delete-refs ";
664
655 - add_alternate_refs();
656 - write_head_info();
657 - clear_extra_refs();
665 + if (advertise_refs || !stateless_rpc) {
666 + add_alternate_refs();
667 + write_head_info();
668 + clear_extra_refs();
669
659 - /* EOF */
660 - packet_flush(1);
670 + /* EOF */
671 + packet_flush(1);
672 + }
673 + if (advertise_refs)
674 + return 0;
675
676 read_head_info();
677 if (commands) {
upload-pack.c
+36 -4
@@ -39,6 +39,8 @@ static unsigned int timeout;
39 */
40 static int use_sideband;
41 static int debug_fd;
42 +static int advertise_refs;
43 +static int stateless_rpc;
44
45 static void reset_timeout(void)
46 {
@@ -509,6 +511,8 @@ static int get_common_commits(void)
511 if (!len) {
512 if (have_obj.nr == 0 || multi_ack)
513 packet_write(1, "NAK\n");
514 + if (stateless_rpc)
515 + exit(0);
516 continue;
517 }
518 strip(line, len);
@@ -710,12 +714,32 @@ static int send_ref(const char *refname, const unsigned char *sha1, int flag, vo
714 return 0;
715 }
716
717 +static int mark_our_ref(const char *refname, const unsigned char *sha1, int flag, void *cb_data)
718 +{
719 + struct object *o = parse_object(sha1);
720 + if (!o)
721 + die("git upload-pack: cannot find object %s:", sha1_to_hex(sha1));
722 + if (!(o->flags & OUR_REF)) {
723 + o->flags |= OUR_REF;
724 + nr_our_refs++;
725 + }
726 + return 0;
727 +}
728 +
729 static void upload_pack(void)
730 {
715 - reset_timeout();
716 - head_ref(send_ref, NULL);
717 - for_each_ref(send_ref, NULL);
718 - packet_flush(1);
731 + if (advertise_refs || !stateless_rpc) {
732 + reset_timeout();
733 + head_ref(send_ref, NULL);
734 + for_each_ref(send_ref, NULL);
735 + packet_flush(1);
736 + } else {
737 + head_ref(mark_our_ref, NULL);
738 + for_each_ref(mark_our_ref, NULL);
739 + }
740 + if (advertise_refs)
741 + return;
742 +
743 receive_needs();
744 if (want_obj.nr) {
745 get_common_commits();
@@ -737,6 +761,14 @@ int main(int argc, char **argv)
761
762 if (arg[0] != '-')
763 break;
764 + if (!strcmp(arg, "--advertise-refs")) {
765 + advertise_refs = 1;
766 + continue;
767 + }
768 + if (!strcmp(arg, "--stateless-rpc")) {
769 + stateless_rpc = 1;
770 + continue;
771 + }
772 if (!strcmp(arg, "--strict")) {
773 strict = 1;
774 continue;