From 93cb5ba03d364efcbb4110c2bd207f3d8de9b292 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Sat, 21 Dec 2024 19:05:45 +0100 Subject: [PATCH 1/3] fix: fix check to detect `git-lfs` managed files that weren't checked out. Previously it would detect them incorrectly due to a find-and-replace error. --- tests/tools/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/tools/src/lib.rs b/tests/tools/src/lib.rs index 520e271ebe3..a03ed9c5c91 100644 --- a/tests/tools/src/lib.rs +++ b/tests/tools/src/lib.rs @@ -680,7 +680,7 @@ fn should_skip_all_archive_creation() -> bool { } fn is_lfs_pointer_file(path: &Path) -> bool { - const PREFIX: &[u8] = b"version https://gix-lfs"; + const PREFIX: &[u8] = b"version https://git-lfs"; let mut buf = [0_u8; PREFIX.len()]; std::fs::OpenOptions::new() .read(true) From 1fe201a8d4ec9f3349d48f1e4afe3f58b11f90b4 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Sat, 21 Dec 2024 19:38:11 +0100 Subject: [PATCH 2/3] fix: revspec parsing now correctly interprets large offsets like `@{100000000}` as unix timestamp. This is the same behaviour as the one shown in Git. --- gix-revision/src/spec/parse/function.rs | 20 ++++++++++++--- .../revision/spec/parse/anchor/at_symbol.rs | 25 +++++++++++++++++++ 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/gix-revision/src/spec/parse/function.rs b/gix-revision/src/spec/parse/function.rs index d9740a3e036..37035697287 100644 --- a/gix-revision/src/spec/parse/function.rs +++ b/gix-revision/src/spec/parse/function.rs @@ -429,9 +429,23 @@ where } } else if has_ref_or_implied_name { delegate - .reflog(delegate::ReflogLookup::Entry( - n.try_into().expect("non-negative isize fits usize"), - )) + .reflog(if n >= 100000000 { + let time = nav + .to_str() + .map_err(|_| Error::Time { + input: nav.into(), + source: None, + }) + .and_then(|date| { + gix_date::parse(date, None).map_err(|err| Error::Time { + input: nav.into(), + source: err.into(), + }) + })?; + delegate::ReflogLookup::Date(time) + } else { + delegate::ReflogLookup::Entry(n.try_into().expect("non-negative isize fits usize")) + }) .ok_or(Error::Delegate)?; } else { return Err(Error::ReflogLookupNeedsRefName { name: (*name).into() }); diff --git a/gix-revision/tests/revision/spec/parse/anchor/at_symbol.rs b/gix-revision/tests/revision/spec/parse/anchor/at_symbol.rs index af6e260f17d..42ff94f6213 100644 --- a/gix-revision/tests/revision/spec/parse/anchor/at_symbol.rs +++ b/gix-revision/tests/revision/spec/parse/anchor/at_symbol.rs @@ -47,6 +47,31 @@ fn reflog_by_date_for_current_branch() { assert_eq!(rec.calls, 1); } +#[test] +fn reflog_by_unix_timestamp_for_current_branch() { + let rec = parse("@{100000000}"); + + assert!(rec.kind.is_none()); + assert_eq!(rec.find_ref[0], None,); + assert_eq!( + rec.prefix[0], None, + "neither ref nor prefixes are set, straight to navigation" + ); + assert_eq!( + rec.current_branch_reflog_entry[0], + Some("100000000 +0000".to_string()), + "This number is the first to count as date" + ); + assert_eq!(rec.calls, 1); + + let rec = parse("@{99999999}"); + assert_eq!( + rec.current_branch_reflog_entry[0], + Some("99999999".to_string()), + "one less is an offset though" + ); +} + #[test] fn reflog_by_date_with_date_parse_failure() { let err = try_parse("@{foo}").unwrap_err(); From 14c3744a0bb5bf9e78055e0b86103a37a1f0c299 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Sat, 21 Dec 2024 19:20:50 +0100 Subject: [PATCH 3/3] fix: assure date-tests won't fail over time. Need to use absolute timestamps as it's impossible to control the system time. --- gix/tests/gix/repository/mod.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/gix/tests/gix/repository/mod.rs b/gix/tests/gix/repository/mod.rs index e5833ad6f5e..2909186ba6a 100644 --- a/gix/tests/gix/repository/mod.rs +++ b/gix/tests/gix/repository/mod.rs @@ -27,14 +27,18 @@ mod revision { fn date() -> crate::Result { let repo = crate::named_repo("make_rev_parse_repo.sh")?; let actual = repo - .rev_parse_single("old@{10 years ago}") + .rev_parse_single("old@{20 years ago}") .expect("it returns the oldest possible rev when overshooting"); assert_eq!(actual, hex_to_id("be2f093f0588eaeb71e1eff7451b18c2a9b1d765")); let actual = repo - .rev_parse_single("old@{1 month ago}") + .rev_parse_single("old@{1732184844}") .expect("it finds something in the middle"); - assert_eq!(actual, hex_to_id("b29405fe9147a3a366c4048fbe295ea04de40fa6")); + assert_eq!( + actual, + hex_to_id("b29405fe9147a3a366c4048fbe295ea04de40fa6"), + "It also figures out that we don't mean an index, but a date" + ); Ok(()) } }