* radicle-git improvements:
  publish: git-ref-format, radicle-git-ext, radicle-surf
  git-ref-format: add Refspec type
  commit: use read_header
  trailers: add Token constructor

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
This commit is contained in:
Fintan Halpenny
2023-05-05 10:12:19 +01:00
6 changed files with 48 additions and 8 deletions
+2 -2
View File
@@ -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"]
+1 -1
View File
@@ -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>",
@@ -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)
}
}
+2 -2
View File
@@ -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 {
+13
View File
@@ -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,
+2 -2
View File
@@ -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"]