##// END OF EJS Templates
utils: move finddirs() to pathutil...
Martin von Zweigbergk -
r44032:0b773371 default
parent child Browse files
Show More
@@ -2080,7 +2080,7 b' class workingfilectx(committablefilectx)'
2080 2080 # warned and backed up
2081 2081 if wvfs.isdir(f) and not wvfs.islink(f):
2082 2082 wvfs.rmtree(f, forcibly=True)
2083 for p in reversed(list(util.finddirs(f))):
2083 for p in reversed(list(pathutil.finddirs(f))):
2084 2084 if wvfs.isfileorlink(p):
2085 2085 wvfs.unlink(p)
2086 2086 break
@@ -59,6 +59,7 b' from . import ('
59 59 merge as mergemod,
60 60 obsolete,
61 61 obsutil,
62 pathutil,
62 63 phases,
63 64 policy,
64 65 pvec,
@@ -1343,7 +1344,7 b' def debugignore(ui, repo, *files, **opts'
1343 1344 ignored = nf
1344 1345 ignoredata = repo.dirstate._ignorefileandline(nf)
1345 1346 else:
1346 for p in util.finddirs(nf):
1347 for p in pathutil.finddirs(nf):
1347 1348 if ignore(p):
1348 1349 ignored = p
1349 1350 ignoredata = repo.dirstate._ignorefileandline(p)
@@ -404,7 +404,7 b' class dirstate(object):'
404 404 _(b'directory %r already in dirstate') % pycompat.bytestr(f)
405 405 )
406 406 # shadows
407 for d in util.finddirs(f):
407 for d in pathutil.finddirs(f):
408 408 if self._map.hastrackeddir(d):
409 409 break
410 410 entry = self._map.get(d)
@@ -707,7 +707,7 b' class dirstate(object):'
707 707 def _dirignore(self, f):
708 708 if self._ignore(f):
709 709 return True
710 for p in util.finddirs(f):
710 for p in pathutil.finddirs(f):
711 711 if self._ignore(p):
712 712 return True
713 713 return False
@@ -32,6 +32,7 b' from .. import ('
32 32 error,
33 33 extensions,
34 34 hg,
35 pathutil,
35 36 profiling,
36 37 pycompat,
37 38 registrar,
@@ -436,7 +437,7 b' class hgwebdir(object):'
436 437 def _virtualdirs():
437 438 # Check the full virtual path, and each parent
438 439 yield virtual
439 for p in util.finddirs(virtual):
440 for p in pathutil.finddirs(virtual):
440 441 yield p
441 442
442 443 for virtualrepo in _virtualdirs():
@@ -18,7 +18,6 b' from . import ('
18 18 encoding,
19 19 error,
20 20 pathutil,
21 pathutil,
22 21 policy,
23 22 pycompat,
24 23 util,
@@ -598,7 +597,8 b' class patternmatcher(basematcher):'
598 597 dir in self._fileset
599 598 or dir in self._dirs
600 599 or any(
601 parentdir in self._fileset for parentdir in util.finddirs(dir)
600 parentdir in self._fileset
601 for parentdir in pathutil.finddirs(dir)
602 602 )
603 603 )
604 604
@@ -643,7 +643,7 b' class _dirchildren(object):'
643 643 @staticmethod
644 644 def _findsplitdirs(path):
645 645 # yields (dirname, basename) tuples, walking back to the root. This is
646 # very similar to util.finddirs, except:
646 # very similar to pathutil.finddirs, except:
647 647 # - produces a (dirname, basename) tuple, not just 'dirname'
648 648 # Unlike manifest._splittopdir, this does not suffix `dirname` with a
649 649 # slash.
@@ -681,7 +681,9 b' class includematcher(basematcher):'
681 681 dir in self._roots
682 682 or dir in self._dirs
683 683 or dir in self._parents
684 or any(parentdir in self._roots for parentdir in util.finddirs(dir))
684 or any(
685 parentdir in self._roots for parentdir in pathutil.finddirs(dir)
686 )
685 687 )
686 688
687 689 @propertycache
@@ -706,7 +708,9 b' class includematcher(basematcher):'
706 708 b'' in self._roots
707 709 or dir in self._roots
708 710 or dir in self._dirs
709 or any(parentdir in self._roots for parentdir in util.finddirs(dir))
711 or any(
712 parentdir in self._roots for parentdir in pathutil.finddirs(dir)
713 )
710 714 ):
711 715 return b'this'
712 716
@@ -1073,7 +1077,7 b' class prefixdirmatcher(basematcher):'
1073 1077
1074 1078 @propertycache
1075 1079 def _pathdirs(self):
1076 return set(util.finddirs(self._path))
1080 return set(pathutil.finddirs(self._path))
1077 1081
1078 1082 def visitdir(self, dir):
1079 1083 if dir == self._path:
@@ -32,6 +32,7 b' from . import ('
32 32 filemerge,
33 33 match as matchmod,
34 34 obsutil,
35 pathutil,
35 36 pycompat,
36 37 scmutil,
37 38 subrepoutil,
@@ -813,7 +814,7 b' class _unknowndirschecker(object):'
813 814 return False
814 815
815 816 # Check for path prefixes that exist as unknown files.
816 for p in reversed(list(util.finddirs(f))):
817 for p in reversed(list(pathutil.finddirs(f))):
817 818 if p in self._missingdircache:
818 819 return
819 820 if p in self._unknowndircache:
@@ -947,7 +948,7 b' def _checkunknownfiles(repo, wctx, mctx,'
947 948 backup = (
948 949 f in fileconflicts
949 950 or f in pathconflicts
950 or any(p in pathconflicts for p in util.finddirs(f))
951 or any(p in pathconflicts for p in pathutil.finddirs(f))
951 952 )
952 953 (flags,) = args
953 954 actions[f] = (ACTION_GET, (flags, backup), msg)
@@ -1077,7 +1078,7 b' def _filesindirs(repo, manifest, dirs):'
1077 1078 in.
1078 1079 """
1079 1080 for f in manifest:
1080 for p in util.finddirs(f):
1081 for p in pathutil.finddirs(f):
1081 1082 if p in dirs:
1082 1083 yield f, p
1083 1084 break
@@ -1116,7 +1117,7 b' def checkpathconflicts(repo, wctx, mctx,'
1116 1117 ACTION_CREATED_MERGE,
1117 1118 ):
1118 1119 # This action may create a new local file.
1119 createdfiledirs.update(util.finddirs(f))
1120 createdfiledirs.update(pathutil.finddirs(f))
1120 1121 if mf.hasdir(f):
1121 1122 # The file aliases a local directory. This might be ok if all
1122 1123 # the files in the local directory are being deleted. This
@@ -1710,7 +1711,7 b' def batchget(repo, mctx, wctx, wantfiled'
1710 1711 # with a directory this file is in, and if so, back that up.
1711 1712 conflicting = f
1712 1713 if not repo.wvfs.lexists(f):
1713 for p in util.finddirs(f):
1714 for p in pathutil.finddirs(f):
1714 1715 if repo.wvfs.isfileorlink(p):
1715 1716 conflicting = p
1716 1717 break
@@ -275,6 +275,14 b' def normasprefix(path):'
275 275 return path
276 276
277 277
278 def finddirs(path):
279 pos = path.rfind(b'/')
280 while pos != -1:
281 yield path[:pos]
282 pos = path.rfind(b'/', 0, pos)
283 yield b''
284
285
278 286 class dirs(object):
279 287 '''a multiset of directory names from a set of file paths'''
280 288
@@ -295,7 +303,7 b' class dirs(object):'
295 303
296 304 def addpath(self, path):
297 305 dirs = self._dirs
298 for base in util.finddirs(path):
306 for base in finddirs(path):
299 307 if base.endswith(b'/'):
300 308 raise ValueError(
301 309 "found invalid consecutive slashes in path: %r" % base
@@ -307,7 +315,7 b' class dirs(object):'
307 315
308 316 def delpath(self, path):
309 317 dirs = self._dirs
310 for base in util.finddirs(path):
318 for base in finddirs(path):
311 319 if dirs[base] > 1:
312 320 dirs[base] -= 1
313 321 return
@@ -964,7 +964,7 b' def backuppath(ui, repo, filepath):'
964 964 ui.note(_(b'creating directory: %s\n') % origvfs.join(origbackupdir))
965 965
966 966 # Remove any files that conflict with the backup file's path
967 for f in reversed(list(util.finddirs(filepath))):
967 for f in reversed(list(pathutil.finddirs(filepath))):
968 968 if origvfs.isfileorlink(f):
969 969 ui.note(_(b'removing conflicting file: %s\n') % origvfs.join(f))
970 970 origvfs.unlink(f)
@@ -3491,14 +3491,6 b' def debugstacktrace('
3491 3491 f.flush()
3492 3492
3493 3493
3494 def finddirs(path):
3495 pos = path.rfind(b'/')
3496 while pos != -1:
3497 yield path[:pos]
3498 pos = path.rfind(b'/', 0, pos)
3499 yield b''
3500
3501
3502 3494 # convenient shortcut
3503 3495 dst = debugstacktrace
3504 3496
@@ -119,7 +119,7 b' mod tests {'
119 119
120 120 #[test]
121 121 fn find_dirs_empty() {
122 // looks weird, but mercurial.util.finddirs(b"") yields b""
122 // looks weird, but mercurial.pathutil.finddirs(b"") yields b""
123 123 let mut dirs = super::find_dirs(HgPath::new(b""));
124 124 assert_eq!(dirs.next(), Some(HgPath::new(b"")));
125 125 assert_eq!(dirs.next(), None);
General Comments 0
You need to be logged in to leave comments. Login now