diff options
author | Vicent Martà <tanoku@gmail.com> | 2011-09-22 10:17:43 -0700 |
---|---|---|
committer | Vicent Martà <tanoku@gmail.com> | 2011-09-22 10:17:43 -0700 |
commit | 8114ee4c950d035388f1191081fbe77d9a9f3017 (patch) | |
tree | a1cfd43c33d8c8d56bf23d91f24bd5bb9840f24e /src/pkt.c | |
parent | e1b86444676b70154bf8ab450d429bdef57a8276 (diff) | |
parent | 4ee8418a0877d1c2f48459bb266342b127fc7d87 (diff) | |
download | libgit2-8114ee4c950d035388f1191081fbe77d9a9f3017.tar.gz |
Merge pull request #405 from carlosmn/http-ls
Implement ls-remote over HTTP
Diffstat (limited to 'src/pkt.c')
-rw-r--r-- | src/pkt.c | 26 |
1 files changed, 21 insertions, 5 deletions
@@ -80,13 +80,30 @@ static int pack_pkt(git_pkt **out) return GIT_SUCCESS; } +static int comment_pkt(git_pkt **out, const char *line, size_t len) +{ + git_pkt_comment *pkt; + + pkt = git__malloc(sizeof(git_pkt_comment) + len + 1); + if (pkt == NULL) + return GIT_ENOMEM; + + pkt->type = GIT_PKT_COMMENT; + memcpy(pkt->comment, line, len); + pkt->comment[len] = '\0'; + + *out = (git_pkt *) pkt; + + return GIT_SUCCESS; +} + /* * Parse an other-ref line. */ static int ref_pkt(git_pkt **out, const char *line, size_t len) { git_pkt_ref *pkt; - int error, has_caps = 0; + int error; pkt = git__malloc(sizeof(git_pkt_ref)); if (pkt == NULL) @@ -110,9 +127,6 @@ static int ref_pkt(git_pkt **out, const char *line, size_t len) line += GIT_OID_HEXSZ + 1; len -= (GIT_OID_HEXSZ + 1); - if (strlen(line) < len) - has_caps = 1; - if (line[len - 1] == '\n') --len; @@ -124,7 +138,7 @@ static int ref_pkt(git_pkt **out, const char *line, size_t len) memcpy(pkt->head.name, line, len); pkt->head.name[len] = '\0'; - if (has_caps) { + if (strlen(pkt->head.name) < len) { pkt->capabilities = strchr(pkt->head.name, '\0') + 1; } @@ -227,6 +241,8 @@ int git_pkt_parse_line(git_pkt **head, const char *line, const char **out, size_ error = ack_pkt(head, line, len); else if (!git__prefixcmp(line, "NAK")) error = nak_pkt(head); + else if (*line == '#') + error = comment_pkt(head, line, len); else error = ref_pkt(head, line, len); |