summaryrefslogtreecommitdiff
path: root/commit-graph.c
diff options
context:
space:
mode:
Diffstat (limited to 'commit-graph.c')
-rw-r--r--commit-graph.c188
1 files changed, 106 insertions, 82 deletions
diff --git a/commit-graph.c b/commit-graph.c
index 0df66e5a24..ad3943b690 100644
--- a/commit-graph.c
+++ b/commit-graph.c
@@ -13,8 +13,7 @@
#include "refs.h"
#include "hash-lookup.h"
#include "commit-graph.h"
-#include "object-file.h"
-#include "object-store-ll.h"
+#include "object-store.h"
#include "oid-array.h"
#include "path.h"
#include "alloc.h"
@@ -223,7 +222,7 @@ static int commit_graph_compatible(struct repository *r)
if (replace_refs_enabled(r)) {
prepare_replace_object(r);
- if (hashmap_get_size(&r->objects->replace_map->map))
+ if (oidmap_get_size(&r->objects->replace_map))
return 0;
}
@@ -1534,6 +1533,7 @@ static void close_reachable(struct write_commit_graph_context *ctx)
if (ctx->report_progress)
ctx->progress = start_delayed_progress(
+ the_repository,
_("Loading known commits in commit graph"),
ctx->oids.nr);
for (i = 0; i < ctx->oids.nr; i++) {
@@ -1551,6 +1551,7 @@ static void close_reachable(struct write_commit_graph_context *ctx)
*/
if (ctx->report_progress)
ctx->progress = start_delayed_progress(
+ the_repository,
_("Expanding reachable commits in commit graph"),
0);
for (i = 0; i < ctx->oids.nr; i++) {
@@ -1571,6 +1572,7 @@ static void close_reachable(struct write_commit_graph_context *ctx)
if (ctx->report_progress)
ctx->progress = start_delayed_progress(
+ the_repository,
_("Clearing commit marks in commit graph"),
ctx->oids.nr);
for (i = 0; i < ctx->oids.nr; i++) {
@@ -1688,6 +1690,7 @@ static void compute_topological_levels(struct write_commit_graph_context *ctx)
if (ctx->report_progress)
info.progress = ctx->progress
= start_delayed_progress(
+ the_repository,
_("Computing commit graph topological levels"),
ctx->commits.nr);
@@ -1722,6 +1725,7 @@ static void compute_generation_numbers(struct write_commit_graph_context *ctx)
if (ctx->report_progress)
info.progress = ctx->progress
= start_delayed_progress(
+ the_repository,
_("Computing commit graph generation numbers"),
ctx->commits.nr);
@@ -1798,6 +1802,7 @@ static void compute_bloom_filters(struct write_commit_graph_context *ctx)
if (ctx->report_progress)
progress = start_delayed_progress(
+ the_repository,
_("Computing commit changed paths Bloom filters"),
ctx->commits.nr);
@@ -1877,6 +1882,7 @@ int write_commit_graph_reachable(struct object_directory *odb,
data.commits = &commits;
if (flags & COMMIT_GRAPH_WRITE_PROGRESS)
data.progress = start_delayed_progress(
+ the_repository,
_("Collecting referenced commits"), 0);
refs_for_each_ref(get_main_ref_store(the_repository), add_ref_to_set,
@@ -1908,7 +1914,8 @@ static int fill_oids_from_packs(struct write_commit_graph_context *ctx,
"Finding commits for commit graph in %"PRIuMAX" packs",
pack_indexes->nr),
(uintmax_t)pack_indexes->nr);
- ctx->progress = start_delayed_progress(progress_title.buf, 0);
+ ctx->progress = start_delayed_progress(the_repository,
+ progress_title.buf, 0);
ctx->progress_done = 0;
}
for (i = 0; i < pack_indexes->nr; i++) {
@@ -1922,6 +1929,8 @@ static int fill_oids_from_packs(struct write_commit_graph_context *ctx,
}
if (open_pack_index(p)) {
ret = error(_("error opening index for %s"), packname.buf);
+ close_pack(p);
+ free(p);
goto cleanup;
}
for_each_object_in_pack(p, add_packed_commits, ctx,
@@ -1959,6 +1968,7 @@ static void fill_oids_from_all_packs(struct write_commit_graph_context *ctx)
{
if (ctx->report_progress)
ctx->progress = start_delayed_progress(
+ the_repository,
_("Finding commits for commit graph among packed objects"),
ctx->approx_nr_objects);
for_each_packed_object(ctx->r, add_packed_commits, ctx,
@@ -1977,6 +1987,7 @@ static void copy_oids_to_commits(struct write_commit_graph_context *ctx)
ctx->num_extra_edges = 0;
if (ctx->report_progress)
ctx->progress = start_delayed_progress(
+ the_repository,
_("Finding extra edges in commit graph"),
ctx->oids.nr);
oid_array_sort(&ctx->oids);
@@ -2055,7 +2066,7 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx)
ctx->graph_name = get_commit_graph_filename(ctx->odb);
}
- if (safe_create_leading_directories(ctx->graph_name)) {
+ if (safe_create_leading_directories(the_repository, ctx->graph_name)) {
error(_("unable to create leading directories of %s"),
ctx->graph_name);
return -1;
@@ -2074,17 +2085,19 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx)
return -1;
}
- if (adjust_shared_perm(get_tempfile_path(graph_layer))) {
+ if (adjust_shared_perm(the_repository, get_tempfile_path(graph_layer))) {
error(_("unable to adjust shared permissions for '%s'"),
get_tempfile_path(graph_layer));
return -1;
}
- f = hashfd(get_tempfile_fd(graph_layer), get_tempfile_path(graph_layer));
+ f = hashfd(the_repository->hash_algo,
+ get_tempfile_fd(graph_layer), get_tempfile_path(graph_layer));
} else {
hold_lock_file_for_update_mode(&lk, ctx->graph_name,
LOCK_DIE_ON_ERROR, 0444);
- f = hashfd(get_lock_file_fd(&lk), get_lock_file_path(&lk));
+ f = hashfd(the_repository->hash_algo,
+ get_lock_file_fd(&lk), get_lock_file_path(&lk));
}
cf = init_chunkfile(f);
@@ -2136,6 +2149,7 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx)
get_num_chunks(cf)),
get_num_chunks(cf));
ctx->progress = start_delayed_progress(
+ the_repository,
progress_title.buf,
st_mult(get_num_chunks(cf), ctx->commits.nr));
}
@@ -2348,6 +2362,7 @@ static void sort_and_scan_merged_commits(struct write_commit_graph_context *ctx)
if (ctx->report_progress)
ctx->progress = start_delayed_progress(
+ the_repository,
_("Scanning merged commits"),
ctx->commits.nr);
@@ -2392,7 +2407,8 @@ static void merge_commit_graphs(struct write_commit_graph_context *ctx)
current_graph_number--;
if (ctx->report_progress)
- ctx->progress = start_delayed_progress(_("Merging commit-graph"), 0);
+ ctx->progress = start_delayed_progress(the_repository,
+ _("Merging commit-graph"), 0);
merge_commit_graph(ctx, g);
stop_progress(&ctx->progress);
@@ -2495,7 +2511,17 @@ int write_commit_graph(struct object_directory *odb,
const struct commit_graph_opts *opts)
{
struct repository *r = the_repository;
- struct write_commit_graph_context *ctx;
+ struct write_commit_graph_context ctx = {
+ .r = r,
+ .odb = odb,
+ .append = flags & COMMIT_GRAPH_WRITE_APPEND ? 1 : 0,
+ .report_progress = flags & COMMIT_GRAPH_WRITE_PROGRESS ? 1 : 0,
+ .split = flags & COMMIT_GRAPH_WRITE_SPLIT ? 1 : 0,
+ .opts = opts,
+ .total_bloom_filter_data_size = 0,
+ .write_generation_data = (get_configured_generation_version(r) == 2),
+ .num_generation_data_overflows = 0,
+ };
uint32_t i;
int res = 0;
int replace = 0;
@@ -2517,17 +2543,6 @@ int write_commit_graph(struct object_directory *odb,
return 0;
}
- CALLOC_ARRAY(ctx, 1);
- ctx->r = r;
- ctx->odb = odb;
- ctx->append = flags & COMMIT_GRAPH_WRITE_APPEND ? 1 : 0;
- ctx->report_progress = flags & COMMIT_GRAPH_WRITE_PROGRESS ? 1 : 0;
- ctx->split = flags & COMMIT_GRAPH_WRITE_SPLIT ? 1 : 0;
- ctx->opts = opts;
- ctx->total_bloom_filter_data_size = 0;
- ctx->write_generation_data = (get_configured_generation_version(r) == 2);
- ctx->num_generation_data_overflows = 0;
-
bloom_settings.hash_version = r->settings.commit_graph_changed_paths_version;
bloom_settings.bits_per_entry = git_env_ulong("GIT_TEST_BLOOM_SETTINGS_BITS_PER_ENTRY",
bloom_settings.bits_per_entry);
@@ -2535,14 +2550,14 @@ int write_commit_graph(struct object_directory *odb,
bloom_settings.num_hashes);
bloom_settings.max_changed_paths = git_env_ulong("GIT_TEST_BLOOM_SETTINGS_MAX_CHANGED_PATHS",
bloom_settings.max_changed_paths);
- ctx->bloom_settings = &bloom_settings;
+ ctx.bloom_settings = &bloom_settings;
init_topo_level_slab(&topo_levels);
- ctx->topo_levels = &topo_levels;
+ ctx.topo_levels = &topo_levels;
- prepare_commit_graph(ctx->r);
- if (ctx->r->objects->commit_graph) {
- struct commit_graph *g = ctx->r->objects->commit_graph;
+ prepare_commit_graph(ctx.r);
+ if (ctx.r->objects->commit_graph) {
+ struct commit_graph *g = ctx.r->objects->commit_graph;
while (g) {
g->topo_levels = &topo_levels;
@@ -2551,15 +2566,15 @@ int write_commit_graph(struct object_directory *odb,
}
if (flags & COMMIT_GRAPH_WRITE_BLOOM_FILTERS)
- ctx->changed_paths = 1;
+ ctx.changed_paths = 1;
if (!(flags & COMMIT_GRAPH_NO_WRITE_BLOOM_FILTERS)) {
struct commit_graph *g;
- g = ctx->r->objects->commit_graph;
+ g = ctx.r->objects->commit_graph;
/* We have changed-paths already. Keep them in the next graph */
if (g && g->bloom_filter_settings) {
- ctx->changed_paths = 1;
+ ctx.changed_paths = 1;
/* don't propagate the hash_version unless unspecified */
if (bloom_settings.hash_version == -1)
@@ -2572,116 +2587,123 @@ int write_commit_graph(struct object_directory *odb,
bloom_settings.hash_version = bloom_settings.hash_version == 2 ? 2 : 1;
- if (ctx->split) {
- struct commit_graph *g = ctx->r->objects->commit_graph;
+ if (ctx.split) {
+ struct commit_graph *g = ctx.r->objects->commit_graph;
while (g) {
- ctx->num_commit_graphs_before++;
+ ctx.num_commit_graphs_before++;
g = g->base_graph;
}
- if (ctx->num_commit_graphs_before) {
- ALLOC_ARRAY(ctx->commit_graph_filenames_before, ctx->num_commit_graphs_before);
- i = ctx->num_commit_graphs_before;
- g = ctx->r->objects->commit_graph;
+ if (ctx.num_commit_graphs_before) {
+ ALLOC_ARRAY(ctx.commit_graph_filenames_before, ctx.num_commit_graphs_before);
+ i = ctx.num_commit_graphs_before;
+ g = ctx.r->objects->commit_graph;
while (g) {
- ctx->commit_graph_filenames_before[--i] = xstrdup(g->filename);
+ ctx.commit_graph_filenames_before[--i] = xstrdup(g->filename);
g = g->base_graph;
}
}
- if (ctx->opts)
- replace = ctx->opts->split_flags & COMMIT_GRAPH_SPLIT_REPLACE;
+ if (ctx.opts)
+ replace = ctx.opts->split_flags & COMMIT_GRAPH_SPLIT_REPLACE;
}
- ctx->approx_nr_objects = repo_approximate_object_count(the_repository);
+ ctx.approx_nr_objects = repo_approximate_object_count(the_repository);
- if (ctx->append && ctx->r->objects->commit_graph) {
- struct commit_graph *g = ctx->r->objects->commit_graph;
+ if (ctx.append && ctx.r->objects->commit_graph) {
+ struct commit_graph *g = ctx.r->objects->commit_graph;
for (i = 0; i < g->num_commits; i++) {
struct object_id oid;
oidread(&oid, g->chunk_oid_lookup + st_mult(g->hash_len, i),
the_repository->hash_algo);
- oid_array_append(&ctx->oids, &oid);
+ oid_array_append(&ctx.oids, &oid);
}
}
if (pack_indexes) {
- ctx->order_by_pack = 1;
- if ((res = fill_oids_from_packs(ctx, pack_indexes)))
+ ctx.order_by_pack = 1;
+ if ((res = fill_oids_from_packs(&ctx, pack_indexes)))
goto cleanup;
}
if (commits) {
- if ((res = fill_oids_from_commits(ctx, commits)))
+ if ((res = fill_oids_from_commits(&ctx, commits)))
goto cleanup;
}
if (!pack_indexes && !commits) {
- ctx->order_by_pack = 1;
- fill_oids_from_all_packs(ctx);
+ ctx.order_by_pack = 1;
+ fill_oids_from_all_packs(&ctx);
}
- close_reachable(ctx);
+ close_reachable(&ctx);
- copy_oids_to_commits(ctx);
+ copy_oids_to_commits(&ctx);
- if (ctx->commits.nr >= GRAPH_EDGE_LAST_MASK) {
+ if (ctx.commits.nr >= GRAPH_EDGE_LAST_MASK) {
error(_("too many commits to write graph"));
res = -1;
goto cleanup;
}
- if (!ctx->commits.nr && !replace)
+ if (!ctx.commits.nr && !replace)
goto cleanup;
- if (ctx->split) {
- split_graph_merge_strategy(ctx);
+ if (ctx.split) {
+ split_graph_merge_strategy(&ctx);
if (!replace)
- merge_commit_graphs(ctx);
+ merge_commit_graphs(&ctx);
} else
- ctx->num_commit_graphs_after = 1;
+ ctx.num_commit_graphs_after = 1;
- ctx->trust_generation_numbers = validate_mixed_generation_chain(ctx->r->objects->commit_graph);
+ ctx.trust_generation_numbers = validate_mixed_generation_chain(ctx.r->objects->commit_graph);
- compute_topological_levels(ctx);
- if (ctx->write_generation_data)
- compute_generation_numbers(ctx);
+ compute_topological_levels(&ctx);
+ if (ctx.write_generation_data)
+ compute_generation_numbers(&ctx);
- if (ctx->changed_paths)
- compute_bloom_filters(ctx);
+ if (ctx.changed_paths)
+ compute_bloom_filters(&ctx);
- res = write_commit_graph_file(ctx);
+ res = write_commit_graph_file(&ctx);
- if (ctx->changed_paths)
+ if (ctx.changed_paths)
deinit_bloom_filters();
- if (ctx->split)
- mark_commit_graphs(ctx);
+ if (ctx.split)
+ mark_commit_graphs(&ctx);
- expire_commit_graphs(ctx);
+ expire_commit_graphs(&ctx);
cleanup:
- free(ctx->graph_name);
- free(ctx->base_graph_name);
- free(ctx->commits.list);
- oid_array_clear(&ctx->oids);
+ free(ctx.graph_name);
+ free(ctx.base_graph_name);
+ free(ctx.commits.list);
+ oid_array_clear(&ctx.oids);
clear_topo_level_slab(&topo_levels);
- for (i = 0; i < ctx->num_commit_graphs_before; i++)
- free(ctx->commit_graph_filenames_before[i]);
- free(ctx->commit_graph_filenames_before);
+ if (ctx.r->objects->commit_graph) {
+ struct commit_graph *g = ctx.r->objects->commit_graph;
- for (i = 0; i < ctx->num_commit_graphs_after; i++) {
- free(ctx->commit_graph_filenames_after[i]);
- free(ctx->commit_graph_hash_after[i]);
+ while (g) {
+ g->topo_levels = NULL;
+ g = g->base_graph;
+ }
}
- free(ctx->commit_graph_filenames_after);
- free(ctx->commit_graph_hash_after);
- free(ctx);
+ for (i = 0; i < ctx.num_commit_graphs_before; i++)
+ free(ctx.commit_graph_filenames_before[i]);
+ free(ctx.commit_graph_filenames_before);
+
+ for (i = 0; i < ctx.num_commit_graphs_after; i++) {
+ free(ctx.commit_graph_filenames_after[i]);
+ free(ctx.commit_graph_hash_after[i]);
+ }
+ free(ctx.commit_graph_filenames_after);
+ free(ctx.commit_graph_hash_after);
return res;
}
@@ -2703,7 +2725,8 @@ static void graph_report(const char *fmt, ...)
static int commit_graph_checksum_valid(struct commit_graph *g)
{
- return hashfile_checksum_valid(g->data, g->data_len);
+ return hashfile_checksum_valid(the_repository->hash_algo,
+ g->data, g->data_len);
}
static int verify_one_commit_graph(struct repository *r,
@@ -2874,7 +2897,8 @@ int verify_commit_graph(struct repository *r, struct commit_graph *g, int flags)
if (!(flags & COMMIT_GRAPH_VERIFY_SHALLOW))
total += g->num_commits_in_base;
- progress = start_progress(_("Verifying commits in commit graph"),
+ progress = start_progress(the_repository,
+ _("Verifying commits in commit graph"),
total);
}