Skip to content

Commit f39cc49

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. This value 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, which is topological level, to the commit data chunk. This means that we need to compute both versions of generation numbers when writing the commit-graph file. Therefore, let's introduce a commit-slab to store topological levels; corrected commit date will be stored in the member `generation` of struct commit_graph_data. When Git creates a split commit-graph, it takes advantage of the generation values that have been computed already and present in existing commit-graph files. So, let's add a pointer to struct commit_graph as well as struct write_commit_graph_context to the topological level commit-slab and populate it with topological levels while writing a commit-graph file. Signed-off-by: Abhishek Kumar <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e3f4638 commit f39cc49

File tree

2 files changed

+33
-15
lines changed

2 files changed

+33
-15
lines changed

commit-graph.c

Lines changed: 32 additions & 15 deletions
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);
@@ -768,6 +770,9 @@ static void fill_commit_graph_info(struct commit *item, struct commit_graph *g,
768770
item->date = (timestamp_t)((date_high << 32) | date_low);
769771

770772
graph_data->generation = get_be32(commit_data + g->hash_len + 8) >> 2;
773+
774+
if (g->topo_levels)
775+
*topo_level_slab_at(g->topo_levels, item) = get_be32(commit_data + g->hash_len + 8) >> 2;
771776
}
772777

773778
static inline void set_commit_tree(struct commit *c, struct tree *t)
@@ -962,6 +967,7 @@ struct write_commit_graph_context {
962967
changed_paths:1,
963968
order_by_pack:1;
964969

970+
struct topo_level_slab *topo_levels;
965971
const struct commit_graph_opts *opts;
966972
size_t total_bloom_filter_data_size;
967973
const struct bloom_filter_settings *bloom_settings;
@@ -1108,7 +1114,7 @@ static int write_graph_chunk_data(struct hashfile *f,
11081114
else
11091115
packedDate[0] = 0;
11101116

1111-
packedDate[0] |= htonl(commit_graph_data_at(*list)->generation << 2);
1117+
packedDate[0] |= htonl(*topo_level_slab_at(ctx->topo_levels, *list) << 2);
11121118

11131119
packedDate[1] = htonl((*list)->date);
11141120
hashwrite(f, packedDate, 8);
@@ -1350,41 +1356,39 @@ static void compute_generation_numbers(struct write_commit_graph_context *ctx)
13501356
_("Computing commit graph generation numbers"),
13511357
ctx->commits.nr);
13521358
for (i = 0; i < ctx->commits.nr; i++) {
1353-
timestamp_t generation = commit_graph_data_at(ctx->commits.list[i])->generation;
1359+
timestamp_t level = *topo_level_slab_at(ctx->topo_levels, ctx->commits.list[i]);
13541360

13551361
display_progress(ctx->progress, i + 1);
1356-
if (generation != GENERATION_NUMBER_INFINITY &&
1357-
generation != GENERATION_NUMBER_ZERO)
1362+
if (level != GENERATION_NUMBER_INFINITY &&
1363+
level != GENERATION_NUMBER_ZERO)
13581364
continue;
13591365

13601366
commit_list_insert(ctx->commits.list[i], &list);
13611367
while (list) {
13621368
struct commit *current = list->item;
13631369
struct commit_list *parent;
13641370
int all_parents_computed = 1;
1365-
uint32_t max_generation = 0;
1371+
uint32_t max_level = 0;
13661372

13671373
for (parent = current->parents; parent; parent = parent->next) {
1368-
generation = commit_graph_data_at(parent->item)->generation;
1374+
level = *topo_level_slab_at(ctx->topo_levels, parent->item);
13691375

1370-
if (generation == GENERATION_NUMBER_INFINITY ||
1371-
generation == GENERATION_NUMBER_ZERO) {
1376+
if (level == GENERATION_NUMBER_INFINITY ||
1377+
level == GENERATION_NUMBER_ZERO) {
13721378
all_parents_computed = 0;
13731379
commit_list_insert(parent->item, &list);
13741380
break;
1375-
} else if (generation > max_generation) {
1376-
max_generation = generation;
1381+
} else if (level > max_level) {
1382+
max_level = level;
13771383
}
13781384
}
13791385

13801386
if (all_parents_computed) {
1381-
struct commit_graph_data *data = commit_graph_data_at(current);
1382-
1383-
data->generation = max_generation + 1;
13841387
pop_commit(&list);
13851388

1386-
if (data->generation > GENERATION_NUMBER_V1_MAX)
1387-
data->generation = GENERATION_NUMBER_V1_MAX;
1389+
if (max_level > GENERATION_NUMBER_V1_MAX - 1)
1390+
max_level = GENERATION_NUMBER_V1_MAX - 1;
1391+
*topo_level_slab_at(ctx->topo_levels, current) = max_level + 1;
13881392
}
13891393
}
13901394
}
@@ -2142,6 +2146,7 @@ int write_commit_graph(struct object_directory *odb,
21422146
int res = 0;
21432147
int replace = 0;
21442148
struct bloom_filter_settings bloom_settings = DEFAULT_BLOOM_FILTER_SETTINGS;
2149+
struct topo_level_slab topo_levels;
21452150

21462151
if (!commit_graph_compatible(the_repository))
21472152
return 0;
@@ -2163,6 +2168,18 @@ int write_commit_graph(struct object_directory *odb,
21632168
bloom_settings.max_changed_paths);
21642169
ctx->bloom_settings = &bloom_settings;
21652170

2171+
init_topo_level_slab(&topo_levels);
2172+
ctx->topo_levels = &topo_levels;
2173+
2174+
if (ctx->r->objects->commit_graph) {
2175+
struct commit_graph *g = ctx->r->objects->commit_graph;
2176+
2177+
while (g) {
2178+
g->topo_levels = &topo_levels;
2179+
g = g->base_graph;
2180+
}
2181+
}
2182+
21662183
if (flags & COMMIT_GRAPH_WRITE_BLOOM_FILTERS)
21672184
ctx->changed_paths = 1;
21682185
if (!(flags & COMMIT_GRAPH_NO_WRITE_BLOOM_FILTERS)) {

commit-graph.h

Lines changed: 1 addition & 0 deletions
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)