From 8745e467453bb26dc15e904ffd4b4897fda52895 Mon Sep 17 00:00:00 2001 From: Fintan Halpenny Date: Tue, 1 Nov 2022 16:30:03 +0000 Subject: [PATCH] git-commit: introduce git-commit crate Porting the commit code that is found in heartwood[0]. It represents a parsed git commit object -- sans the id for the commit itself. [0]: https://github.com/radicle-dev/heartwood/blob/16b22d9178fa6a1aaf2ecb01ec97e067399c5286/radicle/src/git.rs#L392-L575 Signed-off-by: Fintan Halpenny X-Clacks-Overhead: GNU Terry Pratchett --- Cargo.toml | 1 + git-commit/Cargo.toml | 18 +++ git-commit/src/author.rs | 119 +++++++++++++++ git-commit/src/headers.rs | 71 +++++++++ git-commit/src/lib.rs | 260 ++++++++++++++++++++++++++++++++ git-commit/t/Cargo.toml | 26 ++++ git-commit/t/src/commit.rs | 107 +++++++++++++ git-commit/t/src/integration.rs | 28 ++++ git-commit/t/src/lib.rs | 5 + test/Cargo.toml | 4 + 10 files changed, 639 insertions(+) create mode 100644 git-commit/Cargo.toml create mode 100644 git-commit/src/author.rs create mode 100644 git-commit/src/headers.rs create mode 100644 git-commit/src/lib.rs create mode 100644 git-commit/t/Cargo.toml create mode 100644 git-commit/t/src/commit.rs create mode 100644 git-commit/t/src/integration.rs create mode 100644 git-commit/t/src/lib.rs diff --git a/Cargo.toml b/Cargo.toml index 5716e55..0ca20c1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,7 @@ [workspace] members = [ "git-ref-format", + "git-commit", "git-storage", "git-trailers", "link-git", diff --git a/git-commit/Cargo.toml b/git-commit/Cargo.toml new file mode 100644 index 0000000..ae4d0ac --- /dev/null +++ b/git-commit/Cargo.toml @@ -0,0 +1,18 @@ +[package] +name = "git-commit" +version = "0.1.0" +license = "MIT OR Apache-2.0" +edition = "2021" +authors = [ + "Alexis Sellier ", + "Fintan Halpenny ", +] +keywords = ["git", "radicle"] + +[dependencies] +thiserror = "1" + +[dependencies.git2] +version = "0.15.0" +default-features = false +features = ["vendored-libgit2"] diff --git a/git-commit/src/author.rs b/git-commit/src/author.rs new file mode 100644 index 0000000..f7fb711 --- /dev/null +++ b/git-commit/src/author.rs @@ -0,0 +1,119 @@ +use std::{ + fmt, + num::ParseIntError, + str::{self, FromStr}, +}; + +use thiserror::Error; + +/// The data for indicating authorship of an action within a +/// [`super::Commit`]. +#[derive(Clone, Debug, PartialEq, Eq, Hash)] +pub struct Author { + /// Name corresponding to `user.name` in the git config. + /// + /// Note: this must not contain `<` or `>`. + pub name: String, + /// Email corresponding to `user.email` in the git config. + /// + /// Note: this must not contain `<` or `>`. + pub email: String, + /// The time of this author's action. + pub time: Time, +} + +/// The time of a [`Author`]'s action. +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] +pub struct Time { + seconds: i64, + offset: i32, +} + +impl Time { + pub fn new(seconds: i64, offset: i32) -> Self { + Self { seconds, offset } + } +} + +impl From