remotenames: separate lock for the accessed bookmarks file

Summary:
File that tracks accessed bookmarks doesn't interact with anything else and doesn't really need repo.wlock. However if does use wlock, hg commands like `hg log -r`, which normally are read-only, start waiting for the lock and thus are blocked by other writing commands, that might be running in different checkouts of the same repo.

Let's use a different lock for this feature.

Reviewed By: simpkins

Differential Revision: D15165788

fbshipit-source-id: f04c7196d51db67069c6420545be24d2b7c0af27
This commit is contained in:
Aida Getoeva 2019-05-03 06:45:53 -07:00 committed by Facebook Github Bot
parent 75ca3f73f7
commit 10e0a1143a

View File

@ -96,6 +96,8 @@ journalremotebookmarktype = "remotebookmark"
# happened
_selectivepullenabledfile = "selectivepullenabled"
_selectivepullaccessedbookmarks = "selectivepullaccessedbookmarks"
# separate lock to update accessed bookmarks
_selectivepullaccessedbookmarkslock = "selectivepullaccessedbookmarks.lock"
def exbookcalcupdate(orig, ui, repo, checkout):
@ -195,13 +197,11 @@ def updateaccessedbookmarks(repo, remotepath, bookmarks):
vfs = repo.sharedvfs
if vfs.exists(_selectivepullaccessedbookmarks):
knownbooks = set(_readremotenamesfrom(vfs, _selectivepullaccessedbookmarks))
else:
knownbooks = set()
totalaccessednames = 0
with repo.wlock(), vfs(_selectivepullaccessedbookmarks, "w", atomictemp=True) as f:
with lockmod.lock(vfs, _selectivepullaccessedbookmarkslock):
knownbooks = set(_readremotenamesfrom(vfs, _selectivepullaccessedbookmarks))
with vfs(_selectivepullaccessedbookmarks, "w", atomictemp=True) as f:
newbookmarks = {}
for node, nametype, oldremote, rname in knownbooks:
if nametype != "bookmarks":
@ -940,6 +940,8 @@ def extsetup(ui):
bookcmd = extensions.wrapcommand(commands.table, "bookmarks", exbookmarks)
pushcmd = extensions.wrapcommand(commands.table, "push", expushcmd)
localrepo.localrepository._wlockfreeprefix.add("selectivepullaccessedbookmarks")
if _tracking(ui):
bookcmd[1].append(
("t", "track", "", "track this bookmark or remote name", "BOOKMARK")
@ -1639,10 +1641,14 @@ def shareawarecachevfs(repo):
def _readremotenamesfrom(vfs, filename):
if not vfs.exists(filename):
try:
f = vfs(filename)
except EnvironmentError as er:
if er.errno != errno.ENOENT:
raise
return
f = vfs(filename)
with f:
for line in f:
nametype = None
line = line.strip()
@ -1665,8 +1671,6 @@ def _readremotenamesfrom(vfs, filename):
yield node, nametype, remote, rname
f.close()
def readbookmarknames(repo, remote):
for node, nametype, remotename, rname in readremotenames(repo):