8000 [WIP] Shallow smart transport support by tiennou · Pull Request #4747 · libgit2/libgit2 · GitHub
[go: up one dir, main page]

Skip to content

[WIP] Shallow smart transport support #4747

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 20 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
smart: support shallow capability in smart transport
  • Loading branch information
tiennou committed Feb 3, 2019
commit a888aaa3e83f6c6d5dfcef9cd2df5aee2b49d99f
11 changes: 10 additions & 1 deletion src/transports/smart.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#define GIT_CAP_REPORT_STATUS "report-status"
#define GIT_CAP_THIN_PACK "thin-pack"
#define GIT_CAP_SYMREF "symref"
#define GIT_CAP_SHALLOW "shallow"

extern bool git_smart__ofs_delta_enabled;

Expand All @@ -47,6 +48,8 @@ typedef enum {
GIT_PKT_OK,
GIT_PKT_NG,
GIT_PKT_UNPACK,
GIT_PKT_SHALLOW,
GIT_PKT_UNSHALLOW,
} git_pkt_type;

/* Used for multi_ack and multi_ack_detailed */
Expand Down Expand Up @@ -118,6 +121,11 @@ typedef struct {
int unpack_ok;
} git_pkt_unpack;

typedef struct {
git_pkt_type type;
git_oid oid;
} git_pkt_shallow;

typedef struct transport_smart_caps {
int common:1,
ofs_delta:1,
Expand All @@ -128,7 +136,8 @@ typedef struct transport_smart_caps {
include_tag:1,
delete_refs:1,
report_status:1,
thin_pack:1;
thin_pack:1,
shallow:1;
} transp 8000 ort_smart_caps;

typedef int (*packetsize_cb)(size_t received, void *payload);
Expand Down
51 changes: 51 additions & 0 deletions src/transports/smart_pkt.c
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,50 @@ static int unpack_pkt(git_pkt **out, const char *line, size_t len)
return 0;
}

static int shallow_pkt(git_pkt **out, const char *line, size_t len)
{
git_pkt_shallow *pkt;

pkt = git__calloc(1, sizeof(git_pkt_shallow));
GIT_ERROR_CHECK_ALLOC(pkt);

pkt->type = GIT_PKT_SHALLOW;
line += 7;
len -= 7;

if (len >= GIT_OID_HEXSZ) {
git_oid_fromstr(&pkt->oid, line + 1);
line += GIT_OID_HEXSZ + 1;
len -= GIT_OID_HEXSZ + 1;
}

*out = (git_pkt *) pkt;

return 0;
}

static int unshallow_pkt(git_pkt **out, const char *line, size_t len)
{
git_pkt_shallow *pkt;

pkt = git__calloc(1, sizeof(git_pkt_shallow));
GIT_ERROR_CHECK_ALLOC(pkt);

pkt->type = GIT_PKT_UNSHALLOW;
line += 9;
len -= 9;

if (len >= GIT_OID_HEXSZ) {
git_oid_fromstr(&pkt->oid, line + 1);
line += GIT_OID_HEXSZ + 1;
len -= GIT_OID_HEXSZ + 1;
}

*out = (git_pkt *) pkt;

return 0;
}

static int parse_len(size_t *out, const char *line, size_t linelen)
{
char num[PKT_LEN_SIZE + 1];
Expand Down Expand Up @@ -489,6 +533,10 @@ int git_pkt_parse_line(
error = ng_pkt(pkt, line, len);
else if (!git__prefixncmp(line, len, "unpack"))
error = unpack_pkt(pkt, line, len);
else if (!git__prefixcmp(line, "shallow"))
error = shallow_pkt(pkt, line, len);
else if (!git__prefixcmp(line, "unshallow"))
error = unshallow_pkt(pkt, line, len);
else
error = ref_pkt(pkt, line, len);

Expand Down Expand Up @@ -554,6 +602,9 @@ static int buffer_want_with_caps(const git_remote_head *head, transport_smart_ca
if (caps->ofs_delta)
git_buf_puts(&str, GIT_CAP_OFS_DELTA " ");

if (caps->shallow)
git_buf_puts(&str, GIT_CAP_SHALLOW " ");

if (git_buf_oom(&str))
return -1;

Expand Down
6 changes: 6 additions & 0 deletions src/transports/smart_protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,12 @@ int git_smart__detect_caps(git_pkt_ref *pkt, transport_smart_caps *caps, git_vec
continue;
}

if (!git__prefixcmp(ptr, GIT_CAP_SHALLOW)) {
caps->common = caps->shallow = 1;
ptr += strlen(GIT_CAP_SHALLOW);
continue;
}

/* We don't know this capability, so skip it */
ptr = strchr(ptr, ' ');
}
Expand Down
0