All of lore.kernel.org
 help / color / mirror / Atom feed
From: "brian m. carlson" <sandals@crustytoothpaste.net>
To: <git@vger.kernel.org>
Cc: Taylor Blau <me@ttaylorr.com>, Derrick Stolee <dstolee@microsoft.com>
Subject: [PATCH 26/26] midx: switch to using the_hash_algo
Date: Sun, 18 Aug 2019 20:04:27 +0000	[thread overview]
Message-ID: <20190818200427.870753-27-sandals@crustytoothpaste.net> (raw)
In-Reply-To: <20190818200427.870753-1-sandals@crustytoothpaste.net>

Instead of hard-coding the hash size, use the_hash_algo to look up the
hash size at runtime.  Remove the #define constant which was used to
hold the hash length, since writing the expression with the_hash_algo
provide enough documentary value on its own.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 midx.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/midx.c b/midx.c
index d649644420..f29afc0d2d 100644
--- a/midx.c
+++ b/midx.c
@@ -19,8 +19,7 @@
 #define MIDX_BYTE_NUM_PACKS 8
 #define MIDX_HASH_VERSION 1
 #define MIDX_HEADER_SIZE 12
-#define MIDX_HASH_LEN 20
-#define MIDX_MIN_SIZE (MIDX_HEADER_SIZE + MIDX_HASH_LEN)
+#define MIDX_MIN_SIZE (MIDX_HEADER_SIZE + the_hash_algo->rawsz)
 
 #define MIDX_MAX_CHUNKS 5
 #define MIDX_CHUNK_ALIGNMENT 4
@@ -93,7 +92,7 @@ struct multi_pack_index *load_multi_pack_index(const char *object_dir, int local
 	hash_version = m->data[MIDX_BYTE_HASH_VERSION];
 	if (hash_version != MIDX_HASH_VERSION)
 		die(_("hash version %u does not match"), hash_version);
-	m->hash_len = MIDX_HASH_LEN;
+	m->hash_len = the_hash_algo->rawsz;
 
 	m->num_chunks = m->data[MIDX_BYTE_NUM_CHUNKS];
 
@@ -234,7 +233,7 @@ int prepare_midx_pack(struct repository *r, struct multi_pack_index *m, uint32_t
 int bsearch_midx(const struct object_id *oid, struct multi_pack_index *m, uint32_t *result)
 {
 	return bsearch_hash(oid->hash, m->chunk_oid_fanout, m->chunk_oid_lookup,
-			    MIDX_HASH_LEN, result);
+			    the_hash_algo->rawsz, result);
 }
 
 struct object_id *nth_midxed_object_oid(struct object_id *oid,
@@ -928,7 +927,7 @@ static int write_midx_internal(const char *object_dir, struct multi_pack_index *
 
 	cur_chunk++;
 	chunk_ids[cur_chunk] = MIDX_CHUNKID_OBJECTOFFSETS;
-	chunk_offsets[cur_chunk] = chunk_offsets[cur_chunk - 1] + nr_entries * MIDX_HASH_LEN;
+	chunk_offsets[cur_chunk] = chunk_offsets[cur_chunk - 1] + nr_entries * the_hash_algo->rawsz;
 
 	cur_chunk++;
 	chunk_offsets[cur_chunk] = chunk_offsets[cur_chunk - 1] + nr_entries * MIDX_CHUNK_OFFSET_WIDTH;
@@ -976,7 +975,7 @@ static int write_midx_internal(const char *object_dir, struct multi_pack_index *
 				break;
 
 			case MIDX_CHUNKID_OIDLOOKUP:
-				written += write_midx_oid_lookup(f, MIDX_HASH_LEN, entries, nr_entries);
+				written += write_midx_oid_lookup(f, the_hash_algo->rawsz, entries, nr_entries);
 				break;
 
 			case MIDX_CHUNKID_OBJECTOFFSETS:

  parent reply	other threads:[~2019-08-18 20:06 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-18 20:04 [PATCH 00/26] object_id part 17 brian m. carlson
2019-08-18 20:04 ` [PATCH 01/26] builtin/replace: make hash size independent brian m. carlson
2019-08-18 20:04 ` [PATCH 02/26] patch-id: convert to use the_hash_algo brian m. carlson
2019-08-20 21:12   ` René Scharfe
2019-08-20 22:36     ` brian m. carlson
2019-08-22 15:53       ` Junio C Hamano
2019-08-18 20:04 ` [PATCH 03/26] fetch-pack: use parse_oid_hex brian m. carlson
2019-08-18 20:04 ` [PATCH 04/26] builtin/receive-pack: switch to use the_hash_algo brian m. carlson
2019-08-18 20:04 ` [PATCH 05/26] builtin/blame: switch uses of GIT_SHA1_HEXSZ to the_hash_algo brian m. carlson
2019-08-18 20:04 ` [PATCH 06/26] builtin/rev-parse: switch to use the_hash_algo brian m. carlson
2019-08-18 20:04 ` [PATCH 07/26] blame: remove needless comparison with GIT_SHA1_HEXSZ brian m. carlson
2019-08-18 20:04 ` [PATCH 08/26] show-index: switch hard-coded constants to the_hash_algo brian m. carlson
2019-08-18 20:04 ` [PATCH 09/26] connected: switch GIT_SHA1_HEXSZ " brian m. carlson
2019-08-18 20:04 ` [PATCH 10/26] bundle: switch to use the_hash_algo brian m. carlson
2019-08-18 20:04 ` [PATCH 11/26] combine-diff: replace GIT_SHA1_HEXSZ with the_hash_algo brian m. carlson
2019-08-18 20:04 ` [PATCH 12/26] config: use the_hash_algo in abbrev comparison brian m. carlson
2019-08-18 20:04 ` [PATCH 13/26] sha1-lookup: switch hard-coded constants to the_hash_algo brian m. carlson
2019-08-18 20:04 ` [PATCH 14/26] bisect: switch to using the_hash_algo brian m. carlson
2019-08-18 20:04 ` [PATCH 15/26] sequencer: convert to use the_hash_algo brian m. carlson
2019-08-18 20:04 ` [PATCH 16/26] pack-write: use hash_to_hex when writing checksums brian m. carlson
2019-08-18 20:04 ` [PATCH 17/26] builtin/repack: write object IDs of the proper length brian m. carlson
2019-08-18 20:04 ` [PATCH 18/26] builtin/worktree: switch null_sha1 to null_oid brian m. carlson
2019-08-18 20:04 ` [PATCH 19/26] cache: remove null_sha1 brian m. carlson
2019-08-18 20:04 ` [PATCH 20/26] wt-status: convert struct wt_status to object_id brian m. carlson
2019-08-18 20:04 ` [PATCH 21/26] packfile: replace sha1_to_hex brian m. carlson
2019-08-18 20:04 ` [PATCH 22/26] builtin/index-pack: " brian m. carlson
2019-08-18 20:04 ` [PATCH 23/26] builtin/receive-pack: " brian m. carlson
2019-08-18 20:04 ` [PATCH 24/26] rerere: " brian m. carlson
2019-08-18 20:04 ` [PATCH 25/26] builtin/show-index: " brian m. carlson
2019-08-18 20:04 ` brian m. carlson [this message]
2019-08-22 14:04   ` [PATCH 26/26] midx: switch to using the_hash_algo Derrick Stolee
2019-08-23  2:17     ` brian m. carlson
2019-08-23 11:53       ` Derrick Stolee

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190818200427.870753-27-sandals@crustytoothpaste.net \
    --to=sandals@crustytoothpaste.net \
    --cc=dstolee@microsoft.com \
    --cc=git@vger.kernel.org \
    --cc=me@ttaylorr.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.