Skip to content

feature/traverse: Add an option to rely purely on ignore files for traversing directories#339

Open
MA-DDN wants to merge 10 commits intodrahnr:masterfrom
MA-DDN:add-basic-gitignore-support
Open

feature/traverse: Add an option to rely purely on ignore files for traversing directories#339
MA-DDN wants to merge 10 commits intodrahnr:masterfrom
MA-DDN:add-basic-gitignore-support

Conversation

@MA-DDN
Copy link
Copy Markdown

@MA-DDN MA-DDN commented Nov 27, 2024

What does this PR accomplish?

  • 🦚 Feature

Changes proposed by this PR:

This pr adds an option flag to change the behaviour of the traversal module to collect all relevant files except those which match an entry in a .gitignore file. Our usecase for this is to be able to ignore certain temporary Markdown files which are pulled in when building our documentation.

📜 Checklist

  • Works on the ./demo sub directory
  • Test coverage is excellent and passes
  • Documentation is thorough

@MA-DDN MA-DDN marked this pull request as ready for review November 27, 2024 14:56
Comment thread src/traverse/mod.rs Outdated
Comment thread src/traverse/mod.rs
Copy link
Copy Markdown
Owner

@drahnr drahnr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With some delay, I am not opposed to the changes, yet with the added complexity some more code unification and carve outs need to be done before I'll merge this.

Sorry for the long review delay.

@drahnr
Copy link
Copy Markdown
Owner

drahnr commented Feb 11, 2025

Gentle ping @MA-DDN

@MA-DDN MA-DDN force-pushed the add-basic-gitignore-support branch from 7765ad5 to 99a20df Compare August 12, 2025 17:51
@MA-DDN MA-DDN requested a review from drahnr August 13, 2025 15:23
@jgrund
Copy link
Copy Markdown

jgrund commented Aug 18, 2025

Looks like this was updated. Could it be re-reviewed?

@drahnr
Copy link
Copy Markdown
Owner

drahnr commented Aug 19, 2025

I'll get to it next week

Copy link
Copy Markdown
Owner

@drahnr drahnr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, thank you for the PR and the work you put in, it looks good on a technical level, bar the comments I left.

I have a larger scope question: What issue are you solving with using only .gitignore driven file selection? Can you elaborate the use-case, both as part of a comment here and in the relevant code pieces?

Comment thread src/config/args.rs
/// This flag also modifies the behaviour of the recursive flag
/// to purely recurse down directories.
#[clap(short, long)]
pub gitignore: bool,
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this carries ambiguous meaning for the user. We should find a name that includes either follow or only or both terms to convey the meaning you want.

Comment thread src/config/args.rs
/// This flag also modifies the behaviour of the recursive flag
/// to purely recurse down directories.
#[clap(short, long)]
gitignore: bool,
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need this twice, do we?

Comment thread src/traverse/mod.rs
);
continue;
}
/// Process a path that could be a file or directory, with optional directory traversal logic
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requires documentation how Option::None is to be interpreted or use of a custom enum. The previous version, while more complex, avoided that :)

Comment thread src/traverse/mod.rs
let cwd = cwd()?;

// Collect files using gitignore rules
let collect_gitignore_files = |flow: &mut VecDeque<PathBuf>,
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't seem the closure uses any local state, can we upgrade it to a full function?

Comment thread src/traverse/mod.rs
.map(|x| x.path().to_owned())
})
.filter(|path: &PathBuf| {
path.to_str()
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should use path.extension() which yields an OsStr which implements ParitialEq with str or use a match block / matches! invocation to avoid some more visual complexity

Comment thread src/traverse/mod.rs
entry
.ok()
.filter(|entry| entry.file_type().map(|ft| ft.is_file()).unwrap_or(false))
.map(|x| x.path().to_owned())
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Retaining the entry and having this one as the last step seems easier to read. Try to avoid |x| x.., use entry to at least leave a crumb of information, particularly in lengthy chains.

Comment thread src/traverse/mod.rs
};
files_to_check.push(x);
log::debug!("Processing {} -> {}", path_in.display(), path.display());
path.canonicalize().ok()
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am always unsure we want to be so lenient here, we should at the very least print a warning if we omit a file.

Comment thread src/traverse/mod.rs

// stage 2 - check for manifest, .rs , .md files and directories
if gitignore {
let mut all_files = collect_gitignore_files(&mut flow, recurse);
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should pass flow by value, we don't use it everafter.

Comment thread src/traverse/mod.rs
let mut files_to_check = Vec::with_capacity(64);

// stage 2 - check for manifest, .rs , .md files and directories
if gitignore {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable needs a better name

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants