]> git.ipfire.org Git - thirdparty/git.git/commitdiff
read-cache.c: replace update_index_if_able with repo_&
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>
Sat, 12 Jan 2019 02:13:27 +0000 (09:13 +0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 14 Jan 2019 20:13:04 +0000 (12:13 -0800)
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/commit.c
builtin/describe.c
builtin/diff.c
builtin/rebase.c
cache.h
read-cache.c
repository.h
wt-status.c

index 19eb6cff86545689ba7b1cfe5a4c1867b35ec822..d3f1234bf058d9c4ab4c1ad610cec580cc7f1250 100644 (file)
@@ -1396,7 +1396,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
        wt_status_collect(&s);
 
        if (0 <= fd)
-               update_index_if_able(&the_index, &index_lock);
+               repo_update_index_if_able(the_repository, &index_lock);
 
        if (s.relative_paths)
                s.prefix = prefix;
index cc118448ee00d2c4336422afbad1799babfb5783..bc97e50650a39e03448c1c4e5dd0e8f880b9befc 100644 (file)
@@ -634,7 +634,7 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
                                      NULL, NULL, NULL);
                        fd = hold_locked_index(&index_lock, 0);
                        if (0 <= fd)
-                               update_index_if_able(&the_index, &index_lock);
+                               repo_update_index_if_able(the_repository, &index_lock);
 
                        repo_init_revisions(the_repository, &revs, prefix);
                        argv_array_pushv(&args, diff_index_args);
index f0393bba23a7d95c67470508a6b63e4e41e8d46b..ec78920ee24fccd47a20d1b7b93a619695c1be25 100644 (file)
@@ -212,7 +212,7 @@ static void refresh_index_quietly(void)
        discard_cache();
        read_cache();
        refresh_cache(REFRESH_QUIET|REFRESH_UNMERGED);
-       update_index_if_able(&the_index, &lock_file);
+       repo_update_index_if_able(the_repository, &lock_file);
 }
 
 static int builtin_diff_files(struct rev_info *revs, int argc, const char **argv)
index ce5f5b5a17d4887b1d34e3476f3edf06a330268e..7124e66d00e817fd74d1e5876454aea7e0f34a4e 100644 (file)
@@ -1020,8 +1020,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
                refresh_index(the_repository->index, REFRESH_QUIET, NULL, NULL,
                              NULL);
                if (0 <= fd)
-                       update_index_if_able(the_repository->index,
-                                            &lock_file);
+                       repo_update_index_if_able(the_repository, &lock_file);
                rollback_lock_file(&lock_file);
 
                if (has_unstaged_changes(the_repository, 1)) {
@@ -1378,7 +1377,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
                fd = hold_locked_index(&lock_file, 0);
                refresh_cache(REFRESH_QUIET);
                if (0 <= fd)
-                       update_index_if_able(&the_index, &lock_file);
+                       repo_update_index_if_able(the_repository, &lock_file);
                rollback_lock_file(&lock_file);
 
                if (has_unstaged_changes(the_repository, 1) ||
diff --git a/cache.h b/cache.h
index 3715808f52c3daad6221edf49d84227d431fab4f..702c5bfbb33c6f07a94c88b466b2800c07b064dc 100644 (file)
--- a/cache.h
+++ b/cache.h
@@ -823,12 +823,6 @@ extern void fill_stat_cache_info(struct cache_entry *ce, struct stat *st);
 extern int refresh_index(struct index_state *, unsigned int flags, const struct pathspec *pathspec, char *seen, const char *header_msg);
 extern struct cache_entry *refresh_cache_entry(struct index_state *, struct cache_entry *, unsigned int);
 
-/*
- * Opportunistically update the index but do not complain if we can't.
- * The lockfile is always committed or rolled back.
- */
-extern void update_index_if_able(struct index_state *, struct lock_file *);
-
 extern void set_alternate_index_output(const char *);
 
 extern int verify_index_checksum;
index afbf976107552dd15f9a4c5a946da6c1b012298a..61cc0571da7dabfb9548aa1613da5adab62ed031 100644 (file)
@@ -2654,9 +2654,9 @@ out:
        return 0;
 }
 
-static int verify_index(const struct index_state *istate)
+static int repo_verify_index(struct repository *repo)
 {
-       return verify_index_from(istate, get_index_file());
+       return verify_index_from(repo->index, repo->index_file);
 }
 
 static int has_racy_timestamp(struct index_state *istate)
@@ -2672,11 +2672,13 @@ static int has_racy_timestamp(struct index_state *istate)
        return 0;
 }
 
-void update_index_if_able(struct index_state *istate, struct lock_file *lockfile)
+void repo_update_index_if_able(struct repository *repo,
+                              struct lock_file *lockfile)
 {
-       if ((istate->cache_changed || has_racy_timestamp(istate)) &&
-           verify_index(istate))
-               write_locked_index(istate, lockfile, COMMIT_LOCK);
+       if ((repo->index->cache_changed ||
+            has_racy_timestamp(repo->index)) &&
+           repo_verify_index(repo))
+               write_locked_index(repo->index, lockfile, COMMIT_LOCK);
        else
                rollback_lock_file(lockfile);
 }
index cc3879add46573382b44d12f2da3226eecfec665..6fe1c089db9d8e72158290512ba147abb3d1d3cb 100644 (file)
@@ -140,5 +140,11 @@ int repo_read_index_preload(struct repository *,
                            const struct pathspec *pathspec,
                            unsigned refresh_flags);
 int repo_read_index_unmerged(struct repository *);
+/*
+ * Opportunistically update the index but do not complain if we can't.
+ * The lockfile is always committed or rolled back.
+ */
+void repo_update_index_if_able(struct repository *, struct lock_file *);
+
 
 #endif /* REPOSITORY_H */
index becf78b04f50608a0f0dadc4a10b8b6300ddbf1d..1f564b12d259956fa71fb0dce78c6e4c3c006897 100644 (file)
@@ -2378,7 +2378,7 @@ int require_clean_work_tree(struct repository *r,
        fd = repo_hold_locked_index(r, &lock_file, 0);
        refresh_index(r->index, REFRESH_QUIET, NULL, NULL, NULL);
        if (0 <= fd)
-               update_index_if_able(r->index, &lock_file);
+               repo_update_index_if_able(r, &lock_file);
        rollback_lock_file(&lock_file);
 
        if (has_unstaged_changes(r, ignore_submodules)) {