Use fixed-size integers for .idx file I/O
This attempts to finish what Simon started in the previous commit. Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Jan 17, 2007 at 23:17 UTC
b18b00a6612a8da12cb14c232a6ab4184cd262dd
3 files changed
+7
-7
builtin-pack-objects.c
+3
-3
@@ -569,7 +569,7 @@ static void write_index_file(void)
569
sha1_to_hex(object_list_sha1), "idx");
570
struct object_entry **list = sorted_by_sha;
571
struct object_entry **last = list + nr_result;
572
- unsigned int array[256];
572
+ uint32_t array[256];
573
574
/*
575
* Write the first-level table (the list is sorted,
@@ -587,7 +587,7 @@ static void write_index_file(void)
587
array[i] = htonl(next - sorted_by_sha);
588
list = next;
589
}
590
- sha1write(f, array, 256 * sizeof(int));
590
+ sha1write(f, array, 256 * 4);
591
592
/*
593
* Write the actual SHA1 entries..
@@ -595,7 +595,7 @@ static void write_index_file(void)
595
list = sorted_by_sha;
596
for (i = 0; i < nr_result; i++) {
597
struct object_entry *entry = *list++;
598
- unsigned int offset = htonl(entry->offset);
598
+ uint32_t offset = htonl(entry->offset);
599
sha1write(f, &offset, 4);
600
sha1write(f, entry->sha1, 20);
601
}
cache.h
+1
-1
@@ -351,7 +351,7 @@ struct pack_window {
351
extern struct packed_git {
352
struct packed_git *next;
353
struct pack_window *windows;
354
- unsigned int *index_base;
354
+ uint32_t *index_base;
355
off_t index_size;
356
off_t pack_size;
357
int pack_fd;
sha1_file.c
+3
-3
@@ -435,7 +435,7 @@ static int check_packed_git_idx(const char *path, unsigned long *idx_size_,
435
void **idx_map_)
436
{
437
void *idx_map;
438
- unsigned int *index;
438
+ uint32_t *index;
439
unsigned long idx_size;
440
int nr, i;
441
int fd = open(path, O_RDONLY);
@@ -1351,7 +1351,7 @@ int nth_packed_object_sha1(const struct packed_git *p, int n,
1351
unsigned long find_pack_entry_one(const unsigned char *sha1,
1352
struct packed_git *p)
1353
{
1354
- unsigned int *level1_ofs = p->index_base;
1354
+ uint32_t *level1_ofs = p->index_base;
1355
int hi = ntohl(level1_ofs[*sha1]);
1356
int lo = ((*sha1 == 0x0) ? 0 : ntohl(level1_ofs[*sha1 - 1]));
1357
void *index = p->index_base + 256;
@@ -1360,7 +1360,7 @@ unsigned long find_pack_entry_one(const unsigned char *sha1,
1360
int mi = (lo + hi) / 2;
1361
int cmp = hashcmp((unsigned char *)index + (24 * mi) + 4, sha1);
1362
if (!cmp)
1363
- return ntohl(*((unsigned int *) ((char *) index + (24 * mi))));
1363
+ return ntohl(*((uint32_t *)((char *)index + (24 * mi))));
1364
if (cmp > 0)
1365
hi = mi;
1366
else