de-duplicate a constant used by both 'got fetch' and 'got send' Both GOT_FETCH_PKTMAX and GOT_SEND_PKTMAX had the same value. Declare this value as GOT_PKT_MAX in got_lib_pkt.h instead.
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
diff --git a/include/got_fetch.h b/include/got_fetch.h
index 0678325..8facb74 100644
--- a/include/got_fetch.h
+++ b/include/got_fetch.h
@@ -16,8 +16,6 @@
#define GOT_FETCH_DEFAULT_REMOTE_NAME "origin"
-#define GOT_FETCH_PKTMAX 65536
-
/*
* Attempt to parse a URI into the following parts:
* A protocol scheme, hostname, port number (as a string), path on server,
diff --git a/include/got_send.h b/include/got_send.h
index a805a93..225bc42 100644
--- a/include/got_send.h
+++ b/include/got_send.h
@@ -17,8 +17,6 @@
#define GOT_SEND_DEFAULT_REMOTE_NAME "origin"
-#define GOT_SEND_PKTMAX 65536
-
/*
* Attempt to open a connection to a server using the provided protocol
* scheme, hostname port number (as a string) and server-side path.
diff --git a/lib/fetch.c b/lib/fetch.c
index 58ebe83..6392c7e 100644
--- a/lib/fetch.c
+++ b/lib/fetch.c
@@ -61,6 +61,7 @@
#include "got_lib_object_cache.h"
#include "got_lib_repository.h"
#include "got_lib_dial.h"
+#include "got_lib_pkt.h"
#ifndef nitems
#define nitems(_a) (sizeof((_a)) / sizeof((_a)[0]))
@@ -452,7 +453,7 @@ got_fetch_pack(struct got_object_id **pack_hash, struct got_pathlist_head *refs,
npackfd = -1;
packfile_size = 0;
- progress = calloc(GOT_FETCH_PKTMAX, 1);
+ progress = calloc(GOT_PKT_MAX, 1);
if (progress == NULL) {
err = got_error_from_errno("calloc");
goto done;
@@ -488,7 +489,7 @@ got_fetch_pack(struct got_object_id **pack_hash, struct got_pathlist_head *refs,
* partial lines of progress output to the callback.
*/
if (strlcat(progress, server_progress,
- GOT_FETCH_PKTMAX) >= GOT_FETCH_PKTMAX) {
+ GOT_PKT_MAX) >= GOT_PKT_MAX) {
progress[0] = '\0'; /* discard */
continue;
}
@@ -509,9 +510,9 @@ got_fetch_pack(struct got_object_id **pack_hash, struct got_pathlist_head *refs,
if (err)
break;
n = strlen(progress);
- if (n < GOT_FETCH_PKTMAX - 1) {
+ if (n < GOT_PKT_MAX - 1) {
memmove(progress, &progress[n + 1],
- GOT_FETCH_PKTMAX - n - 1);
+ GOT_PKT_MAX - n - 1);
} else
progress[0] = '\0';
}
diff --git a/lib/got_lib_pkt.h b/lib/got_lib_pkt.h
index 63ad536..0095618 100644
--- a/lib/got_lib_pkt.h
+++ b/lib/got_lib_pkt.h
@@ -15,6 +15,8 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#define GOT_PKT_MAX 65536
+
const struct got_error *got_pkt_readn(ssize_t *off, int fd, void *buf,
size_t n);
const struct got_error *got_pkt_flushpkt(int fd, int chattygot);
diff --git a/libexec/got-fetch-pack/got-fetch-pack.c b/libexec/got-fetch-pack/got-fetch-pack.c
index 42a19bf..15451b4 100644
--- a/libexec/got-fetch-pack/got-fetch-pack.c
+++ b/libexec/got-fetch-pack/got-fetch-pack.c
@@ -308,7 +308,7 @@ fetch_pack(int fd, int packfd, uint8_t *pack_sha1,
struct imsgbuf *ibuf)
{
const struct got_error *err = NULL;
- char buf[GOT_FETCH_PKTMAX];
+ char buf[GOT_PKT_MAX];
char hashstr[SHA1_DIGEST_STRING_LENGTH];
struct got_object_id *have, *want;
int is_firstpkt = 1, nref = 0, refsz = 16;
diff --git a/libexec/got-send-pack/got-send-pack.c b/libexec/got-send-pack/got-send-pack.c
index ac6ef5c..366a775 100644
--- a/libexec/got-send-pack/got-send-pack.c
+++ b/libexec/got-send-pack/got-send-pack.c
@@ -325,7 +325,7 @@ send_pack(int fd, struct got_pathlist_head *refs,
struct got_pathlist_head *delete_refs, struct imsgbuf *ibuf)
{
const struct got_error *err = NULL;
- char buf[GOT_FETCH_PKTMAX];
+ char buf[GOT_PKT_MAX];
unsigned char zero_id[SHA1_DIGEST_LENGTH] = { 0 };
char old_hashstr[SHA1_DIGEST_STRING_LENGTH];
char new_hashstr[SHA1_DIGEST_STRING_LENGTH];