Allow to use short tag hashes

pmeunier
Jul 4, 2021, 10:03 PM
FZ7MXL3BGIDZEEEKWX4CHAKPDO46FFF5BZDL6S2KOWTZ53GE7D6AC

Dependencies

Change contents

  • replacement in pijul/src/commands/tag.rs at line 106
    [3.3533][2.93:157]()
    Some(SubCommand::Checkout { tag, to_channel }) => {
    [3.3533]
    [3.3591]
    Some(SubCommand::Checkout {
    mut tag,
    to_channel,
    }) => {
    let mut tag_path = repo.path.join(libpijul::DOT_DIR);
    tag_path.push("tags");
  • edit in pijul/src/commands/tag.rs at line 113
    [3.3678]
    [3.3678]
    libpijul::changestore::filesystem::push_filename(&mut tag_path, &h);
  • edit in pijul/src/commands/tag.rs at line 115
    [3.3700]
    [3.3700]
    } else if tag.len() < 2 {
    bail!("Ambiguous tag hash, need at least two characters")
  • replacement in pijul/src/commands/tag.rs at line 118
    [3.3725][3.3725:3776]()
    bail!("Invalid tag {:?}", tag)
    [3.3725]
    [3.3776]
    find_tag(&mut tag_path, &tag)?
  • edit in pijul/src/commands/tag.rs at line 120
    [3.3795]
    [3.3795]
    let mut txn = repo.pristine.mut_txn_begin()?;
    tag = h.to_base32();
  • edit in pijul/src/commands/tag.rs at line 128
    [3.3984][3.3984:4046]()
    let mut txn = repo.pristine.mut_txn_begin()?;
  • edit in pijul/src/commands/tag.rs at line 131
    [3.4198][3.4198:4392]()
    let mut tag_path = repo.path.join(libpijul::DOT_DIR);
    tag_path.push("tags");
    libpijul::changestore::filesystem::push_filename(&mut tag_path, &h);
  • edit in pijul/src/commands/tag.rs at line 238
    [3.6361]
    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")
    }