# HG changeset patch # User Alexis S. L. Carvalho # Date 1187483770 10800 # Node ID c7e8fe11f34a037f1d5df53e5bf22f59551477c8 # Parent 94e77a174f55b4824324b79cfcdeaf8f85d2c0c2 path_auditor: cache names of audited directories We use a separate cache to avoid problems with audit = path_auditor(repo.root) audit("subrepo") audit("subrepo/file") whitelisting "subrepo" (which is fine) and then using the same whitelist with "subrepo/file" (which is not fine). Since we create a separate path_auditor for every path on the command line, a "hg add dir/a dir/b dir/c" will still lstat dir 3 times just to audit the paths. diff --git a/mercurial/util.py b/mercurial/util.py --- a/mercurial/util.py +++ b/mercurial/util.py @@ -692,7 +692,8 @@ class path_auditor(object): - inside a nested repository''' def __init__(self, root): - self.audited = {} + self.audited = set() + self.auditeddir = set() self.root = root def __call__(self, path): @@ -720,10 +721,19 @@ class path_auditor(object): os.path.isdir(os.path.join(curpath, '.hg'))): raise Abort(_('path %r is inside repo %r') % (path, prefix)) - self.audited[prefix] = True + + prefixes = [] for c in strutil.rfindall(normpath, os.sep): - check(normpath[:c]) - self.audited[path] = True + prefix = normpath[:c] + if prefix in self.auditeddir: + break + check(prefix) + prefixes.append(prefix) + + self.audited.add(path) + # only add prefixes to the cache after checking everything: we don't + # want to add "foo/bar/baz" before checking if there's a "foo/.hg" + self.auditeddir.update(prefixes) def _makelock_file(info, pathname): ld = os.open(pathname, os.O_CREAT | os.O_WRONLY | os.O_EXCL) diff --git a/tests/test-nested-repo b/tests/test-nested-repo --- a/tests/test-nested-repo +++ b/tests/test-nested-repo @@ -13,6 +13,10 @@ echo '# should fail' hg st b/x hg add b/x +echo '# should fail' +hg add b b/x +hg st + echo '# should arguably print nothing' hg st b diff --git a/tests/test-nested-repo.out b/tests/test-nested-repo.out --- a/tests/test-nested-repo.out +++ b/tests/test-nested-repo.out @@ -2,6 +2,8 @@ # should fail abort: path 'b/x' is inside repo 'b' abort: path 'b/x' is inside repo 'b' +# should fail +abort: path 'b/x' is inside repo 'b' # should arguably print nothing # should fail abort: path 'b/a' is inside repo 'b'