eol: handle LockUnavailable error (issue2569) stable
authorMartin Geisler <mg@aragost.com>
Fri, 25 Feb 2011 12:32:15 +0100
branchstable
changeset 13475 c7bef25ca393
parent 13474 6c2e476b7a11
child 13476 b85a09f368bd
eol: handle LockUnavailable error (issue2569) If the repository is not locked when clearing the dirstate, then running test-eol.t in a loop fails sooner or later with: ERROR: /home/mg/src/mercurial-crew/tests/test-eol.t output changed --- /home/mg/src/mercurial-crew/tests/test-eol.t +++ /home/mg/src/mercurial-crew/tests/test-eol.t.err @@ -343,6 +343,7 @@ % hg status (eol activated) M win.txt % hg commit + nothing changed % hg status $ testmixed CRLF However, if we cannot lock the repository, then we can also not make a commit and so we can simply ignore a LockUnavailable error.
hgext/eol.py
tests/test-eol.t
--- a/hgext/eol.py	Thu Feb 24 19:15:00 2011 +0100
+++ b/hgext/eol.py	Fri Feb 25 12:32:15 2011 +0100
@@ -82,7 +82,7 @@
 """
 
 from mercurial.i18n import _
-from mercurial import util, config, extensions, match
+from mercurial import util, config, extensions, match, error
 import re, os
 
 # Matches a lone LF, i.e., one that is not part of CRLF.
@@ -254,13 +254,16 @@
                     for f, e in self.dirstate._map.iteritems():
                         self.dirstate._map[f] = (e[0], e[1], -1, 0)
                     self.dirstate._dirty = True
-                    # Touch the cache to update mtime. TODO: are we sure this
-                    # always enought to update the mtime, or should we write a
-                    # bit to the file?
+                    # Touch the cache to update mtime.
                     self.opener("eol.cache", "w").close()
-                finally:
-                    if wlock is not None:
-                        wlock.release()
+                    wlock.release()
+                except error.LockUnavailable:
+                    # If we cannot lock the repository and clear the
+                    # dirstate, then a commit might not see all files
+                    # as modified. But if we cannot lock the
+                    # repository, then we can also not make a commit,
+                    # so ignore the error.
+                    pass
 
         def commitctx(self, ctx, error=False):
             for f in sorted(ctx.added() + ctx.modified()):
--- a/tests/test-eol.t	Thu Feb 24 19:15:00 2011 +0100
+++ b/tests/test-eol.t	Fri Feb 25 12:32:15 2011 +0100
@@ -383,3 +383,18 @@
   % hg commit
   % hg status
   $ rm -r mixed
+
+Test issue2569 -- eol extension takes write lock on reading:
+
+  $ echo '[extensions]' >> $HGRCPATH
+  $ echo 'eol =' >> $HGRCPATH
+  $ hg init repo
+  $ cd repo
+  $ touch .hgeol
+  $ hg status
+  ? .hgeol
+  $ chmod -R -w .hg
+  $ sleep 1
+  $ touch .hgeol
+  $ hg status --traceback
+  ? .hgeol