Skip to content

Commit 56cac48

Browse files
pcloudsgitster
authored andcommitted
ie_match_stat(): do not ignore skip-worktree bit with CE_MATCH_IGNORE_VALID
Previously CE_MATCH_IGNORE_VALID flag is used by both valid and skip-worktree bits. While the two bits have similar behaviour, sharing this flag means "git update-index --really-refresh" will ignore skip-worktree while it should not. Instead another flag is introduced to ignore skip-worktree bit, CE_MATCH_IGNORE_VALID only applies to valid bit. Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent bbbe508 commit 56cac48

File tree

5 files changed

+26
-9
lines changed

5 files changed

+26
-9
lines changed

builtin-apply.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2505,7 +2505,7 @@ static int verify_index_match(struct cache_entry *ce, struct stat *st)
25052505
return -1;
25062506
return 0;
25072507
}
2508-
return ce_match_stat(ce, st, CE_MATCH_IGNORE_VALID);
2508+
return ce_match_stat(ce, st, CE_MATCH_IGNORE_VALID|CE_MATCH_IGNORE_SKIP_WORKTREE);
25092509
}
25102510

25112511
static int check_preimage(struct patch *patch, struct cache_entry **ce, struct stat *st)

cache.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,9 @@ extern int index_name_is_other(const struct index_state *, const char *, int);
464464
/* do stat comparison even if CE_VALID is true */
465465
#define CE_MATCH_IGNORE_VALID 01
466466
/* do not check the contents but report dirty on racily-clean entries */
467-
#define CE_MATCH_RACY_IS_DIRTY 02
467+
#define CE_MATCH_RACY_IS_DIRTY 02
468+
/* do stat comparison even if CE_SKIP_WORKTREE is true */
469+
#define CE_MATCH_IGNORE_SKIP_WORKTREE 04
468470
extern int ie_match_stat(const struct index_state *, struct cache_entry *, struct stat *, unsigned int);
469471
extern int ie_modified(const struct index_state *, struct cache_entry *, struct stat *, unsigned int);
470472

entry.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ int checkout_entry(struct cache_entry *ce, const struct checkout *state, char *t
202202
len += ce_namelen(ce);
203203

204204
if (!check_path(path, len, &st)) {
205-
unsigned changed = ce_match_stat(ce, &st, CE_MATCH_IGNORE_VALID);
205+
unsigned changed = ce_match_stat(ce, &st, CE_MATCH_IGNORE_VALID|CE_MATCH_IGNORE_SKIP_WORKTREE);
206206
if (!changed)
207207
return 0;
208208
if (!state->force) {

read-cache.c

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -259,13 +259,18 @@ int ie_match_stat(const struct index_state *istate,
259259
{
260260
unsigned int changed;
261261
int ignore_valid = options & CE_MATCH_IGNORE_VALID;
262+
int ignore_skip_worktree = options & CE_MATCH_IGNORE_SKIP_WORKTREE;
262263
int assume_racy_is_modified = options & CE_MATCH_RACY_IS_DIRTY;
263264

264265
/*
265266
* If it's marked as always valid in the index, it's
266267
* valid whatever the checked-out copy says.
268+
*
269+
* skip-worktree has the same effect with higher precedence
267270
*/
268-
if (!ignore_valid && ((ce->ce_flags & CE_VALID) || ce_skip_worktree(ce)))
271+
if (!ignore_skip_worktree && ce_skip_worktree(ce))
272+
return 0;
273+
if (!ignore_valid && (ce->ce_flags & CE_VALID))
269274
return 0;
270275

271276
/*
@@ -564,7 +569,7 @@ int add_to_index(struct index_state *istate, const char *path, struct stat *st,
564569
int size, namelen, was_same;
565570
mode_t st_mode = st->st_mode;
566571
struct cache_entry *ce, *alias;
567-
unsigned ce_option = CE_MATCH_IGNORE_VALID|CE_MATCH_RACY_IS_DIRTY;
572+
unsigned ce_option = CE_MATCH_IGNORE_VALID|CE_MATCH_IGNORE_SKIP_WORKTREE|CE_MATCH_RACY_IS_DIRTY;
568573
int verbose = flags & (ADD_CACHE_VERBOSE | ADD_CACHE_PRETEND);
569574
int pretend = flags & ADD_CACHE_PRETEND;
570575
int intent_only = flags & ADD_CACHE_INTENT;
@@ -1000,11 +1005,21 @@ static struct cache_entry *refresh_cache_ent(struct index_state *istate,
10001005
struct cache_entry *updated;
10011006
int changed, size;
10021007
int ignore_valid = options & CE_MATCH_IGNORE_VALID;
1008+
int ignore_skip_worktree = options & CE_MATCH_IGNORE_SKIP_WORKTREE;
10031009

10041010
if (ce_uptodate(ce))
10051011
return ce;
10061012

1007-
if (!ignore_valid && ((ce->ce_flags & CE_VALID) || ce_skip_worktree(ce))) {
1013+
/*
1014+
* CE_VALID or CE_SKIP_WORKTREE means the user promised us
1015+
* that the change to the work tree does not matter and told
1016+
* us not to worry.
1017+
*/
1018+
if (!ignore_skip_worktree && ce_skip_worktree(ce)) {
1019+
ce_mark_uptodate(ce);
1020+
return ce;
1021+
}
1022+
if (!ignore_valid && (ce->ce_flags & CE_VALID)) {
10081023
ce_mark_uptodate(ce);
10091024
return ce;
10101025
}

unpack-trees.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ static int verify_uptodate_1(struct cache_entry *ce,
569569
return 0;
570570

571571
if (!lstat(ce->name, &st)) {
572-
unsigned changed = ie_match_stat(o->src_index, ce, &st, CE_MATCH_IGNORE_VALID);
572+
unsigned changed = ie_match_stat(o->src_index, ce, &st, CE_MATCH_IGNORE_VALID|CE_MATCH_IGNORE_SKIP_WORKTREE);
573573
if (!changed)
574574
return 0;
575575
/*
@@ -701,7 +701,7 @@ static int icase_exists(struct unpack_trees_options *o, struct cache_entry *dst,
701701
struct cache_entry *src;
702702

703703
src = index_name_exists(o->src_index, dst->name, ce_namelen(dst), 1);
704-
return src && !ie_match_stat(o->src_index, src, st, CE_MATCH_IGNORE_VALID);
704+
return src && !ie_match_stat(o->src_index, src, st, CE_MATCH_IGNORE_VALID|CE_MATCH_IGNORE_SKIP_WORKTREE);
705705
}
706706

707707
/*
@@ -1152,7 +1152,7 @@ int oneway_merge(struct cache_entry **src, struct unpack_trees_options *o)
11521152
if (o->reset && !ce_uptodate(old) && !ce_skip_worktree(old)) {
11531153
struct stat st;
11541154
if (lstat(old->name, &st) ||
1155-
ie_match_stat(o->src_index, old, &st, CE_MATCH_IGNORE_VALID))
1155+
ie_match_stat(o->src_index, old, &st, CE_MATCH_IGNORE_VALID|CE_MATCH_IGNORE_SKIP_WORKTREE))
11561156
update |= CE_UPDATE;
11571157
}
11581158
add_entry(o, old, update, 0);

0 commit comments

Comments
 (0)