# HG changeset patch # User Martin Geisler # Date 2011-02-25 11:32:15 # Node ID c7bef25ca39300756a8f8bcf678f11db6c6ce257 # Parent 6c2e476b7a1170ded89cdedec7a23e717606193c 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. diff --git a/hgext/eol.py b/hgext/eol.py --- a/hgext/eol.py +++ b/hgext/eol.py @@ -82,7 +82,7 @@ used. """ 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 @@ def reposetup(ui, repo): 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()): diff --git a/tests/test-eol.t b/tests/test-eol.t --- a/tests/test-eol.t +++ b/tests/test-eol.t @@ -383,3 +383,18 @@ Mixed tests % 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