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.
This commit is contained in:
Frej Drejhammar
2015-08-15 19:32:59 +02:00
parent d202200fd9
commit b9b6f2a57a

View File

@@ -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)