Skip to content
Snippets Groups Projects
Commit e9713fe6 authored by Georges Racinet's avatar Georges Racinet
Browse files

CommitAuthor message: taking time zones into account

Up to now, we've been simply been ignoring the offset provided
by Mercurial and were not displaying any timezone on the resulting
`Author` message.

Gitaly comparison tests will be provided by work currently in
progress to make comparison more systematic.
parent 02c16a74
No related branches found
No related tags found
1 merge request!68more helpers for comparison tests
......@@ -49,8 +49,21 @@
date = Timestamp()
# hg time resolution is the second, see
# https://www.mercurial-scm.org/wiki/ChangeSet
date.FromSeconds(int(ctx.date()[0]))
seconds, offset = ctx.date()
date.FromSeconds(int(seconds))
if offset <= 0:
# Mercurial sign convention is opposite of UTC+2 etc.
tz_sign = b'+'
offset_abs = -offset
else:
tz_sign = b'-'
offset_abs = offset
# Mercurial offset is in seconds
tz_hours = offset_abs // 3600
tz_minutes = (offset_abs % 3600) // 60
return CommitAuthor(
email=hg_stringutil.email(auth),
name=hg_stringutil.person(auth),
date=date,
......@@ -53,7 +66,8 @@
return CommitAuthor(
email=hg_stringutil.email(auth),
name=hg_stringutil.person(auth),
date=date,
timezone=b"%s%02d%02d" % (tz_sign, tz_hours, tz_minutes),
)
......
......@@ -105,6 +105,7 @@
utc_timestamp=now,
user="HGitaly Test <hgitaly@heptapod.test>")
ctx2 = wrapper.write_commit('foo',
tz_timestamp=(123456, -7200), # UTC+2
parent=ctx,
message="Foo deux\n\nA very interesting bar")
......@@ -118,6 +119,7 @@
assert commit.author.name == b"HGitaly Test"
assert commit.author.email == b"hgitaly@heptapod.test"
assert commit.author.date.seconds == int(now)
assert commit.author.timezone == b'+0000'
request = FindCommitRequest(repository=grpc_repo, revision=ctx2.hex())
response = grpc_stub.FindCommit(request)
......@@ -127,6 +129,7 @@
assert commit2.subject == b'Foo deux'
assert commit2.body == b"Foo deux\n\nA very interesting bar"
assert commit2.parent_ids == [ctx.hex().decode()]
assert commit2.author.timezone == b'+0200'
# TODO check with two parents, it'd be nice to have a helper to create
# merge commits very quickly
......
......@@ -53,6 +53,39 @@
assert tag.signature_type == SignatureType.PGP
def test_commit_author():
class FakeContext:
def __init__(self, user, timestamp_tz):
self._user = user
self._date = timestamp_tz
def date(self):
return self._date
def user(self):
return self._user
timestamp = 1626786076.0 # as good as any, took it from a changeset
name_and_email = b"My Self <me@name.test>"
author = message.commit_author(FakeContext(name_and_email,
(timestamp, 0)))
assert author.name == b'My Self'
assert author.email == b'me@name.test'
assert author.timezone == b'+0000'
assert author.date.seconds == int(timestamp)
def with_tz(offset):
return message.commit_author(FakeContext(name_and_email,
(timestamp, offset)))
assert with_tz(-7200).timezone == b'+0200'
assert with_tz(-16200).timezone == b'+0430'
assert with_tz(3600).timezone == b'-0100'
assert with_tz(4500).timezone == b'-0115'
def test_logging_class():
log_msg = message.Logging(Repository(storage_name='thestore',
relative_path='a/b/c'))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment