sys.stderr.write('Warning: sanitized %s [%s] to [%s]\n' % (what,name,n))
return n
-def export_commit(ui,repo,revision,old_marks,max,count,authors,sob,brmap,hgtags,notes):
+def export_commit(ui,repo,revision,old_marks,max,count,authors,sob,brmap,hgtags,notes,encoding=''):
def get_branchname(name):
if brmap.has_key(name):
return brmap[name]
brmap[name]=n
return n
- (revnode,_,user,(time,timezone),files,desc,branch,_)=get_changeset(ui,repo,revision,authors)
+ (revnode,_,user,(time,timezone),files,desc,branch,_)=get_changeset(ui,repo,revision,authors,encoding)
branch=get_branchname(branch)
return True
-def hg2git(repourl,m,marksfile,mappingfile,headsfile,tipfile,authors={},sob=False,force=False,hgtags=False,notes=False):
+def hg2git(repourl,m,marksfile,mappingfile,headsfile,tipfile,authors={},sob=False,force=False,hgtags=False,notes=False,encoding=''):
_max=int(m)
old_marks=load_cache(marksfile,lambda s: int(s)-1)
c=0
brmap={}
for rev in range(min,max):
- c=export_commit(ui,repo,rev,old_marks,max,c,authors,sob,brmap,hgtags,notes)
+ c=export_commit(ui,repo,rev,old_marks,max,c,authors,sob,brmap,hgtags,notes,encoding)
state_cache['tip']=max
state_cache['repo']=repourl
help="use <name> as namespace to track upstream")
parser.add_option("--hg-hash",action="store_true",dest="notes",
default=False,help="Annotate commits with the hg hash as git notes in the hg namespace")
+ parser.add_option("-e",dest="encoding",
+ help="Assume commit and author strings retrieved from Mercurial are encoded in <encoding>")
(options,args)=parser.parse_args()
if options.origin_name!=None:
set_origin_name(options.origin_name)
- sys.exit(hg2git(options.repourl,m,options.marksfile,options.mappingfile,options.headsfile,
- options.statusfile,authors=a,sob=options.sob,force=options.force,hgtags=options.hgtags,notes=options.notes))
+ encoding=''
+ if options.encoding!=None:
+ encoding=options.encoding
+
+ sys.exit(hg2git(options.repourl,m,options.marksfile,options.mappingfile,
+ options.headsfile, options.statusfile,authors=a,
+ sob=options.sob,force=options.force,hgtags=options.hgtags,
+ notes=options.notes,encoding=encoding))
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)