1
1
mirror of https://github.com/Byron/gitoxide synced 2025-10-06 01:52:40 +02:00

adapt to changes in gix-date and gix-actor

This commit is contained in:
Sebastian Thiel
2025-04-25 13:41:31 +02:00
parent 57366d3ebd
commit afdf1a5d5c
37 changed files with 168 additions and 211 deletions

2
Cargo.lock generated
View File

@@ -1332,7 +1332,6 @@ dependencies = [
"futures-lite", "futures-lite",
"gitoxide-core", "gitoxide-core",
"gix", "gix",
"gix-date 0.9.4",
"gix-features 0.42.0", "gix-features 0.42.0",
"is-terminal", "is-terminal",
"once_cell", "once_cell",
@@ -1361,7 +1360,6 @@ dependencies = [
"futures-lite", "futures-lite",
"gix", "gix",
"gix-archive", "gix-archive",
"gix-date 0.9.4",
"gix-fsck", "gix-fsck",
"gix-pack", "gix-pack",
"gix-status", "gix-status",

View File

@@ -152,7 +152,6 @@ gitoxide-core-async-client = ["gitoxide-core/async-client", "futures-lite"]
anyhow = "1.0.98" anyhow = "1.0.98"
gitoxide-core = { version = "^0.46.0", path = "gitoxide-core" } gitoxide-core = { version = "^0.46.0", path = "gitoxide-core" }
gix-date= { version = "^0.9.4", path = "gix-date" }
gix-features = { version = "^0.42.0", path = "gix-features" } gix-features = { version = "^0.42.0", path = "gix-features" }
gix = { version = "^0.71.0", path = "gix", default-features = false } gix = { version = "^0.71.0", path = "gix", default-features = false }

View File

@@ -150,7 +150,7 @@ fn run(args: Args) -> anyhow::Result<()> {
commit_ref.author.actor().write_to(&mut buf)?; commit_ref.author.actor().write_to(&mut buf)?;
buf.into() buf.into()
}, },
time: gix_date::Time::from_bytes(commit_ref.author.time)?.format(format::DEFAULT), time: commit_ref.author.time()?.format(format::DEFAULT),
message: commit_ref.message.to_owned(), message: commit_ref.message.to_owned(),
}) })
}), }),

View File

@@ -50,7 +50,6 @@ serde = ["gix/serde", "dep:serde_json", "dep:serde", "bytesize/serde"]
[dependencies] [dependencies]
# deselect everything else (like "performance") as this should be controllable by the parent application. # deselect everything else (like "performance") as this should be controllable by the parent application.
gix = { version = "^0.71.0", path = "../gix", default-features = false, features = ["merge", "blob-diff", "blame", "revision", "mailmap", "excludes", "attributes", "worktree-mutation", "credentials", "interrupt", "status", "dirwalk"] } gix = { version = "^0.71.0", path = "../gix", default-features = false, features = ["merge", "blob-diff", "blame", "revision", "mailmap", "excludes", "attributes", "worktree-mutation", "credentials", "interrupt", "status", "dirwalk"] }
gix-date = { version = "^0.9.4", path = "../gix-date" }
gix-pack-for-configuration-only = { package = "gix-pack", version = "^0.58.0", path = "../gix-pack", default-features = false, features = ["pack-cache-lru-dynamic", "pack-cache-lru-static", "generate", "streaming-input"] } gix-pack-for-configuration-only = { package = "gix-pack", version = "^0.58.0", path = "../gix-pack", default-features = false, features = ["pack-cache-lru-dynamic", "pack-cache-lru-static", "generate", "streaming-input"] }
gix-transport-configuration-only = { package = "gix-transport", version = "^0.46.0", path = "../gix-transport", default-features = false } gix-transport-configuration-only = { package = "gix-transport", version = "^0.46.0", path = "../gix-transport", default-features = false }
gix-archive-for-configuration-only = { package = "gix-archive", version = "^0.20.0", path = "../gix-archive", optional = true, features = ["tar", "tar_gz"] } gix-archive-for-configuration-only = { package = "gix-archive", version = "^0.20.0", path = "../gix-archive", optional = true, features = ["tar", "tar_gz"] }

View File

@@ -29,11 +29,11 @@ pub struct Context<W> {
pub struct SignatureRef<'a> { pub struct SignatureRef<'a> {
name: &'a BStr, name: &'a BStr,
email: &'a BStr, email: &'a BStr,
time: gix_date::Time, time: gix::date::Time,
} }
impl SignatureRef<'_> { impl SignatureRef<'_> {
fn seconds(&self) -> gix_date::SecondsSinceUnixEpoch { fn seconds(&self) -> gix::date::SecondsSinceUnixEpoch {
self.time.seconds self.time.seconds
} }
} }

View File

@@ -76,9 +76,7 @@ impl query::Engine {
usize, usize,
) = row?; ) = row?;
let id = gix::ObjectId::from(hash); let id = gix::ObjectId::from(hash);
let commit_time = gix_date::Time::from_bytes( let commit_time = id.attach(&self.repo).object()?.into_commit().committer()?.time()?;
id.attach(&self.repo).object()?.into_commit().committer()?.time,
)?;
let mode = FileMode::from_usize(mode).context("invalid file mode")?; let mode = FileMode::from_usize(mode).context("invalid file mode")?;
info.push(trace_path::Info { info.push(trace_path::Info {
id, id,

View File

@@ -65,10 +65,7 @@ fn round_trip() -> Result<(), Box<dyn std::error::Error>> {
]; ];
for input in DEFAULTS { for input in DEFAULTS {
let signature: Signature = gix_actor::SignatureRef::from_bytes::<()>(input) let signature: Signature = gix_actor::SignatureRef::from_bytes::<()>(input).unwrap().into();
.unwrap()
.try_into()
.unwrap();
let mut output = Vec::new(); let mut output = Vec::new();
signature.write_to(&mut output)?; signature.write_to(&mut output)?;
assert_eq!(output.as_bstr(), input.as_bstr()); assert_eq!(output.as_bstr(), input.as_bstr());
@@ -95,7 +92,7 @@ fn parse_timestamp_with_trailing_digits() {
SignatureRef { SignatureRef {
name: "first last".into(), name: "first last".into(),
email: "name@example.com".into(), email: "name@example.com".into(),
time: "1312735823 +051800".into(), time: "1312735823 +051800",
} }
); );
@@ -106,7 +103,7 @@ fn parse_timestamp_with_trailing_digits() {
SignatureRef { SignatureRef {
name: "first last".into(), name: "first last".into(),
email: "name@example.com".into(), email: "name@example.com".into(),
time: "1312735823 +0518".into(), time: "1312735823 +0518",
} }
); );
} }
@@ -120,7 +117,7 @@ fn parse_missing_timestamp() {
SignatureRef { SignatureRef {
name: "first last".into(), name: "first last".into(),
email: "name@example.com".into(), email: "name@example.com".into(),
time: "".into(), time: ""
} }
); );
} }

View File

@@ -36,7 +36,7 @@ impl TimeBuf {
} }
/// Clear the previous content. /// Clear the previous content.
pub fn clear(&mut self) { fn clear(&mut self) {
self.buf.clear(); self.buf.clear();
} }
} }

View File

@@ -138,7 +138,11 @@ impl Snapshot {
/// ///
/// Note that this method will always allocate. /// Note that this method will always allocate.
pub fn resolve(&self, signature: gix_actor::SignatureRef<'_>) -> gix_actor::Signature { pub fn resolve(&self, signature: gix_actor::SignatureRef<'_>) -> gix_actor::Signature {
self.try_resolve(signature).unwrap_or_else(|| signature.to_owned()) self.try_resolve(signature).unwrap_or_else(|| gix_actor::Signature {
name: signature.name.to_owned(),
email: signature.email.to_owned(),
time: signature.time().unwrap_or_default(),
})
} }
/// Like [`try_resolve()`][Snapshot::try_resolve()], but always returns a special copy-on-write signature, which contains /// Like [`try_resolve()`][Snapshot::try_resolve()], but always returns a special copy-on-write signature, which contains
@@ -157,17 +161,17 @@ fn enriched_signature<'a>(
(Some(new_email), Some(new_name)) => Signature { (Some(new_email), Some(new_name)) => Signature {
email: new_email.to_owned().into(), email: new_email.to_owned().into(),
name: new_name.to_owned().into(), name: new_name.to_owned().into(),
time: gix_date::Time::from_bytes(time).unwrap_or_default(), time: time.parse().unwrap_or_default(),
}, },
(Some(new_email), None) => Signature { (Some(new_email), None) => Signature {
email: new_email.to_owned().into(), email: new_email.to_owned().into(),
name: name.into(), name: name.into(),
time: gix_date::Time::from_bytes(time).unwrap_or_default(), time: time.parse().unwrap_or_default(),
}, },
(None, Some(new_name)) => Signature { (None, Some(new_name)) => Signature {
email: email.into(), email: email.into(),
name: new_name.to_owned().into(), name: new_name.to_owned().into(),
time: gix_date::Time::from_bytes(time).unwrap_or_default(), time: time.parse().unwrap_or_default(),
}, },
(None, None) => unreachable!("BUG: ResolvedSignatures don't exist here when nothing is set"), (None, None) => unreachable!("BUG: ResolvedSignatures don't exist here when nothing is set"),
} }

View File

@@ -29,7 +29,7 @@ impl<'a> From<gix_actor::SignatureRef<'a>> for Signature<'a> {
Signature { Signature {
name: s.name.into(), name: s.name.into(),
email: s.email.into(), email: s.email.into(),
time: gix_date::Time::from_bytes(s.time).unwrap_or_default(), time: s.time.parse().unwrap_or_default(),
} }
} }
} }

View File

@@ -1,42 +1,38 @@
use gix_date::parse::TimeBuf;
use gix_mailmap::{Entry, Snapshot}; use gix_mailmap::{Entry, Snapshot};
use gix_testtools::fixture_bytes; use gix_testtools::fixture_bytes;
#[test] #[test]
fn try_resolve() { fn try_resolve() {
let snapshot = Snapshot::from_bytes(&fixture_bytes("typical.txt")); let snapshot = Snapshot::from_bytes(&fixture_bytes("typical.txt"));
let mut buf = Vec::with_capacity(64); let mut buf = TimeBuf::default();
assert_eq!( assert_eq!(
snapshot.try_resolve(signature("Foo", "Joe@example.com").to_ref(&mut buf)), snapshot.try_resolve(signature("Foo", "Joe@example.com").to_ref(&mut buf)),
Some(signature("Joe R. Developer", "joe@example.com")), Some(signature("Joe R. Developer", "joe@example.com")),
"resolved signatures contain all original fields, and normalize the email as well to match the one that it was looked up with" "resolved signatures contain all original fields, and normalize the email as well to match the one that it was looked up with"
); );
buf.clear();
assert_eq!( assert_eq!(
snapshot.try_resolve(signature("Joe", "bugs@example.com").to_ref(&mut buf)), snapshot.try_resolve(signature("Joe", "bugs@example.com").to_ref(&mut buf)),
Some(signature("Joe R. Developer", "joe@example.com")), Some(signature("Joe R. Developer", "joe@example.com")),
"name and email can be mapped specifically" "name and email can be mapped specifically"
); );
buf.clear();
assert_eq!( assert_eq!(
snapshot.try_resolve(signature("Jane", "jane@laptop.(none)").to_ref(&mut buf)), snapshot.try_resolve(signature("Jane", "jane@laptop.(none)").to_ref(&mut buf)),
Some(signature("Jane Doe", "jane@example.com")), Some(signature("Jane Doe", "jane@example.com")),
"fix name and email by email" "fix name and email by email"
); );
buf.clear();
assert_eq!( assert_eq!(
snapshot.try_resolve(signature("Jane", "jane@desktop.(none)").to_ref(&mut buf)), snapshot.try_resolve(signature("Jane", "jane@desktop.(none)").to_ref(&mut buf)),
Some(signature("Jane Doe", "jane@example.com")), Some(signature("Jane Doe", "jane@example.com")),
"fix name and email by other email" "fix name and email by other email"
); );
buf.clear();
assert_eq!( assert_eq!(
snapshot.try_resolve(signature("janE", "Bugs@example.com").to_ref(&mut buf)), snapshot.try_resolve(signature("janE", "Bugs@example.com").to_ref(&mut buf)),
Some(signature("Jane Doe", "jane@example.com")), Some(signature("Jane Doe", "jane@example.com")),
"name and email can be mapped specifically, case insensitive matching of name" "name and email can be mapped specifically, case insensitive matching of name"
); );
buf.clear();
assert_eq!( assert_eq!(
snapshot.resolve(signature("janE", "jane@ipad.(none)").to_ref(&mut buf)), snapshot.resolve(signature("janE", "jane@ipad.(none)").to_ref(&mut buf)),
signature("janE", "jane@example.com"), signature("janE", "jane@example.com"),
@@ -44,10 +40,8 @@ fn try_resolve() {
); );
let sig = signature("Jane", "other@example.com"); let sig = signature("Jane", "other@example.com");
buf.clear();
assert_eq!(snapshot.try_resolve(sig.to_ref(&mut buf)), None, "unmatched email"); assert_eq!(snapshot.try_resolve(sig.to_ref(&mut buf)), None, "unmatched email");
buf.clear();
assert_eq!( assert_eq!(
snapshot.resolve(sig.to_ref(&mut buf)), snapshot.resolve(sig.to_ref(&mut buf)),
sig, sig,
@@ -55,13 +49,11 @@ fn try_resolve() {
); );
let sig = signature("Jean", "bugs@example.com"); let sig = signature("Jean", "bugs@example.com");
buf.clear();
assert_eq!( assert_eq!(
snapshot.try_resolve(sig.to_ref(&mut buf)), snapshot.try_resolve(sig.to_ref(&mut buf)),
None, None,
"matched email, unmatched name" "matched email, unmatched name"
); );
buf.clear();
assert_eq!(snapshot.resolve(sig.to_ref(&mut buf)), sig); assert_eq!(snapshot.resolve(sig.to_ref(&mut buf)), sig);
assert_eq!( assert_eq!(
@@ -95,17 +87,15 @@ fn non_name_and_name_mappings_will_not_clash() {
"old-email", "old-email",
), ),
]; ];
let mut buf = Vec::with_capacity(64); let mut buf = TimeBuf::default();
for entries in [entries.clone().into_iter().rev().collect::<Vec<_>>(), entries] { for entries in [entries.clone().into_iter().rev().collect::<Vec<_>>(), entries] {
let snapshot = Snapshot::new(entries); let snapshot = Snapshot::new(entries);
buf.clear();
assert_eq!( assert_eq!(
snapshot.try_resolve(signature("replace-by-email", "Old-Email").to_ref(&mut buf)), snapshot.try_resolve(signature("replace-by-email", "Old-Email").to_ref(&mut buf)),
Some(signature("new-name", "old-email")), Some(signature("new-name", "old-email")),
"it can match by email only, and the email is normalized" "it can match by email only, and the email is normalized"
); );
buf.clear();
assert_eq!( assert_eq!(
snapshot.try_resolve(signature("old-name", "Old-Email").to_ref(&mut buf)), snapshot.try_resolve(signature("old-name", "Old-Email").to_ref(&mut buf)),
Some(signature("other-new-name", "other-new-email")), Some(signature("other-new-name", "other-new-email")),
@@ -130,28 +120,25 @@ fn non_name_and_name_mappings_will_not_clash() {
#[test] #[test]
fn overwrite_entries() { fn overwrite_entries() {
let snapshot = Snapshot::from_bytes(&fixture_bytes("overwrite.txt")); let snapshot = Snapshot::from_bytes(&fixture_bytes("overwrite.txt"));
let mut buf = Vec::with_capacity(64); let mut buf = TimeBuf::default();
assert_eq!( assert_eq!(
snapshot.try_resolve(signature("does not matter", "old-a-email").to_ref(&mut buf)), snapshot.try_resolve(signature("does not matter", "old-a-email").to_ref(&mut buf)),
Some(signature("A-overwritten", "old-a-email")), Some(signature("A-overwritten", "old-a-email")),
"email only by email" "email only by email"
); );
buf.clear();
assert_eq!( assert_eq!(
snapshot.try_resolve(signature("to be replaced", "old-b-EMAIL").to_ref(&mut buf)), snapshot.try_resolve(signature("to be replaced", "old-b-EMAIL").to_ref(&mut buf)),
Some(signature("B-overwritten", "new-b-email-overwritten")), Some(signature("B-overwritten", "new-b-email-overwritten")),
"name and email by email" "name and email by email"
); );
buf.clear();
assert_eq!( assert_eq!(
snapshot.try_resolve(signature("old-c", "old-C-email").to_ref(&mut buf)), snapshot.try_resolve(signature("old-c", "old-C-email").to_ref(&mut buf)),
Some(signature("C-overwritten", "new-c-email-overwritten")), Some(signature("C-overwritten", "new-c-email-overwritten")),
"name and email by name and email" "name and email by name and email"
); );
buf.clear();
assert_eq!( assert_eq!(
snapshot.try_resolve(signature("unchanged", "old-d-email").to_ref(&mut buf)), snapshot.try_resolve(signature("unchanged", "old-d-email").to_ref(&mut buf)),
Some(signature("unchanged", "new-d-email-overwritten")), Some(signature("unchanged", "new-d-email-overwritten")),
@@ -178,6 +165,6 @@ fn signature(name: &str, email: &str) -> gix_actor::Signature {
gix_actor::Signature { gix_actor::Signature {
name: name.into(), name: name.into(),
email: email.into(), email: email.into(),
time: gix_date::parse_raw("42 +0800").unwrap(), time: gix_date::parse_header("42 +0800").unwrap(),
} }
} }

View File

@@ -110,9 +110,9 @@ impl<'a> CommitRef<'a> {
MessageRef::from_bytes(self.message) MessageRef::from_bytes(self.message)
} }
/// Returns the time at which this commit was created. /// Returns the time at which this commit was created, or a default time if it could not be parsed.
pub fn time(&self) -> gix_date::Time { pub fn time(&self) -> gix_date::Time {
gix_date::Time::from_bytes(self.committer.time).expect("Time from Git should be valid") self.committer.time.parse().unwrap_or_default()
} }
} }

View File

@@ -11,9 +11,8 @@ impl crate::WriteTo for Commit {
for parent in &self.parents { for parent in &self.parents {
encode::trusted_header_id(b"parent", parent, &mut out)?; encode::trusted_header_id(b"parent", parent, &mut out)?;
} }
let mut buf = Vec::with_capacity(64); let mut buf = gix_date::parse::TimeBuf::default();
encode::trusted_header_signature(b"author", &self.author.to_ref(&mut buf), &mut out)?; encode::trusted_header_signature(b"author", &self.author.to_ref(&mut buf), &mut out)?;
buf.clear();
encode::trusted_header_signature(b"committer", &self.committer.to_ref(&mut buf), &mut out)?; encode::trusted_header_signature(b"committer", &self.committer.to_ref(&mut buf), &mut out)?;
if let Some(encoding) = self.encoding.as_ref() { if let Some(encoding) = self.encoding.as_ref() {
encode::header_field(b"encoding", encoding, &mut out)?; encode::header_field(b"encoding", encoding, &mut out)?;

View File

@@ -1,8 +1,8 @@
use std::io; use std::io;
use bstr::BStr;
use crate::{encode, encode::NL, Kind, Tag, TagRef}; use crate::{encode, encode::NL, Kind, Tag, TagRef};
use bstr::BStr;
use gix_date::parse::TimeBuf;
/// An Error used in [`Tag::write_to()`][crate::WriteTo::write_to()]. /// An Error used in [`Tag::write_to()`][crate::WriteTo::write_to()].
#[derive(Debug, thiserror::Error)] #[derive(Debug, thiserror::Error)]
@@ -26,7 +26,7 @@ impl crate::WriteTo for Tag {
encode::trusted_header_field(b"type", self.target_kind.as_bytes(), out)?; encode::trusted_header_field(b"type", self.target_kind.as_bytes(), out)?;
encode::header_field(b"tag", validated_name(self.name.as_ref())?, out)?; encode::header_field(b"tag", validated_name(self.name.as_ref())?, out)?;
if let Some(tagger) = &self.tagger { if let Some(tagger) = &self.tagger {
let mut buf = Vec::with_capacity(64); let mut buf = TimeBuf::default();
encode::trusted_header_signature(b"tagger", &tagger.to_ref(&mut buf), out)?; encode::trusted_header_signature(b"tagger", &tagger.to_ref(&mut buf), out)?;
} }

View File

@@ -11,7 +11,7 @@ fn invalid_timestsamp() {
let actor = gix_actor::SignatureRef { let actor = gix_actor::SignatureRef {
name: b"Name".as_bstr(), name: b"Name".as_bstr(),
email: b"name@example.com".as_bstr(), email: b"name@example.com".as_bstr(),
time: b"1312735823 +051800".as_bstr(), time: "1312735823 +051800",
}; };
assert_eq!( assert_eq!(
CommitRef::from_bytes(&fixture_name("commit", "invalid-timestamp.txt")) CommitRef::from_bytes(&fixture_name("commit", "invalid-timestamp.txt"))
@@ -34,7 +34,7 @@ fn invalid_email_of_committer() {
let actor = gix_actor::SignatureRef { let actor = gix_actor::SignatureRef {
name: b"Gregor Hartmann".as_bstr(), name: b"Gregor Hartmann".as_bstr(),
email: b"gh <Gregor Hartmann<gh@openoffice.org".as_bstr(), email: b"gh <Gregor Hartmann<gh@openoffice.org".as_bstr(),
time: b"1282910542 +0200".as_bstr(), time: "1282910542 +0200",
}; };
assert_eq!( assert_eq!(
CommitRef::from_bytes(&fixture_name("commit", "invalid-actor.txt")) CommitRef::from_bytes(&fixture_name("commit", "invalid-actor.txt"))
@@ -58,8 +58,8 @@ fn unsigned() -> crate::Result {
CommitRef { CommitRef {
tree: b"1b2dfb4ac5e42080b682fc676e9738c94ce6d54d".as_bstr(), tree: b"1b2dfb4ac5e42080b682fc676e9738c94ce6d54d".as_bstr(),
parents: SmallVec::default(), parents: SmallVec::default(),
author: signature(b"1592437401 +0800"), author: signature("1592437401 +0800"),
committer: signature(b"1592437401 +0800"), committer: signature("1592437401 +0800"),
encoding: None, encoding: None,
message: b"without sig".as_bstr(), message: b"without sig".as_bstr(),
extra_headers: vec![] extra_headers: vec![]
@@ -75,8 +75,8 @@ fn whitespace() -> crate::Result {
CommitRef { CommitRef {
tree: b"9bed6275068a0575243ba8409253e61af81ab2ff".as_bstr(), tree: b"9bed6275068a0575243ba8409253e61af81ab2ff".as_bstr(),
parents: SmallVec::from(vec![b"26b4df046d1776c123ac69d918f5aec247b58cc6".as_bstr()]), parents: SmallVec::from(vec![b"26b4df046d1776c123ac69d918f5aec247b58cc6".as_bstr()]),
author: signature(b"1592448450 +0800"), author: signature("1592448450 +0800"),
committer: signature(b"1592448450 +0800"), committer: signature("1592448450 +0800"),
encoding: None, encoding: None,
message: b" nl".as_bstr(), // this one had a \n trailing it, but git seems to trim that message: b" nl".as_bstr(), // this one had a \n trailing it, but git seems to trim that
extra_headers: vec![] extra_headers: vec![]
@@ -92,8 +92,8 @@ fn signed_singleline() -> crate::Result {
CommitRef { CommitRef {
tree: b"00fc39317701176e326974ce44f5bd545a32ec0b".as_bstr(), tree: b"00fc39317701176e326974ce44f5bd545a32ec0b".as_bstr(),
parents: SmallVec::from(vec![b"09d8d3a12e161a7f6afb522dbe8900a9c09bce06".as_bstr()]), parents: SmallVec::from(vec![b"09d8d3a12e161a7f6afb522dbe8900a9c09bce06".as_bstr()]),
author: signature(b"1592391367 +0800"), author: signature("1592391367 +0800"),
committer: signature(b"1592391367 +0800"), committer: signature("1592391367 +0800"),
encoding: None, encoding: None,
message: b"update tasks\n".as_bstr(), message: b"update tasks\n".as_bstr(),
extra_headers: vec![(b"gpgsig".as_bstr(), b"magic:signature".as_bstr().into())] extra_headers: vec![(b"gpgsig".as_bstr(), b"magic:signature".as_bstr().into())]
@@ -111,8 +111,8 @@ fn mergetag() -> crate::Result {
b"44ebe016df3aad96e3be8f95ec52397728dd7701".as_bstr(), b"44ebe016df3aad96e3be8f95ec52397728dd7701".as_bstr(),
b"8d485da0ddee79d0e6713405694253d401e41b93".as_bstr(), b"8d485da0ddee79d0e6713405694253d401e41b93".as_bstr(),
]), ]),
author: linus_signature(b"1591996221 -0700"), author: linus_signature("1591996221 -0700"),
committer: linus_signature(b"1591996221 -0700"), committer: linus_signature("1591996221 -0700"),
encoding: None, encoding: None,
message: LONG_MESSAGE.as_bytes().as_bstr(), message: LONG_MESSAGE.as_bytes().as_bstr(),
extra_headers: vec![( extra_headers: vec![(
@@ -133,8 +133,8 @@ fn signed() -> crate::Result {
CommitRef { CommitRef {
tree: b"00fc39317701176e326974ce44f5bd545a32ec0b".as_bstr(), tree: b"00fc39317701176e326974ce44f5bd545a32ec0b".as_bstr(),
parents: SmallVec::from(vec![b"09d8d3a12e161a7f6afb522dbe8900a9c09bce06".as_bstr()]), parents: SmallVec::from(vec![b"09d8d3a12e161a7f6afb522dbe8900a9c09bce06".as_bstr()]),
author: signature(b"1592391367 +0800"), author: signature("1592391367 +0800"),
committer: signature(b"1592391367 +0800"), committer: signature("1592391367 +0800"),
encoding: None, encoding: None,
message: b"update tasks\n".as_bstr(), message: b"update tasks\n".as_bstr(),
extra_headers: vec![(b"gpgsig".as_bstr(), b"-----BEGIN PGP SIGNATURE-----\n\niQEzBAABCAAdFiEEdjYp/sh4j8NRKLX27gKdHl60AwAFAl7p9tgACgkQ7gKdHl60\nAwBpegf+KQciv9AOIN7+yPmowecGxBnSfpKWTDzFxnyGR8dq63SpWT8WEKG5mf3a\nG6iUqpsDWaMHlzihaMKRvgRpZxFRbjnNPFBj6F4RRqfE+5R7k6DRSLUV5PqnsdSH\nuccfIDWi1imhsm7AaP5trwl1t+83U2JhHqPcPVFLMODYwWeO6NLR/JCzGSTQRa8t\nRgaVMKI19O/fge5OT5Ua8D47VKEhsJX0LfmkP5RfZQ8JJvNd40TupqKRdlv0sAzP\nya7NXkSHXCavHNR6kA+KpWxn900UoGK8/IDlwU6MeOkpPVawb3NFMqnc7KJDaC2p\nSMzpuEG8LTrCx2YSpHNLqHyzvQ1CZA==\n=5ITV\n-----END PGP SIGNATURE-----\n".as_bstr().into())] extra_headers: vec![(b"gpgsig".as_bstr(), b"-----BEGIN PGP SIGNATURE-----\n\niQEzBAABCAAdFiEEdjYp/sh4j8NRKLX27gKdHl60AwAFAl7p9tgACgkQ7gKdHl60\nAwBpegf+KQciv9AOIN7+yPmowecGxBnSfpKWTDzFxnyGR8dq63SpWT8WEKG5mf3a\nG6iUqpsDWaMHlzihaMKRvgRpZxFRbjnNPFBj6F4RRqfE+5R7k6DRSLUV5PqnsdSH\nuccfIDWi1imhsm7AaP5trwl1t+83U2JhHqPcPVFLMODYwWeO6NLR/JCzGSTQRa8t\nRgaVMKI19O/fge5OT5Ua8D47VKEhsJX0LfmkP5RfZQ8JJvNd40TupqKRdlv0sAzP\nya7NXkSHXCavHNR6kA+KpWxn900UoGK8/IDlwU6MeOkpPVawb3NFMqnc7KJDaC2p\nSMzpuEG8LTrCx2YSpHNLqHyzvQ1CZA==\n=5ITV\n-----END PGP SIGNATURE-----\n".as_bstr().into())]
@@ -150,8 +150,8 @@ fn signed_with_encoding() -> crate::Result {
CommitRef { CommitRef {
tree: b"1973afa74d87b2bb73fa884aaaa8752aec43ea88".as_bstr(), tree: b"1973afa74d87b2bb73fa884aaaa8752aec43ea88".as_bstr(),
parents: SmallVec::from(vec![b"79c51cc86923e2b8ca0ee5c4eb75e48027133f9a".as_bstr()]), parents: SmallVec::from(vec![b"79c51cc86923e2b8ca0ee5c4eb75e48027133f9a".as_bstr()]),
author: signature(b"1592448995 +0800"), author: signature("1592448995 +0800"),
committer: signature(b"1592449083 +0800"), committer: signature("1592449083 +0800"),
encoding: Some(b"ISO-8859-1".as_bstr()), encoding: Some(b"ISO-8859-1".as_bstr()),
message: b"encoding & sig".as_bstr(), message: b"encoding & sig".as_bstr(),
extra_headers: vec![(b"gpgsig".as_bstr(), SIGNATURE.as_bstr().into())] extra_headers: vec![(b"gpgsig".as_bstr(), SIGNATURE.as_bstr().into())]
@@ -167,8 +167,8 @@ fn with_encoding() -> crate::Result {
CommitRef { CommitRef {
tree: b"4a1c03029e7407c0afe9fc0320b3258e188b115e".as_bstr(), tree: b"4a1c03029e7407c0afe9fc0320b3258e188b115e".as_bstr(),
parents: SmallVec::from(vec![b"7ca98aad461a5c302cb4c9e3acaaa6053cc67a62".as_bstr()]), parents: SmallVec::from(vec![b"7ca98aad461a5c302cb4c9e3acaaa6053cc67a62".as_bstr()]),
author: signature(b"1592438199 +0800"), author: signature("1592438199 +0800"),
committer: signature(b"1592438199 +0800"), committer: signature("1592438199 +0800"),
encoding: Some("ISO-8859-1".into()), encoding: Some("ISO-8859-1".into()),
message: b"commit with encoding".as_bstr(), message: b"commit with encoding".as_bstr(),
extra_headers: vec![] extra_headers: vec![]
@@ -182,7 +182,7 @@ fn pre_epoch() -> crate::Result {
let signature = || SignatureRef { let signature = || SignatureRef {
name: "Législateur".into(), name: "Législateur".into(),
email: "".into(), email: "".into(),
time: b"-5263834140 +0009".as_bstr(), time: "-5263834140 +0009",
}; };
assert_eq!( assert_eq!(
CommitRef::from_bytes(&fixture_name("commit", "pre-epoch.txt"))?, CommitRef::from_bytes(&fixture_name("commit", "pre-epoch.txt"))?,
@@ -204,7 +204,7 @@ fn double_dash_special_time_offset() -> crate::Result {
let signature = || SignatureRef { let signature = || SignatureRef {
name: "name".into(), name: "name".into(),
email: "name@example.com".into(), email: "name@example.com".into(),
time: "1288373970 --700".into(), time: "1288373970 --700",
}; };
assert_eq!( assert_eq!(
CommitRef::from_bytes(&fixture_name("commit", "double-dash-date-offset.txt"))?, CommitRef::from_bytes(&fixture_name("commit", "double-dash-date-offset.txt"))?,
@@ -226,7 +226,7 @@ fn with_trailer() -> crate::Result {
let kim = SignatureRef { let kim = SignatureRef {
name: "Kim Altintop".into(), name: "Kim Altintop".into(),
email: "kim@eagain.st".into(), email: "kim@eagain.st".into(),
time: "1631514803 +0200".into(), time: "1631514803 +0200",
}; };
let backing = fixture_name("commit", "message-with-footer.txt"); let backing = fixture_name("commit", "message-with-footer.txt");
let commit = CommitRef::from_bytes(&backing)?; let commit = CommitRef::from_bytes(&backing)?;
@@ -315,8 +315,8 @@ fn merge() -> crate::Result {
b"6a6054db4ce3c1e4e6a37f8c4d7acb63a4d6ad71".as_bstr(), b"6a6054db4ce3c1e4e6a37f8c4d7acb63a4d6ad71".as_bstr(),
b"c91d592913d47ac4e4a76daf16fd649b276e211e".as_bstr() b"c91d592913d47ac4e4a76daf16fd649b276e211e".as_bstr()
]), ]),
author: signature(b"1592454703 +0800"), author: signature("1592454703 +0800"),
committer: signature(b"1592454738 +0800"), committer: signature("1592454738 +0800"),
encoding: Some("ISO-8859-1".into()), encoding: Some("ISO-8859-1".into()),
message: b"Merge branch 'branch'".as_bstr(), message: b"Merge branch 'branch'".as_bstr(),
extra_headers: vec![] extra_headers: vec![]

View File

@@ -33,10 +33,10 @@ fn signed_with_encoding() -> crate::Result {
id: hex_to_id("79c51cc86923e2b8ca0ee5c4eb75e48027133f9a") id: hex_to_id("79c51cc86923e2b8ca0ee5c4eb75e48027133f9a")
}, },
Token::Author { Token::Author {
signature: signature(b"1592448995 +0800") signature: signature("1592448995 +0800")
}, },
Token::Committer { Token::Committer {
signature: signature(b"1592449083 +0800") signature: signature("1592449083 +0800")
}, },
Token::Encoding(b"ISO-8859-1".as_bstr()), Token::Encoding(b"ISO-8859-1".as_bstr()),
Token::ExtraHeader((b"gpgsig".as_bstr(), SIGNATURE.as_bytes().as_bstr().into())), Token::ExtraHeader((b"gpgsig".as_bstr(), SIGNATURE.as_bytes().as_bstr().into())),
@@ -44,8 +44,8 @@ fn signed_with_encoding() -> crate::Result {
] ]
); );
assert_eq!(iter.author().ok(), Some(signature(b"1592448995 +0800"))); assert_eq!(iter.author().ok(), Some(signature("1592448995 +0800")));
assert_eq!(iter.committer().ok(), Some(signature(b"1592449083 +0800"))); assert_eq!(iter.committer().ok(), Some(signature("1592449083 +0800")));
Ok(()) Ok(())
} }
@@ -61,10 +61,10 @@ fn whitespace() -> crate::Result {
id: hex_to_id("26b4df046d1776c123ac69d918f5aec247b58cc6") id: hex_to_id("26b4df046d1776c123ac69d918f5aec247b58cc6")
}, },
Token::Author { Token::Author {
signature: signature(b"1592448450 +0800") signature: signature("1592448450 +0800")
}, },
Token::Committer { Token::Committer {
signature: signature(b"1592448450 +0800") signature: signature("1592448450 +0800")
}, },
Token::Message(b" nl".as_bstr()) Token::Message(b" nl".as_bstr())
] ]
@@ -81,10 +81,10 @@ fn unsigned() -> crate::Result {
id: hex_to_id("1b2dfb4ac5e42080b682fc676e9738c94ce6d54d") id: hex_to_id("1b2dfb4ac5e42080b682fc676e9738c94ce6d54d")
}, },
Token::Author { Token::Author {
signature: signature(b"1592437401 +0800") signature: signature("1592437401 +0800")
}, },
Token::Committer { Token::Committer {
signature: signature(b"1592437401 +0800") signature: signature("1592437401 +0800")
}, },
Token::Message(b"without sig".as_bstr()) Token::Message(b"without sig".as_bstr())
] ]
@@ -104,10 +104,10 @@ fn signed_singleline() -> crate::Result {
id: hex_to_id("09d8d3a12e161a7f6afb522dbe8900a9c09bce06") id: hex_to_id("09d8d3a12e161a7f6afb522dbe8900a9c09bce06")
}, },
Token::Author { Token::Author {
signature: signature(b"1592391367 +0800") signature: signature("1592391367 +0800")
}, },
Token::Committer { Token::Committer {
signature: signature(b"1592391367 +0800") signature: signature("1592391367 +0800")
}, },
Token::ExtraHeader((b"gpgsig".as_bstr(), b"magic:signature".as_bstr().into())), Token::ExtraHeader((b"gpgsig".as_bstr(), b"magic:signature".as_bstr().into())),
Token::Message(b"update tasks\n".as_bstr()), Token::Message(b"update tasks\n".as_bstr()),
@@ -151,10 +151,10 @@ fn mergetag() -> crate::Result {
id: hex_to_id("8d485da0ddee79d0e6713405694253d401e41b93") id: hex_to_id("8d485da0ddee79d0e6713405694253d401e41b93")
}, },
Token::Author { Token::Author {
signature: linus_signature(b"1591996221 -0700") signature: linus_signature("1591996221 -0700")
}, },
Token::Committer { Token::Committer {
signature: linus_signature(b"1591996221 -0700") signature: linus_signature("1591996221 -0700")
}, },
Token::ExtraHeader((b"mergetag".as_bstr(), MERGE_TAG.as_bytes().as_bstr().into())), Token::ExtraHeader((b"mergetag".as_bstr(), MERGE_TAG.as_bytes().as_bstr().into())),
Token::Message(LONG_MESSAGE.into()), Token::Message(LONG_MESSAGE.into()),
@@ -186,7 +186,7 @@ mod method {
); );
assert_eq!( assert_eq!(
iter.signatures().collect::<Vec<_>>(), iter.signatures().collect::<Vec<_>>(),
vec![signature(b"1592437401 +0800"), signature(b"1592437401 +0800")] vec![signature("1592437401 +0800"), signature("1592437401 +0800")]
); );
assert_eq!(iter.parent_ids().count(), 0); assert_eq!(iter.parent_ids().count(), 0);
Ok(()) Ok(())
@@ -198,13 +198,13 @@ mod method {
let iter = CommitRefIter::from_bytes(&input); let iter = CommitRefIter::from_bytes(&input);
assert_eq!( assert_eq!(
iter.signatures().collect::<Vec<_>>(), iter.signatures().collect::<Vec<_>>(),
vec![signature(b"1592437401 +0800"), signature(b"1592437401 +0800")] vec![signature("1592437401 +0800"), signature("1592437401 +0800")]
); );
assert_eq!(iter.author().ok(), Some(signature(b"1592437401 +0800"))); assert_eq!(iter.author().ok(), Some(signature("1592437401 +0800")));
assert_eq!(iter.committer().ok(), Some(signature(b"1592437401 +0800"))); assert_eq!(iter.committer().ok(), Some(signature("1592437401 +0800")));
assert_eq!( assert_eq!(
iter.author().ok(), iter.author().ok(),
Some(signature(b"1592437401 +0800")), Some(signature("1592437401 +0800")),
"it's not consuming" "it's not consuming"
); );
Ok(()) Ok(())

View File

@@ -235,7 +235,7 @@ mod summary {
let actor = SignatureRef { let actor = SignatureRef {
name: "name".into(), name: "name".into(),
email: "email".into(), email: "email".into(),
time: "0 0000".into(), time: "0 0000",
}; };
assert_eq!( assert_eq!(
CommitRef { CommitRef {

View File

@@ -90,20 +90,20 @@ fn hex_to_id(hex: &str) -> ObjectId {
ObjectId::from_hex(hex.as_bytes()).expect("40 bytes hex") ObjectId::from_hex(hex.as_bytes()).expect("40 bytes hex")
} }
fn signature(time: &[u8]) -> gix_actor::SignatureRef<'_> { fn signature(time: &str) -> gix_actor::SignatureRef<'_> {
use gix_object::bstr::ByteSlice; use gix_object::bstr::ByteSlice;
gix_actor::SignatureRef { gix_actor::SignatureRef {
name: b"Sebastian Thiel".as_bstr(), name: b"Sebastian Thiel".as_bstr(),
email: b"sebastian.thiel@icloud.com".as_bstr(), email: b"sebastian.thiel@icloud.com".as_bstr(),
time: time.as_bstr(), time,
} }
} }
fn linus_signature(time: &[u8]) -> gix_actor::SignatureRef<'_> { fn linus_signature(time: &str) -> gix_actor::SignatureRef<'_> {
use gix_object::bstr::ByteSlice; use gix_object::bstr::ByteSlice;
gix_actor::SignatureRef { gix_actor::SignatureRef {
name: b"Linus Torvalds".as_bstr(), name: b"Linus Torvalds".as_bstr(),
email: b"torvalds@linux-foundation.org".as_bstr(), email: b"torvalds@linux-foundation.org".as_bstr(),
time: time.as_bstr(), time,
} }
} }

View File

@@ -3,12 +3,12 @@ use gix_object::{bstr::ByteSlice, Kind, TagRef, TagRefIter};
use crate::fixture_name; use crate::fixture_name;
mod method { mod method {
use crate::{fixture_name, hex_to_id};
use bstr::ByteSlice; use bstr::ByteSlice;
use gix_date::parse::TimeBuf;
use gix_object::TagRef; use gix_object::TagRef;
use pretty_assertions::assert_eq; use pretty_assertions::assert_eq;
use crate::{fixture_name, hex_to_id};
#[test] #[test]
fn target() -> crate::Result { fn target() -> crate::Result {
let fixture = fixture_name("tag", "signed.txt"); let fixture = fixture_name("tag", "signed.txt");
@@ -27,7 +27,7 @@ mod method {
assert_eq!(target.to_string(), tag.target); assert_eq!(target.to_string(), tag.target);
assert_eq!(target_kind, tag.target_kind); assert_eq!(target_kind, tag.target_kind);
assert_eq!(name, tag.name); assert_eq!(name, tag.name);
let mut buf = Vec::with_capacity(64); let mut buf = TimeBuf::default();
assert_eq!(tagger.as_ref().map(|s| s.to_ref(&mut buf)), tag.tagger); assert_eq!(tagger.as_ref().map(|s| s.to_ref(&mut buf)), tag.tagger);
assert_eq!(message, tag.message); assert_eq!(message, tag.message);
assert_eq!(pgp_signature.as_ref().map(|s| s.as_bstr()), tag.pgp_signature); assert_eq!(pgp_signature.as_ref().map(|s| s.as_bstr()), tag.pgp_signature);
@@ -45,7 +45,7 @@ mod iter {
let tag = fixture_name("tag", "empty.txt"); let tag = fixture_name("tag", "empty.txt");
let tag_iter = TagRefIter::from_bytes(&tag); let tag_iter = TagRefIter::from_bytes(&tag);
let target_id = hex_to_id("01dd4e2a978a9f5bd773dae6da7aa4a5ac1cdbbc"); let target_id = hex_to_id("01dd4e2a978a9f5bd773dae6da7aa4a5ac1cdbbc");
let tagger = Some(signature(b"1592381636 +0800")); let tagger = Some(signature("1592381636 +0800"));
assert_eq!( assert_eq!(
tag_iter.collect::<Result<Vec<_>, _>>()?, tag_iter.collect::<Result<Vec<_>, _>>()?,
vec![ vec![
@@ -110,7 +110,7 @@ KLMHist5yj0sw1E4hDTyQa0=
}, },
Token::TargetKind(Kind::Commit), Token::TargetKind(Kind::Commit),
Token::Name(b"whitespace".as_bstr()), Token::Name(b"whitespace".as_bstr()),
Token::Tagger(Some(signature(b"1592382888 +0800"))), Token::Tagger(Some(signature("1592382888 +0800"))),
Token::Body { Token::Body {
message: b" \ttab\nnewline\n\nlast-with-trailer\n".as_bstr(), message: b" \ttab\nnewline\n\nlast-with-trailer\n".as_bstr(),
pgp_signature: None pgp_signature: None
@@ -175,7 +175,7 @@ mod from_bytes {
name: b"empty".as_bstr(), name: b"empty".as_bstr(),
target_kind: Kind::Commit, target_kind: Kind::Commit,
message: b"\n".as_bstr(), message: b"\n".as_bstr(),
tagger: Some(signature(b"1592381636 +0800")), tagger: Some(signature("1592381636 +0800")),
pgp_signature: None pgp_signature: None
} }
); );
@@ -194,7 +194,7 @@ mod from_bytes {
name: b"empty".as_bstr(), name: b"empty".as_bstr(),
target_kind: Kind::Commit, target_kind: Kind::Commit,
message: b"".as_bstr(), message: b"".as_bstr(),
tagger: Some(signature(b"1592381636 +0800")), tagger: Some(signature("1592381636 +0800")),
pgp_signature: None pgp_signature: None
} }
); );
@@ -211,7 +211,7 @@ mod from_bytes {
name: b"baz".as_bstr(), name: b"baz".as_bstr(),
target_kind: Kind::Commit, target_kind: Kind::Commit,
message: b"hello\n\nworld".as_bstr(), message: b"hello\n\nworld".as_bstr(),
tagger: Some(signature(b"1592311808 +0800")), tagger: Some(signature("1592311808 +0800")),
pgp_signature: None pgp_signature: None
} }
); );
@@ -259,7 +259,7 @@ KLMHist5yj0sw1E4hDTyQa0=
name: b"whitespace".as_bstr(), name: b"whitespace".as_bstr(),
target_kind: Kind::Commit, target_kind: Kind::Commit,
message: b" \ttab\nnewline\n\nlast-with-trailer\n".as_bstr(), message: b" \ttab\nnewline\n\nlast-with-trailer\n".as_bstr(),
tagger: Some(signature(b"1592382888 +0800")), tagger: Some(signature("1592382888 +0800")),
pgp_signature: None pgp_signature: None
} }
); );
@@ -278,7 +278,7 @@ KLMHist5yj0sw1E4hDTyQa0=
tagger: Some(SignatureRef { tagger: Some(SignatureRef {
name: b"shemminger".as_bstr(), name: b"shemminger".as_bstr(),
email: b"shemminger".as_bstr(), email: b"shemminger".as_bstr(),
time: b"".as_bstr() time: "",
}), }),
pgp_signature: None pgp_signature: None
} }
@@ -316,7 +316,7 @@ cjHJZXWmV4CcRfmLsXzU8s2cR9A0DBvOxhPD1TlKC2JhBFXigjuL9U4Rbq9tdegB
tagger: Some(gix_actor::SignatureRef { tagger: Some(gix_actor::SignatureRef {
name: b"Sebastian Thiel".as_bstr(), name: b"Sebastian Thiel".as_bstr(),
email: b"byronimo@gmail.com".as_bstr(), email: b"byronimo@gmail.com".as_bstr(),
time: b"1528473343 +0230".as_bstr(), time: "1528473343 +0230",
}), }),
} }
} }

View File

@@ -284,7 +284,7 @@ cjHJZXWmV4CcRfmLsXzU8s2cR9A0DBvOxhPD1TlKC2JhBFXigjuL9U4Rbq9tdegB
" "
.as_bstr(), .as_bstr(),
), ),
tagger: Some(signature(b"1528473343 +0200")), tagger: Some(signature("1528473343 +0200")),
}; };
assert_eq!(o.decode()?.as_tag().expect("tag"), &expected); assert_eq!(o.decode()?.as_tag().expect("tag"), &expected);
Ok(()) Ok(())
@@ -299,8 +299,8 @@ cjHJZXWmV4CcRfmLsXzU8s2cR9A0DBvOxhPD1TlKC2JhBFXigjuL9U4Rbq9tdegB
let expected = CommitRef { let expected = CommitRef {
tree: b"6ba2a0ded519f737fd5b8d5ccfb141125ef3176f".as_bstr(), tree: b"6ba2a0ded519f737fd5b8d5ccfb141125ef3176f".as_bstr(),
parents: vec![].into(), parents: vec![].into(),
author: signature(b"1528473303 +0200"), author: signature("1528473303 +0200"),
committer: signature(b"1528473303 +0200"), committer: signature("1528473303 +0200"),
encoding: None, encoding: None,
message: b"initial commit\n".as_bstr(), message: b"initial commit\n".as_bstr(),
extra_headers: vec![(b"gpgsig".as_bstr(), b"-----BEGIN PGP SIGNATURE-----\nComment: GPGTools - https://gpgtools.org\n\niQIzBAABCgAdFiEEw7xSvXbiwjusbsBqZl+Z+p2ZlmwFAlsaptwACgkQZl+Z+p2Z\nlmxXSQ//fj6t7aWoEKeMdFigfj6OXWPUyrRbS0N9kpJeOfA0BIOea/6Jbn8J5qh1\nYRfrySOzHPXR5Y+w4GwLiVas66qyhAbk4yeqZM0JxBjHDyPyRGhjUd3y7WjEa6bj\nP0ACAIkYZQ/Q/LDE3eubmhAwEobBH3nZbwE+/zDIG0i265bD5C0iDumVOiKkSelw\ncr6FZVw1HH+GcabFkeLRZLNGmPqGdbeBwYERqb0U1aRCzV1xLYteoKwyWcYaH8E3\n97z1rwhUO/L7o8WUEJtP3CLB0zuocslMxskf6bCeubBnRNJ0YrRmxGarxCP3vn4D\n3a/MwECnl6mnUU9t+OnfvrzLDN73rlq8iasUq6hGe7Sje7waX6b2UGpxHqwykmXg\nVimD6Ah7svJanHryfJn38DvJW/wOMqmAnSUAp+Y8W9EIe0xVntCmtMyoKuqBoY7T\nJlZ1kHJte6ELIM5JOY9Gx7D0ZCSKZJQqyjoqtl36dsomT0I78/+7QS1DP4S6XB7d\nc3BYH0JkW81p7AAFbE543ttN0Z4wKXErMFqUKnPZUIEuybtlNYV+krRdfDBWQysT\n3MBebjguVQ60oGs06PzeYBosKGQrHggAcwduLFuqXhLTJqN4UQ18RkE0vbtG3YA0\n+XtZQM13vURdfwFI5qitAGgw4EzPVrkWWzApzLCrRPEMbvP+b9A=\n=2qqN\n-----END PGP SIGNATURE-----\n".as_bstr().into())] extra_headers: vec![(b"gpgsig".as_bstr(), b"-----BEGIN PGP SIGNATURE-----\nComment: GPGTools - https://gpgtools.org\n\niQIzBAABCgAdFiEEw7xSvXbiwjusbsBqZl+Z+p2ZlmwFAlsaptwACgkQZl+Z+p2Z\nlmxXSQ//fj6t7aWoEKeMdFigfj6OXWPUyrRbS0N9kpJeOfA0BIOea/6Jbn8J5qh1\nYRfrySOzHPXR5Y+w4GwLiVas66qyhAbk4yeqZM0JxBjHDyPyRGhjUd3y7WjEa6bj\nP0ACAIkYZQ/Q/LDE3eubmhAwEobBH3nZbwE+/zDIG0i265bD5C0iDumVOiKkSelw\ncr6FZVw1HH+GcabFkeLRZLNGmPqGdbeBwYERqb0U1aRCzV1xLYteoKwyWcYaH8E3\n97z1rwhUO/L7o8WUEJtP3CLB0zuocslMxskf6bCeubBnRNJ0YrRmxGarxCP3vn4D\n3a/MwECnl6mnUU9t+OnfvrzLDN73rlq8iasUq6hGe7Sje7waX6b2UGpxHqwykmXg\nVimD6Ah7svJanHryfJn38DvJW/wOMqmAnSUAp+Y8W9EIe0xVntCmtMyoKuqBoY7T\nJlZ1kHJte6ELIM5JOY9Gx7D0ZCSKZJQqyjoqtl36dsomT0I78/+7QS1DP4S6XB7d\nc3BYH0JkW81p7AAFbE543ttN0Z4wKXErMFqUKnPZUIEuybtlNYV+krRdfDBWQysT\n3MBebjguVQ60oGs06PzeYBosKGQrHggAcwduLFuqXhLTJqN4UQ18RkE0vbtG3YA0\n+XtZQM13vURdfwFI5qitAGgw4EzPVrkWWzApzLCrRPEMbvP+b9A=\n=2qqN\n-----END PGP SIGNATURE-----\n".as_bstr().into())]
@@ -428,10 +428,10 @@ cjHJZXWmV4CcRfmLsXzU8s2cR9A0DBvOxhPD1TlKC2JhBFXigjuL9U4Rbq9tdegB
} }
} }
fn signature(time: &[u8]) -> gix_actor::SignatureRef<'_> { fn signature(time: &str) -> gix_actor::SignatureRef<'_> {
gix_actor::SignatureRef { gix_actor::SignatureRef {
name: b"Sebastian Thiel".as_bstr(), name: b"Sebastian Thiel".as_bstr(),
email: b"byronimo@gmail.com".as_bstr(), email: b"byronimo@gmail.com".as_bstr(),
time: time.as_bstr(), time,
} }
} }

View File

@@ -249,7 +249,7 @@ pub mod decode {
signature: gix_actor::SignatureRef { signature: gix_actor::SignatureRef {
name: b"name".as_bstr(), name: b"name".as_bstr(),
email: b"foo@example.com".as_bstr(), email: b"foo@example.com".as_bstr(),
time: b"1234567890 -0000".as_bstr() time: "1234567890 -0000"
}, },
message: b"".as_bstr(), message: b"".as_bstr(),
} }
@@ -273,7 +273,7 @@ pub mod decode {
signature: gix_actor::SignatureRef { signature: gix_actor::SignatureRef {
name: b"Sebastian Thiel".as_bstr(), name: b"Sebastian Thiel".as_bstr(),
email: b"foo@example.com".as_bstr(), email: b"foo@example.com".as_bstr(),
time: b"1618030561 +0800".as_bstr(), time: "1618030561 +0800",
}, },
message: b"pull --ff-only: Fast-forward".as_bstr(), message: b"pull --ff-only: Fast-forward".as_bstr(),
}; };

View File

@@ -1,4 +1,5 @@
use gix_actor::Signature; use gix_actor::Signature;
use gix_date::parse::TimeBuf;
use gix_object::bstr::ByteSlice; use gix_object::bstr::ByteSlice;
use gix_testtools::tempfile::TempDir; use gix_testtools::tempfile::TempDir;
@@ -56,14 +57,13 @@ fn missing_reflog_creates_it_even_if_similarly_named_empty_dir_exists_and_append
let committer = Signature { let committer = Signature {
name: "committer".into(), name: "committer".into(),
email: "committer@example.com".into(), email: "committer@example.com".into(),
time: gix_date::parse_raw("1234 +0800").unwrap(), time: gix_date::parse_header("1234 +0800").unwrap(),
}; };
let mut buf = Vec::with_capacity(64);
store.reflog_create_or_append( store.reflog_create_or_append(
full_name, full_name,
None, None,
&new, &new,
committer.to_ref(&mut buf).into(), committer.to_ref(&mut TimeBuf::default()).into(),
b"the message".as_bstr(), b"the message".as_bstr(),
false, false,
)?; )?;
@@ -86,7 +86,7 @@ fn missing_reflog_creates_it_even_if_similarly_named_empty_dir_exists_and_append
full_name, full_name,
Some(previous), Some(previous),
&new, &new,
committer.to_ref(&mut buf).into(), committer.to_ref(&mut TimeBuf::default()).into(),
b"next message".as_bstr(), b"next message".as_bstr(),
false, false,
)?; )?;
@@ -123,7 +123,7 @@ fn missing_reflog_creates_it_even_if_similarly_named_empty_dir_exists_and_append
full_name, full_name,
None, None,
&new, &new,
committer.to_ref(&mut buf).into(), committer.to_ref(&mut TimeBuf::default()).into(),
b"more complicated reflog creation".as_bstr(), b"more complicated reflog creation".as_bstr(),
false, false,
)?; )?;

View File

@@ -1,5 +1,6 @@
use crate::file::transaction::prepare_and_commit::{committer, create_at}; use crate::file::transaction::prepare_and_commit::{committer, create_at};
use crate::file::EmptyCommit; use crate::file::EmptyCommit;
use gix_date::parse::TimeBuf;
use gix_lock::acquire::Fail; use gix_lock::acquire::Fail;
use gix_ref::file::transaction::PackedRefs; use gix_ref::file::transaction::PackedRefs;
use gix_ref::store::WriteReflog; use gix_ref::store::WriteReflog;
@@ -30,7 +31,7 @@ fn precompose_unicode_journey() -> crate::Result {
assert!(!store_decomposed.precompose_unicode); assert!(!store_decomposed.precompose_unicode);
let decomposed_ref = format!("refs/heads/{decomposed_a}"); let decomposed_ref = format!("refs/heads/{decomposed_a}");
let mut buf = Vec::with_capacity(64); let mut buf = TimeBuf::default();
store_decomposed store_decomposed
.transaction() .transaction()
.prepare(Some(create_at(&decomposed_ref)), Fail::Immediately, Fail::Immediately)? .prepare(Some(create_at(&decomposed_ref)), Fail::Immediately, Fail::Immediately)?
@@ -77,7 +78,6 @@ fn precompose_unicode_journey() -> crate::Result {
let decomposed_u = "u\u{308}"; let decomposed_u = "u\u{308}";
let decomposed_ref = format!("refs/heads/{decomposed_u}"); let decomposed_ref = format!("refs/heads/{decomposed_u}");
buf.clear();
let edits = store_precomposed let edits = store_precomposed
.transaction() .transaction()
.prepare(Some(create_at(&decomposed_ref)), Fail::Immediately, Fail::Immediately)? .prepare(Some(create_at(&decomposed_ref)), Fail::Immediately, Fail::Immediately)?
@@ -98,7 +98,6 @@ fn precompose_unicode_journey() -> crate::Result {
store_precomposed.cached_packed_buffer()?.is_none(), store_precomposed.cached_packed_buffer()?.is_none(),
"no packed-refs yet" "no packed-refs yet"
); );
buf.clear();
let edits = store_precomposed let edits = store_precomposed
.transaction() .transaction()
.packed_refs(PackedRefs::DeletionsAndNonSymbolicUpdatesRemoveLooseSourceReference( .packed_refs(PackedRefs::DeletionsAndNonSymbolicUpdatesRemoveLooseSourceReference(
@@ -166,7 +165,6 @@ fn precompose_unicode_journey() -> crate::Result {
); );
assert!(store_precomposed.reflog_exists(decomposed_ref.as_str())?); assert!(store_precomposed.reflog_exists(decomposed_ref.as_str())?);
buf.clear();
let edits = store_precomposed let edits = store_precomposed
.transaction() .transaction()
.prepare( .prepare(
@@ -207,7 +205,6 @@ fn precompose_unicode_journey() -> crate::Result {
store_precomposed_with_namespace.namespace = Some(gix_ref::namespace::expand(namespace)?.clone()); store_precomposed_with_namespace.namespace = Some(gix_ref::namespace::expand(namespace)?.clone());
// these edits are loose refs // these edits are loose refs
buf.clear();
let edits = store_precomposed_with_namespace let edits = store_precomposed_with_namespace
.transaction() .transaction()
.prepare( .prepare(
@@ -238,7 +235,6 @@ fn precompose_unicode_journey() -> crate::Result {
); );
// and these go straight to packed-refs // and these go straight to packed-refs
buf.clear();
let edits = store_precomposed_with_namespace let edits = store_precomposed_with_namespace
.transaction() .transaction()
.packed_refs(PackedRefs::DeletionsAndNonSymbolicUpdatesRemoveLooseSourceReference( .packed_refs(PackedRefs::DeletionsAndNonSymbolicUpdatesRemoveLooseSourceReference(

View File

@@ -29,7 +29,7 @@ pub(crate) mod prepare_and_commit {
gix_actor::Signature { gix_actor::Signature {
name: "committer".into(), name: "committer".into(),
email: "committer@example.com".into(), email: "committer@example.com".into(),
time: gix_date::parse_raw("1234 +0800").unwrap(), time: gix_date::parse_header("1234 +0800").unwrap(),
} }
} }

View File

@@ -1,3 +1,4 @@
use gix_date::parse::TimeBuf;
use gix_lock::acquire::Fail; use gix_lock::acquire::Fail;
use gix_ref::{ use gix_ref::{
file::transaction::PackedRefs, file::transaction::PackedRefs,
@@ -54,9 +55,8 @@ fn non_conflicting_creation_without_packed_refs_work() -> crate::Result {
Fail::Immediately, Fail::Immediately,
)?; )?;
let mut buf = Vec::with_capacity(64); let mut buf = TimeBuf::default();
t2.commit(committer().to_ref(&mut buf))?; t2.commit(committer().to_ref(&mut buf))?;
let mut buf = Vec::with_capacity(64);
ongoing.commit(committer().to_ref(&mut buf))?; ongoing.commit(committer().to_ref(&mut buf))?;
assert!(store.reflog_exists("refs/new")?); assert!(store.reflog_exists("refs/new")?);
@@ -86,7 +86,7 @@ fn packed_refs_lock_is_mandatory_for_multiple_ongoing_transactions_even_if_one_d
#[test] #[test]
fn conflicting_creation_into_packed_refs() -> crate::Result { fn conflicting_creation_into_packed_refs() -> crate::Result {
let (_dir, store) = empty_store()?; let (_dir, store) = empty_store()?;
let mut buf = Vec::with_capacity(64); let mut buf = TimeBuf::default();
store store
.transaction() .transaction()
.packed_refs(PackedRefs::DeletionsAndNonSymbolicUpdatesRemoveLooseSourceReference( .packed_refs(PackedRefs::DeletionsAndNonSymbolicUpdatesRemoveLooseSourceReference(
@@ -119,7 +119,6 @@ fn conflicting_creation_into_packed_refs() -> crate::Result {
// The following works because locks aren't actually obtained if there would be no change. // The following works because locks aren't actually obtained if there would be no change.
// Otherwise there would be a conflict on case-insensitive filesystems // Otherwise there would be a conflict on case-insensitive filesystems
buf.clear();
store store
.transaction() .transaction()
.packed_refs(PackedRefs::DeletionsAndNonSymbolicUpdatesRemoveLooseSourceReference( .packed_refs(PackedRefs::DeletionsAndNonSymbolicUpdatesRemoveLooseSourceReference(
@@ -190,7 +189,6 @@ fn conflicting_creation_into_packed_refs() -> crate::Result {
// Create a loose ref at a path // Create a loose ref at a path
assert_eq!(store.loose_iter()?.count(), 1, "a symref"); assert_eq!(store.loose_iter()?.count(), 1, "a symref");
buf.clear();
store store
.transaction() .transaction()
.prepare( .prepare(
@@ -213,7 +211,6 @@ fn conflicting_creation_into_packed_refs() -> crate::Result {
"we created a loose ref, overlaying the packed one, and have a symbolic one" "we created a loose ref, overlaying the packed one, and have a symbolic one"
); );
buf.clear();
store store
.transaction() .transaction()
.prepare( .prepare(

View File

@@ -1,3 +1,14 @@
use crate::{
file::{
store_with_packed_refs, store_writable,
transaction::prepare_and_commit::{
committer, create_at, create_symbolic_at, delete_at, empty_store, log_line, reflog_lines,
},
EmptyCommit,
},
hex_to_id,
};
use gix_date::parse::TimeBuf;
use gix_hash::ObjectId; use gix_hash::ObjectId;
use gix_lock::acquire::Fail; use gix_lock::acquire::Fail;
use gix_object::bstr::{BString, ByteSlice}; use gix_object::bstr::{BString, ByteSlice};
@@ -12,17 +23,6 @@ use gix_ref::{
}; };
use std::error::Error; use std::error::Error;
use crate::{
file::{
store_with_packed_refs, store_writable,
transaction::prepare_and_commit::{
committer, create_at, create_symbolic_at, delete_at, empty_store, log_line, reflog_lines,
},
EmptyCommit,
},
hex_to_id,
};
mod collisions; mod collisions;
#[test] #[test]
@@ -65,7 +65,7 @@ fn reference_with_equally_named_empty_or_non_empty_directory_already_in_place_ca
std::fs::write(head_dir.join("file.ext"), "".as_bytes())?; std::fs::write(head_dir.join("file.ext"), "".as_bytes())?;
} }
let mut buf = Vec::with_capacity(64); let mut buf = TimeBuf::default();
let edits = store let edits = store
.transaction() .transaction()
.prepare( .prepare(
@@ -167,7 +167,7 @@ fn reference_with_explicit_value_must_match_the_value_on_update() -> crate::Resu
fn the_existing_must_match_constraint_allow_non_existing_references_to_be_created() -> crate::Result { fn the_existing_must_match_constraint_allow_non_existing_references_to_be_created() -> crate::Result {
let (_keep, store) = store_writable("make_repo_for_reflog.sh")?; let (_keep, store) = store_writable("make_repo_for_reflog.sh")?;
let expected = PreviousValue::ExistingMustMatch(Target::Object(ObjectId::empty_tree(gix_hash::Kind::Sha1))); let expected = PreviousValue::ExistingMustMatch(Target::Object(ObjectId::empty_tree(gix_hash::Kind::Sha1)));
let mut buf = Vec::with_capacity(64); let mut buf = TimeBuf::default();
let edits = store let edits = store
.transaction() .transaction()
.prepare( .prepare(
@@ -259,11 +259,10 @@ fn namespaced_updates_or_deletions_are_transparent_and_not_observable() -> crate
delete_at("refs/for/deletion"), delete_at("refs/for/deletion"),
create_symbolic_at("HEAD", "refs/heads/hello"), create_symbolic_at("HEAD", "refs/heads/hello"),
]; ];
let mut buf = Vec::with_capacity(64);
let edits = store let edits = store
.transaction() .transaction()
.prepare(actual.clone(), Fail::Immediately, Fail::Immediately)? .prepare(actual.clone(), Fail::Immediately, Fail::Immediately)?
.commit(committer().to_ref(&mut buf))?; .commit(committer().to_ref(&mut TimeBuf::default()))?;
assert_eq!(edits, actual); assert_eq!(edits, actual);
Ok(()) Ok(())
@@ -277,7 +276,6 @@ fn reference_with_must_exist_constraint_must_exist_already_with_any_value() -> c
let previous_reflog_count = reflog_lines(&store, "HEAD")?.len(); let previous_reflog_count = reflog_lines(&store, "HEAD")?.len();
let new_target = Target::Object(ObjectId::empty_tree(gix_hash::Kind::Sha1)); let new_target = Target::Object(ObjectId::empty_tree(gix_hash::Kind::Sha1));
let mut buf = Vec::with_capacity(64);
let edits = store let edits = store
.transaction() .transaction()
.prepare( .prepare(
@@ -293,7 +291,7 @@ fn reference_with_must_exist_constraint_must_exist_already_with_any_value() -> c
Fail::Immediately, Fail::Immediately,
Fail::Immediately, Fail::Immediately,
)? )?
.commit(committer().to_ref(&mut buf))?; .commit(committer().to_ref(&mut TimeBuf::default()))?;
assert_eq!( assert_eq!(
edits, edits,
@@ -323,7 +321,6 @@ fn reference_with_must_not_exist_constraint_may_exist_already_if_the_new_value_m
let head = store.try_find_loose("HEAD")?.expect("head exists already"); let head = store.try_find_loose("HEAD")?.expect("head exists already");
let target = head.target; let target = head.target;
let previous_reflog_count = reflog_lines(&store, "HEAD")?.len(); let previous_reflog_count = reflog_lines(&store, "HEAD")?.len();
let mut buf = Vec::with_capacity(64);
let edits = store let edits = store
.transaction() .transaction()
@@ -340,7 +337,7 @@ fn reference_with_must_not_exist_constraint_may_exist_already_if_the_new_value_m
Fail::Immediately, Fail::Immediately,
Fail::Immediately, Fail::Immediately,
)? )?
.commit(committer().to_ref(&mut buf))?; .commit(committer().to_ref(&mut TimeBuf::default()))?;
assert_eq!( assert_eq!(
edits, edits,
@@ -402,7 +399,6 @@ fn symbolic_reference_writes_reflog_if_previous_value_is_set() -> crate::Result
}; };
let new_head_value = Target::Symbolic(referent.try_into().unwrap()); let new_head_value = Target::Symbolic(referent.try_into().unwrap());
let new_oid = hex_to_id("28ce6a8b26aa170e1de65536fe8abe1832bd3242"); let new_oid = hex_to_id("28ce6a8b26aa170e1de65536fe8abe1832bd3242");
let mut buf = Vec::with_capacity(64);
let edits = store let edits = store
.transaction() .transaction()
.prepare( .prepare(
@@ -418,7 +414,7 @@ fn symbolic_reference_writes_reflog_if_previous_value_is_set() -> crate::Result
Fail::Immediately, Fail::Immediately,
Fail::Immediately, Fail::Immediately,
)? )?
.commit(committer().to_ref(&mut buf))?; .commit(committer().to_ref(&mut TimeBuf::default()))?;
assert_eq!(edits.len(), 1, "no split was performed"); assert_eq!(edits.len(), 1, "no split was performed");
let head = store.find_loose(&edits[0].name)?; let head = store.find_loose(&edits[0].name)?;
assert_eq!(head.name.as_bstr(), "refs/heads/symbolic"); assert_eq!(head.name.as_bstr(), "refs/heads/symbolic");
@@ -510,7 +506,7 @@ fn symbolic_head_missing_referent_then_update_referent() -> crate::Result {
message: "ignored".into(), message: "ignored".into(),
}; };
let new_head_value = Target::Symbolic(referent.try_into().unwrap()); let new_head_value = Target::Symbolic(referent.try_into().unwrap());
let mut buf = Vec::with_capacity(64); let mut buf = TimeBuf::default();
let edits = store let edits = store
.transaction() .transaction()
.prepare( .prepare(
@@ -563,7 +559,6 @@ fn symbolic_head_missing_referent_then_update_referent() -> crate::Result {
mode: RefLog::AndReference, mode: RefLog::AndReference,
force_create_reflog: false, force_create_reflog: false,
}; };
buf.clear();
let edits = store let edits = store
.transaction() .transaction()
.prepare( .prepare(
@@ -658,7 +653,6 @@ fn write_reference_to_which_head_points_to_does_not_update_heads_reflog_even_tho
let previous_head_reflog = reflog_lines(&store, "HEAD")?; let previous_head_reflog = reflog_lines(&store, "HEAD")?;
let new_id = hex_to_id("01dd4e2a978a9f5bd773dae6da7aa4a5ac1cdbbc"); let new_id = hex_to_id("01dd4e2a978a9f5bd773dae6da7aa4a5ac1cdbbc");
let mut buf = Vec::with_capacity(64);
let edits = store let edits = store
.transaction() .transaction()
.prepare( .prepare(
@@ -678,7 +672,7 @@ fn write_reference_to_which_head_points_to_does_not_update_heads_reflog_even_tho
Fail::Immediately, Fail::Immediately,
Fail::Immediately, Fail::Immediately,
)? )?
.commit(committer().to_ref(&mut buf))?; .commit(committer().to_ref(&mut TimeBuf::default()))?;
assert_eq!(edits.len(), 1, "HEAD wasn't update"); assert_eq!(edits.len(), 1, "HEAD wasn't update");
assert_eq!( assert_eq!(
@@ -725,7 +719,6 @@ fn packed_refs_are_looked_up_when_checking_existing_values() -> crate::Result {
); );
let new_id = hex_to_id("0000000000000000000000000000000000000001"); let new_id = hex_to_id("0000000000000000000000000000000000000001");
let old_id = hex_to_id("134385f6d781b7e97062102c6a483440bfda2a03"); let old_id = hex_to_id("134385f6d781b7e97062102c6a483440bfda2a03");
let mut buf = Vec::with_capacity(64);
let edits = store let edits = store
.transaction() .transaction()
.prepare( .prepare(
@@ -745,7 +738,7 @@ fn packed_refs_are_looked_up_when_checking_existing_values() -> crate::Result {
Fail::Immediately, Fail::Immediately,
Fail::Immediately, Fail::Immediately,
)? )?
.commit(committer().to_ref(&mut buf))?; .commit(committer().to_ref(&mut TimeBuf::default()))?;
assert_eq!(edits.len(), 1, "only one edit was performed in the loose refs store"); assert_eq!(edits.len(), 1, "only one edit was performed in the loose refs store");
@@ -776,7 +769,6 @@ fn packed_refs_creation_with_packed_refs_mode_prune_removes_original_loose_refs(
"there should be no packed refs to start out with" "there should be no packed refs to start out with"
); );
let odb = gix_odb::at(store.git_dir().join("objects"))?; let odb = gix_odb::at(store.git_dir().join("objects"))?;
let mut buf = Vec::with_capacity(64);
let edits = store let edits = store
.transaction() .transaction()
.packed_refs(PackedRefs::DeletionsAndNonSymbolicUpdatesRemoveLooseSourceReference( .packed_refs(PackedRefs::DeletionsAndNonSymbolicUpdatesRemoveLooseSourceReference(
@@ -798,7 +790,7 @@ fn packed_refs_creation_with_packed_refs_mode_prune_removes_original_loose_refs(
Fail::Immediately, Fail::Immediately,
Fail::Immediately, Fail::Immediately,
)? )?
.commit(committer().to_ref(&mut buf))?; .commit(committer().to_ref(&mut TimeBuf::default()))?;
assert_eq!( assert_eq!(
edits.len(), edits.len(),
@@ -847,12 +839,11 @@ fn packed_refs_creation_with_packed_refs_mode_leave_keeps_original_loose_refs()
deref: false, deref: false,
}); });
let mut buf = Vec::with_capacity(64);
let edits = store let edits = store
.transaction() .transaction()
.packed_refs(PackedRefs::DeletionsAndNonSymbolicUpdates(Box::new(EmptyCommit))) .packed_refs(PackedRefs::DeletionsAndNonSymbolicUpdates(Box::new(EmptyCommit)))
.prepare(edits, Fail::Immediately, Fail::Immediately)? .prepare(edits, Fail::Immediately, Fail::Immediately)?
.commit(committer().to_ref(&mut buf))?; .commit(committer().to_ref(&mut TimeBuf::default()))?;
assert_eq!( assert_eq!(
edits.len(), edits.len(),
2, 2,
@@ -893,7 +884,6 @@ fn packed_refs_deletion_in_deletions_and_updates_mode() -> crate::Result {
); );
let odb = gix_odb::at(store.git_dir().join("objects"))?; let odb = gix_odb::at(store.git_dir().join("objects"))?;
let old_id = hex_to_id("134385f6d781b7e97062102c6a483440bfda2a03"); let old_id = hex_to_id("134385f6d781b7e97062102c6a483440bfda2a03");
let mut buf = Vec::with_capacity(64);
let edits = store let edits = store
.transaction() .transaction()
.packed_refs(PackedRefs::DeletionsAndNonSymbolicUpdates(Box::new(odb))) .packed_refs(PackedRefs::DeletionsAndNonSymbolicUpdates(Box::new(odb)))
@@ -909,7 +899,7 @@ fn packed_refs_deletion_in_deletions_and_updates_mode() -> crate::Result {
Fail::Immediately, Fail::Immediately,
Fail::Immediately, Fail::Immediately,
)? )?
.commit(committer().to_ref(&mut buf))?; .commit(committer().to_ref(&mut TimeBuf::default()))?;
assert_eq!(edits.len(), 1, "only one edit was performed in the packed refs store"); assert_eq!(edits.len(), 1, "only one edit was performed in the packed refs store");

View File

@@ -1,3 +1,4 @@
use gix_date::parse::TimeBuf;
use gix_lock::acquire::Fail; use gix_lock::acquire::Fail;
use gix_ref::{ use gix_ref::{
file::ReferenceExt, file::ReferenceExt,
@@ -16,7 +17,6 @@ use crate::{
#[test] #[test]
fn delete_a_ref_which_is_gone_succeeds() -> crate::Result { fn delete_a_ref_which_is_gone_succeeds() -> crate::Result {
let (_keep, store) = empty_store()?; let (_keep, store) = empty_store()?;
let mut buf = Vec::with_capacity(64);
let edits = store let edits = store
.transaction() .transaction()
.prepare( .prepare(
@@ -31,7 +31,7 @@ fn delete_a_ref_which_is_gone_succeeds() -> crate::Result {
Fail::Immediately, Fail::Immediately,
Fail::Immediately, Fail::Immediately,
)? )?
.commit(committer().to_ref(&mut buf))?; .commit(committer().to_ref(&mut TimeBuf::default()))?;
assert_eq!(edits.len(), 1); assert_eq!(edits.len(), 1);
Ok(()) Ok(())
} }
@@ -68,7 +68,6 @@ fn delete_ref_and_reflog_on_symbolic_no_deref() -> crate::Result {
assert!(head.log_exists(&store)); assert!(head.log_exists(&store));
let _main = store.find_loose("main")?; let _main = store.find_loose("main")?;
let mut buf = Vec::with_capacity(64);
let edits = store let edits = store
.transaction() .transaction()
.prepare( .prepare(
@@ -83,7 +82,7 @@ fn delete_ref_and_reflog_on_symbolic_no_deref() -> crate::Result {
Fail::Immediately, Fail::Immediately,
Fail::Immediately, Fail::Immediately,
)? )?
.commit(committer().to_ref(&mut buf))?; .commit(committer().to_ref(&mut TimeBuf::default()))?;
assert_eq!( assert_eq!(
edits, edits,
@@ -145,7 +144,6 @@ fn delete_reflog_only_of_symbolic_no_deref() -> crate::Result {
let head = store.find_loose("HEAD")?; let head = store.find_loose("HEAD")?;
assert!(head.log_exists(&store)); assert!(head.log_exists(&store));
let mut buf = Vec::with_capacity(64);
let edits = store let edits = store
.transaction() .transaction()
.prepare( .prepare(
@@ -160,7 +158,7 @@ fn delete_reflog_only_of_symbolic_no_deref() -> crate::Result {
Fail::Immediately, Fail::Immediately,
Fail::Immediately, Fail::Immediately,
)? )?
.commit(committer().to_ref(&mut buf))?; .commit(committer().to_ref(&mut TimeBuf::default()))?;
assert_eq!(edits.len(), 1); assert_eq!(edits.len(), 1);
let head: Reference = store.find_loose("HEAD")?.into(); let head: Reference = store.find_loose("HEAD")?.into();
@@ -181,7 +179,6 @@ fn delete_reflog_only_of_symbolic_with_deref() -> crate::Result {
let head = store.find_loose("HEAD")?; let head = store.find_loose("HEAD")?;
assert!(head.log_exists(&store)); assert!(head.log_exists(&store));
let mut buf = Vec::with_capacity(64);
let edits = store let edits = store
.transaction() .transaction()
.prepare( .prepare(
@@ -196,7 +193,7 @@ fn delete_reflog_only_of_symbolic_with_deref() -> crate::Result {
Fail::Immediately, Fail::Immediately,
Fail::Immediately, Fail::Immediately,
)? )?
.commit(committer().to_ref(&mut buf))?; .commit(committer().to_ref(&mut TimeBuf::default()))?;
assert_eq!(edits.len(), 2); assert_eq!(edits.len(), 2);
let head: Reference = store.find_loose("HEAD")?.into(); let head: Reference = store.find_loose("HEAD")?.into();
@@ -247,7 +244,6 @@ fn non_existing_can_be_deleted_with_the_may_exist_match_constraint() -> crate::R
let (_keep, store) = empty_store()?; let (_keep, store) = empty_store()?;
let previous_value = let previous_value =
PreviousValue::ExistingMustMatch(Target::Object(hex_to_id("134385f6d781b7e97062102c6a483440bfda2a03"))); PreviousValue::ExistingMustMatch(Target::Object(hex_to_id("134385f6d781b7e97062102c6a483440bfda2a03")));
let mut buf = Vec::with_capacity(64);
let edits = store let edits = store
.transaction() .transaction()
.prepare( .prepare(
@@ -262,7 +258,7 @@ fn non_existing_can_be_deleted_with_the_may_exist_match_constraint() -> crate::R
Fail::Immediately, Fail::Immediately,
Fail::Immediately, Fail::Immediately,
)? )?
.commit(committer().to_ref(&mut buf))?; .commit(committer().to_ref(&mut TimeBuf::default()))?;
assert_eq!( assert_eq!(
edits, edits,
@@ -285,7 +281,6 @@ fn delete_broken_ref_that_may_not_exist_works_even_in_deref_mode() -> crate::Res
std::fs::write(store.git_dir().join("HEAD"), b"broken")?; std::fs::write(store.git_dir().join("HEAD"), b"broken")?;
assert!(store.try_find_loose("HEAD").is_err(), "the ref is truly broken"); assert!(store.try_find_loose("HEAD").is_err(), "the ref is truly broken");
let mut buf = Vec::with_capacity(64);
let edits = store let edits = store
.transaction() .transaction()
.prepare( .prepare(
@@ -300,7 +295,7 @@ fn delete_broken_ref_that_may_not_exist_works_even_in_deref_mode() -> crate::Res
Fail::Immediately, Fail::Immediately,
Fail::Immediately, Fail::Immediately,
)? )?
.commit(committer().to_ref(&mut buf))?; .commit(committer().to_ref(&mut TimeBuf::default()))?;
assert!(store.try_find_loose("HEAD")?.is_none(), "the ref was deleted"); assert!(store.try_find_loose("HEAD")?.is_none(), "the ref was deleted");
assert_eq!( assert_eq!(
@@ -328,7 +323,6 @@ fn store_write_mode_has_no_effect_and_reflogs_are_always_deleted() -> crate::Res
assert!(store.find_loose("HEAD")?.log_exists(&store)); assert!(store.find_loose("HEAD")?.log_exists(&store));
assert!(store.open_packed_buffer()?.is_none(), "there is no pack"); assert!(store.open_packed_buffer()?.is_none(), "there is no pack");
let mut buf = Vec::with_capacity(64);
let edits = store let edits = store
.transaction() .transaction()
.prepare( .prepare(
@@ -343,7 +337,7 @@ fn store_write_mode_has_no_effect_and_reflogs_are_always_deleted() -> crate::Res
Fail::Immediately, Fail::Immediately,
Fail::Immediately, Fail::Immediately,
)? )?
.commit(committer().to_ref(&mut buf))?; .commit(committer().to_ref(&mut TimeBuf::default()))?;
assert_eq!(edits.len(), 1); assert_eq!(edits.len(), 1);
assert!(!store.find_loose("HEAD")?.log_exists(&store), "log was deleted"); assert!(!store.find_loose("HEAD")?.log_exists(&store), "log was deleted");
assert!(store.open_packed_buffer()?.is_none(), "there still is no pack"); assert!(store.open_packed_buffer()?.is_none(), "there still is no pack");
@@ -365,7 +359,6 @@ fn packed_refs_are_consulted_when_determining_previous_value_of_ref_to_be_delete
); );
let old_id = hex_to_id("134385f6d781b7e97062102c6a483440bfda2a03"); let old_id = hex_to_id("134385f6d781b7e97062102c6a483440bfda2a03");
let mut buf = Vec::with_capacity(64);
let edits = store let edits = store
.transaction() .transaction()
.prepare( .prepare(
@@ -380,7 +373,7 @@ fn packed_refs_are_consulted_when_determining_previous_value_of_ref_to_be_delete
Fail::Immediately, Fail::Immediately,
Fail::Immediately, Fail::Immediately,
)? )?
.commit(committer().to_ref(&mut buf))?; .commit(committer().to_ref(&mut TimeBuf::default()))?;
assert_eq!(edits.len(), 1, "an edit was performed in the packed refs store"); assert_eq!(edits.len(), 1, "an edit was performed in the packed refs store");
let packed = store.open_packed_buffer()?.expect("packed ref present"); let packed = store.open_packed_buffer()?.expect("packed ref present");
@@ -400,7 +393,6 @@ fn a_loose_ref_with_old_value_check_and_outdated_packed_refs_value_deletes_both_
"the packed ref is outdated" "the packed ref is outdated"
); );
let mut buf = Vec::with_capacity(64);
let edits = store let edits = store
.transaction() .transaction()
.prepare( .prepare(
@@ -415,7 +407,7 @@ fn a_loose_ref_with_old_value_check_and_outdated_packed_refs_value_deletes_both_
Fail::Immediately, Fail::Immediately,
Fail::Immediately, Fail::Immediately,
)? )?
.commit(committer().to_ref(&mut buf))?; .commit(committer().to_ref(&mut TimeBuf::default()))?;
assert_eq!( assert_eq!(
edits.len(), edits.len(),
@@ -433,7 +425,6 @@ fn a_loose_ref_with_old_value_check_and_outdated_packed_refs_value_deletes_both_
fn all_contained_references_deletes_the_packed_ref_file_too() -> crate::Result { fn all_contained_references_deletes_the_packed_ref_file_too() -> crate::Result {
for mode in ["must-exist", "may-exist"] { for mode in ["must-exist", "may-exist"] {
let (_keep, store) = store_writable("make_packed_ref_repository.sh")?; let (_keep, store) = store_writable("make_packed_ref_repository.sh")?;
let mut buf = Vec::with_capacity(64);
let edits = store let edits = store
.transaction() .transaction()
.prepare( .prepare(
@@ -455,7 +446,7 @@ fn all_contained_references_deletes_the_packed_ref_file_too() -> crate::Result {
Fail::Immediately, Fail::Immediately,
Fail::Immediately, Fail::Immediately,
)? )?
.commit(committer().to_ref(&mut buf))?; .commit(committer().to_ref(&mut TimeBuf::default()))?;
assert!(!store.packed_refs_path().is_file(), "packed-refs was entirely removed"); assert!(!store.packed_refs_path().is_file(), "packed-refs was entirely removed");

View File

@@ -189,6 +189,7 @@ mod read_only {
} }
mod writable { mod writable {
use gix_date::parse::TimeBuf;
use gix_lock::acquire::Fail; use gix_lock::acquire::Fail;
use gix_ref::{ use gix_ref::{
file::{transaction::PackedRefs, Store}, file::{transaction::PackedRefs, Store},
@@ -219,7 +220,6 @@ mod writable {
let new_id_main = hex_to_id(new_id_main_str); let new_id_main = hex_to_id(new_id_main_str);
let new_id_linked_str = "22222222222222222262102c6a483440bfda2a03"; let new_id_linked_str = "22222222222222222262102c6a483440bfda2a03";
let new_id_linked = hex_to_id(new_id_linked_str); let new_id_linked = hex_to_id(new_id_linked_str);
let mut buf = Vec::with_capacity(64);
for packed in [false, true] { for packed in [false, true] {
let (store, _odb, _tmp) = main_store(packed, Mode::Write)?; let (store, _odb, _tmp) = main_store(packed, Mode::Write)?;
@@ -228,7 +228,6 @@ mod writable {
t = t.packed_refs(PackedRefs::DeletionsAndNonSymbolicUpdates(Box::new(EmptyCommit))); t = t.packed_refs(PackedRefs::DeletionsAndNonSymbolicUpdates(Box::new(EmptyCommit)));
} }
buf.clear();
let edits = t let edits = t
.prepare( .prepare(
vec![ vec![
@@ -261,7 +260,7 @@ mod writable {
Fail::Immediately, Fail::Immediately,
Fail::Immediately, Fail::Immediately,
)? )?
.commit(committer().to_ref(&mut buf)) .commit(committer().to_ref(&mut TimeBuf::default()))
.expect("successful commit as even similar resolved names live in different base locations"); .expect("successful commit as even similar resolved names live in different base locations");
assert_eq!( assert_eq!(
@@ -479,7 +478,6 @@ mod writable {
let new_id = hex_to_id(new_id_str); let new_id = hex_to_id(new_id_str);
let new_id_main_str = "22222222222222227062102c6a483440bfda2a03"; let new_id_main_str = "22222222222222227062102c6a483440bfda2a03";
let new_id_main = hex_to_id(new_id_main_str); let new_id_main = hex_to_id(new_id_main_str);
let mut buf = Vec::with_capacity(64);
for packed in [false, true] { for packed in [false, true] {
let (store, _odb, _tmp) = worktree_store(packed, "w1", Mode::Write)?; let (store, _odb, _tmp) = worktree_store(packed, "w1", Mode::Write)?;
@@ -510,7 +508,6 @@ mod writable {
t = t.packed_refs(PackedRefs::DeletionsAndNonSymbolicUpdates(Box::new(EmptyCommit))); t = t.packed_refs(PackedRefs::DeletionsAndNonSymbolicUpdates(Box::new(EmptyCommit)));
} }
buf.clear();
let edits = t let edits = t
.prepare( .prepare(
vec![ vec![
@@ -543,7 +540,7 @@ mod writable {
Fail::Immediately, Fail::Immediately,
Fail::Immediately, Fail::Immediately,
)? )?
.commit(committer().to_ref(&mut buf)) .commit(committer().to_ref(&mut TimeBuf::default()))
.expect("successful commit as even similar resolved names live in different base locations"); .expect("successful commit as even similar resolved names live in different base locations");
assert_eq!( assert_eq!(

View File

@@ -76,7 +76,7 @@ impl<'repo> Commit<'repo> {
/// ///
/// For the time at which it was authored, refer to `.decode()?.author.time`. /// For the time at which it was authored, refer to `.decode()?.author.time`.
pub fn time(&self) -> Result<gix_date::Time, Error> { pub fn time(&self) -> Result<gix_date::Time, Error> {
Ok(gix_date::Time::from_bytes(self.committer()?.time)?) Ok(self.committer()?.time()?)
} }
/// Decode the entire commit object and return it for accessing all commit information. /// Decode the entire commit object and return it for accessing all commit information.

View File

@@ -3,6 +3,7 @@ use crate::{
config, config,
config::tree::{gitoxide, keys, Author, Committer, Key, User}, config::tree::{gitoxide, keys, Author, Committer, Key, User},
}; };
use std::time::SystemTime;
/// Identity handling. /// Identity handling.
/// ///
@@ -68,7 +69,7 @@ impl crate::Repository {
pub(crate) struct Entity { pub(crate) struct Entity {
pub name: Option<BString>, pub name: Option<BString>,
pub email: Option<BString>, pub email: Option<BString>,
pub time: Option<BString>, pub time: Option<String>,
} }
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
@@ -104,7 +105,7 @@ impl Personas {
.map(std::borrow::Cow::into_owned), .map(std::borrow::Cow::into_owned),
) )
} }
let parse_date = |key: &str, date: &keys::Any| -> Option<BString> { let parse_date = |key: &str, date: &keys::Any| -> Option<String> {
debug_assert_eq!( debug_assert_eq!(
key, key,
date.logical_name(), date.logical_name(),
@@ -113,9 +114,14 @@ impl Personas {
config config
.string(key) .string(key)
.map(std::borrow::Cow::into_owned) .map(std::borrow::Cow::into_owned)
.and_then(|config_date| gix_date::Time::from_config(config_date.as_bstr()).ok()) .and_then(|config_date| {
config_date
.to_str()
.ok()
.and_then(|date| gix_date::parse(date, Some(SystemTime::now())).ok())
})
.or_else(|| Some(gix_date::Time::now_local_or_utc())) .or_else(|| Some(gix_date::Time::now_local_or_utc()))
.map(|time| time.format(gix_date::time::Format::Raw).into()) .map(|time| time.format(gix_date::time::Format::Raw))
}; };
let fallback = ( let fallback = (

View File

@@ -249,7 +249,7 @@ impl crate::Repository {
target: target.as_ref().into(), target: target.as_ref().into(),
target_kind, target_kind,
name: name.as_ref().into(), name: name.as_ref().into(),
tagger: tagger.map(|t| t.to_owned()), tagger: tagger.map(|t| t.to_owned()).transpose()?,
message: message.as_ref().into(), message: message.as_ref().into(),
pgp_signature: None, pgp_signature: None,
}; };

View File

@@ -137,7 +137,7 @@ impl delegate::Revision for Delegate<'_> {
d.previous_oid d.previous_oid
}); });
}) })
.find(|l| l.signature.seconds() <= date.seconds) .find(|l| l.signature.time.seconds <= date.seconds)
{ {
Some(closest_line) => closest_line.new_oid, Some(closest_line) => closest_line.new_oid,
None => match last { None => match last {

View File

@@ -1,6 +1,5 @@
use std::collections::HashSet;
use gix_hash::ObjectId; use gix_hash::ObjectId;
use std::collections::HashSet;
use super::Error; use super::Error;
use crate::{bstr, bstr::BString, ext::ObjectIdExt, Repository}; use crate::{bstr, bstr::BString, ext::ObjectIdExt, Repository};
@@ -26,7 +25,7 @@ pub enum CandidateInfo {
/// The candidate is a commit. /// The candidate is a commit.
Commit { Commit {
/// The date of the commit. /// The date of the commit.
date: BString, date: String,
/// The subject line. /// The subject line.
title: BString, title: BString,
}, },
@@ -42,8 +41,8 @@ impl std::fmt::Display for CandidateInfo {
write!( write!(
f, f,
"commit {} {title:?}", "commit {} {title:?}",
gix_date::Time::from_bytes(date.as_ref()) gix_date::parse_header(date)
.map_err(|_e| Default::default())? .unwrap_or_default()
.format(gix_date::time::format::SHORT) .format(gix_date::time::format::SHORT)
) )
} }

View File

@@ -12,6 +12,8 @@ mod error {
WriteObject(#[from] crate::object::write::Error), WriteObject(#[from] crate::object::write::Error),
#[error(transparent)] #[error(transparent)]
ReferenceEdit(#[from] crate::reference::edit::Error), ReferenceEdit(#[from] crate::reference::edit::Error),
#[error(transparent)]
DateParseError(#[from] gix_date::parse::Error),
} }
} }
pub use error::Error; pub use error::Error;

View File

@@ -334,7 +334,7 @@ mod blocking_io {
.next() .next()
.expect("one line")? .expect("one line")?
.signature .signature
.to_owned(); .to_owned()?;
assert_eq!(sig.name, "no name configured during clone"); assert_eq!(sig.name, "no name configured during clone");
assert_eq!(sig.email, "noEmailAvailable@example.com"); assert_eq!(sig.email, "noEmailAvailable@example.com");

View File

@@ -54,7 +54,7 @@ fn author_and_committer_and_fallback() -> crate::Result {
gix_actor::SignatureRef { gix_actor::SignatureRef {
name: "author".into(), name: "author".into(),
email: "author@email".into(), email: "author@email".into(),
time: "1659329106 +0800".into(), time: "1659329106 +0800",
} }
); );
@@ -63,7 +63,7 @@ fn author_and_committer_and_fallback() -> crate::Result {
gix_actor::SignatureRef { gix_actor::SignatureRef {
name: "committer".into(), name: "committer".into(),
email: "committer@email".into(), email: "committer@email".into(),
time: "1659365106 -0200".into(), time: "1659365106 -0200",
} }
); );
let config = repo.config_snapshot(); let config = repo.config_snapshot();
@@ -161,7 +161,7 @@ fn author_from_different_config_sections() -> crate::Result {
Some(gix_actor::SignatureRef { Some(gix_actor::SignatureRef {
name: "global name".into(), name: "global name".into(),
email: "local@example.com".into(), email: "local@example.com".into(),
time: "42 +0030".into() time: "42 +0030",
}), }),
"author name comes from global config, \ "author name comes from global config, \
but email comes from repository-local config", but email comes from repository-local config",
@@ -171,7 +171,7 @@ fn author_from_different_config_sections() -> crate::Result {
Some(gix_actor::SignatureRef { Some(gix_actor::SignatureRef {
name: "local committer".into(), name: "local committer".into(),
email: "global-committer@example.com".into(), email: "global-committer@example.com".into(),
time: "320437800 +0000".into() time: "320437800 +0000",
}), }),
"committer name comes from repository-local config, \ "committer name comes from repository-local config, \
but committer email comes from global config" but committer email comes from global config"

View File

@@ -534,6 +534,7 @@ mod tag {
} }
mod commit_as { mod commit_as {
use gix_date::parse::TimeBuf;
use gix_testtools::tempfile; use gix_testtools::tempfile;
#[test] #[test]
@@ -550,19 +551,17 @@ mod commit_as {
let committer = gix::actor::Signature { let committer = gix::actor::Signature {
name: "c".into(), name: "c".into(),
email: "c@example.com".into(), email: "c@example.com".into(),
time: gix_date::parse_raw("1 +0030").unwrap(), time: gix_date::parse_header("1 +0030").unwrap(),
}; };
let author = gix::actor::Signature { let author = gix::actor::Signature {
name: "a".into(), name: "a".into(),
email: "a@example.com".into(), email: "a@example.com".into(),
time: gix_date::parse_raw("3 +0100").unwrap(), time: gix_date::parse_header("3 +0100").unwrap(),
}; };
let mut c_buf = Vec::with_capacity(64);
let mut a_buf = Vec::with_capacity(64);
let commit_id = repo.commit_as( let commit_id = repo.commit_as(
committer.to_ref(&mut c_buf), committer.to_ref(&mut TimeBuf::default()),
author.to_ref(&mut a_buf), author.to_ref(&mut TimeBuf::default()),
"HEAD", "HEAD",
"initial", "initial",
empty_tree.id, empty_tree.id,
@@ -570,9 +569,8 @@ mod commit_as {
)?; )?;
let commit = commit_id.object()?.into_commit(); let commit = commit_id.object()?.into_commit();
let mut buf = Vec::with_capacity(64); let mut buf = TimeBuf::default();
assert_eq!(commit.committer()?, committer.to_ref(&mut buf)); assert_eq!(commit.committer()?, committer.to_ref(&mut buf));
buf.clear();
assert_eq!(commit.author()?, author.to_ref(&mut buf)); assert_eq!(commit.author()?, author.to_ref(&mut buf));
Ok(()) Ok(())
} }