diff mbox series

[05/14] pack-revindex: express constants in terms of the_hash_algo

Message ID 20181008215701.779099-6-sandals@crustytoothpaste.net (mailing list archive)
State New, archived
Headers show
Series Hash function transition part 15 | expand

Commit Message

brian m. carlson Oct. 8, 2018, 9:56 p.m. UTC
Express the various constants used in terms of the_hash_algo.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 pack-revindex.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

Comments

Stefan Beller Oct. 8, 2018, 10:44 p.m. UTC | #1
> -       /* This knows the pack format -- the 20-byte trailer
> +       /* This knows the pack format -- the hash trailer
>          * follows immediately after the last object data.

While at it, fix the comment style?

With or without the nit addressed, this patch (and patches
1 and 4) are

  Reviewed-by: Stefan Beller <sbeller@google.com>
brian m. carlson Oct. 9, 2018, 10:26 p.m. UTC | #2
On Mon, Oct 08, 2018 at 03:44:36PM -0700, Stefan Beller wrote:
> > -       /* This knows the pack format -- the 20-byte trailer
> > +       /* This knows the pack format -- the hash trailer
> >          * follows immediately after the last object data.
> 
> While at it, fix the comment style?

Sure, I can do that.
diff mbox series

Patch

diff --git a/pack-revindex.c b/pack-revindex.c
index bb521cf7fb..3756ec71a8 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,16 @@  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);
 }