]> 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 0a9ace06fb99b88bf971f9c2f9a9df3003ad90b4..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,7 +969,7 @@ 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;
 
@@ -1286,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(
@@ -1408,6 +1415,7 @@ 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();
 
@@ -1424,13 +1432,16 @@ 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_or_compute_bloom_filter(
                        ctx->r,
                        c,
-                       1,
+                       ctx->count_bloom_filter_computed < max_new_filters,
                        ctx->bloom_settings,
                        &computed);
                if (computed & BLOOM_COMPUTED) {
@@ -1441,7 +1452,8 @@ static void compute_bloom_filters(struct write_commit_graph_context *ctx)
                                ctx->count_bloom_filter_trunc_large++;
                } else if (computed & BLOOM_NOT_COMPUTED)
                        ctx->count_bloom_filter_not_computed++;
-               ctx->total_bloom_filter_data_size += sizeof(unsigned char) * filter->len;
+               ctx->total_bloom_filter_data_size += filter
+                       ? sizeof(unsigned char) * filter->len : 0;
                display_progress(progress, i + 1);
        }
 
@@ -1476,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;
@@ -1493,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;
@@ -1608,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)
@@ -1711,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);
@@ -1894,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;
@@ -2078,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;
@@ -2130,7 +2142,7 @@ 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;
@@ -2147,7 +2159,7 @@ 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",
@@ -2195,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);