@@ -514,38 +514,47 @@ def _getfnodes(ui, repo, nodes):
def _writetagcache(ui, repo, valid, cachetags):
filename = _filename(repo)
+
try:
- cachefile = repo.cachevfs(filename, b'w', atomictemp=True)
- except (OSError, IOError):
+ lock = repo.lock(wait=False)
+ except error.LockError:
+ repo.ui.log(
+ b'tagscache',
+ b'not writing .hg/cache/%s because lock cannot be acquired\n'
+ % filename,
+ )
return
- ui.log(
- b'tagscache',
- b'writing .hg/cache/%s with %d tags\n',
- filename,
- len(cachetags),
- )
-
- if valid[2]:
- cachefile.write(
- b'%d %s %s\n' % (valid[0], hex(valid[1]), hex(valid[2]))
+ try:
+ cachefile = repo.cachevfs(filename, b'w', atomictemp=True)
+ ui.log(
+ b'tagscache',
+ b'writing .hg/cache/%s with %d tags\n',
+ filename,
+ len(cachetags),
)
- else:
- cachefile.write(b'%d %s\n' % (valid[0], hex(valid[1])))
+
+ if valid[2]:
+ cachefile.write(
+ b'%d %s %s\n' % (valid[0], hex(valid[1]), hex(valid[2]))
+ )
+ else:
+ cachefile.write(b'%d %s\n' % (valid[0], hex(valid[1])))
- # Tag names in the cache are in UTF-8 -- which is the whole reason
- # we keep them in UTF-8 throughout this module. If we converted
- # them local encoding on input, we would lose info writing them to
- # the cache.
- for (name, (node, hist)) in sorted(pycompat.iteritems(cachetags)):
- for n in hist:
- cachefile.write(b"%s %s\n" % (hex(n), name))
- cachefile.write(b"%s %s\n" % (hex(node), name))
+ # Tag names in the cache are in UTF-8 -- which is the whole reason
+ # we keep them in UTF-8 throughout this module. If we converted
+ # them local encoding on input, we would lose info writing them to
+ # the cache.
+ for (name, (node, hist)) in sorted(pycompat.iteritems(cachetags)):
+ for n in hist:
+ cachefile.write(b"%s %s\n" % (hex(n), name))
+ cachefile.write(b"%s %s\n" % (hex(node), name))
- try:
cachefile.close()
except (OSError, IOError):
pass
+ finally:
+ lock.release()
def tag(repo, names, node, message, local, user, date, editor=False):
@@ -163,7 +163,7 @@ Failure to acquire lock results in no wr
1970/01/01 00:00:00 bob @b9154636be938d3d431e75a7c906504a079bfe07 (5000)> identify
1970/01/01 00:00:00 bob @b9154636be938d3d431e75a7c906504a079bfe07 (5000)> not writing .hg/cache/hgtagsfnodes1 because lock cannot be acquired
1970/01/01 00:00:00 bob @b9154636be938d3d431e75a7c906504a079bfe07 (5000)> 0/2 cache hits/lookups in * seconds (glob)
- 1970/01/01 00:00:00 bob @b9154636be938d3d431e75a7c906504a079bfe07 (5000)> writing .hg/cache/tags2-visible with 1 tags
+ 1970/01/01 00:00:00 bob @b9154636be938d3d431e75a7c906504a079bfe07 (5000)> not writing .hg/cache/tags2-visible because lock cannot be acquired
1970/01/01 00:00:00 bob @b9154636be938d3d431e75a7c906504a079bfe07 (5000)> identify exited 0 after * seconds (glob)
1970/01/01 00:00:00 bob @b9154636be938d3d431e75a7c906504a079bfe07 (5000)> blackbox -l 6