Merge pull request 'Sources index: skip .obsidian, .voidbot, LICENSE and provenance files' (#26) from eureka/sources-skip-noise into main

This commit is contained in:
Eureka 2026-11-10 14:24:00 +00:00
commit a60e83fce9

View file

@ -24,13 +24,27 @@ const SKIPPED_NAMES: &[&str] = &["package-lock.json", "pnpm-lock.yaml", "yarn.lo
const LFS_POINTER: &[u8] = b"version https://git-lfs.github.com/spec/v1";
/// Directories of editor settings and generated packets, not the repo's own
/// writing: a path with one of these as a component is not indexed.
const SKIPPED_DIRECTORIES: &[&str] = &[".obsidian", ".voidbot"];
/// Licence texts: a file named exactly one of these stems, bare or with a prose
/// extension. They crowd out a front page; `license.rs` and `Copying.cs` are code.
const SKIPPED_STEMS: &[&str] = &["license", "licence", "copying"];
const LICENSE_EXTENSIONS: &[&str] = &["", "md", "txt", "rst"];
/// Whether a path is not worth reading, by name alone.
pub fn skipped_path(path: &str) -> bool {
let name = path.rsplit('/').next().unwrap_or(path).to_ascii_lowercase();
let mut components = path.split('/');
let name = components.next_back().unwrap_or(path).to_ascii_lowercase();
if components.any(|directory| SKIPPED_DIRECTORIES.contains(&directory.to_ascii_lowercase().as_str())) {
return true;
}
if SKIPPED_NAMES.contains(&name.as_str()) {
return true;
}
name.rsplit_once('.').is_some_and(|(_, extension)| SKIPPED_EXTENSIONS.contains(&extension))
let (stem, extension) = name.rsplit_once('.').unwrap_or((&name, ""));
(SKIPPED_STEMS.contains(&stem) && LICENSE_EXTENSIONS.contains(&extension)) || extension == "provenance" || SKIPPED_EXTENSIONS.contains(&extension)
}
/// The text of a blob worth indexing, or `None`: a NUL byte, bytes that are
@ -186,10 +200,14 @@ mod tests {
#[test]
fn binary_unity_and_lock_paths_are_skipped_by_name_and_source_is_not() {
for path in ["a.png", "dir/B.PNG", "x.lock", "Assets/a.prefab", "Assets/a.unity", "a.cs.meta", "p/package-lock.json", "Cargo.lock"] {
for path in ["a.png", "dir/B.PNG", "x.lock", "Assets/a.prefab", "Assets/a.unity", "a.cs.meta", "p/package-lock.json", "Cargo.lock",
".obsidian/app.json", "vault/.obsidian/appearance.json", ".voidbot/packets/a.json", "LICENSE", "LICENSE.md", "sub/licence.txt", "COPYING", "COPYING.rst", "x/.Obsidian/a.md", "x/.VoidBot/p.json",
"bundle.provenance", "x/bundle.provenance", ".provenance"] {
assert!(skipped_path(path), "{path}");
}
for path in ["src/main.rs", "README.md", "docs/lock.md", "Assets/Scripts/Player.cs", "Makefile", ".gitignore", "locksmith"] {
for path in ["src/main.rs", "README.md", "docs/lock.md", "Assets/Scripts/Player.cs", "Makefile", ".gitignore", "locksmith",
"docs/x.md", "src/obsidian_notes.rs", "docs/licensing.md", "docs/obsidian/notes.md", "provenance.md",
"src/license.rs", "crates/x/src/license.rs", "Copying.cs", "LICENSE-MIT", "LICENSE.md.bak"] {
assert!(!skipped_path(path), "{path}");
}
}