]> git.ipfire.org Git - thirdparty/git.git/commitdiff
commit-graph: stop using `the_repository`
authorPatrick Steinhardt <ps@pks.im>
Fri, 15 Aug 2025 05:49:51 +0000 (07:49 +0200)
committerJunio C Hamano <gitster@pobox.com>
Fri, 15 Aug 2025 16:34:48 +0000 (09:34 -0700)
There's still a bunch of uses of `the_repository` in "commit-graph.c",
which we want to stop using due to it being a global variable. Refactor
the code to stop using `the_repository` in favor of the repository
provided via the calling context.

This allows us to drop the `USE_THE_REPOSITORY_VARIABLE` macro.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/commit.c
builtin/merge.c
commit-graph.c
commit-graph.h

index b5b96088133b123c781678554112d6582791b712..8a5dee384d71e10de77689f073933cbee962f0ea 100644 (file)
@@ -1947,7 +1947,7 @@ int cmd_commit(int argc,
                      "new index file. Check that disk is not full and quota is\n"
                      "not exceeded, and then \"git restore --staged :/\" to recover."));
 
-       git_test_write_commit_graph_or_die();
+       git_test_write_commit_graph_or_die(the_repository->objects->sources);
 
        repo_rerere(the_repository, 0);
        run_auto_maintenance(quiet);
index dc4cb8fb14dbf314ecc3248ff27c4039101c7466..a62317f4fdd91d49a703afabbc44e595521264e2 100644 (file)
@@ -1862,7 +1862,7 @@ int cmd_merge(int argc,
        if (squash) {
                finish(head_commit, remoteheads, NULL, NULL);
 
-               git_test_write_commit_graph_or_die();
+               git_test_write_commit_graph_or_die(the_repository->objects->sources);
        } else
                write_merge_state(remoteheads);
 
index fbb351d9ee465ac03fa71bad5b0d820ccf5aae05..d6f0bf5e88a1245dc8273c44fae4d52d45c4d8b8 100644 (file)
@@ -1,4 +1,3 @@
-#define USE_THE_REPOSITORY_VARIABLE
 #define DISABLE_SIGN_COMPARE_WARNINGS
 
 #include "git-compat-util.h"
@@ -29,7 +28,7 @@
 #include "tree.h"
 #include "chunk-format.h"
 
-void git_test_write_commit_graph_or_die(void)
+void git_test_write_commit_graph_or_die(struct odb_source *source)
 {
        int flags = 0;
        if (!git_env_bool(GIT_TEST_COMMIT_GRAPH, 0))
@@ -38,8 +37,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->sources,
-                                        flags, NULL))
+       if (write_commit_graph_reachable(source, flags, NULL))
                die("failed to write commit-graph under GIT_TEST_COMMIT_GRAPH");
 }
 
@@ -597,7 +595,7 @@ static int add_graph_to_chain(struct commit_graph *g,
                if (!cur_g ||
                    !oideq(&oids[n], &cur_g->oid) ||
                    !hasheq(oids[n].hash, g->chunk_base_graphs + st_mult(g->hash_algo->rawsz, n),
-                           the_repository->hash_algo)) {
+                           g->hash_algo)) {
                        warning(_("commit-graph chain does not match"));
                        return 0;
                }
@@ -666,7 +664,7 @@ struct commit_graph *load_commit_graph_chain_fd_st(struct repository *r,
                if (strbuf_getline_lf(&line, fp) == EOF)
                        break;
 
-               if (get_oid_hex(line.buf, &oids[i])) {
+               if (get_oid_hex_algop(line.buf, &oids[i], r->hash_algo)) {
                        warning(_("invalid commit-graph chain: line '%s' not a hash"),
                                line.buf);
                        valid = 0;
@@ -752,7 +750,7 @@ static void prepare_commit_graph_one(struct repository *r,
  * Return 1 if commit_graph is non-NULL, and 0 otherwise.
  *
  * On the first invocation, this function attempts to load the commit
- * graph if the_repository is configured to have one.
+ * graph if the repository is configured to have one.
  */
 static int prepare_commit_graph(struct repository *r)
 {
@@ -873,7 +871,7 @@ static void load_oid_from_graph(struct commit_graph *g,
        lex_index = pos - g->num_commits_in_base;
 
        oidread(oid, g->chunk_oid_lookup + st_mult(g->hash_algo->rawsz, lex_index),
-               the_repository->hash_algo);
+               g->hash_algo);
 }
 
 static struct commit_list **insert_parent_or_die(struct repository *r,
@@ -1116,7 +1114,7 @@ static struct tree *load_tree_for_commit(struct repository *r,
                        st_mult(graph_data_width(g->hash_algo),
                                graph_pos - g->num_commits_in_base);
 
-       oidread(&oid, commit_data, the_repository->hash_algo);
+       oidread(&oid, commit_data, g->hash_algo);
        set_commit_tree(c, lookup_tree(r, &oid));
 
        return c->maybe_tree;
@@ -1543,7 +1541,7 @@ static void close_reachable(struct write_commit_graph_context *ctx)
 
        if (ctx->report_progress)
                ctx->progress = start_delayed_progress(
-                                       the_repository,
+                                       ctx->r,
                                        _("Loading known commits in commit graph"),
                                        ctx->oids.nr);
        for (i = 0; i < ctx->oids.nr; i++) {
@@ -1561,7 +1559,7 @@ static void close_reachable(struct write_commit_graph_context *ctx)
         */
        if (ctx->report_progress)
                ctx->progress = start_delayed_progress(
-                                       the_repository,
+                                       ctx->r,
                                        _("Expanding reachable commits in commit graph"),
                                        0);
        for (i = 0; i < ctx->oids.nr; i++) {
@@ -1582,7 +1580,7 @@ static void close_reachable(struct write_commit_graph_context *ctx)
 
        if (ctx->report_progress)
                ctx->progress = start_delayed_progress(
-                                       the_repository,
+                                       ctx->r,
                                        _("Clearing commit marks in commit graph"),
                                        ctx->oids.nr);
        for (i = 0; i < ctx->oids.nr; i++) {
@@ -1700,7 +1698,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,
+                                       ctx->r,
                                        _("Computing commit graph topological levels"),
                                        ctx->commits.nr);
 
@@ -1735,7 +1733,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,
+                                       ctx->r,
                                        _("Computing commit graph generation numbers"),
                                        ctx->commits.nr);
 
@@ -1812,7 +1810,7 @@ static void compute_bloom_filters(struct write_commit_graph_context *ctx)
 
        if (ctx->report_progress)
                progress = start_delayed_progress(
-                       the_repository,
+                       ctx->r,
                        _("Computing commit changed paths Bloom filters"),
                        ctx->commits.nr);
 
@@ -1858,6 +1856,7 @@ static void compute_bloom_filters(struct write_commit_graph_context *ctx)
 }
 
 struct refs_cb_data {
+       struct repository *repo;
        struct oidset *commits;
        struct progress *progress;
 };
@@ -1870,9 +1869,9 @@ static int add_ref_to_set(const char *refname UNUSED,
        struct object_id peeled;
        struct refs_cb_data *data = (struct refs_cb_data *)cb_data;
 
-       if (!peel_iterated_oid(the_repository, oid, &peeled))
+       if (!peel_iterated_oid(data->repo, oid, &peeled))
                oid = &peeled;
-       if (odb_read_object_info(the_repository->objects, oid, NULL) == OBJ_COMMIT)
+       if (odb_read_object_info(data->repo->objects, oid, NULL) == OBJ_COMMIT)
                oidset_insert(data->commits, oid);
 
        display_progress(data->progress, oidset_size(data->commits));
@@ -1889,13 +1888,15 @@ int write_commit_graph_reachable(struct odb_source *source,
        int result;
 
        memset(&data, 0, sizeof(data));
+       data.repo = source->odb->repo;
        data.commits = &commits;
+
        if (flags & COMMIT_GRAPH_WRITE_PROGRESS)
                data.progress = start_delayed_progress(
-                       the_repository,
+                       source->odb->repo,
                        _("Collecting referenced commits"), 0);
 
-       refs_for_each_ref(get_main_ref_store(the_repository), add_ref_to_set,
+       refs_for_each_ref(get_main_ref_store(source->odb->repo), add_ref_to_set,
                          &data);
 
        stop_progress(&data.progress);
@@ -1924,7 +1925,7 @@ 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(the_repository,
+               ctx->progress = start_delayed_progress(ctx->r,
                                                       progress_title.buf, 0);
                ctx->progress_done = 0;
        }
@@ -1978,7 +1979,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,
+                       ctx->r,
                        _("Finding commits for commit graph among packed objects"),
                        ctx->approx_nr_objects);
        for_each_packed_object(ctx->r, add_packed_commits, ctx,
@@ -1997,7 +1998,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,
+                       ctx->r,
                        _("Finding extra edges in commit graph"),
                        ctx->oids.nr);
        oid_array_sort(&ctx->oids);
@@ -2076,7 +2077,7 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx)
                ctx->graph_name = get_commit_graph_filename(ctx->odb_source);
        }
 
-       if (safe_create_leading_directories(the_repository, ctx->graph_name)) {
+       if (safe_create_leading_directories(ctx->r, ctx->graph_name)) {
                error(_("unable to create leading directories of %s"),
                        ctx->graph_name);
                return -1;
@@ -2095,18 +2096,18 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx)
                        return -1;
                }
 
-               if (adjust_shared_perm(the_repository, get_tempfile_path(graph_layer))) {
+               if (adjust_shared_perm(ctx->r, get_tempfile_path(graph_layer))) {
                        error(_("unable to adjust shared permissions for '%s'"),
                              get_tempfile_path(graph_layer));
                        return -1;
                }
 
-               f = hashfd(the_repository->hash_algo,
+               f = hashfd(ctx->r->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(the_repository->hash_algo,
+               f = hashfd(ctx->r->hash_algo,
                           get_lock_file_fd(&lk), get_lock_file_path(&lk));
        }
 
@@ -2159,7 +2160,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,
+                       ctx->r,
                        progress_title.buf,
                        st_mult(get_num_chunks(cf), ctx->commits.nr));
        }
@@ -2217,7 +2218,8 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx)
                }
 
                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));
+               ctx->commit_graph_hash_after[ctx->num_commit_graphs_after - 1] =
+                       xstrdup(hash_to_hex_algop(file_hash, ctx->r->hash_algo));
                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]);
@@ -2372,7 +2374,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,
+                                       ctx->r,
                                        _("Scanning merged commits"),
                                        ctx->commits.nr);
 
@@ -2417,7 +2419,7 @@ static void merge_commit_graphs(struct write_commit_graph_context *ctx)
                current_graph_number--;
 
                if (ctx->report_progress)
-                       ctx->progress = start_delayed_progress(the_repository,
+                       ctx->progress = start_delayed_progress(ctx->r,
                                                               _("Merging commit-graph"), 0);
 
                merge_commit_graph(ctx, g);
@@ -2520,7 +2522,7 @@ int write_commit_graph(struct odb_source *source,
                       enum commit_graph_write_flags flags,
                       const struct commit_graph_opts *opts)
 {
-       struct repository *r = the_repository;
+       struct repository *r = source->odb->repo;
        struct write_commit_graph_context ctx = {
                .r = r,
                .odb_source = source,
@@ -2620,14 +2622,14 @@ int write_commit_graph(struct odb_source *source,
                        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(r);
 
        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_algo->rawsz, i),
-                               the_repository->hash_algo);
+                               r->hash_algo);
                        oid_array_append(&ctx.oids, &oid);
                }
        }
@@ -2735,7 +2737,7 @@ static void graph_report(const char *fmt, ...)
 
 static int commit_graph_checksum_valid(struct commit_graph *g)
 {
-       return hashfile_checksum_valid(the_repository->hash_algo,
+       return hashfile_checksum_valid(g->hash_algo,
                                       g->data, g->data_len);
 }
 
@@ -2758,7 +2760,7 @@ static int verify_one_commit_graph(struct repository *r,
                struct commit *graph_commit;
 
                oidread(&cur_oid, g->chunk_oid_lookup + st_mult(g->hash_algo->rawsz, i),
-                       the_repository->hash_algo);
+                       g->hash_algo);
 
                if (i && oidcmp(&prev_oid, &cur_oid) >= 0)
                        graph_report(_("commit-graph has incorrect OID order: %s then %s"),
@@ -2803,7 +2805,7 @@ static int verify_one_commit_graph(struct repository *r,
 
                display_progress(progress, ++(*seen));
                oidread(&cur_oid, g->chunk_oid_lookup + st_mult(g->hash_algo->rawsz, i),
-                       the_repository->hash_algo);
+                       g->hash_algo);
 
                graph_commit = lookup_commit(r, &cur_oid);
                odb_commit = (struct commit *)create_object(r, &cur_oid, alloc_commit_node(r));
@@ -2907,7 +2909,7 @@ 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(the_repository,
+               progress = start_progress(r,
                                          _("Verifying commits in commit graph"),
                                          total);
        }
index df10daf01c7ae044043fc4ac17e89ba080d69813..0a67ac92803d0eb8bbbf5437f8b4c83ae54e69c8 100644 (file)
@@ -21,7 +21,7 @@
  * call this method oustide of a builtin, and only if you know what
  * you are doing!
  */
-void git_test_write_commit_graph_or_die(void);
+void git_test_write_commit_graph_or_die(struct odb_source *source);
 
 struct commit;
 struct bloom_filter_settings;