Skip to content

Commit 0dbe8f6

Browse files
committed
chore: update gix to 0.66
This version of gix uses jiff instead of time for time/date related functionality. (gix-date 0.9 is really the driver.) Some other minor breaking changes are accounted for.
1 parent e36fa10 commit 0dbe8f6

File tree

11 files changed

+87
-230
lines changed

11 files changed

+87
-230
lines changed

Cargo.lock

Lines changed: 50 additions & 126 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ clap = { version = "~4.5", default-features = false, features = [
3737
ctrlc = "3.4"
3838
encoding_rs = "0.8"
3939
flate2 = "1"
40-
gix = { version = "0.64", default-features = false, features = ["command", "revision"] }
40+
gix = { version = "0.66", default-features = false, features = ["command", "revision"] }
4141
indexmap = "2.1"
4242
is-terminal = "0.4"
4343
jiff = "0.1.10"
@@ -48,12 +48,6 @@ tar = "0.4"
4848
tempfile = "3"
4949
termcolor = "1.4"
5050
thiserror = "~1.0"
51-
time = { version = "0.3.31", default-features = false, features = [
52-
"local-offset",
53-
"formatting",
54-
"macros",
55-
"parsing",
56-
] }
5751
winnow = "0.6.18"
5852

5953
curl = { version = "0.4", optional = true }

src/cmd/branch/clone.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ pub(super) fn dispatch(repo: &gix::Repository, matches: &ArgMatches) -> Result<(
7171
message: format!("clone from {current_branchname}").into(),
7272
},
7373
expected: gix::refs::transaction::PreviousValue::Any,
74-
new: gix::refs::Target::Peeled(state_commit.id),
74+
new: gix::refs::Target::Object(state_commit.id),
7575
},
7676
name: gix::refs::FullName::try_from(state_refname_from_branch_name(
7777
new_branchname.as_ref(),

src/cmd/branch/create.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ pub(super) fn dispatch(repo: &gix::Repository, matches: &clap::ArgMatches) -> Re
128128
message: format!("branch: Created from {target_name}").into(),
129129
},
130130
expected: gix::refs::transaction::PreviousValue::MustNotExist,
131-
new: gix::refs::Target::Peeled(target_commit.id),
131+
new: gix::refs::Target::Object(target_commit.id),
132132
},
133133
name: gix::refs::FullName::try_from(format!("refs/heads/{new_branchname}"))?,
134134
deref: false,

src/cmd/branch/rename.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ pub(super) fn dispatch(repo: &gix::Repository, matches: &clap::ArgMatches) -> Re
7171
message: format!("rename {old_branchname} to {new_branchname}").into(),
7272
},
7373
expected: gix::refs::transaction::PreviousValue::MustNotExist,
74-
new: gix::refs::Target::Peeled(state_commit.id),
74+
new: gix::refs::Target::Object(state_commit.id),
7575
},
7676
name: gix::refs::FullName::try_from(state_refname_from_branch_name(
7777
new_branchname.as_ref(),

src/ext/repository.rs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,6 @@ pub(crate) trait RepositoryExtended {
4747
/// Write repository-local config file.
4848
fn write_local_config(&self, file: gix::config::File) -> Result<()>;
4949

50-
/// Find [`gix::Tree`] by its object id.
51-
///
52-
/// The provided object id must point to a tree object. I.e. this will not peel a
53-
/// commit to a tree.
54-
fn find_tree(&self, id: impl Into<gix::ObjectId>) -> Result<gix::Tree<'_>>;
55-
56-
/// Find [`gix::Commit`] by its object id.
57-
///
58-
/// The provided object id must point to a commit object. An id pointing to a tag
59-
/// will not be peeled to a commit.
60-
fn find_commit(&self, id: impl Into<gix::ObjectId>) -> Result<gix::Commit<'_>>;
61-
6250
/// Create a new commit object in the repository, with extended features.
6351
///
6452
/// The extended features versus [`gix::Repository::commit()`] include:
@@ -207,14 +195,6 @@ impl RepositoryExtended for gix::Repository {
207195
Ok(())
208196
}
209197

210-
fn find_tree(&self, id: impl Into<gix::ObjectId>) -> Result<gix::Tree<'_>> {
211-
Ok(self.find_object(id)?.try_into_tree()?)
212-
}
213-
214-
fn find_commit(&self, id: impl Into<gix::ObjectId>) -> Result<gix::Commit<'_>> {
215-
Ok(self.find_object(id)?.try_into_commit()?)
216-
}
217-
218198
fn commit_ex<'a>(
219199
&self,
220200
author: impl Into<gix::actor::SignatureRef<'a>>,

src/ext/time.rs

Lines changed: 23 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -19,63 +19,29 @@ pub(crate) trait TimeExtended {
1919
/// | `gitoxide default`| `Thu Jan 6 2022 09:32:07 -0500` |
2020
fn parse_time(time_str: &str) -> Result<gix::date::Time> {
2121
let time_str = time_str.trim();
22+
let now = std::time::SystemTime::now();
23+
let zoned_now = jiff::Zoned::try_from(now).unwrap_or_else(|_| jiff::Zoned::now());
2224

2325
if time_str == "now" {
24-
return Ok(gix::date::Time::now_local_or_utc());
26+
Ok(gix::date::Time::new(
27+
zoned_now.timestamp().as_second(),
28+
zoned_now.offset().seconds(),
29+
))
30+
} else if let Ok(time) = gix::date::parse(time_str, Some(now)) {
31+
Ok(time)
32+
} else if let Ok(time) = gix::date::parse(
33+
&format!("{time_str} {}", zoned_now.strftime("%z")),
34+
Some(now),
35+
) {
36+
Ok(time)
37+
} else if let Ok(time) = gix::date::parse(
38+
&format!("{time_str}{}", zoned_now.strftime("%:z")),
39+
Some(now),
40+
) {
41+
Ok(time)
42+
} else {
43+
Err(anyhow!("invalid date `{time_str}`"))
2544
}
26-
27-
if let Ok(time) = gix::date::parse(time_str, Some(std::time::SystemTime::now())) {
28-
return Ok(time);
29-
}
30-
31-
// Datetime strings without timezone offset
32-
for format_desc in [
33-
// Git default without tz offset
34-
time::macros::format_description!(
35-
"[weekday repr:short] [month repr:short] [day padding:none] [hour]:[minute]:[second] [year]"
36-
),
37-
38-
// RFC-2822 without tz offset
39-
time::macros::format_description!(
40-
"[weekday repr:short], [day] [month repr:short] [year] [hour]:[minute]:[second]"
41-
),
42-
43-
// ISO8601 without tz offset
44-
time::macros::format_description!(
45-
"[year]-[month]-[day] [hour]:[minute]:[second] [offset_hour sign:mandatory][offset_minute]"
46-
),
47-
48-
// Strict ISO8601 without tz offset
49-
time::macros::format_description!(
50-
"[year]-[month]-[day]T[hour]:[minute]:[second]"
51-
),
52-
53-
// Gitoxide default without tz offset
54-
time::macros::format_description!(
55-
"[weekday repr:short] [month repr:short] [day] [year] [hour]:[minute]:[second]"
56-
),
57-
] {
58-
if let Ok(primitive_dt) = time::PrimitiveDateTime::parse(time_str, format_desc) {
59-
let offset = time::UtcOffset::from_whole_seconds(
60-
gix::date::Time::now_local_or_utc().offset,
61-
)?;
62-
let offset_dt = primitive_dt.assume_offset(offset);
63-
return Ok(gix::date::Time::new(
64-
offset_dt.unix_timestamp(),
65-
offset_dt.offset().whole_seconds(),
66-
));
67-
}
68-
}
69-
70-
if let Ok(seconds) = time_str.parse::<u32>() {
71-
let offset_dt = time::OffsetDateTime::from_unix_timestamp(seconds.into())?;
72-
return Ok(gix::date::Time::new(
73-
offset_dt.unix_timestamp(),
74-
offset_dt.offset().whole_seconds(),
75-
));
76-
}
77-
78-
Err(anyhow!("invalid date `{time_str}`"))
7945
}
8046
}
8147

@@ -120,12 +86,9 @@ mod tests {
12086
fn parse_8601_without_tz() {
12187
let time_str = "2005-04-07T22:13:09";
12288
let time = Time::parse_time(time_str).unwrap();
123-
assert_eq!(
124-
time.format(gix::date::time::format::ISO8601_STRICT)
125-
.strip_suffix("+00:00")
126-
.unwrap(),
127-
time_str,
128-
);
89+
assert!(time
90+
.format(gix::date::time::format::ISO8601_STRICT)
91+
.starts_with(time_str));
12992
}
13093

13194
#[test]

src/main.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,6 @@ pub(crate) fn get_full_command(
146146
/// quickly as possible.
147147
fn main() -> ! {
148148
let argv: Vec<OsString> = std::env::args_os().collect();
149-
unsafe {
150-
// SAFETY: It's sound as we don't manipulate environment variables while querying local offsets.
151-
time::util::local_offset::set_soundness(time::util::local_offset::Soundness::Unsound);
152-
}
153149

154150
// Chicken and egg: the --color option must be parsed from argv in order to setup
155151
// clap with the desired color choice. So a simple pre-parse is performed just to

src/stack/stack.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -334,9 +334,9 @@ impl<'repo> Stack<'repo> {
334334
message: reflog_msg.into(),
335335
},
336336
expected: gix::refs::transaction::PreviousValue::ExistingMustMatch(
337-
gix::refs::Target::Peeled(prev_state_commit_id),
337+
gix::refs::Target::Object(prev_state_commit_id),
338338
),
339-
new: gix::refs::Target::Peeled(state_commit_id),
339+
new: gix::refs::Target::Object(state_commit_id),
340340
},
341341
name: gix::refs::FullName::try_from(self.stack_refname.as_str())?,
342342
deref: false,
@@ -495,7 +495,7 @@ fn ensure_patch_refs(repo: &gix::Repository, branch_name: &str, state: &StackSta
495495
expected: gix::refs::transaction::PreviousValue::ExistingMustMatch(
496496
existing_ref.target().into_owned(),
497497
),
498-
new: gix::refs::Target::Peeled(patchdesc.commit.id),
498+
new: gix::refs::Target::Object(patchdesc.commit.id),
499499
},
500500
name: existing_ref.name().into(),
501501
deref: false,
@@ -526,7 +526,7 @@ fn ensure_patch_refs(repo: &gix::Repository, branch_name: &str, state: &StackSta
526526
message: "fixup missing patch ref".into(),
527527
},
528528
expected: gix::refs::transaction::PreviousValue::MustNotExist,
529-
new: gix::refs::Target::Peeled(patchdesc.commit.id),
529+
new: gix::refs::Target::Object(patchdesc.commit.id),
530530
},
531531
name: gix::refs::FullName::try_from(get_patch_refname(
532532
branch_name,

src/stack/transaction/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ impl<'repo> ExecuteContext<'repo> {
248248
gix::refs::transaction::Change::Update {
249249
log: log.clone(),
250250
expected: gix::refs::transaction::PreviousValue::Any, // TODO?
251-
new: gix::refs::Target::Peeled(patch.commit.id),
251+
new: gix::refs::Target::Object(patch.commit.id),
252252
}
253253
} else {
254254
gix::refs::transaction::Change::Delete {
@@ -269,12 +269,12 @@ impl<'repo> ExecuteContext<'repo> {
269269
log: log.clone(),
270270
expected: if let Some(prev_state_commit) = stack.state_mut().prev.as_ref() {
271271
gix::refs::transaction::PreviousValue::ExistingMustMatch(
272-
gix::refs::Target::Peeled(prev_state_commit.id),
272+
gix::refs::Target::Object(prev_state_commit.id),
273273
)
274274
} else {
275275
gix::refs::transaction::PreviousValue::MustNotExist
276276
},
277-
new: gix::refs::Target::Peeled(state_commit_id),
277+
new: gix::refs::Target::Object(state_commit_id),
278278
},
279279
name: gix::refs::FullName::try_from(stack.get_stack_refname())
280280
.expect("stack reference name is valid"),
@@ -286,7 +286,7 @@ impl<'repo> ExecuteContext<'repo> {
286286
change: gix::refs::transaction::Change::Update {
287287
log,
288288
expected: gix::refs::transaction::PreviousValue::Any,
289-
new: gix::refs::Target::Peeled(trans_head.id),
289+
new: gix::refs::Target::Object(trans_head.id),
290290
},
291291
name: branch_ref_name.clone(),
292292
deref: false,

0 commit comments

Comments
 (0)