Change the interface of the pack index search function In particular, on a successful search, we now return the index entry number of the object rather than the '.pack' file offset. Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
diff --git a/src/odb.c b/src/odb.c
index 47015c6..87a63e9 100644
--- a/src/odb.c
+++ b/src/odb.c
@@ -37,7 +37,7 @@ struct git_pack {
/** Functions to access idx_map. */
int (*idx_search)(
- off_t *,
+ uint32_t *,
struct git_pack *,
const git_oid *);
@@ -663,20 +663,20 @@ static int pack_openidx_map(git_pack *p)
return GIT_SUCCESS;
}
-static int idxv1_search(off_t *out, git_pack *p, const git_oid *id)
+static int idxv1_search(uint32_t *out, git_pack *p, const git_oid *id)
{
unsigned char *data = p->im_oid;
- size_t lo = id->id[0] ? p->im_fanout[id->id[0] - 1] : 0;
- size_t hi = p->im_fanout[id->id[0]];
+ uint32_t lo = id->id[0] ? p->im_fanout[id->id[0] - 1] : 0;
+ uint32_t hi = p->im_fanout[id->id[0]];
do {
- size_t mid = (lo + hi) >> 1;
- size_t pos = 24 * mid;
+ uint32_t mid = (lo + hi) >> 1;
+ uint32_t pos = 24 * mid;
int cmp = memcmp(id->id, data + pos + 4, 20);
if (cmp < 0)
hi = mid;
else if (!cmp) {
- *out = decode32(data + pos);
+ *out = mid;
return GIT_SUCCESS;
} else
lo = mid + 1;
@@ -716,24 +716,20 @@ static int pack_openidx_v1(git_pack *p)
return GIT_SUCCESS;
}
-static int idxv2_search(off_t *out, git_pack *p, const git_oid *id)
+static int idxv2_search(uint32_t *out, git_pack *p, const git_oid *id)
{
unsigned char *data = p->im_oid;
- size_t lo = id->id[0] ? p->im_fanout[id->id[0] - 1] : 0;
- size_t hi = p->im_fanout[id->id[0]];
+ uint32_t lo = id->id[0] ? p->im_fanout[id->id[0] - 1] : 0;
+ uint32_t hi = p->im_fanout[id->id[0]];
do {
- size_t mid = (lo + hi) >> 1;
- size_t pos = 20 * mid;
+ uint32_t mid = (lo + hi) >> 1;
+ uint32_t pos = 20 * mid;
int cmp = memcmp(id->id, data + pos, 20);
if (cmp < 0)
hi = mid;
else if (!cmp) {
- uint32_t o32 = decode32(p->im_offset32 + mid);
- if (o32 & 0x80000000)
- *out = decode64(p->im_offset64 + 2*(o32 & ~0x80000000));
- else
- *out = o32;
+ *out = mid;
return GIT_SUCCESS;
} else
lo = mid + 1;
@@ -977,7 +973,7 @@ static git_packlist *packlist_get(git_odb *db)
return pl;
}
-static int search_packs(git_pack **p, off_t *offset, git_odb *db, const git_oid *id)
+static int search_packs(git_pack **p, uint32_t *n, git_odb *db, const git_oid *id)
{
git_packlist *pl = packlist_get(db);
size_t j;
@@ -988,7 +984,7 @@ static int search_packs(git_pack **p, off_t *offset, git_odb *db, const git_oid
for (j = 0; j < pl->n_packs; j++) {
git_pack *pack = pl->packs[j];
- off_t pos;
+ uint32_t pos;
int res;
if (pack_openidx(pack))
@@ -1000,8 +996,8 @@ static int search_packs(git_pack **p, off_t *offset, git_odb *db, const git_oid
packlist_dec(db, pl);
if (p)
*p = pack;
- if (offset)
- *offset = pos;
+ if (n)
+ *n = pos;
return GIT_SUCCESS;
}
@@ -1132,18 +1128,18 @@ int git_odb__read_loose(git_obj *out, git_odb *db, const git_oid *id)
static int read_packed(git_obj *out, git_pack *p, const git_oid *id)
{
- off_t pos;
+ uint32_t n;
int res;
assert(out && p && id);
if (pack_openidx(p))
return GIT_ERROR;
- res = p->idx_search(&pos, p, id);
+ res = p->idx_search(&n, p, id);
pack_decidx(p);
if (!res) {
- /* TODO unpack object at pos */
+ /* TODO unpack object */
res = GIT_ERROR;
}