commit - f57598a25f07ea6b68f64ef9369142b9c056eb05
commit + 42b6bfc81cdd6a9cba14c9d8916aeddbe561a356
blob - 9e0f5450c83d862479c43c0409e69c88745d5341
blob + eb4cc4d7fd73f259f3ba94f94963980b5cbfe2ae
--- lib/got_lib_pack.h
+++ lib/got_lib_pack.h
struct got_packidx {
char *path_packidx; /* actual on-disk path */
int fd;
+ enum got_hash_algorithm algo;
uint8_t *map;
size_t len;
size_t nlargeobj;
const struct got_error *got_packidx_init_hdr(struct got_packidx *, int, off_t);
const struct got_error *got_packidx_open(struct got_packidx **,
- int, const char *, int);
+ int, const char *, int, enum got_hash_algorithm);
const struct got_error *got_packidx_close(struct got_packidx *);
const struct got_error *got_packidx_get_packfile_path(char **, const char *);
off_t got_packidx_get_object_offset(struct got_packidx *, int idx);
blob - 7f43e610d9a73ffd8cdb88bf5a0a79062d2de48b
blob + 013a402d0c1fab8136006cdfa4f5a916f5c02608
--- lib/got_lib_privsep.h
+++ lib/got_lib_privsep.h
struct got_imsg_packidx {
size_t len;
off_t packfile_size;
+ int algo;
/* Additionally, a file desciptor is passed via imsg. */
};
blob - b67ad40ec2c31fe24e90f390d0eb3ffb1f047d5b
blob + 8f9592941a48ee995d730c7c932ebc6ea4a4f574
--- lib/pack.c
+++ lib/pack.c
got_packidx_init_hdr(struct got_packidx *p, int verify, off_t packfile_size)
{
const struct got_error *err = NULL;
- enum got_hash_algorithm algo = GOT_HASH_SHA1;
struct got_packidx_v2_hdr *h;
struct got_hash ctx;
uint8_t hash[GOT_OBJECT_ID_MAXLEN];
ssize_t n;
int i;
- got_hash_init(&ctx, algo);
+ got_hash_init(&ctx, p->algo);
h = &p->hdr;
offset = 0;
remain -= len_fanout;
nobj = be32toh(h->fanout_table[0xff]);
- len_ids = nobj * got_hash_digest_length(algo);
+ len_ids = nobj * got_hash_digest_length(p->algo);
if (len_ids <= nobj || len_ids > remain) {
err = got_error(GOT_ERR_BAD_PACKIDX);
goto done;
}
if (verify) {
got_hash_update(&ctx, h->trailer->packfile_hash,
- got_hash_digest_length(algo));
+ got_hash_digest_length(p->algo));
got_hash_final(&ctx, hash);
if (got_hash_cmp(&ctx, hash, h->trailer->packidx_hash) != 0)
err = got_error(GOT_ERR_PACKIDX_CSUM);
const struct got_error *
got_packidx_open(struct got_packidx **packidx,
- int dir_fd, const char *relpath, int verify)
+ int dir_fd, const char *relpath, int verify,
+ enum got_hash_algorithm algo)
{
const struct got_error *err = NULL;
struct got_packidx *p = NULL;
err = got_error_from_errno("calloc");
goto done;
}
+
+ p->algo = algo;
p->fd = openat(dir_fd, relpath, O_RDONLY | O_NOFOLLOW | O_CLOEXEC);
if (p->fd == -1) {
int left = 0, right = totobj - 1;
size_t idlen;
- idlen = got_hash_digest_length(GOT_HASH_SHA1);
+ idlen = got_hash_digest_length(packidx->algo);
if (id0 > 0)
left = be32toh(packidx->hdr.fanout_table[id0 - 1]);
struct got_packidx *packidx, int idx)
{
uint32_t totobj = be32toh(packidx->hdr.fanout_table[0xff]);
- enum got_hash_algorithm algo = GOT_HASH_SHA1;
struct got_packidx_object_id *oid;
size_t idlen;
- idlen = got_hash_digest_length(algo);
+ idlen = got_hash_digest_length(packidx->algo);
if (idx < 0 || idx >= totobj)
return got_error(GOT_ERR_NO_OBJ);
struct got_packidx *packidx, const char *id_str_prefix)
{
const struct got_error *err = NULL;
- enum got_hash_algorithm algo = GOT_HASH_SHA1;
u_int8_t id0;
uint32_t totobj = be32toh(packidx->hdr.fanout_table[0xff]);
char hex[3];
struct got_packidx_object_id *oid;
uint32_t i = 0;
- idlen = got_hash_digest_length(algo);
+ idlen = got_hash_digest_length(packidx->algo);
STAILQ_INIT(matched_ids);
int cmp;
if (!got_hash_digest_to_str(oid->hash, id_str, sizeof(id_str),
- algo))
+ packidx->algo))
return got_error(GOT_ERR_NO_SPACE);
cmp = strncmp(id_str, id_str_prefix, prefix_len);
blob - 02bee8a7044af6efd5c1837b240e0941d9a1549a
blob + 484ce580e9c3944b02b5123ec7490114fb93d54c
--- lib/pack_index.c
+++ lib/pack_index.c
int cmp = 0, i = 0;
size_t idlen;
- idlen = got_hash_digest_length(GOT_HASH_SHA1);
+ idlen = got_hash_digest_length(packidx->algo);
if (id0 > 0)
left = be32toh(packidx->hdr.fanout_table[id0 - 1]);
print_packidx(struct got_packidx *packidx)
{
uint32_t nindexed = be32toh(packidx->hdr.fanout_table[0xff]);
- enum got_hash_algorithm algo = GOT_HASH_SHA1;
struct got_packidx_object_id *oid;
size_t idlen;
int i;
- idlen = got_hash_digest_length(algo);
+ idlen = got_hash_digest_length(packidx->algo);
fprintf(stderr, "object IDs:\n");
for (i = 0; i < nindexed; i++) {
char hex[GOT_OBJECT_ID_HEX_MAXLEN];
oid = packidx->hdr.sorted_ids + idlen * i;
- got_hash_digest_to_str(oid->hash, hex, sizeof(hex), algo);
+ got_hash_digest_to_str(oid->hash, hex, sizeof(hex),
+ packidx->algo);
fprintf(stderr, "%s\n", hex);
}
fprintf(stderr, "\n");
add_indexed_object(struct got_packidx *packidx, uint32_t idx,
struct got_indexed_object *obj)
{
- enum got_hash_algorithm algo = GOT_HASH_SHA1;
size_t idlen;
int i;
- idlen = got_hash_digest_length(algo);
+ idlen = got_hash_digest_length(packidx->algo);
memcpy(packidx->hdr.sorted_ids + idx * idlen, obj->id.hash,
idlen);
{
int idx;
size_t idlen;
- enum got_hash_algorithm algo = GOT_HASH_SHA1;
uint32_t nindexed = be32toh(packidx->hdr.fanout_table[0xff]);
- idlen = got_hash_digest_length(algo);
+ idlen = got_hash_digest_length(packidx->algo);
idx = find_object_idx(packidx, obj->id.hash);
if (idx == -1)
blob - 329973acb13ee4e4327e1d7e515e0d23543cb25d
blob + 7f15bf37fe4ec0704fd41e0612b9c21663dc29d6
--- lib/privsep.c
+++ lib/privsep.c
ipackidx.len = packidx->len;
ipackidx.packfile_size = pack->filesize;
+ ipackidx.algo = packidx->algo;
fd = dup(packidx->fd);
if (fd == -1)
return got_error_from_errno("dup");
blob - 39881d55e76da49d2e37a089ca50e5d0c345a31f
blob + 5096af954e1ccadb5899b44af5069d80f24b817e
--- lib/repository.c
+++ lib/repository.c
continue; /* already searched */
err = got_packidx_open(packidx, got_repo_get_fd(repo),
- path_packidx, 0);
+ path_packidx, 0, repo->algo);
if (err)
goto done;
/* No luck. Search the filesystem. */
err = got_packidx_open(packidx, got_repo_get_fd(repo),
- path_packidx, 0);
+ path_packidx, 0, repo->algo);
if (err)
return err;
struct got_object_qid *qid;
err = got_packidx_open(&packidx, got_repo_get_fd(repo),
- path_packidx, 0);
+ path_packidx, 0, repo->algo);
if (err)
break;
}
err = got_packidx_open(&packidx, got_repo_get_fd(repo),
- path_packidx, 0);
+ path_packidx, 0, repo->algo);
free(path_packidx);
if (err)
goto done;
blob - 9f11106c2c45a73b5745d8715c16bec6e2cf610d
blob + 719ece083358fc07f5c3c5071dde8e88a1ababff
--- lib/repository_admin.c
+++ lib/repository_admin.c
goto done;
}
- err = got_packidx_open(&packidx, got_repo_get_fd(repo), idxpath, 1);
+ err = got_packidx_open(&packidx, got_repo_get_fd(repo), idxpath, 1,
+ repo->algo);
if (err)
goto done;
blob - 4d84586f4f4ba3c3c0eb7902c012ca9549cd5424
blob + 588b4f006b33d0a701ce9f5a483d27b23295806c
--- libexec/got-read-pack/got-read-pack.c
+++ libexec/got-read-pack/got-read-pack.c
}
memcpy(&ipackidx, imsg.data, sizeof(ipackidx));
+ p->algo = ipackidx.algo;
p->len = ipackidx.len;
p->fd = dup(imsg.fd);
if (p->fd == -1) {