represent packfile hash as byte array in the privsep layer, not as object ID
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 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
diff --git a/lib/fetch.c b/lib/fetch.c
index ffdb2f2..bc53875 100644
--- a/lib/fetch.c
+++ b/lib/fetch.c
@@ -613,6 +613,13 @@ got_fetch_pack(struct got_object_id **pack_hash, struct got_pathlist_head *refs,
err = got_error_from_errno("calloc");
goto done;
}
+
+ *pack_hash = calloc(1, sizeof(**pack_hash));
+ if (*pack_hash == NULL) {
+ err = got_error_from_errno("calloc");
+ goto done;
+ }
+
while (!done) {
struct got_object_id *id = NULL;
char *refname = NULL;
@@ -621,19 +628,14 @@ got_fetch_pack(struct got_object_id **pack_hash, struct got_pathlist_head *refs,
err = got_privsep_recv_fetch_progress(&done,
&id, &refname, symrefs, &server_progress,
- &packfile_size_cur, &fetchibuf);
+ &packfile_size_cur, (*pack_hash)->sha1, &fetchibuf);
if (err != NULL)
goto done;
- if (done) {
- if (packfile_size > 0)
- *pack_hash = id;
- else
- free(id);
- } else if (refname && id) {
+ if (!done && refname && id) {
err = got_pathlist_insert(NULL, refs, refname, id);
if (err)
goto done;
- } else if (server_progress) {
+ } else if (!done && server_progress) {
char *p;
/*
* XXX git-daemon tends to send batched output with
@@ -672,7 +674,7 @@ got_fetch_pack(struct got_object_id **pack_hash, struct got_pathlist_head *refs,
free(server_progress);
if (err)
goto done;
- } else if (packfile_size_cur != packfile_size) {
+ } else if (!done && packfile_size_cur != packfile_size) {
err = progress_cb(progress_arg, NULL,
packfile_size_cur, 0, 0, 0, 0);
if (err)
@@ -691,9 +693,11 @@ got_fetch_pack(struct got_object_id **pack_hash, struct got_pathlist_head *refs,
}
/* If zero data was fetched without error we are already up-to-date. */
- if (packfile_size == 0)
+ if (packfile_size == 0) {
+ free(*pack_hash);
+ *pack_hash = NULL;
goto done;
- else if (packfile_size < sizeof(pack_hdr) + SHA1_DIGEST_LENGTH) {
+ } else if (packfile_size < sizeof(pack_hdr) + SHA1_DIGEST_LENGTH) {
err = got_error_msg(GOT_ERR_BAD_PACKFILE, "short pack file");
goto done;
} else {
diff --git a/lib/got_lib_privsep.h b/lib/got_lib_privsep.h
index b6668b2..950723f 100644
--- a/lib/got_lib_privsep.h
+++ b/lib/got_lib_privsep.h
@@ -414,8 +414,8 @@ const struct got_error *got_privsep_send_fetch_req(struct imsgbuf *, int,
struct got_pathlist_head *, int, int);
const struct got_error *got_privsep_send_fetch_outfd(struct imsgbuf *, int);
const struct got_error *got_privsep_recv_fetch_progress(int *,
- struct got_object_id **, char **, struct got_pathlist_head *,
- char **, off_t *, struct imsgbuf *);
+ struct got_object_id **, char **, struct got_pathlist_head *, char **,
+ off_t *, uint8_t *, struct imsgbuf *);
const struct got_error *got_privsep_get_imsg_obj(struct got_object **,
struct imsg *, struct imsgbuf *);
const struct got_error *got_privsep_recv_obj(struct got_object **,
diff --git a/lib/privsep.c b/lib/privsep.c
index 7a87cf1..79edb65 100644
--- a/lib/privsep.c
+++ b/lib/privsep.c
@@ -568,7 +568,7 @@ got_privsep_send_fetch_outfd(struct imsgbuf *ibuf, int fd)
const struct got_error *
got_privsep_recv_fetch_progress(int *done, struct got_object_id **id,
char **refname, struct got_pathlist_head *symrefs, char **server_progress,
- off_t *packfile_size, struct imsgbuf *ibuf)
+ off_t *packfile_size, uint8_t *pack_sha1, struct imsgbuf *ibuf)
{
const struct got_error *err = NULL;
struct imsg imsg;
@@ -583,6 +583,7 @@ got_privsep_recv_fetch_progress(int *done, struct got_object_id **id,
*refname = NULL;
*server_progress = NULL;
*packfile_size = 0;
+ memset(pack_sha1, 0, SHA1_DIGEST_LENGTH);
err = got_privsep_recv_imsg(&imsg, ibuf, 0);
if (err)
@@ -697,16 +698,11 @@ got_privsep_recv_fetch_progress(int *done, struct got_object_id **id,
memcpy(packfile_size, imsg.data, sizeof(*packfile_size));
break;
case GOT_IMSG_FETCH_DONE:
- *id = malloc(sizeof(**id));
- if (*id == NULL) {
- err = got_error_from_errno("malloc");
- break;
- }
if (datalen != SHA1_DIGEST_LENGTH) {
err = got_error(GOT_ERR_PRIVSEP_MSG);
break;
}
- memcpy((*id)->sha1, imsg.data, SHA1_DIGEST_LENGTH);
+ memcpy(pack_sha1, imsg.data, SHA1_DIGEST_LENGTH);
*done = 1;
break;
default:
diff --git a/libexec/got-fetch-pack/got-fetch-pack.c b/libexec/got-fetch-pack/got-fetch-pack.c
index 22347c7..8f12b8a 100644
--- a/libexec/got-fetch-pack/got-fetch-pack.c
+++ b/libexec/got-fetch-pack/got-fetch-pack.c
@@ -498,10 +498,10 @@ send_fetch_download_progress(struct imsgbuf *ibuf, off_t bytes)
}
static const struct got_error *
-send_fetch_done(struct imsgbuf *ibuf, struct got_object_id hash)
+send_fetch_done(struct imsgbuf *ibuf, uint8_t *pack_sha1)
{
if (imsg_compose(ibuf, GOT_IMSG_FETCH_DONE, 0, 0, -1,
- hash.sha1, SHA1_DIGEST_LENGTH) == -1)
+ pack_sha1, SHA1_DIGEST_LENGTH) == -1)
return got_error_from_errno("imsg_compose FETCH");
return got_privsep_flush_imsg(ibuf);
}
@@ -649,7 +649,7 @@ send_fetch_ref(struct imsgbuf *ibuf, struct got_object_id *refid,
}
static const struct got_error *
-fetch_pack(int fd, int packfd, struct got_object_id *packid,
+fetch_pack(int fd, int packfd, uint8_t *pack_sha1,
struct got_pathlist_head *have_refs, int fetch_all_branches,
struct got_pathlist_head *wanted_branches,
struct got_pathlist_head *wanted_refs, int list_refs_only,
@@ -670,7 +670,6 @@ fetch_pack(int fd, int packfd, struct got_object_id *packid,
int sent_my_capabilites = 0, have_sidebands = 0;
int found_branch = 0;
SHA1_CTX sha1_ctx;
- uint8_t pack_sha1[SHA1_DIGEST_LENGTH];
uint8_t sha1_buf[SHA1_DIGEST_LENGTH];
size_t sha1_buf_len = 0;
ssize_t w;
@@ -1107,7 +1106,7 @@ main(int argc, char **argv)
{
const struct got_error *err = NULL;
int fetchfd, packfd = -1, i;
- struct got_object_id packid;
+ uint8_t pack_sha1[SHA1_DIGEST_LENGTH];
struct imsgbuf ibuf;
struct imsg imsg;
struct got_pathlist_head have_refs;
@@ -1310,7 +1309,7 @@ main(int argc, char **argv)
}
packfd = imsg.fd;
- err = fetch_pack(fetchfd, packfd, &packid, &have_refs,
+ err = fetch_pack(fetchfd, packfd, pack_sha1, &have_refs,
fetch_req.fetch_all_branches, &wanted_branches,
&wanted_refs, fetch_req.list_refs_only, &ibuf);
done:
@@ -1329,7 +1328,7 @@ done:
if (err != NULL)
got_privsep_send_error(&ibuf, err);
else
- err = send_fetch_done(&ibuf, packid);
+ err = send_fetch_done(&ibuf, pack_sha1);
if (err != NULL) {
fprintf(stderr, "%s: %s\n", getprogname(), err->msg);
got_privsep_send_error(&ibuf, err);