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>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
diff --git a/src/pkt.c b/src/pkt.c
index be850bc..9471df2 100644
--- a/src/pkt.c
+++ b/src/pkt.c
@@ -21,6 +21,10 @@
#include <ctype.h>
#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)
{
@@ -264,15 +268,14 @@ void git_pkt_free(git_pkt *pkt)
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;
}
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)
@@ -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
* 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)
{
@@ -342,7 +344,7 @@ int git_pkt_buffer_wants(git_headarray *refs, git_transport_caps *caps, git_buf
continue;
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_putc(buf, '\n');
}
@@ -354,10 +356,10 @@ int git_pkt_send_wants(git_headarray *refs, git_transport_caps *caps, int fd)
{
unsigned int i = 0;
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;
- memcpy(buf, WANT_PREFIX, strlen(WANT_PREFIX));
+ memcpy(buf, pkt_want_prefix, strlen(pkt_want_prefix));
buf[sizeof(buf) - 2] = '\n';
buf[sizeof(buf) - 1] = '\0';
@@ -384,7 +386,7 @@ int git_pkt_send_wants(git_headarray *refs, git_transport_caps *caps, int fd)
if (head->local)
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);
if (error < GIT_SUCCESS)
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)
return git_pkt_send_flush(fd);
}
-#define HAVE_PREFIX "0032have "
-
int git_pkt_buffer_have(git_oid *oid, git_buf *buf)
{
char oidhex[GIT_OID_HEXSZ + 1];
memset(oidhex, 0x0, sizeof(oidhex));
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;
}
@@ -409,21 +409,18 @@ int git_pkt_send_have(git_oid *oid, int fd)
{
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);
}
-static char *donestr = "0009done\n";
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;
}
int git_pkt_send_done(int fd)
{
- char buf[] = "0009done\n";
-
- return gitno_send(fd, buf, strlen(buf), 0);
+ return gitno_send(fd, pkt_done_str, strlen(pkt_done_str), 0);
}