aboutsummaryrefslogtreecommitdiff
path: root/sha1_file.c
diff options
context:
space:
mode:
authorNicolas Pitre <nico@cam.org>2007-04-09 01:06:28 -0400
committerJunio C Hamano <junkio@cox.net>2007-04-10 12:48:14 -0700
commit57059091fad25427bce9b3d47e073ce0518d164b (patch)
tree9e51d626819d9eedc260a157774dc8fe1f06f5e4 /sha1_file.c
parent8ff21b1a3307c7059ea1e00b5117a50a2bc5fec8 (diff)
downloadgit-57059091fad25427bce9b3d47e073ce0518d164b.tar.gz
git-57059091fad25427bce9b3d47e073ce0518d164b.tar.xz
get rid of num_packed_objects()
The coming index format change doesn't allow for the number of objects to be determined from the size of the index file directly. Instead, Let's initialize a field in the packed_git structure with the object count when the index is validated since the count is always known at that point. While at it let's reorder some struct packed_git fields to avoid padding due to needed 64-bit alignment for some of them. Signed-off-by: Nicolas Pitre <nico@cam.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
Diffstat (limited to 'sha1_file.c')
-rw-r--r--sha1_file.c17
1 files changed, 6 insertions, 11 deletions
diff --git a/sha1_file.c b/sha1_file.c
index 4304fe9bb..d9ca69a91 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -494,6 +494,7 @@ static int check_packed_git_idx(const char *path, struct packed_git *p)
p->index_version = 1;
p->index_data = idx_map;
p->index_size = idx_size;
+ p->num_objects = nr;
return 0;
}
@@ -605,11 +606,11 @@ static int open_packed_git_1(struct packed_git *p)
p->pack_name, ntohl(hdr.hdr_version));
/* Verify the pack matches its index. */
- if (num_packed_objects(p) != ntohl(hdr.hdr_entries))
+ if (p->num_objects != ntohl(hdr.hdr_entries))
return error("packfile %s claims to have %u objects"
- " while index size indicates %u objects",
- p->pack_name, ntohl(hdr.hdr_entries),
- num_packed_objects(p));
+ " while index indicates %u objects",
+ p->pack_name, ntohl(hdr.hdr_entries),
+ p->num_objects);
if (lseek(p->pack_fd, p->pack_size - sizeof(sha1), SEEK_SET) == -1)
return error("end of packfile %s is unavailable", p->pack_name);
if (read_in_full(p->pack_fd, sha1, sizeof(sha1)) != sizeof(sha1))
@@ -1526,18 +1527,12 @@ void *unpack_entry(struct packed_git *p, off_t obj_offset,
return data;
}
-uint32_t num_packed_objects(const struct packed_git *p)
-{
- /* See check_packed_git_idx() */
- return (uint32_t)((p->index_size - 20 - 20 - 4*256) / 24);
-}
-
const unsigned char *nth_packed_object_sha1(const struct packed_git *p,
uint32_t n)
{
const unsigned char *index = p->index_data;
index += 4 * 256;
- if (num_packed_objects(p) <= n)
+ if (n >= p->num_objects)
return NULL;
return index + 24 * n + 4;
}