Commit Diff


commit - 49e8084f17c186e6b7188980436c524822c0be12571f8f061abcedd0b8f02991
commit + a5fb4de1927f211101c0b9a47b68f2764834954aca1c26f3386a6a30b744d97d
blob - 1f9f384eaa537b454caf66e1233ee428923c159bf5562c56866733823b8e64ac
blob + 31995eb56e56b1a70ff920abe5e646817710b31d6dac2cd8aec00647318db1c0
--- lib/got_lib_object_idset.h	
+++ lib/got_lib_object_idset.h	
@@ -27,6 +27,8 @@ const struct got_error *got_object_idset_remove(void *
     struct got_object_idset *, struct got_object_id *);
 int got_object_idset_contains(struct got_object_idset *,
     struct got_object_id *);
+int got_object_idset_contains_hash(struct got_object_idset *,
+    enum got_hash_algorithm, uint8_t *);
 const struct got_error *got_object_idset_for_each(struct got_object_idset *,
     const struct got_error *(*cb)(struct got_object_id *, void *, void *),
     void *);
blob - 3a9362075b104b203b30573a6e14ff1b7b44a1ef9b92e962a7c1d10cd3e42ede
blob + 2fe406027023bc5076eaabce4c1a73a5338b871954040778208dd4ad18fadf5f
--- lib/object_idset.c	
+++ lib/object_idset.c	
@@ -123,6 +123,12 @@ idset_hash(SIPHASH_KEY *key, struct got_object_id *id)
 	return SipHash24(key, id->hash, got_hash_digest_length(id->algo));
 }
 
+static uint64_t
+idset_hash_hash(SIPHASH_KEY *key, enum got_hash_algorithm algo, uint8_t *hash)
+{
+	return SipHash24(key, hash, got_hash_digest_length(algo));
+}
+
 static const struct got_error *
 idset_add(struct got_object_idset_bucket *bucket, struct got_object_id *id,
     void *data)
@@ -408,6 +414,47 @@ got_object_idset_contains(struct got_object_idset *set
 	return id_found ? 1 : 0;
 }
 
+static void
+find_element_hash(struct got_object_id **id_found, void **data_found,
+    struct got_object_idset *set, enum got_hash_algorithm algo,
+    uint8_t *hash)
+{
+	uint64_t idx = idset_hash_hash(&set->key, algo, hash) % set->nbuckets;
+	struct got_object_idset_bucket *bucket = &set->buckets[idx];
+	struct got_object_qid *qid;
+
+	*id_found = NULL;
+	*data_found = NULL;
+
+	if (bucket->id.algo == GOT_OBJECT_IDSET_SLOT_EMPTY)
+		return;
+
+	if (got_hash_cmp(algo, bucket->id.hash, hash) == 0) {
+		*id_found = &bucket->id;
+		*data_found = bucket->data;
+		return;
+	}
+
+	STAILQ_FOREACH(qid, &bucket->ids, entry) {
+		if (got_hash_cmp(algo, qid->id.hash, hash) == 0) {
+			*id_found = &qid->id;
+			*data_found = qid->data;
+			return;
+		}
+	}
+}
+
+int
+got_object_idset_contains_hash(struct got_object_idset *set,
+    enum got_hash_algorithm algo, uint8_t *hash)
+{
+	struct got_object_id *id_found;
+	void *data_found;
+
+	find_element_hash(&id_found, &data_found, set, algo, hash);
+	return id_found ? 1 : 0;
+}
+
 const struct got_error *
 got_object_idset_for_each(struct got_object_idset *set,
     const struct got_error *(*cb)(struct got_object_id *, void *, void *),
blob - c850ec3fc83e0d4a35206e684818b07b9ba3458ad718d71d34cd5b99c7e8f59a
blob + 3155c9473a878ff3bad765fec4142ff2b31bb3d44000cebfefd9059142c6c1af
--- libexec/got-read-pack/got-read-pack.c	
+++ libexec/got-read-pack/got-read-pack.c	
@@ -55,10 +55,6 @@
 #define nitems(_a)	(sizeof((_a)) / sizeof((_a)[0]))
 #endif
 
-#ifndef MINIMUM
-#define MINIMUM(a, b)	((a) < (b) ? (a) : (b))
-#endif
-
 static volatile sig_atomic_t sigint_received;
 
 static void
@@ -1286,23 +1282,21 @@ enumerate_tree(int *have_all_entries, struct imsgbuf *
 		for (i = 0; i < nentries; i++) {
 			struct got_object_qid *eqid = NULL;
 			struct got_parsed_tree_entry *pte = &entries[i];
-			struct got_object_id id;
 			char *p;
 
 			if (!S_ISDIR(pte->mode))
 				continue;
 
-			id.algo = pte->algo;
-			memcpy(id.hash, pte->id,
-			    MINIMUM(pte->digest_len, sizeof(id.hash)));
-			if (got_object_idset_contains(idset, &id))
+			if (got_object_idset_contains_hash(idset, pte->algo,
+			    pte->id))
 				continue;
 
 			err = got_object_qid_alloc_partial(&eqid);
 			if (err)
 				goto done;
 	
-			memcpy(&eqid->id, &id, sizeof(eqid->id));
+			eqid->id.algo = pte->algo;
+			memcpy(&eqid->id.hash, pte->id, pte->digest_len);
 
 			if (asprintf(&p, "%s%s%s", path,
 			    got_path_is_root_dir(path) ? "" : "/",