Add option for specifying the text encoding used by Mercurial

When a mercurial repository does not use utf-8 for encoding author
strings and commit messages the "-e <encoding>" command line option
can be used to force fast-export to convert incoming meta data from
<encoding> to utf-8.

When "-e <encoding>" is given, we use Python's string
decoding/encoding API to convert meta data on the fly when processing
commits.
This commit is contained in:
zed
2014-10-25 13:18:41 +03:00
committed by Frej Drejhammar
parent f64c10ba14
commit e87c9cb3b8
4 changed files with 26 additions and 8 deletions

View File

@@ -67,9 +67,12 @@ def get_branch(name):
return origin_name + '/' + name
return name
def get_changeset(ui,repo,revision,authors={}):
def get_changeset(ui,repo,revision,authors={},encoding=''):
node=repo.lookup(revision)
(manifest,user,(time,timezone),files,desc,extra)=repo.changelog.read(node)
if encoding:
user=user.decode(encoding).encode('utf8')
desc=desc.decode(encoding).encode('utf8')
tz="%+03d%02d" % (-timezone / 3600, ((-timezone % 3600) / 60))
branch=get_branch(extra.get('branch','master'))
return (node,manifest,fixup_user(user,authors),(time,tz),files,desc,branch,extra)