Radish alpha
r
rad:z6cFWeWpnZNHh9rUW8phgA3b5yGt
Git libraries for Radicle
Radicle
Git
Merge
Fintan Halpenny committed 2 years ago
commit 30693264da48b909b54d676f101f97338396240e
parent 1501492
6 files changed +48 -8
modified 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 <alexis@radicle.xyz>",
  "Kim Altintop <kim@eagain.st>",
@@ -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"]

modified 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 <kim@eagain.st>",
  "Fintan Halpenny <fintan.halpenny@gmail.com>",
modified 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<T, U> {
+
    pub src: T,
+
    pub dst: U,
+
    pub force: bool,
+
}
+

+
impl<T, U> fmt::Display for Refspec<T, U>
+
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)
+
    }
+
}
modified 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 {
modified 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<Self, Self::Error> {
+
        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,
modified 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 <dev@radicle.xyz>"]
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"]