Skip to content

Commit 2e486bf

Browse files
rscharfegitster
authored andcommitted
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>
1 parent 75e05f6 commit 2e486bf

17 files changed

Lines changed: 46 additions & 36 deletions

apply.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4287,7 +4287,8 @@ static int build_fake_ancestor(struct apply_state *state, struct patch *list)
42874287
}
42884288
}
42894289

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);
42914292
res = write_locked_index(&result, &lock, COMMIT_LOCK);
42924293
discard_index(&result);
42934294

@@ -4945,9 +4946,10 @@ static int apply_patch(struct apply_state *state,
49454946
state->update_index = (state->check_index || state->ita_only) && state->apply;
49464947
if (state->update_index && !is_lock_file_locked(&state->lock_file)) {
49474948
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);
49514953
else
49524954
repo_hold_locked_index(state->repo, &state->lock_file,
49534955
LOCK_DIE_ON_ERROR);

builtin/difftool.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ static int run_dir_diff(struct repository *repo,
636636
struct lock_file lock = LOCK_INIT;
637637
strbuf_reset(&buf);
638638
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 ||
640640
write_locked_index(&wtindex, &lock, COMMIT_LOCK)) {
641641
ret = error("could not write %s", buf.buf);
642642
goto finish;

builtin/gc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1790,7 +1790,7 @@ static int maintenance_run_tasks(struct maintenance_run_opts *opts,
17901790
struct repository *r = the_repository;
17911791
char *lock_path = xstrfmt("%s/maintenance", r->objects->sources->path);
17921792

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) {
17941794
/*
17951795
* Another maintenance command is running.
17961796
*

builtin/history.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,7 @@ static int write_ondisk_index(struct repository *repo,
764764

765765
prime_cache_tree(repo, &index, tree);
766766

767-
if (hold_lock_file_for_update(&lock, path, 0) < 0) {
767+
if (repo_hold_lock_file_for_update(repo, &lock, path, 0) < 0) {
768768
ret = error_errno(_("unable to acquire index lock"));
769769
goto out;
770770
}

builtin/sparse-checkout.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,8 @@ static int write_patterns_and_update(struct repository *repo,
341341
if (safe_create_leading_directories(repo, sparse_filename))
342342
die(_("failed to create directory for sparse-checkout file"));
343343

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);
345346

346347
result = update_working_directory(repo, pl);
347348
if (result) {

bundle.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -519,8 +519,8 @@ int create_bundle(struct repository *r, const char *path,
519519
if (bundle_to_stdout)
520520
bundle_fd = 1;
521521
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);
524524

525525
if (version == -1)
526526
version = min_version;

commit-graph.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2122,8 +2122,8 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx)
21222122
if (ctx->split) {
21232123
char *lock_name = get_commit_graph_chain_filename(ctx->odb_source);
21242124

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);
21272127
free(lock_name);
21282128

21292129
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)
21412141
f = hashfd(ctx->r->hash_algo,
21422142
get_tempfile_fd(graph_layer), get_tempfile_path(graph_layer));
21432143
} 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);
21462147
f = hashfd(ctx->r->hash_algo,
21472148
get_lock_file_fd(&lk), get_lock_file_path(&lk));
21482149
}

config.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3034,7 +3034,7 @@ int repo_config_set_multivar_in_file_gently(struct repository *r,
30343034
* The lock serves a purpose in addition to locking: the new
30353035
* contents of .git/config will be written into it.
30363036
*/
3037-
fd = hold_lock_file_for_update(&lock, config_filename, 0);
3037+
fd = repo_hold_lock_file_for_update(r, &lock, config_filename, 0);
30383038
if (fd < 0) {
30393039
error_errno(_("could not lock config file %s"), config_filename);
30403040
ret = CONFIG_NO_LOCK;
@@ -3379,7 +3379,7 @@ static int repo_config_copy_or_rename_section_in_file(
33793379
if (!config_filename)
33803380
config_filename = filename_buf = repo_git_path(r, "config");
33813381

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);
33833383
if (out_fd < 0) {
33843384
ret = error(_("could not lock config file %s"), config_filename);
33853385
goto out;

loose.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,8 @@ int repo_write_loose_object_map(struct repository *repo)
138138
return 0;
139139

140140
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);
142143
iter = kh_begin(map);
143144
if (write_in_full(fd, loose_object_header, strlen(loose_object_header)) < 0)
144145
goto errout;
@@ -180,7 +181,8 @@ static int write_one_object(struct odb_source_loose *loose,
180181
struct strbuf buf = STRBUF_INIT, path = STRBUF_INIT;
181182

182183
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);
184186

185187
fd = open(path.buf, O_WRONLY | O_CREAT | O_APPEND, 0666);
186188
if (fd < 0)

midx-write.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1627,8 +1627,8 @@ static int write_midx_internal(struct write_midx_opts *opts)
16271627
struct strbuf lock_name = STRBUF_INIT;
16281628

16291629
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);
16321632
strbuf_release(&lock_name);
16331633
}
16341634

@@ -1647,7 +1647,8 @@ static int write_midx_internal(struct write_midx_opts *opts)
16471647
f = hashfd(r->hash_algo, get_tempfile_fd(incr),
16481648
get_tempfile_path(incr));
16491649
} 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);
16511652
f = hashfd(r->hash_algo, get_lock_file_fd(&lk),
16521653
get_lock_file_path(&lk));
16531654
}

0 commit comments

Comments
 (0)