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>
This commit is contained in:
parent
2f4038ab33
commit
42526b478e
@ -615,6 +615,8 @@ static void add_alternate_refs(void)
|
|||||||
|
|
||||||
int cmd_receive_pack(int argc, const char **argv, const char *prefix)
|
int cmd_receive_pack(int argc, const char **argv, const char *prefix)
|
||||||
{
|
{
|
||||||
|
int advertise_refs = 0;
|
||||||
|
int stateless_rpc = 0;
|
||||||
int i;
|
int i;
|
||||||
char *dir = NULL;
|
char *dir = NULL;
|
||||||
|
|
||||||
@ -623,7 +625,15 @@ int cmd_receive_pack(int argc, const char **argv, const char *prefix)
|
|||||||
const char *arg = *argv++;
|
const char *arg = *argv++;
|
||||||
|
|
||||||
if (*arg == '-') {
|
if (*arg == '-') {
|
||||||
/* Do flag handling here */
|
if (!strcmp(arg, "--advertise-refs")) {
|
||||||
|
advertise_refs = 1;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!strcmp(arg, "--stateless-rpc")) {
|
||||||
|
stateless_rpc = 1;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
usage(receive_pack_usage);
|
usage(receive_pack_usage);
|
||||||
}
|
}
|
||||||
if (dir)
|
if (dir)
|
||||||
@ -652,12 +662,16 @@ int cmd_receive_pack(int argc, const char **argv, const char *prefix)
|
|||||||
" report-status delete-refs ofs-delta " :
|
" report-status delete-refs ofs-delta " :
|
||||||
" report-status delete-refs ";
|
" report-status delete-refs ";
|
||||||
|
|
||||||
add_alternate_refs();
|
if (advertise_refs || !stateless_rpc) {
|
||||||
write_head_info();
|
add_alternate_refs();
|
||||||
clear_extra_refs();
|
write_head_info();
|
||||||
|
clear_extra_refs();
|
||||||
|
|
||||||
/* EOF */
|
/* EOF */
|
||||||
packet_flush(1);
|
packet_flush(1);
|
||||||
|
}
|
||||||
|
if (advertise_refs)
|
||||||
|
return 0;
|
||||||
|
|
||||||
read_head_info();
|
read_head_info();
|
||||||
if (commands) {
|
if (commands) {
|
||||||
|
@ -39,6 +39,8 @@ static unsigned int timeout;
|
|||||||
*/
|
*/
|
||||||
static int use_sideband;
|
static int use_sideband;
|
||||||
static int debug_fd;
|
static int debug_fd;
|
||||||
|
static int advertise_refs;
|
||||||
|
static int stateless_rpc;
|
||||||
|
|
||||||
static void reset_timeout(void)
|
static void reset_timeout(void)
|
||||||
{
|
{
|
||||||
@ -509,6 +511,8 @@ static int get_common_commits(void)
|
|||||||
if (!len) {
|
if (!len) {
|
||||||
if (have_obj.nr == 0 || multi_ack)
|
if (have_obj.nr == 0 || multi_ack)
|
||||||
packet_write(1, "NAK\n");
|
packet_write(1, "NAK\n");
|
||||||
|
if (stateless_rpc)
|
||||||
|
exit(0);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
strip(line, len);
|
strip(line, len);
|
||||||
@ -710,12 +714,32 @@ static int send_ref(const char *refname, const unsigned char *sha1, int flag, vo
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int mark_our_ref(const char *refname, const unsigned char *sha1, int flag, void *cb_data)
|
||||||
|
{
|
||||||
|
struct object *o = parse_object(sha1);
|
||||||
|
if (!o)
|
||||||
|
die("git upload-pack: cannot find object %s:", sha1_to_hex(sha1));
|
||||||
|
if (!(o->flags & OUR_REF)) {
|
||||||
|
o->flags |= OUR_REF;
|
||||||
|
nr_our_refs++;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static void upload_pack(void)
|
static void upload_pack(void)
|
||||||
{
|
{
|
||||||
reset_timeout();
|
if (advertise_refs || !stateless_rpc) {
|
||||||
head_ref(send_ref, NULL);
|
reset_timeout();
|
||||||
for_each_ref(send_ref, NULL);
|
head_ref(send_ref, NULL);
|
||||||
packet_flush(1);
|
for_each_ref(send_ref, NULL);
|
||||||
|
packet_flush(1);
|
||||||
|
} else {
|
||||||
|
head_ref(mark_our_ref, NULL);
|
||||||
|
for_each_ref(mark_our_ref, NULL);
|
||||||
|
}
|
||||||
|
if (advertise_refs)
|
||||||
|
return;
|
||||||
|
|
||||||
receive_needs();
|
receive_needs();
|
||||||
if (want_obj.nr) {
|
if (want_obj.nr) {
|
||||||
get_common_commits();
|
get_common_commits();
|
||||||
@ -737,6 +761,14 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
if (arg[0] != '-')
|
if (arg[0] != '-')
|
||||||
break;
|
break;
|
||||||
|
if (!strcmp(arg, "--advertise-refs")) {
|
||||||
|
advertise_refs = 1;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!strcmp(arg, "--stateless-rpc")) {
|
||||||
|
stateless_rpc = 1;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (!strcmp(arg, "--strict")) {
|
if (!strcmp(arg, "--strict")) {
|
||||||
strict = 1;
|
strict = 1;
|
||||||
continue;
|
continue;
|
||||||
|
Loading…
Reference in New Issue
Block a user