Skip to content

Commit cb611c9

Browse files
committed
git_backend: update gix, adapt to breaking changes
Update `gix` to 0.72.1, and adapt to its breaking changes. 1. Adapt to a change in signature of `gix::reference::iter::Platform::prefixed` that seems to confuse Rust compiler. 2. Adapt to `git_object::Tree::EntryMode` API change; `entry.mode()` now has a `value()` method. 3. Most significantly, adapt to the changes to `gix::actor::SignatureRef`. ## Details about `gix::actor::SignatureRef` The API for `gix::actor::Signature` and `gix::actor::SignatureRef` changedd. 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. We use the epoch for the time if the timestamp is unreadable, like gix did before. Cc: GitoxideLabs/gitoxide#1935, GitoxideLabs/gitoxide#2038
1 parent 5a91c50 commit cb611c9

File tree

3 files changed

+25
-22
lines changed

3 files changed

+25
-22
lines changed

lib/src/git.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1862,9 +1862,10 @@ fn remove_remote_git_refs(
18621862
git_repo: &mut gix::Repository,
18631863
remote: &RemoteName,
18641864
) -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
1865+
let prefix = format!("refs/remotes/{remote}/", remote = remote.as_str());
18651866
let edits: Vec<_> = git_repo
18661867
.references()?
1867-
.prefixed(format!("refs/remotes/{remote}/", remote = remote.as_str()))?
1868+
.prefixed(prefix.as_str())?
18681869
.map_ok(remove_ref)
18691870
.try_collect()?;
18701871
git_repo.edit_references(edits)?;
@@ -1960,7 +1961,7 @@ fn rename_remote_git_refs(
19601961

19611962
let edits: Vec<_> = git_repo
19621963
.references()?
1963-
.prefixed(old_prefix.clone())?
1964+
.prefixed(old_prefix.as_str())?
19641965
.map_ok(|old_ref| {
19651966
let new_name = BString::new(
19661967
[

lib/src/git_backend.rs

Lines changed: 18 additions & 18 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: "[email protected]".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, "[email protected]");
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
}
@@ -2124,7 +2124,7 @@ mod tests {
21242124
.iter()
21252125
.map(Result::unwrap)
21262126
.filter(|entry| entry.filename() != b"README")
2127-
.all(|entry| entry.mode().0 == 0o040000));
2127+
.all(|entry| entry.mode().value() == 0o040000));
21282128
let mut iter = git_tree.iter().map(Result::unwrap);
21292129
let entry = iter.next().unwrap();
21302130
assert_eq!(entry.filename(), b".jjconflict-base-0");
@@ -2158,7 +2158,7 @@ mod tests {
21582158
);
21592159
let entry = iter.next().unwrap();
21602160
assert_eq!(entry.filename(), b"README");
2161-
assert_eq!(entry.mode().0, 0o100644);
2161+
assert_eq!(entry.mode().value(), 0o100644);
21622162
assert!(iter.next().is_none());
21632163

21642164
// When writing a single tree using the new format, it's represented by a
@@ -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 = "[email protected]";
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)