From e06c43c7959042e5612984b8193700f32f12b2be Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sun, 30 Mar 2008 09:25:52 -0700 Subject: [PATCH 1/2] write_index(): optimize ce_smudge_racily_clean_entry() calls with CE_UPTODATE When writing the index out, we need to check the work tree again to see if an entry whose timestamp indicates that it could be "racily clean", in order to smudge it if it is stat-clean but with modified contents. However, we can skip this step for entries marked with CE_UPTODATE, which are known to be the really clean (i.e. the one we already have checked when we prepared the index). This will reduce lstat(2) calls necessary in git-status. Signed-off-by: Junio C Hamano --- read-cache.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/read-cache.c b/read-cache.c index a92b25b59b..c3692f41ad 100644 --- a/read-cache.c +++ b/read-cache.c @@ -1370,7 +1370,7 @@ int write_index(const struct index_state *istate, int newfd) struct cache_entry *ce = cache[i]; if (ce->ce_flags & CE_REMOVE) continue; - if (is_racy_timestamp(istate, ce)) + if (!ce_uptodate(ce) && is_racy_timestamp(istate, ce)) ce_smudge_racily_clean_entry(ce); if (ce_write_entry(&c, newfd, ce) < 0) return -1; From 8fa29602d4cf8c9ec7d837f7308a9582a8372cb5 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sun, 30 Mar 2008 12:39:25 -0700 Subject: [PATCH 2/2] diff-files: mark an index entry we know is up-to-date as such This does not make any difference when running diff-files alone, but if you internally run run_diff_files() and then run other operations further on the index, we do not have to run lstat(2) again on entries we already have checked. Signed-off-by: Junio C Hamano --- diff-lib.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/diff-lib.c b/diff-lib.c index 069e4507ae..6e7ab29e34 100644 --- a/diff-lib.c +++ b/diff-lib.c @@ -476,8 +476,11 @@ int run_diff_files(struct rev_info *revs, unsigned int option) continue; } changed = ce_match_stat(ce, &st, ce_option); - if (!changed && !DIFF_OPT_TST(&revs->diffopt, FIND_COPIES_HARDER)) - continue; + if (!changed) { + ce_mark_uptodate(ce); + if (!DIFF_OPT_TST(&revs->diffopt, FIND_COPIES_HARDER)) + continue; + } oldmode = ce->ce_mode; newmode = ce_mode_from_stat(ce, st.st_mode); diff_change(&revs->diffopt, oldmode, newmode,