Recursive add

[?]
Dec 5, 2020, 1:10 PM
4OCC6D42GZYRDLH3NSKXMJTRKXP7UZ6Z3YNGCNUT7NT6WBDBCBIAC

Dependencies

  • [2] R3H7D42U Debugging `pijul git`: proper error reporting
  • [3] BZSC7VMY address clippy lints
  • [4] TZVUNELW Documentation comments
  • [5] JP3BYVXX Fixing file paths on Windows
  • [6] BAUL3WR2 Format, versions, README
  • [7] YDKNUL6B Add `diff --short` that lists changes without showing them
  • [8] SXEYMYF7 Fixing the bad changes in history (unfortunately, by rebooting).

Change contents

  • edit in pijul/src/commands/file_operations.rs at line 91
    [4.171296]
    [4.331]
    #[clap(short = 'r', long = "recursive")]
    recursive: bool,
  • edit in pijul/src/commands/file_operations.rs at line 101
    [4.171507][4.171507:171551]()
    let mut stderr = std::io::stderr();
  • replacement in pijul/src/commands/file_operations.rs at line 102
    [4.171591][4.171591:171720](),[4.171720][3.454:540](),[3.540][4.171806:171880](),[4.171806][4.171806:171880]()
    debug!("{:?}", path);
    if let Some(p) = path.file_name() {
    if let Some(p) = p.to_str() {
    if p.ends_with('~') || (p.starts_with('#') && p.ends_with('#')) {
    continue;
    }
    }
    [4.171591]
    [4.171880]
    info!("Adding {:?}", path);
    if self.paths.len() > 1 && !libpijul::working_copy::filesystem::ignore_filter_path(path)
    {
    continue;
  • replacement in pijul/src/commands/file_operations.rs at line 107
    [4.171894][4.171894:172084]()
    let path = path.canonicalize()?;
    let meta = std::fs::metadata(&path)?;
    let path = if let Ok(path) = path.strip_prefix(&repo.path) {
    path
    [4.171894]
    [4.172084]
    if self.recursive {
    use libpijul::working_copy::filesystem::*;
    if let Ok((full, prefix)) = get_prefix(Some(&repo.path), path) {
    repo.working_copy
    .add_prefix_rec(&mut txn, &repo.path, &full, &prefix)?
    }
  • replacement in pijul/src/commands/file_operations.rs at line 114
    [4.172105][4.172105:172392]()
    continue;
    };
    let path_str = path.to_str().unwrap();
    if !txn.is_tracked(&path_str) {
    writeln!(stderr, "Adding {:?}", path)?;
    info!("Adding {:?}", path);
    txn.add(&path_str, meta.is_dir())?
    [4.172105]
    [4.172392]
    let path = path.canonicalize()?;
    let meta = std::fs::metadata(&path)?;
    let path = if let Ok(path) = path.strip_prefix(&repo.path) {
    path
    } else {
    continue;
    };
    let path_str = path.to_str().unwrap();
    if !txn.is_tracked(&path_str) {
    txn.add(&path_str, meta.is_dir())?
    }
  • edit in libpijul/src/working_copy/filesystem.rs at line 8
    [4.209107]
    [4.209107]
    }
    pub fn ignore_filter(entry: &ignore::DirEntry) -> bool {
    ignore_filter_path(entry.path())
  • edit in libpijul/src/working_copy/filesystem.rs at line 14
    [4.209110]
    [4.209110]
    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
    }
    } else {
    true
    }
    }
    /// From a path on the filesystem, return the canonical path (a `PathBuf`), and a
    /// prefix relative to the root of the repository (a `String`).
  • edit in libpijul/src/working_copy/filesystem.rs at line 83
    [2.1570]
    [4.210920]
    }
    Ok(())
    }
    pub fn add_prefix_rec<T: crate::MutTxnTExt + crate::TxnTExt>(
    &self,
    txn: &mut T,
    repo_path: &Path,
    full: &Path,
    prefix: &str,
    ) -> Result<(), anyhow::Error> {
    debug!("record_prefix {:?}", prefix);
    let repo_path_ = std::fs::canonicalize(repo_path)?;
    debug!("full = {:?}", full);
    let meta = std::fs::metadata(&full);
    debug!("meta = {:?}", meta);
    debug!("{:?}", full.strip_prefix(&repo_path_));
    if let Ok(meta) = meta {
    if meta.is_dir() {
    let mut walk = WalkBuilder::new(&full);
    walk.standard_filters(true);
    let walk = walk.build();
    for entry in walk {
    let entry = entry?;
    let p = entry.path();
    if let Some(p) = p.file_name() {
    if let Some(p) = p.to_str() {
    if p.ends_with("~") || (p.starts_with("#") && p.ends_with("#")) {
    continue;
    }
    }
    }
    debug!("entry path = {:?} {:?}", entry.path(), repo_path);
    if let Ok(path) = entry.path().strip_prefix(&repo_path_) {
    let path_str = path.to_str().unwrap();
    if !txn.is_tracked(&path_str) {
    info!("Adding {:?}", path);
    txn.add(path_str, entry.file_type().unwrap().is_dir())?
    } else {
    debug!("already tracked {:?}", path_str)
    }
    } else {
    debug!("entry = {:?}", entry.path());
    }
    }
    } else if let Ok(path) = full.strip_prefix(&repo_path_) {
    let path_str = path.to_str().unwrap();
    if !txn.is_tracked(&path_str) {
    info!("Adding file {:?}", path);
    txn.add(path_str, false)?
    }
    }
  • edit in libpijul/src/working_copy/filesystem.rs at line 151
    [4.211319][4.211319:211425]()
    debug!("record_prefix {:?}", prefix);
    let repo_path_ = std::fs::canonicalize(repo_path)?;
  • replacement in libpijul/src/working_copy/filesystem.rs at line 152
    [4.211500][4.211500:212689](),[4.212753][4.212753:213373](),[4.213429][4.213429:213590]()
    debug!("full = {:?}", full);
    let meta = std::fs::metadata(&full);
    debug!("meta = {:?}", meta);
    debug!("{:?}", full.strip_prefix(&repo_path_));
    if let Ok(meta) = meta {
    if meta.is_dir() {
    let mut walk = WalkBuilder::new(&full);
    walk.standard_filters(true);
    let walk = walk.build();
    for entry in walk {
    let entry = entry?;
    let p = entry.path();
    if let Some(p) = p.file_name() {
    if let Some(p) = p.to_str() {
    if p.ends_with("~") || (p.starts_with("#") && p.ends_with("#")) {
    continue;
    }
    }
    }
    debug!("entry path = {:?} {:?}", entry.path(), repo_path);
    if let Ok(path) = entry.path().strip_prefix(&repo_path_) {
    let path_str = path.to_str().unwrap();
    if !txn.is_tracked(&path_str) {
    info!("Adding {:?}", path);
    txn.add(path_str, entry.file_type().unwrap().is_dir())?
    } else {
    debug!("already tracked {:?}", path_str)
    }
    } else {
    debug!("entry = {:?}", entry.path());
    }
    }
    } else if let Ok(path) = full.strip_prefix(&repo_path_) {
    let path_str = path.to_str().unwrap();
    if !txn.is_tracked(&path_str) {
    info!("Adding file {:?}", path);
    txn.add(path_str, false)?
    }
    }
    }
    [4.211500]
    [4.213590]
    self.add_prefix_rec(txn, repo_path, &full, &prefix)?;