905 i = s.find(' ') |
905 i = s.find(' ') |
906 if i < 0: |
906 if i < 0: |
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) |
932 gooda = not nulla and util.lexists(afile) |
932 gooda = not nulla and util.lexists(afile) |
933 bbase, bfile = pathstrip(bfile_orig, strip) |
933 bbase, bfile = pathstrip(bfile_orig, strip) |
1188 current_file = None |
1188 current_file = None |
1189 rejects += 1 |
1189 rejects += 1 |
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 |
1196 else: |
1199 else: |
1197 raise util.Abort(_('unsupported parser state: %s') % state) |
1200 raise util.Abort(_('unsupported parser state: %s') % state) |