summaryrefslogtreecommitdiff
path: root/commit-graph.c
diff options
context:
space:
mode:
Diffstat (limited to 'commit-graph.c')
-rw-r--r--commit-graph.c298
1 files changed, 162 insertions, 136 deletions
diff --git a/commit-graph.c b/commit-graph.c
index 79b0e72cc4..e0d92b816f 100644
--- a/commit-graph.c
+++ b/commit-graph.c
@@ -1,8 +1,10 @@
#define USE_THE_REPOSITORY_VARIABLE
+#define DISABLE_SIGN_COMPARE_WARNINGS
#include "git-compat-util.h"
#include "config.h"
#include "csum-file.h"
+#include "environment.h"
#include "gettext.h"
#include "hex.h"
#include "lockfile.h"
@@ -12,8 +14,7 @@
#include "refs.h"
#include "hash-lookup.h"
#include "commit-graph.h"
-#include "object-file.h"
-#include "object-store-ll.h"
+#include "odb.h"
#include "oid-array.h"
#include "path.h"
#include "alloc.h"
@@ -37,7 +38,7 @@ void git_test_write_commit_graph_or_die(void)
if (git_env_bool(GIT_TEST_COMMIT_GRAPH_CHANGED_PATHS, 0))
flags = COMMIT_GRAPH_WRITE_BLOOM_FILTERS;
- if (write_commit_graph_reachable(the_repository->objects->odb,
+ if (write_commit_graph_reachable(the_repository->objects->sources,
flags, NULL))
die("failed to write commit-graph under GIT_TEST_COMMIT_GRAPH");
}
@@ -191,21 +192,21 @@ static int commit_gen_cmp(const void *va, const void *vb)
return 0;
}
-char *get_commit_graph_filename(struct object_directory *obj_dir)
+char *get_commit_graph_filename(struct odb_source *source)
{
- return xstrfmt("%s/info/commit-graph", obj_dir->path);
+ return xstrfmt("%s/info/commit-graph", source->path);
}
-static char *get_split_graph_filename(struct object_directory *odb,
+static char *get_split_graph_filename(struct odb_source *source,
const char *oid_hex)
{
- return xstrfmt("%s/info/commit-graphs/graph-%s.graph", odb->path,
+ return xstrfmt("%s/info/commit-graphs/graph-%s.graph", source->path,
oid_hex);
}
-char *get_commit_graph_chain_filename(struct object_directory *odb)
+char *get_commit_graph_chain_filename(struct odb_source *source)
{
- return xstrfmt("%s/info/commit-graphs/commit-graph-chain", odb->path);
+ return xstrfmt("%s/info/commit-graphs/commit-graph-chain", source->path);
}
static struct commit_graph *alloc_commit_graph(void)
@@ -222,7 +223,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;
}
@@ -250,7 +251,7 @@ int open_commit_graph(const char *graph_file, int *fd, struct stat *st)
struct commit_graph *load_commit_graph_one_fd_st(struct repository *r,
int fd, struct stat *st,
- struct object_directory *odb)
+ struct odb_source *source)
{
void *graph_map;
size_t graph_size;
@@ -269,7 +270,7 @@ struct commit_graph *load_commit_graph_one_fd_st(struct repository *r,
ret = parse_commit_graph(&r->settings, graph_map, graph_size);
if (ret)
- ret->odb = odb;
+ ret->odb_source = source;
else
munmap(graph_map, graph_size);
@@ -487,7 +488,7 @@ free_and_return:
static struct commit_graph *load_commit_graph_one(struct repository *r,
const char *graph_file,
- struct object_directory *odb)
+ struct odb_source *source)
{
struct stat st;
@@ -498,7 +499,7 @@ static struct commit_graph *load_commit_graph_one(struct repository *r,
if (!open_ok)
return NULL;
- g = load_commit_graph_one_fd_st(r, fd, &st, odb);
+ g = load_commit_graph_one_fd_st(r, fd, &st, source);
if (g)
g->filename = xstrdup(graph_file);
@@ -507,10 +508,10 @@ static struct commit_graph *load_commit_graph_one(struct repository *r,
}
static struct commit_graph *load_commit_graph_v1(struct repository *r,
- struct object_directory *odb)
+ struct odb_source *source)
{
- char *graph_name = get_commit_graph_filename(odb);
- struct commit_graph *g = load_commit_graph_one(r, graph_name, odb);
+ char *graph_name = get_commit_graph_filename(source);
+ struct commit_graph *g = load_commit_graph_one(r, graph_name, source);
free(graph_name);
return g;
@@ -649,10 +650,10 @@ struct commit_graph *load_commit_graph_chain_fd_st(struct repository *r,
count = st->st_size / (the_hash_algo->hexsz + 1);
CALLOC_ARRAY(oids, count);
- prepare_alt_odb(r);
+ odb_prepare_alternates(r->objects);
for (i = 0; i < count; i++) {
- struct object_directory *odb;
+ struct odb_source *source;
if (strbuf_getline_lf(&line, fp) == EOF)
break;
@@ -665,9 +666,9 @@ struct commit_graph *load_commit_graph_chain_fd_st(struct repository *r,
}
valid = 0;
- for (odb = r->objects->odb; odb; odb = odb->next) {
- char *graph_name = get_split_graph_filename(odb, line.buf);
- struct commit_graph *g = load_commit_graph_one(r, graph_name, odb);
+ for (source = r->objects->sources; source; source = source->next) {
+ char *graph_name = get_split_graph_filename(source, line.buf);
+ struct commit_graph *g = load_commit_graph_one(r, graph_name, source);
free(graph_name);
@@ -701,9 +702,9 @@ struct commit_graph *load_commit_graph_chain_fd_st(struct repository *r,
}
static struct commit_graph *load_commit_graph_chain(struct repository *r,
- struct object_directory *odb)
+ struct odb_source *source)
{
- char *chain_file = get_commit_graph_chain_filename(odb);
+ char *chain_file = get_commit_graph_chain_filename(source);
struct stat st;
int fd;
struct commit_graph *g = NULL;
@@ -719,24 +720,24 @@ static struct commit_graph *load_commit_graph_chain(struct repository *r,
}
struct commit_graph *read_commit_graph_one(struct repository *r,
- struct object_directory *odb)
+ struct odb_source *source)
{
- struct commit_graph *g = load_commit_graph_v1(r, odb);
+ struct commit_graph *g = load_commit_graph_v1(r, source);
if (!g)
- g = load_commit_graph_chain(r, odb);
+ g = load_commit_graph_chain(r, source);
return g;
}
static void prepare_commit_graph_one(struct repository *r,
- struct object_directory *odb)
+ struct odb_source *source)
{
if (r->objects->commit_graph)
return;
- r->objects->commit_graph = read_commit_graph_one(r, odb);
+ r->objects->commit_graph = read_commit_graph_one(r, source);
}
/*
@@ -747,7 +748,7 @@ static void prepare_commit_graph_one(struct repository *r,
*/
static int prepare_commit_graph(struct repository *r)
{
- struct object_directory *odb;
+ struct odb_source *source;
/*
* Early return if there is no git dir or if the commit graph is
@@ -778,11 +779,11 @@ static int prepare_commit_graph(struct repository *r)
if (!commit_graph_compatible(r))
return 0;
- prepare_alt_odb(r);
- for (odb = r->objects->odb;
- !r->objects->commit_graph && odb;
- odb = odb->next)
- prepare_commit_graph_one(r, odb);
+ odb_prepare_alternates(r->objects);
+ for (source = r->objects->sources;
+ !r->objects->commit_graph && source;
+ source = source->next)
+ prepare_commit_graph_one(r, source);
return !!r->objects->commit_graph;
}
@@ -829,7 +830,7 @@ struct bloom_filter_settings *get_bloom_filter_settings(struct repository *r)
return NULL;
}
-void close_commit_graph(struct raw_object_store *o)
+void close_commit_graph(struct object_database *o)
{
if (!o->commit_graph)
return;
@@ -1040,7 +1041,7 @@ struct commit *lookup_commit_in_graph(struct repository *repo, const struct obje
return NULL;
if (!search_commit_pos_in_graph(id, repo->objects->commit_graph, &pos))
return NULL;
- if (commit_graph_paranoia && !has_object(repo, id, 0))
+ if (commit_graph_paranoia && !odb_has_object(repo->objects, id, 0))
return NULL;
commit = lookup_commit(repo, id);
@@ -1137,7 +1138,7 @@ struct packed_commit_list {
struct write_commit_graph_context {
struct repository *r;
- struct object_directory *odb;
+ struct odb_source *odb_source;
char *graph_name;
struct oid_array oids;
struct packed_commit_list commits;
@@ -1533,6 +1534,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++) {
@@ -1550,6 +1552,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++) {
@@ -1570,6 +1573,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++) {
@@ -1687,6 +1691,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);
@@ -1721,6 +1726,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);
@@ -1797,6 +1803,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);
@@ -1847,6 +1854,7 @@ struct refs_cb_data {
};
static int add_ref_to_set(const char *refname UNUSED,
+ const char *referent UNUSED,
const struct object_id *oid,
int flags UNUSED, void *cb_data)
{
@@ -1855,7 +1863,7 @@ static int add_ref_to_set(const char *refname UNUSED,
if (!peel_iterated_oid(the_repository, oid, &peeled))
oid = &peeled;
- if (oid_object_info(the_repository, oid, NULL) == OBJ_COMMIT)
+ if (odb_read_object_info(the_repository->objects, oid, NULL) == OBJ_COMMIT)
oidset_insert(data->commits, oid);
display_progress(data->progress, oidset_size(data->commits));
@@ -1863,7 +1871,7 @@ static int add_ref_to_set(const char *refname UNUSED,
return 0;
}
-int write_commit_graph_reachable(struct object_directory *odb,
+int write_commit_graph_reachable(struct odb_source *source,
enum commit_graph_write_flags flags,
const struct commit_graph_opts *opts)
{
@@ -1875,6 +1883,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,
@@ -1882,7 +1891,7 @@ int write_commit_graph_reachable(struct object_directory *odb,
stop_progress(&data.progress);
- result = write_commit_graph(odb, NULL, &commits,
+ result = write_commit_graph(source, NULL, &commits,
flags, opts);
oidset_clear(&commits);
@@ -1898,7 +1907,7 @@ static int fill_oids_from_packs(struct write_commit_graph_context *ctx,
int dirlen;
int ret = 0;
- strbuf_addf(&packname, "%s/pack/", ctx->odb->path);
+ strbuf_addf(&packname, "%s/pack/", ctx->odb_source->path);
dirlen = packname.len;
if (ctx->report_progress) {
strbuf_addf(&progress_title,
@@ -1906,20 +1915,23 @@ 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++) {
struct packed_git *p;
strbuf_setlen(&packname, dirlen);
strbuf_addstr(&packname, pack_indexes->items[i].string);
- p = add_packed_git(packname.buf, packname.len, 1);
+ p = add_packed_git(ctx->r, packname.buf, packname.len, 1);
if (!p) {
ret = error(_("error adding pack %s"), packname.buf);
goto cleanup;
}
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,
@@ -1957,9 +1969,10 @@ 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(add_packed_commits, ctx,
+ for_each_packed_object(ctx->r, add_packed_commits, ctx,
FOR_EACH_OBJECT_PACK_ORDER);
if (ctx->progress_done < ctx->approx_nr_objects)
display_progress(ctx->progress, ctx->approx_nr_objects);
@@ -1975,6 +1988,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);
@@ -2047,21 +2061,20 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx)
strbuf_addf(&tmp_file,
"%s/info/commit-graphs/tmp_graph_XXXXXX",
- ctx->odb->path);
+ ctx->odb_source->path);
ctx->graph_name = strbuf_detach(&tmp_file, NULL);
} else {
- ctx->graph_name = get_commit_graph_filename(ctx->odb);
+ ctx->graph_name = get_commit_graph_filename(ctx->odb_source);
}
- if (safe_create_leading_directories(ctx->graph_name)) {
- UNLEAK(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;
}
if (ctx->split) {
- char *lock_name = get_commit_graph_chain_filename(ctx->odb);
+ char *lock_name = get_commit_graph_chain_filename(ctx->odb_source);
hold_lock_file_for_update_mode(&lk, lock_name,
LOCK_DIE_ON_ERROR, 0444);
@@ -2073,17 +2086,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);
@@ -2135,6 +2150,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));
}
@@ -2146,7 +2162,7 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx)
if (ctx->split && ctx->base_graph_name && ctx->num_commit_graphs_after > 1) {
char *new_base_hash = xstrdup(oid_to_hex(&ctx->new_base_graph->oid));
- char *new_base_name = get_split_graph_filename(ctx->new_base_graph->odb, new_base_hash);
+ char *new_base_name = get_split_graph_filename(ctx->new_base_graph->odb_source, new_base_hash);
free(ctx->commit_graph_filenames_after[ctx->num_commit_graphs_after - 2]);
free(ctx->commit_graph_hash_after[ctx->num_commit_graphs_after - 2]);
@@ -2186,14 +2202,14 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx)
}
}
} else {
- char *graph_name = get_commit_graph_filename(ctx->odb);
+ char *graph_name = get_commit_graph_filename(ctx->odb_source);
unlink(graph_name);
free(graph_name);
}
free(ctx->commit_graph_hash_after[ctx->num_commit_graphs_after - 1]);
ctx->commit_graph_hash_after[ctx->num_commit_graphs_after - 1] = xstrdup(hash_to_hex(file_hash));
- final_graph_name = get_split_graph_filename(ctx->odb,
+ final_graph_name = get_split_graph_filename(ctx->odb_source,
ctx->commit_graph_hash_after[ctx->num_commit_graphs_after - 1]);
free(ctx->commit_graph_filenames_after[ctx->num_commit_graphs_after - 1]);
ctx->commit_graph_filenames_after[ctx->num_commit_graphs_after - 1] = final_graph_name;
@@ -2244,7 +2260,7 @@ static void split_graph_merge_strategy(struct write_commit_graph_context *ctx)
flags != COMMIT_GRAPH_SPLIT_REPLACE) {
while (g && (g->num_commits <= st_mult(size_mult, num_commits) ||
(max_commits && num_commits > max_commits))) {
- if (g->odb != ctx->odb)
+ if (g->odb_source != ctx->odb_source)
break;
if (unsigned_add_overflows(num_commits, g->num_commits))
@@ -2266,10 +2282,10 @@ static void split_graph_merge_strategy(struct write_commit_graph_context *ctx)
"should be 1 with --split=replace");
if (ctx->num_commit_graphs_after == 2) {
- char *old_graph_name = get_commit_graph_filename(g->odb);
+ char *old_graph_name = get_commit_graph_filename(g->odb_source);
if (!strcmp(g->filename, old_graph_name) &&
- g->odb != ctx->odb) {
+ g->odb_source != ctx->odb_source) {
ctx->num_commit_graphs_after = 1;
ctx->new_base_graph = NULL;
}
@@ -2347,6 +2363,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);
@@ -2391,7 +2408,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);
@@ -2439,13 +2457,13 @@ static void expire_commit_graphs(struct write_commit_graph_context *ctx)
if (ctx->opts && ctx->opts->expire_time)
expire_time = ctx->opts->expire_time;
if (!ctx->split) {
- char *chain_file_name = get_commit_graph_chain_filename(ctx->odb);
+ char *chain_file_name = get_commit_graph_chain_filename(ctx->odb_source);
unlink(chain_file_name);
free(chain_file_name);
ctx->num_commit_graphs_after = 0;
}
- strbuf_addstr(&path, ctx->odb->path);
+ strbuf_addstr(&path, ctx->odb_source->path);
strbuf_addstr(&path, "/info/commit-graphs");
dir = opendir(path.buf);
@@ -2487,14 +2505,24 @@ out:
strbuf_release(&path);
}
-int write_commit_graph(struct object_directory *odb,
+int write_commit_graph(struct odb_source *source,
const struct string_list *const pack_indexes,
struct oidset *commits,
enum commit_graph_write_flags flags,
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_source = source,
+ .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;
@@ -2516,17 +2544,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);
@@ -2534,14 +2551,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;
@@ -2550,15 +2567,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)
@@ -2571,116 +2588,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;
}
@@ -2702,7 +2726,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,
@@ -2873,7 +2898,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);
}