mirror of
https://github.com/facebook/sapling.git
synced 2024-10-06 23:07:18 +03:00
git: fix timezone reading
Summary:
It turns out D33668305 (4dad74346b
) is incomplete. The timezone offset translated from git
was wrong. This diff fixes it.
Examples:
hg log default display (commit made using hg in a hg repo):
Wed, 23 Nov 2022 17:47:30 -0800
hg raw message (`repo.changelog.revision(repo['.'].node())`):
1669254450 28800
hg `repo['.'].date()`:
(1669254450.0, 28800)
git log default display (commit made using git in a git repo):
Wed Nov 23 17:47:30 2022 -0800
git raw message (`git cat-file -p HASH`):
1669254450 -0800
libgit2 [offset_minutes](https://docs.rs/git2/latest/git2/struct.Time.html#method.offset_minutes):
-480
Before this change, Sapling reading the commit created by git would do:
hg log default display (repo created via `debuginitgit` using the git created repo):
Wed, 23 Nov 2022 17:47:30 -0800
hg raw message (`repo.changelog.revision(repo['tip'].node())`):
1669254450 -480
hg `repo['tip'].date()`:
(1669254450.0, -480)
Commits created by Sapling seem to have the right timezone offset that can be
read by git just fine.
After this change the above -480 is now changed to 28800.
The default `log` output uses local timezone, so it's not affected by this bug.
Resolves #227.
Reviewed By: zzl0
Differential Revision: D41514692
fbshipit-source-id: 9be269cf4c40e7f92d071f7469bc31ec97e015ae
This commit is contained in:
parent
311ff27039
commit
acd61bb782
@ -394,8 +394,16 @@ fn to_hex(oid: git2::Oid) -> String {
|
||||
unsafe { String::from_utf8_unchecked(v) }
|
||||
}
|
||||
|
||||
// For "Wed, 23 Nov 2022 17:47:30 -0800",
|
||||
//
|
||||
// git commit message: "1669254450 -0800"
|
||||
// hg commit message: "1669254450 28800"
|
||||
// libgit2 Time::offset_minutes: -480
|
||||
|
||||
fn to_hg_date_text(time: &git2::Time) -> String {
|
||||
format!("{} {}", time.seconds(), time.offset_minutes())
|
||||
// See above. Convert -480 to 28800.
|
||||
let hg_date_offset_seconds = -time.offset_minutes() * 60;
|
||||
format!("{} {}", time.seconds(), hg_date_offset_seconds)
|
||||
}
|
||||
|
||||
/// Convert a git commit to hg commit text.
|
||||
|
22
eden/scm/tests/test-git-date-timezone.t
Normal file
22
eden/scm/tests/test-git-date-timezone.t
Normal file
@ -0,0 +1,22 @@
|
||||
#chg-compatible
|
||||
#require git no-windows
|
||||
#debugruntest-compatible
|
||||
|
||||
$ . $TESTDIR/git.sh
|
||||
|
||||
Make a commit with a non-GMT timezone:
|
||||
|
||||
$ hg init --git gitrepo1
|
||||
$ cd gitrepo1
|
||||
$ hg commit -d '2022-11-23 17:47:30 -0800' -m A --config ui.allowemptycommit=1
|
||||
$ hg bookmark -q A
|
||||
|
||||
Timezone parsed by hg:
|
||||
|
||||
$ hg log -r . -T '{date|isodatesec}\n'
|
||||
2022-11-23 17:47:30 -0800
|
||||
|
||||
Timezone parsed by Git:
|
||||
|
||||
$ git --git-dir=.hg/store/git log --format=%ai refs/heads/A
|
||||
2022-11-23 17:47:30 -0800
|
Loading…
Reference in New Issue
Block a user