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
):
38 message
= ctx
.description() + "\n"
39 if 'message' in extra
:
40 message
= apply_delta(message
, extra
['message'])
42 # HG EXTRA INFORMATION
45 if not ctx
.branch() == 'default':
47 extra_message
+= "branch : " + ctx
.branch() + "\n"
51 if f
not in ctx
.manifest():
53 rename
= ctx
.filectx(f
).renamed()
55 renames
.append((rename
[0], f
))
59 for oldfile
, newfile
in renames
:
60 extra_message
+= "rename : " + oldfile
+ " => " + newfile
+ "\n"
62 for key
, value
in extra
.iteritems():
63 if key
in ('author', 'committer', 'encoding', 'message', 'branch', 'hg-git'):
67 extra_message
+= "extra : " + key
+ " : " + urllib
.quote(value
) + "\n"
70 message
+= "\n--HG--\n" + extra_message
74 def get_author(self
, ctx
):
75 # hg authors might not have emails
78 # check for git author pattern compliance
79 regex
= re
.compile('^(.*?) ?\<(.*?)\>(.*)$')
80 a
= regex
.match(author
)
85 if len(a
.group(3)) > 0:
86 name
+= ' ext:(' + urllib
.quote(a
.group(3)) + ')'
87 author
= name
+ ' <' + email
+ '>'
89 author
= author
+ ' <none@none>'
91 if 'author' in ctx
.extra():
92 author
= apply_delta(author
, ctx
.extra()['author'])
94 (time
, timezone
) = ctx
.date()
95 date
= str(int(time
)) + ' ' + self
.format_timezone(-timezone
)
97 return author
+ ' ' + date
99 def get_parents(self
, ctx
):
100 def is_octopus_part(ctx
):
101 return ctx
.extra().get('hg-git', None) in ('octopus', 'octopus-done')
104 if ctx
.extra().get('hg-git', None) == 'octopus-done':
105 # implode octopus parents
107 while is_octopus_part(part
):
108 (p1
, p2
) = part
.parents()
109 assert not is_octopus_part(p1
)
114 parents
= ctx
.parents()