E7UUQQCCX2WSVOSMO4OWCJFFU7RGQKQ4TRBBICVM52K7ATTHYNSAC
TYTQGSKZTHRGBOD6HQGK3VWWPXYXT5JONXYOV65ZO4O3HT7MBUNQC
A3RM526Y7LUXNYW4TL56YKQ5GVOK2R5D7JJVTSQ6TT5MEXIR6YAAC
FZ7MXL3BGIDZEEEKWX4CHAKPDO46FFF5BZDL6S2KOWTZ53GE7D6AC
QL6K2ZM35B3NIXEMMCJWUSFXOBQHAGXRDMO7ID5DCKTJH4QJVY7QC
SXEYMYF7P4RZMZ46WPL4IZUTSQ2ATBWYZX7QNVMS3SGOYXYOHAGQC
SLJ3OHD4F6GJGZ3SV2D7DMR3PXYHPSI64X77KZ3RJ24EGEX6ZNQAC
R3H7D42UZ446V5TO2574BMAQQAYYJPEIMSZVDPAGVIYU2COJSWBAC
}
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")
}
}
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);
}
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)
let mut changes = repo.changes_dir.clone();
super::find_hash(&mut changes, &ch)?