use repo_hold_lock_file_for_update{,_mode,_timeout}() with custom repos

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>

René Scharfe committed Jul 14, 2026 at 19:59 UTC 2e486bfbf75c5098406a07e6967ecb80a28c316a
17 files changed +46 -36
apply.c
+6 -4
@@ -4287,7 +4287,8 @@ static int build_fake_ancestor(struct apply_state *state, struct patch *list)
4287 }
4288 }
4289
4290 - hold_lock_file_for_update(&lock, state->fake_ancestor, LOCK_DIE_ON_ERROR);
4290 + repo_hold_lock_file_for_update(state->repo, &lock, state->fake_ancestor,
4291 + LOCK_DIE_ON_ERROR);
4292 res = write_locked_index(&result, &lock, COMMIT_LOCK);
4293 discard_index(&result);
4294
@@ -4945,9 +4946,10 @@ static int apply_patch(struct apply_state *state,
4946 state->update_index = (state->check_index || state->ita_only) && state->apply;
4947 if (state->update_index && !is_lock_file_locked(&state->lock_file)) {
4948 if (state->index_file)
4948 - hold_lock_file_for_update(&state->lock_file,
4949 - state->index_file,
4950 - LOCK_DIE_ON_ERROR);
4949 + repo_hold_lock_file_for_update(state->repo,
4950 + &state->lock_file,
4951 + state->index_file,
4952 + LOCK_DIE_ON_ERROR);
4953 else
4954 repo_hold_locked_index(state->repo, &state->lock_file,
4955 LOCK_DIE_ON_ERROR);
builtin/difftool.c
+1 -1
@@ -636,7 +636,7 @@ static int run_dir_diff(struct repository *repo,
636 struct lock_file lock = LOCK_INIT;
637 strbuf_reset(&buf);
638 strbuf_addf(&buf, "%s/wtindex", tmpdir.buf);
639 - if (hold_lock_file_for_update(&lock, buf.buf, 0) < 0 ||
639 + if (repo_hold_lock_file_for_update(repo, &lock, buf.buf, 0) < 0 ||
640 write_locked_index(&wtindex, &lock, COMMIT_LOCK)) {
641 ret = error("could not write %s", buf.buf);
642 goto finish;
builtin/gc.c
+1 -1
@@ -1790,7 +1790,7 @@ static int maintenance_run_tasks(struct maintenance_run_opts *opts,
1790 struct repository *r = the_repository;
1791 char *lock_path = xstrfmt("%s/maintenance", r->objects->sources->path);
1792
1793 - if (hold_lock_file_for_update(&lk, lock_path, LOCK_NO_DEREF) < 0) {
1793 + if (repo_hold_lock_file_for_update(r, &lk, lock_path, LOCK_NO_DEREF) < 0) {
1794 /*
1795 * Another maintenance command is running.
1796 *
builtin/history.c
+1 -1
@@ -764,7 +764,7 @@ static int write_ondisk_index(struct repository *repo,
764
765 prime_cache_tree(repo, &index, tree);
766
767 - if (hold_lock_file_for_update(&lock, path, 0) < 0) {
767 + if (repo_hold_lock_file_for_update(repo, &lock, path, 0) < 0) {
768 ret = error_errno(_("unable to acquire index lock"));
769 goto out;
770 }
builtin/sparse-checkout.c
+2 -1
@@ -341,7 +341,8 @@ static int write_patterns_and_update(struct repository *repo,
341 if (safe_create_leading_directories(repo, sparse_filename))
342 die(_("failed to create directory for sparse-checkout file"));
343
344 - hold_lock_file_for_update(&lk, sparse_filename, LOCK_DIE_ON_ERROR);
344 + repo_hold_lock_file_for_update(repo, &lk, sparse_filename,
345 + LOCK_DIE_ON_ERROR);
346
347 result = update_working_directory(repo, pl);
348 if (result) {
bundle.c
+2 -2
@@ -519,8 +519,8 @@ int create_bundle(struct repository *r, const char *path,
519 if (bundle_to_stdout)
520 bundle_fd = 1;
521 else
522 - bundle_fd = hold_lock_file_for_update(&lock, path,
523 - LOCK_DIE_ON_ERROR);
522 + bundle_fd = repo_hold_lock_file_for_update(r, &lock, path,
523 + LOCK_DIE_ON_ERROR);
524
525 if (version == -1)
526 version = min_version;
commit-graph.c
+5 -4
@@ -2122,8 +2122,8 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx)
2122 if (ctx->split) {
2123 char *lock_name = get_commit_graph_chain_filename(ctx->odb_source);
2124
2125 - hold_lock_file_for_update_mode(&lk, lock_name,
2126 - LOCK_DIE_ON_ERROR, 0444);
2125 + repo_hold_lock_file_for_update_mode(ctx->r, &lk, lock_name,
2126 + LOCK_DIE_ON_ERROR, 0444);
2127 free(lock_name);
2128
2129 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)
2141 f = hashfd(ctx->r->hash_algo,
2142 get_tempfile_fd(graph_layer), get_tempfile_path(graph_layer));
2143 } else {
2144 - hold_lock_file_for_update_mode(&lk, ctx->graph_name,
2145 - LOCK_DIE_ON_ERROR, 0444);
2144 + repo_hold_lock_file_for_update_mode(ctx->r, &lk,
2145 + ctx->graph_name,
2146 + LOCK_DIE_ON_ERROR, 0444);
2147 f = hashfd(ctx->r->hash_algo,
2148 get_lock_file_fd(&lk), get_lock_file_path(&lk));
2149 }
config.c
+2 -2
@@ -3034,7 +3034,7 @@ int repo_config_set_multivar_in_file_gently(struct repository *r,
3034 * The lock serves a purpose in addition to locking: the new
3035 * contents of .git/config will be written into it.
3036 */
3037 - fd = hold_lock_file_for_update(&lock, config_filename, 0);
3037 + fd = repo_hold_lock_file_for_update(r, &lock, config_filename, 0);
3038 if (fd < 0) {
3039 error_errno(_("could not lock config file %s"), config_filename);
3040 ret = CONFIG_NO_LOCK;
@@ -3379,7 +3379,7 @@ static int repo_config_copy_or_rename_section_in_file(
3379 if (!config_filename)
3380 config_filename = filename_buf = repo_git_path(r, "config");
3381
3382 - out_fd = hold_lock_file_for_update(&lock, config_filename, 0);
3382 + out_fd = repo_hold_lock_file_for_update(r, &lock, config_filename, 0);
3383 if (out_fd < 0) {
3384 ret = error(_("could not lock config file %s"), config_filename);
3385 goto out;
loose.c
+4 -2
@@ -138,7 +138,8 @@ int repo_write_loose_object_map(struct repository *repo)
138 return 0;
139
140 repo_common_path_replace(repo, &path, "objects/loose-object-idx");
141 - fd = hold_lock_file_for_update_timeout(&lock, path.buf, LOCK_DIE_ON_ERROR, -1);
141 + fd = repo_hold_lock_file_for_update_timeout(repo, &lock, path.buf,
142 + LOCK_DIE_ON_ERROR, -1);
143 iter = kh_begin(map);
144 if (write_in_full(fd, loose_object_header, strlen(loose_object_header)) < 0)
145 goto errout;
@@ -180,7 +181,8 @@ static int write_one_object(struct odb_source_loose *loose,
181 struct strbuf buf = STRBUF_INIT, path = STRBUF_INIT;
182
183 strbuf_addf(&path, "%s/loose-object-idx", loose->base.path);
183 - hold_lock_file_for_update_timeout(&lock, path.buf, LOCK_DIE_ON_ERROR, -1);
184 + repo_hold_lock_file_for_update_timeout(loose->base.odb->repo, &lock,
185 + path.buf, LOCK_DIE_ON_ERROR, -1);
186
187 fd = open(path.buf, O_WRONLY | O_CREAT | O_APPEND, 0666);
188 if (fd < 0)
midx-write.c
+4 -3
@@ -1627,8 +1627,8 @@ static int write_midx_internal(struct write_midx_opts *opts)
1627 struct strbuf lock_name = STRBUF_INIT;
1628
1629 get_midx_chain_filename(opts->source, &lock_name);
1630 - hold_lock_file_for_update(&lk, lock_name.buf,
1631 - LOCK_DIE_ON_ERROR);
1630 + repo_hold_lock_file_for_update(r, &lk, lock_name.buf,
1631 + LOCK_DIE_ON_ERROR);
1632 strbuf_release(&lock_name);
1633 }
1634
@@ -1647,7 +1647,8 @@ static int write_midx_internal(struct write_midx_opts *opts)
1647 f = hashfd(r->hash_algo, get_tempfile_fd(incr),
1648 get_tempfile_path(incr));
1649 } else {
1650 - hold_lock_file_for_update(&lk, midx_name.buf, LOCK_DIE_ON_ERROR);
1650 + repo_hold_lock_file_for_update(r, &lk, midx_name.buf,
1651 + LOCK_DIE_ON_ERROR);
1652 f = hashfd(r->hash_algo, get_lock_file_fd(&lk),
1653 get_lock_file_path(&lk));
1654 }
odb/source-files.c
+2 -1
@@ -217,7 +217,8 @@ static int odb_source_files_write_alternate(struct odb_source *source,
217 int found = 0;
218 int ret;
219
220 - hold_lock_file_for_update(&lock, path, LOCK_DIE_ON_ERROR);
220 + repo_hold_lock_file_for_update(source->odb->repo, &lock, path,
221 + LOCK_DIE_ON_ERROR);
222 out = fdopen_lock_file(&lock, "w");
223 if (!out) {
224 ret = error_errno(_("unable to fdopen alternates lockfile"));
refs/files-backend.c
+6 -4
@@ -791,7 +791,7 @@ retry:
791 goto error_return;
792 }
793
794 - if (hold_lock_file_for_update_timeout(
794 + if (repo_hold_lock_file_for_update_timeout(refs->base.repo,
795 &lock->lk, ref_file.buf, LOCK_NO_DEREF,
796 get_files_ref_lock_timeout_ms(transaction->ref_store->repo)) < 0) {
797 int myerr = errno;
@@ -1199,8 +1199,8 @@ struct create_reflock_cb {
1199 static int create_reflock(const char *path, void *cb)
1200 {
1201 struct create_reflock_cb *data = cb;
1202 - return hold_lock_file_for_update_timeout(
1203 - data->lk, path, LOCK_NO_DEREF,
1202 + return repo_hold_lock_file_for_update_timeout(
1203 + data->repo, data->lk, path, LOCK_NO_DEREF,
1204 get_files_ref_lock_timeout_ms(data->repo)) < 0 ? -1 : 0;
1205 }
1206
@@ -3529,7 +3529,9 @@ static int files_reflog_expire(struct ref_store *ref_store,
3529 * work we need, including cleaning up if the program
3530 * exits unexpectedly.
3531 */
3532 - if (hold_lock_file_for_update(&reflog_lock, log_file, 0) < 0) {
3532 + if (repo_hold_lock_file_for_update(ref_store->repo,
3533 + &reflog_lock, log_file,
3534 + 0) < 0) {
3535 struct strbuf err = STRBUF_INIT;
3536 unable_to_lock_message(log_file, errno, &err);
3537 error("%s", err.buf);
refs/packed-backend.c
+3 -4
@@ -1232,10 +1232,9 @@ int packed_refs_lock(struct ref_store *ref_store, int flags, struct strbuf *err)
1232 * don't write new content to it, but rather to a separate
1233 * tempfile.
1234 */
1235 - if (hold_lock_file_for_update_timeout(
1236 - &refs->lock,
1237 - refs->path,
1238 - flags, timeout_value) < 0) {
1235 + if (repo_hold_lock_file_for_update_timeout(ref_store->repo, &refs->lock,
1236 + refs->path, flags,
1237 + timeout_value) < 0) {
1238 unable_to_lock_message(refs->path, errno, err);
1239 return -1;
1240 }
refs/packed-backend.h
+1 -1
@@ -21,7 +21,7 @@ struct ref_store *packed_ref_store_init(struct repository *repo,
21
22 /*
23 * Lock the packed-refs file for writing. Flags is passed to
24 - * hold_lock_file_for_update(). Return 0 on success. On errors, write
24 + * repo_hold_lock_file_for_update(). Return 0 on success. On errors, write
25 * an error message to `err` and return a nonzero value.
26 */
27 int packed_refs_lock(struct ref_store *ref_store, int flags, struct strbuf *err);
repack-midx.c
+2 -1
@@ -951,7 +951,8 @@ static int write_midx_incremental(struct repack_write_midx_opts *opts)
951 lock_name.buf))
952 die_errno(_("unable to create leading directories of %s"),
953 lock_name.buf);
954 - hold_lock_file_for_update(&lf, lock_name.buf, LOCK_DIE_ON_ERROR);
954 + repo_hold_lock_file_for_update(opts->existing->repo, &lf, lock_name.buf,
955 + LOCK_DIE_ON_ERROR);
956
957 if (!fdopen_lock_file(&lf, "w")) {
958 ret = error_errno(_("unable to open multi-pack-index chain file"));
repository.c
+1 -1
@@ -466,5 +466,5 @@ int repo_hold_locked_index(struct repository *repo,
466 {
467 if (!repo->index_file)
468 BUG("the repo hasn't been setup");
469 - return hold_lock_file_for_update(lf, repo->index_file, flags);
469 + return repo_hold_lock_file_for_update(repo, lf, repo->index_file, flags);
470 }
rerere.c
+3 -3
@@ -911,9 +911,9 @@ int setup_rerere(struct repository *r, struct string_list *merge_rr, int flags)
911 if (flags & RERERE_READONLY)
912 fd = 0;
913 else
914 - fd = hold_lock_file_for_update(&write_lock,
915 - git_path_merge_rr(r),
916 - LOCK_DIE_ON_ERROR);
914 + fd = repo_hold_lock_file_for_update(r, &write_lock,
915 + git_path_merge_rr(r),
916 + LOCK_DIE_ON_ERROR);
917 read_rr(r, merge_rr);
918 return fd;
919 }