[PATCH 1 of 6] localrepo: add auditor attribute which knows about subrepos

Martin Geisler mg at lazybytes.net
Wed Sep 1 09:46:57 CDT 2010


Martin Geisler <mg at lazybytes.net> writes:

> # HG changeset patch
> # User Martin Geisler <mg at lazybytes.net>
> # Date 1283205545 -7200
> # Node ID 2075384560dc39a9ffa340473a9abd2abda57a96
> # Parent  cd895084a4cd80abd241060705090aa7c3d9f39a
> localrepo: add auditor attribute which knows about subrepos
>
> diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
> --- a/mercurial/localrepo.py
> +++ b/mercurial/localrepo.py
> @@ -28,6 +28,7 @@
>          self.root = os.path.realpath(util.expandpath(path))
>          self.path = os.path.join(self.root, ".hg")
>          self.origroot = path
> +        self.auditor = util.path_auditor(self.root, self._checknested)
>          self.opener = util.opener(self.path)
>          self.wopener = util.opener(self.root)
>          self.baseui = baseui
> @@ -111,6 +112,15 @@
>          self._datafilters = {}
>          self._transref = self._lockref = self._wlockref = None
>  
> +    def _checknested(self, path):
> +        """Determine if path is a legal nested repository."""
> +        # XXX: which revision to use?

Until now, all paths that cross into another repository are forbidden.
This check is basically done by splitting the string on '/' and looking
for '.hg' and it is independent of what is actually on the filesystem
and independent of the revision asked for.

After this change,

  $ hg status --rev X sub/a.txt

will always work if sub/ is a subrepository in the current revision. If
you askfor the status in a revision where sub/a.txt did not exist, then
you get:

  $ hg status -S --rev 1 sub/a.txt
  ? sub/a.txt

when it should arguably return 'A sub/a.txt' since the file has been
added since the revision.

> +        ctx = self['.']
> +        if not path.startswith(self.root):
> +            return False
> +        sub = path[len(self.root) + 1:]
> +        return sub in ctx.substate
> +
>      @propertycache
>      def changelog(self):
>          c = changelog.changelog(self.sopener)

-- 
Martin Geisler

aragost Trifork
Professional Mercurial support
http://aragost.com/mercurial/


More information about the Mercurial-devel mailing list