# HG changeset patch # User Mads Kiilerich # Date 1272280863 -7200 # Node ID 0429d0d49f9240449ebef46bd2528c98663677d2 # Parent c47a1cfad57215d88153b7d90b341e8d87252cc2 patch: strip paths in leaked git patchmeta objects diff -r c47a1cfad572 -r 0429d0d49f92 mercurial/patch.py --- a/mercurial/patch.py Mon Apr 26 13:21:03 2010 +0200 +++ b/mercurial/patch.py Mon Apr 26 13:21:03 2010 +0200 @@ -907,25 +907,25 @@ return s return s[:i] +def pathstrip(path, strip): + pathlen = len(path) + i = 0 + if strip == 0: + return '', path.rstrip() + count = strip + while count > 0: + i = path.find('/', i) + if i == -1: + raise PatchError(_("unable to strip away %d of %d dirs from %s") % + (count, strip, path)) + i += 1 + # consume '//' in the path + while i < pathlen - 1 and path[i] == '/': + i += 1 + count -= 1 + return path[:i].lstrip(), path[i:].rstrip() + def selectfile(afile_orig, bfile_orig, hunk, strip): - def pathstrip(path, strip): - pathlen = len(path) - i = 0 - if strip == 0: - return '', path.rstrip() - count = strip - while count > 0: - i = path.find('/', i) - if i == -1: - raise PatchError(_("unable to strip away %d of %d dirs from %s") % - (count, strip, path)) - i += 1 - # consume '//' in the path - while i < pathlen - 1 and path[i] == '/': - i += 1 - count -= 1 - return path[:i].lstrip(), path[i:].rstrip() - nulla = afile_orig == "/dev/null" nullb = bfile_orig == "/dev/null" abase, afile = pathstrip(afile_orig, strip) @@ -1190,6 +1190,9 @@ continue elif state == 'git': for gp in values: + gp.path = pathstrip(gp.path, strip - 1)[1] + if gp.oldpath: + gp.oldpath = pathstrip(gp.oldpath, strip - 1)[1] if gp.op in ('COPY', 'RENAME'): copyfn(gp.oldpath, gp.path, cwd) changed[gp.path] = gp