path: root/pack-check.c
diff options
authorShawn O. Pearce <>2006-12-23 07:34:08 (GMT)
committerJunio C Hamano <>2006-12-29 19:36:44 (GMT)
commit03e79c88aa34ce188eb4fb7509e6d127c79c507d (patch)
treee3d6134907c7f7adf1e89c14d107c96b0a43a404 /pack-check.c
parent9bc879c1ced505089e2a1e420d32599bb15b35b5 (diff)
Replace use_packed_git with window cursors.
Part of the implementation concept of the sliding mmap window for pack access is to permit multiple windows per pack to be mapped independently. Since the inuse_cnt is associated with the mmap and not with the file, this value is in struct pack_window and needs to be incremented/decremented for each pack_window accessed by any code. To faciliate that implementation we need to replace all uses of use_packed_git() and unuse_packed_git() with a different API that follows struct pack_window objects rather than struct packed_git. The way this works is when we need to start accessing a pack for the first time we should setup a new window 'cursor' by declaring a local and setting it to NULL: struct pack_windows *w_curs = NULL; To obtain the memory region which contains a specific section of the pack file we invoke use_pack(), supplying the address of our current window cursor: unsigned int len; unsigned char *addr = use_pack(p, &w_curs, offset, &len); the returned address `addr` will be the first byte at `offset` within the pack file. The optional variable len will also be updated with the number of bytes remaining following the address. Multiple calls to use_pack() with the same window cursor will update the window cursor, moving it from one window to another when necessary. In this way each window cursor variable maintains only one struct pack_window inuse at a time. Finally before exiting the scope which originally declared the window cursor we must invoke unuse_pack() to unuse the current window (which may be different from the one that was first obtained from use_pack): unuse_pack(&w_curs); This implementation is still not complete with regards to multiple windows, as only one window per pack file is supported right now. Signed-off-by: Shawn O. Pearce <> Signed-off-by: Junio C Hamano <>
Diffstat (limited to 'pack-check.c')
1 files changed, 12 insertions, 10 deletions
diff --git a/pack-check.c b/pack-check.c
index 761cc85..972916f 100644
--- a/pack-check.c
+++ b/pack-check.c
@@ -1,7 +1,8 @@
#include "cache.h"
#include "pack.h"
-static int verify_packfile(struct packed_git *p)
+static int verify_packfile(struct packed_git *p,
+ struct pack_window **w_curs)
unsigned long index_size = p->index_size;
void *index_base = p->index_base;
@@ -13,7 +14,7 @@ static int verify_packfile(struct packed_git *p)
int nr_objects, err, i;
/* Header consistency check */
- pack_base = p->windows->base;
+ pack_base = use_pack(p, w_curs, 0, NULL);
hdr = (struct pack_header*)pack_base;
if (hdr->hdr_signature != htonl(PACK_SIGNATURE))
return error("Packfile %s signature mismatch", p->pack_name);
@@ -72,13 +73,14 @@ static int verify_packfile(struct packed_git *p)
#define MAX_CHAIN 40
-static void show_pack_info(struct packed_git *p)
+static void show_pack_info(struct packed_git *p,
+ struct pack_window **w_curs)
struct pack_header *hdr;
int nr_objects, i;
unsigned int chain_histogram[MAX_CHAIN];
- hdr = (struct pack_header*)p->windows->base;
+ hdr = (struct pack_header*)use_pack(p, w_curs, 0, NULL);
nr_objects = ntohl(hdr->hdr_entries);
memset(chain_histogram, 0, sizeof(chain_histogram));
@@ -142,18 +144,18 @@ int verify_pack(struct packed_git *p, int verbose)
if (!ret) {
/* Verify pack file */
- use_packed_git(p);
- ret = verify_packfile(p);
- unuse_packed_git(p);
+ struct pack_window *w_curs = NULL;
+ ret = verify_packfile(p, &w_curs);
+ unuse_pack(&w_curs);
if (verbose) {
if (ret)
printf("%s: bad\n", p->pack_name);
else {
- use_packed_git(p);
- show_pack_info(p);
- unuse_packed_git(p);
+ struct pack_window *w_curs = NULL;
+ show_pack_info(p, &w_curs);
+ unuse_pack(&w_curs);
printf("%s: ok\n", p->pack_name);