Command to delete a tag

pmeunier
Dec 30, 2021, 10:07 AM
E6IKUIPDX3P5CHW5R62DEJTCZZFJIM6UKQ6QN3SPASTAJY3MYZWQC

Dependencies

  • [2] ZDK3GNDB Tag transactions (including a massive refactoring of errors)
  • [3] QL6K2ZM3 Tags
  • [4] 3FTEGCMR add timestamp_validator to tag --timestamp option
  • [5] L3RCAPPK Add --repository to tag commands

Change contents

  • replacement in pijul/src/commands/tag.rs at line 38
    [3.942][3.942:1019]()
    /// Record the change in this channel instead of the current channel
    [3.942]
    [3.1019]
    /// Tag the current state of this channel instead of the
    /// current channel.
  • edit in pijul/src/commands/tag.rs at line 62
    [2.5312]
    [2.5312]
    /// Set the repository where this command should run. Defaults to
    /// the first ancestor of the current directory that contains a
    /// `.pijul` directory.
    #[clap(long = "repository")]
    repo_path: Option<PathBuf>,
    tag: String,
    },
    /// Delete a tag from a channel. If the same state isn't tagged in
    /// other channels, delete the tag file.
    #[clap(name = "delete")]
    Delete {
  • edit in pijul/src/commands/tag.rs at line 78
    [2.5563]
    [2.5563]
    /// Delete the tag in this channel instead of the current channel
    #[clap(long = "channel")]
    channel: Option<String>,
  • edit in pijul/src/commands/tag.rs at line 200
    [2.7017]
    [3.4565]
    }
    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())?;