Correct handling of ignore files
[?]
Dec 15, 2020, 9:19 PM
4VWXL6KQGYGDUQRCVJCEVIV6CKJSEIYDX4YF33OX6EDNKJNEGD2ACDependencies
- [2]
ZHABNS3SCanonicalize all paths - [3]
4OCC6D42Recursive add - [4]
OJZWJUF2MUCH faster `pijul add -r` - [5]
SXEYMYF7Fixing the bad changes in history (unfortunately, by rebooting).
Change contents
- edit in pijul/src/commands/file_operations.rs at line 104
let mut stderr = std::io::stderr(); - replacement in pijul/src/commands/file_operations.rs at line 107
if self.paths.len() > 1 && !libpijul::working_copy::filesystem::ignore_filter_path(path)let path = CanonicalPathBuf::canonicalize(&path)?;debug!("{:?}", path);let meta = std::fs::metadata(&path)?;debug!("{:?}", meta);if self.paths.len() > 1&& !libpijul::working_copy::filesystem::filter_ignore(repo_path.as_ref(),path.as_ref(),meta.is_dir(),) - replacement in pijul/src/commands/file_operations.rs at line 122
if let Ok((full, prefix)) = get_prefix(Some(repo_path.as_ref()), path) {if let Ok((full, prefix)) = get_prefix(Some(repo_path.as_ref()), path.as_path()) { - replacement in pijul/src/commands/file_operations.rs at line 132
let path = path.canonicalize()?;let meta = std::fs::metadata(&path)?;let path = if let Ok(path) = path.strip_prefix(&repo.path) {let path = if let Ok(path) = path.as_path().strip_prefix(&repo_path.as_path()) { - replacement in pijul/src/commands/file_operations.rs at line 139
txn.add(&path_str, meta.is_dir())?if let Err(e) = txn.add(&path_str, meta.is_dir()) {writeln!(stderr, "{}", e)?;} - replacement in libpijul/src/working_copy/filesystem.rs at line 12[3.1016]→[3.1016:1110](∅→∅),[3.1110]→[3.209107:209110](∅→∅),[3.209107]→[3.209107:209110](∅→∅),[3.209110]→[3.1111:1397](∅→∅)
pub fn ignore_filter(entry: &ignore::DirEntry) -> bool {ignore_filter_path(entry.path())}pub fn ignore_filter_path(path: &std::path::Path) -> bool {debug!("ignore_filter_path {:?}", path);if let Some(file) = path.file_name() {if let Some(file) = file.to_str() {!file.ends_with("~") && !file.starts_with("#")} else {falsepub fn filter_ignore(root_: &CanonicalPath, path: &CanonicalPath, is_dir: bool) -> bool {debug!("path = {:?} root = {:?}", path, root_);if let Ok(suffix) = path.as_path().strip_prefix(root_.as_path()) {debug!("suffix = {:?}", suffix);let mut root = root_.as_path().to_path_buf();let mut ignore = ignore::gitignore::GitignoreBuilder::new(&root);let mut add_root = |root: &mut PathBuf| {root.push(".ignore");ignore.add(&root);root.pop();root.push(".gitignore");ignore.add(&root);root.pop();};add_root(&mut root);for c in suffix.components() {root.push(c);add_root(&mut root);}if let Ok(ig) = ignore.build() {let m = ig.matched(suffix, is_dir);debug!("m = {:?}", m);return !m.is_ignore(); - edit in libpijul/src/working_copy/filesystem.rs at line 36
} else {true - edit in libpijul/src/working_copy/filesystem.rs at line 37
false - replacement in libpijul/src/working_copy/filesystem.rs at line 175
sender.send((path.to_path_buf(), is_dir)).unwrap();if sender.send((path.to_path_buf(), is_dir)).is_err() {return ignore::WalkState::Quit;} - replacement in libpijul/src/working_copy/filesystem.rs at line 195
txn.add(path_str, is_dir)?match txn.add(path_str, is_dir) {Ok(()) => {}Err(crate::fs::FsError::AlreadyInRepo(_)) => {}Err(e) => return Err(e.into()),}