read-cache.c: replace update_index_if_able with repo_&

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nguyễn Thái Ngọc Duy committed Jan 12, 2019 at 09:13 UTC 1b0d968b34122a0f3ceec2786f01679437f2baba
8 files changed +20 -19
builtin/commit.c
+1 -1
@@ -1396,7 +1396,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
1396 wt_status_collect(&s);
1397
1398 if (0 <= fd)
1399 - update_index_if_able(&the_index, &index_lock);
1399 + repo_update_index_if_able(the_repository, &index_lock);
1400
1401 if (s.relative_paths)
1402 s.prefix = prefix;
builtin/describe.c
+1 -1
@@ -634,7 +634,7 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
634 NULL, NULL, NULL);
635 fd = hold_locked_index(&index_lock, 0);
636 if (0 <= fd)
637 - update_index_if_able(&the_index, &index_lock);
637 + repo_update_index_if_able(the_repository, &index_lock);
638
639 repo_init_revisions(the_repository, &revs, prefix);
640 argv_array_pushv(&args, diff_index_args);
builtin/diff.c
+1 -1
@@ -212,7 +212,7 @@ static void refresh_index_quietly(void)
212 discard_cache();
213 read_cache();
214 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);
216 }
217
218 static int builtin_diff_files(struct rev_info *revs, int argc, const char **argv)
builtin/rebase.c
+2 -3
@@ -1020,8 +1020,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
1020 refresh_index(the_repository->index, REFRESH_QUIET, NULL, NULL,
1021 NULL);
1022 if (0 <= fd)
1023 - update_index_if_able(the_repository->index,
1024 - &lock_file);
1023 + repo_update_index_if_able(the_repository, &lock_file);
1024 rollback_lock_file(&lock_file);
1025
1026 if (has_unstaged_changes(the_repository, 1)) {
@@ -1378,7 +1377,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
1377 fd = hold_locked_index(&lock_file, 0);
1378 refresh_cache(REFRESH_QUIET);
1379 if (0 <= fd)
1381 - update_index_if_able(&the_index, &lock_file);
1380 + repo_update_index_if_able(the_repository, &lock_file);
1381 rollback_lock_file(&lock_file);
1382
1383 if (has_unstaged_changes(the_repository, 1) ||
cache.h
-6
@@ -823,12 +823,6 @@ extern void fill_stat_cache_info(struct cache_entry *ce, struct stat *st);
823 extern int refresh_index(struct index_state *, unsigned int flags, const struct pathspec *pathspec, char *seen, const char *header_msg);
824 extern struct cache_entry *refresh_cache_entry(struct index_state *, struct cache_entry *, unsigned int);
825
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 -
826 extern void set_alternate_index_output(const char *);
827
828 extern int verify_index_checksum;
read-cache.c
+8 -6
@@ -2654,9 +2654,9 @@ out:
2654 return 0;
2655 }
2656
2657 -static int verify_index(const struct index_state *istate)
2657 +static int repo_verify_index(struct repository *repo)
2658 {
2659 - return verify_index_from(istate, get_index_file());
2659 + return verify_index_from(repo->index, repo->index_file);
2660 }
2661
2662 static int has_racy_timestamp(struct index_state *istate)
@@ -2672,11 +2672,13 @@ static int has_racy_timestamp(struct index_state *istate)
2672 return 0;
2673 }
2674
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)
2677 {
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);
2682 else
2683 rollback_lock_file(lockfile);
2684 }
repository.h
+6
@@ -140,5 +140,11 @@ int repo_read_index_preload(struct repository *,
140 const struct pathspec *pathspec,
141 unsigned refresh_flags);
142 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 +
149
150 #endif /* REPOSITORY_H */
wt-status.c
+1 -1
@@ -2378,7 +2378,7 @@ int require_clean_work_tree(struct repository *r,
2378 fd = repo_hold_locked_index(r, &lock_file, 0);
2379 refresh_index(r->index, REFRESH_QUIET, NULL, NULL, NULL);
2380 if (0 <= fd)
2381 - update_index_if_able(r->index, &lock_file);
2381 + repo_update_index_if_able(r, &lock_file);
2382 rollback_lock_file(&lock_file);
2383
2384 if (has_unstaged_changes(r, ignore_submodules)) {