Commit 3707b331 by Carlos Martín Nieto Committed by Vicent Marti

pkt: move the protocol strings to the top of the file

Put them all together so we know where to find them.

Signed-off-by: Carlos Martín Nieto <carlos@cmartin.tk>
parent dfafb03b
...@@ -21,6 +21,10 @@ ...@@ -21,6 +21,10 @@
#include <ctype.h> #include <ctype.h>
#define PKT_LEN_SIZE 4 #define PKT_LEN_SIZE 4
static const char pkt_done_str[] = "0009done\n";
static const char pkt_flush_str[] = "0000";
static const char pkt_have_prefix[] = "0032have ";
static const char pkt_want_prefix[] = "0032want ";
static int flush_pkt(git_pkt **out) static int flush_pkt(git_pkt **out)
{ {
...@@ -264,15 +268,14 @@ void git_pkt_free(git_pkt *pkt) ...@@ -264,15 +268,14 @@ void git_pkt_free(git_pkt *pkt)
int git_pkt_buffer_flush(git_buf *buf) int git_pkt_buffer_flush(git_buf *buf)
{ {
git_buf_puts(buf, "0000"); git_buf_put(buf, pkt_flush_str, strlen(pkt_flush_str));
return git_buf_oom(buf) ? GIT_ENOMEM : GIT_SUCCESS; return git_buf_oom(buf) ? GIT_ENOMEM : GIT_SUCCESS;
} }
int git_pkt_send_flush(int s) int git_pkt_send_flush(int s)
{ {
char flush[] = "0000";
return gitno_send(s, flush, strlen(flush), 0); return gitno_send(s, pkt_flush_str, strlen(pkt_flush_str), 0);
} }
static int buffer_want_with_caps(git_remote_head *head, git_transport_caps *caps, git_buf *buf) static int buffer_want_with_caps(git_remote_head *head, git_transport_caps *caps, git_buf *buf)
...@@ -312,7 +315,6 @@ static int send_want_with_caps(git_remote_head *head, git_transport_caps *caps, ...@@ -312,7 +315,6 @@ static int send_want_with_caps(git_remote_head *head, git_transport_caps *caps,
* All "want" packets have the same length and format, so what we do * All "want" packets have the same length and format, so what we do
* is overwrite the OID each time. * is overwrite the OID each time.
*/ */
#define WANT_PREFIX "0032want "
int git_pkt_buffer_wants(git_headarray *refs, git_transport_caps *caps, git_buf *buf) int git_pkt_buffer_wants(git_headarray *refs, git_transport_caps *caps, git_buf *buf)
{ {
...@@ -342,7 +344,7 @@ int git_pkt_buffer_wants(git_headarray *refs, git_transport_caps *caps, git_buf ...@@ -342,7 +344,7 @@ int git_pkt_buffer_wants(git_headarray *refs, git_transport_caps *caps, git_buf
continue; continue;
git_oid_fmt(oid, &head->oid); git_oid_fmt(oid, &head->oid);
git_buf_puts(buf, WANT_PREFIX); git_buf_put(buf, pkt_want_prefix, strlen(pkt_want_prefix));
git_buf_put(buf, oid, GIT_OID_HEXSZ); git_buf_put(buf, oid, GIT_OID_HEXSZ);
git_buf_putc(buf, '\n'); git_buf_putc(buf, '\n');
} }
...@@ -354,10 +356,10 @@ int git_pkt_send_wants(git_headarray *refs, git_transport_caps *caps, int fd) ...@@ -354,10 +356,10 @@ int git_pkt_send_wants(git_headarray *refs, git_transport_caps *caps, int fd)
{ {
unsigned int i = 0; unsigned int i = 0;
int error = GIT_SUCCESS; int error = GIT_SUCCESS;
char buf[sizeof(WANT_PREFIX) + GIT_OID_HEXSZ + 1]; char buf[sizeof(pkt_want_prefix) + GIT_OID_HEXSZ + 1];
git_remote_head *head; git_remote_head *head;
memcpy(buf, WANT_PREFIX, strlen(WANT_PREFIX)); memcpy(buf, pkt_want_prefix, strlen(pkt_want_prefix));
buf[sizeof(buf) - 2] = '\n'; buf[sizeof(buf) - 2] = '\n';
buf[sizeof(buf) - 1] = '\0'; buf[sizeof(buf) - 1] = '\0';
...@@ -384,7 +386,7 @@ int git_pkt_send_wants(git_headarray *refs, git_transport_caps *caps, int fd) ...@@ -384,7 +386,7 @@ int git_pkt_send_wants(git_headarray *refs, git_transport_caps *caps, int fd)
if (head->local) if (head->local)
continue; continue;
git_oid_fmt(buf + strlen(WANT_PREFIX), &head->oid); git_oid_fmt(buf + strlen(pkt_want_prefix), &head->oid);
error = gitno_send(fd, buf, strlen(buf), 0); error = gitno_send(fd, buf, strlen(buf), 0);
if (error < GIT_SUCCESS) if (error < GIT_SUCCESS)
return git__rethrow(error, "Failed to send want pkt"); return git__rethrow(error, "Failed to send want pkt");
...@@ -393,15 +395,13 @@ int git_pkt_send_wants(git_headarray *refs, git_transport_caps *caps, int fd) ...@@ -393,15 +395,13 @@ int git_pkt_send_wants(git_headarray *refs, git_transport_caps *caps, int fd)
return git_pkt_send_flush(fd); return git_pkt_send_flush(fd);
} }
#define HAVE_PREFIX "0032have "
int git_pkt_buffer_have(git_oid *oid, git_buf *buf) int git_pkt_buffer_have(git_oid *oid, git_buf *buf)
{ {
char oidhex[GIT_OID_HEXSZ + 1]; char oidhex[GIT_OID_HEXSZ + 1];
memset(oidhex, 0x0, sizeof(oidhex)); memset(oidhex, 0x0, sizeof(oidhex));
git_oid_fmt(oidhex, oid); git_oid_fmt(oidhex, oid);
git_buf_printf(buf, "%s%s\n", HAVE_PREFIX, oidhex); git_buf_printf(buf, "%s%s\n", pkt_have_prefix, oidhex);
return git_buf_oom(buf) ? GIT_ENOMEM : GIT_SUCCESS; return git_buf_oom(buf) ? GIT_ENOMEM : GIT_SUCCESS;
} }
...@@ -409,21 +409,18 @@ int git_pkt_send_have(git_oid *oid, int fd) ...@@ -409,21 +409,18 @@ int git_pkt_send_have(git_oid *oid, int fd)
{ {
char buf[] = "0032have 0000000000000000000000000000000000000000\n"; char buf[] = "0032have 0000000000000000000000000000000000000000\n";
git_oid_fmt(buf + strlen(HAVE_PREFIX), oid); git_oid_fmt(buf + strlen(pkt_have_prefix), oid);
return gitno_send(fd, buf, strlen(buf), 0); return gitno_send(fd, buf, strlen(buf), 0);
} }
static char *donestr = "0009done\n";
int git_pkt_buffer_done(git_buf *buf) int git_pkt_buffer_done(git_buf *buf)
{ {
git_buf_puts(buf, donestr); git_buf_puts(buf, pkt_done_str);
return git_buf_oom(buf) ? GIT_ENOMEM : GIT_SUCCESS; return git_buf_oom(buf) ? GIT_ENOMEM : GIT_SUCCESS;
} }
int git_pkt_send_done(int fd) int git_pkt_send_done(int fd)
{ {
char buf[] = "0009done\n"; return gitno_send(fd, pkt_done_str, strlen(pkt_done_str), 0);
return gitno_send(fd, buf, strlen(buf), 0);
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment