433 return (False, files, False) |
433 return (False, files, False) |
434 |
434 |
435 return (True, files, fuzz) |
435 return (True, files, fuzz) |
436 |
436 |
437 def apply(self, repo, series, list=False, update_status=True, |
437 def apply(self, repo, series, list=False, update_status=True, |
438 strict=False, patchdir=None, merge=None, wlock=None): |
438 strict=False, patchdir=None, merge=None, wlock=None, |
|
439 all_files={}): |
|
440 tr = repo.transaction() |
|
441 try: |
|
442 ret = self._apply(tr, repo, series, list, update_status, |
|
443 strict, patchdir, merge, wlock, |
|
444 all_files=all_files) |
|
445 tr.close() |
|
446 self.save_dirty() |
|
447 return ret |
|
448 except: |
|
449 try: |
|
450 tr.abort() |
|
451 finally: |
|
452 repo.reload() |
|
453 repo.wreload() |
|
454 raise |
|
455 |
|
456 def _apply(self, tr, repo, series, list=False, update_status=True, |
|
457 strict=False, patchdir=None, merge=None, wlock=None, |
|
458 all_files={}): |
439 # TODO unify with commands.py |
459 # TODO unify with commands.py |
440 if not patchdir: |
460 if not patchdir: |
441 patchdir = self.path |
461 patchdir = self.path |
442 err = 0 |
462 err = 0 |
443 if not wlock: |
463 if not wlock: |
444 wlock = repo.wlock() |
464 wlock = repo.wlock() |
445 lock = repo.lock() |
465 lock = repo.lock() |
446 tr = repo.transaction() |
|
447 n = None |
466 n = None |
448 for patchname in series: |
467 for patchname in series: |
449 pushable, reason = self.pushable(patchname) |
468 pushable, reason = self.pushable(patchname) |
450 if not pushable: |
469 if not pushable: |
451 self.explain_pushable(patchname, all_patches=True) |
470 self.explain_pushable(patchname, all_patches=True) |
466 if list: |
485 if list: |
467 message.append("\nimported patch %s" % patchname) |
486 message.append("\nimported patch %s" % patchname) |
468 message = '\n'.join(message) |
487 message = '\n'.join(message) |
469 |
488 |
470 (patcherr, files, fuzz) = self.patch(repo, pf) |
489 (patcherr, files, fuzz) = self.patch(repo, pf) |
|
490 all_files.update(files) |
471 patcherr = not patcherr |
491 patcherr = not patcherr |
472 |
492 |
473 if merge and files: |
493 if merge and files: |
474 # Mark as removed/merged and update dirstate parent info |
494 # Mark as removed/merged and update dirstate parent info |
475 removed = [] |
495 removed = [] |
858 patch = self.series[start] |
877 patch = self.series[start] |
859 end = start + 1 |
878 end = start + 1 |
860 else: |
879 else: |
861 end = self.series.index(patch, start) + 1 |
880 end = self.series.index(patch, start) + 1 |
862 s = self.series[start:end] |
881 s = self.series[start:end] |
863 if mergeq: |
882 all_files = {} |
864 ret = self.mergepatch(repo, mergeq, s, wlock) |
883 try: |
865 else: |
884 if mergeq: |
866 ret = self.apply(repo, s, list, wlock=wlock) |
885 ret = self.mergepatch(repo, mergeq, s, wlock) |
|
886 else: |
|
887 ret = self.apply(repo, s, list, wlock=wlock, |
|
888 all_files=all_files) |
|
889 except: |
|
890 self.ui.warn(_('cleaning up working directory...')) |
|
891 node = repo.dirstate.parents()[0] |
|
892 hg.revert(repo, node, None, wlock) |
|
893 unknown = repo.status(wlock=wlock)[4] |
|
894 # only remove unknown files that we know we touched or |
|
895 # created while patching |
|
896 for f in unknown: |
|
897 if f in all_files: |
|
898 util.unlink(repo.wjoin(f)) |
|
899 self.ui.warn(_('done\n')) |
|
900 raise |
867 top = self.applied[-1].name |
901 top = self.applied[-1].name |
868 if ret[0]: |
902 if ret[0]: |
869 self.ui.write("Errors during apply, please fix and refresh %s\n" % |
903 self.ui.write("Errors during apply, please fix and refresh %s\n" % |
870 top) |
904 top) |
871 else: |
905 else: |
1835 return 1 |
1869 return 1 |
1836 mergeq = queue(ui, repo.join(""), newpath) |
1870 mergeq = queue(ui, repo.join(""), newpath) |
1837 ui.warn("merging with queue at: %s\n" % mergeq.path) |
1871 ui.warn("merging with queue at: %s\n" % mergeq.path) |
1838 ret = q.push(repo, patch, force=opts['force'], list=opts['list'], |
1872 ret = q.push(repo, patch, force=opts['force'], list=opts['list'], |
1839 mergeq=mergeq) |
1873 mergeq=mergeq) |
1840 q.save_dirty() |
|
1841 return ret |
1874 return ret |
1842 |
1875 |
1843 def pop(ui, repo, patch=None, **opts): |
1876 def pop(ui, repo, patch=None, **opts): |
1844 """pop the current patch off the stack""" |
1877 """pop the current patch off the stack""" |
1845 localupdate = True |
1878 localupdate = True |