Browse Source

Merge branch 'tk/empty-untracked-cache'

The untracked cache newly computed weren't written back to the
on-disk index file when there is no other change to the index,
which has been corrected.

* tk/empty-untracked-cache:
  untracked-cache: write index when populating empty untracked cache
  t7519: populate untracked cache before test
  t7519: avoid file to index mtime race for untracked cache
maint
Junio C Hamano 3 years ago
parent
commit
47e0380289
  1. 10
      dir.c
  2. 7
      t/t7519-status-fsmonitor.sh

10
dir.c

@ -2781,7 +2781,8 @@ void remove_untracked_cache(struct index_state *istate)


static struct untracked_cache_dir *validate_untracked_cache(struct dir_struct *dir, static struct untracked_cache_dir *validate_untracked_cache(struct dir_struct *dir,
int base_len, int base_len,
const struct pathspec *pathspec) const struct pathspec *pathspec,
struct index_state *istate)
{ {
struct untracked_cache_dir *root; struct untracked_cache_dir *root;
static int untracked_cache_disabled = -1; static int untracked_cache_disabled = -1;
@ -2845,8 +2846,11 @@ static struct untracked_cache_dir *validate_untracked_cache(struct dir_struct *d
return NULL; return NULL;
} }


if (!dir->untracked->root) if (!dir->untracked->root) {
/* Untracked cache existed but is not initialized; fix that */
FLEX_ALLOC_STR(dir->untracked->root, name, ""); FLEX_ALLOC_STR(dir->untracked->root, name, "");
istate->cache_changed |= UNTRACKED_CHANGED;
}


/* Validate $GIT_DIR/info/exclude and core.excludesfile */ /* Validate $GIT_DIR/info/exclude and core.excludesfile */
root = dir->untracked->root; root = dir->untracked->root;
@ -2916,7 +2920,7 @@ int read_directory(struct dir_struct *dir, struct index_state *istate,
return dir->nr; return dir->nr;
} }


untracked = validate_untracked_cache(dir, len, pathspec); untracked = validate_untracked_cache(dir, len, pathspec, istate);
if (!untracked) if (!untracked)
/* /*
* make sure untracked cache code path is disabled, * make sure untracked cache code path is disabled,

7
t/t7519-status-fsmonitor.sh

@ -324,17 +324,24 @@ test_expect_success UNTRACKED_CACHE 'ignore .git changes when invalidating UNTR'
cd dot-git && cd dot-git &&
mkdir -p .git/hooks && mkdir -p .git/hooks &&
: >tracked && : >tracked &&
test-tool chmtime =-60 tracked &&
: >modified && : >modified &&
test-tool chmtime =-60 modified &&
mkdir dir1 && mkdir dir1 &&
: >dir1/tracked && : >dir1/tracked &&
test-tool chmtime =-60 dir1/tracked &&
: >dir1/modified && : >dir1/modified &&
test-tool chmtime =-60 dir1/modified &&
mkdir dir2 && mkdir dir2 &&
: >dir2/tracked && : >dir2/tracked &&
test-tool chmtime =-60 dir2/tracked &&
: >dir2/modified && : >dir2/modified &&
test-tool chmtime =-60 dir2/modified &&
write_integration_script && write_integration_script &&
git config core.fsmonitor .git/hooks/fsmonitor-test && git config core.fsmonitor .git/hooks/fsmonitor-test &&
git update-index --untracked-cache && git update-index --untracked-cache &&
git update-index --fsmonitor && git update-index --fsmonitor &&
git status &&
GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace-before" \ GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace-before" \
git status && git status &&
test-tool dump-untracked-cache >../before test-tool dump-untracked-cache >../before

Loading…
Cancel
Save