mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-09 15:00:04 +00:00
pkt-line: read capabilities
Try to read the server capabilities and add them to the git_pkt_ref struct. Signed-off-by: Carlos Martín Nieto <carlos@cmartin.tk>
This commit is contained in:
parent
b31803f310
commit
8b9e8de5ce
@ -48,4 +48,5 @@ struct git_pkt_cmd {
|
|||||||
struct git_pkt_ref {
|
struct git_pkt_ref {
|
||||||
enum git_pkt_type type;
|
enum git_pkt_type type;
|
||||||
git_remote_head head;
|
git_remote_head head;
|
||||||
|
char *capabilities;
|
||||||
};
|
};
|
||||||
|
21
src/pkt.c
21
src/pkt.c
@ -57,6 +57,7 @@ int ref_pkt(git_pkt **out, const char *line, size_t len)
|
|||||||
if (pkt == NULL)
|
if (pkt == NULL)
|
||||||
return GIT_ENOMEM;
|
return GIT_ENOMEM;
|
||||||
|
|
||||||
|
memset(pkt, 0x0, sizeof(git_pkt_ref));
|
||||||
pkt->type = GIT_PKT_REF;
|
pkt->type = GIT_PKT_REF;
|
||||||
error = git_oid_fromstr(&pkt->head.oid, line);
|
error = git_oid_fromstr(&pkt->head.oid, line);
|
||||||
if (error < GIT_SUCCESS) {
|
if (error < GIT_SUCCESS) {
|
||||||
@ -70,9 +71,11 @@ int ref_pkt(git_pkt **out, const char *line, size_t len)
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Jump from the name */
|
||||||
line += GIT_OID_HEXSZ + 1;
|
line += GIT_OID_HEXSZ + 1;
|
||||||
|
len -= (GIT_OID_HEXSZ + 1);
|
||||||
|
|
||||||
name_len = len - (GIT_OID_HEXSZ + 1);
|
name_len = min(strlen(line), len);
|
||||||
if (line[name_len - 1] == '\n')
|
if (line[name_len - 1] == '\n')
|
||||||
--name_len;
|
--name_len;
|
||||||
|
|
||||||
@ -82,6 +85,22 @@ int ref_pkt(git_pkt **out, const char *line, size_t len)
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Try to get the capabilities */
|
||||||
|
line += name_len + 1; /* + \0 */
|
||||||
|
len -= (name_len + 1);
|
||||||
|
if (line[len - 1] == '\n')
|
||||||
|
--len;
|
||||||
|
|
||||||
|
if (len > 0) { /* capatilities */
|
||||||
|
pkt->capabilities = git__malloc(len);
|
||||||
|
if (pkt->capabilities == NULL) {
|
||||||
|
error = GIT_ENOMEM;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy(pkt->capabilities, line, len);
|
||||||
|
}
|
||||||
|
|
||||||
out:
|
out:
|
||||||
if (error < GIT_SUCCESS)
|
if (error < GIT_SUCCESS)
|
||||||
free(pkt);
|
free(pkt);
|
||||||
|
@ -4,6 +4,9 @@
|
|||||||
#define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
|
#define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
|
||||||
#define bitsizeof(x) (CHAR_BIT * sizeof(x))
|
#define bitsizeof(x) (CHAR_BIT * sizeof(x))
|
||||||
#define MSB(x, bits) ((x) & (~0ULL << (bitsizeof(x) - (bits))))
|
#define MSB(x, bits) ((x) & (~0ULL << (bitsizeof(x) - (bits))))
|
||||||
|
#ifndef min
|
||||||
|
# define min(a,b) ((a) < (b) ? (a) : (b))
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Custom memory allocation wrappers
|
* Custom memory allocation wrappers
|
||||||
|
Loading…
Reference in New Issue
Block a user