Allow to use short tag hashes
Dependencies
- [2]
AAXP2534Tags: completing the subcommand - [3]
QL6K2ZM3Tags - [4]
DX2FO4HZTag CLI cleanup - [5]
IQWG3UP4Fixing a bug in tag restore
Change contents
- replacement in pijul/src/commands/tag.rs at line 106
Some(SubCommand::Checkout { tag, to_channel }) => {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
libpijul::changestore::filesystem::push_filename(&mut tag_path, &h); - edit in pijul/src/commands/tag.rs at line 115
} else if tag.len() < 2 {bail!("Ambiguous tag hash, need at least two characters") - replacement in pijul/src/commands/tag.rs at line 118
bail!("Invalid tag {:?}", tag)find_tag(&mut tag_path, &tag)? - edit in pijul/src/commands/tag.rs at line 120
let mut txn = repo.pristine.mut_txn_begin()?;tag = h.to_base32(); - edit in pijul/src/commands/tag.rs at line 128
let mut txn = repo.pristine.mut_txn_begin()?; - edit in pijul/src/commands/tag.rs at line 131
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")}