[PATCH STABLE] tags: do not abort if failed to write lock file to save cache

Yuya Nishihara yuya at tcha.org
Fri Apr 17 14:59:19 UTC 2015


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1429280578 -32400
#      Fri Apr 17 23:22:58 2015 +0900
# Branch stable
# Node ID 6dedda260a8f457f7a7b0d7b93fd1037d8c23557
# Parent  82fe5721302973f90b594239772a05f447c493aa
tags: do not abort if failed to write lock file to save cache

LockHeld wasn't enough to suppress error during acquiring lock. If .hg directory
is read-only, LockUnavailable will be raised.

  $ chmod ugo-w .hg
  $ hg identify
  abort: could not lock working directory of ...: Permission denied

diff --git a/mercurial/tags.py b/mercurial/tags.py
--- a/mercurial/tags.py
+++ b/mercurial/tags.py
@@ -502,9 +502,9 @@ class hgtagsfnodescache(object):
 
         try:
             lock = repo.wlock(wait=False)
-        except error.LockHeld:
+        except error.LockError:
             repo.ui.log('tagscache',
-                        'not writing .hg/%s because lock held\n' %
+                        'not writing .hg/%s because lock cannot be acquired\n' %
                         (_fnodescachefile))
             return
 
diff --git a/tests/test-tags.t b/tests/test-tags.t
--- a/tests/test-tags.t
+++ b/tests/test-tags.t
@@ -114,7 +114,7 @@ Repeat with cold tag cache:
   0010: ff ff ff ff ff ff ff ff b9 15 46 36 26 b7 b4 a7 |..........F6&...|
   0020: 73 e0 9e e3 c5 2f 51 0e 19 e0 5e 1f f9 66 d8 59 |s..../Q...^..f.Y|
 
-And again, but now unable to write tag cache:
+And again, but now unable to write tag cache or lock file:
 
 #if unix-permissions
   $ rm -f .hg/cache/tags2-visible .hg/cache/hgtagsfnodes1
@@ -122,6 +122,11 @@ And again, but now unable to write tag c
   $ hg identify
   b9154636be93 tip
   $ chmod 755 .hg/cache
+
+  $ chmod 555 .hg
+  $ hg identify
+  b9154636be93 tip
+  $ chmod 755 .hg
 #endif
 
 Tag cache debug info written to blackbox log
@@ -144,7 +149,7 @@ Failure to acquire lock results in no wr
   b9154636be93 tip
   $ hg blackbox -l 5
   1970/01/01 00:00:00 bob> identify
-  1970/01/01 00:00:00 bob> not writing .hg/cache/hgtagsfnodes1 because lock held
+  1970/01/01 00:00:00 bob> not writing .hg/cache/hgtagsfnodes1 because lock cannot be acquired
   1970/01/01 00:00:00 bob> 0/1 cache hits/lookups in * seconds (glob)
   1970/01/01 00:00:00 bob> writing .hg/cache/tags2-visible with 1 tags
   1970/01/01 00:00:00 bob> identify exited 0 after * seconds (glob)


More information about the Mercurial-devel mailing list