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

[PATCH 3/3] pack-write: use hashwrite_be64()

From
René Scharfe <l.s.r@web.de>
Date
Nov 12, 2020, 12:23 UTC
Message-ID
<716c9fd8-273e-6bf6-ab67-1f589d2c9687@web.de>
In-Reply-To
<16932ced-8bcd-89bd-b927-cae1bce0365a@web.de>

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 <l.s.r@web.de>
---
 pack-write.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/pack-write.c b/pack-write.c
index 23e19cc1ec..3513665e1e 100644
--- a/pack-write.c
+++ b/pack-write.c
@@ -151,13 +151,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--;
 		}
 	}
--
2.29.2
Previous: René ScharfeNext: Derrick Stolee
Message 3 of 6 in “csum-file: add hashwrite_be64()”
  1. 1/3 csum-file: add hashwrite_be64()René Scharfe, Nov 12, 2020
  2. 2/3 midx: use hashwrite_be64()René Scharfe, Nov 12, 2020
  3. 3/3 pack-write: use hashwrite_be64()René Scharfe, Nov 12, 2020
  4. Derrick StoleeNov 12, 2020
  5. Taylor BlauNov 12, 2020
  6. Taylor BlauNov 12, 2020

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.