annotate tests/test-dirs.py @ 45562:b51167d70f5a

rust: add `dirstate_tree` module Mercurial needs to represent the filesystem hierarchy on which it operates, for example in the dirstate. Its current on-disk representation is an unsorted, flat structure that gets transformed in the current Rust code into a `HashMap`. This loses the hierarchical information of the dirstate, leading to some unfortunate performance and algorithmic compromises. This module adds an implementation of a radix tree that is specialized for representing the dirstate: its unit is the path component. I have made no efforts to optimize either its memory footprint or its insertion speed: they're pretty bad for now. Following will be a few patches that modify the dirstate.status logic to use that new hierarchical information, fixing issue 6335 in the same swing. Differential Revision: https://phab.mercurial-scm.org/D9085
author Raphaël Gomès <rgomes@octobus.net>
date Fri, 25 Sep 2020 17:51:34 +0200
parents c21aca51b392
children 627cd8f33db0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
43494
5d40317d42b7 dirs: reject consecutive slashes in paths
Augie Fackler <augie@google.com>
parents:
diff changeset
1 from __future__ import absolute_import
5d40317d42b7 dirs: reject consecutive slashes in paths
Augie Fackler <augie@google.com>
parents:
diff changeset
2
5d40317d42b7 dirs: reject consecutive slashes in paths
Augie Fackler <augie@google.com>
parents:
diff changeset
3 import unittest
5d40317d42b7 dirs: reject consecutive slashes in paths
Augie Fackler <augie@google.com>
parents:
diff changeset
4
5d40317d42b7 dirs: reject consecutive slashes in paths
Augie Fackler <augie@google.com>
parents:
diff changeset
5 import silenttestrunner
5d40317d42b7 dirs: reject consecutive slashes in paths
Augie Fackler <augie@google.com>
parents:
diff changeset
6
43523
c21aca51b392 utils: move the `dirs` definition in pathutil (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43494
diff changeset
7 from mercurial import pathutil
43494
5d40317d42b7 dirs: reject consecutive slashes in paths
Augie Fackler <augie@google.com>
parents:
diff changeset
8
5d40317d42b7 dirs: reject consecutive slashes in paths
Augie Fackler <augie@google.com>
parents:
diff changeset
9
5d40317d42b7 dirs: reject consecutive slashes in paths
Augie Fackler <augie@google.com>
parents:
diff changeset
10 class dirstests(unittest.TestCase):
5d40317d42b7 dirs: reject consecutive slashes in paths
Augie Fackler <augie@google.com>
parents:
diff changeset
11 def testdirs(self):
5d40317d42b7 dirs: reject consecutive slashes in paths
Augie Fackler <augie@google.com>
parents:
diff changeset
12 for case, want in [
5d40317d42b7 dirs: reject consecutive slashes in paths
Augie Fackler <augie@google.com>
parents:
diff changeset
13 (b'a/a/a', [b'a', b'a/a', b'']),
5d40317d42b7 dirs: reject consecutive slashes in paths
Augie Fackler <augie@google.com>
parents:
diff changeset
14 (b'alpha/beta/gamma', [b'', b'alpha', b'alpha/beta']),
5d40317d42b7 dirs: reject consecutive slashes in paths
Augie Fackler <augie@google.com>
parents:
diff changeset
15 ]:
43523
c21aca51b392 utils: move the `dirs` definition in pathutil (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43494
diff changeset
16 d = pathutil.dirs({})
43494
5d40317d42b7 dirs: reject consecutive slashes in paths
Augie Fackler <augie@google.com>
parents:
diff changeset
17 d.addpath(case)
5d40317d42b7 dirs: reject consecutive slashes in paths
Augie Fackler <augie@google.com>
parents:
diff changeset
18 self.assertEqual(sorted(d), sorted(want))
5d40317d42b7 dirs: reject consecutive slashes in paths
Augie Fackler <augie@google.com>
parents:
diff changeset
19
5d40317d42b7 dirs: reject consecutive slashes in paths
Augie Fackler <augie@google.com>
parents:
diff changeset
20 def testinvalid(self):
5d40317d42b7 dirs: reject consecutive slashes in paths
Augie Fackler <augie@google.com>
parents:
diff changeset
21 with self.assertRaises(ValueError):
43523
c21aca51b392 utils: move the `dirs` definition in pathutil (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43494
diff changeset
22 d = pathutil.dirs({})
43494
5d40317d42b7 dirs: reject consecutive slashes in paths
Augie Fackler <augie@google.com>
parents:
diff changeset
23 d.addpath(b'a//b')
5d40317d42b7 dirs: reject consecutive slashes in paths
Augie Fackler <augie@google.com>
parents:
diff changeset
24
5d40317d42b7 dirs: reject consecutive slashes in paths
Augie Fackler <augie@google.com>
parents:
diff changeset
25
5d40317d42b7 dirs: reject consecutive slashes in paths
Augie Fackler <augie@google.com>
parents:
diff changeset
26 if __name__ == '__main__':
5d40317d42b7 dirs: reject consecutive slashes in paths
Augie Fackler <augie@google.com>
parents:
diff changeset
27 silenttestrunner.main(__name__)