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:
Fintan Halpenny
2022-11-18 10:18:11 +00:00
parent c6c8fe3164
commit 9b5ea4352f
18 changed files with 708 additions and 600 deletions
+5 -10
View File
@@ -17,6 +17,7 @@
//! Represents a commit.
use git_ref_format::RefString;
#[cfg(feature = "serialize")]
use serde::{
ser::{SerializeStruct as _, Serializer},
@@ -26,7 +27,7 @@ use serde::{
use crate::{
diff,
file_system,
git::{self, BranchName, Glob, RepositoryRef},
git::{self, Glob, RepositoryRef},
person::Person,
revision::Revision,
};
@@ -54,7 +55,7 @@ pub struct Commit {
/// The changeset introduced by this commit.
pub diff: diff::Diff,
/// The list of branches this commit belongs to.
pub branches: Vec<BranchName>,
pub branches: Vec<RefString>,
}
/// Representation of a code commit.
@@ -195,7 +196,7 @@ pub fn commit<R: git::Revision>(repo: &RepositoryRef, rev: R) -> Result<Commit,
let branches = repo
.revision_branches(&sha1, &Glob::heads("*")?.and_remotes("*")?)?
.into_iter()
.map(|b| b.name)
.map(|b| b.refname().into())
.collect();
Ok(Commit {
@@ -226,13 +227,7 @@ pub fn header(repo: &RepositoryRef, sha1: Oid) -> Result<Header, Error> {
///
/// Will return [`Error`] if the project doesn't exist or the surf interaction
/// fails.
pub fn commits<P>(
repo: &RepositoryRef,
maybe_revision: Option<Revision<P>>,
) -> Result<Commits, Error>
where
P: ToString,
{
pub fn commits(repo: &RepositoryRef, maybe_revision: Option<Revision>) -> Result<Commits, Error> {
let rev = match maybe_revision {
Some(revision) => revision,
None => Revision::Sha {