##// END OF EJS Templates
patch: add lexists() to backends, use it in selectfile()...
Patrick Mezard -
r14351:d54f9bbc default
parent child Browse files
Show More
@@ -1178,7 +1178,7 b' class queue(object):'
1178 1178 if wcfiles:
1179 1179 for patchname in s:
1180 1180 pf = os.path.join(self.path, patchname)
1181 patchfiles = patchmod.changedfiles(pf, strip=1)
1181 patchfiles = patchmod.changedfiles(self.ui, repo, pf)
1182 1182 if wcfiles.intersection(patchfiles):
1183 1183 self.localchangesfound(self.applied)
1184 1184 elif mergeq:
@@ -394,6 +394,9 b' class abstractbackend(object):'
394 394 """
395 395 raise NotImplementedError
396 396
397 def exists(self, fname):
398 raise NotImplementedError
399
397 400 class fsbackend(abstractbackend):
398 401 def __init__(self, ui, basedir):
399 402 super(fsbackend, self).__init__(ui)
@@ -461,6 +464,9 b' class fsbackend(abstractbackend):'
461 464 % dst)
462 465 util.copyfile(abssrc, absdst)
463 466
467 def exists(self, fname):
468 return os.path.lexists(fname)
469
464 470 # @@ -start,len +start,len @@ or @@ -start +start @@ if len is 1
465 471 unidesc = re.compile('@@ -(\d+)(,(\d+))? \+(\d+)(,(\d+))? @@')
466 472 contextdesc = re.compile('(---|\*\*\*) (\d+)(,(\d+))? (---|\*\*\*)')
@@ -970,16 +976,16 b' def pathstrip(path, strip):'
970 976 count -= 1
971 977 return path[:i].lstrip(), path[i:].rstrip()
972 978
973 def selectfile(afile_orig, bfile_orig, hunk, strip):
979 def selectfile(backend, afile_orig, bfile_orig, hunk, strip):
974 980 nulla = afile_orig == "/dev/null"
975 981 nullb = bfile_orig == "/dev/null"
976 982 abase, afile = pathstrip(afile_orig, strip)
977 gooda = not nulla and os.path.lexists(afile)
983 gooda = not nulla and backend.exists(afile)
978 984 bbase, bfile = pathstrip(bfile_orig, strip)
979 985 if afile == bfile:
980 986 goodb = gooda
981 987 else:
982 goodb = not nullb and os.path.lexists(bfile)
988 goodb = not nullb and backend.exists(bfile)
983 989 createfunc = hunk.createfile
984 990 missing = not goodb and not gooda and not createfunc()
985 991
@@ -1176,7 +1182,7 b' def _applydiff(ui, fp, patcher, changed,'
1176 1182 rejects += current_file.close()
1177 1183 afile, bfile, first_hunk = values
1178 1184 try:
1179 current_file, missing = selectfile(afile, bfile,
1185 current_file, missing = selectfile(backend, afile, bfile,
1180 1186 first_hunk, strip)
1181 1187 current_file = patcher(ui, current_file, backend,
1182 1188 missing=missing, eolmode=eolmode)
@@ -1347,7 +1353,8 b' def patch(ui, repo, patchname, strip=1, '
1347 1353 except PatchError, err:
1348 1354 raise util.Abort(str(err))
1349 1355
1350 def changedfiles(patchpath, strip=1):
1356 def changedfiles(ui, repo, patchpath, strip=1):
1357 backend = fsbackend(ui, repo.root)
1351 1358 fp = open(patchpath, 'rb')
1352 1359 try:
1353 1360 changed = set()
@@ -1356,7 +1363,7 b' def changedfiles(patchpath, strip=1):'
1356 1363 continue
1357 1364 elif state == 'file':
1358 1365 afile, bfile, first_hunk = values
1359 current_file, missing = selectfile(afile, bfile,
1366 current_file, missing = selectfile(backend, afile, bfile,
1360 1367 first_hunk, strip)
1361 1368 changed.add(current_file)
1362 1369 elif state == 'git':
General Comments 0
You need to be logged in to leave comments. Login now