Skip to content

Commit 1fe201a

Browse files
committed
fix: revspec parsing now correctly interprets large offsets like @{100000000} as unix timestamp.
This is the same behaviour as the one shown in Git.
1 parent 93cb5ba commit 1fe201a

File tree

2 files changed

+42
-3
lines changed

2 files changed

+42
-3
lines changed

gix-revision/src/spec/parse/function.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -429,9 +429,23 @@ where
429429
}
430430
} else if has_ref_or_implied_name {
431431
delegate
432-
.reflog(delegate::ReflogLookup::Entry(
433-
n.try_into().expect("non-negative isize fits usize"),
434-
))
432+
.reflog(if n >= 100000000 {
433+
let time = nav
434+
.to_str()
435+
.map_err(|_| Error::Time {
436+
input: nav.into(),
437+
source: None,
438+
})
439+
.and_then(|date| {
440+
gix_date::parse(date, None).map_err(|err| Error::Time {
441+
input: nav.into(),
442+
source: err.into(),
443+
})
444+
})?;
445+
delegate::ReflogLookup::Date(time)
446+
} else {
447+
delegate::ReflogLookup::Entry(n.try_into().expect("non-negative isize fits usize"))
448+
})
435449
.ok_or(Error::Delegate)?;
436450
} else {
437451
return Err(Error::ReflogLookupNeedsRefName { name: (*name).into() });

gix-revision/tests/revision/spec/parse/anchor/at_symbol.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,31 @@ fn reflog_by_date_for_current_branch() {
4747
assert_eq!(rec.calls, 1);
4848
}
4949

50+
#[test]
51+
fn reflog_by_unix_timestamp_for_current_branch() {
52+
let rec = parse("@{100000000}");
53+
54+
assert!(rec.kind.is_none());
55+
assert_eq!(rec.find_ref[0], None,);
56+
assert_eq!(
57+
rec.prefix[0], None,
58+
"neither ref nor prefixes are set, straight to navigation"
59+
);
60+
assert_eq!(
61+
rec.current_branch_reflog_entry[0],
62+
Some("100000000 +0000".to_string()),
63+
"This number is the first to count as date"
64+
);
65+
assert_eq!(rec.calls, 1);
66+
67+
let rec = parse("@{99999999}");
68+
assert_eq!(
69+
rec.current_branch_reflog_entry[0],
70+
Some("99999999".to_string()),
71+
"one less is an offset though"
72+
);
73+
}
74+
5075
#[test]
5176
fn reflog_by_date_with_date_parse_failure() {
5277
let err = try_parse("@{foo}").unwrap_err();

0 commit comments

Comments
 (0)