]> git.ipfire.org Git - thirdparty/git.git/commitdiff
use repo_hold_lock_file_for_update{,_mode,_timeout}() with custom repos
authorRené Scharfe <l.s.r@web.de>
Tue, 14 Jul 2026 17:59:56 +0000 (19:59 +0200)
committerJunio C Hamano <gitster@pobox.com>
Tue, 14 Jul 2026 19:54:25 +0000 (12:54 -0700)
Apply the config setting core.sharedRepository from the repository at
hand instead of from the_repository.

Signed-off-by: René Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
17 files changed:
apply.c
builtin/difftool.c
builtin/gc.c
builtin/history.c
builtin/sparse-checkout.c
bundle.c
commit-graph.c
config.c
loose.c
midx-write.c
odb/source-files.c
refs/files-backend.c
refs/packed-backend.c
refs/packed-backend.h
repack-midx.c
repository.c
rerere.c

diff --git a/apply.c b/apply.c
index 5e54453f799ea2ccc736e4f213641e4bdd95a07d..ac1bfc7f85a5d5a506ed2ca8021c733380aa54b9 100644 (file)
--- a/apply.c
+++ b/apply.c
@@ -4287,7 +4287,8 @@ static int build_fake_ancestor(struct apply_state *state, struct patch *list)
                }
        }
 
-       hold_lock_file_for_update(&lock, state->fake_ancestor, LOCK_DIE_ON_ERROR);
+       repo_hold_lock_file_for_update(state->repo, &lock, state->fake_ancestor,
+                                      LOCK_DIE_ON_ERROR);
        res = write_locked_index(&result, &lock, COMMIT_LOCK);
        discard_index(&result);
 
@@ -4945,9 +4946,10 @@ static int apply_patch(struct apply_state *state,
        state->update_index = (state->check_index || state->ita_only) && state->apply;
        if (state->update_index && !is_lock_file_locked(&state->lock_file)) {
                if (state->index_file)
-                       hold_lock_file_for_update(&state->lock_file,
-                                                 state->index_file,
-                                                 LOCK_DIE_ON_ERROR);
+                       repo_hold_lock_file_for_update(state->repo,
+                                                      &state->lock_file,
+                                                      state->index_file,
+                                                      LOCK_DIE_ON_ERROR);
                else
                        repo_hold_locked_index(state->repo, &state->lock_file,
                                               LOCK_DIE_ON_ERROR);
index 26778f8515deefc835c041a69a98655718e87bb1..99c01c92ef212a55bc3640fc7b229280cd73f01f 100644 (file)
@@ -636,7 +636,7 @@ static int run_dir_diff(struct repository *repo,
                        struct lock_file lock = LOCK_INIT;
                        strbuf_reset(&buf);
                        strbuf_addf(&buf, "%s/wtindex", tmpdir.buf);
-                       if (hold_lock_file_for_update(&lock, buf.buf, 0) < 0 ||
+                       if (repo_hold_lock_file_for_update(repo, &lock, buf.buf, 0) < 0 ||
                            write_locked_index(&wtindex, &lock, COMMIT_LOCK)) {
                                ret = error("could not write %s", buf.buf);
                                goto finish;
index c26c93ee0fe4a3cbdb7b9241c1296e3b1b4aed7f..01d034829c609b3f8cf5f12df0b70406f766c2e0 100644 (file)
@@ -1790,7 +1790,7 @@ static int maintenance_run_tasks(struct maintenance_run_opts *opts,
        struct repository *r = the_repository;
        char *lock_path = xstrfmt("%s/maintenance", r->objects->sources->path);
 
-       if (hold_lock_file_for_update(&lk, lock_path, LOCK_NO_DEREF) < 0) {
+       if (repo_hold_lock_file_for_update(r, &lk, lock_path, LOCK_NO_DEREF) < 0) {
                /*
                 * Another maintenance command is running.
                 *
index 091465a59e2f962c001228e907bf93698acc11b8..5b070fb33514088b04890df624a07a5818ae1e7a 100644 (file)
@@ -764,7 +764,7 @@ static int write_ondisk_index(struct repository *repo,
 
        prime_cache_tree(repo, &index, tree);
 
-       if (hold_lock_file_for_update(&lock, path, 0) < 0) {
+       if (repo_hold_lock_file_for_update(repo, &lock, path, 0) < 0) {
                ret = error_errno(_("unable to acquire index lock"));
                goto out;
        }
index 0863d0fb460cf80bdbce6bcc270bd25eb81a557b..cb4a037b77029156f1bf5dc25f307e83224a87ee 100644 (file)
@@ -341,7 +341,8 @@ static int write_patterns_and_update(struct repository *repo,
        if (safe_create_leading_directories(repo, sparse_filename))
                die(_("failed to create directory for sparse-checkout file"));
 
-       hold_lock_file_for_update(&lk, sparse_filename, LOCK_DIE_ON_ERROR);
+       repo_hold_lock_file_for_update(repo, &lk, sparse_filename,
+                                      LOCK_DIE_ON_ERROR);
 
        result = update_working_directory(repo, pl);
        if (result) {
index fd2db2c837df603771418009ec38504fe3b853bb..b64716f252b78f288444c32a6d3cc2e02e3e78bd 100644 (file)
--- a/bundle.c
+++ b/bundle.c
@@ -519,8 +519,8 @@ int create_bundle(struct repository *r, const char *path,
        if (bundle_to_stdout)
                bundle_fd = 1;
        else
-               bundle_fd = hold_lock_file_for_update(&lock, path,
-                                                     LOCK_DIE_ON_ERROR);
+               bundle_fd = repo_hold_lock_file_for_update(r, &lock, path,
+                                                          LOCK_DIE_ON_ERROR);
 
        if (version == -1)
                version = min_version;
index 801471a09802d9b124acc0e0facca5781cc54611..063b545eb75c1e472d5f64182f73b6b46394682d 100644 (file)
@@ -2122,8 +2122,8 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx)
        if (ctx->split) {
                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);
+               repo_hold_lock_file_for_update_mode(ctx->r, &lk, lock_name,
+                                                   LOCK_DIE_ON_ERROR, 0444);
                free(lock_name);
 
                graph_layer = mks_tempfile_m(ctx->graph_name, 0444);
@@ -2141,8 +2141,9 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx)
                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);
+               repo_hold_lock_file_for_update_mode(ctx->r, &lk,
+                                                   ctx->graph_name,
+                                                   LOCK_DIE_ON_ERROR, 0444);
                f = hashfd(ctx->r->hash_algo,
                           get_lock_file_fd(&lk), get_lock_file_path(&lk));
        }
index 6a0de86e3ae95865f39b8608ed037de06f2f47fb..d29425ab8e8408b206ac4357759f91bda3e6e1ea 100644 (file)
--- a/config.c
+++ b/config.c
@@ -3034,7 +3034,7 @@ int repo_config_set_multivar_in_file_gently(struct repository *r,
         * The lock serves a purpose in addition to locking: the new
         * contents of .git/config will be written into it.
         */
-       fd = hold_lock_file_for_update(&lock, config_filename, 0);
+       fd = repo_hold_lock_file_for_update(r, &lock, config_filename, 0);
        if (fd < 0) {
                error_errno(_("could not lock config file %s"), config_filename);
                ret = CONFIG_NO_LOCK;
@@ -3379,7 +3379,7 @@ static int repo_config_copy_or_rename_section_in_file(
        if (!config_filename)
                config_filename = filename_buf = repo_git_path(r, "config");
 
-       out_fd = hold_lock_file_for_update(&lock, config_filename, 0);
+       out_fd = repo_hold_lock_file_for_update(r, &lock, config_filename, 0);
        if (out_fd < 0) {
                ret = error(_("could not lock config file %s"), config_filename);
                goto out;
diff --git a/loose.c b/loose.c
index 0b626c1b85464209cc7b2be796ab8c8b012ac997..a79cafd38aae98bd316d870f1a0c49d4477c8046 100644 (file)
--- a/loose.c
+++ b/loose.c
@@ -138,7 +138,8 @@ int repo_write_loose_object_map(struct repository *repo)
                return 0;
 
        repo_common_path_replace(repo, &path, "objects/loose-object-idx");
-       fd = hold_lock_file_for_update_timeout(&lock, path.buf, LOCK_DIE_ON_ERROR, -1);
+       fd = repo_hold_lock_file_for_update_timeout(repo, &lock, path.buf,
+                                                   LOCK_DIE_ON_ERROR, -1);
        iter = kh_begin(map);
        if (write_in_full(fd, loose_object_header, strlen(loose_object_header)) < 0)
                goto errout;
@@ -180,7 +181,8 @@ static int write_one_object(struct odb_source_loose *loose,
        struct strbuf buf = STRBUF_INIT, path = STRBUF_INIT;
 
        strbuf_addf(&path, "%s/loose-object-idx", loose->base.path);
-       hold_lock_file_for_update_timeout(&lock, path.buf, LOCK_DIE_ON_ERROR, -1);
+       repo_hold_lock_file_for_update_timeout(loose->base.odb->repo, &lock,
+                                              path.buf, LOCK_DIE_ON_ERROR, -1);
 
        fd = open(path.buf, O_WRONLY | O_CREAT | O_APPEND, 0666);
        if (fd < 0)
index 19e1cd10b7dee4c6dcab90f14d6ca7d65738dc5a..e0730d02545687e5e1f2be339036e428eaa09ba2 100644 (file)
@@ -1627,8 +1627,8 @@ static int write_midx_internal(struct write_midx_opts *opts)
                        struct strbuf lock_name = STRBUF_INIT;
 
                        get_midx_chain_filename(opts->source, &lock_name);
-                       hold_lock_file_for_update(&lk, lock_name.buf,
-                                                 LOCK_DIE_ON_ERROR);
+                       repo_hold_lock_file_for_update(r, &lk, lock_name.buf,
+                                                      LOCK_DIE_ON_ERROR);
                        strbuf_release(&lock_name);
                }
 
@@ -1647,7 +1647,8 @@ static int write_midx_internal(struct write_midx_opts *opts)
                f = hashfd(r->hash_algo, get_tempfile_fd(incr),
                           get_tempfile_path(incr));
        } else {
-               hold_lock_file_for_update(&lk, midx_name.buf, LOCK_DIE_ON_ERROR);
+               repo_hold_lock_file_for_update(r, &lk, midx_name.buf,
+                                              LOCK_DIE_ON_ERROR);
                f = hashfd(r->hash_algo, get_lock_file_fd(&lk),
                           get_lock_file_path(&lk));
        }
index 5bdd04292253971fdfc3cb60fb9f1201a6075f2e..3dd9e71e7341e5a5f831cb89237c03fd70131ab2 100644 (file)
@@ -217,7 +217,8 @@ static int odb_source_files_write_alternate(struct odb_source *source,
        int found = 0;
        int ret;
 
-       hold_lock_file_for_update(&lock, path, LOCK_DIE_ON_ERROR);
+       repo_hold_lock_file_for_update(source->odb->repo, &lock, path,
+                                      LOCK_DIE_ON_ERROR);
        out = fdopen_lock_file(&lock, "w");
        if (!out) {
                ret = error_errno(_("unable to fdopen alternates lockfile"));
index a4c7858787127d1ffd76d6b898ab928a68d33afc..2e82258844e8725881e114aa8e46f45c263eea2c 100644 (file)
@@ -791,7 +791,7 @@ retry:
                goto error_return;
        }
 
-       if (hold_lock_file_for_update_timeout(
+       if (repo_hold_lock_file_for_update_timeout(refs->base.repo,
                            &lock->lk, ref_file.buf, LOCK_NO_DEREF,
                            get_files_ref_lock_timeout_ms(transaction->ref_store->repo)) < 0) {
                int myerr = errno;
@@ -1199,8 +1199,8 @@ struct create_reflock_cb {
 static int create_reflock(const char *path, void *cb)
 {
        struct create_reflock_cb *data = cb;
-       return hold_lock_file_for_update_timeout(
-                       data->lk, path, LOCK_NO_DEREF,
+       return repo_hold_lock_file_for_update_timeout(
+                       data->repo, data->lk, path, LOCK_NO_DEREF,
                        get_files_ref_lock_timeout_ms(data->repo)) < 0 ? -1 : 0;
 }
 
@@ -3529,7 +3529,9 @@ static int files_reflog_expire(struct ref_store *ref_store,
                 * work we need, including cleaning up if the program
                 * exits unexpectedly.
                 */
-               if (hold_lock_file_for_update(&reflog_lock, log_file, 0) < 0) {
+               if (repo_hold_lock_file_for_update(ref_store->repo,
+                                                  &reflog_lock, log_file,
+                                                  0) < 0) {
                        struct strbuf err = STRBUF_INIT;
                        unable_to_lock_message(log_file, errno, &err);
                        error("%s", err.buf);
index 7c4e8aca87355596215f505e2c6b32721d728327..117f2d43681a6b0ce171247240caeb49f56236b4 100644 (file)
@@ -1232,10 +1232,9 @@ int packed_refs_lock(struct ref_store *ref_store, int flags, struct strbuf *err)
         * don't write new content to it, but rather to a separate
         * tempfile.
         */
-       if (hold_lock_file_for_update_timeout(
-                           &refs->lock,
-                           refs->path,
-                           flags, timeout_value) < 0) {
+       if (repo_hold_lock_file_for_update_timeout(ref_store->repo, &refs->lock,
+                                                  refs->path, flags,
+                                                  timeout_value) < 0) {
                unable_to_lock_message(refs->path, errno, err);
                return -1;
        }
index 1db48e801d63d0c97001d96861d90037a5a5ba51..8a7b3238254d3d0fd4e504443497323862863319 100644 (file)
@@ -21,7 +21,7 @@ struct ref_store *packed_ref_store_init(struct repository *repo,
 
 /*
  * Lock the packed-refs file for writing. Flags is passed to
- * hold_lock_file_for_update(). Return 0 on success. On errors, write
+ * repo_hold_lock_file_for_update(). Return 0 on success. On errors, write
  * an error message to `err` and return a nonzero value.
  */
 int packed_refs_lock(struct ref_store *ref_store, int flags, struct strbuf *err);
index b6b1de718058dac998180bac067d424966f11b25..78dbed3df6a71e770e39cbbfd402fd445fc1976d 100644 (file)
@@ -951,7 +951,8 @@ static int write_midx_incremental(struct repack_write_midx_opts *opts)
                                            lock_name.buf))
                die_errno(_("unable to create leading directories of %s"),
                          lock_name.buf);
-       hold_lock_file_for_update(&lf, lock_name.buf, LOCK_DIE_ON_ERROR);
+       repo_hold_lock_file_for_update(opts->existing->repo, &lf, lock_name.buf,
+                                      LOCK_DIE_ON_ERROR);
 
        if (!fdopen_lock_file(&lf, "w")) {
                ret = error_errno(_("unable to open multi-pack-index chain file"));
index 187dd471c4e607910f093aec6cdb641f382d1229..25583073085f6108e234ae6249134eae7ce4f902 100644 (file)
@@ -466,5 +466,5 @@ int repo_hold_locked_index(struct repository *repo,
 {
        if (!repo->index_file)
                BUG("the repo hasn't been setup");
-       return hold_lock_file_for_update(lf, repo->index_file, flags);
+       return repo_hold_lock_file_for_update(repo, lf, repo->index_file, flags);
 }
index 8232542585cad411e4937c6c1ec3d1196879d199..2d1e99ec11429447570e87a90d3c1c72b7d98848 100644 (file)
--- a/rerere.c
+++ b/rerere.c
@@ -911,9 +911,9 @@ int setup_rerere(struct repository *r, struct string_list *merge_rr, int flags)
        if (flags & RERERE_READONLY)
                fd = 0;
        else
-               fd = hold_lock_file_for_update(&write_lock,
-                                              git_path_merge_rr(r),
-                                              LOCK_DIE_ON_ERROR);
+               fd = repo_hold_lock_file_for_update(r, &write_lock,
+                                                   git_path_merge_rr(r),
+                                                   LOCK_DIE_ON_ERROR);
        read_rr(r, merge_rr);
        return fd;
 }