Skip to content

Commit 3a95f31

Browse files
pcloudsgitster
authored andcommitted
repository.c: replace hold_locked_index() with repo_hold_locked_index()
hold_locked_index() assumes the index path at $GIT_DIR/index. This is not good for places that take an arbitrary index_state instead of the_index, which is basically everywhere except builtin/. Replace it with repo_hold_locked_index(). hold_locked_index() remains as a wrapper around repo_hold_locked_index() to reduce changes in builtin/ Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 1d18d75 commit 3a95f31

File tree

10 files changed

+26
-16
lines changed

10 files changed

+26
-16
lines changed

apply.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4712,7 +4712,8 @@ static int apply_patch(struct apply_state *state,
47124712
state->index_file,
47134713
LOCK_DIE_ON_ERROR);
47144714
else
4715-
hold_locked_index(&state->lock_file, LOCK_DIE_ON_ERROR);
4715+
repo_hold_locked_index(state->repo, &state->lock_file,
4716+
LOCK_DIE_ON_ERROR);
47164717
}
47174718

47184719
if (state->check_index && read_apply_cache(state) < 0) {

cache.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,7 @@ void validate_cache_entries(const struct index_state *istate);
433433
#define unmerge_cache_entry_at(at) unmerge_index_entry_at(&the_index, at)
434434
#define unmerge_cache(pathspec) unmerge_index(&the_index, pathspec)
435435
#define read_blob_data_from_cache(path, sz) read_blob_data_from_index(&the_index, (path), (sz))
436+
#define hold_locked_index(lock_file, flags) repo_hold_locked_index(the_repository, (lock_file), (flags))
436437
#endif
437438

438439
#define TYPE_BITS 3
@@ -833,7 +834,6 @@ extern struct cache_entry *refresh_cache_entry(struct index_state *, struct cach
833834
*/
834835
extern void update_index_if_able(struct index_state *, struct lock_file *);
835836

836-
extern int hold_locked_index(struct lock_file *, int);
837837
extern void set_alternate_index_output(const char *);
838838

839839
extern int verify_index_checksum;

merge-recursive.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3643,7 +3643,7 @@ int merge_recursive_generic(struct merge_options *o,
36433643
}
36443644
}
36453645

3646-
hold_locked_index(&lock, LOCK_DIE_ON_ERROR);
3646+
repo_hold_locked_index(the_repository, &lock, LOCK_DIE_ON_ERROR);
36473647
clean = merge_recursive(o, head_commit, next_commit, ca,
36483648
result);
36493649
if (clean < 0) {

merge.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ int checkout_fast_forward(struct repository *r,
5858

5959
refresh_index(r->index, REFRESH_QUIET, NULL, NULL, NULL);
6060

61-
if (hold_locked_index(&lock_file, LOCK_REPORT_ON_ERROR) < 0)
61+
if (repo_hold_locked_index(r, &lock_file, LOCK_REPORT_ON_ERROR) < 0)
6262
return -1;
6363

6464
memset(&trees, 0, sizeof(trees));

read-cache.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1733,11 +1733,6 @@ static int read_index_extension(struct index_state *istate,
17331733
return 0;
17341734
}
17351735

1736-
int hold_locked_index(struct lock_file *lk, int lock_flags)
1737-
{
1738-
return hold_lock_file_for_update(lk, get_index_file(), lock_flags);
1739-
}
1740-
17411736
int read_index(struct index_state *istate)
17421737
{
17431738
return read_index_from(istate, get_index_file(), get_git_dir());

repository.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "object-store.h"
44
#include "config.h"
55
#include "object.h"
6+
#include "lockfile.h"
67
#include "submodule-config.h"
78

89
/* The main repository */
@@ -263,3 +264,12 @@ int repo_read_index(struct repository *repo)
263264

264265
return read_index_from(repo->index, repo->index_file, repo->gitdir);
265266
}
267+
268+
int repo_hold_locked_index(struct repository *repo,
269+
struct lock_file *lf,
270+
int flags)
271+
{
272+
if (!repo->index_file)
273+
BUG("the repo hasn't been setup");
274+
return hold_lock_file_for_update(lf, repo->index_file, flags);
275+
}

repository.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
struct config_set;
77
struct git_hash_algo;
88
struct index_state;
9+
struct lock_file;
910
struct raw_object_store;
1011
struct submodule_cache;
1112

@@ -130,5 +131,8 @@ void repo_clear(struct repository *repo);
130131
* populated then the number of entries will simply be returned.
131132
*/
132133
int repo_read_index(struct repository *repo);
134+
int repo_hold_locked_index(struct repository *repo,
135+
struct lock_file *lf,
136+
int flags);
133137

134138
#endif /* REPOSITORY_H */

rerere.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,7 @@ static void update_paths(struct repository *r, struct string_list *update)
705705
struct lock_file index_lock = LOCK_INIT;
706706
int i;
707707

708-
hold_locked_index(&index_lock, LOCK_DIE_ON_ERROR);
708+
repo_hold_locked_index(r, &index_lock, LOCK_DIE_ON_ERROR);
709709

710710
for (i = 0; i < update->nr; i++) {
711711
struct string_list_item *item = &update->items[i];

sequencer.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ static int do_recursive_merge(struct repository *r,
540540
char **xopt;
541541
struct lock_file index_lock = LOCK_INIT;
542542

543-
if (hold_locked_index(&index_lock, LOCK_REPORT_ON_ERROR) < 0)
543+
if (repo_hold_locked_index(r, &index_lock, LOCK_REPORT_ON_ERROR) < 0)
544544
return -1;
545545

546546
read_index(r->index);
@@ -1992,8 +1992,8 @@ static int read_and_refresh_cache(struct repository *r,
19921992
struct replay_opts *opts)
19931993
{
19941994
struct lock_file index_lock = LOCK_INIT;
1995-
int index_fd = hold_locked_index(&index_lock, 0);
1996-
if (read_index(r->index) < 0) {
1995+
int index_fd = repo_hold_locked_index(r, &index_lock, 0);
1996+
if (repo_read_index(r) < 0) {
19971997
rollback_lock_file(&index_lock);
19981998
return error(_("git %s: failed to read the index"),
19991999
_(action_name(opts)));
@@ -2978,7 +2978,7 @@ static int do_reset(struct repository *r,
29782978
struct unpack_trees_options unpack_tree_opts;
29792979
int ret = 0;
29802980

2981-
if (hold_locked_index(&lock, LOCK_REPORT_ON_ERROR) < 0)
2981+
if (repo_hold_locked_index(r, &lock, LOCK_REPORT_ON_ERROR) < 0)
29822982
return -1;
29832983

29842984
if (len == 10 && !strncmp("[new root]", name, len)) {
@@ -3096,7 +3096,7 @@ static int do_merge(struct repository *r,
30963096
static struct lock_file lock;
30973097
const char *p;
30983098

3099-
if (hold_locked_index(&lock, LOCK_REPORT_ON_ERROR) < 0) {
3099+
if (repo_hold_locked_index(r, &lock, LOCK_REPORT_ON_ERROR) < 0) {
31003100
ret = -1;
31013101
goto leave_merge;
31023102
}

wt-status.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2375,7 +2375,7 @@ int require_clean_work_tree(struct repository *r,
23752375
struct lock_file lock_file = LOCK_INIT;
23762376
int err = 0, fd;
23772377

2378-
fd = hold_locked_index(&lock_file, 0);
2378+
fd = repo_hold_locked_index(r, &lock_file, 0);
23792379
refresh_index(r->index, REFRESH_QUIET, NULL, NULL, NULL);
23802380
if (0 <= fd)
23812381
update_index_if_able(r->index, &lock_file);

0 commit comments

Comments
 (0)