[PATCH] hg root, run-tests.py: existence of an unreadable /.hg directory causes run-tests.py failures
Roland Eggner
edvx1 at systemanalysen.net
Mon Jun 11 17:18:38 UTC 2012
(1) Bug reproduction
---------------------
(i) [ -d /.hg ] || install -d -m 700 -o root -g root /.hg
(ii) Run run-tests.py within a mercurial source tree as an unprivileged user.
Existence of the unreadable /.hg directory will cause failure of some 13 tests.
(2) How I encountered the bug
------------------------------
Distribution: Gentoo Linux
For compiling and testing packages I am using a dedicated user “portage” with
restricted privileges, who has no access permissions for “/.hg” at all.
At “/.hg” my repository for tracking system configuration changes is mounted.
$ FEATURES="test" emerge -av =dev-vcs/mercurial-1.9
…
ERROR: /var/tmp/portage/dev-vcs/mercurial-1.9/work/mercurial-1.9/tests/test-config-case.t output changed
…
Skipped test-casefolding.t: missing feature: case insensitive file system
Skipped test-check-code-hg.py: cannot check code on non-repository sources
Skipped test-check-pyflakes.t: missing feature: Pyflakes python linter
Skipped test-convert-bzr-114.t: missing feature: Canonical's Bazaar client >= 1.14
Skipped test-convert-bzr-directories.t: missing feature: Canonical's Bazaar client
Skipped test-convert-bzr-ghosts.t: missing feature: Canonical's Bazaar client
Skipped test-convert-bzr-merges.t: missing feature: Canonical's Bazaar client
Skipped test-convert-bzr-treeroot.t: missing feature: Canonical's Bazaar client
Skipped test-convert-bzr.t: missing feature: Canonical's Bazaar client
Skipped test-convert-p4: missing feature: Perforce server and client
Skipped test-convert-p4-filetypes: missing feature: Perforce server and client
Skipped test-no-symlinks.t: system supports symbolic links
Failed test-config-case.t: output changed
Failed test-dispatch.t: output changed
Failed test-globalopts.t: output changed
Failed test-glog.t: output changed
Failed test-hgrc.t: output changed
Failed test-hgwebdir.t: output changed
Failed test-hgwebdirsym.t: output changed
Failed test-i18n.t: output changed
Failed test-identify.t: output changed
Failed test-keyword.t: output changed
Failed test-mq-qclone-http.t: output changed
Failed test-mq.t: output changed
Failed test-subrepo-relative-path.t: output changed
# Ran 389 tests, 12 skipped, 13 failed.
# --- /var/tmp/portage/dev-vcs/mercurial-1.9/work/mercurial-1.9/tests/test-config-case.t
# +++ /var/tmp/portage/dev-vcs/mercurial-1.9/work/mercurial-1.9/tests/test-config-case.t.err
# @@ -3,6 +3,6 @@
# $ echo 'key = lower case' >> $HGRCPATH
#
# $ hg showconfig Section
# - Section.KeY=Case Sensitive
# - Section.key=lower case
# + abort: Permission denied: /.hg/requires
# + [255]
# ls -dl --time-style=long-iso /.hg
drwx------ 4 root root 512 2011-07-09 09:21 /.hg/
$ ps -t tty2 f
PPID SESS PID USER GROUP TT STARTED TIME CMD
1 3290 3290 root root tty2 Jun 24 00:00:00 /bin/login --
3290 3290 4156 root root tty2 Jun 24 00:00:01 \_ -bash
4156 3290 3904 root root tty2 09:17:50 00:00:05 \_ /usr/bin/python2.6 /usr/bin/emerge -av dev-vcs/mercurial
3904 3290 4399 portage portage tty2 09:19:29 00:00:00 \_ [dev-vcs/mercurial-1.9] sandbox "/usr/lib64/portage/bin/ebuild.sh" test
4399 3290 4402 portage portage tty2 09:19:29 00:00:00 \_ /bin/bash /usr/lib64/portage/bin/ebuild.sh test
4402 3290 4426 portage portage tty2 09:19:29 00:00:00 \_ /bin/bash /usr/lib64/portage/bin/ebuild.sh test
4426 3290 4471 portage portage tty2 09:19:29 00:00:02 \_ python2.6 run-tests.py --tmpdir=/var/tmp/portage/dev-vcs/mercurial-1.9/temp/tests-2.6
4471 3290 14539 portage portage tty2 09:43:50 00:00:00 \_ /bin/sh /var/tmp/portage/dev-vcs/mercurial-1.9/temp/tmpDxkEEGhg-tst
14539 3290 14542 portage portage tty2 09:43:50 00:00:00 \_ /bin/sh /var/tmp/portage/dev-vcs/mercurial-1.9/temp/tmpDxkEEGhg-tst
14542 3290 14546 portage portage tty2 09:43:51 00:00:00 \_ /usr/bin/python2.6 /var/tmp/portage/dev-vcs/mercurial-1.9/temp/tests-2.6/install/bin/hg qnew status
(3) With my patch applied …
----------------------------
… to mercurial-2.0.2, run-tests.py succeeds as shown below, no need any more
to umount and rename “/.hg” for building mercurial.
$ FEATURES="test" emerge -av =dev-vcs/mercurial-2.0.2
…
* Removing tests which are known to fail:
removed `svn/svndump-startrev.sh'
removed `svn/svndump-replace.sh'
removed `svn/svndump-branches.sh'
removed `svn/replace.svndump'
removed `svn/svndump-encoding.sh'
removed `svn/move.svndump'
removed `svn/svndump-move.sh'
removed `svn/branches.svndump'
removed `svn/startrev.svndump'
removed `svn/encoding.svndump'
removed `svn/svndump-tags.sh'
removed `svn/tags.svndump'
removed directory: `svn'
removed `svn-safe-append.py'
removed `test-convert-hg-svn.t'
removed `test-convert-svn-branches.t'
removed `test-convert-svn-encoding.t'
removed `test-convert-svn-move.t'
removed `test-convert-svn-sink.t'
removed `test-convert-svn-source.t'
removed `test-convert-svn-startrev.t'
removed `test-convert-svn-tags.t'
removed `test-mq-subrepo-svn.t'
removed `test-subrepo-svn.t'
removed `test-archive-symlinks.t'
removed `test-archive.t'
removed `test-convert-baz'
removed `test-convert-baz.out'
removed `test-convert-cvs-branch.t'
removed `test-convert-cvs-detectmerge.t'
removed `test-convert-cvs-synthetic.t'
removed `test-convert-cvs.t'
removed `test-convert-cvsnt-mergepoints.rlog'
removed `test-convert-cvsnt-mergepoints.t'
removed `test-convert-darcs.t'
removed `test-convert-mtn-rename-directory.out'
removed `test-convert-mtn.t'
removed `test-convert-tla.t'
removed `test-doctest.py'
* Testing of dev-vcs/mercurial-2.0.2 with CPython 2.7...
............................ss...s.........s.......ss................s............s......s..s..............................ss....s...............................................s...................................................................................................................s........................................................................................................................
Skipped test-casefolding.t: missing feature: case insensitive file system
Skipped test-check-pyflakes.t: missing feature: Pyflakes python linter
Skipped test-convert-bzr-directories.t: missing feature: Canonical's Bazaar client
Skipped test-highlight.t: missing feature: Pygments source highlighting library
Skipped test-convert-bzr-merges.t: missing feature: Canonical's Bazaar client
Skipped test-convert-p4: missing feature: Perforce server and client
Skipped test-convert-bzr-ghosts.t: missing feature: Canonical's Bazaar client
Skipped test-https.t: missing feature: python >= 2.6 ssl module and python OpenSSL
Skipped test-no-symlinks.t: system supports symbolic links
Skipped test-convert-bzr-114.t: missing feature: Canonical's Bazaar client >= 1.14
Skipped test-convert-bzr.t: missing feature: Canonical's Bazaar client
Skipped test-casecollision-merge.t: missing feature: case insensitive file system
Skipped test-check-code-hg.py: cannot check code on non-repository sources
Skipped test-convert-bzr-treeroot.t: missing feature: Canonical's Bazaar client
Skipped test-convert-p4-filetypes: missing feature: Perforce server and client
# Ran 399 tests, 15 skipped, 0 failed.
(4) Patch
----------
It has been written for mercurial-2.0.2. It applies cleanly to mercurial-2.2.2
sources, thus probably works for mercurial-2.2.2 too.
I use linebreaks to emphasize repetitions and to show “what it does”.
If 80 columns limit is more important for you, let me know and I will fold and
resend.
To get a proper “hg export” format, I set up a repository just holding the
2 modified files, thus hashes are probably useless.
# HG changeset patch
# User Roland Eggner < odvx1 at systomanalyson.not s/o/e/g >
# Date 1339434022 -7200
# Node ID 3f22a0580c54328cbc82947bdfc180e955156c7f
# Parent 654ad2f8392c501a55d28a7f1f8f9e39148fcaa5
hg root: Skip repositories not readable with current privileges. Skip empty .hg directories, e.g. unmounted mountpoints.
diff --git a/mercurial-2.0.2/mercurial/cmdutil.py b/mercurial-2.0.2/mercurial/cmdutil.py
--- a/mercurial-2.0.2/mercurial/cmdutil.py
+++ b/mercurial-2.0.2/mercurial/cmdutil.py
@@ -69,7 +69,9 @@ def findcmd(cmd, table, strict=True):
raise error.UnknownCommand(cmd)
def findrepo(p):
- while not os.path.isdir(os.path.join(p, ".hg")):
+ while not (os.path.isdir(os.path.join(p, ".hg"))
+ and ((os.path.isfile(os.path.join(p, '.hg', 'requires' )) and os.access(os.path.join(p, '.hg', 'requires' ), os.R_OK))
+ or (os.path.isfile(os.path.join(p, '.hg', '00changelog.i')) and os.access(os.path.join(p, '.hg', '00changelog.i'), os.R_OK)))):
oldp, p = p, os.path.dirname(p)
if p == oldp:
return None
diff --git a/mercurial-2.0.2/mercurial/scmutil.py b/mercurial-2.0.2/mercurial/scmutil.py
--- a/mercurial-2.0.2/mercurial/scmutil.py
+++ b/mercurial-2.0.2/mercurial/scmutil.py
@@ -355,7 +355,9 @@ def walkrepos(path, followsym=False, see
adddir(seen_dirs, path)
for root, dirs, files in os.walk(path, topdown=True, onerror=errhandler):
dirs.sort()
- if '.hg' in dirs:
+ if ('.hg' in dirs
+ and ((os.path.isfile(os.path.join(root, '.hg', 'requires' )) and os.access(os.path.join(root, '.hg', 'requires' ), os.R_OK))
+ or (os.path.isfile(os.path.join(root, '.hg', '00changelog.i')) and os.access(os.path.join(root, '.hg', '00changelog.i'), os.R_OK)))):
yield root # found a repository
qroot = os.path.join(root, '.hg', 'patches')
if os.path.isdir(os.path.join(qroot, '.hg')):
--
Roland Eggner
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: <http://lists.mercurial-scm.org/pipermail/mercurial-devel/attachments/20120611/aff46477/attachment.asc>
More information about the Mercurial-devel
mailing list