1 from git_remote_helpers.hg.metadata_util import (get_git_author,
2 get_git_parents, get_git_message)
5 """Class that handles various aspects of converting a hg commit to git.
8 def __init__(self, warn):
9 """Initializes a new GitHg object with the specified warner.
14 def format_timezone(self, offset):
16 raise ValueError("Unable to handle non-minute offset.")
17 sign = (offset < 0) and '-' or '+'
19 return '%c%02d%02d' % (sign, offset / 3600, (offset / 60) % 60)
21 def get_committer(self, ctx):
24 if 'committer' in extra:
26 (name_timestamp, timezone) = extra['committer'].rsplit(' ', 1)
28 timezone = self.format_timezone(-int(timezone))
29 return '%s %s' % (name_timestamp, timezone)
31 self.warn("Ignoring committer in extra, invalid timezone in r%s: '%s'.\n" % (ctx.rev(), timezone))
35 def get_message(self, ctx):
36 return get_git_message(ctx)
38 def get_author(self, ctx):
39 author = get_git_author(ctx)
41 (time, timezone) = ctx.date()
42 date = str(int(time)) + ' ' + self.format_timezone(-timezone)
44 return author + ' ' + date
46 def get_parents(self, ctx):
47 return get_git_parents(ctx)