|
8 | 8 | * size is easily available by examining the pack entry header). It is
|
9 | 9 | * also rather expensive to find the sha1 for an object given its offset.
|
10 | 10 | *
|
11 |
| - * We build a hashtable of existing packs (pack_revindex), and keep reverse |
12 |
| - * index here -- pack index file is sorted by object name mapping to offset; |
13 |
| - * this pack_revindex[].revindex array is a list of offset/index_nr pairs |
| 11 | + * The pack index file is sorted by object name mapping to offset; |
| 12 | + * this revindex array is a list of offset/index_nr pairs |
14 | 13 | * ordered by offset, so if you know the offset of an object, next offset
|
15 | 14 | * is where its packed representation ends and the index_nr can be used to
|
16 | 15 | * get the object sha1 from the main index.
|
17 | 16 | */
|
18 | 17 |
|
19 |
| -static struct pack_revindex *pack_revindex; |
20 |
| -static int pack_revindex_hashsz; |
21 |
| - |
22 |
| -static int pack_revindex_ix(struct packed_git *p) |
23 |
| -{ |
24 |
| - unsigned long ui = (unsigned long)p; |
25 |
| - int i; |
26 |
| - |
27 |
| - ui = ui ^ (ui >> 16); /* defeat structure alignment */ |
28 |
| - i = (int)(ui % pack_revindex_hashsz); |
29 |
| - while (pack_revindex[i].p) { |
30 |
| - if (pack_revindex[i].p == p) |
31 |
| - return i; |
32 |
| - if (++i == pack_revindex_hashsz) |
33 |
| - i = 0; |
34 |
| - } |
35 |
| - return -1 - i; |
36 |
| -} |
37 |
| - |
38 |
| -static void init_pack_revindex(void) |
39 |
| -{ |
40 |
| - int num; |
41 |
| - struct packed_git *p; |
42 |
| - |
43 |
| - for (num = 0, p = packed_git; p; p = p->next) |
44 |
| - num++; |
45 |
| - if (!num) |
46 |
| - return; |
47 |
| - pack_revindex_hashsz = num * 11; |
48 |
| - pack_revindex = xcalloc(sizeof(*pack_revindex), pack_revindex_hashsz); |
49 |
| - for (p = packed_git; p; p = p->next) { |
50 |
| - num = pack_revindex_ix(p); |
51 |
| - num = - 1 - num; |
52 |
| - pack_revindex[num].p = p; |
53 |
| - } |
54 |
| - /* revindex elements are lazily initialized */ |
55 |
| -} |
56 |
| - |
57 | 18 | /*
|
58 | 19 | * This is a least-significant-digit radix sort.
|
59 | 20 | *
|
@@ -198,20 +159,11 @@ static void create_pack_revindex(struct pack_revindex *rix)
|
198 | 159 |
|
199 | 160 | struct pack_revindex *revindex_for_pack(struct packed_git *p)
|
200 | 161 | {
|
201 |
| - int num; |
202 |
| - struct pack_revindex *rix; |
203 |
| - |
204 |
| - if (!pack_revindex_hashsz) |
205 |
| - init_pack_revindex(); |
206 |
| - |
207 |
| - num = pack_revindex_ix(p); |
208 |
| - if (num < 0) |
209 |
| - die("internal error: pack revindex fubar"); |
210 |
| - |
211 |
| - rix = &pack_revindex[num]; |
212 |
| - if (!rix->revindex) |
| 162 | + struct pack_revindex *rix = &p->reverse_index; |
| 163 | + if (!rix->revindex) { |
| 164 | + rix->p = p; |
213 | 165 | create_pack_revindex(rix);
|
214 |
| - |
| 166 | + } |
215 | 167 | return rix;
|
216 | 168 | }
|
217 | 169 |
|
|
0 commit comments