mirror of
https://github.com/frej/fast-export.git
synced 2025-11-01 08:55:47 +01:00
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:
@@ -159,7 +159,7 @@ def sanitize_name(name,what="branch"):
|
||||
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]
|
||||
@@ -167,7 +167,7 @@ def export_commit(ui,repo,revision,old_marks,max,count,authors,sob,brmap,hgtags,
|
||||
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)
|
||||
|
||||
@@ -323,7 +323,7 @@ def verify_heads(ui,repo,cache,force):
|
||||
|
||||
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)
|
||||
@@ -354,7 +354,7 @@ def hg2git(repourl,m,marksfile,mappingfile,headsfile,tipfile,authors={},sob=Fals
|
||||
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
|
||||
@@ -401,6 +401,8 @@ if __name__=='__main__':
|
||||
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()
|
||||
|
||||
@@ -423,5 +425,11 @@ if __name__=='__main__':
|
||||
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))
|
||||
|
||||
Reference in New Issue
Block a user