Skip to content

Commit 16b2052

Browse files
committed
smart: add a pkt type for negotiation
This lets us model the have/want lines from the client.
1 parent c83979e commit 16b2052

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

src/transports/smart.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "netops.h"
1414
#include "buffer.h"
1515
#include "push.h"
16+
#include "oid.h"
1617

1718
#define GIT_SIDE_BAND_DATA 1
1819
#define GIT_SIDE_BAND_PROGRESS 2
@@ -34,6 +35,7 @@ enum git_pkt_type {
3435
GIT_PKT_FLUSH,
3536
GIT_PKT_REF,
3637
GIT_PKT_HAVE,
38+
GIT_PKT_WANT,
3739
GIT_PKT_ACK,
3840
GIT_PKT_NAK,
3941
GIT_PKT_PACK,
@@ -129,6 +131,11 @@ typedef struct {
129131
char path[GIT_FLEX_ARRAY];
130132
} git_pkt_request;
131133

134+
typedef struct {
135+
enum git_pkt_type type;
136+
git_oid id;
137+
} git_pkt_have_want;
138+
132139
typedef struct transport_smart_caps {
133140
int common:1,
134141
ofs_delta:1,

src/transports/smart_pkt.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,29 @@ static int request_pkt(git_pkt **out, const char *line, size_t len)
351351
return 0;
352352
}
353353

354+
static int have_want_pkt(git_pkt **out, enum git_pkt_type type, const char *line, size_t len)
355+
{
356+
git_pkt_have_want *pkt;
357+
size_t min_len;
358+
359+
min_len = 5 /* 'have ' */ + GIT_OID_HEXSZ;
360+
361+
if (len < min_len) {
362+
giterr_set(GITERR_NET, "have/want pkt too short");
363+
return -1;
364+
}
365+
366+
pkt = git__malloc(sizeof(*pkt));
367+
GITERR_CHECK_ALLOC(pkt);
368+
369+
line += 5;
370+
pkt->type = type;
371+
git_oid_fromstr(&pkt->id, line);
372+
373+
*out = (git_pkt *) pkt;
374+
return 0;
375+
}
376+
354377
static int32_t parse_len(const char *line)
355378
{
356379
char num[PKT_LEN_SIZE + 1];
@@ -456,6 +479,10 @@ int git_pkt_parse_line(
456479
ret = ng_pkt(head, line, len);
457480
else if (!git__prefixcmp(line, "unpack"))
458481
ret = unpack_pkt(head, line, len);
482+
else if (!git__prefixcmp(line, "have"))
483+
ret = have_want_pkt(head, GIT_PKT_HAVE, line, len);
484+
else if (!git__prefixcmp(line, "want"))
485+
ret = have_want_pkt(head, GIT_PKT_WANT, line, len);
459486
else if (!git__prefixcmp(line, "git-upload-pack"))
460487
ret = request_pkt(head, line, len);
461488
else if (!git__prefixcmp(line, "git-receive-pack"))

0 commit comments

Comments
 (0)