Commit Diff


commit - f57598a25f07ea6b68f64ef9369142b9c056eb05
commit + 42b6bfc81cdd6a9cba14c9d8916aeddbe561a356
blob - 9e0f5450c83d862479c43c0409e69c88745d5341
blob + eb4cc4d7fd73f259f3ba94f94963980b5cbfe2ae
--- lib/got_lib_pack.h
+++ lib/got_lib_pack.h
@@ -125,6 +125,7 @@ struct got_pack_large_offset_index {
 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;
@@ -199,7 +200,7 @@ struct got_packfile_obj_data {
 
 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
@@ -507,6 +507,7 @@ struct got_imsg_index_pack_progress {
 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
@@ -74,7 +74,6 @@ const struct got_error *
 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];
@@ -82,7 +81,7 @@ got_packidx_init_hdr(struct got_packidx *p, int verify
 	ssize_t n;
 	int i;
 
-	got_hash_init(&ctx, algo);
+	got_hash_init(&ctx, p->algo);
 
 	h = &p->hdr;
 	offset = 0;
@@ -182,7 +181,7 @@ got_packidx_init_hdr(struct got_packidx *p, int verify
 	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;
@@ -325,7 +324,7 @@ checksum:
 	}
 	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);
@@ -336,7 +335,8 @@ done:
 
 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;
@@ -368,6 +368,8 @@ got_packidx_open(struct got_packidx **packidx,
 		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) {
@@ -493,7 +495,7 @@ got_packidx_get_object_idx(struct got_packidx *packidx
 	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]);
@@ -654,11 +656,10 @@ got_packidx_get_object_id(struct got_object_id *id,
     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);
@@ -673,7 +674,6 @@ got_packidx_match_id_str_prefix(struct got_object_id_q
     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];
@@ -681,7 +681,7 @@ got_packidx_match_id_str_prefix(struct got_object_id_q
 	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);
 
@@ -703,7 +703,7 @@ got_packidx_match_id_str_prefix(struct got_object_id_q
 		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
@@ -476,7 +476,7 @@ find_object_idx(struct got_packidx *packidx, uint8_t *
 	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]);
@@ -504,19 +504,19 @@ static void
 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");
@@ -544,11 +544,10 @@ static void
 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);
@@ -607,10 +606,9 @@ update_packidx(struct got_packidx *packidx, uint32_t n
 {
 	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
@@ -1935,6 +1935,7 @@ got_privsep_init_pack_child(struct imsgbuf *ibuf, stru
 
 	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
@@ -1278,7 +1278,7 @@ got_repo_search_packidx(struct got_packidx **packidx, 
 			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;
 
@@ -1380,7 +1380,7 @@ got_repo_get_packidx(struct got_packidx **packidx, con
 	/* 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;
 
@@ -1678,7 +1678,7 @@ match_packed_object(struct got_object_id **unique_id,
 		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;
 
@@ -2406,7 +2406,7 @@ got_repo_get_packfile_info(int *npackfiles, int *nobje
 		}
 
 		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
@@ -547,7 +547,8 @@ got_repo_list_pack(FILE *packfile, struct got_object_i
 		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
@@ -1124,6 +1124,7 @@ receive_packidx(struct got_packidx **packidx, struct i
 	}
 	memcpy(&ipackidx, imsg.data, sizeof(ipackidx));
 
+	p->algo = ipackidx.algo;
 	p->len = ipackidx.len;
 	p->fd = dup(imsg.fd);
 	if (p->fd == -1) {