mirror of
https://seed.radicle.dev/rad:z6cFWeWpnZNHh9rUW8phgA3b5yGt.git
synced 2026-11-29 22:20:27 +08:00
radicle-surf: rework to use git-ref-format
The aim of this commit is to better represent the reference names using git-ref-format. The first places to change were the Branch and Tag types. For Branch, the previous types were simply wrappers around the names. They stay this way, using RefString instead. For Tag, the `name` field is replaced with RefString. Note: The parsing logic becomes easier here by utilising the Namespaced and Qualified types. The consequences of these changes meant that areas that used BranchName or TagName are changed to use RefString. Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com> X-Clacks-Overhead: GNU Terry Pratchett
This commit is contained in:
+29
-9
@@ -67,6 +67,7 @@ use std::str::FromStr;
|
||||
|
||||
// Re-export git2 as sub-module
|
||||
pub use git2::{self, Error as Git2Error, Time};
|
||||
use git_ref_format::{name::Components, Component, Qualified, RefString};
|
||||
pub use radicle_git_ext::Oid;
|
||||
|
||||
mod repo;
|
||||
@@ -81,15 +82,13 @@ pub use history::History;
|
||||
pub mod error;
|
||||
pub use error::Error;
|
||||
|
||||
pub mod ext;
|
||||
|
||||
/// Provides the data for talking about branches.
|
||||
pub mod branch;
|
||||
pub use branch::{Branch, BranchName, BranchType};
|
||||
pub use branch::{Branch, Local, Remote};
|
||||
|
||||
/// Provides the data for talking about tags.
|
||||
pub mod tag;
|
||||
pub use tag::{Tag, TagName};
|
||||
pub use tag::Tag;
|
||||
|
||||
/// Provides the data for talking about commits.
|
||||
pub mod commit;
|
||||
@@ -121,6 +120,30 @@ pub trait Revision {
|
||||
fn object_id(&self, repo: &RepositoryRef) -> Result<Oid, Error>;
|
||||
}
|
||||
|
||||
impl Revision for RefString {
|
||||
fn object_id(&self, repo: &RepositoryRef) -> Result<Oid, Error> {
|
||||
repo.refname_to_oid(self.as_str())
|
||||
}
|
||||
}
|
||||
|
||||
impl Revision for &RefString {
|
||||
fn object_id(&self, repo: &RepositoryRef) -> Result<Oid, Error> {
|
||||
repo.refname_to_oid(self.as_str())
|
||||
}
|
||||
}
|
||||
|
||||
impl Revision for Qualified<'_> {
|
||||
fn object_id(&self, repo: &RepositoryRef) -> Result<Oid, Error> {
|
||||
repo.refname_to_oid(self.as_str())
|
||||
}
|
||||
}
|
||||
|
||||
impl Revision for &Qualified<'_> {
|
||||
fn object_id(&self, repo: &RepositoryRef) -> Result<Oid, Error> {
|
||||
repo.refname_to_oid(self.as_str())
|
||||
}
|
||||
}
|
||||
|
||||
impl Revision for Oid {
|
||||
fn object_id(&self, _repo: &RepositoryRef) -> Result<Oid, Error> {
|
||||
Ok(*self)
|
||||
@@ -147,9 +170,6 @@ impl Revision for &Tag {
|
||||
}
|
||||
}
|
||||
|
||||
impl Revision for &TagName {
|
||||
fn object_id(&self, repo: &RepositoryRef) -> Result<Oid, Error> {
|
||||
let refname = repo.namespaced_refname(&self.refname())?;
|
||||
Ok(repo.repo_ref.refname_to_id(&refname).map(Oid::from)?)
|
||||
}
|
||||
pub(crate) fn refstr_join<'a>(c: Component<'a>, cs: Components<'a>) -> RefString {
|
||||
std::iter::once(c).chain(cs).collect::<RefString>()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user