[PATCH] hg root, run-tests.py: existence of an unreadable /.hg directory causes run-tests.py failures

Mads Kiilerich mads at kiilerich.com
Mon Jun 11 17:09:43 CDT 2012


Roland Eggner wrote, On 06/11/2012 07:18 PM:
> (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.
...
> # 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

Thank you for the patch, but ...

One property of Mercurial is that it is very well-defined which 
repository a given file belong to, even when working directories are 
nested. All users will get the same output from 'hg root' ... or a 
failure if they don't have access. The behaviour changed by this patch 
is intentional - failure to access a .hg should not pass silently.

The error message is quite clear and helpful for debugging the problem. 
The test suite should pass if just there is read access to the outer 
repo - I would suggest that as a workaround. If you don't want to change 
the permissions of /.hg then you could create another readable repo in 
/tmp and set TMP to point inside that. The few tests that depend on not 
having a (readable) outer repo is guarded with 'hghave outer-repo'.

If you want a fix in Mercurial then I consider it feasible to have a 
secret 'debug' option for controlling how close to '/' Mercurial should 
go when searching for a surrounding .hg. It could perhaps be a 
HGDEBUGSKIPROOT environment variable that made findrepo stop searching 
at that directory when looking for a .hg.

/Mads

ps: The guidelines for contributing changes can be found on 
http://mercurial.selenic.com/wiki/ContributingChanges .



More information about the Mercurial-devel mailing list