]> git.ipfire.org Git - thirdparty/git.git/blobdiff - commit-graph.c
submodules: fix of regression on fetching of non-init subsub-repo
[thirdparty/git.git] / commit-graph.c
index 44dceb80459994b19d9d882d912a3364e1a91781..cb042bdba8c83288cfc1e42853447d5bc06f47fe 100644 (file)
@@ -172,14 +172,21 @@ static char *get_split_graph_filename(struct object_directory *odb,
                       oid_hex);
 }
 
-static char *get_chain_filename(struct object_directory *odb)
+char *get_commit_graph_chain_filename(struct object_directory *odb)
 {
        return xstrfmt("%s/info/commit-graphs/commit-graph-chain", odb->path);
 }
 
 static uint8_t oid_version(void)
 {
-       return 1;
+       switch (hash_algo_by_ptr(the_hash_algo)) {
+       case GIT_HASH_SHA1:
+               return 1;
+       case GIT_HASH_SHA256:
+               return 2;
+       default:
+               die(_("invalid hash version"));
+       }
 }
 
 static struct commit_graph *alloc_commit_graph(void)
@@ -522,7 +529,7 @@ static struct commit_graph *load_commit_graph_chain(struct repository *r,
        struct stat st;
        struct object_id *oids;
        int i = 0, valid = 1, count;
-       char *chain_name = get_chain_filename(odb);
+       char *chain_name = get_commit_graph_chain_filename(odb);
        FILE *fp;
        int stat_res;
 
@@ -962,9 +969,14 @@ struct write_commit_graph_context {
                 changed_paths:1,
                 order_by_pack:1;
 
-       const struct split_commit_graph_opts *split_opts;
+       const struct commit_graph_opts *opts;
        size_t total_bloom_filter_data_size;
        const struct bloom_filter_settings *bloom_settings;
+
+       int count_bloom_filter_computed;
+       int count_bloom_filter_not_computed;
+       int count_bloom_filter_trunc_empty;
+       int count_bloom_filter_trunc_large;
 };
 
 static int write_graph_chunk_fanout(struct hashfile *f,
@@ -1176,7 +1188,7 @@ static int write_graph_chunk_bloom_indexes(struct hashfile *f,
        uint32_t cur_pos = 0;
 
        while (list < last) {
-               struct bloom_filter *filter = get_bloom_filter(ctx->r, *list, 0);
+               struct bloom_filter *filter = get_bloom_filter(ctx->r, *list);
                size_t len = filter ? filter->len : 0;
                cur_pos += len;
                display_progress(ctx->progress, ++ctx->progress_cnt);
@@ -1216,7 +1228,7 @@ static int write_graph_chunk_bloom_data(struct hashfile *f,
        hashwrite_be32(f, ctx->bloom_settings->bits_per_entry);
 
        while (list < last) {
-               struct bloom_filter *filter = get_bloom_filter(ctx->r, *list, 0);
+               struct bloom_filter *filter = get_bloom_filter(ctx->r, *list);
                size_t len = filter ? filter->len : 0;
 
                display_progress(ctx->progress, ++ctx->progress_cnt);
@@ -1281,8 +1293,8 @@ static void close_reachable(struct write_commit_graph_context *ctx)
 {
        int i;
        struct commit *commit;
-       enum commit_graph_split_flags flags = ctx->split_opts ?
-               ctx->split_opts->flags : COMMIT_GRAPH_SPLIT_UNSPECIFIED;
+       enum commit_graph_split_flags flags = ctx->opts ?
+               ctx->opts->split_flags : COMMIT_GRAPH_SPLIT_UNSPECIFIED;
 
        if (ctx->report_progress)
                ctx->progress = start_delayed_progress(
@@ -1386,11 +1398,24 @@ static void compute_generation_numbers(struct write_commit_graph_context *ctx)
        stop_progress(&ctx->progress);
 }
 
+static void trace2_bloom_filter_write_statistics(struct write_commit_graph_context *ctx)
+{
+       trace2_data_intmax("commit-graph", ctx->r, "filter-computed",
+                          ctx->count_bloom_filter_computed);
+       trace2_data_intmax("commit-graph", ctx->r, "filter-not-computed",
+                          ctx->count_bloom_filter_not_computed);
+       trace2_data_intmax("commit-graph", ctx->r, "filter-trunc-empty",
+                          ctx->count_bloom_filter_trunc_empty);
+       trace2_data_intmax("commit-graph", ctx->r, "filter-trunc-large",
+                          ctx->count_bloom_filter_trunc_large);
+}
+
 static void compute_bloom_filters(struct write_commit_graph_context *ctx)
 {
        int i;
        struct progress *progress = NULL;
        struct commit **sorted_commits;
+       int max_new_filters;
 
        init_bloom_filters();
 
@@ -1407,13 +1432,34 @@ static void compute_bloom_filters(struct write_commit_graph_context *ctx)
        else
                QSORT(sorted_commits, ctx->commits.nr, commit_gen_cmp);
 
+       max_new_filters = ctx->opts && ctx->opts->max_new_filters >= 0 ?
+               ctx->opts->max_new_filters : ctx->commits.nr;
+
        for (i = 0; i < ctx->commits.nr; i++) {
+               enum bloom_filter_computed computed = 0;
                struct commit *c = sorted_commits[i];
-               struct bloom_filter *filter = get_bloom_filter(ctx->r, c, 1);
-               ctx->total_bloom_filter_data_size += sizeof(unsigned char) * filter->len;
+               struct bloom_filter *filter = get_or_compute_bloom_filter(
+                       ctx->r,
+                       c,
+                       ctx->count_bloom_filter_computed < max_new_filters,
+                       ctx->bloom_settings,
+                       &computed);
+               if (computed & BLOOM_COMPUTED) {
+                       ctx->count_bloom_filter_computed++;
+                       if (computed & BLOOM_TRUNC_EMPTY)
+                               ctx->count_bloom_filter_trunc_empty++;
+                       if (computed & BLOOM_TRUNC_LARGE)
+                               ctx->count_bloom_filter_trunc_large++;
+               } else if (computed & BLOOM_NOT_COMPUTED)
+                       ctx->count_bloom_filter_not_computed++;
+               ctx->total_bloom_filter_data_size += filter
+                       ? sizeof(unsigned char) * filter->len : 0;
                display_progress(progress, i + 1);
        }
 
+       if (trace2_is_enabled())
+               trace2_bloom_filter_write_statistics(ctx);
+
        free(sorted_commits);
        stop_progress(&progress);
 }
@@ -1442,7 +1488,7 @@ static int add_ref_to_set(const char *refname,
 
 int write_commit_graph_reachable(struct object_directory *odb,
                                 enum commit_graph_write_flags flags,
-                                const struct split_commit_graph_opts *split_opts)
+                                const struct commit_graph_opts *opts)
 {
        struct oidset commits = OIDSET_INIT;
        struct refs_cb_data data;
@@ -1459,7 +1505,7 @@ int write_commit_graph_reachable(struct object_directory *odb,
        stop_progress(&data.progress);
 
        result = write_commit_graph(odb, NULL, &commits,
-                                   flags, split_opts);
+                                   flags, opts);
 
        oidset_clear(&commits);
        return result;
@@ -1574,8 +1620,8 @@ static uint32_t count_distinct_commits(struct write_commit_graph_context *ctx)
 static void copy_oids_to_commits(struct write_commit_graph_context *ctx)
 {
        uint32_t i;
-       enum commit_graph_split_flags flags = ctx->split_opts ?
-               ctx->split_opts->flags : COMMIT_GRAPH_SPLIT_UNSPECIFIED;
+       enum commit_graph_split_flags flags = ctx->opts ?
+               ctx->opts->split_flags : COMMIT_GRAPH_SPLIT_UNSPECIFIED;
 
        ctx->num_extra_edges = 0;
        if (ctx->report_progress)
@@ -1657,17 +1703,6 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx)
        int num_chunks = 3;
        uint64_t chunk_offset;
        struct object_id file_hash;
-       struct bloom_filter_settings bloom_settings = DEFAULT_BLOOM_FILTER_SETTINGS;
-
-       if (!ctx->bloom_settings) {
-               bloom_settings.bits_per_entry = git_env_ulong("GIT_TEST_BLOOM_SETTINGS_BITS_PER_ENTRY",
-                                                             bloom_settings.bits_per_entry);
-               bloom_settings.num_hashes = git_env_ulong("GIT_TEST_BLOOM_SETTINGS_NUM_HASHES",
-                                                         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;
-       }
 
        if (ctx->split) {
                struct strbuf tmp_file = STRBUF_INIT;
@@ -1688,7 +1723,7 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx)
        }
 
        if (ctx->split) {
-               char *lock_name = get_chain_filename(ctx->odb);
+               char *lock_name = get_commit_graph_chain_filename(ctx->odb);
 
                hold_lock_file_for_update_mode(&lk, lock_name,
                                               LOCK_DIE_ON_ERROR, 0444);
@@ -1871,13 +1906,13 @@ static void split_graph_merge_strategy(struct write_commit_graph_context *ctx)
        int max_commits = 0;
        int size_mult = 2;
 
-       if (ctx->split_opts) {
-               max_commits = ctx->split_opts->max_commits;
+       if (ctx->opts) {
+               max_commits = ctx->opts->max_commits;
 
-               if (ctx->split_opts->size_multiple)
-                       size_mult = ctx->split_opts->size_multiple;
+               if (ctx->opts->size_multiple)
+                       size_mult = ctx->opts->size_multiple;
 
-               flags = ctx->split_opts->flags;
+               flags = ctx->opts->split_flags;
        }
 
        g = ctx->r->objects->commit_graph;
@@ -2055,10 +2090,10 @@ static void expire_commit_graphs(struct write_commit_graph_context *ctx)
        size_t dirnamelen;
        timestamp_t expire_time = time(NULL);
 
-       if (ctx->split_opts && ctx->split_opts->expire_time)
-               expire_time = ctx->split_opts->expire_time;
+       if (ctx->opts && ctx->opts->expire_time)
+               expire_time = ctx->opts->expire_time;
        if (!ctx->split) {
-               char *chain_file_name = get_chain_filename(ctx->odb);
+               char *chain_file_name = get_commit_graph_chain_filename(ctx->odb);
                unlink(chain_file_name);
                free(chain_file_name);
                ctx->num_commit_graphs_after = 0;
@@ -2107,12 +2142,13 @@ int write_commit_graph(struct object_directory *odb,
                       struct string_list *pack_indexes,
                       struct oidset *commits,
                       enum commit_graph_write_flags flags,
-                      const struct split_commit_graph_opts *split_opts)
+                      const struct commit_graph_opts *opts)
 {
        struct write_commit_graph_context *ctx;
        uint32_t i, count_distinct = 0;
        int res = 0;
        int replace = 0;
+       struct bloom_filter_settings bloom_settings = DEFAULT_BLOOM_FILTER_SETTINGS;
 
        if (!commit_graph_compatible(the_repository))
                return 0;
@@ -2123,9 +2159,17 @@ int write_commit_graph(struct object_directory *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->split_opts = split_opts;
+       ctx->opts = opts;
        ctx->total_bloom_filter_data_size = 0;
 
+       bloom_settings.bits_per_entry = git_env_ulong("GIT_TEST_BLOOM_SETTINGS_BITS_PER_ENTRY",
+                                                     bloom_settings.bits_per_entry);
+       bloom_settings.num_hashes = git_env_ulong("GIT_TEST_BLOOM_SETTINGS_NUM_HASHES",
+                                                 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;
+
        if (flags & COMMIT_GRAPH_WRITE_BLOOM_FILTERS)
                ctx->changed_paths = 1;
        if (!(flags & COMMIT_GRAPH_NO_WRITE_BLOOM_FILTERS)) {
@@ -2163,15 +2207,15 @@ int write_commit_graph(struct object_directory *odb,
                        }
                }
 
-               if (ctx->split_opts)
-                       replace = ctx->split_opts->flags & COMMIT_GRAPH_SPLIT_REPLACE;
+               if (ctx->opts)
+                       replace = ctx->opts->split_flags & COMMIT_GRAPH_SPLIT_REPLACE;
        }
 
        ctx->approx_nr_objects = approximate_object_count();
        ctx->oids.alloc = ctx->approx_nr_objects / 32;
 
-       if (ctx->split && split_opts && ctx->oids.alloc > split_opts->max_commits)
-               ctx->oids.alloc = split_opts->max_commits;
+       if (ctx->split && opts && ctx->oids.alloc > opts->max_commits)
+               ctx->oids.alloc = opts->max_commits;
 
        if (ctx->append) {
                prepare_commit_graph_one(ctx->r, ctx->odb);