Skip to content

Commit 6fe3e58

Browse files
committed
post-update signature stuff
Adapt to changes in `gix-actor::Signature` and `gix-actor::SignatureRef`. The latter now contains an unparsed string time field, while the former still contains a parsed time. So, the conversions between `gix-actor::SignatureRef` and either `gix-actor::Signature` or jj's `Signature` types can now fail. Cc: GitoxideLabs/gitoxide#1935, GitoxideLabs/gitoxide#2038
1 parent db722f0 commit 6fe3e58

File tree

2 files changed

+20
-18
lines changed

2 files changed

+20
-18
lines changed

lib/src/git_backend.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -652,14 +652,13 @@ fn signature_from_git(signature: gix::actor::SignatureRef) -> Signature {
652652
} else {
653653
"".to_string()
654654
};
655-
let timestamp = MillisSinceEpoch(signature.time.seconds * 1000);
656-
let tz_offset = signature.time.offset.div_euclid(60); // in minutes
655+
let time = signature.time().unwrap_or_default();
657656
Signature {
658657
name,
659658
email,
660659
timestamp: Timestamp {
661-
timestamp,
662-
tz_offset,
660+
timestamp: MillisSinceEpoch(time.seconds * 1000),
661+
tz_offset: time.offset.div_euclid(60), // in minutes
663662
},
664663
}
665664
}
@@ -1599,6 +1598,7 @@ fn bytes_vec_from_json(value: &serde_json::Value) -> Vec<u8> {
15991598
#[cfg(test)]
16001599
mod tests {
16011600
use assert_matches::assert_matches;
1601+
use gix::date::parse::TimeBuf;
16021602
use hex::ToHex as _;
16031603
use pollster::FutureExt as _;
16041604

@@ -1671,8 +1671,8 @@ mod tests {
16711671
};
16721672
let git_commit_id = git_repo
16731673
.commit_as(
1674-
&git_committer,
1675-
&git_author,
1674+
git_committer.to_ref(&mut TimeBuf::default()),
1675+
git_author.to_ref(&mut TimeBuf::default()),
16761676
"refs/heads/dummy",
16771677
"git commit message",
16781678
root_tree_id,
@@ -1698,8 +1698,8 @@ mod tests {
16981698
// Add an empty commit on top
16991699
let git_commit_id2 = git_repo
17001700
.commit_as(
1701-
&git_committer,
1702-
&git_author,
1701+
git_committer.to_ref(&mut TimeBuf::default()),
1702+
git_author.to_ref(&mut TimeBuf::default()),
17031703
"refs/heads/dummy2",
17041704
"git commit message 2",
17051705
root_tree_id,
@@ -1823,8 +1823,8 @@ mod tests {
18231823
gix::ObjectId::from_hex(b"4b825dc642cb6eb9a060e54bf8d69288fbee4904").unwrap();
18241824
let git_commit_id = git_repo
18251825
.commit_as(
1826-
&signature,
1827-
&signature,
1826+
signature.to_ref(&mut TimeBuf::default()),
1827+
signature.to_ref(&mut TimeBuf::default()),
18281828
"refs/heads/main",
18291829
"git commit message",
18301830
empty_tree_id,
@@ -1954,20 +1954,20 @@ mod tests {
19541954

19551955
#[test]
19561956
fn read_empty_string_placeholder() {
1957-
let git_signature1 = gix::actor::SignatureRef {
1957+
let git_signature1 = gix::actor::Signature {
19581958
name: EMPTY_STRING_PLACEHOLDER.into(),
19591959
email: "git.author@example.com".into(),
19601960
time: gix::date::Time::new(1000, 60 * 60),
19611961
};
1962-
let signature1 = signature_from_git(git_signature1);
1962+
let signature1 = signature_from_git(git_signature1.to_ref(&mut TimeBuf::default()));
19631963
assert!(signature1.name.is_empty());
19641964
assert_eq!(signature1.email, "git.author@example.com");
1965-
let git_signature2 = gix::actor::SignatureRef {
1965+
let git_signature2 = gix::actor::Signature {
19661966
name: "git committer".into(),
19671967
email: EMPTY_STRING_PLACEHOLDER.into(),
19681968
time: gix::date::Time::new(2000, -480 * 60),
19691969
};
1970-
let signature2 = signature_from_git(git_signature2);
1970+
let signature2 = signature_from_git(git_signature2.to_ref(&mut TimeBuf::default()));
19711971
assert_eq!(signature2.name, "git committer");
19721972
assert!(signature2.email.is_empty());
19731973
}
@@ -2242,8 +2242,8 @@ mod tests {
22422242
gix::ObjectId::from_hex(b"4b825dc642cb6eb9a060e54bf8d69288fbee4904").unwrap();
22432243
let git_commit_id = git_repo
22442244
.commit_as(
2245-
&signature,
2246-
&signature,
2245+
signature.to_ref(&mut TimeBuf::default()),
2246+
signature.to_ref(&mut TimeBuf::default()),
22472247
"refs/heads/main",
22482248
"git commit message",
22492249
empty_tree_id,

lib/testutils/src/git.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
use std::path::Path;
1616
use std::path::PathBuf;
1717

18+
use gix::date::parse::TimeBuf;
19+
1820
pub const GIT_USER: &str = "Someone";
1921
pub const GIT_EMAIL: &str = "someone@example.org";
2022

@@ -150,8 +152,8 @@ pub fn write_commit(
150152
) -> gix::ObjectId {
151153
let signature = signature();
152154
repo.commit_as(
153-
&signature,
154-
&signature,
155+
signature.to_ref(&mut TimeBuf::default()),
156+
signature.to_ref(&mut TimeBuf::default()),
155157
reference,
156158
message,
157159
tree_id,

0 commit comments

Comments
 (0)