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:
Fintan Halpenny
2022-11-18 11:20:08 +00:00
parent 1ac99ac456
commit 9f1302649c
2 changed files with 39 additions and 7 deletions
+30
View File
@@ -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 {
+9 -7
View File
@@ -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 {