All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH 05/10] read-cache.c: replace update_index_if_able with repo_&
Date: Sat,  5 Jan 2019 12:51:48 +0700	[thread overview]
Message-ID: <20190105055153.3256-6-pclouds@gmail.com> (raw)
In-Reply-To: <20190105055153.3256-1-pclouds@gmail.com>

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 builtin/commit.c   |  2 +-
 builtin/describe.c |  2 +-
 builtin/diff.c     |  2 +-
 builtin/rebase.c   |  5 ++---
 cache.h            |  6 ------
 read-cache.c       | 14 ++++++++------
 repository.h       |  6 ++++++
 wt-status.c        |  2 +-
 8 files changed, 20 insertions(+), 19 deletions(-)

diff --git a/builtin/commit.c b/builtin/commit.c
index 19eb6cff86..d3f1234bf0 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -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;
diff --git a/builtin/describe.c b/builtin/describe.c
index cc118448ee..bc97e50650 100644
--- a/builtin/describe.c
+++ b/builtin/describe.c
@@ -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);
diff --git a/builtin/diff.c b/builtin/diff.c
index f0393bba23..ec78920ee2 100644
--- a/builtin/diff.c
+++ b/builtin/diff.c
@@ -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)
diff --git a/builtin/rebase.c b/builtin/rebase.c
index ce5f5b5a17..7124e66d00 100644
--- a/builtin/rebase.c
+++ b/builtin/rebase.c
@@ -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 3715808f52..702c5bfbb3 100644
--- 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;
diff --git a/read-cache.c b/read-cache.c
index afbf976107..61cc0571da 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -2654,9 +2654,9 @@ static int verify_index_from(const struct index_state *istate, const char *path)
 	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);
 }
diff --git a/repository.h b/repository.h
index cc3879add4..6fe1c089db 100644
--- a/repository.h
+++ b/repository.h
@@ -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 */
diff --git a/wt-status.c b/wt-status.c
index becf78b04f..1f564b12d2 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -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)) {
-- 
2.20.0.482.g66447595a7


  parent reply	other threads:[~2019-01-05  5:52 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-05  5:51 [PATCH 00/10] Remove the_index, the final part Nguyễn Thái Ngọc Duy
2019-01-05  5:51 ` [PATCH 01/10] notes-utils.c: remove the_repository references Nguyễn Thái Ngọc Duy
2019-01-05  5:51 ` [PATCH 02/10] repository.c: replace hold_locked_index() with repo_hold_locked_index() Nguyễn Thái Ngọc Duy
2019-01-05 14:33   ` Martin Ågren
2019-01-07 12:55     ` Duy Nguyen
2019-01-05  5:51 ` [PATCH 03/10] checkout: avoid the_index when possible Nguyễn Thái Ngọc Duy
2019-01-05  5:51 ` [PATCH 04/10] read-cache.c: kill read_index() Nguyễn Thái Ngọc Duy
2019-01-05  5:51 ` Nguyễn Thái Ngọc Duy [this message]
2019-01-05  5:51 ` [PATCH 06/10] sha1-name.c: remove implicit dependency on the_index Nguyễn Thái Ngọc Duy
2019-01-05  5:51 ` [PATCH 07/10] merge-recursive.c: " Nguyễn Thái Ngọc Duy
2019-01-05  5:51 ` [PATCH 08/10] merge-recursive.c: remove implicit dependency on the_repository Nguyễn Thái Ngọc Duy
2019-01-05  5:51 ` [PATCH 09/10] read-cache.c: remove the_* from index_has_changes() Nguyễn Thái Ngọc Duy
2019-01-05  5:51 ` [PATCH 10/10] cache.h: flip NO_THE_INDEX_COMPATIBILITY_MACROS switch Nguyễn Thái Ngọc Duy
2019-01-12  2:13 ` [PATCH v2 00/11] Remove the_index, the final part Nguyễn Thái Ngọc Duy
2019-01-12  2:13   ` [PATCH v2 01/11] grep: use grep_opt->repo instead of explict repo argument Nguyễn Thái Ngọc Duy
2019-01-12  2:13   ` [PATCH v2 02/11] notes-utils.c: remove the_repository references Nguyễn Thái Ngọc Duy
2019-01-12  2:13   ` [PATCH v2 03/11] repository.c: replace hold_locked_index() with repo_hold_locked_index() Nguyễn Thái Ngọc Duy
2019-01-12  2:13   ` [PATCH v2 04/11] checkout: avoid the_index when possible Nguyễn Thái Ngọc Duy
2019-01-12  2:13   ` [PATCH v2 05/11] read-cache.c: kill read_index() Nguyễn Thái Ngọc Duy
2019-01-12  2:13   ` [PATCH v2 06/11] read-cache.c: replace update_index_if_able with repo_& Nguyễn Thái Ngọc Duy
2019-01-12  2:13   ` [PATCH v2 07/11] sha1-name.c: remove implicit dependency on the_index Nguyễn Thái Ngọc Duy
2019-01-12  2:13   ` [PATCH v2 08/11] merge-recursive.c: " Nguyễn Thái Ngọc Duy
2019-01-12  2:13   ` [PATCH v2 09/11] merge-recursive.c: remove implicit dependency on the_repository Nguyễn Thái Ngọc Duy
2019-01-12  2:13   ` [PATCH v2 10/11] read-cache.c: remove the_* from index_has_changes() Nguyễn Thái Ngọc Duy
2019-01-12  2:13   ` [PATCH v2 11/11] cache.h: flip NO_THE_INDEX_COMPATIBILITY_MACROS switch Nguyễn Thái Ngọc Duy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190105055153.3256-6-pclouds@gmail.com \
    --to=pclouds@gmail.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.