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 <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Nguyễn Thái Ngọc Duy committed
Dec 14, 2009 at 18:43 UTC
56cac48c3550de88d71b3944576d44337261d71b
5 files changed
+26
-9
builtin-apply.c
+1
-1
@@ -2505,7 +2505,7 @@ static int verify_index_match(struct cache_entry *ce, struct stat *st)
2505
return -1;
2506
return 0;
2507
}
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);
2509
}
2510
2511
static int check_preimage(struct patch *patch, struct cache_entry **ce, struct stat *st)
cache.h
+3
-1
@@ -464,7 +464,9 @@ extern int index_name_is_other(const struct index_state *, const char *, int);
464
/* do stat comparison even if CE_VALID is true */
465
#define CE_MATCH_IGNORE_VALID 01
466
/* 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
470
extern int ie_match_stat(const struct index_state *, struct cache_entry *, struct stat *, unsigned int);
471
extern int ie_modified(const struct index_state *, struct cache_entry *, struct stat *, unsigned int);
472
entry.c
+1
-1
@@ -202,7 +202,7 @@ int checkout_entry(struct cache_entry *ce, const struct checkout *state, char *t
202
len += ce_namelen(ce);
203
204
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);
206
if (!changed)
207
return 0;
208
if (!state->force) {
read-cache.c
+18
-3
@@ -259,13 +259,18 @@ int ie_match_stat(const struct index_state *istate,
259
{
260
unsigned int changed;
261
int ignore_valid = options & CE_MATCH_IGNORE_VALID;
262
+ int ignore_skip_worktree = options & CE_MATCH_IGNORE_SKIP_WORKTREE;
263
int assume_racy_is_modified = options & CE_MATCH_RACY_IS_DIRTY;
264
265
/*
266
* If it's marked as always valid in the index, it's
267
* valid whatever the checked-out copy says.
268
+ *
269
+ * skip-worktree has the same effect with higher precedence
270
*/
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))
274
return 0;
275
276
/*
@@ -564,7 +569,7 @@ int add_to_index(struct index_state *istate, const char *path, struct stat *st,
569
int size, namelen, was_same;
570
mode_t st_mode = st->st_mode;
571
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;
573
int verbose = flags & (ADD_CACHE_VERBOSE | ADD_CACHE_PRETEND);
574
int pretend = flags & ADD_CACHE_PRETEND;
575
int intent_only = flags & ADD_CACHE_INTENT;
@@ -1000,11 +1005,21 @@ static struct cache_entry *refresh_cache_ent(struct index_state *istate,
1005
struct cache_entry *updated;
1006
int changed, size;
1007
int ignore_valid = options & CE_MATCH_IGNORE_VALID;
1008
+ int ignore_skip_worktree = options & CE_MATCH_IGNORE_SKIP_WORKTREE;
1009
1010
if (ce_uptodate(ce))
1011
return ce;
1012
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)) {
1023
ce_mark_uptodate(ce);
1024
return ce;
1025
}
unpack-trees.c
+3
-3
@@ -569,7 +569,7 @@ static int verify_uptodate_1(struct cache_entry *ce,
569
return 0;
570
571
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);
573
if (!changed)
574
return 0;
575
/*
@@ -701,7 +701,7 @@ static int icase_exists(struct unpack_trees_options *o, struct cache_entry *dst,
701
struct cache_entry *src;
702
703
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);
705
}
706
707
/*
@@ -1152,7 +1152,7 @@ int oneway_merge(struct cache_entry **src, struct unpack_trees_options *o)
1152
if (o->reset && !ce_uptodate(old) && !ce_skip_worktree(old)) {
1153
struct stat st;
1154
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))
1156
update |= CE_UPDATE;
1157
}
1158
add_entry(o, old, update, 0);