mirror of
https://seed.radicle.dev/rad:z6cFWeWpnZNHh9rUW8phgA3b5yGt.git
synced 2026-10-29 16:01:01 +08:00
radicle-surf: add short_name methods
Add `short_name` methods to `Branch`, `Local`, `Remote`, and `Tag` to get the short version of the reference name. Also adds a `remote` method to `Remote`. Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com> X-Clacks-Overhead: GNU Terry Pratchett
This commit is contained in:
@@ -37,6 +37,18 @@ impl Branch {
|
||||
Self::Remote(Remote::new(remote, name))
|
||||
}
|
||||
|
||||
/// Return the short `Branch` refname,
|
||||
/// e.g. `fix/ref-format`.
|
||||
pub fn short_name(&self) -> &RefString {
|
||||
match self {
|
||||
Branch::Local(local) => local.short_name(),
|
||||
Branch::Remote(remote) => remote.short_name(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Give back the fully qualified `Branch` refname,
|
||||
/// e.g. `refs/remotes/origin/fix/ref-format`,
|
||||
/// `refs/heads/fix/ref-format`.
|
||||
pub fn refname(&self) -> Qualified {
|
||||
match self {
|
||||
Branch::Local(local) => local.refname(),
|
||||
@@ -126,6 +138,12 @@ impl Local {
|
||||
}
|
||||
}
|
||||
|
||||
/// Return the short `Local` refname,
|
||||
/// e.g. `fix/ref-format`.
|
||||
pub fn short_name(&self) -> &RefString {
|
||||
&self.name
|
||||
}
|
||||
|
||||
/// Return the fully qualified `Local` refname,
|
||||
/// e.g. `refs/heads/fix/ref-format`.
|
||||
pub fn refname(&self) -> Qualified {
|
||||
@@ -219,6 +237,18 @@ impl Remote {
|
||||
})
|
||||
}
|
||||
|
||||
/// Return the short `Remote` refname,
|
||||
/// e.g. `fix/ref-format`.
|
||||
pub fn short_name(&self) -> &RefString {
|
||||
&self.name
|
||||
}
|
||||
|
||||
/// Return the remote of the `Remote`'s refname,
|
||||
/// e.g. `origin`.
|
||||
pub fn remote(&self) -> &RefString {
|
||||
&self.remote
|
||||
}
|
||||
|
||||
/// Give back the fully qualified `Remote` refname,
|
||||
/// e.g. `refs/remotes/origin/fix/ref-format`.
|
||||
pub fn refname(&self) -> Qualified {
|
||||
|
||||
@@ -39,18 +39,20 @@ impl Tag {
|
||||
}
|
||||
}
|
||||
|
||||
/// Return the fully qualified `Tag` refname,
|
||||
/// e.g. `refs/tags/release/v1`.
|
||||
pub fn refname(&self) -> Qualified {
|
||||
lit::refs_tags(self.name()).into()
|
||||
}
|
||||
|
||||
fn name(&self) -> &RefString {
|
||||
/// Return the short `Tag` refname,
|
||||
/// e.g. `release/v1`.
|
||||
pub fn short_name(&self) -> &RefString {
|
||||
match &self {
|
||||
Tag::Light { name, .. } => name,
|
||||
Tag::Annotated { name, .. } => name,
|
||||
}
|
||||
}
|
||||
|
||||
/// Return the fully qualified `Tag` refname,
|
||||
/// e.g. `refs/tags/release/v1`.
|
||||
pub fn refname(&self) -> Qualified {
|
||||
lit::refs_tags(self.short_name()).into()
|
||||
}
|
||||
}
|
||||
|
||||
pub mod error {
|
||||
|
||||
Reference in New Issue
Block a user