Mercurial > hg > mercurial-crew-with-dirclash
comparison mercurial/localrepo.py @ 4961:126f527b3ba3
Make repo locks recursive, eliminate all passing of lock/wlock
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Sat, 21 Jul 2007 16:02:10 -0500 |
parents | 5c5d23d93447 |
children | 30d4d8985dd8 |
comparison
equal
deleted
inserted
replaced
4960:5c5d23d93447 | 4961:126f527b3ba3 |
---|---|
528 self.ui.warn(_("no interrupted transaction available\n")) | 528 self.ui.warn(_("no interrupted transaction available\n")) |
529 return False | 529 return False |
530 finally: | 530 finally: |
531 del l | 531 del l |
532 | 532 |
533 def rollback(self, wlock=None, lock=None): | 533 def rollback(self): |
534 try: | 534 wlock = lock = None |
535 if not wlock: | 535 try: |
536 wlock = self.wlock() | 536 wlock = self.wlock() |
537 if not lock: | 537 lock = self.lock() |
538 lock = self.lock() | |
539 if os.path.exists(self.sjoin("undo")): | 538 if os.path.exists(self.sjoin("undo")): |
540 self.ui.status(_("rolling back last transaction\n")) | 539 self.ui.status(_("rolling back last transaction\n")) |
541 transaction.rollback(self.sopener, self.sjoin("undo")) | 540 transaction.rollback(self.sopener, self.sjoin("undo")) |
542 util.rename(self.join("undo.dirstate"), self.join("dirstate")) | 541 util.rename(self.join("undo.dirstate"), self.join("dirstate")) |
543 self.invalidate() | 542 self.invalidate() |
568 if acquirefn: | 567 if acquirefn: |
569 acquirefn() | 568 acquirefn() |
570 return l | 569 return l |
571 | 570 |
572 def lock(self, wait=True): | 571 def lock(self, wait=True): |
573 return self._lock(self.sjoin("lock"), wait, None, self.invalidate, | 572 if self._lockref and self._lockref(): |
574 _('repository %s') % self.origroot) | 573 return self._lockref() |
574 | |
575 l = self._lock(self.sjoin("lock"), wait, None, self.invalidate, | |
576 _('repository %s') % self.origroot) | |
577 self._lockref = weakref.ref(l) | |
578 return l | |
575 | 579 |
576 def wlock(self, wait=True): | 580 def wlock(self, wait=True): |
577 return self._lock(self.join("wlock"), wait, self.dirstate.write, | 581 if self._wlockref and self._wlockref(): |
578 self.dirstate.invalidate, | 582 return self._wlockref() |
579 _('working directory of %s') % self.origroot) | 583 |
584 l = self._lock(self.join("wlock"), wait, self.dirstate.write, | |
585 self.dirstate.invalidate, _('working directory of %s') % | |
586 self.origroot) | |
587 self._wlockref = weakref.ref(l) | |
588 return l | |
580 | 589 |
581 def filecommit(self, fn, manifest1, manifest2, linkrev, transaction, changelist): | 590 def filecommit(self, fn, manifest1, manifest2, linkrev, transaction, changelist): |
582 """ | 591 """ |
583 commit an individual file as part of a larger transaction | 592 commit an individual file as part of a larger transaction |
584 """ | 593 """ |
636 return fp1 | 645 return fp1 |
637 | 646 |
638 changelist.append(fn) | 647 changelist.append(fn) |
639 return fl.add(t, meta, transaction, linkrev, fp1, fp2) | 648 return fl.add(t, meta, transaction, linkrev, fp1, fp2) |
640 | 649 |
641 def rawcommit(self, files, text, user, date, p1=None, p2=None, wlock=None, extra={}): | 650 def rawcommit(self, files, text, user, date, p1=None, p2=None, extra={}): |
642 if p1 is None: | 651 if p1 is None: |
643 p1, p2 = self.dirstate.parents() | 652 p1, p2 = self.dirstate.parents() |
644 return self.commit(files=files, text=text, user=user, date=date, | 653 return self.commit(files=files, text=text, user=user, date=date, |
645 p1=p1, p2=p2, wlock=wlock, extra=extra) | 654 p1=p1, p2=p2, extra=extra) |
646 | 655 |
647 def commit(self, files=None, text="", user=None, date=None, | 656 def commit(self, files=None, text="", user=None, date=None, |
648 match=util.always, force=False, lock=None, wlock=None, | 657 match=util.always, force=False, force_editor=False, |
649 force_editor=False, p1=None, p2=None, extra={}): | 658 p1=None, p2=None, extra={}): |
650 tr = None | 659 wlock = lock = tr = None |
651 try: | 660 try: |
652 commit = [] | 661 commit = [] |
653 remove = [] | 662 remove = [] |
654 changed = [] | 663 changed = [] |
655 use_dirstate = (p1 is None) # not rawcommit | 664 use_dirstate = (p1 is None) # not rawcommit |
705 if p2 == nullid: xp2 = '' | 714 if p2 == nullid: xp2 = '' |
706 else: xp2 = hex(p2) | 715 else: xp2 = hex(p2) |
707 | 716 |
708 self.hook("precommit", throw=True, parent1=xp1, parent2=xp2) | 717 self.hook("precommit", throw=True, parent1=xp1, parent2=xp2) |
709 | 718 |
710 if not wlock: | 719 wlock = self.wlock() |
711 wlock = self.wlock() | 720 lock = self.lock() |
712 if not lock: | |
713 lock = self.lock() | |
714 tr = self.transaction() | 721 tr = self.transaction() |
715 | 722 |
716 # check in files | 723 # check in files |
717 new = {} | 724 new = {} |
718 linkrev = self.changelog.count() | 725 linkrev = self.changelog.count() |
852 else: | 859 else: |
853 for src, fn in self.dirstate.walk(files, match, badmatch=badmatch): | 860 for src, fn in self.dirstate.walk(files, match, badmatch=badmatch): |
854 yield src, fn | 861 yield src, fn |
855 | 862 |
856 def status(self, node1=None, node2=None, files=[], match=util.always, | 863 def status(self, node1=None, node2=None, files=[], match=util.always, |
857 wlock=None, list_ignored=False, list_clean=False): | 864 list_ignored=False, list_clean=False): |
858 """return status of files between two nodes or node and working directory | 865 """return status of files between two nodes or node and working directory |
859 | 866 |
860 If node1 is None, use the first dirstate parent instead. | 867 If node1 is None, use the first dirstate parent instead. |
861 If node2 is None, compare node1 with working directory. | 868 If node2 is None, compare node1 with working directory. |
862 """ | 869 """ |
906 if list_clean: | 913 if list_clean: |
907 clean.append(f) | 914 clean.append(f) |
908 | 915 |
909 # update dirstate for files that are actually clean | 916 # update dirstate for files that are actually clean |
910 if fixup: | 917 if fixup: |
911 fixlock = wlock | 918 wlock = None |
912 try: | 919 try: |
913 if not fixlock: | 920 try: |
914 try: | 921 wlock = self.wlock(False) |
915 fixlock = self.wlock(False) | 922 except lock.LockException: |
916 except lock.LockException: | 923 pass |
917 pass | 924 if wlock: |
918 if fixlock: | |
919 for f in fixup: | 925 for f in fixup: |
920 self.dirstate.normal(f) | 926 self.dirstate.normal(f) |
921 finally: | 927 finally: |
922 del fixlock | 928 del wlock |
923 else: | 929 else: |
924 # we are comparing working dir against non-parent | 930 # we are comparing working dir against non-parent |
925 # generate a pseudo-manifest for the working dir | 931 # generate a pseudo-manifest for the working dir |
926 # XXX: create it in dirstate.py ? | 932 # XXX: create it in dirstate.py ? |
927 mf2 = mfmatches(self.dirstate.parents()[0]) | 933 mf2 = mfmatches(self.dirstate.parents()[0]) |
964 # sort and return results: | 970 # sort and return results: |
965 for l in modified, added, removed, deleted, unknown, ignored, clean: | 971 for l in modified, added, removed, deleted, unknown, ignored, clean: |
966 l.sort() | 972 l.sort() |
967 return (modified, added, removed, deleted, unknown, ignored, clean) | 973 return (modified, added, removed, deleted, unknown, ignored, clean) |
968 | 974 |
969 def add(self, list, wlock=None): | 975 def add(self, list): |
970 try: | 976 wlock = self.wlock() |
971 if not wlock: | 977 try: |
972 wlock = self.wlock() | |
973 for f in list: | 978 for f in list: |
974 p = self.wjoin(f) | 979 p = self.wjoin(f) |
975 try: | 980 try: |
976 st = os.lstat(p) | 981 st = os.lstat(p) |
977 except: | 982 except: |
990 else: | 995 else: |
991 self.dirstate.add(f) | 996 self.dirstate.add(f) |
992 finally: | 997 finally: |
993 del wlock | 998 del wlock |
994 | 999 |
995 def forget(self, list, wlock=None): | 1000 def forget(self, list): |
996 try: | 1001 wlock = self.wlock() |
997 if not wlock: | 1002 try: |
998 wlock = self.wlock() | |
999 for f in list: | 1003 for f in list: |
1000 if self.dirstate[f] != 'a': | 1004 if self.dirstate[f] != 'a': |
1001 self.ui.warn(_("%s not added!\n") % f) | 1005 self.ui.warn(_("%s not added!\n") % f) |
1002 else: | 1006 else: |
1003 self.dirstate.forget(f) | 1007 self.dirstate.forget(f) |
1004 finally: | 1008 finally: |
1005 del wlock | 1009 del wlock |
1006 | 1010 |
1007 def remove(self, list, unlink=False, wlock=None): | 1011 def remove(self, list, unlink=False): |
1012 wlock = None | |
1008 try: | 1013 try: |
1009 if unlink: | 1014 if unlink: |
1010 for f in list: | 1015 for f in list: |
1011 try: | 1016 try: |
1012 util.unlink(self.wjoin(f)) | 1017 util.unlink(self.wjoin(f)) |
1013 except OSError, inst: | 1018 except OSError, inst: |
1014 if inst.errno != errno.ENOENT: | 1019 if inst.errno != errno.ENOENT: |
1015 raise | 1020 raise |
1016 if not wlock: | 1021 wlock = self.wlock() |
1017 wlock = self.wlock() | |
1018 for f in list: | 1022 for f in list: |
1019 if unlink and os.path.exists(self.wjoin(f)): | 1023 if unlink and os.path.exists(self.wjoin(f)): |
1020 self.ui.warn(_("%s still exists!\n") % f) | 1024 self.ui.warn(_("%s still exists!\n") % f) |
1021 elif self.dirstate[f] == 'a': | 1025 elif self.dirstate[f] == 'a': |
1022 self.dirstate.forget(f) | 1026 self.dirstate.forget(f) |
1025 else: | 1029 else: |
1026 self.dirstate.remove(f) | 1030 self.dirstate.remove(f) |
1027 finally: | 1031 finally: |
1028 del wlock | 1032 del wlock |
1029 | 1033 |
1030 def undelete(self, list, wlock=None): | 1034 def undelete(self, list): |
1035 wlock = None | |
1031 try: | 1036 try: |
1032 p = self.dirstate.parents()[0] | 1037 p = self.dirstate.parents()[0] |
1033 mn = self.changelog.read(p)[0] | 1038 mn = self.changelog.read(p)[0] |
1034 m = self.manifest.read(mn) | 1039 m = self.manifest.read(mn) |
1035 if not wlock: | 1040 wlock = self.wlock() |
1036 wlock = self.wlock() | |
1037 for f in list: | 1041 for f in list: |
1038 if self.dirstate[f] != 'r': | 1042 if self.dirstate[f] != 'r': |
1039 self.ui.warn("%s not removed!\n" % f) | 1043 self.ui.warn("%s not removed!\n" % f) |
1040 else: | 1044 else: |
1041 t = self.file(f).read(m[f]) | 1045 t = self.file(f).read(m[f]) |
1042 self.wwrite(f, t, m.flags(f)) | 1046 self.wwrite(f, t, m.flags(f)) |
1043 self.dirstate.normal(f) | 1047 self.dirstate.normal(f) |
1044 finally: | 1048 finally: |
1045 del wlock | 1049 del wlock |
1046 | 1050 |
1047 def copy(self, source, dest, wlock=None): | 1051 def copy(self, source, dest): |
1052 wlock = None | |
1048 try: | 1053 try: |
1049 p = self.wjoin(dest) | 1054 p = self.wjoin(dest) |
1050 if not (os.path.exists(p) or os.path.islink(p)): | 1055 if not (os.path.exists(p) or os.path.islink(p)): |
1051 self.ui.warn(_("%s does not exist!\n") % dest) | 1056 self.ui.warn(_("%s does not exist!\n") % dest) |
1052 elif not (os.path.isfile(p) or os.path.islink(p)): | 1057 elif not (os.path.isfile(p) or os.path.islink(p)): |
1053 self.ui.warn(_("copy failed: %s is not a file or a " | 1058 self.ui.warn(_("copy failed: %s is not a file or a " |
1054 "symbolic link\n") % dest) | 1059 "symbolic link\n") % dest) |
1055 else: | 1060 else: |
1056 if not wlock: | 1061 wlock = self.wlock() |
1057 wlock = self.wlock() | |
1058 if dest not in self.dirstate: | 1062 if dest not in self.dirstate: |
1059 self.dirstate.add(dest) | 1063 self.dirstate.add(dest) |
1060 self.dirstate.copy(source, dest) | 1064 self.dirstate.copy(source, dest) |
1061 finally: | 1065 finally: |
1062 del wlock | 1066 del wlock |
1334 if heads: | 1338 if heads: |
1335 return subset, updated_heads.keys() | 1339 return subset, updated_heads.keys() |
1336 else: | 1340 else: |
1337 return subset | 1341 return subset |
1338 | 1342 |
1339 def pull(self, remote, heads=None, force=False, lock=None): | 1343 def pull(self, remote, heads=None, force=False): |
1340 try: | 1344 lock = self.lock() |
1341 if not lock: | 1345 try: |
1342 lock = self.lock() | |
1343 fetch = self.findincoming(remote, force=force) | 1346 fetch = self.findincoming(remote, force=force) |
1344 if fetch == [nullid]: | 1347 if fetch == [nullid]: |
1345 self.ui.status(_("requesting all changes\n")) | 1348 self.ui.status(_("requesting all changes\n")) |
1346 | 1349 |
1347 if not fetch: | 1350 if not fetch: |