##// END OF EJS Templates
patch: add a workingbackend dirstate layer on top of fsbackend...
Patrick Mezard -
r14370:17cea10c default
parent child Browse files
Show More
@@ -477,8 +477,7 b' def dorecord(ui, repo, commitfunc, *pats'
477 477 try:
478 478 ui.debug('applying patch\n')
479 479 ui.debug(fp.getvalue())
480 patch.internalpatch(ui, repo, fp, 1, repo.root,
481 eolmode=None)
480 patch.internalpatch(ui, repo, fp, 1, eolmode=None)
482 481 except patch.PatchError, err:
483 482 raise util.Abort(str(err))
484 483 del fp
@@ -478,6 +478,49 b' class fsbackend(abstractbackend):'
478 478 def setmode(self, fname, islink, isexec):
479 479 util.setflags(self._join(fname), islink, isexec)
480 480
481 class workingbackend(fsbackend):
482 def __init__(self, ui, repo, similarity):
483 super(workingbackend, self).__init__(ui, repo.root)
484 self.repo = repo
485 self.similarity = similarity
486 self.removed = set()
487 self.changed = set()
488 self.copied = []
489
490 def writelines(self, fname, lines, mode):
491 super(workingbackend, self).writelines(fname, lines, mode)
492 self.changed.add(fname)
493
494 def unlink(self, fname):
495 super(workingbackend, self).unlink(fname)
496 self.removed.add(fname)
497 self.changed.add(fname)
498
499 def copy(self, src, dst):
500 super(workingbackend, self).copy(src, dst)
501 self.copied.append((src, dst))
502 self.changed.add(dst)
503
504 def setmode(self, fname, islink, isexec):
505 super(workingbackend, self).setmode(fname, islink, isexec)
506 self.changed.add(fname)
507
508 def close(self):
509 wctx = self.repo[None]
510 addremoved = set(self.changed)
511 for src, dst in self.copied:
512 scmutil.dirstatecopy(self.ui, self.repo, wctx, src, dst)
513 addremoved.discard(src)
514 if (not self.similarity) and self.removed:
515 wctx.remove(sorted(self.removed))
516 if addremoved:
517 cwd = self.repo.getcwd()
518 if cwd:
519 addremoved = [util.pathto(self.repo.root, cwd, f)
520 for f in addremoved]
521 scmutil.addremove(self.repo, addremoved, similarity=self.similarity)
522 return sorted(self.changed)
523
481 524 # @@ -start,len +start,len @@ or @@ -start +start @@ if len is 1
482 525 unidesc = re.compile('@@ -(\d+)(,(\d+))? \+(\d+)(,(\d+))? @@')
483 526 contextdesc = re.compile('(---|\*\*\*) (\d+)(,(\d+))? (---|\*\*\*)')
@@ -1169,9 +1212,6 b' def applydiff(ui, fp, changed, backend, '
1169 1212 If 'eolmode' is 'strict', the patch content and patched file are
1170 1213 read in binary mode. Otherwise, line endings are ignored when
1171 1214 patching then normalized according to 'eolmode'.
1172
1173 Callers probably want to call '_updatedir' after this to
1174 apply certain categories of changes not done by this function.
1175 1215 """
1176 1216 return _applydiff(ui, fp, patchfile, backend, changed, strip=strip,
1177 1217 eolmode=eolmode)
@@ -1311,7 +1351,7 b' def _externalpatch(patcher, patchname, u'
1311 1351 util.explainexit(code)[0])
1312 1352 return fuzz
1313 1353
1314 def internalpatch(ui, repo, patchobj, strip, cwd, files=None, eolmode='strict',
1354 def internalpatch(ui, repo, patchobj, strip, files=None, eolmode='strict',
1315 1355 similarity=0):
1316 1356 """use builtin patch to apply <patchobj> to the working directory.
1317 1357 returns whether patch was applied with fuzz factor."""
@@ -1324,7 +1364,7 b' def internalpatch(ui, repo, patchobj, st'
1324 1364 raise util.Abort(_('unsupported line endings type: %s') % eolmode)
1325 1365 eolmode = eolmode.lower()
1326 1366
1327 backend = fsbackend(ui, cwd)
1367 backend = workingbackend(ui, repo, similarity)
1328 1368 try:
1329 1369 fp = open(patchobj, 'rb')
1330 1370 except TypeError:
@@ -1334,8 +1374,7 b' def internalpatch(ui, repo, patchobj, st'
1334 1374 finally:
1335 1375 if fp != patchobj:
1336 1376 fp.close()
1337 touched = _updatedir(ui, repo, files, similarity)
1338 files.update(dict.fromkeys(touched))
1377 files.update(dict.fromkeys(backend.close()))
1339 1378 if ret < 0:
1340 1379 raise PatchError(_('patch failed to apply'))
1341 1380 return ret > 0
@@ -1364,7 +1403,7 b' def patch(ui, repo, patchname, strip=1, '
1364 1403 finally:
1365 1404 touched = _updatedir(ui, repo, files, similarity)
1366 1405 files.update(dict.fromkeys(touched))
1367 return internalpatch(ui, repo, patchname, strip, cwd, files, eolmode,
1406 return internalpatch(ui, repo, patchname, strip, files, eolmode,
1368 1407 similarity)
1369 1408 except PatchError, err:
1370 1409 raise util.Abort(str(err))
@@ -101,7 +101,6 b' Push git patch with missing target:'
101 101 applying changeb
102 102 unable to find 'b' for patching
103 103 1 out of 1 hunks FAILED -- saving rejects to file b.rej
104 b: No such file or directory
105 104 patch failed, unable to continue (try -v)
106 105 patch failed, rejects left in working dir
107 106 errors during apply, please fix and refresh changeb
General Comments 0
You need to be logged in to leave comments. Login now