Skip to content

Commit

Permalink
revindex: export new APIs
Browse files Browse the repository at this point in the history
Allow users to efficiently lookup consecutive entries that are expected
to be found on the same revindex by exporting `find_revindex_position`:
this function takes a pointer to revindex itself, instead of looking up
the proper revindex for a given packfile on each call.

Signed-off-by: Vicent Marti <tanoku@gmail.com>
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Vicent Marti authored and Junio C Hamano committed Oct 24, 2013
1 parent e74435a commit 92e5c77
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 13 deletions.
38 changes: 25 additions & 13 deletions pack-revindex.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@
* get the object sha1 from the main index.
*/

struct pack_revindex {
struct packed_git *p;
struct revindex_entry *revindex;
};

static struct pack_revindex *pack_revindex;
static int pack_revindex_hashsz;

Expand Down Expand Up @@ -201,37 +196,54 @@ static void create_pack_revindex(struct pack_revindex *rix)
sort_revindex(rix->revindex, num_ent, p->pack_size);
}

struct revindex_entry *find_pack_revindex(struct packed_git *p, off_t ofs)
struct pack_revindex *revindex_for_pack(struct packed_git *p)
{
int num;
unsigned lo, hi;
struct pack_revindex *rix;
struct revindex_entry *revindex;

if (!pack_revindex_hashsz)
init_pack_revindex();

num = pack_revindex_ix(p);
if (num < 0)
die("internal error: pack revindex fubar");

rix = &pack_revindex[num];
if (!rix->revindex)
create_pack_revindex(rix);
revindex = rix->revindex;

lo = 0;
hi = p->num_objects + 1;
return rix;
}

int find_revindex_position(struct pack_revindex *pridx, off_t ofs)
{
int lo = 0;
int hi = pridx->p->num_objects + 1;
struct revindex_entry *revindex = pridx->revindex;

do {
unsigned mi = lo + (hi - lo) / 2;
if (revindex[mi].offset == ofs) {
return revindex + mi;
return mi;
} else if (ofs < revindex[mi].offset)
hi = mi;
else
lo = mi + 1;
} while (lo < hi);

error("bad offset for revindex");
return NULL;
return -1;
}

struct revindex_entry *find_pack_revindex(struct packed_git *p, off_t ofs)
{
struct pack_revindex *pridx = revindex_for_pack(p);
int pos = find_revindex_position(pridx, ofs);

if (pos < 0)
return NULL;

return pridx->revindex + pos;
}

void discard_revindex(void)
Expand Down
8 changes: 8 additions & 0 deletions pack-revindex.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ struct revindex_entry {
unsigned int nr;
};

struct pack_revindex {
struct packed_git *p;
struct revindex_entry *revindex;
};

struct pack_revindex *revindex_for_pack(struct packed_git *p);
int find_revindex_position(struct pack_revindex *pridx, off_t ofs);

struct revindex_entry *find_pack_revindex(struct packed_git *p, off_t ofs);
void discard_revindex(void);

Expand Down

0 comments on commit 92e5c77

Please sign in to comment.