Skip to content

Commit 3204323

Browse files
shengyfuCopilot
andcommitted
Prune whitelisted hidden paths on unchanged verification
This PR keeps the raw hidden status of whitelisted files beside the published visibility, so that a no-op notification for a whitelisted dot-file is dropped. A verification that found the publication current refreshed the evidence but kept that set as published. On Windows, a file can lose both its hidden attribute and the whitelist that admitted it without a change to its visibility or its file version, which has no change time. If neither change was notified, verification found nothing to publish and kept the stale entry. The notification for setting the attribute again then looked unchanged and was dropped, so the file stayed visible to queries without --hidden until a later pass or verification. v1.2.6 invalidated in that case. Elsewhere the raw hidden status depends only on the name, so changing it is a rename, which verification sees as a membership change. Unchanged verification now keeps only the entries that its own walk still reports as hidden and whitelisted. It prunes the set rather than replacing it, as it does the excluded records, because retained view memory is charged for the published set. A whitelisted file hidden since the last publication therefore has no entry and keeps invalidating until a pass publishes. Tests: - unchanged_verification_prunes_whitelisted_entries_its_walk_no_longer_reports (Windows) removes a file's hidden attribute and its info/exclude whitelist without a notification, verifies, sets the attribute again and expects HiddenChanged. - unchanged_file_drops_whitelisted_hidden_files now also checks that an unchanged verification keeps the entries its walk still reports. Co-authored-by: Copilot App <[email protected]>
1 parent b9da528 commit 3204323

3 files changed

Lines changed: 102 additions & 17 deletions

File tree

‎SHARED_WORKTREE_INDEXES.md‎

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1595,15 +1595,24 @@ an ignore-file whitelist admits is visible to queries but still hidden by name.
15951595
For a regular tracked file that ignore rules exclude, each pass records its
15961596
trusted metadata. A tracked file the walk did not list gets a record only when
15971597
the ignore rules the walk applied, parsed from the rule-file contents it read,
1598-
exclude the file or a parent directory; a file restored after the walk, or one
1599-
skipped only for another reason, gets none. It stats only excluded tracked files
1600-
that are present, listing each directory once; absent files and missing
1601-
directories cost no failed stat. The charges for the rule-file snapshots and
1602-
parsed patterns the walk read are held until the records are built, then
1603-
released.
1598+
exclude the file or a parent directory; a tracked file that no rule excludes,
1599+
whether restored after the walk or skipped only for another reason, gets none.
1600+
It stats only excluded tracked files that are present, listing each directory
1601+
once; absent files and missing directories cost no failed stat. The charges for
1602+
the rule-file snapshots and parsed patterns the walk read are held until the
1603+
records are built, then released.
16041604
`last_reconcile.excluded_tracked` counts these records, which count toward
16051605
retained view memory, and `last_reconcile.timings.excluded_records_us` reports
1606-
their cost within discovery. Metadata verification refreshes them in place.
1606+
their cost within discovery. When verification finds the publication current,
1607+
it refreshes these records in place, drops those for files that are gone, and
1608+
forgets the raw hidden status of whitelisted files that its walk no longer
1609+
reports as hidden and whitelisted. On Windows, a file can lose both its hidden
1610+
attribute and the whitelist that admitted it without changing its visibility or
1611+
its file version. If neither change was notified, verification finds the
1612+
publication current; without that pruning, the notification for setting the
1613+
attribute again would be dropped as unchanged. Verification adds neither,
1614+
so a tracked file excluded, or a whitelisted file hidden, since the last
1615+
publication keeps invalidating until a pass publishes.
16071616
Ignore and attributes files (`.gitignore`, `.ignore`, `p4ignore.ini`,
16081617
`.gitattributes`) that the walk does not list, untracked ignored files such as
16091618
build output, and other files without recorded metadata are never dropped:

‎tgrep-core/src/worktrees.rs‎

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1193,11 +1193,20 @@ impl WorktreeView {
11931193
.write()
11941194
.map_err(|_| WorktreeError::Synchronization)?;
11951195
state.evidence = prepared.evidence;
1196-
// Retained memory accounts for the published records only, so only
1197-
// those are refreshed. A file excluded since then stays without a
1198-
// record and keeps invalidating until a pass publishes. Whitelisted
1199-
// hidden paths are kept: with the published visibility unchanged,
1200-
// a stale entry can only make the raw comparison report a change.
1196+
// Retained memory accounts for the published records and
1197+
// whitelisted hidden paths, so both are pruned rather than
1198+
// replaced: a tracked file excluded, or a whitelisted file
1199+
// hidden, since then has no entry and keeps invalidating until a
1200+
// pass publishes. A whitelisted hidden path the walk no longer
1201+
// reports must go. A file can lose both its whitelist and its
1202+
// hidden attribute without changing its published visibility or,
1203+
// on Windows, its file version. If neither change was notified,
1204+
// the stale entry would drop the notification for setting the
1205+
// attribute again.
1206+
let whitelisted_hidden = prepared.whitelisted_hidden;
1207+
state
1208+
.whitelisted_hidden
1209+
.retain(|path| whitelisted_hidden.contains(path));
12011210
let mut excluded = prepared.excluded;
12021211
state
12031212
.excluded

‎tgrep-core/src/worktrees/tests.rs‎

Lines changed: 72 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1592,14 +1592,19 @@ fn unchanged(view: &WorktreeView, root: &Path, path: &str) -> bool {
15921592

15931593
#[cfg(windows)]
15941594
fn set_hidden_attribute(path: &Path) {
1595+
set_file_attributes(
1596+
path,
1597+
windows_sys::Win32::Storage::FileSystem::FILE_ATTRIBUTE_HIDDEN,
1598+
);
1599+
}
1600+
1601+
#[cfg(windows)]
1602+
fn set_file_attributes(path: &Path, attributes: u32) {
15951603
use std::os::windows::ffi::OsStrExt;
1596-
use windows_sys::Win32::Storage::FileSystem::{FILE_ATTRIBUTE_HIDDEN, SetFileAttributesW};
1604+
use windows_sys::Win32::Storage::FileSystem::SetFileAttributesW;
15971605
let wide: Vec<_> = path.as_os_str().encode_wide().chain(Some(0)).collect();
15981606
// The NUL-terminated buffer remains live for the Win32 call.
1599-
assert_ne!(
1600-
unsafe { SetFileAttributesW(wide.as_ptr(), FILE_ATTRIBUTE_HIDDEN) },
1601-
0
1602-
);
1607+
assert_ne!(unsafe { SetFileAttributesW(wide.as_ptr(), attributes) }, 0);
16031608
}
16041609

16051610
#[test]
@@ -1621,6 +1626,14 @@ fn unchanged_file_drops_whitelisted_hidden_files() {
16211626
for target in ["wl/.keep.txt", "sub/.gitignore"] {
16221627
assert!(unchanged(&view, root, target), "{target}");
16231628
}
1629+
// Verification keeps the whitelisted entries its walk still reports.
1630+
assert!(matches!(
1631+
view.verify_metadata().unwrap(),
1632+
Verification::Unchanged(_)
1633+
));
1634+
for target in ["wl/.keep.txt", "sub/.gitignore"] {
1635+
assert!(unchanged(&view, root, target), "{target}");
1636+
}
16241637
write(root, "wl/.keep.txt", b"needle, edited\n");
16251638
assert!(!unchanged(&view, root, "wl/.keep.txt"));
16261639
view.invalidate_path(Path::new("wl/.keep.txt")).unwrap();
@@ -1646,6 +1659,60 @@ fn unchanged_file_drops_whitelisted_hidden_files() {
16461659
}
16471660
}
16481661

1662+
#[cfg(windows)]
1663+
#[test]
1664+
fn unchanged_verification_prunes_whitelisted_entries_its_walk_no_longer_reports() {
1665+
use windows_sys::Win32::Storage::FileSystem::FILE_ATTRIBUTE_NORMAL;
1666+
let fixture = Fixture::new();
1667+
let root = &fixture.root;
1668+
write(root, "plain.txt", b"needle\n");
1669+
write(root, "kept.txt", b"needle\n");
1670+
git(root, &["add", "plain.txt", "kept.txt"]);
1671+
commit(root);
1672+
// The walk doesn't list the repository's exclude file, so verification
1673+
// sees an edit to it only through the visibility the edit changes.
1674+
let exclude = root.join(".git").join("info").join("exclude");
1675+
fs::create_dir_all(exclude.parent().unwrap()).unwrap();
1676+
fs::write(&exclude, "!plain.txt\n!kept.txt\n").unwrap();
1677+
set_hidden_attribute(&root.join("plain.txt"));
1678+
set_hidden_attribute(&root.join("kept.txt"));
1679+
let view = stale_view(root, &fixture.generation());
1680+
view.refresh().unwrap();
1681+
for path in ["plain.txt", "kept.txt"] {
1682+
assert!(!view.state.read().unwrap().visibility.records_hidden(path));
1683+
assert!(unchanged(&view, root, path), "{path}");
1684+
}
1685+
1686+
// Without a notification, plain.txt loses both its attribute and its
1687+
// whitelist. Its visibility and its Windows file version are unchanged,
1688+
// so verification publishes nothing.
1689+
set_file_attributes(&root.join("plain.txt"), FILE_ATTRIBUTE_NORMAL);
1690+
fs::write(&exclude, "!kept.txt\n").unwrap();
1691+
assert!(matches!(
1692+
view.verify_metadata().unwrap(),
1693+
Verification::Unchanged(_)
1694+
));
1695+
assert!(unchanged(&view, root, "kept.txt"));
1696+
1697+
// With no whitelist left, setting the attribute again hides the file.
1698+
set_hidden_attribute(&root.join("plain.txt"));
1699+
let metadata = fs::metadata(root.join("plain.txt")).unwrap();
1700+
assert_eq!(
1701+
view.unchanged_file_reason(Path::new("plain.txt"), &metadata),
1702+
UnchangedFile::HiddenChanged
1703+
);
1704+
view.invalidate_path(Path::new("plain.txt")).unwrap();
1705+
view.refresh().unwrap();
1706+
assert!(
1707+
view.state
1708+
.read()
1709+
.unwrap()
1710+
.visibility
1711+
.records_hidden("plain.txt")
1712+
);
1713+
assert!(unchanged(&view, root, "plain.txt"));
1714+
}
1715+
16491716
#[test]
16501717
fn unchanged_file_drops_tracked_files_that_ignore_rules_exclude() {
16511718
let fixture = filter_fixture();

0 commit comments

Comments
 (0)