comparison hgext/keyword.py @ 32935:69d1c3ea0d6f

keyword: use context manager for rollback locking
author Christian Ebert <blacktrash@gmx.net>
date Tue, 20 Jun 2017 12:51:36 +0100
parents 50586a0a946f
children 7f569ce30216
comparison
equal deleted inserted replaced
32934:6123a5267119 32935:69d1c3ea0d6f
637 False, True) 637 False, True)
638 kwt.restrict = restrict 638 kwt.restrict = restrict
639 return n 639 return n
640 640
641 def rollback(self, dryrun=False, force=False): 641 def rollback(self, dryrun=False, force=False):
642 wlock = self.wlock() 642 with self.wlock():
643 origrestrict = kwt.restrict 643 origrestrict = kwt.restrict
644 try: 644 try:
645 if not dryrun: 645 if not dryrun:
646 changed = self['.'].files() 646 changed = self['.'].files()
647 ret = super(kwrepo, self).rollback(dryrun, force) 647 ret = super(kwrepo, self).rollback(dryrun, force)
648 if not dryrun: 648 if not dryrun:
649 ctx = self['.'] 649 ctx = self['.']
650 modified, added = _preselect(ctx.status(), changed) 650 modified, added = _preselect(ctx.status(), changed)
651 kwt.restrict = False 651 kwt.restrict = False
652 kwt.overwrite(ctx, modified, True, True) 652 kwt.overwrite(ctx, modified, True, True)
653 kwt.overwrite(ctx, added, True, False) 653 kwt.overwrite(ctx, added, True, False)
654 return ret 654 return ret
655 finally: 655 finally:
656 kwt.restrict = origrestrict 656 kwt.restrict = origrestrict
657 wlock.release()
658 657
659 # monkeypatches 658 # monkeypatches
660 def kwpatchfile_init(orig, self, ui, gp, backend, store, eolmode=None): 659 def kwpatchfile_init(orig, self, ui, gp, backend, store, eolmode=None):
661 '''Monkeypatch/wrap patch.patchfile.__init__ to avoid 660 '''Monkeypatch/wrap patch.patchfile.__init__ to avoid
662 rejects or conflicts due to expanded keywords in working dir.''' 661 rejects or conflicts due to expanded keywords in working dir.'''