Skip to content

Commit 47db249

Browse files
author
Pierre Chevalier
committed
fix: Adapt to changes in gix-actor
Use the committer date and author date that are now backed by bytes and interpret these bytes into a `gix_date::Time` on demand.
1 parent 9d17b34 commit 47db249

File tree

29 files changed

+75
-131
lines changed

29 files changed

+75
-131
lines changed

Cargo.lock

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ gitoxide-core-async-client = ["gitoxide-core/async-client", "futures-lite"]
168168
anyhow = "1.0.42"
169169

170170
gitoxide-core = { version = "^0.46.0", path = "gitoxide-core" }
171+
gix-date= { version = "^0.9.4", path = "gix-date" }
171172
gix-features = { version = "^0.41.1", path = "gix-features" }
172173
gix = { version = "^0.71.0", path = "gix", default-features = false }
173174

examples/log.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ fn run(args: Args) -> anyhow::Result<()> {
150150
commit_ref.author.actor().write_to(&mut buf)?;
151151
buf.into()
152152
},
153-
time: commit_ref.author.time.format(format::DEFAULT),
153+
time: gix_date::Time::from_bytes(commit_ref.author.time)?.format(format::DEFAULT),
154154
message: commit_ref.message.to_owned(),
155155
})
156156
}),

gitoxide-core/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ serde = ["gix/serde", "dep:serde_json", "dep:serde", "bytesize/serde"]
5050
[dependencies]
5151
# deselect everything else (like "performance") as this should be controllable by the parent application.
5252
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"] }
53+
gix-date = { version = "^0.9.4", path = "../gix-date" }
5354
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"] }
5455
gix-transport-configuration-only = { package = "gix-transport", version = "^0.46.0", path = "../gix-transport", default-features = false }
5556
gix-archive-for-configuration-only = { package = "gix-archive", version = "^0.20.0", path = "../gix-archive", optional = true, features = ["tar", "tar_gz"] }

gitoxide-core/src/hours/core.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub fn estimate_hours(
3131
let mut cur = commits.next().expect("at least one commit if we are here");
3232

3333
for next in commits {
34-
let change_in_minutes = (next.time.seconds.saturating_sub(cur.time.seconds)) as f32 / MINUTES_PER_HOUR;
34+
let change_in_minutes = (next.seconds().saturating_sub(cur.seconds())) as f32 / MINUTES_PER_HOUR;
3535
if change_in_minutes < MAX_COMMIT_DIFFERENCE_IN_MINUTES {
3636
hours += change_in_minutes / MINUTES_PER_HOUR;
3737
} else {

gitoxide-core/src/hours/mod.rs

+3-9
Original file line numberDiff line numberDiff line change
@@ -82,22 +82,16 @@ where
8282
};
8383
let name = string_ref(author.name.as_ref());
8484
let email = string_ref(author.email.as_ref());
85+
let time = string_ref(author.time.as_ref());
8586

86-
out.push((
87-
commit_idx,
88-
actor::SignatureRef {
89-
name,
90-
email,
91-
time: author.time,
92-
},
93-
));
87+
out.push((commit_idx, actor::SignatureRef { name, email, time }));
9488
}
9589
}
9690
out.shrink_to_fit();
9791
out.sort_by(|a, b| {
9892
a.1.email
9993
.cmp(b.1.email)
100-
.then(a.1.time.seconds.cmp(&b.1.time.seconds).reverse())
94+
.then(a.1.seconds().cmp(&b.1.seconds()).reverse())
10195
});
10296
Ok(out)
10397
});

gitoxide-core/src/query/engine/command.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ impl query::Engine {
7676
usize,
7777
) = row?;
7878
let id = gix::ObjectId::from(hash);
79-
let commit_time = id.attach(&self.repo).object()?.into_commit().committer()?.time;
79+
let commit_time = gix_date::Time::from_bytes(
80+
id.attach(&self.repo).object()?.into_commit().committer()?.time,
81+
)?;
8082
let mode = FileMode::from_usize(mode).context("invalid file mode")?;
8183
info.push(trace_path::Info {
8284
id,

gitoxide-core/src/repository/archive.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ fn fetch_rev_info(
8484
Ok(match object.kind {
8585
gix::object::Kind::Commit => {
8686
let commit = object.into_commit();
87-
(Some(commit.committer()?.time.seconds), commit.tree_id()?.detach())
87+
(Some(commit.committer()?.seconds()), commit.tree_id()?.detach())
8888
}
8989
gix::object::Kind::Tree => (None, object.id),
9090
gix::object::Kind::Tag => fetch_rev_info(object.peel_to_kind(gix::object::Kind::Commit)?)?,

gix-blame/src/file/function.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,7 @@ type CommitTime = i64;
672672
fn commit_time(commit: gix_traverse::commit::Either<'_, '_>) -> Result<CommitTime, gix_object::decode::Error> {
673673
match commit {
674674
gix_traverse::commit::Either::CommitRefIter(commit_ref_iter) => {
675-
commit_ref_iter.committer().map(|c| c.time.seconds)
675+
commit_ref_iter.committer().map(|c| c.seconds())
676676
}
677677
gix_traverse::commit::Either::CachedCommit(commit) => Ok(commit.committer_timestamp() as i64),
678678
}
@@ -701,7 +701,7 @@ fn collect_parents(
701701
for id in commit_ref_iter.parent_ids() {
702702
let parent = odb.find_commit_iter(id.as_ref(), buf).ok();
703703
let parent_commit_time = parent
704-
.and_then(|parent| parent.committer().ok().map(|committer| committer.time.seconds))
704+
.and_then(|parent| parent.committer().ok().map(|committer| committer.seconds()))
705705
.unwrap_or_default();
706706
parent_ids.push((id, parent_commit_time));
707707
}

gix-mailmap/src/snapshot/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -157,17 +157,17 @@ fn enriched_signature<'a>(
157157
(Some(new_email), Some(new_name)) => Signature {
158158
email: new_email.to_owned().into(),
159159
name: new_name.to_owned().into(),
160-
time,
160+
time: time.into(),
161161
},
162162
(Some(new_email), None) => Signature {
163163
email: new_email.to_owned().into(),
164164
name: name.into(),
165-
time,
165+
time: time.into(),
166166
},
167167
(None, Some(new_name)) => Signature {
168168
email: email.into(),
169169
name: new_name.to_owned().into(),
170-
time,
170+
time: time.into(),
171171
},
172172
(None, None) => unreachable!("BUG: ResolvedSignatures don't exist here when nothing is set"),
173173
}

gix-mailmap/src/snapshot/signature.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ pub struct Signature<'a> {
1111
/// The possibly mapped email.
1212
pub email: Cow<'a, BStr>,
1313
/// The time stamp at which the signature is performed.
14-
pub time: gix_date::Time,
14+
pub time: Cow<'a, BStr>,
1515
}
1616

1717
impl<'a> From<Signature<'a>> for gix_actor::Signature {
1818
fn from(s: Signature<'a>) -> Self {
1919
gix_actor::Signature {
2020
name: s.name.into_owned(),
2121
email: s.email.into_owned(),
22-
time: s.time,
22+
time: s.time.into_owned(),
2323
}
2424
}
2525
}
@@ -29,7 +29,7 @@ impl<'a> From<gix_actor::SignatureRef<'a>> for Signature<'a> {
2929
Signature {
3030
name: s.name.into(),
3131
email: s.email.into(),
32-
time: s.time,
32+
time: s.time.into(),
3333
}
3434
}
3535
}

gix-mailmap/tests/snapshot/mod.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -161,11 +161,6 @@ fn signature(name: &str, email: &str) -> gix_actor::Signature {
161161
gix_actor::Signature {
162162
name: name.into(),
163163
email: email.into(),
164-
time: gix_date::Time {
165-
// marker
166-
seconds: 42,
167-
offset: 53,
168-
sign: gix_date::time::Sign::Minus,
169-
},
164+
time: b"42 +0800".into(),
170165
}
171166
}

gix-odb/tests/odb/store/loose.rs

+5-10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use std::sync::atomic::AtomicBool;
22

3-
use gix_date::{time::Sign, SecondsSinceUnixEpoch, Time};
43
use gix_features::progress;
54
use gix_object::bstr::ByteSlice;
65
use gix_odb::loose::Store;
@@ -285,7 +284,7 @@ cjHJZXWmV4CcRfmLsXzU8s2cR9A0DBvOxhPD1TlKC2JhBFXigjuL9U4Rbq9tdegB
285284
"
286285
.as_bstr(),
287286
),
288-
tagger: Some(signature(1528473343)),
287+
tagger: Some(signature(b"1528473343 +0200")),
289288
};
290289
assert_eq!(o.decode()?.as_tag().expect("tag"), &expected);
291290
Ok(())
@@ -300,8 +299,8 @@ cjHJZXWmV4CcRfmLsXzU8s2cR9A0DBvOxhPD1TlKC2JhBFXigjuL9U4Rbq9tdegB
300299
let expected = CommitRef {
301300
tree: b"6ba2a0ded519f737fd5b8d5ccfb141125ef3176f".as_bstr(),
302301
parents: vec![].into(),
303-
author: signature(1528473303),
304-
committer: signature(1528473303),
302+
author: signature(b"1528473303 +0200"),
303+
committer: signature(b"1528473303 +0200"),
305304
encoding: None,
306305
message: b"initial commit\n".as_bstr(),
307306
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())]
@@ -429,14 +428,10 @@ cjHJZXWmV4CcRfmLsXzU8s2cR9A0DBvOxhPD1TlKC2JhBFXigjuL9U4Rbq9tdegB
429428
}
430429
}
431430

432-
fn signature(seconds: SecondsSinceUnixEpoch) -> gix_actor::SignatureRef<'static> {
431+
fn signature(time: &[u8]) -> gix_actor::SignatureRef<'_> {
433432
gix_actor::SignatureRef {
434433
name: b"Sebastian Thiel".as_bstr(),
435434
email: b"[email protected]".as_bstr(),
436-
time: Time {
437-
seconds,
438-
offset: 7200,
439-
sign: Sign::Plus,
440-
},
435+
time: time.as_bstr(),
441436
}
442437
}

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

+2-11
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,6 @@ pub mod decode {
190190
#[cfg(test)]
191191
mod test {
192192
use super::*;
193-
use gix_date::{time::Sign, Time};
194193

195194
/// Convert a hexadecimal hash into its corresponding `ObjectId` or _panic_.
196195
fn hex_to_oid(hex: &str) -> gix_hash::ObjectId {
@@ -250,11 +249,7 @@ pub mod decode {
250249
signature: gix_actor::SignatureRef {
251250
name: b"name".as_bstr(),
252251
email: b"[email protected]".as_bstr(),
253-
time: Time {
254-
seconds: 1234567890,
255-
offset: 0,
256-
sign: Sign::Minus
257-
}
252+
time: b"1234567890 -0000".as_bstr()
258253
},
259254
message: b"".as_bstr(),
260255
}
@@ -278,11 +273,7 @@ pub mod decode {
278273
signature: gix_actor::SignatureRef {
279274
name: b"Sebastian Thiel".as_bstr(),
280275
email: b"[email protected]".as_bstr(),
281-
time: Time {
282-
seconds: 1618030561,
283-
offset: 28800,
284-
sign: Sign::Plus,
285-
},
276+
time: b"1618030561 +0800".as_bstr(),
286277
},
287278
message: b"pull --ff-only: Fast-forward".as_bstr(),
288279
};

gix-ref/src/store/file/loose/reflog/create_or_update/tests.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use gix_actor::Signature;
2-
use gix_date::{time::Sign, Time};
32
use gix_object::bstr::ByteSlice;
43
use gix_testtools::tempfile::TempDir;
54

@@ -57,11 +56,7 @@ fn missing_reflog_creates_it_even_if_similarly_named_empty_dir_exists_and_append
5756
let committer = Signature {
5857
name: "committer".into(),
5958
email: "[email protected]".into(),
60-
time: Time {
61-
seconds: 1234,
62-
offset: 1800,
63-
sign: Sign::Plus,
64-
},
59+
time: "1234 +0800".into(),
6560
};
6661
store.reflog_create_or_append(
6762
full_name,

gix-ref/tests/refs/file/log.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ mod line {
3838
let line = log::LineRef::from_bytes(b"7b114132d03c468a9cd97836901553658c9792de 306cdbab5457c323d1201aa8a59b3639f600a758 First Last <[email protected]> 1727013187 +0200\trebase (pick): Replace Into<Range<u32>> by From<LineRange>")?;
3939
assert_eq!(line.signature.name, "First Last");
4040
assert_eq!(line.signature.email, "[email protected]");
41-
assert_eq!(line.signature.time.seconds, 1727013187);
41+
assert_eq!(line.signature.seconds(), 1727013187);
4242
assert_eq!(
4343
line.message,
4444
"rebase (pick): Replace Into<Range<u32>> by From<LineRange>"

gix-ref/tests/refs/file/transaction/mod.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
pub(crate) mod prepare_and_commit {
2-
use gix_date::{time::Sign, Time};
32
use gix_hash::ObjectId;
43
use gix_object::bstr::BString;
54
use gix_ref::{
@@ -30,11 +29,7 @@ pub(crate) mod prepare_and_commit {
3029
gix_actor::Signature {
3130
name: "committer".into(),
3231
email: "[email protected]".into(),
33-
time: Time {
34-
seconds: 1234,
35-
offset: 1800,
36-
sign: Sign::Plus,
37-
},
32+
time: "1234 +0800".into(),
3833
}
3934
}
4035

gix-revwalk/src/graph/commit.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ impl<'graph, 'cache> LazyCommit<'graph, 'cache> {
2020
/// Note that this can only fail if the commit is backed by the object database *and* parsing fails.
2121
pub fn committer_timestamp(&self) -> Result<SecondsSinceUnixEpoch, gix_object::decode::Error> {
2222
Ok(match &self.backing {
23-
Either::Left(buf) => gix_object::CommitRefIter::from_bytes(buf).committer()?.time.seconds,
23+
Either::Left(buf) => gix_object::CommitRefIter::from_bytes(buf).committer()?.seconds(),
2424
Either::Right((cache, pos)) => cache.commit_at(*pos).committer_timestamp() as SecondsSinceUnixEpoch, // a cast as we cannot represent the error and trying seems overkill
2525
})
2626
}
@@ -38,10 +38,7 @@ impl<'graph, 'cache> LazyCommit<'graph, 'cache> {
3838
&self,
3939
) -> Result<(Option<Generation>, SecondsSinceUnixEpoch), gix_object::decode::Error> {
4040
Ok(match &self.backing {
41-
Either::Left(buf) => (
42-
None,
43-
gix_object::CommitRefIter::from_bytes(buf).committer()?.time.seconds,
44-
),
41+
Either::Left(buf) => (None, gix_object::CommitRefIter::from_bytes(buf).committer()?.seconds()),
4542
Either::Right((cache, pos)) => {
4643
let commit = cache.commit_at(*pos);
4744
(
@@ -69,7 +66,7 @@ impl<'graph, 'cache> LazyCommit<'graph, 'cache> {
6966
Token::Parent { id } => parents.push(id),
7067
Token::Author { .. } => {}
7168
Token::Committer { signature } => {
72-
timestamp = Some(signature.time.seconds);
69+
timestamp = Some(signature.seconds());
7370
break;
7471
}
7572
_ => {

gix-traverse/src/commit/simple.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ mod init {
150150
let state = &mut self.state;
151151
for commit_id in state.next.drain(..) {
152152
let commit_iter = self.objects.find_commit_iter(&commit_id, &mut state.buf)?;
153-
let time = commit_iter.committer()?.time.seconds;
153+
let time = commit_iter.committer()?.seconds();
154154
let key = to_queue_key(time, order);
155155
match (cutoff_time, order) {
156156
(Some(cutoff_time), _) if time >= cutoff_time => {
@@ -351,7 +351,7 @@ mod init {
351351

352352
let parent = self.objects.find_commit_iter(id.as_ref(), &mut state.parents_buf).ok();
353353
let parent_commit_time = parent
354-
.and_then(|parent| parent.committer().ok().map(|committer| committer.time.seconds))
354+
.and_then(|parent| parent.committer().ok().map(|committer| committer.seconds()))
355355
.unwrap_or_default();
356356

357357
let time = to_queue_key(parent_commit_time, order);

gix-traverse/src/commit/topo/iter.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ pub(super) fn gen_and_commit_time(c: Either<'_, '_>) -> Result<GenAndCommitTime,
304304
Ok(T::Parent { .. }) => continue,
305305
Ok(T::Author { .. }) => continue,
306306
Ok(T::Committer { signature }) => {
307-
commit_time = signature.time.seconds;
307+
commit_time = signature.seconds();
308308
break;
309309
}
310310
Ok(_unused_token) => break,

gix/src/commit.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ pub mod describe {
126126
let (prio, tag_time) = match target_id {
127127
Some(target_id) if peeled_id != *target_id => {
128128
let tag = repo.find_object(target_id).ok()?.try_into_tag().ok()?;
129-
(1, tag.tagger().ok()??.time.seconds)
129+
(1, tag.tagger().ok()??.seconds())
130130
}
131131
_ => (0, 0),
132132
};
@@ -159,7 +159,7 @@ pub mod describe {
159159
// TODO: we assume direct refs for tags, which is the common case, but it doesn't have to be
160160
// so rather follow symrefs till the first object and then peel tags after the first object was found.
161161
let tag = r.try_id()?.object().ok()?.try_into_tag().ok()?;
162-
let tag_time = tag.tagger().ok().and_then(|s| s.map(|s| s.time.seconds)).unwrap_or(0);
162+
let tag_time = tag.tagger().ok().and_then(|s| s.map(|s| s.seconds())).unwrap_or(0);
163163
let commit_id = tag.target_id().ok()?.object().ok()?.try_into_commit().ok()?.id;
164164
Some((commit_id, tag_time, Cow::<BStr>::from(r.name().shorten().to_owned())))
165165
})

gix/src/config/tree/sections/gitoxide.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -511,11 +511,11 @@ mod subsections {
511511

512512
impl Commit {
513513
/// The `gitoxide.commit.authorDate` key.
514-
pub const AUTHOR_DATE: keys::Time =
515-
keys::Time::new_time("authorDate", &Gitoxide::COMMIT).with_environment_override("GIT_AUTHOR_DATE");
514+
pub const AUTHOR_DATE: keys::Any =
515+
keys::Any::new("authorDate", &Gitoxide::COMMIT).with_environment_override("GIT_AUTHOR_DATE");
516516
/// The `gitoxide.commit.committerDate` key.
517-
pub const COMMITTER_DATE: keys::Time =
518-
keys::Time::new_time("committerDate", &Gitoxide::COMMIT).with_environment_override("GIT_COMMITTER_DATE");
517+
pub const COMMITTER_DATE: keys::Any =
518+
keys::Any::new("committerDate", &Gitoxide::COMMIT).with_environment_override("GIT_COMMITTER_DATE");
519519
}
520520

521521
impl Section for Commit {

0 commit comments

Comments
 (0)