Skip to content

Commit 2aab086

Browse files
committed
adapt to changes in gix-actor
1 parent 54a3fa1 commit 2aab086

6 files changed

Lines changed: 44 additions & 15 deletions

File tree

gitoxide-core/src/hours/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@ impl ParsedIdentity<'_> {
7171

7272
fn parse_trailer_identity(trailer: gix::objs::commit::message::body::TrailerRef<'_>) -> Option<ParsedIdentity<'_>> {
7373
match trailer.value {
74-
std::borrow::Cow::Borrowed(value) => IdentityRef::from_bytes::<gix::objs::decode::ParseError>(value.as_ref())
74+
std::borrow::Cow::Borrowed(value) => IdentityRef::from_bytes(value.as_ref())
7575
.ok()
7676
.map(|identity| ParsedIdentity::Borrowed(identity.trim())),
77-
std::borrow::Cow::Owned(value) => IdentityRef::from_bytes::<gix::objs::decode::ParseError>(value.as_ref())
77+
std::borrow::Cow::Owned(value) => IdentityRef::from_bytes(value.as_ref())
7878
.ok()
7979
.map(|identity| ParsedIdentity::Owned(identity.trim().to_owned())),
8080
}

gitoxide-core/src/repository/mailmap.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ pub fn check(
7171

7272
let mut buf = Vec::new();
7373
for contact in contacts {
74-
let actor = match gix::actor::IdentityRef::from_bytes::<()>(&contact) {
74+
let actor = match gix::actor::IdentityRef::from_bytes(&contact) {
7575
Ok(a) => a,
7676
Err(_) => {
7777
let Some(email) = contact

gix-mailmap/fuzz/fuzz_targets/mailmap.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ fn resolve(snapshot: &Snapshot, input: &[u8]) {
2727
b"Jane <jane@desktop.(none)> 1 +0000".as_slice(),
2828
b"Unknown <[email protected]> 1 +0000".as_slice(),
2929
] {
30-
let Ok(signature) = SignatureRef::from_bytes::<()>(candidate) else {
30+
let Ok(signature) = SignatureRef::from_bytes(candidate) else {
3131
continue;
3232
};
3333
_ = black_box(snapshot.try_resolve_ref(signature));

gix-mailmap/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
//!
1919
//! let snapshot = gix_mailmap::Snapshot::new(parsed);
2020
//! let resolved = snapshot.resolve(
21-
//! SignatureRef::from_bytes::<()>(b"Jane <[email protected]> 1711398853 +0800").unwrap(),
21+
//! SignatureRef::from_bytes(b"Jane <[email protected]> 1711398853 +0800").unwrap(),
2222
//! );
2323
//!
2424
//! assert_eq!(resolved.name, "Jane Doe");

gix-object/src/parse.rs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
use bstr::{BStr, BString, ByteVec};
22
use winnow::{
33
combinator::{preceded, repeat, terminated},
4-
error::{AddContext, ParserError, StrContext},
4+
error::{AddContext, ErrMode, ParserError, StrContext},
55
prelude::*,
6+
stream::Stream,
67
token::{take_till, take_until, take_while},
78
};
89

@@ -70,20 +71,30 @@ pub fn hex_hash<'a, E: ParserError<&'a [u8]>>(i: &mut &'a [u8]) -> ModalResult<&
7071
pub(crate) fn signature<'a, E: ParserError<&'a [u8]> + AddContext<&'a [u8], StrContext>>(
7172
i: &mut &'a [u8],
7273
) -> ModalResult<gix_actor::SignatureRef<'a>, E> {
74+
let start = i.checkpoint();
7375
gix_actor::signature::decode(i)
76+
.map_err(|err| ErrMode::Cut(E::from_input(i).add_context(i, &start, StrContext::Label(actor_error_label(err)))))
7477
}
7578

7679
pub(crate) fn signature_and_consumed<'a, E: ParserError<&'a [u8]> + AddContext<&'a [u8], StrContext>>(
7780
i: &mut &'a [u8],
7881
) -> ModalResult<(gix_actor::SignatureRef<'a>, &'a BStr), E> {
7982
let original = *i;
80-
gix_actor::signature::decode(i).map(|signature| {
81-
let consumed = original.len() - i.len();
82-
(signature, original[..consumed].as_bstr())
83-
})
83+
let signature = signature(i)?;
84+
let consumed = original.len() - i.len();
85+
Ok((signature, original[..consumed].as_bstr()))
8486
}
8587

8688
pub(crate) fn parse_signature(raw: &BStr) -> Result<gix_actor::SignatureRef<'_>, crate::decode::Error> {
87-
gix_actor::SignatureRef::from_bytes::<crate::decode::ParseError>(raw.as_ref())
88-
.map_err(|err| crate::decode::Error::with_err(err, raw.as_ref()))
89+
let input = raw.as_ref();
90+
let mut raw = input;
91+
signature::<crate::decode::ParseError>(&mut raw).map_err(|err| crate::decode::Error::with_err(err, input))
92+
}
93+
94+
fn actor_error_label(err: gix_actor::decode::Error) -> &'static str {
95+
match err {
96+
gix_actor::decode::Error::MissingClosingBracket => "Closing '>' not found",
97+
gix_actor::decode::Error::MissingOpeningBracket => "Opening '<' not found",
98+
gix_actor::decode::Error::DelimiterOverlap => "Skipped parts run into each other",
99+
}
89100
}

gix-ref/src/store/file/log/line.rs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,9 @@ pub mod decode {
7676
use gix_object::bstr::{BStr, ByteSlice};
7777
use winnow::{
7878
combinator::{alt, eof, fail, opt, preceded, terminated},
79-
error::{AddContext, ParserError, StrContext},
79+
error::{AddContext, ErrMode, ParserError, StrContext},
8080
prelude::*,
81+
stream::Stream,
8182
token::{rest, take_while},
8283
};
8384

@@ -140,7 +141,7 @@ pub mod decode {
140141
let (old, new, signature) = (
141142
terminated(hex_hash, b" ").context(StrContext::Expected("<old-hexsha>".into())),
142143
terminated(hex_hash, b" ").context(StrContext::Expected("<new-hexsha>".into())),
143-
gix_actor::signature::decode.context(StrContext::Expected("<name> <<email>> <timestamp>".into())),
144+
signature.context(StrContext::Expected("<name> <<email>> <timestamp>".into())),
144145
)
145146
.context(StrContext::Expected(
146147
r"<old-hexsha> <new-hexsha> <name> <<email>> <timestamp> <tz>\t<message>".into(),
@@ -161,7 +162,7 @@ pub mod decode {
161162
(
162163
terminated(hex_hash, b" ").context(StrContext::Expected("<old-hexsha>".into())),
163164
terminated(hex_hash, b" ").context(StrContext::Expected("<new-hexsha>".into())),
164-
gix_actor::signature::decode.context(StrContext::Expected("<name> <<email>> <timestamp>".into())),
165+
signature.context(StrContext::Expected("<name> <<email>> <timestamp>".into())),
165166
)
166167
.context(StrContext::Expected(
167168
r"<old-hexsha> <new-hexsha> <name> <<email>> <timestamp> <tz>\t<message>".into(),
@@ -188,6 +189,23 @@ pub mod decode {
188189
}
189190
}
190191

192+
fn signature<'a, E: ParserError<&'a [u8]> + AddContext<&'a [u8], StrContext>>(
193+
i: &mut &'a [u8],
194+
) -> ModalResult<gix_actor::SignatureRef<'a>, E> {
195+
let start = i.checkpoint();
196+
gix_actor::signature::decode(i).map_err(|err| {
197+
ErrMode::Cut(E::from_input(i).add_context(i, &start, StrContext::Label(actor_error_label(err))))
198+
})
199+
}
200+
201+
fn actor_error_label(err: gix_actor::decode::Error) -> &'static str {
202+
match err {
203+
gix_actor::decode::Error::MissingClosingBracket => "Closing '>' not found",
204+
gix_actor::decode::Error::MissingOpeningBracket => "Opening '<' not found",
205+
gix_actor::decode::Error::DelimiterOverlap => "Skipped parts run into each other",
206+
}
207+
}
208+
191209
#[cfg(test)]
192210
mod test {
193211
use super::*;

0 commit comments

Comments
 (0)