##// END OF EJS Templates
patch: strip paths in leaked git patchmeta objects
Mads Kiilerich -
r11022:0429d0d4 default
parent child Browse files
Show More
@@ -907,25 +907,25 b' def parsefilename(str):'
907 return s
907 return s
908 return s[:i]
908 return s[:i]
909
909
910 def pathstrip(path, strip):
911 pathlen = len(path)
912 i = 0
913 if strip == 0:
914 return '', path.rstrip()
915 count = strip
916 while count > 0:
917 i = path.find('/', i)
918 if i == -1:
919 raise PatchError(_("unable to strip away %d of %d dirs from %s") %
920 (count, strip, path))
921 i += 1
922 # consume '//' in the path
923 while i < pathlen - 1 and path[i] == '/':
924 i += 1
925 count -= 1
926 return path[:i].lstrip(), path[i:].rstrip()
927
910 def selectfile(afile_orig, bfile_orig, hunk, strip):
928 def selectfile(afile_orig, bfile_orig, hunk, strip):
911 def pathstrip(path, strip):
912 pathlen = len(path)
913 i = 0
914 if strip == 0:
915 return '', path.rstrip()
916 count = strip
917 while count > 0:
918 i = path.find('/', i)
919 if i == -1:
920 raise PatchError(_("unable to strip away %d of %d dirs from %s") %
921 (count, strip, path))
922 i += 1
923 # consume '//' in the path
924 while i < pathlen - 1 and path[i] == '/':
925 i += 1
926 count -= 1
927 return path[:i].lstrip(), path[i:].rstrip()
928
929 nulla = afile_orig == "/dev/null"
929 nulla = afile_orig == "/dev/null"
930 nullb = bfile_orig == "/dev/null"
930 nullb = bfile_orig == "/dev/null"
931 abase, afile = pathstrip(afile_orig, strip)
931 abase, afile = pathstrip(afile_orig, strip)
@@ -1190,6 +1190,9 b' def _applydiff(ui, fp, patcher, copyfn, '
1190 continue
1190 continue
1191 elif state == 'git':
1191 elif state == 'git':
1192 for gp in values:
1192 for gp in values:
1193 gp.path = pathstrip(gp.path, strip - 1)[1]
1194 if gp.oldpath:
1195 gp.oldpath = pathstrip(gp.oldpath, strip - 1)[1]
1193 if gp.op in ('COPY', 'RENAME'):
1196 if gp.op in ('COPY', 'RENAME'):
1194 copyfn(gp.oldpath, gp.path, cwd)
1197 copyfn(gp.oldpath, gp.path, cwd)
1195 changed[gp.path] = gp
1198 changed[gp.path] = gp
General Comments 0
You need to be logged in to leave comments. Login now