@@ -1784,12 +1784,8 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx)
chunk_offset = 8 + (num_chunks + 1) * GRAPH_CHUNKLOOKUP_WIDTH;
for (i = 0; i <= num_chunks; i++) {
- uint32_t chunk_write[3];
-
- chunk_write[0] = htonl(chunks[i].id);
- chunk_write[1] = htonl(chunk_offset >> 32);
- chunk_write[2] = htonl(chunk_offset & 0xffffffff);
- hashwrite(f, chunk_write, 12);
+ hashwrite_be32(f, chunks[i].id);
+ hashwrite_be64(f, chunk_offset);
chunk_offset += chunks[i].size;
}
@@ -62,4 +62,10 @@ static inline void hashwrite_be32(struct hashfile *f, uint32_t data)
hashwrite(f, &data, sizeof(data));
}
+static inline void hashwrite_be64(struct hashfile *f, uint64_t data)
+{
+ hashwrite_be32(f, data >> 32);
+ hashwrite_be32(f, data & 0xffffffffUL);
+}
+
#endif
@@ -775,8 +775,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);
+ hashwrite_be64(f, offset);
written += 2 * sizeof(uint32_t);
nr_large_offset--;
A small handful of writers who wish to encode 64-bit values in network order have worked around the lack of such a helper by calling the 32-bit variant twice. The subsequent commit will add another caller who wants to write a 64-bit value. To ease their (and the existing caller's) pain, introduce a helper to do just that, and convert existing call-sites. Suggested-by: Derrick Stolee <dstolee@microsoft.com> Signed-off-by: Taylor Blau <me@ttaylorr.com> --- commit-graph.c | 8 ++------ csum-file.h | 6 ++++++ midx.c | 3 +-- 3 files changed, 9 insertions(+), 8 deletions(-)