Skip to content

Commit 0f81b9c

Browse files
ttaylorrgitster
authored andcommitted
pseudo-merge: scaffolding for reads
Implement scaffolding within the new pseudo-merge compilation unit necessary to use the pseudo-merge API from within the pack-bitmap.c machinery. The core of this scaffolding is two-fold: - The `pseudo_merge` structure itself, which represents an individual pseudo-merge bitmap. It has fields for both bitmaps, as well as metadata about its position within the memory-mapped region, and a few extra bits indicating whether or not it is satisfied, and which bitmaps(s, if any) have been read, since they are initialized lazily. - The `pseudo_merge_map` structure, which holds an array of pseudo_merges, as well as a pointer to the memory-mapped region containing the pseudo-merge serialization from within a .bitmap file. Note that the `bitmap_index` structure is defined statically within the pack-bitmap.o compilation unit, so we can't take in a `struct bitmap_index *`. Instead, wrap the primary components necessary to read the pseudo-merges in this new structure to avoid exposing the implementation details of the `bitmap_index` structure. Signed-off-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 79621f3 commit 0f81b9c

File tree

2 files changed

+75
-0
lines changed

2 files changed

+75
-0
lines changed

pseudo-merge.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,3 +454,13 @@ void select_pseudo_merges(struct bitmap_writer *writer,
454454

455455
stop_progress(&progress);
456456
}
457+
458+
void free_pseudo_merge_map(struct pseudo_merge_map *pm)
459+
{
460+
uint32_t i;
461+
for (i = 0; i < pm->nr; i++) {
462+
ewah_pool_free(pm->v[i].commits);
463+
ewah_pool_free(pm->v[i].bitmap);
464+
}
465+
free(pm->v);
466+
}

pseudo-merge.h

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,69 @@ struct pseudo_merge_commit_idx {
9797
void select_pseudo_merges(struct bitmap_writer *writer,
9898
struct commit **commits, size_t commits_nr);
9999

100+
/*
101+
* Represents a serialized view of a file containing pseudo-merge(s)
102+
* (see Documentation/technical/bitmap-format.txt for a specification
103+
* of the format).
104+
*/
105+
struct pseudo_merge_map {
106+
/*
107+
* An array of pseudo-merge(s), lazily loaded from the .bitmap
108+
* file.
109+
*/
110+
struct pseudo_merge *v;
111+
size_t nr;
112+
size_t commits_nr;
113+
114+
/*
115+
* Pointers into a memory-mapped view of the .bitmap file:
116+
*
117+
* - map: the beginning of the .bitmap file
118+
* - commits: the beginning of the pseudo-merge commit index
119+
* - map_size: the size of the .bitmap file
120+
*/
121+
const unsigned char *map;
122+
const unsigned char *commits;
123+
124+
size_t map_size;
125+
};
126+
127+
/*
128+
* An individual pseudo-merge, storing a pair of lazily-loaded
129+
* bitmaps:
130+
*
131+
* - commits: the set of commit(s) that are part of the pseudo-merge
132+
* - bitmap: the set of object(s) reachable from the above set of
133+
* commits.
134+
*
135+
* The `at` and `bitmap_at` fields are used to store the locations of
136+
* each of the above bitmaps in the .bitmap file.
137+
*/
138+
struct pseudo_merge {
139+
struct ewah_bitmap *commits;
140+
struct ewah_bitmap *bitmap;
141+
142+
off_t at;
143+
off_t bitmap_at;
144+
145+
/*
146+
* `satisfied` indicates whether the given pseudo-merge has been
147+
* used.
148+
*
149+
* `loaded_commits` and `loaded_bitmap` indicate whether the
150+
* respective bitmaps have been loaded and read from the
151+
* .bitmap file.
152+
*/
153+
unsigned satisfied : 1,
154+
loaded_commits : 1,
155+
loaded_bitmap : 1;
156+
};
157+
158+
/*
159+
* Frees the given pseudo-merge map, releasing any memory held by (a)
160+
* parsed EWAH bitmaps, or (b) the array of pseudo-merges itself. Does
161+
* not free the memory-mapped view of the .bitmap file.
162+
*/
163+
void free_pseudo_merge_map(struct pseudo_merge_map *pm);
164+
100165
#endif

0 commit comments

Comments
 (0)