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

[PATCH] pack-write: use hashwrite_be32() in write_idx_file()

From
René Scharfe <l.s.r@web.de>
Date
Sep 19, 2020, 18:26 UTC
Message-ID
<4c561e04-7edc-448f-46ca-4d4ac33e9ab3@web.de>

Call hashwrite_be32() instead of open-coding it. This shortens the code a bit and makes it easier to read.

Signed-off-by: René Scharfe <l.s.r@web.de>
---
 pack-write.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)
diff --git a/pack-write.c b/pack-write.c
index 685d327d80..a6cdb3c67c 100644
--- a/pack-write.c
+++ b/pack-write.c
@@ -117,10 +117,8 @@ const char *write_idx_file(const char *index_name, struct pack_idx_entry **objec
 	list = sorted_by_sha;
 	for (i = 0; i < nr_objects; i++) {
 		struct pack_idx_entry *obj = *list++;
-		if (index_version < 2) {
-			uint32_t offset = htonl(obj->offset);
-			hashwrite(f, &offset, 4);
-		}
+		if (index_version < 2)
+			hashwrite_be32(f, obj->offset);
 		hashwrite(f, obj->oid.hash, the_hash_algo->rawsz);
 		if ((opts->flags & WRITE_IDX_STRICT) &&
 		    (i && oideq(&list[-2]->oid, &obj->oid)))
@@ -135,8 +133,7 @@ const char *write_idx_file(const char *index_name, struct pack_idx_entry **objec
 		list = sorted_by_sha;
 		for (i = 0; i < nr_objects; i++) {
 			struct pack_idx_entry *obj = *list++;
-			uint32_t crc32_val = htonl(obj->crc32);
-			hashwrite(f, &crc32_val, 4);
+			hashwrite_be32(f, obj->crc32);
 		}

 		/* write the 32-bit offset table */
@@ -148,8 +145,7 @@ const char *write_idx_file(const char *index_name, struct pack_idx_entry **objec
 			offset = (need_large_offset(obj->offset, opts)
 				  ? (0x80000000 | nr_large_offset++)
 				  : obj->offset);
-			offset = htonl(offset);
-			hashwrite(f, &offset, 4);
+			hashwrite_be32(f, offset);
 		}

 		/* write the large offset table */
--
2.28.0
Next: Derrick Stolee
Message 1 of 2 in “pack-write: use hashwrite_be32() in write_idx_file()”
  1. pack-write: use hashwrite_be32() in write_idx_file()René Scharfe, Sep 19, 2020
  2. Derrick StoleeSep 21, 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.