[PATCH 2 of 4 V5] localrepo: adds times parameter to lock and wlock functions
Yuya Nishihara
yuya at tcha.org
Fri Nov 13 09:55:26 CST 2015
On Thu, 12 Nov 2015 14:17:45 +0100, liscju wrote:
> # HG changeset patch
> # User liscju <piotr.listkiewicz at gmail.com>
> # Date 1447331898 -3600
> # Thu Nov 12 13:38:18 2015 +0100
> # Node ID 8b107a3648068503b154eef2bf9f08c4cd13a51b
> # Parent 3a0f7224a3466e49068c0cd355640152631d1ba3
> localrepo: adds times parameter to lock and wlock functions
>
> This gives a possibility for acquiring/releasing repository
> lock and wlock multiple times.
>
> diff -r 3a0f7224a346 -r 8b107a364806 mercurial/localrepo.py
> --- a/mercurial/localrepo.py Thu Nov 12 13:35:22 2015 +0100
> +++ b/mercurial/localrepo.py Thu Nov 12 13:38:18 2015 +0100
> @@ -1238,7 +1238,7 @@
> ce.refresh()
>
> def _lock(self, vfs, lockname, wait, releasefn, acquirefn, desc,
> - inheritchecker=None, parentenvvar=None):
> + inheritchecker=None, parentenvvar=None, times=1):
> parentlock = None
> # the contents of parentenvvar are used by the underlying lock to
> # determine whether it can be inherited
> @@ -1248,7 +1248,7 @@
> l = lockmod.lock(vfs, lockname, 0, releasefn=releasefn,
> acquirefn=acquirefn, desc=desc,
> inheritchecker=inheritchecker,
> - parentlock=parentlock)
> + parentlock=parentlock, times=times)
> except error.LockHeld as inst:
> if not wait:
> raise
> @@ -1258,7 +1258,7 @@
> l = lockmod.lock(vfs, lockname,
> int(self.ui.config("ui", "timeout", "600")),
> releasefn=releasefn, acquirefn=acquirefn,
> - desc=desc)
> + desc=desc, times=times)
> self.ui.warn(_("got lock after %s seconds\n") % l.delay)
> return l
>
> @@ -1275,7 +1275,7 @@
> else: # no lock have been found.
> callback()
>
> - def lock(self, wait=True):
> + def lock(self, wait=True, times=1):
> '''Lock the repository store (.hg/store) and return a weak reference
> to the lock. Use this before modifying the store (e.g. committing or
> stripping). If you are opening a transaction, get a lock as well.)
> @@ -1284,11 +1284,11 @@
> 'wlock' first to avoid a dead-lock hazard.'''
> l = self._lockref and self._lockref()
> if l is not None and l.held:
> - l.lock()
> + l.lock(times)
> return l
>
> l = self._lock(self.svfs, "lock", wait, None,
> - self.invalidate, _('repository %s') % self.origroot)
> + self.invalidate, _('repository %s') % self.origroot, times=times)
> self._lockref = weakref.ref(l)
> return l
This won't work correctly because the previous active locks are forcibly
released and new lock object is created.
Think that there are two lockers:
wl0 = repo.wlock() # wl0.held = 1
wl1 = repo.wlock() # wl0.held = 2
wheld = wl1.releaseall() # wl0.held = 0
wl1 = repo.wlock(times=wheld) # wl0.held = 0, wl1.held = 2
wl1.release() # wl0.held = 0, wl1.held = 1
wl0.release() # wl0.held = 0 (noop, still locked)
# lock file is deleted here by wl1.__del__
Perhaps foozy would mention the lock inheritance that was recently introduced.
But I'm noob about it.
Regards,
More information about the Mercurial-devel
mailing list