Skip to content

Commit 0b01c0a

Browse files
committed
Merge branch 'tk/t7063-chmtime-dirs-too'
Teach "test-chmtime" to work on a directory and use it to avoid having to wait for a second in a few places in tests. * tk/t7063-chmtime-dirs-too: t7063: mtime-mangling instead of delays in untracked cache testing t/helper/test-chmtime: update mingw to support chmtime on directories
2 parents a54cc52 + 9ba83eb commit 0b01c0a

File tree

2 files changed

+28
-16
lines changed

2 files changed

+28
-16
lines changed

compat/mingw.c

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -961,9 +961,11 @@ static inline void time_t_to_filetime(time_t t, FILETIME *ft)
961961
int mingw_utime (const char *file_name, const struct utimbuf *times)
962962
{
963963
FILETIME mft, aft;
964-
int fh, rc;
964+
int rc;
965965
DWORD attrs;
966966
wchar_t wfilename[MAX_PATH];
967+
HANDLE osfilehandle;
968+
967969
if (xutftowcs_path(wfilename, file_name) < 0)
968970
return -1;
969971

@@ -975,7 +977,17 @@ int mingw_utime (const char *file_name, const struct utimbuf *times)
975977
SetFileAttributesW(wfilename, attrs & ~FILE_ATTRIBUTE_READONLY);
976978
}
977979

978-
if ((fh = _wopen(wfilename, O_RDWR | O_BINARY)) < 0) {
980+
osfilehandle = CreateFileW(wfilename,
981+
FILE_WRITE_ATTRIBUTES,
982+
0 /*FileShare.None*/,
983+
NULL,
984+
OPEN_EXISTING,
985+
(attrs != INVALID_FILE_ATTRIBUTES &&
986+
(attrs & FILE_ATTRIBUTE_DIRECTORY)) ?
987+
FILE_FLAG_BACKUP_SEMANTICS : 0,
988+
NULL);
989+
if (osfilehandle == INVALID_HANDLE_VALUE) {
990+
errno = err_win_to_posix(GetLastError());
979991
rc = -1;
980992
goto revert_attrs;
981993
}
@@ -987,12 +999,15 @@ int mingw_utime (const char *file_name, const struct utimbuf *times)
987999
GetSystemTimeAsFileTime(&mft);
9881000
aft = mft;
9891001
}
990-
if (!SetFileTime((HANDLE)_get_osfhandle(fh), NULL, &aft, &mft)) {
1002+
1003+
if (!SetFileTime(osfilehandle, NULL, &aft, &mft)) {
9911004
errno = EINVAL;
9921005
rc = -1;
9931006
} else
9941007
rc = 0;
995-
close(fh);
1008+
1009+
if (osfilehandle != INVALID_HANDLE_VALUE)
1010+
CloseHandle(osfilehandle);
9961011

9971012
revert_attrs:
9981013
if (attrs != INVALID_FILE_ATTRIBUTES &&

t/t7063-status-untracked-cache.sh

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ test_expect_success 'setup' '
9090
cd worktree &&
9191
mkdir done dtwo dthree &&
9292
touch one two three done/one dtwo/two dthree/three &&
93+
test-tool chmtime =-300 one two three done/one dtwo/two dthree/three &&
94+
test-tool chmtime =-300 done dtwo dthree &&
95+
test-tool chmtime =-300 . &&
9396
git add one two done/one &&
9497
: >.git/info/exclude &&
9598
git update-index --untracked-cache &&
@@ -142,7 +145,6 @@ two
142145
EOF
143146

144147
test_expect_success 'status first time (empty cache)' '
145-
avoid_racy &&
146148
: >../trace.output &&
147149
GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
148150
git status --porcelain >../actual &&
@@ -166,7 +168,6 @@ test_expect_success 'untracked cache after first status' '
166168
'
167169

168170
test_expect_success 'status second time (fully populated cache)' '
169-
avoid_racy &&
170171
: >../trace.output &&
171172
GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
172173
git status --porcelain >../actual &&
@@ -190,8 +191,8 @@ test_expect_success 'untracked cache after second status' '
190191
'
191192

192193
test_expect_success 'modify in root directory, one dir invalidation' '
193-
avoid_racy &&
194194
: >four &&
195+
test-tool chmtime =-240 four &&
195196
: >../trace.output &&
196197
GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
197198
git status --porcelain >../actual &&
@@ -241,7 +242,6 @@ EOF
241242
'
242243

243244
test_expect_success 'new .gitignore invalidates recursively' '
244-
avoid_racy &&
245245
echo four >.gitignore &&
246246
: >../trace.output &&
247247
GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
@@ -292,7 +292,6 @@ EOF
292292
'
293293

294294
test_expect_success 'new info/exclude invalidates everything' '
295-
avoid_racy &&
296295
echo three >>.git/info/exclude &&
297296
: >../trace.output &&
298297
GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
@@ -520,14 +519,14 @@ test_expect_success 'create/modify files, some of which are gitignored' '
520519
echo three >done/three && # three is gitignored
521520
echo four >done/four && # four is gitignored at a higher level
522521
echo five >done/five && # five is not gitignored
523-
echo test >base && #we need to ensure that the root dir is touched
524-
rm base &&
522+
test-tool chmtime =-180 done/two done/three done/four done/five done &&
523+
# we need to ensure that the root dir is touched (in the past);
524+
test-tool chmtime =-180 . &&
525525
sync_mtime
526526
'
527527

528528
test_expect_success 'test sparse status with untracked cache' '
529529
: >../trace.output &&
530-
avoid_racy &&
531530
GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
532531
git status --porcelain >../status.actual &&
533532
iuc status --porcelain >../status.iuc &&
@@ -570,7 +569,6 @@ EOF
570569
'
571570

572571
test_expect_success 'test sparse status again with untracked cache' '
573-
avoid_racy &&
574572
: >../trace.output &&
575573
GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
576574
git status --porcelain >../status.actual &&
@@ -597,11 +595,11 @@ EOF
597595
test_expect_success 'set up for test of subdir and sparse checkouts' '
598596
mkdir done/sub &&
599597
mkdir done/sub/sub &&
600-
echo "sub" > done/sub/sub/file
598+
echo "sub" > done/sub/sub/file &&
599+
test-tool chmtime =-120 done/sub/sub/file done/sub/sub done/sub done
601600
'
602601

603602
test_expect_success 'test sparse status with untracked cache and subdir' '
604-
avoid_racy &&
605603
: >../trace.output &&
606604
GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
607605
git status --porcelain >../status.actual &&
@@ -651,7 +649,6 @@ EOF
651649
'
652650

653651
test_expect_success 'test sparse status again with untracked cache and subdir' '
654-
avoid_racy &&
655652
: >../trace.output &&
656653
GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
657654
git status --porcelain >../status.actual &&

0 commit comments

Comments
 (0)