Skip to content

Commit 1b0d968

Browse files
pcloudsgitster
authored andcommitted
read-cache.c: replace update_index_if_able with repo_&
Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e1ff0a3 commit 1b0d968

File tree

8 files changed

+20
-19
lines changed

8 files changed

+20
-19
lines changed

builtin/commit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1396,7 +1396,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
13961396
wt_status_collect(&s);
13971397

13981398
if (0 <= fd)
1399-
update_index_if_able(&the_index, &index_lock);
1399+
repo_update_index_if_able(the_repository, &index_lock);
14001400

14011401
if (s.relative_paths)
14021402
s.prefix = prefix;

builtin/describe.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
634634
NULL, NULL, NULL);
635635
fd = hold_locked_index(&index_lock, 0);
636636
if (0 <= fd)
637-
update_index_if_able(&the_index, &index_lock);
637+
repo_update_index_if_able(the_repository, &index_lock);
638638

639639
repo_init_revisions(the_repository, &revs, prefix);
640640
argv_array_pushv(&args, diff_index_args);

builtin/diff.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ static void refresh_index_quietly(void)
212212
discard_cache();
213213
read_cache();
214214
refresh_cache(REFRESH_QUIET|REFRESH_UNMERGED);
215-
update_index_if_able(&the_index, &lock_file);
215+
repo_update_index_if_able(the_repository, &lock_file);
216216
}
217217

218218
static int builtin_diff_files(struct rev_info *revs, int argc, const char **argv)

builtin/rebase.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,8 +1020,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
10201020
refresh_index(the_repository->index, REFRESH_QUIET, NULL, NULL,
10211021
NULL);
10221022
if (0 <= fd)
1023-
update_index_if_able(the_repository->index,
1024-
&lock_file);
1023+
repo_update_index_if_able(the_repository, &lock_file);
10251024
rollback_lock_file(&lock_file);
10261025

10271026
if (has_unstaged_changes(the_repository, 1)) {
@@ -1378,7 +1377,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
13781377
fd = hold_locked_index(&lock_file, 0);
13791378
refresh_cache(REFRESH_QUIET);
13801379
if (0 <= fd)
1381-
update_index_if_able(&the_index, &lock_file);
1380+
repo_update_index_if_able(the_repository, &lock_file);
13821381
rollback_lock_file(&lock_file);
13831382

13841383
if (has_unstaged_changes(the_repository, 1) ||

cache.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -823,12 +823,6 @@ extern void fill_stat_cache_info(struct cache_entry *ce, struct stat *st);
823823
extern int refresh_index(struct index_state *, unsigned int flags, const struct pathspec *pathspec, char *seen, const char *header_msg);
824824
extern struct cache_entry *refresh_cache_entry(struct index_state *, struct cache_entry *, unsigned int);
825825

826-
/*
827-
* Opportunistically update the index but do not complain if we can't.
828-
* The lockfile is always committed or rolled back.
829-
*/
830-
extern void update_index_if_able(struct index_state *, struct lock_file *);
831-
832826
extern void set_alternate_index_output(const char *);
833827

834828
extern int verify_index_checksum;

read-cache.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2654,9 +2654,9 @@ static int verify_index_from(const struct index_state *istate, const char *path)
26542654
return 0;
26552655
}
26562656

2657-
static int verify_index(const struct index_state *istate)
2657+
static int repo_verify_index(struct repository *repo)
26582658
{
2659-
return verify_index_from(istate, get_index_file());
2659+
return verify_index_from(repo->index, repo->index_file);
26602660
}
26612661

26622662
static int has_racy_timestamp(struct index_state *istate)
@@ -2672,11 +2672,13 @@ static int has_racy_timestamp(struct index_state *istate)
26722672
return 0;
26732673
}
26742674

2675-
void update_index_if_able(struct index_state *istate, struct lock_file *lockfile)
2675+
void repo_update_index_if_able(struct repository *repo,
2676+
struct lock_file *lockfile)
26762677
{
2677-
if ((istate->cache_changed || has_racy_timestamp(istate)) &&
2678-
verify_index(istate))
2679-
write_locked_index(istate, lockfile, COMMIT_LOCK);
2678+
if ((repo->index->cache_changed ||
2679+
has_racy_timestamp(repo->index)) &&
2680+
repo_verify_index(repo))
2681+
write_locked_index(repo->index, lockfile, COMMIT_LOCK);
26802682
else
26812683
rollback_lock_file(lockfile);
26822684
}

repository.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,5 +140,11 @@ int repo_read_index_preload(struct repository *,
140140
const struct pathspec *pathspec,
141141
unsigned refresh_flags);
142142
int repo_read_index_unmerged(struct repository *);
143+
/*
144+
* Opportunistically update the index but do not complain if we can't.
145+
* The lockfile is always committed or rolled back.
146+
*/
147+
void repo_update_index_if_able(struct repository *, struct lock_file *);
148+
143149

144150
#endif /* REPOSITORY_H */

wt-status.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2378,7 +2378,7 @@ int require_clean_work_tree(struct repository *r,
23782378
fd = repo_hold_locked_index(r, &lock_file, 0);
23792379
refresh_index(r->index, REFRESH_QUIET, NULL, NULL, NULL);
23802380
if (0 <= fd)
2381-
update_index_if_able(r->index, &lock_file);
2381+
repo_update_index_if_able(r, &lock_file);
23822382
rollback_lock_file(&lock_file);
23832383

23842384
if (has_unstaged_changes(r, ignore_submodules)) {

0 commit comments

Comments
 (0)