Patchwork [8,of,8] lock: take both vfs and lock file path relative to vfs to access via vfs

login
register
mail settings
Submitter Katsunori FUJIWARA
Date Nov. 12, 2013, 7:31 a.m.
Message ID <56afda9e0ab01e4ff68e.1384241517@juju>
Download mbox | patch
Permalink /patch/2931/
State Accepted
Commit abfe6a8e619b6b9d2b15018bdf2e3bac80e02f29
Headers show

Comments

Katsunori FUJIWARA - Nov. 12, 2013, 7:31 a.m.
# HG changeset patch
# User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
# Date 1384241032 -32400
#      Tue Nov 12 16:23:52 2013 +0900
# Node ID 56afda9e0ab01e4ff68e027c6bc3064edb99d1f8
# Parent  8aea1ee094ee05bea6f89851f408895e3bf16c6f
lock: take both vfs and lock file path relative to vfs to access via vfs

This patch makes "lock.lock.__init__()" take both vfs and lock file
path relative to vfs, instead of absolute path to lock file.

This allows lock file to be accessed via vfs.
Matt Mackall - Nov. 22, 2013, 9:38 p.m.
On Tue, 2013-11-12 at 16:31 +0900, FUJIWARA Katsunori wrote:
> # HG changeset patch
> # User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
> # Date 1384241032 -32400
> #      Tue Nov 12 16:23:52 2013 +0900
> # Node ID 56afda9e0ab01e4ff68e027c6bc3064edb99d1f8
> # Parent  8aea1ee094ee05bea6f89851f408895e3bf16c6f
> lock: take both vfs and lock file path relative to vfs to access via vfs

These are queued for default, thanks.

Patch

diff --git a/mercurial/hg.py b/mercurial/hg.py
--- a/mercurial/hg.py
+++ b/mercurial/hg.py
@@ -213,7 +213,7 @@ 
             if srcvfs.exists(f):
                 if f.endswith('data'):
                     # lock to avoid premature writing to the target
-                    destlock = lock.lock(dstvfs.join(dstbase + "/lock"))
+                    destlock = lock.lock(dstvfs, dstbase + "/lock")
                 hardlink, n = util.copyfiles(srcvfs.join(f), dstvfs.join(f),
                                              hardlink)
                 num += n
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -999,16 +999,16 @@ 
                 pass
         self.invalidatecaches()
 
-    def _lock(self, lockname, wait, releasefn, acquirefn, desc):
+    def _lock(self, vfs, lockname, wait, releasefn, acquirefn, desc):
         try:
-            l = lockmod.lock(lockname, 0, releasefn, desc=desc)
+            l = lockmod.lock(vfs, lockname, 0, releasefn, desc=desc)
         except error.LockHeld, inst:
             if not wait:
                 raise
             self.ui.warn(_("waiting for lock on %s held by %r\n") %
                          (desc, inst.locker))
             # default to 600 seconds timeout
-            l = lockmod.lock(lockname,
+            l = lockmod.lock(vfs, lockname,
                              int(self.ui.config("ui", "timeout", "600")),
                              releasefn, desc=desc)
         if acquirefn:
@@ -1043,7 +1043,7 @@ 
                     continue
                 ce.refresh()
 
-        l = self._lock(self.sjoin("lock"), wait, unlock,
+        l = self._lock(self.svfs, "lock", wait, unlock,
                        self.invalidate, _('repository %s') % self.origroot)
         self._lockref = weakref.ref(l)
         return l
@@ -1061,7 +1061,7 @@ 
             self.dirstate.write()
             self._filecache['dirstate'].refresh()
 
-        l = self._lock(self.join("wlock"), wait, unlock,
+        l = self._lock(self.vfs, "wlock", wait, unlock,
                        self.invalidatedirstate, _('working directory of %s') %
                        self.origroot)
         self._wlockref = weakref.ref(l)
diff --git a/mercurial/lock.py b/mercurial/lock.py
--- a/mercurial/lock.py
+++ b/mercurial/lock.py
@@ -29,7 +29,8 @@ 
 
     _host = None
 
-    def __init__(self, file, timeout=-1, releasefn=None, desc=None):
+    def __init__(self, vfs, file, timeout=-1, releasefn=None, desc=None):
+        self.vfs = vfs
         self.f = file
         self.held = 0
         self.timeout = timeout
@@ -75,13 +76,14 @@ 
         lockname = '%s:%s' % (lock._host, self.pid)
         while not self.held:
             try:
-                util.makelock(lockname, self.f)
+                self.vfs.makelock(lockname, self.f)
                 self.held = 1
             except (OSError, IOError), why:
                 if why.errno == errno.EEXIST:
                     locker = self.testlock()
                     if locker is not None:
-                        raise error.LockHeld(errno.EAGAIN, self.f, self.desc,
+                        raise error.LockHeld(errno.EAGAIN,
+                                             self.vfs.join(self.f), self.desc,
                                              locker)
                 else:
                     raise error.LockUnavailable(why.errno, why.strerror,
@@ -99,7 +101,7 @@ 
 
         """
         try:
-            locker = util.readlock(self.f)
+            locker = self.vfs.readlock(self.f)
         except (OSError, IOError), why:
             if why.errno == errno.ENOENT:
                 return None
@@ -119,8 +121,8 @@ 
         # if locker dead, break lock.  must do this with another lock
         # held, or can race and break valid lock.
         try:
-            l = lock(self.f + '.break', timeout=0)
-            util.unlink(self.f)
+            l = lock(self.vfs, self.f + '.break', timeout=0)
+            self.vfs.unlink(self.f)
             l.release()
         except error.LockError:
             return locker
@@ -140,7 +142,7 @@ 
             if self.releasefn:
                 self.releasefn()
             try:
-                util.unlink(self.f)
+                self.vfs.unlink(self.f)
             except OSError:
                 pass
             for callback in self.postrelease: