Skip to content

Commit 6c9690a

Browse files
committed
Merge branch 'ps/commit-graph-per-object-source' into next
Declare commit-graph is per object_source, which may not be a good idea. * ps/commit-graph-per-object-source: commit-graph: pass graphs that are to be merged as parameter commit-graph: return commit graph from `repo_find_commit_pos_in_graph()` commit-graph: return the prepared commit graph from `prepare_commit_graph()` revision: drop explicit check for commit graph blame: drop explicit check for commit graph
2 parents 5b991a7 + 62490b6 commit 6c9690a

File tree

5 files changed

+64
-78
lines changed

5 files changed

+64
-78
lines changed

blame.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2909,9 +2909,6 @@ void setup_blame_bloom_data(struct blame_scoreboard *sb)
29092909
struct blame_bloom_data *bd;
29102910
struct bloom_filter_settings *bs;
29112911

2912-
if (!sb->repo->objects->commit_graph)
2913-
return;
2914-
29152912
bs = get_bloom_filter_settings(sb->repo);
29162913
if (!bs)
29172914
return;

bloom.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -452,10 +452,12 @@ struct bloom_filter *get_or_compute_bloom_filter(struct repository *r,
452452
filter = bloom_filter_slab_at(&bloom_filters, c);
453453

454454
if (!filter->data) {
455+
struct commit_graph *g;
455456
uint32_t graph_pos;
456-
if (repo_find_commit_pos_in_graph(r, c, &graph_pos))
457-
load_bloom_filter_from_graph(r->objects->commit_graph,
458-
filter, graph_pos);
457+
458+
g = repo_find_commit_pos_in_graph(r, c, &graph_pos);
459+
if (g)
460+
load_bloom_filter_from_graph(g, filter, graph_pos);
459461
}
460462

461463
if (filter->data && filter->len) {

commit-graph.c

Lines changed: 53 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,7 @@ struct commit_graph *read_commit_graph_one(struct odb_source *source)
735735
* On the first invocation, this function attempts to load the commit
736736
* graph if the repository is configured to have one.
737737
*/
738-
static int prepare_commit_graph(struct repository *r)
738+
static struct commit_graph *prepare_commit_graph(struct repository *r)
739739
{
740740
struct odb_source *source;
741741

@@ -747,10 +747,10 @@ static int prepare_commit_graph(struct repository *r)
747747
* we want to disable even an already-loaded graph file.
748748
*/
749749
if (!r->gitdir || r->commit_graph_disabled)
750-
return 0;
750+
return NULL;
751751

752752
if (r->objects->commit_graph_attempted)
753-
return !!r->objects->commit_graph;
753+
return r->objects->commit_graph;
754754
r->objects->commit_graph_attempted = 1;
755755

756756
prepare_repo_settings(r);
@@ -763,10 +763,10 @@ static int prepare_commit_graph(struct repository *r)
763763
* so that commit graph loading is not attempted again for this
764764
* repository.)
765765
*/
766-
return 0;
766+
return NULL;
767767

768768
if (!commit_graph_compatible(r))
769-
return 0;
769+
return NULL;
770770

771771
odb_prepare_alternates(r->objects);
772772
for (source = r->objects->sources; source; source = source->next) {
@@ -775,20 +775,17 @@ static int prepare_commit_graph(struct repository *r)
775775
break;
776776
}
777777

778-
return !!r->objects->commit_graph;
778+
return r->objects->commit_graph;
779779
}
780780

781781
int generation_numbers_enabled(struct repository *r)
782782
{
783783
uint32_t first_generation;
784784
struct commit_graph *g;
785-
if (!prepare_commit_graph(r))
786-
return 0;
787-
788-
g = r->objects->commit_graph;
789785

790-
if (!g->num_commits)
791-
return 0;
786+
g = prepare_commit_graph(r);
787+
if (!g || !g->num_commits)
788+
return 0;
792789

793790
first_generation = get_be32(g->chunk_commit_data +
794791
g->hash_algo->rawsz + 8) >> 2;
@@ -799,12 +796,9 @@ int generation_numbers_enabled(struct repository *r)
799796
int corrected_commit_dates_enabled(struct repository *r)
800797
{
801798
struct commit_graph *g;
802-
if (!prepare_commit_graph(r))
803-
return 0;
804-
805-
g = r->objects->commit_graph;
806799

807-
if (!g->num_commits)
800+
g = prepare_commit_graph(r);
801+
if (!g || !g->num_commits)
808802
return 0;
809803

810804
return g->read_generation_data;
@@ -1014,26 +1008,32 @@ static int find_commit_pos_in_graph(struct commit *item, struct commit_graph *g,
10141008
}
10151009
}
10161010

1017-
int repo_find_commit_pos_in_graph(struct repository *r, struct commit *c,
1018-
uint32_t *pos)
1011+
struct commit_graph *repo_find_commit_pos_in_graph(struct repository *r,
1012+
struct commit *c,
1013+
uint32_t *pos)
10191014
{
1020-
if (!prepare_commit_graph(r))
1021-
return 0;
1022-
return find_commit_pos_in_graph(c, r->objects->commit_graph, pos);
1015+
struct commit_graph *g = prepare_commit_graph(r);
1016+
if (!g)
1017+
return NULL;
1018+
if (!find_commit_pos_in_graph(c, g, pos))
1019+
return NULL;
1020+
return g;
10231021
}
10241022

10251023
struct commit *lookup_commit_in_graph(struct repository *repo, const struct object_id *id)
10261024
{
10271025
static int commit_graph_paranoia = -1;
1026+
struct commit_graph *g;
10281027
struct commit *commit;
10291028
uint32_t pos;
10301029

10311030
if (commit_graph_paranoia == -1)
10321031
commit_graph_paranoia = git_env_bool(GIT_COMMIT_GRAPH_PARANOIA, 0);
10331032

1034-
if (!prepare_commit_graph(repo))
1033+
g = prepare_commit_graph(repo);
1034+
if (!g)
10351035
return NULL;
1036-
if (!search_commit_pos_in_graph(id, repo->objects->commit_graph, &pos))
1036+
if (!search_commit_pos_in_graph(id, g, &pos))
10371037
return NULL;
10381038
if (commit_graph_paranoia && !odb_has_object(repo->objects, id, 0))
10391039
return NULL;
@@ -1044,7 +1044,7 @@ struct commit *lookup_commit_in_graph(struct repository *repo, const struct obje
10441044
if (commit->object.parsed)
10451045
return commit;
10461046

1047-
if (!fill_commit_in_graph(commit, repo->objects->commit_graph, pos))
1047+
if (!fill_commit_in_graph(commit, g, pos))
10481048
return NULL;
10491049

10501050
return commit;
@@ -1067,23 +1067,28 @@ static int parse_commit_in_graph_one(struct commit_graph *g,
10671067
int parse_commit_in_graph(struct repository *r, struct commit *item)
10681068
{
10691069
static int checked_env = 0;
1070+
struct commit_graph *g;
10701071

10711072
if (!checked_env &&
10721073
git_env_bool(GIT_TEST_COMMIT_GRAPH_DIE_ON_PARSE, 0))
10731074
die("dying as requested by the '%s' variable on commit-graph parse!",
10741075
GIT_TEST_COMMIT_GRAPH_DIE_ON_PARSE);
10751076
checked_env = 1;
10761077

1077-
if (!prepare_commit_graph(r))
1078+
g = prepare_commit_graph(r);
1079+
if (!g)
10781080
return 0;
1079-
return parse_commit_in_graph_one(r->objects->commit_graph, item);
1081+
return parse_commit_in_graph_one(g, item);
10801082
}
10811083

10821084
void load_commit_graph_info(struct repository *r, struct commit *item)
10831085
{
1086+
struct commit_graph *g;
10841087
uint32_t pos;
1085-
if (repo_find_commit_pos_in_graph(r, item, &pos))
1086-
fill_commit_graph_info(item, r->objects->commit_graph, pos);
1088+
1089+
g = repo_find_commit_pos_in_graph(r, item, &pos);
1090+
if (g)
1091+
fill_commit_graph_info(item, g, pos);
10871092
}
10881093

10891094
static struct tree *load_tree_for_commit(struct commit_graph *g,
@@ -2226,7 +2231,8 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx)
22262231
return 0;
22272232
}
22282233

2229-
static void split_graph_merge_strategy(struct write_commit_graph_context *ctx)
2234+
static void split_graph_merge_strategy(struct write_commit_graph_context *ctx,
2235+
struct commit_graph *graph_to_merge)
22302236
{
22312237
struct commit_graph *g;
22322238
uint32_t num_commits;
@@ -2245,7 +2251,7 @@ static void split_graph_merge_strategy(struct write_commit_graph_context *ctx)
22452251
flags = ctx->opts->split_flags;
22462252
}
22472253

2248-
g = ctx->r->objects->commit_graph;
2254+
g = graph_to_merge;
22492255
num_commits = ctx->commits.nr;
22502256
if (flags == COMMIT_GRAPH_SPLIT_REPLACE)
22512257
ctx->num_commit_graphs_after = 1;
@@ -2297,7 +2303,7 @@ static void split_graph_merge_strategy(struct write_commit_graph_context *ctx)
22972303
ctx->commit_graph_filenames_after[i] = xstrdup(ctx->commit_graph_filenames_before[i]);
22982304

22992305
i = ctx->num_commit_graphs_before - 1;
2300-
g = ctx->r->objects->commit_graph;
2306+
g = graph_to_merge;
23012307

23022308
while (g) {
23032309
if (i < ctx->num_commit_graphs_after)
@@ -2395,9 +2401,9 @@ static void sort_and_scan_merged_commits(struct write_commit_graph_context *ctx)
23952401
stop_progress(&ctx->progress);
23962402
}
23972403

2398-
static void merge_commit_graphs(struct write_commit_graph_context *ctx)
2404+
static void merge_commit_graphs(struct write_commit_graph_context *ctx,
2405+
struct commit_graph *g)
23992406
{
2400-
struct commit_graph *g = ctx->r->objects->commit_graph;
24012407
uint32_t current_graph_number = ctx->num_commit_graphs_before;
24022408

24032409
while (g && current_graph_number >= ctx->num_commit_graphs_after) {
@@ -2524,6 +2530,7 @@ int write_commit_graph(struct odb_source *source,
25242530
int replace = 0;
25252531
struct bloom_filter_settings bloom_settings = DEFAULT_BLOOM_FILTER_SETTINGS;
25262532
struct topo_level_slab topo_levels;
2533+
struct commit_graph *g;
25272534

25282535
prepare_repo_settings(r);
25292536
if (!r->settings.core_commit_graph) {
@@ -2552,23 +2559,13 @@ int write_commit_graph(struct odb_source *source,
25522559
init_topo_level_slab(&topo_levels);
25532560
ctx.topo_levels = &topo_levels;
25542561

2555-
prepare_commit_graph(ctx.r);
2556-
if (ctx.r->objects->commit_graph) {
2557-
struct commit_graph *g = ctx.r->objects->commit_graph;
2558-
2559-
while (g) {
2560-
g->topo_levels = &topo_levels;
2561-
g = g->base_graph;
2562-
}
2563-
}
2562+
g = prepare_commit_graph(ctx.r);
2563+
for (struct commit_graph *chain = g; chain; chain = chain->base_graph)
2564+
g->topo_levels = &topo_levels;
25642565

25652566
if (flags & COMMIT_GRAPH_WRITE_BLOOM_FILTERS)
25662567
ctx.changed_paths = 1;
25672568
if (!(flags & COMMIT_GRAPH_NO_WRITE_BLOOM_FILTERS)) {
2568-
struct commit_graph *g;
2569-
2570-
g = ctx.r->objects->commit_graph;
2571-
25722569
/* We have changed-paths already. Keep them in the next graph */
25732570
if (g && g->bloom_filter_settings) {
25742571
ctx.changed_paths = 1;
@@ -2585,22 +2582,15 @@ int write_commit_graph(struct odb_source *source,
25852582
bloom_settings.hash_version = bloom_settings.hash_version == 2 ? 2 : 1;
25862583

25872584
if (ctx.split) {
2588-
struct commit_graph *g = ctx.r->objects->commit_graph;
2589-
2590-
while (g) {
2585+
for (struct commit_graph *chain = g; chain; chain = chain->base_graph)
25912586
ctx.num_commit_graphs_before++;
2592-
g = g->base_graph;
2593-
}
25942587

25952588
if (ctx.num_commit_graphs_before) {
25962589
ALLOC_ARRAY(ctx.commit_graph_filenames_before, ctx.num_commit_graphs_before);
25972590
i = ctx.num_commit_graphs_before;
2598-
g = ctx.r->objects->commit_graph;
25992591

2600-
while (g) {
2601-
ctx.commit_graph_filenames_before[--i] = xstrdup(g->filename);
2602-
g = g->base_graph;
2603-
}
2592+
for (struct commit_graph *chain = g; chain; chain = chain->base_graph)
2593+
ctx.commit_graph_filenames_before[--i] = xstrdup(chain->filename);
26042594
}
26052595

26062596
if (ctx.opts)
@@ -2609,8 +2599,7 @@ int write_commit_graph(struct odb_source *source,
26092599

26102600
ctx.approx_nr_objects = repo_approximate_object_count(r);
26112601

2612-
if (ctx.append && ctx.r->objects->commit_graph) {
2613-
struct commit_graph *g = ctx.r->objects->commit_graph;
2602+
if (ctx.append && g) {
26142603
for (i = 0; i < g->num_commits; i++) {
26152604
struct object_id oid;
26162605
oidread(&oid, g->chunk_oid_lookup + st_mult(g->hash_algo->rawsz, i),
@@ -2649,14 +2638,15 @@ int write_commit_graph(struct odb_source *source,
26492638
goto cleanup;
26502639

26512640
if (ctx.split) {
2652-
split_graph_merge_strategy(&ctx);
2641+
split_graph_merge_strategy(&ctx, g);
26532642

26542643
if (!replace)
2655-
merge_commit_graphs(&ctx);
2656-
} else
2644+
merge_commit_graphs(&ctx, g);
2645+
} else {
26572646
ctx.num_commit_graphs_after = 1;
2647+
}
26582648

2659-
ctx.trust_generation_numbers = validate_mixed_generation_chain(ctx.r->objects->commit_graph);
2649+
ctx.trust_generation_numbers = validate_mixed_generation_chain(g);
26602650

26612651
compute_topological_levels(&ctx);
26622652
if (ctx.write_generation_data)

commit-graph.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,19 @@ int open_commit_graph_chain(const char *chain_file, int *fd, struct stat *st,
4848
int parse_commit_in_graph(struct repository *r, struct commit *item);
4949

5050
/*
51-
* Fills `*pos` with the graph position of `c`, and returns 1 if `c` is
52-
* found in the commit-graph belonging to `r`, or 0 otherwise.
53-
* Initializes the commit-graph belonging to `r` if it hasn't been
54-
* already.
51+
* Fills `*pos` with the graph position of `c`, and returns the graph `c` is
52+
* found in, or NULL otherwise. Initializes the commit-graphs belonging to
53+
* `r` if it hasn't been already.
5554
*
5655
* Note: this is a low-level helper that does not alter any slab data
5756
* associated with `c`. Useful in circumstances where the slab data is
5857
* already being modified (e.g., writing the commit-graph itself).
5958
*
6059
* In most cases, callers should use `parse_commit_in_graph()` instead.
6160
*/
62-
int repo_find_commit_pos_in_graph(struct repository *r, struct commit *c,
63-
uint32_t *pos);
61+
struct commit_graph *repo_find_commit_pos_in_graph(struct repository *r,
62+
struct commit *c,
63+
uint32_t *pos);
6464

6565
/*
6666
* Look up the given commit ID in the commit-graph. This will only return a

revision.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -774,9 +774,6 @@ static int check_maybe_different_in_bloom_filter(struct rev_info *revs,
774774
struct bloom_filter *filter;
775775
int result = 0;
776776

777-
if (!revs->repo->objects->commit_graph)
778-
return -1;
779-
780777
if (commit_graph_generation(commit) == GENERATION_NUMBER_INFINITY)
781778
return -1;
782779

0 commit comments

Comments
 (0)