From 9f1302649c1bb5a6b179c150bc79af5beccbae5d Mon Sep 17 00:00:00 2001 From: Fintan Halpenny Date: Wed, 16 Nov 2022 12:51:21 +0000 Subject: [PATCH] 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 X-Clacks-Overhead: GNU Terry Pratchett --- radicle-surf/src/git/branch.rs | 30 ++++++++++++++++++++++++++++++ radicle-surf/src/git/tag.rs | 16 +++++++++------- 2 files changed, 39 insertions(+), 7 deletions(-) diff --git a/radicle-surf/src/git/branch.rs b/radicle-surf/src/git/branch.rs index 988f667..c6f3a65 100644 --- a/radicle-surf/src/git/branch.rs +++ b/radicle-surf/src/git/branch.rs @@ -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 { diff --git a/radicle-surf/src/git/tag.rs b/radicle-surf/src/git/tag.rs index 743599b..587bd2d 100644 --- a/radicle-surf/src/git/tag.rs +++ b/radicle-surf/src/git/tag.rs @@ -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 {