summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 8ff21b1)
raw | patch | inline | side by side (parent: 8ff21b1)
author | Nicolas Pitre <nico@cam.org> | |
Mon, 9 Apr 2007 05:06:28 +0000 (01:06 -0400) | ||
committer | Junio C Hamano <junkio@cox.net> | |
Tue, 10 Apr 2007 19:48:14 +0000 (12:48 -0700) |
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>
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>
builtin-count-objects.c | patch | blob | history | |
builtin-fsck.c | patch | blob | history | |
builtin-pack-objects.c | patch | blob | history | |
cache.h | patch | blob | history | |
pack-check.c | patch | blob | history | |
sha1_file.c | patch | blob | history | |
sha1_name.c | patch | blob | history |
index 6263d8af295a5abce3e417157af7cb41e3623f38..ff90ebd465002882781507ecfcfc33cab2f759fc 100644 (file)
--- a/builtin-count-objects.c
+++ b/builtin-count-objects.c
for (p = packed_git; p; p = p->next) {
if (!p->pack_local)
continue;
- packed += num_packed_objects(p);
+ packed += p->num_objects;
num_pack++;
}
printf("count: %lu\n", loose);
diff --git a/builtin-fsck.c b/builtin-fsck.c
index 4d8b66c344422dd60c72c72bbfbc5aa87be7907e..44a02d3120128d4956604c4254fbdd9809a36833 100644 (file)
--- a/builtin-fsck.c
+++ b/builtin-fsck.c
verify_pack(p, 0);
for (p = packed_git; p; p = p->next) {
- uint32_t i, num = num_packed_objects(p);
+ uint32_t i, num = p->num_objects;
for (i = 0; i < num; i++)
fsck_sha1(nth_packed_object_sha1(p, i));
}
diff --git a/builtin-pack-objects.c b/builtin-pack-objects.c
index 45ac3e482acc1c0f8f2bad043f1ba50019dec505..6bff17b130b6a4aa4cbde44164f4e56b5893975d 100644 (file)
--- a/builtin-pack-objects.c
+++ b/builtin-pack-objects.c
static void prepare_pack_revindex(struct pack_revindex *rix)
{
struct packed_git *p = rix->p;
- int num_ent = num_packed_objects(p);
+ int num_ent = p->num_objects;
int i;
const char *index = p->index_data;
prepare_pack_revindex(rix);
revindex = rix->revindex;
lo = 0;
- hi = num_packed_objects(p) + 1;
+ hi = p->num_objects + 1;
do {
int mi = (lo + hi) / 2;
if (revindex[mi].offset == ofs) {
index eb57507b804019f7d6b27a27a2b262d4b051e43b..5b67f4c9895be0127a1228a87bd2d173ba430b44 100644 (file)
--- a/cache.h
+++ b/cache.h
extern struct packed_git {
struct packed_git *next;
struct pack_window *windows;
- const void *index_data;
- off_t index_size;
off_t pack_size;
- time_t mtime;
+ const void *index_data;
+ size_t index_size;
+ uint32_t num_objects;
int index_version;
+ time_t mtime;
int pack_fd;
int pack_local;
unsigned char sha1[20];
extern unsigned char* use_pack(struct packed_git *, struct pack_window **, off_t, unsigned int *);
extern void unuse_pack(struct pack_window **);
extern struct packed_git *add_packed_git(const char *, int, int);
-extern uint32_t num_packed_objects(const struct packed_git *p);
extern const unsigned char *nth_packed_object_sha1(const struct packed_git *, uint32_t);
extern off_t find_pack_entry_one(const unsigned char *, struct packed_git *);
extern void *unpack_entry(struct packed_git *, off_t, enum object_type *, unsigned long *);
diff --git a/pack-check.c b/pack-check.c
index f58083d11e0cfb974861d340bdea4ae18d2469e8..d04536bbff7cba22ca67521d45e690dfa5aa8675 100644 (file)
--- a/pack-check.c
+++ b/pack-check.c
* have verified that nr_objects matches between idx and pack,
* we do not do scan-streaming check on the pack file.
*/
- nr_objects = num_packed_objects(p);
+ nr_objects = p->num_objects;
for (i = 0, err = 0; i < nr_objects; i++) {
const unsigned char *sha1;
void *data;
{
uint32_t nr_objects, i, chain_histogram[MAX_CHAIN];
- nr_objects = num_packed_objects(p);
+ nr_objects = p->num_objects;
memset(chain_histogram, 0, sizeof(chain_histogram));
for (i = 0; i < nr_objects; i++) {
diff --git a/sha1_file.c b/sha1_file.c
index 4304fe9bbc2b8e796e944fa7ddb2ea2791000adf..d9ca69a916f9a9699deb7d9972a0c6f491755f9d 100644 (file)
--- a/sha1_file.c
+++ b/sha1_file.c
p->index_version = 1;
p->index_data = idx_map;
p->index_size = idx_size;
+ p->num_objects = nr;
return 0;
}
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))
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;
}
diff --git a/sha1_name.c b/sha1_name.c
index 267ea3f3edc63600bc1591d2115ee85222f3e8c5..b0b12bbe9de11403c5965518026433c8851e092b 100644 (file)
--- a/sha1_name.c
+++ b/sha1_name.c
prepare_packed_git();
for (p = packed_git; p && found < 2; p = p->next) {
- uint32_t num = num_packed_objects(p);
+ uint32_t num = p->num_objects;
uint32_t first = 0, last = num;
while (first < last) {
uint32_t mid = (first + last) / 2;