Skip to content

Commit 455e8d1

Browse files
committed
Merge branch 'rs/hashwrite-be64'
Code simplification. * rs/hashwrite-be64: pack-write: use hashwrite_be64() midx: use hashwrite_be64() csum-file: add hashwrite_be64()
2 parents 2557c11 + 970909c commit 455e8d1

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

csum-file.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,11 @@ static inline void hashwrite_be32(struct hashfile *f, uint32_t data)
6262
hashwrite(f, &data, sizeof(data));
6363
}
6464

65+
static inline size_t hashwrite_be64(struct hashfile *f, uint64_t data)
66+
{
67+
data = htonll(data);
68+
hashwrite(f, &data, sizeof(data));
69+
return sizeof(data);
70+
}
71+
6572
#endif

midx.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -785,9 +785,7 @@ static size_t write_midx_large_offsets(struct hashfile *f, uint32_t nr_large_off
785785
if (!(offset >> 31))
786786
continue;
787787

788-
hashwrite_be32(f, offset >> 32);
789-
hashwrite_be32(f, offset & 0xffffffffUL);
790-
written += 2 * sizeof(uint32_t);
788+
written += hashwrite_be64(f, offset);
791789

792790
nr_large_offset--;
793791
}
@@ -975,8 +973,7 @@ static int write_midx_internal(const char *object_dir, struct multi_pack_index *
975973
chunk_offsets[i]);
976974

977975
hashwrite_be32(f, chunk_ids[i]);
978-
hashwrite_be32(f, chunk_offsets[i] >> 32);
979-
hashwrite_be32(f, chunk_offsets[i]);
976+
hashwrite_be64(f, chunk_offsets[i]);
980977

981978
written += MIDX_CHUNKLOOKUP_WIDTH;
982979
}

pack-write.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,13 +151,10 @@ const char *write_idx_file(const char *index_name, struct pack_idx_entry **objec
151151
while (nr_large_offset) {
152152
struct pack_idx_entry *obj = *list++;
153153
uint64_t offset = obj->offset;
154-
uint32_t split[2];
155154

156155
if (!need_large_offset(offset, opts))
157156
continue;
158-
split[0] = htonl(offset >> 32);
159-
split[1] = htonl(offset & 0xffffffff);
160-
hashwrite(f, split, 8);
157+
hashwrite_be64(f, offset);
161158
nr_large_offset--;
162159
}
163160
}

0 commit comments

Comments
 (0)