From 956bf070d45538e3b68a2b39dc88c173341d2bad Mon Sep 17 00:00:00 2001 From: Fintan Halpenny Date: Thu, 4 May 2023 11:54:21 +0100 Subject: [PATCH 1/4] trailers: add Token constructor During the reorganisation of the codebase, the constructors for Token were removed. Add back a constructor via the `TryFrom<&'a str>` trait. Signed-off-by: Fintan Halpenny X-Clacks-Overhead: GNU Terry Pratchett --- radicle-git-ext/src/commit/trailers.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) 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, From 24e27f6e879899f83bd21fa78b916726ad1bfa46 Mon Sep 17 00:00:00 2001 From: Fintan Halpenny Date: Thu, 4 May 2023 17:27:47 +0100 Subject: [PATCH 2/4] commit: use read_header MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The `Odb::reader` method states: Note that most backends do not support streaming reads because they store their objects as compressed/delta’ed blobs. If the backend does not support streaming reads, use the read method instead. This can lead to objects not being found when verifying for commits. Instead use `read_header` to determine the `ObjectType` of the `Oid`. Signed-off-by: Fintan Halpenny X-Clacks-Overhead: GNU Terry Pratchett --- radicle-git-ext/src/commit.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 { From 64fef2f0ad67b14353ee75e1d0099b48da5aac52 Mon Sep 17 00:00:00 2001 From: Fintan Halpenny Date: Fri, 5 May 2023 09:50:53 +0100 Subject: [PATCH 3/4] git-ref-format: add Refspec type Add a Refspec type that represents a `[+]:` refspec[[0]]. [0]: https://git-scm.com/book/en/v2/Git-Internals-The-Refspec Signed-off-by: Fintan Halpenny X-Clacks-Overhead: GNU Terry Pratchett --- .../git-ref-format/core/src/refspec.rs | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) 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) + } +} From fc6a4fcac5c302892311c7bb5e82d5fa6d08ce2a Mon Sep 17 00:00:00 2001 From: Fintan Halpenny Date: Fri, 5 May 2023 10:11:13 +0100 Subject: [PATCH 4/4] publish: git-ref-format, radicle-git-ext, radicle-surf Publish git-ref-format, radicle-git-ext, and radicle-surf with several additions and bug fixes. Signed-off-by: Fintan Halpenny X-Clacks-Overhead: GNU Terry Pratchett --- radicle-git-ext/Cargo.toml | 4 ++-- radicle-git-ext/git-ref-format/Cargo.toml | 2 +- radicle-surf/Cargo.toml | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) 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-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"]