Skip to content
This repository was archived by the owner on Jan 2, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions server/bleep/src/repo/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,18 @@ impl FileType {
}
}

fn should_index_entry(de: &ignore::DirEntry) -> bool {
should_index(&de.path())
}

fn should_index<P: AsRef<Path>>(p: &P) -> bool {
let path = p.as_ref();

// TODO: Make this more robust
if path.components().any(|c| c.as_os_str() == ".git") {
return false;
}

#[rustfmt::skip]
const EXT_BLACKLIST: &[&str] = &[
// graphics
Expand Down Expand Up @@ -149,6 +158,11 @@ mod test {
// These are not typically vendored in Rust.
("dist/main.rs", true),
("vendor/foo.rs", true),
// Ignore .git directory.
(".git/HEAD", false),
(".git/config", false),
(".gitignore", true),
(".github/workflows/ci.yml", true),
];

for (path, index) in tests {
Expand Down
14 changes: 7 additions & 7 deletions server/bleep/src/repo/iterator/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ pub struct FileWalker {
impl FileWalker {
pub fn index_directory(dir: impl AsRef<Path>) -> impl FileSource {
// note: this WILL observe .gitignore files for the respective repos.
let file_list = ignore::Walk::new(&dir)
let walker = ignore::WalkBuilder::new(&dir)
.standard_filters(true)
.hidden(false)
.filter_entry(should_index_entry)
.build();

let file_list = walker
.filter_map(|de| match de {
Ok(de) => Some(de),
Err(err) => {
Expand All @@ -22,12 +28,6 @@ impl FileWalker {
// Preliminarily ignore files that are very large, without reading the contents.
.filter(|de| matches!(de.metadata(), Ok(meta) if meta.len() < MAX_FILE_LEN))
.filter_map(|de| crate::canonicalize(de.into_path()).ok())
.filter(|p| {
p.strip_prefix(&dir)
.as_ref()
.map(should_index)
.unwrap_or_default()
})
.collect();

Self { file_list }
Expand Down