git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 06/15] pack-revindex: express constants in terms of the_hash_algo

From
brian m. carlson <sandals@crustytoothpaste.net>
Date
Oct 15, 2018, 00:01 UTC
Message-ID
<20181015000202.951965-7-sandals@crustytoothpaste.net>
In-Reply-To
<20181015000202.951965-1-sandals@crustytoothpaste.net>

Express the various constants used in terms of the_hash_algo. While we're at it, fix a comment style issue as well.

Reviewed-by: Stefan Beller <sbeller@google.com>
Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 pack-revindex.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/pack-revindex.c b/pack-revindex.c
index bb521cf7fb..3c58784a5f 100644
--- a/pack-revindex.c
+++ b/pack-revindex.c
@@ -122,13 +122,14 @@ static void create_pack_revindex(struct packed_git *p)
 	unsigned num_ent = p->num_objects;
 	unsigned i;
 	const char *index = p->index_data;
+	const unsigned hashsz = the_hash_algo->rawsz;
 
 	ALLOC_ARRAY(p->revindex, num_ent + 1);
 	index += 4 * 256;
 
 	if (p->index_version > 1) {
 		const uint32_t *off_32 =
-			(uint32_t *)(index + 8 + p->num_objects * (20 + 4));
+			(uint32_t *)(index + 8 + p->num_objects * (hashsz + 4));
 		const uint32_t *off_64 = off_32 + p->num_objects;
 		for (i = 0; i < num_ent; i++) {
 			uint32_t off = ntohl(*off_32++);
@@ -142,16 +143,17 @@ static void create_pack_revindex(struct packed_git *p)
 		}
 	} else {
 		for (i = 0; i < num_ent; i++) {
-			uint32_t hl = *((uint32_t *)(index + 24 * i));
+			uint32_t hl = *((uint32_t *)(index + (hashsz + 4) * i));
 			p->revindex[i].offset = ntohl(hl);
 			p->revindex[i].nr = i;
 		}
 	}
 
-	/* This knows the pack format -- the 20-byte trailer
+	/*
+	 * This knows the pack format -- the hash trailer
 	 * follows immediately after the last object data.
 	 */
-	p->revindex[num_ent].offset = p->pack_size - 20;
+	p->revindex[num_ent].offset = p->pack_size - hashsz;
 	p->revindex[num_ent].nr = -1;
 	sort_revindex(p->revindex, num_ent, p->pack_size);
 }
Previous: brian m. carlsonNext: brian m. carlson
Message 7 of 17 in “Hash function transition part 15”
  1. 00/15 Hash function transition part 15brian m. carlson, Oct 15, 2018
  2. 01/15 object_id.cocci: match only expressions of type 'struct object_id'brian m. carlson, Oct 15, 2018
  3. 02/15 pack-bitmap-write: use GIT_MAX_RAWSZ for allocationbrian m. carlson, Oct 15, 2018
  4. 03/15 builtin/repack: replace hard-coded constantsbrian m. carlson, Oct 15, 2018
  5. 04/15 builtin/mktree: remove hard-coded constantbrian m. carlson, Oct 15, 2018
  6. 05/15 builtin/fetch-pack: remove constants with parse_oid_hexbrian m. carlson, Oct 15, 2018
  7. 06/15 pack-revindex: express constants in terms of the_hash_algobrian m. carlson, Oct 15, 2018
  8. 07/15 packfile: express constants in terms of the_hash_algobrian m. carlson, Oct 15, 2018
  9. 09/15 upload-pack: express constants in terms of the_hash_algobrian m. carlson, Oct 15, 2018
  10. 08/15 refs/packed-backend: express constants using the_hash_algobrian m. carlson, Oct 15, 2018
  11. 10/15 transport: use parse_oid_hex instead of a constantbrian m. carlson, Oct 15, 2018
  12. 11/15 tag: express constant in terms of the_hash_algobrian m. carlson, Oct 15, 2018
  13. 13/15 apply: rename new_sha1_prefix and old_sha1_prefixbrian m. carlson, Oct 15, 2018
  14. 12/15 apply: replace hard-coded constantsbrian m. carlson, Oct 15, 2018
  15. 14/15 submodule: make zero-oid comparison hash function agnosticbrian m. carlson, Oct 15, 2018
  16. 15/15 rerere: convert to use the_hash_algobrian m. carlson, Oct 15, 2018
  17. Junio C HamanoOct 25, 2018

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.