Apply changes with prefixes in .pijul/changes

pmeunier
Jul 7, 2021, 12:13 PM
E7UUQQCCX2WSVOSMO4OWCJFFU7RGQKQ4TRBBICVM52K7ATTHYNSAC

Dependencies

  • [2] TYTQGSKZ Apply: proper error message when the change is not found
  • [3] A3RM526Y Integrating identity malleability
  • [4] FZ7MXL3B Allow to use short tag hashes
  • [5] SXEYMYF7 Fixing the bad changes in history (unfortunately, by rebooting).
  • [6] DX2FO4HZ Tag CLI cleanup
  • [7] QL6K2ZM3 Tags
  • [8] R3H7D42U Debugging `pijul git`: proper error reporting
  • [*] SLJ3OHD4 unrecord: show list of changes if none were given as arguments

Change contents

  • edit in pijul/src/commands/tag.rs at line 115
    [5.3700][4.313:433]()
    } else if tag.len() < 2 {
    bail!("Ambiguous tag hash, need at least two characters")
  • replacement in pijul/src/commands/tag.rs at line 116
    [5.3725][4.434:485]()
    find_tag(&mut tag_path, &tag)?
    [5.3725]
    [5.3776]
    super::find_hash(&mut tag_path, &tag)?
  • edit in pijul/src/commands/tag.rs at line 235
    [5.6359][5.6359:6361](),[5.6361][4.587:1457]()
    }
    fn find_tag(tag_path: &mut PathBuf, tag: &str) -> Result<libpijul::Hash, anyhow::Error> {
    let (a, b) = tag.split_at(2);
    tag_path.push(a);
    let mut result = None;
    for f in std::fs::read_dir(&tag_path)? {
    let e = f?;
    let p = if let Ok(p) = e.file_name().into_string() {
    p
    } else {
    continue;
    };
    if p.starts_with(b) {
    if result.is_none() {
    result = Some(p)
    } else {
    bail!("Ambiguous tag hash");
    }
    }
    }
    if let Some(mut r) = result {
    tag_path.push(&r);
    if let Some(i) = r.find('.') {
    r.truncate(i)
    }
    let f = format!("{}{}", a, r);
    if let Some(h) = libpijul::Hash::from_base32(f.as_bytes()) {
    return Ok(h);
    }
    }
    bail!("Tag not found")
  • edit in pijul/src/commands/mod.rs at line 259
    [3.21042]
    [3.21042]
    }
    }
    fn find_hash(path: &mut std::path::PathBuf, hash: &str) -> Result<libpijul::Hash, anyhow::Error> {
    use libpijul::Base32;
    if hash.len() < 2 {
    bail!("Ambiguous hash, need at least two characters")
    }
    let (a, b) = hash.split_at(2);
    path.push(a);
    let mut result = None;
    for f in std::fs::read_dir(&path)? {
    let e = f?;
    let p = if let Ok(p) = e.file_name().into_string() {
    p
    } else {
    continue;
    };
    if p.starts_with(b) {
    if result.is_none() {
    result = Some(p)
    } else {
    bail!("Ambiguous hash");
    }
    }
    }
    if let Some(mut r) = result {
    path.push(&r);
    if let Some(i) = r.find('.') {
    r.truncate(i)
    }
    let f = format!("{}{}", a, r);
    if let Some(h) = libpijul::Hash::from_base32(f.as_bytes()) {
    return Ok(h);
    }
  • edit in pijul/src/commands/mod.rs at line 295
    [3.21048]
    [10.5215]
    bail!("Hash not found")
  • replacement in pijul/src/commands/apply.rs at line 51
    [2.79][2.79:165]()
    let change = match change {
    Ok(change) => change,
    [2.79]
    [2.165]
    match change {
    Ok(change) => repo.changes.save_change(&change)?,
  • replacement in pijul/src/commands/apply.rs at line 55
    [2.305][2.305:707]()
    let extra = if std::path::Path::new(&ch).is_relative() {
    " Using the full path to the change file may help."
    } else {
    ""
    };
    bail!("File {} not found, and not recognised as a prefix of a known change identifier.{}", ch, extra)
    [2.305]
    [2.707]
    let mut changes = repo.changes_dir.clone();
    super::find_hash(&mut changes, &ch)?
  • replacement in pijul/src/commands/apply.rs at line 58
    [2.740][2.740:789]()
    return Err(e.into())
    [2.740]
    [2.789]
    return Err(e.into());
  • replacement in pijul/src/commands/apply.rs at line 61
    [2.837][2.837:907](),[2.907][5.195640:195691](),[5.195640][5.195640:195691]()
    Err(e) => return Err(e.into())
    };
    repo.changes.save_change(&change)?
    [2.837]
    [5.922]
    Err(e) => return Err(e.into()),
    }