Correct handling of ignore files

[?]
Dec 15, 2020, 9:19 PM
4VWXL6KQGYGDUQRCVJCEVIV6CKJSEIYDX4YF33OX6EDNKJNEGD2AC

Dependencies

  • [2] ZHABNS3S Canonicalize all paths
  • [3] OJZWJUF2 MUCH faster `pijul add -r`
  • [4] SXEYMYF7 Fixing the bad changes in history (unfortunately, by rebooting).
  • [5] 4OCC6D42 Recursive add

Change contents

  • edit in pijul/src/commands/file_operations.rs at line 104
    [2.717]
    [3.171551]
    let mut stderr = std::io::stderr();
  • replacement in pijul/src/commands/file_operations.rs at line 107
    [3.107][3.107:208]()
    if self.paths.len() > 1 && !libpijul::working_copy::filesystem::ignore_filter_path(path)
    [3.107]
    [3.208]
    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
    [3.340][2.718:807]()
    if let Ok((full, prefix)) = get_prefix(Some(repo_path.as_ref()), path) {
    [3.340]
    [2.807]
    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
    [3.172105][3.557:737]()
    let path = path.canonicalize()?;
    let meta = std::fs::metadata(&path)?;
    let path = if let Ok(path) = path.strip_prefix(&repo.path) {
    [3.172105]
    [3.737]
    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
    [3.939][3.939:994]()
    txn.add(&path_str, meta.is_dir())?
    [3.939]
    [3.994]
    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 {
    false
    [3.1016]
    [3.1397]
    pub 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
    [3.1407][3.1407:1433]()
    } else {
    true
  • edit in libpijul/src/working_copy/filesystem.rs at line 37
    [3.1439]
    [3.1439]
    false
  • replacement in libpijul/src/working_copy/filesystem.rs at line 175
    [2.2273][2.2273:2361]()
    sender.send((path.to_path_buf(), is_dir)).unwrap();
    [2.2273]
    [2.2361]
    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
    [3.3006][3.3006:3045]()
    txn.add(path_str, is_dir)?
    [3.3006]
    [3.3045]
    match txn.add(path_str, is_dir) {
    Ok(()) => {}
    Err(crate::fs::FsError::AlreadyInRepo(_)) => {}
    Err(e) => return Err(e.into()),
    }