Skip to content

Commit 72a2bfc

Browse files
abhishekkumar2718gitster
authored andcommitted
commit-graph: add a slab to store topological levels
In a later commit we will introduce corrected commit date as the generation number v2. Corrected commit dates will be stored in the new seperate Generation Data chunk. However, to ensure backwards compatibility with "Old" Git we need to continue to write generation number v1 (topological levels) to the commit data chunk. Thus, we need to compute and store both versions of generation numbers to write the commit-graph file. Therefore, let's introduce a commit-slab `topo_level_slab` to store topological levels; corrected commit date will be stored in the member `generation` of struct commit_graph_data. The macros `GENERATION_NUMBER_INFINITY` and `GENERATION_NUMBER_ZERO` mark commits not in the commit-graph file and commits written by a version of Git that did not compute generation numbers respectively. Generation numbers are computed identically for both kinds of commits. A "slab-miss" should return `GENERATION_NUMBER_INFINITY` as the commit is not in the commit-graph file. However, since the slab is zero-initialized, it returns 0 (or rather `GENERATION_NUMBER_ZERO`). Thus, we no longer need to check if the topological level of a commit is `GENERATION_NUMBER_INFINITY`. We will add a pointer to the slab in `struct write_commit_graph_context` and `struct commit_graph` to populate the slab in `fill_commit_graph_info` if the commit has a pre-computed topological level as in case of split commit-graphs. Signed-off-by: Abhishek Kumar <abhishekkumar8222@gmail.com> Reviewed-by: Taylor Blau <me@ttaylorr.com> Reviewed-by: Derrick Stolee <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent c0ef139 commit 72a2bfc

File tree

2 files changed

+31
-15
lines changed

2 files changed

+31
-15
lines changed

Diff for: commit-graph.c

+30-15
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ void git_test_write_commit_graph_or_die(void)
6464
/* Remember to update object flag allocation in object.h */
6565
#define REACHABLE (1u<<15)
6666

67+
define_commit_slab(topo_level_slab, uint32_t);
68+
6769
/* Keep track of the order in which commits are added to our list. */
6870
define_commit_slab(commit_pos, int);
6971
static struct commit_pos commit_pos = COMMIT_SLAB_INIT(1, commit_pos);
@@ -772,6 +774,9 @@ static void fill_commit_graph_info(struct commit *item, struct commit_graph *g,
772774
item->date = (timestamp_t)((date_high << 32) | date_low);
773775

774776
graph_data->generation = get_be32(commit_data + g->hash_len + 8) >> 2;
777+
778+
if (g->topo_levels)
779+
*topo_level_slab_at(g->topo_levels, item) = get_be32(commit_data + g->hash_len + 8) >> 2;
775780
}
776781

777782
static inline void set_commit_tree(struct commit *c, struct tree *t)
@@ -960,6 +965,7 @@ struct write_commit_graph_context {
960965
changed_paths:1,
961966
order_by_pack:1;
962967

968+
struct topo_level_slab *topo_levels;
963969
const struct commit_graph_opts *opts;
964970
size_t total_bloom_filter_data_size;
965971
const struct bloom_filter_settings *bloom_settings;
@@ -1106,7 +1112,7 @@ static int write_graph_chunk_data(struct hashfile *f,
11061112
else
11071113
packedDate[0] = 0;
11081114

1109-
packedDate[0] |= htonl(commit_graph_data_at(*list)->generation << 2);
1115+
packedDate[0] |= htonl(*topo_level_slab_at(ctx->topo_levels, *list) << 2);
11101116

11111117
packedDate[1] = htonl((*list)->date);
11121118
hashwrite(f, packedDate, 8);
@@ -1336,41 +1342,37 @@ static void compute_generation_numbers(struct write_commit_graph_context *ctx)
13361342
_("Computing commit graph generation numbers"),
13371343
ctx->commits.nr);
13381344
for (i = 0; i < ctx->commits.nr; i++) {
1339-
uint32_t generation = commit_graph_data_at(ctx->commits.list[i])->generation;
1345+
uint32_t level = *topo_level_slab_at(ctx->topo_levels, ctx->commits.list[i]);
13401346

13411347
display_progress(ctx->progress, i + 1);
1342-
if (generation != GENERATION_NUMBER_INFINITY &&
1343-
generation != GENERATION_NUMBER_ZERO)
1348+
if (level != GENERATION_NUMBER_ZERO)
13441349
continue;
13451350

13461351
commit_list_insert(ctx->commits.list[i], &list);
13471352
while (list) {
13481353
struct commit *current = list->item;
13491354
struct commit_list *parent;
13501355
int all_parents_computed = 1;
1351-
uint32_t max_generation = 0;
1356+
uint32_t max_level = 0;
13521357

13531358
for (parent = current->parents; parent; parent = parent->next) {
1354-
generation = commit_graph_data_at(parent->item)->generation;
1359+
level = *topo_level_slab_at(ctx->topo_levels, parent->item);
13551360

1356-
if (generation == GENERATION_NUMBER_INFINITY ||
1357-
generation == GENERATION_NUMBER_ZERO) {
1361+
if (level == GENERATION_NUMBER_ZERO) {
13581362
all_parents_computed = 0;
13591363
commit_list_insert(parent->item, &list);
13601364
break;
1361-
} else if (generation > max_generation) {
1362-
max_generation = generation;
1365+
} else if (level > max_level) {
1366+
max_level = level;
13631367
}
13641368
}
13651369

13661370
if (all_parents_computed) {
1367-
struct commit_graph_data *data = commit_graph_data_at(current);
1368-
1369-
data->generation = max_generation + 1;
13701371
pop_commit(&list);
13711372

1372-
if (data->generation > GENERATION_NUMBER_MAX)
1373-
data->generation = GENERATION_NUMBER_MAX;
1373+
if (max_level > GENERATION_NUMBER_MAX - 1)
1374+
max_level = GENERATION_NUMBER_MAX - 1;
1375+
*topo_level_slab_at(ctx->topo_levels, current) = max_level + 1;
13741376
}
13751377
}
13761378
}
@@ -2106,6 +2108,7 @@ int write_commit_graph(struct object_directory *odb,
21062108
int res = 0;
21072109
int replace = 0;
21082110
struct bloom_filter_settings bloom_settings = DEFAULT_BLOOM_FILTER_SETTINGS;
2111+
struct topo_level_slab topo_levels;
21092112

21102113
prepare_repo_settings(the_repository);
21112114
if (!the_repository->settings.core_commit_graph) {
@@ -2132,6 +2135,18 @@ int write_commit_graph(struct object_directory *odb,
21322135
bloom_settings.max_changed_paths);
21332136
ctx->bloom_settings = &bloom_settings;
21342137

2138+
init_topo_level_slab(&topo_levels);
2139+
ctx->topo_levels = &topo_levels;
2140+
2141+
if (ctx->r->objects->commit_graph) {
2142+
struct commit_graph *g = ctx->r->objects->commit_graph;
2143+
2144+
while (g) {
2145+
g->topo_levels = &topo_levels;
2146+
g = g->base_graph;
2147+
}
2148+
}
2149+
21352150
if (flags & COMMIT_GRAPH_WRITE_BLOOM_FILTERS)
21362151
ctx->changed_paths = 1;
21372152
if (!(flags & COMMIT_GRAPH_NO_WRITE_BLOOM_FILTERS)) {

Diff for: commit-graph.h

+1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ struct commit_graph {
7373
const unsigned char *chunk_bloom_indexes;
7474
const unsigned char *chunk_bloom_data;
7575

76+
struct topo_level_slab *topo_levels;
7677
struct bloom_filter_settings *bloom_filter_settings;
7778
};
7879

0 commit comments

Comments
 (0)