match: de-flake test-doctest.py by not depending on util.dirs() order
authorMartin von Zweigbergk <martinvonz@google.com>
Wed, 22 May 2019 13:58:05 -0700
changeset 42361 c4b8f8637d7a
parent 42360 3293086ff663
child 42362 52beb1b8a649
match: de-flake test-doctest.py by not depending on util.dirs() order util.dirs() yields directories in arbitrary order, which has made test-doctest.py flaky. I think they have been flaky since d8e55c0c642c (util: make util.dirs() and util.finddirs() include root directory (API), 2017-05-16). Before that commit, I think util.dirs() would return at most one entry, so there was only one iteration order. This patch fixes the problem by making _rootsdirsandparents() return a set (whose __str__() is defined to be in sorted order, I believe). The only caller wanted a set anyway. Differential Revision: https://phab.mercurial-scm.org/D6432
mercurial/match.py
--- a/mercurial/match.py	Tue May 21 15:26:48 2019 +0200
+++ b/mercurial/match.py	Wed May 22 13:58:05 2019 -0700
@@ -614,7 +614,7 @@
         self._dirs = set(dirs)
         # parents are directories which are non-recursively included because
         # they are needed to get to items in _dirs or _roots.
-        self._parents = set(parents)
+        self._parents = parents
 
     def visitdir(self, dir):
         dir = normalizerootdir(dir, 'visitdir')
@@ -1384,26 +1384,26 @@
     >>> _rootsdirsandparents(
     ...     [(b'glob', b'g/h/*', b''), (b'glob', b'g/h', b''),
     ...      (b'glob', b'g*', b'')])
-    (['g/h', 'g/h', ''], [], ['', 'g'])
+    (['g/h', 'g/h', ''], [], set(['', 'g']))
     >>> _rootsdirsandparents(
     ...     [(b'rootfilesin', b'g/h', b''), (b'rootfilesin', b'', b'')])
-    ([], ['g/h', ''], ['', 'g'])
+    ([], ['g/h', ''], set(['', 'g']))
     >>> _rootsdirsandparents(
     ...     [(b'relpath', b'r', b''), (b'path', b'p/p', b''),
     ...      (b'path', b'', b'')])
-    (['r', 'p/p', ''], [], ['', 'p'])
+    (['r', 'p/p', ''], [], set(['', 'p']))
     >>> _rootsdirsandparents(
     ...     [(b'relglob', b'rg*', b''), (b're', b're/', b''),
     ...      (b'relre', b'rr', b'')])
-    (['', '', ''], [], [''])
+    (['', '', ''], [], set(['']))
     '''
     r, d = _patternrootsanddirs(kindpats)
 
-    p = []
-    # Append the parents as non-recursive/exact directories, since they must be
+    p = set()
+    # Add the parents as non-recursive/exact directories, since they must be
     # scanned to get to either the roots or the other exact directories.
-    p.extend(util.dirs(d))
-    p.extend(util.dirs(r))
+    p.update(util.dirs(d))
+    p.update(util.dirs(r))
 
     # FIXME: all uses of this function convert these to sets, do so before
     # returning.