Skip to content

Commit 38a81b4

Browse files
spearcegitster
authored andcommitted
receive-pack: Wrap status reports inside side-band-64k
If the client requests the side-band-64k protocol capability we now wrap the status report data inside of packets sent to band #1. This permits us to later send additional progress or informational messages down band #2. If side-band-64k was enabled, we always send a final flush packet to let the client know we are done transmitting. Signed-off-by: Shawn O. Pearce <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 185c04e commit 38a81b4

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

builtin-receive-pack.c

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "pack.h"
33
#include "refs.h"
44
#include "pkt-line.h"
5+
#include "sideband.h"
56
#include "run-command.h"
67
#include "exec_cmd.h"
78
#include "commit.h"
@@ -27,6 +28,7 @@ static int receive_unpack_limit = -1;
2728
static int transfer_unpack_limit = -1;
2829
static int unpack_limit = 100;
2930
static int report_status;
31+
static int use_sideband;
3032
static int prefer_ofs_delta = 1;
3133
static int auto_update_server_info;
3234
static int auto_gc = 1;
@@ -110,7 +112,7 @@ static int show_ref(const char *path, const unsigned char *sha1, int flag, void
110112
else
111113
packet_write(1, "%s %s%c%s%s\n",
112114
sha1_to_hex(sha1), path, 0,
113-
" report-status delete-refs",
115+
" report-status delete-refs side-band-64k",
114116
prefer_ofs_delta ? " ofs-delta" : "");
115117
sent_capabilities = 1;
116118
return 0;
@@ -466,6 +468,8 @@ static void read_head_info(void)
466468
if (reflen + 82 < len) {
467469
if (strstr(refname + reflen + 1, "report-status"))
468470
report_status = 1;
471+
if (strstr(refname + reflen + 1, "side-band-64k"))
472+
use_sideband = LARGE_PACKET_MAX;
469473
}
470474
cmd = xmalloc(sizeof(struct command) + len - 80);
471475
hashcpy(cmd->old_sha1, old_sha1);
@@ -565,17 +569,25 @@ static const char *unpack(void)
565569
static void report(const char *unpack_status)
566570
{
567571
struct command *cmd;
568-
packet_write(1, "unpack %s\n",
569-
unpack_status ? unpack_status : "ok");
572+
struct strbuf buf = STRBUF_INIT;
573+
574+
packet_buf_write(&buf, "unpack %s\n",
575+
unpack_status ? unpack_status : "ok");
570576
for (cmd = commands; cmd; cmd = cmd->next) {
571577
if (!cmd->error_string)
572-
packet_write(1, "ok %s\n",
573-
cmd->ref_name);
578+
packet_buf_write(&buf, "ok %s\n",
579+
cmd->ref_name);
574580
else
575-
packet_write(1, "ng %s %s\n",
576-
cmd->ref_name, cmd->error_string);
581+
packet_buf_write(&buf, "ng %s %s\n",
582+
cmd->ref_name, cmd->error_string);
577583
}
578-
packet_flush(1);
584+
packet_buf_flush(&buf);
585+
586+
if (use_sideband)
587+
send_sideband(1, 1, buf.buf, buf.len, use_sideband);
588+
else
589+
safe_write(1, buf.buf, buf.len);
590+
strbuf_release(&buf);
579591
}
580592

581593
static int delete_only(struct command *cmd)
@@ -705,5 +717,7 @@ int cmd_receive_pack(int argc, const char **argv, const char *prefix)
705717
if (auto_update_server_info)
706718
update_server_info(0);
707719
}
720+
if (use_sideband)
721+
packet_flush(1);
708722
return 0;
709723
}

0 commit comments

Comments
 (0)