Skip to content

Commit 94dcdca

Browse files
author
Pierre Chevalier
committed
fix!: Store the raw time in Commit
1 parent 2c0c32a commit 94dcdca

File tree

7 files changed

+62
-103
lines changed

7 files changed

+62
-103
lines changed

gix-object/src/commit/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ impl<'a> CommitRef<'a> {
112112

113113
/// Returns the time at which this commit was created.
114114
pub fn time(&self) -> gix_date::Time {
115-
self.committer.time
115+
gix_date::Time::from_bytes(self.committer.time).expect("Time from Git should be valid")
116116
}
117117
}
118118

gix-object/tests/object/commit/from_bytes.rs

+21-42
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use crate::{
33
fixture_name, linus_signature, signature,
44
};
55
use gix_actor::SignatureRef;
6-
use gix_date::{time::Sign, Time};
76
use gix_object::{bstr::ByteSlice, commit::message::body::TrailerRef, CommitRef};
87
use smallvec::SmallVec;
98

@@ -12,11 +11,7 @@ fn invalid_timestsamp() {
1211
let actor = gix_actor::SignatureRef {
1312
name: b"Name".as_bstr(),
1413
email: b"[email protected]".as_bstr(),
15-
time: Time {
16-
seconds: 1312735823,
17-
offset: 0,
18-
sign: Sign::Plus,
19-
},
14+
time: b"1312735823 +051800".as_bstr(),
2015
};
2116
assert_eq!(
2217
CommitRef::from_bytes(&fixture_name("commit", "invalid-timestamp.txt"))
@@ -39,11 +34,7 @@ fn invalid_email_of_committer() {
3934
let actor = gix_actor::SignatureRef {
4035
name: b"Gregor Hartmann".as_bstr(),
4136
email: b"gh <Gregor Hartmann<[email protected]".as_bstr(),
42-
time: Time {
43-
seconds: 1282910542,
44-
offset: 2 * 60 * 60,
45-
sign: Sign::Plus,
46-
},
37+
time: b"1282910542 +0200".as_bstr(),
4738
};
4839
assert_eq!(
4940
CommitRef::from_bytes(&fixture_name("commit", "invalid-actor.txt"))
@@ -67,8 +58,8 @@ fn unsigned() -> crate::Result {
6758
CommitRef {
6859
tree: b"1b2dfb4ac5e42080b682fc676e9738c94ce6d54d".as_bstr(),
6960
parents: SmallVec::default(),
70-
author: signature(1592437401),
71-
committer: signature(1592437401),
61+
author: signature(b"1592437401 +0800"),
62+
committer: signature(b"1592437401 +0800"),
7263
encoding: None,
7364
message: b"without sig".as_bstr(),
7465
extra_headers: vec![]
@@ -84,8 +75,8 @@ fn whitespace() -> crate::Result {
8475
CommitRef {
8576
tree: b"9bed6275068a0575243ba8409253e61af81ab2ff".as_bstr(),
8677
parents: SmallVec::from(vec![b"26b4df046d1776c123ac69d918f5aec247b58cc6".as_bstr()]),
87-
author: signature(1592448450),
88-
committer: signature(1592448450),
78+
author: signature(b"1592448450 +0800"),
79+
committer: signature(b"1592448450 +0800"),
8980
encoding: None,
9081
message: b" nl".as_bstr(), // this one had a \n trailing it, but git seems to trim that
9182
extra_headers: vec![]
@@ -101,8 +92,8 @@ fn signed_singleline() -> crate::Result {
10192
CommitRef {
10293
tree: b"00fc39317701176e326974ce44f5bd545a32ec0b".as_bstr(),
10394
parents: SmallVec::from(vec![b"09d8d3a12e161a7f6afb522dbe8900a9c09bce06".as_bstr()]),
104-
author: signature(1592391367),
105-
committer: signature(1592391367),
95+
author: signature(b"1592391367 +0800"),
96+
committer: signature(b"1592391367 +0800"),
10697
encoding: None,
10798
message: b"update tasks\n".as_bstr(),
10899
extra_headers: vec![(b"gpgsig".as_bstr(), b"magic:signature".as_bstr().into())]
@@ -120,8 +111,8 @@ fn mergetag() -> crate::Result {
120111
b"44ebe016df3aad96e3be8f95ec52397728dd7701".as_bstr(),
121112
b"8d485da0ddee79d0e6713405694253d401e41b93".as_bstr(),
122113
]),
123-
author: linus_signature(1591996221),
124-
committer: linus_signature(1591996221),
114+
author: linus_signature(b"1591996221 -0700"),
115+
committer: linus_signature(b"1591996221 -0700"),
125116
encoding: None,
126117
message: LONG_MESSAGE.as_bytes().as_bstr(),
127118
extra_headers: vec![(
@@ -142,8 +133,8 @@ fn signed() -> crate::Result {
142133
CommitRef {
143134
tree: b"00fc39317701176e326974ce44f5bd545a32ec0b".as_bstr(),
144135
parents: SmallVec::from(vec![b"09d8d3a12e161a7f6afb522dbe8900a9c09bce06".as_bstr()]),
145-
author: signature(1592391367),
146-
committer: signature(1592391367),
136+
author: signature(b"1592391367 +0800"),
137+
committer: signature(b"1592391367 +0800"),
147138
encoding: None,
148139
message: b"update tasks\n".as_bstr(),
149140
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())]
@@ -159,8 +150,8 @@ fn signed_with_encoding() -> crate::Result {
159150
CommitRef {
160151
tree: b"1973afa74d87b2bb73fa884aaaa8752aec43ea88".as_bstr(),
161152
parents: SmallVec::from(vec![b"79c51cc86923e2b8ca0ee5c4eb75e48027133f9a".as_bstr()]),
162-
author: signature(1592448995),
163-
committer: signature(1592449083),
153+
author: signature(b"1592448995 +0800"),
154+
committer: signature(b"1592449083 +0800"),
164155
encoding: Some(b"ISO-8859-1".as_bstr()),
165156
message: b"encoding & sig".as_bstr(),
166157
extra_headers: vec![(b"gpgsig".as_bstr(), SIGNATURE.as_bstr().into())]
@@ -176,8 +167,8 @@ fn with_encoding() -> crate::Result {
176167
CommitRef {
177168
tree: b"4a1c03029e7407c0afe9fc0320b3258e188b115e".as_bstr(),
178169
parents: SmallVec::from(vec![b"7ca98aad461a5c302cb4c9e3acaaa6053cc67a62".as_bstr()]),
179-
author: signature(1592438199),
180-
committer: signature(1592438199),
170+
author: signature(b"1592438199 +0800"),
171+
committer: signature(b"1592438199 +0800"),
181172
encoding: Some("ISO-8859-1".into()),
182173
message: b"commit with encoding".as_bstr(),
183174
extra_headers: vec![]
@@ -191,11 +182,7 @@ fn pre_epoch() -> crate::Result {
191182
let signature = || SignatureRef {
192183
name: "Législateur".into(),
193184
email: "".into(),
194-
time: Time {
195-
seconds: -5263834140,
196-
offset: 540,
197-
sign: Sign::Plus,
198-
},
185+
time: b"-5263834140 +0009".as_bstr(),
199186
};
200187
assert_eq!(
201188
CommitRef::from_bytes(&fixture_name("commit", "pre-epoch.txt"))?,
@@ -217,11 +204,7 @@ fn double_dash_special_time_offset() -> crate::Result {
217204
let signature = || SignatureRef {
218205
name: "name".into(),
219206
email: "[email protected]".into(),
220-
time: Time {
221-
seconds: 1288373970,
222-
offset: -252000,
223-
sign: Sign::Minus,
224-
},
207+
time: "1288373970 --700".into(),
225208
};
226209
assert_eq!(
227210
CommitRef::from_bytes(&fixture_name("commit", "double-dash-date-offset.txt"))?,
@@ -243,11 +226,7 @@ fn with_trailer() -> crate::Result {
243226
let kim = SignatureRef {
244227
name: "Kim Altintop".into(),
245228
email: "[email protected]".into(),
246-
time: Time {
247-
seconds: 1631514803,
248-
offset: 7200,
249-
sign: Sign::Plus,
250-
},
229+
time: "1631514803 +0200".into(),
251230
};
252231
let backing = fixture_name("commit", "message-with-footer.txt");
253232
let commit = CommitRef::from_bytes(&backing)?;
@@ -336,8 +315,8 @@ fn merge() -> crate::Result {
336315
b"6a6054db4ce3c1e4e6a37f8c4d7acb63a4d6ad71".as_bstr(),
337316
b"c91d592913d47ac4e4a76daf16fd649b276e211e".as_bstr()
338317
]),
339-
author: signature(1592454703),
340-
committer: signature(1592454738),
318+
author: signature(b"1592454703 +0800"),
319+
committer: signature(b"1592454738 +0800"),
341320
encoding: Some("ISO-8859-1".into()),
342321
message: b"Merge branch 'branch'".as_bstr(),
343322
extra_headers: vec![]

gix-object/tests/object/commit/iter.rs

+21-17
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,19 @@ fn signed_with_encoding() -> crate::Result {
3333
id: hex_to_id("79c51cc86923e2b8ca0ee5c4eb75e48027133f9a")
3434
},
3535
Token::Author {
36-
signature: signature(1592448995)
36+
signature: signature(b"1592448995 +0800")
3737
},
3838
Token::Committer {
39-
signature: signature(1592449083)
39+
signature: signature(b"1592449083 +0800")
4040
},
4141
Token::Encoding(b"ISO-8859-1".as_bstr()),
4242
Token::ExtraHeader((b"gpgsig".as_bstr(), SIGNATURE.as_bytes().as_bstr().into())),
4343
Token::Message(b"encoding & sig".as_bstr()),
4444
]
4545
);
4646

47-
assert_eq!(iter.author().ok(), Some(signature(1592448995)));
48-
assert_eq!(iter.committer().ok(), Some(signature(1592449083)));
47+
assert_eq!(iter.author().ok(), Some(signature(b"1592448995 +0800")));
48+
assert_eq!(iter.committer().ok(), Some(signature(b"1592449083 +0800")));
4949
Ok(())
5050
}
5151

@@ -61,10 +61,10 @@ fn whitespace() -> crate::Result {
6161
id: hex_to_id("26b4df046d1776c123ac69d918f5aec247b58cc6")
6262
},
6363
Token::Author {
64-
signature: signature(1592448450)
64+
signature: signature(b"1592448450 +0800")
6565
},
6666
Token::Committer {
67-
signature: signature(1592448450)
67+
signature: signature(b"1592448450 +0800")
6868
},
6969
Token::Message(b" nl".as_bstr())
7070
]
@@ -81,10 +81,10 @@ fn unsigned() -> crate::Result {
8181
id: hex_to_id("1b2dfb4ac5e42080b682fc676e9738c94ce6d54d")
8282
},
8383
Token::Author {
84-
signature: signature(1592437401)
84+
signature: signature(b"1592437401 +0800")
8585
},
8686
Token::Committer {
87-
signature: signature(1592437401)
87+
signature: signature(b"1592437401 +0800")
8888
},
8989
Token::Message(b"without sig".as_bstr())
9090
]
@@ -104,10 +104,10 @@ fn signed_singleline() -> crate::Result {
104104
id: hex_to_id("09d8d3a12e161a7f6afb522dbe8900a9c09bce06")
105105
},
106106
Token::Author {
107-
signature: signature(1592391367)
107+
signature: signature(b"1592391367 +0800")
108108
},
109109
Token::Committer {
110-
signature: signature(1592391367)
110+
signature: signature(b"1592391367 +0800")
111111
},
112112
Token::ExtraHeader((b"gpgsig".as_bstr(), b"magic:signature".as_bstr().into())),
113113
Token::Message(b"update tasks\n".as_bstr()),
@@ -151,10 +151,10 @@ fn mergetag() -> crate::Result {
151151
id: hex_to_id("8d485da0ddee79d0e6713405694253d401e41b93")
152152
},
153153
Token::Author {
154-
signature: linus_signature(1591996221)
154+
signature: linus_signature(b"1591996221 -0700")
155155
},
156156
Token::Committer {
157-
signature: linus_signature(1591996221)
157+
signature: linus_signature(b"1591996221 -0700")
158158
},
159159
Token::ExtraHeader((b"mergetag".as_bstr(), MERGE_TAG.as_bytes().as_bstr().into())),
160160
Token::Message(LONG_MESSAGE.into()),
@@ -186,7 +186,7 @@ mod method {
186186
);
187187
assert_eq!(
188188
iter.signatures().collect::<Vec<_>>(),
189-
vec![signature(1592437401), signature(1592437401)]
189+
vec![signature(b"1592437401 +0800"), signature(b"1592437401 +0800")]
190190
);
191191
assert_eq!(iter.parent_ids().count(), 0);
192192
Ok(())
@@ -198,11 +198,15 @@ mod method {
198198
let iter = CommitRefIter::from_bytes(&input);
199199
assert_eq!(
200200
iter.signatures().collect::<Vec<_>>(),
201-
vec![signature(1592437401), signature(1592437401)]
201+
vec![signature(b"1592437401 +0800"), signature(b"1592437401 +0800")]
202+
);
203+
assert_eq!(iter.author().ok(), Some(signature(b"1592437401 +0800")));
204+
assert_eq!(iter.committer().ok(), Some(signature(b"1592437401 +0800")));
205+
assert_eq!(
206+
iter.author().ok(),
207+
Some(signature(b"1592437401 +0800")),
208+
"it's not consuming"
202209
);
203-
assert_eq!(iter.author().ok(), Some(signature(1592437401)));
204-
assert_eq!(iter.committer().ok(), Some(signature(1592437401)));
205-
assert_eq!(iter.author().ok(), Some(signature(1592437401)), "it's not consuming");
206210
Ok(())
207211
}
208212

gix-object/tests/object/commit/message.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,6 @@ mod summary {
224224
use std::borrow::Cow;
225225

226226
use gix_actor::SignatureRef;
227-
use gix_date::{time::Sign, Time};
228227
use gix_object::{
229228
bstr::{BStr, ByteSlice},
230229
commit::MessageRef,
@@ -236,11 +235,7 @@ mod summary {
236235
let actor = SignatureRef {
237236
name: "name".into(),
238237
email: "email".into(),
239-
time: Time {
240-
seconds: 0,
241-
offset: 0,
242-
sign: Sign::Plus,
243-
},
238+
time: "0 0000".into(),
244239
};
245240
assert_eq!(
246241
CommitRef {

gix-object/tests/object/commit/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ fn invalid() {
172172
assert_eq!(
173173
CommitRef::from_bytes(partial_commit).unwrap_err().to_string(),
174174
if cfg!(feature = "verbose-object-parsing-errors") {
175-
"object parsing failed at `1`\nexpected `author <signature>`"
175+
"object parsing failed at ``\nexpected `author <signature>`"
176176
} else {
177177
"object parsing failed"
178178
}

gix-object/tests/object/main.rs

+6-15
Original file line numberDiff line numberDiff line change
@@ -81,39 +81,30 @@ fn fixture_name(kind: &str, path: &str) -> Vec<u8> {
8181
fn size_in_memory() {
8282
let actual = std::mem::size_of::<gix_object::Object>();
8383
assert!(
84-
actual <= 264,
85-
"{actual} <= 264: Prevent unexpected growth of what should be lightweight objects"
84+
actual <= 272,
85+
"{actual} <= 272: Prevent unexpected growth of what should be lightweight objects"
8686
);
8787
}
8888

8989
fn hex_to_id(hex: &str) -> ObjectId {
9090
ObjectId::from_hex(hex.as_bytes()).expect("40 bytes hex")
9191
}
9292

93-
use gix_date::{time::Sign, SecondsSinceUnixEpoch, Time};
9493

95-
fn signature(seconds: SecondsSinceUnixEpoch) -> gix_actor::SignatureRef<'static> {
94+
fn signature(time: &[u8]) -> gix_actor::SignatureRef<'_> {
9695
use gix_object::bstr::ByteSlice;
9796
gix_actor::SignatureRef {
9897
name: b"Sebastian Thiel".as_bstr(),
9998
email: b"[email protected]".as_bstr(),
100-
time: Time {
101-
seconds,
102-
offset: 28800,
103-
sign: Sign::Plus,
104-
},
99+
time: time.as_bstr(),
105100
}
106101
}
107102

108-
fn linus_signature(seconds: SecondsSinceUnixEpoch) -> gix_actor::SignatureRef<'static> {
103+
fn linus_signature(time: &[u8]) -> gix_actor::SignatureRef<'_> {
109104
use gix_object::bstr::ByteSlice;
110105
gix_actor::SignatureRef {
111106
name: b"Linus Torvalds".as_bstr(),
112107
email: b"[email protected]".as_bstr(),
113-
time: Time {
114-
seconds,
115-
offset: -25200,
116-
sign: Sign::Minus,
117-
},
108+
time: time.as_bstr(),
118109
}
119110
}

0 commit comments

Comments
 (0)