The next patch wants to ignore CE_VALID under some condition but not really clears it. Centralizing its access makes such a change easier. Not all "ce_flags & CE_VALID" is converted though. The tests that really mean _bit_ CE_VALID remains so. The tests that mean "ignore worktree" are converted. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@xxxxxxxxx> --- builtin/grep.c | 2 +- cache.h | 4 ++++ diff-lib.c | 4 ++-- diff.c | 2 +- read-cache.c | 6 +++--- unpack-trees.c | 2 +- 6 files changed, 12 insertions(+), 8 deletions(-) diff --git a/builtin/grep.c b/builtin/grep.c index 63f8603..00526a1 100644 --- a/builtin/grep.c +++ b/builtin/grep.c @@ -386,7 +386,7 @@ static int grep_cache(struct grep_opt *opt, const struct pathspec *pathspec, int * are identical, even if worktree file has been modified, so use * cache version instead */ - if (cached || (ce->ce_flags & CE_VALID) || ce_skip_worktree(ce)) { + if (cached || ce_valid(ce) || ce_skip_worktree(ce)) { if (ce_stage(ce)) continue; hit |= grep_sha1(opt, ce->sha1, ce->name, 0, ce->name); diff --git a/cache.h b/cache.h index 9f7d952..c229bf9 100644 --- a/cache.h +++ b/cache.h @@ -222,6 +222,10 @@ static inline unsigned create_ce_flags(unsigned stage) #define ce_uptodate(ce) ((ce)->ce_flags & CE_UPTODATE) #define ce_skip_worktree(ce) ((ce)->ce_flags & CE_SKIP_WORKTREE) #define ce_mark_uptodate(ce) ((ce)->ce_flags |= CE_UPTODATE) +static inline int ce_valid(const struct cache_entry *ce) +{ + return ce->ce_flags & CE_VALID; +} #define ce_permissions(mode) (((mode) & 0100) ? 0755 : 0644) static inline unsigned int create_ce_mode(unsigned int mode) diff --git a/diff-lib.c b/diff-lib.c index 346cac6..dcda7f3 100644 --- a/diff-lib.c +++ b/diff-lib.c @@ -198,7 +198,7 @@ int run_diff_files(struct rev_info *revs, unsigned int option) continue; /* If CE_VALID is set, don't look at workdir for file removal */ - changed = (ce->ce_flags & CE_VALID) ? 0 : check_removed(ce, &st); + changed = ce_valid(ce) ? 0 : check_removed(ce, &st); if (changed) { if (changed < 0) { perror(ce->name); @@ -369,7 +369,7 @@ static void do_oneway_diff(struct unpack_trees_options *o, /* if the entry is not checked out, don't examine work tree */ cached = o->index_only || - (idx && ((idx->ce_flags & CE_VALID) || ce_skip_worktree(idx))); + (idx && (ce_valid(idx) || ce_skip_worktree(idx))); /* * Backward compatibility wart - "diff-index -m" does * not mean "do not ignore merges", but "match_missing". diff --git a/diff.c b/diff.c index 8e4a6a9..22c73fe 100644 --- a/diff.c +++ b/diff.c @@ -2636,7 +2636,7 @@ static int reuse_worktree_file(const char *name, const unsigned char *sha1, int * If ce is marked as "assume unchanged", there is no * guarantee that work tree matches what we are looking for. */ - if ((ce->ce_flags & CE_VALID) || ce_skip_worktree(ce)) + if (ce_valid(ce) || ce_skip_worktree(ce)) return 0; /* diff --git a/read-cache.c b/read-cache.c index 5540b06..95c9ccb 100644 --- a/read-cache.c +++ b/read-cache.c @@ -289,8 +289,8 @@ int ie_match_stat(const struct index_state *istate, */ if (!ignore_skip_worktree && ce_skip_worktree(ce)) return 0; - if (!ignore_valid && (ce->ce_flags & CE_VALID)) - return 0; + if (!ignore_valid && ce_valid(ce)) + return 0; /* * Intent-to-add entries have not been added, so the index entry @@ -1047,7 +1047,7 @@ static struct cache_entry *refresh_cache_ent(struct index_state *istate, ce_mark_uptodate(ce); return ce; } - if (!ignore_valid && (ce->ce_flags & CE_VALID)) { + if (!ignore_valid && ce_valid(ce)) { ce_mark_uptodate(ce); return ce; } diff --git a/unpack-trees.c b/unpack-trees.c index 164354d..61c3f35 100644 --- a/unpack-trees.c +++ b/unpack-trees.c @@ -1215,7 +1215,7 @@ static int verify_uptodate_1(const struct cache_entry *ce, * if this entry is truly up-to-date because this file may be * overwritten. */ - if ((ce->ce_flags & CE_VALID) || ce_skip_worktree(ce)) + if (ce_valid(ce) || ce_skip_worktree(ce)) ; /* keep checking */ else if (o->reset || ce_uptodate(ce)) return 0; -- 1.8.5.2.240.g8478abd -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html