Skip to content

Commit a4cfd41

Browse files
bmwillgitster
authored andcommitted
pkt-line: add delim packet support
One of the design goals of protocol-v2 is to improve the semantics of flush packets. Currently in protocol-v1, flush packets are used both to indicate a break in a list of packet lines as well as an indication that one side has finished speaking. This makes it particularly difficult to implement proxies as a proxy would need to completely understand git protocol instead of simply looking for a flush packet. To do this, introduce the special deliminator packet '0001'. A delim packet can then be used as a deliminator between lists of packet lines while flush packets can be reserved to indicate the end of a response. Documentation for how this packet will be used in protocol v2 will included in a future patch. Signed-off-by: Brandon Williams <bmwill@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 77dabc1 commit a4cfd41

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

pkt-line.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,12 @@ void packet_flush(int fd)
9191
write_or_die(fd, "0000", 4);
9292
}
9393

94+
void packet_delim(int fd)
95+
{
96+
packet_trace("0001", 4, 1);
97+
write_or_die(fd, "0001", 4);
98+
}
99+
94100
int packet_flush_gently(int fd)
95101
{
96102
packet_trace("0000", 4, 1);
@@ -105,6 +111,12 @@ void packet_buf_flush(struct strbuf *buf)
105111
strbuf_add(buf, "0000", 4);
106112
}
107113

114+
void packet_buf_delim(struct strbuf *buf)
115+
{
116+
packet_trace("0001", 4, 1);
117+
strbuf_add(buf, "0001", 4);
118+
}
119+
108120
static void set_packet_header(char *buf, const int size)
109121
{
110122
static char hexchar[] = "0123456789abcdef";
@@ -301,6 +313,10 @@ enum packet_read_status packet_read_with_status(int fd, char **src_buffer,
301313
packet_trace("0000", 4, 0);
302314
*pktlen = 0;
303315
return PACKET_READ_FLUSH;
316+
} else if (len == 1) {
317+
packet_trace("0001", 4, 0);
318+
*pktlen = 0;
319+
return PACKET_READ_DELIM;
304320
} else if (len < 4) {
305321
die("protocol error: bad line length %d", len);
306322
}

pkt-line.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@
2020
* side can't, we stay with pure read/write interfaces.
2121
*/
2222
void packet_flush(int fd);
23+
void packet_delim(int fd);
2324
void packet_write_fmt(int fd, const char *fmt, ...) __attribute__((format (printf, 2, 3)));
2425
void packet_buf_flush(struct strbuf *buf);
26+
void packet_buf_delim(struct strbuf *buf);
2527
void packet_write(int fd_out, const char *buf, size_t size);
2628
void packet_buf_write(struct strbuf *buf, const char *fmt, ...) __attribute__((format (printf, 2, 3)));
2729
int packet_flush_gently(int fd);
@@ -75,6 +77,7 @@ enum packet_read_status {
7577
PACKET_READ_EOF,
7678
PACKET_READ_NORMAL,
7779
PACKET_READ_FLUSH,
80+
PACKET_READ_DELIM,
7881
};
7982
enum packet_read_status packet_read_with_status(int fd, char **src_buffer,
8083
size_t *src_len, char *buffer,

0 commit comments

Comments
 (0)