Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 7 additions & 6 deletions gitoxide-core/src/hours/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ impl ParsedIdentity<'_> {

fn parse_trailer_identity(trailer: gix::objs::commit::message::body::TrailerRef<'_>) -> Option<ParsedIdentity<'_>> {
match trailer.value {
std::borrow::Cow::Borrowed(value) => IdentityRef::from_bytes::<gix::objs::decode::ParseError>(value.as_ref())
std::borrow::Cow::Borrowed(value) => IdentityRef::from_bytes(value.as_ref())
.ok()
.map(|identity| ParsedIdentity::Borrowed(identity.trim())),
std::borrow::Cow::Owned(value) => IdentityRef::from_bytes::<gix::objs::decode::ParseError>(value.as_ref())
std::borrow::Cow::Owned(value) => IdentityRef::from_bytes(value.as_ref())
.ok()
.map(|identity| ParsedIdentity::Owned(identity.trim().to_owned())),
}
Expand All @@ -83,8 +83,9 @@ fn parse_trailer_identity(trailer: gix::objs::commit::message::body::TrailerRef<
/// Return `(commit_author, [commit_author, co_authors...])`. Use the `commit_author` for easy access to the commit author itself.
fn commit_author_identities(
commit_data: &[u8],
hash_kind: gix::hash::Kind,
) -> Result<(gix::actor::SignatureRef<'_>, SmallVec<[ParsedIdentity<'_>; 2]>), gix::objs::decode::Error> {
let commit = gix::objs::CommitRef::from_bytes(commit_data)?;
let commit = gix::objs::CommitRef::from_bytes(commit_data, hash_kind)?;
let author = commit.author()?.trim();
let mut authors = smallvec![ParsedIdentity::Borrowed(gix::actor::IdentityRef::from(author))];
authors.extend(commit.co_authored_by_trailers().filter_map(parse_trailer_identity));
Expand Down Expand Up @@ -130,7 +131,7 @@ where
let extract_signatures = scope.spawn(move || -> anyhow::Result<Vec<_>> {
let mut out = Vec::new();
for (commit_idx, commit_data) in rx {
if let Ok((commit_author, authors)) = commit_author_identities(&commit_data) {
if let Ok((commit_author, authors)) = commit_author_identities(&commit_data, commit_id.kind()) {
let mut string_ref = |s: &[u8]| -> &'static BStr {
match string_heap.get(s) {
Some(n) => n.as_bstr(),
Expand Down Expand Up @@ -445,7 +446,7 @@ body\n\
\n\
Co-authored-by: Second Author <second@example.com>\n\
Co-authored-by: Third Author <third@example.com>\n";
let (author, authors) = commit_author_identities(commit).expect("valid commit");
let (author, authors) = commit_author_identities(commit, gix::hash::Kind::Sha1).expect("valid commit");
assert_eq!(author.time, "1710000000 +0000");
assert_eq!(
authors
Expand Down Expand Up @@ -478,7 +479,7 @@ committer Main Author <main@example.com> 1710000000 +0000\n\
subject\n\
\n\
Co-authored-by: not a signature\n";
let (_, authors) = commit_author_identities(commit).expect("valid commit");
let (_, authors) = commit_author_identities(commit, gix::hash::Kind::Sha1).expect("valid commit");
assert_eq!(authors.len(), 1);
assert_eq!(authors[0].name(), "Main Author".as_bytes().as_bstr());
assert_eq!(authors[0].email(), "main@example.com".as_bytes().as_bstr());
Expand Down
2 changes: 1 addition & 1 deletion gitoxide-core/src/query/engine/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ pub fn update(
self.progress.inc();
if self.known_commits.binary_search(&id.to_owned()).is_err() {
let res = {
let mut parents = gix::objs::CommitRefIter::from_bytes(obj.data).parent_ids();
let mut parents = gix::objs::CommitRefIter::from_bytes(obj.data, obj.hash_kind).parent_ids();
let res = parents.next().map(|first_parent| (Some(first_parent), id.to_owned()));
match parents.next() {
Some(_) => None,
Expand Down
2 changes: 1 addition & 1 deletion gitoxide-core/src/repository/mailmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ pub fn check(

let mut buf = Vec::new();
for contact in contacts {
let actor = match gix::actor::IdentityRef::from_bytes::<()>(&contact) {
let actor = match gix::actor::IdentityRef::from_bytes(&contact) {
Ok(a) => a,
Err(_) => {
let Some(email) = contact
Expand Down
1 change: 0 additions & 1 deletion gix-actor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ bstr = { version = "1.12.0", default-features = false, features = [
"std",
"unicode",
] }
winnow = { version = "1.0.0", features = ["simd"] }
serde = { version = "1.0.114", optional = true, default-features = false, features = [
"derive",
] }
Expand Down
6 changes: 3 additions & 3 deletions gix-actor/fuzz/fuzz_targets/actors.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![no_main]

use gix_actor::{IdentityRef, Signature, SignatureRef};
use gix_actor::{IdentityRef, SignatureRef};
use libfuzzer_sys::fuzz_target;
use std::hint::black_box;

Expand All @@ -24,10 +24,10 @@ fn inspect_signature(signature: SignatureRef<'_>) {
}

fuzz_target!(|input: &[u8]| {
if let Ok(identity) = IdentityRef::from_bytes::<()>(input) {
if let Ok(identity) = IdentityRef::from_bytes(input) {
inspect_identity(identity);
}
if let Ok(signature) = SignatureRef::from_bytes::<()>(input) {
if let Ok(signature) = SignatureRef::from_bytes(input) {
inspect_signature(signature);
}
});
18 changes: 12 additions & 6 deletions gix-actor/src/identity.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
use bstr::ByteSlice;
use winnow::{error::StrContext, prelude::*};

use crate::{signature::decode, Identity, IdentityRef};

impl<'a> IdentityRef<'a> {
/// Deserialize an identity from the given `data`.
pub fn from_bytes<E>(mut data: &'a [u8]) -> Result<Self, winnow::error::ErrMode<E>>
where
E: winnow::error::ParserError<&'a [u8]> + winnow::error::AddContext<&'a [u8], StrContext>,
{
decode::identity.parse_next(&mut data)
///
/// Typical input is `Name <name@example.com> 1700000000 +0000`.
pub fn from_bytes(mut data: &'a [u8]) -> Result<Self, gix_error::ValidationError> {
Self::from_bytes_consuming(&mut data)
}

/// Deserialize an identity from the given `data` and advance it past the identity.
///
/// Typical input is `Name <name@example.com> 1700000000 +0000`; on success,
/// `data` points to the bytes immediately after the closing `>`.
pub fn from_bytes_consuming(data: &mut &'a [u8]) -> Result<Self, gix_error::ValidationError> {
decode::identity(data)
}

/// Create an owned instance from this shared one.
Expand Down
4 changes: 2 additions & 2 deletions gix-actor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
//! ```
//! use gix_actor::{IdentityRef, SignatureRef};
//!
//! let actor = IdentityRef::from_bytes::<()>(b" Taylor Example < taylor@example.com >")
//! let actor = IdentityRef::from_bytes(b" Taylor Example < taylor@example.com >")
//! .unwrap()
//! .trim();
//! assert_eq!(actor.name, "Taylor Example");
//! assert_eq!(actor.email, "taylor@example.com");
//!
//! let signature = SignatureRef::from_bytes::<()>(b"Taylor Example <taylor@example.com> 1711398853 +0800")
//! let signature = SignatureRef::from_bytes(b"Taylor Example <taylor@example.com> 1711398853 +0800")
//! .unwrap()
//! .trim();
//! assert_eq!(signature.actor(), actor);
Expand Down
Loading
Loading