@matheusbsbs / matheus-bagliano / commits / 389cf68caf
Fork 0

pack-write: use hashwrite_be32() in write_idx_file()

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> Signed-off-by: Junio C Hamano <gitster@pobox.com>

René Scharfe committed Sep 19, 2020 at 20:26 UTC 389cf68caf8bc79669133c8744b06092925461e0
1 file changed +4 -8
pack-write.c
+4 -8
@@ -117,10 +117,8 @@ const char *write_idx_file(const char *index_name, struct pack_idx_entry **objec
117 list = sorted_by_sha;
118 for (i = 0; i < nr_objects; i++) {
119 struct pack_idx_entry *obj = *list++;
120 - if (index_version < 2) {
121 - uint32_t offset = htonl(obj->offset);
122 - hashwrite(f, &offset, 4);
123 - }
120 + if (index_version < 2)
121 + hashwrite_be32(f, obj->offset);
122 hashwrite(f, obj->oid.hash, the_hash_algo->rawsz);
123 if ((opts->flags & WRITE_IDX_STRICT) &&
124 (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
133 list = sorted_by_sha;
134 for (i = 0; i < nr_objects; i++) {
135 struct pack_idx_entry *obj = *list++;
138 - uint32_t crc32_val = htonl(obj->crc32);
139 - hashwrite(f, &crc32_val, 4);
136 + hashwrite_be32(f, obj->crc32);
137 }
138
139 /* write the 32-bit offset table */
@@ -148,8 +145,7 @@ const char *write_idx_file(const char *index_name, struct pack_idx_entry **objec
145 offset = (need_large_offset(obj->offset, opts)
146 ? (0x80000000 | nr_large_offset++)
147 : obj->offset);
151 - offset = htonl(offset);
152 - hashwrite(f, &offset, 4);
148 + hashwrite_be32(f, offset);
149 }
150
151 /* write the large offset table */