Skip to content

Commit 2fe0987

Browse files
committed
adapt to changes in gix-date and gix-actor
1 parent b704026 commit 2fe0987

File tree

33 files changed

+171
-205
lines changed

33 files changed

+171
-205
lines changed

examples/log.rs

Lines changed: 1 addition & 1 deletion
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: gix_date::Time::from_bytes(commit_ref.author.time)?.format(format::DEFAULT),
153+
time: commit_ref.author.time()?.format(format::DEFAULT),
154154
message: commit_ref.message.to_owned(),
155155
})
156156
}),

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

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

gix-actor/tests/signature/mod.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,7 @@ fn round_trip() -> Result<(), Box<dyn std::error::Error>> {
6565
];
6666

6767
for input in DEFAULTS {
68-
let signature: Signature = gix_actor::SignatureRef::from_bytes::<()>(input)
69-
.unwrap()
70-
.try_into()
71-
.unwrap();
68+
let signature: Signature = gix_actor::SignatureRef::from_bytes::<()>(input).unwrap().into();
7269
let mut output = Vec::new();
7370
signature.write_to(&mut output)?;
7471
assert_eq!(output.as_bstr(), input.as_bstr());
@@ -95,7 +92,7 @@ fn parse_timestamp_with_trailing_digits() {
9592
SignatureRef {
9693
name: "first last".into(),
9794
email: "[email protected]".into(),
98-
time: "1312735823 +051800".into(),
95+
time: "1312735823 +051800",
9996
}
10097
);
10198

@@ -106,7 +103,7 @@ fn parse_timestamp_with_trailing_digits() {
106103
SignatureRef {
107104
name: "first last".into(),
108105
email: "[email protected]".into(),
109-
time: "1312735823 +0518".into(),
106+
time: "1312735823 +0518",
110107
}
111108
);
112109
}
@@ -120,7 +117,7 @@ fn parse_missing_timestamp() {
120117
SignatureRef {
121118
name: "first last".into(),
122119
email: "[email protected]".into(),
123-
time: "".into(),
120+
time: ""
124121
}
125122
);
126123
}

gix-date/src/parse.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ impl TimeBuf {
3636
}
3737

3838
/// Clear the previous content.
39-
pub fn clear(&mut self) {
39+
fn clear(&mut self) {
4040
self.buf.clear();
4141
}
4242
}

gix-mailmap/src/snapshot/mod.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,11 @@ impl Snapshot {
138138
///
139139
/// Note that this method will always allocate.
140140
pub fn resolve(&self, signature: gix_actor::SignatureRef<'_>) -> gix_actor::Signature {
141-
self.try_resolve(signature).unwrap_or_else(|| signature.to_owned())
141+
self.try_resolve(signature).unwrap_or_else(|| gix_actor::Signature {
142+
name: signature.name.to_owned(),
143+
email: signature.email.to_owned(),
144+
time: signature.time().unwrap_or_default(),
145+
})
142146
}
143147

144148
/// 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>(
157161
(Some(new_email), Some(new_name)) => Signature {
158162
email: new_email.to_owned().into(),
159163
name: new_name.to_owned().into(),
160-
time: gix_date::Time::from_bytes(time).unwrap_or_default(),
164+
time: time.parse().unwrap_or_default(),
161165
},
162166
(Some(new_email), None) => Signature {
163167
email: new_email.to_owned().into(),
164168
name: name.into(),
165-
time: gix_date::Time::from_bytes(time).unwrap_or_default(),
169+
time: time.parse().unwrap_or_default(),
166170
},
167171
(None, Some(new_name)) => Signature {
168172
email: email.into(),
169173
name: new_name.to_owned().into(),
170-
time: gix_date::Time::from_bytes(time).unwrap_or_default(),
174+
time: time.parse().unwrap_or_default(),
171175
},
172176
(None, None) => unreachable!("BUG: ResolvedSignatures don't exist here when nothing is set"),
173177
}

gix-mailmap/src/snapshot/signature.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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: gix_date::Time::from_bytes(s.time).unwrap_or_default(),
32+
time: s.time.parse().unwrap_or_default(),
3333
}
3434
}
3535
}

gix-mailmap/tests/snapshot/mod.rs

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,59 @@
1+
use gix_date::parse::TimeBuf;
12
use gix_mailmap::{Entry, Snapshot};
23
use gix_testtools::fixture_bytes;
34

45
#[test]
56
fn try_resolve() {
67
let snapshot = Snapshot::from_bytes(&fixture_bytes("typical.txt"));
7-
let mut buf = Vec::with_capacity(64);
8+
let mut buf = TimeBuf::default();
89
assert_eq!(
910
snapshot.try_resolve(signature("Foo", "[email protected]").to_ref(&mut buf)),
1011
Some(signature("Joe R. Developer", "[email protected]")),
1112
"resolved signatures contain all original fields, and normalize the email as well to match the one that it was looked up with"
1213
);
13-
buf.clear();
1414
assert_eq!(
1515
snapshot.try_resolve(signature("Joe", "[email protected]").to_ref(&mut buf)),
1616
Some(signature("Joe R. Developer", "[email protected]")),
1717
"name and email can be mapped specifically"
1818
);
1919

20-
buf.clear();
2120
assert_eq!(
2221
snapshot.try_resolve(signature("Jane", "jane@laptop.(none)").to_ref(&mut buf)),
2322
Some(signature("Jane Doe", "[email protected]")),
2423
"fix name and email by email"
2524
);
26-
buf.clear();
2725
assert_eq!(
2826
snapshot.try_resolve(signature("Jane", "jane@desktop.(none)").to_ref(&mut buf)),
2927
Some(signature("Jane Doe", "[email protected]")),
3028
"fix name and email by other email"
3129
);
3230

33-
buf.clear();
3431
assert_eq!(
3532
snapshot.try_resolve(signature("janE", "[email protected]").to_ref(&mut buf)),
3633
Some(signature("Jane Doe", "[email protected]")),
3734
"name and email can be mapped specifically, case insensitive matching of name"
3835
);
39-
buf.clear();
4036
assert_eq!(
4137
snapshot.resolve(signature("janE", "jane@ipad.(none)").to_ref(&mut buf)),
4238
signature("janE", "[email protected]"),
4339
"an email can be mapped by name and email specifically, both match case-insensitively"
4440
);
4541

4642
let sig = signature("Jane", "[email protected]");
47-
buf.clear();
4843
assert_eq!(snapshot.try_resolve(sig.to_ref(&mut buf)), None, "unmatched email");
4944

50-
buf.clear();
5145
assert_eq!(
5246
snapshot.resolve(sig.to_ref(&mut buf)),
5347
sig,
5448
"resolution always works here, returning a copy of the original"
5549
);
5650

5751
let sig = signature("Jean", "[email protected]");
58-
buf.clear();
5952
assert_eq!(
6053
snapshot.try_resolve(sig.to_ref(&mut buf)),
6154
None,
6255
"matched email, unmatched name"
6356
);
64-
buf.clear();
6557
assert_eq!(snapshot.resolve(sig.to_ref(&mut buf)), sig);
6658

6759
assert_eq!(
@@ -95,17 +87,15 @@ fn non_name_and_name_mappings_will_not_clash() {
9587
"old-email",
9688
),
9789
];
98-
let mut buf = Vec::with_capacity(64);
90+
let mut buf = TimeBuf::default();
9991
for entries in [entries.clone().into_iter().rev().collect::<Vec<_>>(), entries] {
10092
let snapshot = Snapshot::new(entries);
10193

102-
buf.clear();
10394
assert_eq!(
10495
snapshot.try_resolve(signature("replace-by-email", "Old-Email").to_ref(&mut buf)),
10596
Some(signature("new-name", "old-email")),
10697
"it can match by email only, and the email is normalized"
10798
);
108-
buf.clear();
10999
assert_eq!(
110100
snapshot.try_resolve(signature("old-name", "Old-Email").to_ref(&mut buf)),
111101
Some(signature("other-new-name", "other-new-email")),
@@ -130,28 +120,25 @@ fn non_name_and_name_mappings_will_not_clash() {
130120
#[test]
131121
fn overwrite_entries() {
132122
let snapshot = Snapshot::from_bytes(&fixture_bytes("overwrite.txt"));
133-
let mut buf = Vec::with_capacity(64);
123+
let mut buf = TimeBuf::default();
134124
assert_eq!(
135125
snapshot.try_resolve(signature("does not matter", "old-a-email").to_ref(&mut buf)),
136126
Some(signature("A-overwritten", "old-a-email")),
137127
"email only by email"
138128
);
139129

140-
buf.clear();
141130
assert_eq!(
142131
snapshot.try_resolve(signature("to be replaced", "old-b-EMAIL").to_ref(&mut buf)),
143132
Some(signature("B-overwritten", "new-b-email-overwritten")),
144133
"name and email by email"
145134
);
146135

147-
buf.clear();
148136
assert_eq!(
149137
snapshot.try_resolve(signature("old-c", "old-C-email").to_ref(&mut buf)),
150138
Some(signature("C-overwritten", "new-c-email-overwritten")),
151139
"name and email by name and email"
152140
);
153141

154-
buf.clear();
155142
assert_eq!(
156143
snapshot.try_resolve(signature("unchanged", "old-d-email").to_ref(&mut buf)),
157144
Some(signature("unchanged", "new-d-email-overwritten")),
@@ -178,6 +165,6 @@ fn signature(name: &str, email: &str) -> gix_actor::Signature {
178165
gix_actor::Signature {
179166
name: name.into(),
180167
email: email.into(),
181-
time: gix_date::parse_raw("42 +0800").unwrap(),
168+
time: gix_date::parse_header("42 +0800").unwrap(),
182169
}
183170
}

gix-object/src/commit/mod.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,14 @@ impl<'a> CommitRef<'a> {
110110
MessageRef::from_bytes(self.message)
111111
}
112112

113-
/// Returns the time at which this commit was created.
113+
/// Returns the time at which this commit was created, or a default time if it could not be parsed.
114114
pub fn time(&self) -> gix_date::Time {
115-
gix_date::Time::from_bytes(self.committer.time).expect("Time from Git should be valid")
115+
self.committer.time.parse().unwrap_or_default()
116+
}
117+
118+
/// Returns the time at which this commit was created.
119+
pub fn try_time(&self) -> Result<gix_date::Time, gix_date::parse::Error> {
120+
self.committer.time.parse()
116121
}
117122
}
118123

gix-object/src/commit/write.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@ impl crate::WriteTo for Commit {
1111
for parent in &self.parents {
1212
encode::trusted_header_id(b"parent", parent, &mut out)?;
1313
}
14-
let mut buf = Vec::with_capacity(64);
14+
let mut buf = gix_date::parse::TimeBuf::default();
1515
encode::trusted_header_signature(b"author", &self.author.to_ref(&mut buf), &mut out)?;
16-
buf.clear();
1716
encode::trusted_header_signature(b"committer", &self.committer.to_ref(&mut buf), &mut out)?;
1817
if let Some(encoding) = self.encoding.as_ref() {
1918
encode::header_field(b"encoding", encoding, &mut out)?;

gix-object/src/tag/write.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use std::io;
22

3-
use bstr::BStr;
4-
53
use crate::{encode, encode::NL, Kind, Tag, TagRef};
4+
use bstr::BStr;
5+
use gix_date::parse::TimeBuf;
66

77
/// An Error used in [`Tag::write_to()`][crate::WriteTo::write_to()].
88
#[derive(Debug, thiserror::Error)]
@@ -26,7 +26,7 @@ impl crate::WriteTo for Tag {
2626
encode::trusted_header_field(b"type", self.target_kind.as_bytes(), out)?;
2727
encode::header_field(b"tag", validated_name(self.name.as_ref())?, out)?;
2828
if let Some(tagger) = &self.tagger {
29-
let mut buf = Vec::with_capacity(64);
29+
let mut buf = TimeBuf::default();
3030
encode::trusted_header_signature(b"tagger", &tagger.to_ref(&mut buf), out)?;
3131
}
3232

0 commit comments

Comments
 (0)