diff --git a/radicle-git-ext/Cargo.toml b/radicle-git-ext/Cargo.toml index 1b61c35..93ff388 100644 --- a/radicle-git-ext/Cargo.toml +++ b/radicle-git-ext/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "radicle-git-ext" -version = "0.4.1" +version = "0.4.2" authors = [ "Alexis Sellier ", "Kim Altintop ", @@ -26,7 +26,7 @@ default-features = false features = ["vendored-libgit2"] [dependencies.git-ref-format] -version = "0.2.1" +version = "0.2.2" path = "./git-ref-format" features = ["macro", "serde", "minicbor"] diff --git a/radicle-git-ext/git-ref-format/Cargo.toml b/radicle-git-ext/git-ref-format/Cargo.toml index ba4d568..18421fe 100644 --- a/radicle-git-ext/git-ref-format/Cargo.toml +++ b/radicle-git-ext/git-ref-format/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "git-ref-format" -version = "0.2.1" +version = "0.2.2" authors = [ "Kim Altintop ", "Fintan Halpenny ", diff --git a/radicle-git-ext/git-ref-format/core/src/refspec.rs b/radicle-git-ext/git-ref-format/core/src/refspec.rs index 2b1d018..0e1967e 100644 --- a/radicle-git-ext/git-ref-format/core/src/refspec.rs +++ b/radicle-git-ext/git-ref-format/core/src/refspec.rs @@ -6,7 +6,7 @@ use std::{ borrow::{Borrow, Cow}, convert::TryFrom, - fmt::{self, Display}, + fmt::{self, Display, Write as _}, iter::FromIterator, ops::Deref, }; @@ -558,3 +558,30 @@ impl Display for NamespacedPattern<'_> { self.0.fmt(f) } } + +/// A Git [refspec]. +/// +/// **Note** that this is a simplified version of a [refspec] where +/// the `src` and `dst` are required and there is no way to construct +/// a negative refspec, e.g. `^refs/heads/no-thanks`. +/// +/// [refspec]: https://git-scm.com/book/en/v2/Git-Internals-The-Refspec +#[derive(Clone, Debug, PartialEq, Eq)] +pub struct Refspec { + pub src: T, + pub dst: U, + pub force: bool, +} + +impl fmt::Display for Refspec +where + T: fmt::Display, + U: fmt::Display, +{ + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + if self.force { + f.write_char('+')?; + } + write!(f, "{}:{}", self.src, self.dst) + } +} diff --git a/radicle-git-ext/src/commit.rs b/radicle-git-ext/src/commit.rs index dbd51c9..9eaf772 100644 --- a/radicle-git-ext/src/commit.rs +++ b/radicle-git-ext/src/commit.rs @@ -149,8 +149,8 @@ impl Commit { fn verify_object(odb: &git2::Odb, oid: &Oid, expected: ObjectType) -> Result<(), error::Write> { use git2::{Error, ErrorClass, ErrorCode}; - let (_, _, kind) = odb - .reader(*oid) + let (_, kind) = odb + .read_header(*oid) .map_err(|err| error::Write::OdbRead { oid: *oid, err })?; if kind != expected { Err(error::Write::NotCommit { diff --git a/radicle-git-ext/src/commit/trailers.rs b/radicle-git-ext/src/commit/trailers.rs index 7265d81..00b4c42 100644 --- a/radicle-git-ext/src/commit/trailers.rs +++ b/radicle-git-ext/src/commit/trailers.rs @@ -130,6 +130,19 @@ impl Deref for Token<'_> { } } +impl<'a> TryFrom<&'a str> for Token<'a> { + type Error = &'static str; + + fn try_from(s: &'a str) -> Result { + let is_token = s.chars().all(|c| c.is_alphanumeric() || c == '-'); + if is_token { + Ok(Token(s)) + } else { + Err("token contains invalid characters") + } + } +} + pub struct Display<'a> { trailer: &'a Trailer<'a>, separator: &'a str, diff --git a/radicle-surf/Cargo.toml b/radicle-surf/Cargo.toml index e4c824e..1cb97b7 100644 --- a/radicle-surf/Cargo.toml +++ b/radicle-surf/Cargo.toml @@ -2,7 +2,7 @@ name = "radicle-surf" description = "A code surfing library for Git repositories" readme = "README.md" -version = "0.10.1" +version = "0.10.2" authors = ["The Radicle Team "] edition = "2021" homepage = "https://github.com/radicle-dev/radicle-surf" @@ -38,7 +38,7 @@ default-features = false features = ["vendored-libgit2"] [dependencies.radicle-git-ext] -version = "0.4.1" +version = "0.4.2" path = "../radicle-git-ext" features = ["serde"]