diff options
| author | A Farzat <a@farzat.xyz> | 2026-06-06 14:01:12 +0300 |
|---|---|---|
| committer | A Farzat <a@farzat.xyz> | 2026-06-06 14:01:12 +0300 |
| commit | afc1765530e69cf40aac4b33e4c5e384b4702f22 (patch) | |
| tree | 4c49fcef988f85481fa9da01b9ba39c9192b88e4 /src/main.rs | |
| parent | cc23e7734459f3e118dd6204b13296caf83591b2 (diff) | |
| download | repo2markdown-afc1765530e69cf40aac4b33e4c5e384b4702f22.tar.gz repo2markdown-afc1765530e69cf40aac4b33e4c5e384b4702f22.zip | |
Add naive duplication avoidance
Diffstat (limited to 'src/main.rs')
| -rw-r--r-- | src/main.rs | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/src/main.rs b/src/main.rs index f95c372..bf687c6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,7 +3,7 @@ use std::{ ffi::OsStr, io::{self, Read, Write}, os::unix::ffi::OsStrExt, - path::Path, + path::{Path, PathBuf}, }; use repo2markdown::{ @@ -74,6 +74,7 @@ pub fn run<R: Read, W: Write>( let project_name = project_name.unwrap_or_else(|| derive_project_name(root)); renderer.render_header(project_name)?; + let mut last_rendered_path = PathBuf::from(""); for segment in buf.split(|b| *b == 0) { if segment.is_empty() { continue; @@ -81,7 +82,15 @@ pub fn run<R: Read, W: Write>( let path = Path::new(OsStr::from_bytes(segment)); let normalized_path = normalizer.normalize(path)?; - renderer.render_path(&normalized_path)?; + if normalized_path.relative == last_rendered_path { + logger.warn(format!( + "Duplicate file detected: {:?}", + normalized_path.relative + )); + } else { + renderer.render_path(&normalized_path)?; + last_rendered_path = normalized_path.relative; + } } Ok(()) } @@ -243,6 +252,24 @@ mod tests { } #[test] + fn duplicate_files_in_sequence_are_skipped() { + let temp_dir = tempdir().unwrap(); + let origin = temp_dir.path(); + let root = temp_dir.path(); + + fs::write(origin.join("a.rs"), "A").unwrap(); + + let input = Cursor::new(b"a.rs\0a.rs\0"); + let mut output = Vec::new(); + + run_with_default_logger(input, &mut output, root, origin, None).unwrap(); + + let output = String::from_utf8(output).unwrap(); + + assert_eq!(output.matches("## File: a.rs").count(), 1); + } + + #[test] fn project_name_is_derived_from_root_by_default_even_if_directory_does_not_exist() { let temp_dir = tempdir().unwrap(); let origin_base = temp_dir.path(); |
