]> git.proxmox.com Git - libgit2.git/blame - src/protocol.c
Update Copyright header
[libgit2.git] / src / protocol.c
CommitLineData
40a40e8e 1/*
5e0de328 2 * Copyright (C) 2009-2012 the libgit2 contributors
40a40e8e
CMN
3 *
4 * This file is part of libgit2, distributed under the GNU GPL v2 with
5 * a Linking Exception. For full terms see the included COPYING file.
6 */
7#include "common.h"
8#include "protocol.h"
9#include "pkt.h"
10#include "buffer.h"
11
12int git_protocol_store_refs(git_protocol *p, const char *data, size_t len)
13{
14 git_buf *buf = &p->buf;
15 git_vector *refs = p->refs;
16 int error;
17 const char *line_end, *ptr;
18
19 if (len == 0) { /* EOF */
20 if (buf->size != 0)
21 return p->error = git__throw(GIT_ERROR, "EOF and unprocessed data");
22 else
23 return 0;
24 }
25
26 git_buf_put(buf, data, len);
27 ptr = buf->ptr;
28 while (1) {
29 git_pkt *pkt;
30
31 if (buf->size == 0)
32 return 0;
33
34 error = git_pkt_parse_line(&pkt, ptr, &line_end, buf->size);
35 if (error == GIT_ESHORTBUFFER)
36 return 0; /* Ask for more */
37 if (error < GIT_SUCCESS)
38 return p->error = git__rethrow(error, "Failed to parse pkt-line");
39
40 git_buf_consume(buf, line_end);
41 error = git_vector_insert(refs, pkt);
42 if (error < GIT_SUCCESS)
43 return p->error = git__rethrow(error, "Failed to add pkt to list");
44
45 if (pkt->type == GIT_PKT_FLUSH)
46 p->flush = 1;
47 }
48
49 return error;
50}