changeset 8109:496ae1ea4698

switch lock releasing in the core from gc to explicit
author Ronny Pfannschmidt <Ronny.Pfannschmidt@gmx.de>
date Wed, 22 Apr 2009 02:01:22 +0200
parents a26d33749bd8
children b616f328af9f
files mercurial/commands.py mercurial/hbisect.py mercurial/hg.py mercurial/hgweb/protocol.py mercurial/localrepo.py mercurial/merge.py mercurial/sshserver.py mercurial/streamclone.py mercurial/verify.py
diffstat 9 files changed, 52 insertions(+), 47 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/commands.py	Wed Apr 22 02:01:22 2009 +0200
+++ b/mercurial/commands.py	Wed Apr 22 02:01:22 2009 +0200
@@ -6,6 +6,7 @@
 # of the GNU General Public License, incorporated herein by reference.
 
 from node import hex, nullid, nullrev, short
+from lock import release
 from i18n import _, gettext
 import os, re, sys, textwrap
 import hg, util, revlog, bundlerepo, extensions, copies, context, error
@@ -684,7 +685,7 @@
     try:
         return cmdutil.copy(ui, repo, pats, opts)
     finally:
-        del wlock
+        wlock.release()
 
 def debugancestor(ui, repo, *args):
     """find the ancestor revision of two revisions in a given index"""
@@ -747,7 +748,7 @@
     try:
         repo.dirstate.rebuild(ctx.node(), ctx.manifest())
     finally:
-        del wlock
+        wlock.release()
 
 def debugcheckstate(ui, repo):
     """validate the correctness of the current dirstate"""
@@ -816,7 +817,7 @@
     try:
         repo.dirstate.setparents(repo.lookup(rev1), repo.lookup(rev2))
     finally:
-        del wlock
+        wlock.release()
 
 def debugstate(ui, repo, nodates=None):
     """show the contents of the current dirstate"""
@@ -1743,7 +1744,7 @@
             finally:
                 os.unlink(tmpname)
     finally:
-        del lock, wlock
+        release(lock, wlock)
 
 def incoming(ui, repo, source="default", **opts):
     """show new changesets found in source
@@ -2355,7 +2356,7 @@
     try:
         return cmdutil.copy(ui, repo, pats, opts, rename=True)
     finally:
-        del wlock
+        wlock.release()
 
 def resolve(ui, repo, *pats, **opts):
     """retry file merges from a merge or update
@@ -2627,7 +2628,7 @@
                 normal(f)
 
     finally:
-        del wlock
+        wlock.release()
 
 def rollback(ui, repo):
     """roll back the last transaction
@@ -2919,15 +2920,14 @@
     """
     fnames = (fname1,) + fnames
 
-    lock = None
+    lock = repo.lock()
     try:
-        lock = repo.lock()
         for fname in fnames:
             f = url.open(ui, fname)
             gen = changegroup.readbundle(f, fname)
             modheads = repo.addchangegroup(gen, 'unbundle', 'bundle:' + fname)
     finally:
-        del lock
+        lock.release()
 
     return postincoming(ui, repo, modheads, opts.get('update'), None)
 
--- a/mercurial/hbisect.py	Wed Apr 22 02:01:22 2009 +0200
+++ b/mercurial/hbisect.py	Wed Apr 22 02:01:22 2009 +0200
@@ -140,5 +140,5 @@
                 f.write("%s %s\n" % (kind, hex(node)))
         f.rename()
     finally:
-        del wlock
+        wlock.release()
 
--- a/mercurial/hg.py	Wed Apr 22 02:01:22 2009 +0200
+++ b/mercurial/hg.py	Wed Apr 22 02:01:22 2009 +0200
@@ -7,6 +7,7 @@
 # of the GNU General Public License, incorporated herein by reference.
 
 from i18n import _
+from lock import release
 import localrepo, bundlerepo, httprepo, sshrepo, statichttprepo
 import errno, lock, os, shutil, util, extensions, error
 import merge as _merge
@@ -249,7 +250,8 @@
 
         return src_repo, dest_repo
     finally:
-        del src_lock, dest_lock, dir_cleanup
+        release(src_lock, dest_lock)
+        del dir_cleanup
 
 def _showstats(repo, stats):
     stats = ((stats[0], _("updated")),
--- a/mercurial/hgweb/protocol.py	Wed Apr 22 02:01:22 2009 +0200
+++ b/mercurial/hgweb/protocol.py	Wed Apr 22 02:01:22 2009 +0200
@@ -163,7 +163,7 @@
                 req.respond(HTTP_OK, HGTYPE)
                 return '%d\n%s' % (ret, val),
             finally:
-                del lock
+                lock.release()
         except ValueError, inst:
             raise ErrorResponse(HTTP_OK, inst)
         except (OSError, IOError), inst:
--- a/mercurial/localrepo.py	Wed Apr 22 02:01:22 2009 +0200
+++ b/mercurial/localrepo.py	Wed Apr 22 02:01:22 2009 +0200
@@ -14,6 +14,8 @@
 import match as match_
 import merge as merge_
 
+from lock import release
+
 class localrepository(repo.repository):
     capabilities = util.set(('lookup', 'changegroupsubset'))
     supported = ('revlogv1', 'store', 'fncache')
@@ -620,7 +622,7 @@
         return tr
 
     def recover(self):
-        l = self.lock()
+        lock = self.lock()
         try:
             if os.path.exists(self.sjoin("journal")):
                 self.ui.status(_("rolling back interrupted transaction\n"))
@@ -631,7 +633,7 @@
                 self.ui.warn(_("no interrupted transaction available\n"))
                 return False
         finally:
-            del l
+            lock.release()
 
     def rollback(self):
         wlock = lock = None
@@ -654,7 +656,7 @@
             else:
                 self.ui.warn(_("no rollback information available\n"))
         finally:
-            del lock, wlock
+            release(lock, wlock)
 
     def invalidate(self):
         for a in "changelog manifest".split():
@@ -835,7 +837,7 @@
             return r
 
         finally:
-            del lock, wlock
+            release(lock, wlock)
 
     def commitctx(self, ctx):
         """Add a new revision to current repository.
@@ -851,7 +853,7 @@
                                    empty_ok=True, use_dirstate=False,
                                    update_dirstate=False)
         finally:
-            del lock, wlock
+            release(lock, wlock)
 
     def _commitctx(self, wctx, force=False, force_editor=False, empty_ok=False,
                   use_dirstate=True, update_dirstate=True):
@@ -1072,7 +1074,7 @@
                         except error.LockError:
                             pass
                     finally:
-                        del wlock
+                        release(wlock)
 
         if not parentworking:
             mf1 = mfmatches(ctx1)
@@ -1138,7 +1140,7 @@
                     self.dirstate.add(f)
             return rejected
         finally:
-            del wlock
+            wlock.release()
 
     def forget(self, list):
         wlock = self.wlock()
@@ -1149,7 +1151,7 @@
                 else:
                     self.dirstate.forget(f)
         finally:
-            del wlock
+            wlock.release()
 
     def remove(self, list, unlink=False):
         wlock = None
@@ -1172,14 +1174,13 @@
                 else:
                     self.dirstate.remove(f)
         finally:
-            del wlock
+            release(wlock)
 
     def undelete(self, list):
-        wlock = None
+        manifests = [self.manifest.read(self.changelog.read(p)[0])
+                     for p in self.dirstate.parents() if p != nullid]
+        wlock = self.wlock()
         try:
-            manifests = [self.manifest.read(self.changelog.read(p)[0])
-                         for p in self.dirstate.parents() if p != nullid]
-            wlock = self.wlock()
             for f in list:
                 if self.dirstate[f] != 'r':
                     self.ui.warn(_("%s not removed!\n") % f)
@@ -1189,24 +1190,23 @@
                     self.wwrite(f, t, m.flags(f))
                     self.dirstate.normal(f)
         finally:
-            del wlock
+            wlock.release()
 
     def copy(self, source, dest):
-        wlock = None
-        try:
-            p = self.wjoin(dest)
-            if not (os.path.exists(p) or os.path.islink(p)):
-                self.ui.warn(_("%s does not exist!\n") % dest)
-            elif not (os.path.isfile(p) or os.path.islink(p)):
-                self.ui.warn(_("copy failed: %s is not a file or a "
-                               "symbolic link\n") % dest)
-            else:
-                wlock = self.wlock()
+        p = self.wjoin(dest)
+        if not (os.path.exists(p) or os.path.islink(p)):
+            self.ui.warn(_("%s does not exist!\n") % dest)
+        elif not (os.path.isfile(p) or os.path.islink(p)):
+            self.ui.warn(_("copy failed: %s is not a file or a "
+                           "symbolic link\n") % dest)
+        else:
+            wlock = self.wlock()
+            try:
                 if self.dirstate[dest] in '?r':
                     self.dirstate.add(dest)
                 self.dirstate.copy(source, dest)
-        finally:
-            del wlock
+            finally:
+                wlock.release()
 
     def heads(self, start=None, closed=True):
         heads = self.changelog.heads(start)
@@ -1500,7 +1500,7 @@
                 cg = remote.changegroupsubset(fetch, heads, 'pull')
             return self.addchangegroup(cg, 'pull', remote.url())
         finally:
-            del lock
+            lock.release()
 
     def push(self, remote, force=False, revs=None):
         # there are two ways to push to remote repo:
@@ -1581,7 +1581,7 @@
                 return remote.addchangegroup(cg, 'push', self.url())
             return ret[1]
         finally:
-            del lock
+            lock.release()
 
     def push_unbundle(self, remote, force, revs):
         # local repo finds heads on server, finds out what revs it
--- a/mercurial/merge.py	Wed Apr 22 02:01:22 2009 +0200
+++ b/mercurial/merge.py	Wed Apr 22 02:01:22 2009 +0200
@@ -504,4 +504,4 @@
 
         return stats
     finally:
-        del wlock
+        wlock.release()
--- a/mercurial/sshserver.py	Wed Apr 22 02:01:22 2009 +0200
+++ b/mercurial/sshserver.py	Wed Apr 22 02:01:22 2009 +0200
@@ -37,7 +37,11 @@
         self.fout.flush()
 
     def serve_forever(self):
-        while self.serve_one(): pass
+        try:
+            while self.serve_one(): pass
+        finally:
+            if self.lock is not None:
+                self.lock.release()
         sys.exit(0)
 
     def serve_one(self):
--- a/mercurial/streamclone.py	Wed Apr 22 02:01:22 2009 +0200
+++ b/mercurial/streamclone.py	Wed Apr 22 02:01:22 2009 +0200
@@ -41,16 +41,15 @@
     entries = []
     total_bytes = 0
     try:
-        l = None
+        # get consistent snapshot of repo, lock during scan
+        lock = repo.lock()
         try:
             repo.ui.debug(_('scanning\n'))
-            # get consistent snapshot of repo, lock during scan
-            l = repo.lock()
             for name, ename, size in repo.store.walk():
                 entries.append((name, size))
                 total_bytes += size
         finally:
-            del l
+            lock.release()
     except error.LockError:
         raise StreamException(2)
 
--- a/mercurial/verify.py	Wed Apr 22 02:01:22 2009 +0200
+++ b/mercurial/verify.py	Wed Apr 22 02:01:22 2009 +0200
@@ -14,7 +14,7 @@
     try:
         return _verify(repo)
     finally:
-        del lock
+        lock.release()
 
 def _verify(repo):
     mflinkrevs = {}