commit - 92dc95a8ef154c5ab569feff59be53cea26f5a90
commit + 1d72a2a0ee2d5c4546c0471e054c0d81e407bc72
blob - ffdb2f264540f878337fd2792f8b41eafa1d5b55
blob + bc538754a1763f2c475adf6b02dd67afde0541ef
--- lib/fetch.c
+++ lib/fetch.c
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;
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
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)
}
/* 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 {
blob - b6668b257a2454bd0f92457ae8cd5ccb9069e2a9
blob + 950723fdd3cab55b86ef0eb87c5739432be13b7c
--- lib/got_lib_privsep.h
+++ lib/got_lib_privsep.h
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 **,
blob - 7a87cf1648983cbf4f1f078d5daff69f534db236
blob + 79edb658b827574e323a216f2a813c4418040d70
--- lib/privsep.c
+++ lib/privsep.c
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;
*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)
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:
blob - 22347c7306d44201b88b5b26b0759e20e8d05c0e
blob + 8f12b8a31ccaad03d37aa324b719c8c96c8f50d1
--- libexec/got-fetch-pack/got-fetch-pack.c
+++ libexec/got-fetch-pack/got-fetch-pack.c
}
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);
}
}
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,
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;
{
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;
}
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:
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);