From 54273d1042b7a7e9a5635ccf15363eec819cb951 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Scharfe?= Date: Thu, 12 Nov 2020 13:20:19 +0100 Subject: csum-file: add hashwrite_be64() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add a helper function for hashing and writing 64-bit integers in network byte order. It returns the number of written bytes. This simplifies callers that keep track of the file offset, even though this number is a constant. Suggested-by: Derrick Stolee Original-patch-by: Taylor Blau Signed-off-by: René Scharfe Signed-off-by: Junio C Hamano diff --git a/csum-file.h b/csum-file.h index f9cbd31..e54d53d 100644 --- a/csum-file.h +++ b/csum-file.h @@ -62,4 +62,11 @@ static inline void hashwrite_be32(struct hashfile *f, uint32_t data) hashwrite(f, &data, sizeof(data)); } +static inline size_t hashwrite_be64(struct hashfile *f, uint64_t data) +{ + data = htonll(data); + hashwrite(f, &data, sizeof(data)); + return sizeof(data); +} + #endif -- cgit v0.10.2-6-g49f6 From ef1b853c15d443b057e5a6306c89b869168a8270 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Scharfe?= Date: Thu, 12 Nov 2020 13:22:16 +0100 Subject: midx: use hashwrite_be64() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Call hashwrite_be64() to write 64-bit values instead of open-coding it using hashwrite_be32() and sizeof. This shortens the code and makes its intent clearer. Signed-off-by: René Scharfe Signed-off-by: Junio C Hamano diff --git a/midx.c b/midx.c index 0de42ff..f56321dc 100644 --- a/midx.c +++ b/midx.c @@ -790,9 +790,7 @@ static size_t write_midx_large_offsets(struct hashfile *f, uint32_t nr_large_off if (!(offset >> 31)) continue; - hashwrite_be32(f, offset >> 32); - hashwrite_be32(f, offset & 0xffffffffUL); - written += 2 * sizeof(uint32_t); + written += hashwrite_be64(f, offset); nr_large_offset--; } @@ -980,8 +978,7 @@ static int write_midx_internal(const char *object_dir, struct multi_pack_index * chunk_offsets[i]); hashwrite_be32(f, chunk_ids[i]); - hashwrite_be32(f, chunk_offsets[i] >> 32); - hashwrite_be32(f, chunk_offsets[i]); + hashwrite_be64(f, chunk_offsets[i]); written += MIDX_CHUNKLOOKUP_WIDTH; } -- cgit v0.10.2-6-g49f6 From 970909c2a7803564f82ab1d3660d77ad6a44b68f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Scharfe?= Date: Thu, 12 Nov 2020 13:23:10 +0100 Subject: pack-write: use hashwrite_be64() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Call hashwrite_be64() to write a 64-bit value instead of open-coding it using htonl() and hashwrite(). This shortens the code, gets rid of a buffer and several magic numbers, and makes the intent clearer. Signed-off-by: René Scharfe Signed-off-by: Junio C Hamano diff --git a/pack-write.c b/pack-write.c index a6cdb3c..4bdd44c 100644 --- a/pack-write.c +++ b/pack-write.c @@ -153,13 +153,10 @@ const char *write_idx_file(const char *index_name, struct pack_idx_entry **objec while (nr_large_offset) { struct pack_idx_entry *obj = *list++; uint64_t offset = obj->offset; - uint32_t split[2]; if (!need_large_offset(offset, opts)) continue; - split[0] = htonl(offset >> 32); - split[1] = htonl(offset & 0xffffffff); - hashwrite(f, split, 8); + hashwrite_be64(f, offset); nr_large_offset--; } } -- cgit v0.10.2-6-g49f6