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