Skip to content
Merged
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
3 changes: 0 additions & 3 deletions gitoxide-core/src/index/information.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ mod serde_only {
}
}
}

#[derive(serde::Serialize, serde::Deserialize)]
pub struct NodeId {}
}
}

Expand Down
4 changes: 2 additions & 2 deletions gix-object/src/commit/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ pub fn commit<'a, E: ParserError<&'a [u8]> + AddContext<&'a [u8], StrContext>>(
.context(StrContext::Expected("author <signature>".into())),
(|i: &mut _| parse::header_field(i, b"committer", parse::signature))
.context(StrContext::Expected("committer <signature>".into())),
opt(|i: &mut _| parse::header_field(i, b"encoding", take_till(1.., NL)))
opt(|i: &mut _| parse::header_field(i, b"encoding", take_till(0.., NL)))
.context(StrContext::Expected("encoding <encoding>".into())),
repeat(
0..,
alt((
parse::any_header_field_multi_line.map(|(k, o)| (k.as_bstr(), Cow::Owned(o))),
|i: &mut _| {
parse::any_header_field(i, take_till(1.., NL))
parse::any_header_field(i, take_till(0.., NL))
.map(|(k, o)| (k.as_bstr(), Cow::Borrowed(o.as_bstr())))
},
)),
Expand Down
4 changes: 2 additions & 2 deletions gix-object/src/commit/ref_iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ impl<'a> CommitRefIter<'a> {
}
}
Encoding => {
let encoding = opt(|i: &mut _| parse::header_field(i, b"encoding", take_till(1.., NL)))
let encoding = opt(|i: &mut _| parse::header_field(i, b"encoding", take_till(0.., NL)))
.context(StrContext::Expected("encoding <encoding>".into()))
.parse_next(input)?;
*state = State::ExtraHeaders;
Expand All @@ -227,7 +227,7 @@ impl<'a> CommitRefIter<'a> {
let extra_header = opt(alt((
|i: &mut _| parse::any_header_field_multi_line(i).map(|(k, o)| (k.as_bstr(), Cow::Owned(o))),
|i: &mut _| {
parse::any_header_field(i, take_till(1.., NL))
parse::any_header_field(i, take_till(0.., NL))
.map(|(k, o)| (k.as_bstr(), Cow::Borrowed(o.as_bstr())))
},
)))
Expand Down
4 changes: 3 additions & 1 deletion gix-object/src/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ pub(crate) fn header_field_multi_line(name: &[u8], value: &[u8], out: &mut dyn i
let mut lines = value.as_bstr().lines_with_terminator();
out.write_all(name)?;
out.write_all(SPACE)?;
out.write_all(lines.next().ok_or(Error::EmptyValue)?)?;
if let Some(line) = lines.next() {
out.write_all(line)?;
}
for line in lines {
out.write_all(SPACE)?;
out.write_all(line)?;
Expand Down
2 changes: 1 addition & 1 deletion gix-object/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub(crate) fn any_header_field_multi_line<'a, E: ParserError<&'a [u8]> + AddCont
(
terminated(take_till(1.., SPACE_OR_NL), SPACE),
(
take_till(1.., NL),
take_till(0.., NL),
NL,
repeat(1.., terminated((SPACE, take_until(0.., NL)), NL)).map(|()| ()),
)
Expand Down
31 changes: 31 additions & 0 deletions gix-object/tests/fixtures/commit/bogus-gpgsig-lines-in-git.git.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
tree db079155794727ac821adfba2eb68b330cc0c120
parent 33a11a20eb7610771268e34211509cbbdee76b1e
author Junio C Hamano <[email protected]> 1319256362 -0700
committer Junio C Hamano <[email protected]> 1319259176 -0700
gpgsig -----BEGIN PGP SIGNATURE-----
gpgsig Version: GnuPG v1.4.10 (GNU/Linux)
gpgsig
gpgsig iQIcBAABAgAGBQJOokwoAAoJELC16IaWr+bL0WoP/2QKYkWpEyXF608m2L/cB9Qx
gpgsig /N0oBjyL1guIjPX9B3Wxq80dnLLEPnpnO39aiQIXFoJS0L6KEurqK6uDPHy3/ULa
gpgsig QsAug2HeCLsDnIFbzFSpSIMv/bP/72FDb/idMBT99xTcQj5UJEUgj7AAtx0vnKvQ
gpgsig pQIXtPu5GBUdhl3SiGgiJFRyp4r5EgV5I40GBwx/ty9cPEIN7ukJ3CR9+KC8eIGx
gpgsig Az7qngi3dhTn7g+3Z8XX5OYFDMSt9xn1gxqWXOMNlG0mxCvpFe59kwciugp26KVp
gpgsig n+yJ0UOdoxyZX8pdqXQjvklmoo7e55aaxtbHe7KSD56ebL7h7vHhkGWORU1dOp+h
gpgsig Iv5dQItkKSR8afB7FmRjo8+B/2g0wZDKRTGhzm7d1gooO5gpXvuvm4GRl5Io+IEj
gpgsig c7Li3EYmXADWUZWJtbDKDgKGKIOmWv72Qrz52iaESrhZ909HiXfn/jhHBuDRmLtQ
gpgsig /4v3T4O25uhdZ4p/PjHQn/ZroCmDyMwmnrtw/tt5fSNrl4qGcYg8Jj/1ynfF1AtS
gpgsig dM2LR65sOwXzSsqAbQjyRFYMLSWhHd/h8BcpZHDXmNBkZJVPm4zvD3ZVaAo6rtZD
gpgsig WJ9YXWXtPhuf09OgYBzcBlamTrk9ByH+NCIdrFkqfhNF1YI5dArSZytIXJhpPI1e
gpgsig TrmQAZf0BiI5J6PYN0AI
gpgsig =Qg/+
gpgsig -----END PGP SIGNATURE-----

pretty: %G[?GS] placeholders

Add new placeholders related to the GPG signature on signed commits.

- %GG to show the raw verification message from GPG;
- %G? to show either "G" for Good, "B" for Bad;
- %GS to show the name of the signer.

Signed-off-by: Junio C Hamano <[email protected]>
28 changes: 26 additions & 2 deletions gix-object/tests/object/commit/from_bytes.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use gix_actor::SignatureRef;
use gix_object::{bstr::ByteSlice, commit::message::body::TrailerRef, CommitRef};
use gix_object::{bstr::ByteSlice, commit::message::body::TrailerRef, CommitRef, WriteTo};
use smallvec::SmallVec;

use crate::{
commit::{LONG_MESSAGE, MERGE_TAG, SIGNATURE},
fixture_name, linus_signature, signature,
fixture_name, hex_to_id, linus_signature, signature,
};

#[test]
Expand Down Expand Up @@ -342,3 +342,27 @@ fn newline_right_after_signature_multiline_header() -> crate::Result {
assert!(commit.message.starts_with(b"Rollup"));
Ok(())
}

#[test]
fn bogus_multi_gpgsig_header() -> crate::Result {
let fixture = fixture_name("commit", "bogus-gpgsig-lines-in-git.git.txt");
let commit = CommitRef::from_bytes(&fixture)?;
let pgp_sig = b"-----BEGIN PGP SIGNATURE-----".as_bstr();
assert_eq!(commit.extra_headers().pgp_signature(), Some(pgp_sig));
assert_eq!(
commit.extra_headers().find_all("gpgsig").count(),
17,
"Each signature header line is prefixed with `gpgsig` here, so we parse it as extra header"
);
assert!(commit.message.starts_with(b"pretty: %G[?GS] placeholders"));

let mut buf = Vec::<u8>::new();
commit.write_to(&mut buf)?;
let actual = gix_object::compute_hash(gix_hash::Kind::Sha1, gix_object::Kind::Commit, &buf)?;
assert_eq!(
actual,
hex_to_id("5f549aa2f78314ac37bbd436c8f80aea4c752e07"),
"round-tripping works despite the strangeness"
);
Ok(())
}
Loading