From: Frej Drejhammar Date: Sat, 15 Aug 2015 17:32:59 +0000 (+0200) Subject: Survive corrupt source repositories X-Git-Url: http://crossforests.com/gitweb?a=commitdiff_plain;h=b9b6f2a57ade75f06f06f1052c2148cb9b41f52b;p=python%2Ffast-export.git Survive corrupt source repositories Apparently a bug (http://bz.selenic.com/show_bug.cgi?id=3511) in multiple released versions of Mercurial could produce commits where files had absolute paths. As a "healthy" repo should not contain any absolute paths, it should be safe to always strip a leading '/' from the path and let the conversion continue. --- diff --git a/hg-fast-export.py b/hg-fast-export.py index 0c683c5..9c7a935 100755 --- a/hg-fast-export.py +++ b/hg-fast-export.py @@ -135,7 +135,8 @@ def export_file_contents(ctx,manifest,files,hgtags,encoding=''): filename=file.decode(encoding).encode('utf8') else: filename=file - wr('M %s inline %s' % (gitmode(manifest.flags(file)),filename)) + wr('M %s inline %s' % (gitmode(manifest.flags(file)), + strip_leading_slash(filename))) wr('data %d' % len(d)) # had some trouble with size() wr(d) count+=1 @@ -163,6 +164,11 @@ def sanitize_name(name,what="branch"): sys.stderr.write('Warning: sanitized %s [%s] to [%s]\n' % (what,name,n)) return n +def strip_leading_slash(filename): + if filename[0] == '/': + return filename[1:] + return filename + 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): @@ -221,6 +227,8 @@ def export_commit(ui,repo,revision,old_marks,max,count,authors,sob,brmap,hgtags, if encoding: removed=[r.decode(encoding).encode('utf8') for r in removed] + removed=[strip_leading_slash(x) for x in removed] + map(lambda r: wr('D %s' % r),removed) export_file_contents(ctx,man,added,hgtags,encoding) export_file_contents(ctx,man,changed,hgtags,encoding)