24 May 16:50
[PATCH] localrepo: Add locking to _branchtags around _writebrancache
Joshua Redstone <joshua.redstone <at> fb.com>
2012-05-24 14:50:53 GMT
2012-05-24 14:50:53 GMT
# HG changeset patch
# User Joshua Redstone <joshua.redstone <at> fb.com>
# Date 1336812429 25200
# Node ID b3bb1d7360c481b847431fc0d264111b1d93f993
# Parent 2ac08d8b21aa7b6e0a062afed5a3f357ccef67f9
localrepo: Add locking to _branchtags around _writebrancache
Read code paths such as via localrepo.branchmap() may end up calling
_writebranchcache without having acquire a repo lock, potentially leading to
races with other repo mutations. This fix acquires the repo lock if not yet
held before calling _writebranchcache.
diff -r 2ac08d8b21aa -r b3bb1d7360c4 mercurial/localrepo.py
--- a/mercurial/localrepo.py Tue May 22 14:37:20 2012 -0500
+++ b/mercurial/localrepo.py Sat May 12 01:47:09 2012 -0700
@@ -481,8 +481,18 @@
if lrev != tiprev:
ctxgen = (self[r] for r in xrange(lrev + 1, tiprev + 1))
self._updatebranchcache(partial, ctxgen)
- self._writebranchcache(partial, self.changelog.tip(), tiprev)
-
+ # Read code paths (e.g., from branchmap()) do not have the lock
+ # yet. Lock acquisition may fail if we do not have write-access
+ # to the directory.
+ try:
+ wlock = self.wlock(wait=False)
+ try:
+ self._writebranchcache(partial, self.changelog.tip(),
+ tiprev)
+ finally:
(Continue reading)
RSS Feed