}
Some(SubCommand::Delete {
repo_path,
channel,
tag,
}) => {
let repo = Repository::find_root(repo_path)?;
let mut tag_path = repo.changes_dir.clone();
let h = if let Some(h) = libpijul::Merkle::from_base32(tag.as_bytes()) {
libpijul::changestore::filesystem::push_tag_filename(&mut tag_path, &h);
h
} else {
super::find_hash(&mut tag_path, &tag)?
};
let mut txn = repo.pristine.mut_txn_begin()?;
let channel_name = channel.unwrap_or_else(|| {
txn.current_channel()
.unwrap_or(crate::DEFAULT_CHANNEL)
.to_string()
});
let channel = if let Some(c) = txn.load_channel(&channel_name)? {
c
} else {
bail!("Channel {:?} not found", channel_name)
};
{
let mut ch = channel.write();
if let Some(n) = txn.channel_has_state(txn.states(&*ch), &h.into())? {
let tags = txn.tags_mut(&mut *ch);
txn.del_tags(tags, n.into())?;
}
}
txn.commit()?;
writeln!(stdout, "Deleted tag {}", h.to_base32())?;