annotate mercurial/pathutil.py @ 53040:cdd7bf612c7b stable tip

bundle-spec: properly format boolean parameter (issue6960) This was breaking automatic clone bundle generation. This changeset fixes it and add a test to catch it in the future.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Tue, 11 Mar 2025 02:29:42 +0100
parents bde94bd8e8a2
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
51901
f4733654f144 typing: add `from __future__ import annotations` to most files
Matt Harbison <matt_harbison@yahoo.com>
parents: 51617
diff changeset
1 from __future__ import annotations
f4733654f144 typing: add `from __future__ import annotations` to most files
Matt Harbison <matt_harbison@yahoo.com>
parents: 51617
diff changeset
2
44924
233ee525dcef grep: reduce the cost of pathauditor checks when grepping working copy
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents: 44630
diff changeset
3 import contextlib
25964
d740df4e96cf pathutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
4 import errno
d740df4e96cf pathutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
5 import os
d740df4e96cf pathutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
6 import posixpath
d740df4e96cf pathutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
7 import stat
d740df4e96cf pathutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
8
49979
15175774e1c5 typing: import unconditionally
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49969
diff changeset
9 from typing import (
15175774e1c5 typing: import unconditionally
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49969
diff changeset
10 Any,
15175774e1c5 typing: import unconditionally
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49969
diff changeset
11 Callable,
15175774e1c5 typing: import unconditionally
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49969
diff changeset
12 Iterator,
15175774e1c5 typing: import unconditionally
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49969
diff changeset
13 Optional,
15175774e1c5 typing: import unconditionally
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49969
diff changeset
14 )
15175774e1c5 typing: import unconditionally
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49969
diff changeset
15
25964
d740df4e96cf pathutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
16 from .i18n import _
d740df4e96cf pathutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
17 from . import (
d740df4e96cf pathutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
18 encoding,
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25964
diff changeset
19 error,
43571
c21aca51b392 utils: move the `dirs` definition in pathutil (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43077
diff changeset
20 policy,
30619
cfe66dcf45c0 py3: replace os.sep with pycompat.ossep (part 2 of 4)
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30342
diff changeset
21 pycompat,
25964
d740df4e96cf pathutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
22 util,
d740df4e96cf pathutil: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25660
diff changeset
23 )
20033
f962870712da pathutil: tease out a new library to break an import cycle from canonpath use
Augie Fackler <raf@durin42.com>
parents:
diff changeset
24
52906
bde94bd8e8a2 typing: use a protocol to annotate `pathutil.dirs` in repository.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52883
diff changeset
25 from .interfaces import misc as int_misc
bde94bd8e8a2 typing: use a protocol to annotate `pathutil.dirs` in repository.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52883
diff changeset
26
52883
0bd91b0a1a93 rust-pyo3-dirstate: using from Python
Georges Racinet <georges.racinet@cloudcrane.io>
parents: 51901
diff changeset
27 rustdirs = policy.importrust('dirstate', 'Dirs', pyo3=True)
43571
c21aca51b392 utils: move the `dirs` definition in pathutil (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43077
diff changeset
28 parsers = policy.importmod('parsers')
c21aca51b392 utils: move the `dirs` definition in pathutil (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43077
diff changeset
29
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 38593
diff changeset
30
51304
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51302
diff changeset
31 def _lowerclean(s: bytes) -> bytes:
23598
c02a05cc6f5e pathauditor: check for codepoints ignored on OS X
Augie Fackler <raf@durin42.com>
parents: 21568
diff changeset
32 return encoding.hfsignoreclean(s.lower())
c02a05cc6f5e pathauditor: check for codepoints ignored on OS X
Augie Fackler <raf@durin42.com>
parents: 21568
diff changeset
33
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 38593
diff changeset
34
49037
642e31cb55f0 py3: use class X: instead of class X(object):
Gregory Szorc <gregory.szorc@gmail.com>
parents: 49004
diff changeset
35 class pathauditor:
45957
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 44924
diff changeset
36 """ensure that a filesystem path contains no banned components.
20033
f962870712da pathutil: tease out a new library to break an import cycle from canonpath use
Augie Fackler <raf@durin42.com>
parents:
diff changeset
37 the following properties of a path are checked:
f962870712da pathutil: tease out a new library to break an import cycle from canonpath use
Augie Fackler <raf@durin42.com>
parents:
diff changeset
38
f962870712da pathutil: tease out a new library to break an import cycle from canonpath use
Augie Fackler <raf@durin42.com>
parents:
diff changeset
39 - ends with a directory separator
f962870712da pathutil: tease out a new library to break an import cycle from canonpath use
Augie Fackler <raf@durin42.com>
parents:
diff changeset
40 - under top-level .hg
f962870712da pathutil: tease out a new library to break an import cycle from canonpath use
Augie Fackler <raf@durin42.com>
parents:
diff changeset
41 - starts at the root of a windows drive
f962870712da pathutil: tease out a new library to break an import cycle from canonpath use
Augie Fackler <raf@durin42.com>
parents:
diff changeset
42 - contains ".."
27232
79a86a95f325 pathauditor: add a way to skip file system check
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 27231
diff changeset
43
79a86a95f325 pathauditor: add a way to skip file system check
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 27231
diff changeset
44 More check are also done about the file system states:
20033
f962870712da pathutil: tease out a new library to break an import cycle from canonpath use
Augie Fackler <raf@durin42.com>
parents:
diff changeset
45 - traverses a symlink (e.g. a/symlink_here/b)
f962870712da pathutil: tease out a new library to break an import cycle from canonpath use
Augie Fackler <raf@durin42.com>
parents:
diff changeset
46 - inside a nested repository (a callback can be used to approve
f962870712da pathutil: tease out a new library to break an import cycle from canonpath use
Augie Fackler <raf@durin42.com>
parents:
diff changeset
47 some nested repositories, e.g., subrepositories)
27232
79a86a95f325 pathauditor: add a way to skip file system check
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 27231
diff changeset
48
79a86a95f325 pathauditor: add a way to skip file system check
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 27231
diff changeset
49 The file system checks are only done when 'realfs' is set to True (the
79a86a95f325 pathauditor: add a way to skip file system check
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 27231
diff changeset
50 default). They should be disable then we are auditing path for operation on
79a86a95f325 pathauditor: add a way to skip file system check
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 27231
diff changeset
51 stored history.
33647
377e8ddaebef pathauditor: disable cache of audited paths by default (issue5628)
Yuya Nishihara <yuya@tcha.org>
parents: 33435
diff changeset
52
377e8ddaebef pathauditor: disable cache of audited paths by default (issue5628)
Yuya Nishihara <yuya@tcha.org>
parents: 33435
diff changeset
53 If 'cached' is set to True, audited paths and sub-directories are cached.
377e8ddaebef pathauditor: disable cache of audited paths by default (issue5628)
Yuya Nishihara <yuya@tcha.org>
parents: 33435
diff changeset
54 Be careful to not keep the cache of unmanaged directories for long because
377e8ddaebef pathauditor: disable cache of audited paths by default (issue5628)
Yuya Nishihara <yuya@tcha.org>
parents: 33435
diff changeset
55 audited paths may be replaced with symlinks.
45957
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 44924
diff changeset
56 """
20033
f962870712da pathutil: tease out a new library to break an import cycle from canonpath use
Augie Fackler <raf@durin42.com>
parents:
diff changeset
57
33647
377e8ddaebef pathauditor: disable cache of audited paths by default (issue5628)
Yuya Nishihara <yuya@tcha.org>
parents: 33435
diff changeset
58 def __init__(self, root, callback=None, realfs=True, cached=False):
20033
f962870712da pathutil: tease out a new library to break an import cycle from canonpath use
Augie Fackler <raf@durin42.com>
parents:
diff changeset
59 self.audited = set()
49968
c7624b1ac8b4 merge: cache the fs checks made during [_checkunknownfiles]
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49967
diff changeset
60 self.auditeddir = dict()
20033
f962870712da pathutil: tease out a new library to break an import cycle from canonpath use
Augie Fackler <raf@durin42.com>
parents:
diff changeset
61 self.root = root
27232
79a86a95f325 pathauditor: add a way to skip file system check
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 27231
diff changeset
62 self._realfs = realfs
33647
377e8ddaebef pathauditor: disable cache of audited paths by default (issue5628)
Yuya Nishihara <yuya@tcha.org>
parents: 33435
diff changeset
63 self._cached = cached
20033
f962870712da pathutil: tease out a new library to break an import cycle from canonpath use
Augie Fackler <raf@durin42.com>
parents:
diff changeset
64 self.callback = callback
29893
6f447b9ec263 util: rename checkcase() to fscasesensitive() (API)
Martin von Zweigbergk <martinvonz@google.com>
parents: 28087
diff changeset
65 if os.path.lexists(root) and not util.fscasesensitive(root):
20033
f962870712da pathutil: tease out a new library to break an import cycle from canonpath use
Augie Fackler <raf@durin42.com>
parents:
diff changeset
66 self.normcase = util.normcase
f962870712da pathutil: tease out a new library to break an import cycle from canonpath use
Augie Fackler <raf@durin42.com>
parents:
diff changeset
67 else:
f962870712da pathutil: tease out a new library to break an import cycle from canonpath use
Augie Fackler <raf@durin42.com>
parents:
diff changeset
68 self.normcase = lambda x: x
f962870712da pathutil: tease out a new library to break an import cycle from canonpath use
Augie Fackler <raf@durin42.com>
parents:
diff changeset
69
51304
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51302
diff changeset
70 def __call__(self, path: bytes, mode: Optional[Any] = None) -> None:
45957
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 44924
diff changeset
71 """Check the relative path.
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 44924
diff changeset
72 path may contain a pattern (e.g. foodir/**.txt)"""
20033
f962870712da pathutil: tease out a new library to break an import cycle from canonpath use
Augie Fackler <raf@durin42.com>
parents:
diff changeset
73
f962870712da pathutil: tease out a new library to break an import cycle from canonpath use
Augie Fackler <raf@durin42.com>
parents:
diff changeset
74 path = util.localpath(path)
49964
445b4d819e9a pathauditor: no need to normcase the paths
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49963
diff changeset
75 if path in self.audited:
20033
f962870712da pathutil: tease out a new library to break an import cycle from canonpath use
Augie Fackler <raf@durin42.com>
parents:
diff changeset
76 return
f962870712da pathutil: tease out a new library to break an import cycle from canonpath use
Augie Fackler <raf@durin42.com>
parents:
diff changeset
77 # AIX ignores "/" at end of path, others raise EISDIR.
f962870712da pathutil: tease out a new library to break an import cycle from canonpath use
Augie Fackler <raf@durin42.com>
parents:
diff changeset
78 if util.endswithsep(path):
48417
35f1ecd84bd0 errors: use detailed exit code in pathauditor
Martin von Zweigbergk <martinvonz@google.com>
parents: 47972
diff changeset
79 raise error.InputError(
35f1ecd84bd0 errors: use detailed exit code in pathauditor
Martin von Zweigbergk <martinvonz@google.com>
parents: 47972
diff changeset
80 _(b"path ends in directory separator: %s") % path
35f1ecd84bd0 errors: use detailed exit code in pathauditor
Martin von Zweigbergk <martinvonz@google.com>
parents: 47972
diff changeset
81 )
20033
f962870712da pathutil: tease out a new library to break an import cycle from canonpath use
Augie Fackler <raf@durin42.com>
parents:
diff changeset
82 parts = util.splitpath(path)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 38593
diff changeset
83 if (
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 38593
diff changeset
84 os.path.splitdrive(path)[0]
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
85 or _lowerclean(parts[0]) in (b'.hg', b'.hg.', b'')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 38593
diff changeset
86 or pycompat.ospardir in parts
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 38593
diff changeset
87 ):
48417
35f1ecd84bd0 errors: use detailed exit code in pathauditor
Martin von Zweigbergk <martinvonz@google.com>
parents: 47972
diff changeset
88 raise error.InputError(
35f1ecd84bd0 errors: use detailed exit code in pathauditor
Martin von Zweigbergk <martinvonz@google.com>
parents: 47972
diff changeset
89 _(b"path contains illegal component: %s") % path
35f1ecd84bd0 errors: use detailed exit code in pathauditor
Martin von Zweigbergk <martinvonz@google.com>
parents: 47972
diff changeset
90 )
23599
6dad422ecc5a pathauditor: check for Windows shortname aliases
Matt Mackall <mpm@selenic.com>
parents: 23598
diff changeset
91 # Windows shortname aliases
49963
44deb5a164dc pathutil: slightly faster path audit in the common case
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49037
diff changeset
92 if b"~" in path:
44deb5a164dc pathutil: slightly faster path audit in the common case
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49037
diff changeset
93 for p in parts:
44deb5a164dc pathutil: slightly faster path audit in the common case
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49037
diff changeset
94 if b"~" in p:
44deb5a164dc pathutil: slightly faster path audit in the common case
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49037
diff changeset
95 first, last = p.split(b"~", 1)
44deb5a164dc pathutil: slightly faster path audit in the common case
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49037
diff changeset
96 if last.isdigit() and first.upper() in [b"HG", b"HG8B6C"]:
44deb5a164dc pathutil: slightly faster path audit in the common case
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49037
diff changeset
97 raise error.InputError(
44deb5a164dc pathutil: slightly faster path audit in the common case
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49037
diff changeset
98 _(b"path contains illegal component: %s") % path
44deb5a164dc pathutil: slightly faster path audit in the common case
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49037
diff changeset
99 )
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
100 if b'.hg' in _lowerclean(path):
44255
d84420232492 pathauditor: drop a redundant call to bytes.lower()
Martin von Zweigbergk <martinvonz@google.com>
parents: 43677
diff changeset
101 lparts = [_lowerclean(p) for p in parts]
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
102 for p in b'.hg', b'.hg.':
20033
f962870712da pathutil: tease out a new library to break an import cycle from canonpath use
Augie Fackler <raf@durin42.com>
parents:
diff changeset
103 if p in lparts[1:]:
f962870712da pathutil: tease out a new library to break an import cycle from canonpath use
Augie Fackler <raf@durin42.com>
parents:
diff changeset
104 pos = lparts.index(p)
f962870712da pathutil: tease out a new library to break an import cycle from canonpath use
Augie Fackler <raf@durin42.com>
parents:
diff changeset
105 base = os.path.join(*parts[:pos])
48417
35f1ecd84bd0 errors: use detailed exit code in pathauditor
Martin von Zweigbergk <martinvonz@google.com>
parents: 47972
diff changeset
106 raise error.InputError(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
107 _(b"path '%s' is inside nested repo %r")
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 38593
diff changeset
108 % (path, pycompat.bytestr(base))
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 38593
diff changeset
109 )
20033
f962870712da pathutil: tease out a new library to break an import cycle from canonpath use
Augie Fackler <raf@durin42.com>
parents:
diff changeset
110
49967
76d1e9f229fe merge: disable the whole filesystem access loop if [_realfs] is false
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49966
diff changeset
111 if self._realfs:
76d1e9f229fe merge: disable the whole filesystem access loop if [_realfs] is false
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49966
diff changeset
112 # It's important that we check the path parts starting from the root.
76d1e9f229fe merge: disable the whole filesystem access loop if [_realfs] is false
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49966
diff changeset
113 # We don't want to add "foo/bar/baz" to auditeddir before checking if
76d1e9f229fe merge: disable the whole filesystem access loop if [_realfs] is false
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49966
diff changeset
114 # there's a "foo/.hg" directory. This also means we won't accidentally
76d1e9f229fe merge: disable the whole filesystem access loop if [_realfs] is false
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49966
diff changeset
115 # traverse a symlink into some other filesystem (which is potentially
76d1e9f229fe merge: disable the whole filesystem access loop if [_realfs] is false
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49966
diff changeset
116 # expensive to access).
49981
789e152a6bdb pathutil: use `finddirs_rev_noroot` instead of `parts`
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49980
diff changeset
117 for prefix in finddirs_rev_noroot(path):
49967
76d1e9f229fe merge: disable the whole filesystem access loop if [_realfs] is false
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49966
diff changeset
118 if prefix in self.auditeddir:
49968
c7624b1ac8b4 merge: cache the fs checks made during [_checkunknownfiles]
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49967
diff changeset
119 res = self.auditeddir[prefix]
c7624b1ac8b4 merge: cache the fs checks made during [_checkunknownfiles]
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49967
diff changeset
120 else:
49985
bc83ebe07bf0 pathauditor: make _checkfs_exists a static method
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49981
diff changeset
121 res = pathauditor._checkfs_exists(
bc83ebe07bf0 pathauditor: make _checkfs_exists a static method
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49981
diff changeset
122 self.root, prefix, path, self.callback
bc83ebe07bf0 pathauditor: make _checkfs_exists a static method
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49981
diff changeset
123 )
49968
c7624b1ac8b4 merge: cache the fs checks made during [_checkunknownfiles]
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49967
diff changeset
124 if self._cached:
c7624b1ac8b4 merge: cache the fs checks made during [_checkunknownfiles]
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49967
diff changeset
125 self.auditeddir[prefix] = res
49967
76d1e9f229fe merge: disable the whole filesystem access loop if [_realfs] is false
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49966
diff changeset
126 if not res:
76d1e9f229fe merge: disable the whole filesystem access loop if [_realfs] is false
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49966
diff changeset
127 break
20033
f962870712da pathutil: tease out a new library to break an import cycle from canonpath use
Augie Fackler <raf@durin42.com>
parents:
diff changeset
128
33647
377e8ddaebef pathauditor: disable cache of audited paths by default (issue5628)
Yuya Nishihara <yuya@tcha.org>
parents: 33435
diff changeset
129 if self._cached:
49964
445b4d819e9a pathauditor: no need to normcase the paths
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49963
diff changeset
130 self.audited.add(path)
20033
f962870712da pathutil: tease out a new library to break an import cycle from canonpath use
Augie Fackler <raf@durin42.com>
parents:
diff changeset
131
49985
bc83ebe07bf0 pathauditor: make _checkfs_exists a static method
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49981
diff changeset
132 @staticmethod
bc83ebe07bf0 pathauditor: make _checkfs_exists a static method
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49981
diff changeset
133 def _checkfs_exists(
bc83ebe07bf0 pathauditor: make _checkfs_exists a static method
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49981
diff changeset
134 root,
bc83ebe07bf0 pathauditor: make _checkfs_exists a static method
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49981
diff changeset
135 prefix: bytes,
bc83ebe07bf0 pathauditor: make _checkfs_exists a static method
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49981
diff changeset
136 path: bytes,
bc83ebe07bf0 pathauditor: make _checkfs_exists a static method
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49981
diff changeset
137 callback: Optional[Callable[[bytes], bool]] = None,
bc83ebe07bf0 pathauditor: make _checkfs_exists a static method
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49981
diff changeset
138 ):
49966
1b701d425c37 merge: short-circuit the _checkfs loop upon getting ENOENT
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49964
diff changeset
139 """raise exception if a file system backed check fails.
1b701d425c37 merge: short-circuit the _checkfs loop upon getting ENOENT
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49964
diff changeset
140
1b701d425c37 merge: short-circuit the _checkfs loop upon getting ENOENT
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49964
diff changeset
141 Return a bool that indicates that the directory (or file) exists."""
49985
bc83ebe07bf0 pathauditor: make _checkfs_exists a static method
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49981
diff changeset
142 curpath = os.path.join(root, prefix)
27231
6d29ce250a3d pathauditor: move file system specific check in their own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26587
diff changeset
143 try:
6d29ce250a3d pathauditor: move file system specific check in their own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26587
diff changeset
144 st = os.lstat(curpath)
6d29ce250a3d pathauditor: move file system specific check in their own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26587
diff changeset
145 except OSError as err:
49966
1b701d425c37 merge: short-circuit the _checkfs loop upon getting ENOENT
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49964
diff changeset
146 if err.errno == errno.ENOENT:
1b701d425c37 merge: short-circuit the _checkfs loop upon getting ENOENT
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49964
diff changeset
147 return False
27231
6d29ce250a3d pathauditor: move file system specific check in their own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26587
diff changeset
148 # EINVAL can be raised as invalid path syntax under win32.
6d29ce250a3d pathauditor: move file system specific check in their own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26587
diff changeset
149 # They must be ignored for patterns can be checked too.
6d29ce250a3d pathauditor: move file system specific check in their own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26587
diff changeset
150 if err.errno not in (errno.ENOENT, errno.ENOTDIR, errno.EINVAL):
6d29ce250a3d pathauditor: move file system specific check in their own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26587
diff changeset
151 raise
6d29ce250a3d pathauditor: move file system specific check in their own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26587
diff changeset
152 else:
6d29ce250a3d pathauditor: move file system specific check in their own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26587
diff changeset
153 if stat.S_ISLNK(st.st_mode):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
154 msg = _(b'path %r traverses symbolic link %r') % (
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 38593
diff changeset
155 pycompat.bytestr(path),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 38593
diff changeset
156 pycompat.bytestr(prefix),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 38593
diff changeset
157 )
27235
054cd38a2f19 pathutil: use temporary variables instead of complicated wrapping
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 27232
diff changeset
158 raise error.Abort(msg)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 38593
diff changeset
159 elif stat.S_ISDIR(st.st_mode) and os.path.isdir(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
160 os.path.join(curpath, b'.hg')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 38593
diff changeset
161 ):
49985
bc83ebe07bf0 pathauditor: make _checkfs_exists a static method
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49981
diff changeset
162 if not callback or not callback(curpath):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
163 msg = _(b"path '%s' is inside nested repo %r")
36678
d3b893ec5f08 py3: fix formatting of path-auditing errors
Yuya Nishihara <yuya@tcha.org>
parents: 36676
diff changeset
164 raise error.Abort(msg % (path, pycompat.bytestr(prefix)))
49966
1b701d425c37 merge: short-circuit the _checkfs loop upon getting ENOENT
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49964
diff changeset
165 return True
27231
6d29ce250a3d pathauditor: move file system specific check in their own function
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26587
diff changeset
166
51304
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51302
diff changeset
167 def check(self, path: bytes) -> bool:
20033
f962870712da pathutil: tease out a new library to break an import cycle from canonpath use
Augie Fackler <raf@durin42.com>
parents:
diff changeset
168 try:
f962870712da pathutil: tease out a new library to break an import cycle from canonpath use
Augie Fackler <raf@durin42.com>
parents:
diff changeset
169 self(path)
f962870712da pathutil: tease out a new library to break an import cycle from canonpath use
Augie Fackler <raf@durin42.com>
parents:
diff changeset
170 return True
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25964
diff changeset
171 except (OSError, error.Abort):
20033
f962870712da pathutil: tease out a new library to break an import cycle from canonpath use
Augie Fackler <raf@durin42.com>
parents:
diff changeset
172 return False
f962870712da pathutil: tease out a new library to break an import cycle from canonpath use
Augie Fackler <raf@durin42.com>
parents:
diff changeset
173
44924
233ee525dcef grep: reduce the cost of pathauditor checks when grepping working copy
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents: 44630
diff changeset
174 @contextlib.contextmanager
233ee525dcef grep: reduce the cost of pathauditor checks when grepping working copy
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents: 44630
diff changeset
175 def cached(self):
233ee525dcef grep: reduce the cost of pathauditor checks when grepping working copy
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents: 44630
diff changeset
176 if self._cached:
233ee525dcef grep: reduce the cost of pathauditor checks when grepping working copy
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents: 44630
diff changeset
177 yield
233ee525dcef grep: reduce the cost of pathauditor checks when grepping working copy
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents: 44630
diff changeset
178 else:
233ee525dcef grep: reduce the cost of pathauditor checks when grepping working copy
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents: 44630
diff changeset
179 try:
233ee525dcef grep: reduce the cost of pathauditor checks when grepping working copy
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents: 44630
diff changeset
180 self._cached = True
233ee525dcef grep: reduce the cost of pathauditor checks when grepping working copy
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents: 44630
diff changeset
181 yield
233ee525dcef grep: reduce the cost of pathauditor checks when grepping working copy
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents: 44630
diff changeset
182 finally:
233ee525dcef grep: reduce the cost of pathauditor checks when grepping working copy
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents: 44630
diff changeset
183 self.audited.clear()
233ee525dcef grep: reduce the cost of pathauditor checks when grepping working copy
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents: 44630
diff changeset
184 self.auditeddir.clear()
233ee525dcef grep: reduce the cost of pathauditor checks when grepping working copy
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents: 44630
diff changeset
185 self._cached = False
233ee525dcef grep: reduce the cost of pathauditor checks when grepping working copy
Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
parents: 44630
diff changeset
186
51617
24844407fa0d perf: clear vfs audit_cache before each run
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51307
diff changeset
187 def clear_audit_cache(self):
24844407fa0d perf: clear vfs audit_cache before each run
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51307
diff changeset
188 """reset all audit cache
24844407fa0d perf: clear vfs audit_cache before each run
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51307
diff changeset
189
24844407fa0d perf: clear vfs audit_cache before each run
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51307
diff changeset
190 intended for debug and performance benchmark purposes"""
24844407fa0d perf: clear vfs audit_cache before each run
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51307
diff changeset
191 self.audited.clear()
24844407fa0d perf: clear vfs audit_cache before each run
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51307
diff changeset
192 self.auditeddir.clear()
24844407fa0d perf: clear vfs audit_cache before each run
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51307
diff changeset
193
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 38593
diff changeset
194
51304
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51302
diff changeset
195 def canonpath(
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51302
diff changeset
196 root: bytes,
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51302
diff changeset
197 cwd: bytes,
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51302
diff changeset
198 myname: bytes,
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51302
diff changeset
199 auditor: Optional[pathauditor] = None,
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51302
diff changeset
200 ) -> bytes:
45957
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 44924
diff changeset
201 """return the canonical path of myname, given cwd and root
34958
705d0f2bb677 pathutil: add doctests for canonpath()
Matt Harbison <matt_harbison@yahoo.com>
parents: 34956
diff changeset
202
705d0f2bb677 pathutil: add doctests for canonpath()
Matt Harbison <matt_harbison@yahoo.com>
parents: 34956
diff changeset
203 >>> def check(root, cwd, myname):
705d0f2bb677 pathutil: add doctests for canonpath()
Matt Harbison <matt_harbison@yahoo.com>
parents: 34956
diff changeset
204 ... a = pathauditor(root, realfs=False)
705d0f2bb677 pathutil: add doctests for canonpath()
Matt Harbison <matt_harbison@yahoo.com>
parents: 34956
diff changeset
205 ... try:
705d0f2bb677 pathutil: add doctests for canonpath()
Matt Harbison <matt_harbison@yahoo.com>
parents: 34956
diff changeset
206 ... return canonpath(root, cwd, myname, a)
705d0f2bb677 pathutil: add doctests for canonpath()
Matt Harbison <matt_harbison@yahoo.com>
parents: 34956
diff changeset
207 ... except error.Abort:
705d0f2bb677 pathutil: add doctests for canonpath()
Matt Harbison <matt_harbison@yahoo.com>
parents: 34956
diff changeset
208 ... return 'aborted'
705d0f2bb677 pathutil: add doctests for canonpath()
Matt Harbison <matt_harbison@yahoo.com>
parents: 34956
diff changeset
209 >>> def unixonly(root, cwd, myname, expected='aborted'):
705d0f2bb677 pathutil: add doctests for canonpath()
Matt Harbison <matt_harbison@yahoo.com>
parents: 34956
diff changeset
210 ... if pycompat.iswindows:
705d0f2bb677 pathutil: add doctests for canonpath()
Matt Harbison <matt_harbison@yahoo.com>
parents: 34956
diff changeset
211 ... return expected
705d0f2bb677 pathutil: add doctests for canonpath()
Matt Harbison <matt_harbison@yahoo.com>
parents: 34956
diff changeset
212 ... return check(root, cwd, myname)
705d0f2bb677 pathutil: add doctests for canonpath()
Matt Harbison <matt_harbison@yahoo.com>
parents: 34956
diff changeset
213 >>> def winonly(root, cwd, myname, expected='aborted'):
705d0f2bb677 pathutil: add doctests for canonpath()
Matt Harbison <matt_harbison@yahoo.com>
parents: 34956
diff changeset
214 ... if not pycompat.iswindows:
705d0f2bb677 pathutil: add doctests for canonpath()
Matt Harbison <matt_harbison@yahoo.com>
parents: 34956
diff changeset
215 ... return expected
705d0f2bb677 pathutil: add doctests for canonpath()
Matt Harbison <matt_harbison@yahoo.com>
parents: 34956
diff changeset
216 ... return check(root, cwd, myname)
705d0f2bb677 pathutil: add doctests for canonpath()
Matt Harbison <matt_harbison@yahoo.com>
parents: 34956
diff changeset
217 >>> winonly(b'd:\\\\repo', b'c:\\\\dir', b'filename')
705d0f2bb677 pathutil: add doctests for canonpath()
Matt Harbison <matt_harbison@yahoo.com>
parents: 34956
diff changeset
218 'aborted'
705d0f2bb677 pathutil: add doctests for canonpath()
Matt Harbison <matt_harbison@yahoo.com>
parents: 34956
diff changeset
219 >>> winonly(b'c:\\\\repo', b'c:\\\\dir', b'filename')
705d0f2bb677 pathutil: add doctests for canonpath()
Matt Harbison <matt_harbison@yahoo.com>
parents: 34956
diff changeset
220 'aborted'
705d0f2bb677 pathutil: add doctests for canonpath()
Matt Harbison <matt_harbison@yahoo.com>
parents: 34956
diff changeset
221 >>> winonly(b'c:\\\\repo', b'c:\\\\', b'filename')
705d0f2bb677 pathutil: add doctests for canonpath()
Matt Harbison <matt_harbison@yahoo.com>
parents: 34956
diff changeset
222 'aborted'
705d0f2bb677 pathutil: add doctests for canonpath()
Matt Harbison <matt_harbison@yahoo.com>
parents: 34956
diff changeset
223 >>> winonly(b'c:\\\\repo', b'c:\\\\', b'repo\\\\filename',
705d0f2bb677 pathutil: add doctests for canonpath()
Matt Harbison <matt_harbison@yahoo.com>
parents: 34956
diff changeset
224 ... b'filename')
705d0f2bb677 pathutil: add doctests for canonpath()
Matt Harbison <matt_harbison@yahoo.com>
parents: 34956
diff changeset
225 'filename'
705d0f2bb677 pathutil: add doctests for canonpath()
Matt Harbison <matt_harbison@yahoo.com>
parents: 34956
diff changeset
226 >>> winonly(b'c:\\\\repo', b'c:\\\\repo', b'filename', b'filename')
705d0f2bb677 pathutil: add doctests for canonpath()
Matt Harbison <matt_harbison@yahoo.com>
parents: 34956
diff changeset
227 'filename'
705d0f2bb677 pathutil: add doctests for canonpath()
Matt Harbison <matt_harbison@yahoo.com>
parents: 34956
diff changeset
228 >>> winonly(b'c:\\\\repo', b'c:\\\\repo\\\\subdir', b'filename',
705d0f2bb677 pathutil: add doctests for canonpath()
Matt Harbison <matt_harbison@yahoo.com>
parents: 34956
diff changeset
229 ... b'subdir/filename')
705d0f2bb677 pathutil: add doctests for canonpath()
Matt Harbison <matt_harbison@yahoo.com>
parents: 34956
diff changeset
230 'subdir/filename'
705d0f2bb677 pathutil: add doctests for canonpath()
Matt Harbison <matt_harbison@yahoo.com>
parents: 34956
diff changeset
231 >>> unixonly(b'/repo', b'/dir', b'filename')
705d0f2bb677 pathutil: add doctests for canonpath()
Matt Harbison <matt_harbison@yahoo.com>
parents: 34956
diff changeset
232 'aborted'
705d0f2bb677 pathutil: add doctests for canonpath()
Matt Harbison <matt_harbison@yahoo.com>
parents: 34956
diff changeset
233 >>> unixonly(b'/repo', b'/', b'filename')
705d0f2bb677 pathutil: add doctests for canonpath()
Matt Harbison <matt_harbison@yahoo.com>
parents: 34956
diff changeset
234 'aborted'
705d0f2bb677 pathutil: add doctests for canonpath()
Matt Harbison <matt_harbison@yahoo.com>
parents: 34956
diff changeset
235 >>> unixonly(b'/repo', b'/', b'repo/filename', b'filename')
705d0f2bb677 pathutil: add doctests for canonpath()
Matt Harbison <matt_harbison@yahoo.com>
parents: 34956
diff changeset
236 'filename'
705d0f2bb677 pathutil: add doctests for canonpath()
Matt Harbison <matt_harbison@yahoo.com>
parents: 34956
diff changeset
237 >>> unixonly(b'/repo', b'/repo', b'filename', b'filename')
705d0f2bb677 pathutil: add doctests for canonpath()
Matt Harbison <matt_harbison@yahoo.com>
parents: 34956
diff changeset
238 'filename'
705d0f2bb677 pathutil: add doctests for canonpath()
Matt Harbison <matt_harbison@yahoo.com>
parents: 34956
diff changeset
239 >>> unixonly(b'/repo', b'/repo/subdir', b'filename', b'subdir/filename')
705d0f2bb677 pathutil: add doctests for canonpath()
Matt Harbison <matt_harbison@yahoo.com>
parents: 34956
diff changeset
240 'subdir/filename'
45957
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 44924
diff changeset
241 """
20033
f962870712da pathutil: tease out a new library to break an import cycle from canonpath use
Augie Fackler <raf@durin42.com>
parents:
diff changeset
242 if util.endswithsep(root):
f962870712da pathutil: tease out a new library to break an import cycle from canonpath use
Augie Fackler <raf@durin42.com>
parents:
diff changeset
243 rootsep = root
f962870712da pathutil: tease out a new library to break an import cycle from canonpath use
Augie Fackler <raf@durin42.com>
parents:
diff changeset
244 else:
30619
cfe66dcf45c0 py3: replace os.sep with pycompat.ossep (part 2 of 4)
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30342
diff changeset
245 rootsep = root + pycompat.ossep
20033
f962870712da pathutil: tease out a new library to break an import cycle from canonpath use
Augie Fackler <raf@durin42.com>
parents:
diff changeset
246 name = myname
f962870712da pathutil: tease out a new library to break an import cycle from canonpath use
Augie Fackler <raf@durin42.com>
parents:
diff changeset
247 if not os.path.isabs(name):
f962870712da pathutil: tease out a new library to break an import cycle from canonpath use
Augie Fackler <raf@durin42.com>
parents:
diff changeset
248 name = os.path.join(root, cwd, name)
f962870712da pathutil: tease out a new library to break an import cycle from canonpath use
Augie Fackler <raf@durin42.com>
parents:
diff changeset
249 name = os.path.normpath(name)
f962870712da pathutil: tease out a new library to break an import cycle from canonpath use
Augie Fackler <raf@durin42.com>
parents:
diff changeset
250 if auditor is None:
f962870712da pathutil: tease out a new library to break an import cycle from canonpath use
Augie Fackler <raf@durin42.com>
parents:
diff changeset
251 auditor = pathauditor(root)
f962870712da pathutil: tease out a new library to break an import cycle from canonpath use
Augie Fackler <raf@durin42.com>
parents:
diff changeset
252 if name != rootsep and name.startswith(rootsep):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 38593
diff changeset
253 name = name[len(rootsep) :]
20033
f962870712da pathutil: tease out a new library to break an import cycle from canonpath use
Augie Fackler <raf@durin42.com>
parents:
diff changeset
254 auditor(name)
f962870712da pathutil: tease out a new library to break an import cycle from canonpath use
Augie Fackler <raf@durin42.com>
parents:
diff changeset
255 return util.pconvert(name)
f962870712da pathutil: tease out a new library to break an import cycle from canonpath use
Augie Fackler <raf@durin42.com>
parents:
diff changeset
256 elif name == root:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
257 return b''
20033
f962870712da pathutil: tease out a new library to break an import cycle from canonpath use
Augie Fackler <raf@durin42.com>
parents:
diff changeset
258 else:
f962870712da pathutil: tease out a new library to break an import cycle from canonpath use
Augie Fackler <raf@durin42.com>
parents:
diff changeset
259 # Determine whether `name' is in the hierarchy at or beneath `root',
f962870712da pathutil: tease out a new library to break an import cycle from canonpath use
Augie Fackler <raf@durin42.com>
parents:
diff changeset
260 # by iterating name=dirname(name) until that causes no change (can't
f962870712da pathutil: tease out a new library to break an import cycle from canonpath use
Augie Fackler <raf@durin42.com>
parents:
diff changeset
261 # check name == '/', because that doesn't work on windows). The list
f962870712da pathutil: tease out a new library to break an import cycle from canonpath use
Augie Fackler <raf@durin42.com>
parents:
diff changeset
262 # `rel' holds the reversed list of components making up the relative
f962870712da pathutil: tease out a new library to break an import cycle from canonpath use
Augie Fackler <raf@durin42.com>
parents:
diff changeset
263 # file name we want.
f962870712da pathutil: tease out a new library to break an import cycle from canonpath use
Augie Fackler <raf@durin42.com>
parents:
diff changeset
264 rel = []
f962870712da pathutil: tease out a new library to break an import cycle from canonpath use
Augie Fackler <raf@durin42.com>
parents:
diff changeset
265 while True:
f962870712da pathutil: tease out a new library to break an import cycle from canonpath use
Augie Fackler <raf@durin42.com>
parents:
diff changeset
266 try:
f962870712da pathutil: tease out a new library to break an import cycle from canonpath use
Augie Fackler <raf@durin42.com>
parents:
diff changeset
267 s = util.samefile(name, root)
f962870712da pathutil: tease out a new library to break an import cycle from canonpath use
Augie Fackler <raf@durin42.com>
parents:
diff changeset
268 except OSError:
f962870712da pathutil: tease out a new library to break an import cycle from canonpath use
Augie Fackler <raf@durin42.com>
parents:
diff changeset
269 s = False
f962870712da pathutil: tease out a new library to break an import cycle from canonpath use
Augie Fackler <raf@durin42.com>
parents:
diff changeset
270 if s:
f962870712da pathutil: tease out a new library to break an import cycle from canonpath use
Augie Fackler <raf@durin42.com>
parents:
diff changeset
271 if not rel:
f962870712da pathutil: tease out a new library to break an import cycle from canonpath use
Augie Fackler <raf@durin42.com>
parents:
diff changeset
272 # name was actually the same as root (maybe a symlink)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
273 return b''
20033
f962870712da pathutil: tease out a new library to break an import cycle from canonpath use
Augie Fackler <raf@durin42.com>
parents:
diff changeset
274 rel.reverse()
f962870712da pathutil: tease out a new library to break an import cycle from canonpath use
Augie Fackler <raf@durin42.com>
parents:
diff changeset
275 name = os.path.join(*rel)
f962870712da pathutil: tease out a new library to break an import cycle from canonpath use
Augie Fackler <raf@durin42.com>
parents:
diff changeset
276 auditor(name)
f962870712da pathutil: tease out a new library to break an import cycle from canonpath use
Augie Fackler <raf@durin42.com>
parents:
diff changeset
277 return util.pconvert(name)
f962870712da pathutil: tease out a new library to break an import cycle from canonpath use
Augie Fackler <raf@durin42.com>
parents:
diff changeset
278 dirname, basename = util.split(name)
f962870712da pathutil: tease out a new library to break an import cycle from canonpath use
Augie Fackler <raf@durin42.com>
parents:
diff changeset
279 rel.append(basename)
f962870712da pathutil: tease out a new library to break an import cycle from canonpath use
Augie Fackler <raf@durin42.com>
parents:
diff changeset
280 if dirname == name:
f962870712da pathutil: tease out a new library to break an import cycle from canonpath use
Augie Fackler <raf@durin42.com>
parents:
diff changeset
281 break
f962870712da pathutil: tease out a new library to break an import cycle from canonpath use
Augie Fackler <raf@durin42.com>
parents:
diff changeset
282 name = dirname
f962870712da pathutil: tease out a new library to break an import cycle from canonpath use
Augie Fackler <raf@durin42.com>
parents:
diff changeset
283
25011
7d6a507a4c53 pathutil: hint if a path is root relative instead of cwd relative (issue4663)
Matt Harbison <matt_harbison@yahoo.com>
parents: 23602
diff changeset
284 # A common mistake is to use -R, but specify a file relative to the repo
7d6a507a4c53 pathutil: hint if a path is root relative instead of cwd relative (issue4663)
Matt Harbison <matt_harbison@yahoo.com>
parents: 23602
diff changeset
285 # instead of cwd. Detect that case, and provide a hint to the user.
7d6a507a4c53 pathutil: hint if a path is root relative instead of cwd relative (issue4663)
Matt Harbison <matt_harbison@yahoo.com>
parents: 23602
diff changeset
286 hint = None
7d6a507a4c53 pathutil: hint if a path is root relative instead of cwd relative (issue4663)
Matt Harbison <matt_harbison@yahoo.com>
parents: 23602
diff changeset
287 try:
25022
10bbdcd89164 canonpath: fix infinite recursion
Matt Mackall <mpm@selenic.com>
parents: 25011
diff changeset
288 if cwd != root:
10bbdcd89164 canonpath: fix infinite recursion
Matt Mackall <mpm@selenic.com>
parents: 25011
diff changeset
289 canonpath(root, root, myname, auditor)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
290 relpath = util.pathto(root, cwd, b'')
38593
21be76e07148 py3: use bytes.endswith() instead of bytes[n]
Yuya Nishihara <yuya@tcha.org>
parents: 36678
diff changeset
291 if relpath.endswith(pycompat.ossep):
34956
f445b10dc7fb pathutil: use util.pathto() to calculate relative cwd in canonpath()
Matt Harbison <matt_harbison@yahoo.com>
parents: 34261
diff changeset
292 relpath = relpath[:-1]
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
293 hint = _(b"consider using '--cwd %s'") % relpath
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 25964
diff changeset
294 except error.Abort:
25011
7d6a507a4c53 pathutil: hint if a path is root relative instead of cwd relative (issue4663)
Matt Harbison <matt_harbison@yahoo.com>
parents: 23602
diff changeset
295 pass
7d6a507a4c53 pathutil: hint if a path is root relative instead of cwd relative (issue4663)
Matt Harbison <matt_harbison@yahoo.com>
parents: 23602
diff changeset
296
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 38593
diff changeset
297 raise error.Abort(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
298 _(b"%s not under root '%s'") % (myname, root), hint=hint
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 38593
diff changeset
299 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 38593
diff changeset
300
21568
8dd17b19e722 subrepo: normalize path in the specific way for problematic encodings
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20033
diff changeset
301
51304
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51302
diff changeset
302 def normasprefix(path: bytes) -> bytes:
45957
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 44924
diff changeset
303 """normalize the specified path as path prefix
21568
8dd17b19e722 subrepo: normalize path in the specific way for problematic encodings
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20033
diff changeset
304
23139
e53f6b72a0e4 spelling: fixes from proofreading of spell checker issues
Mads Kiilerich <madski@unity3d.com>
parents: 21568
diff changeset
305 Returned value can be used safely for "p.startswith(prefix)",
21568
8dd17b19e722 subrepo: normalize path in the specific way for problematic encodings
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20033
diff changeset
306 "p[len(prefix):]", and so on.
8dd17b19e722 subrepo: normalize path in the specific way for problematic encodings
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20033
diff changeset
307
8dd17b19e722 subrepo: normalize path in the specific way for problematic encodings
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20033
diff changeset
308 For efficiency, this expects "path" argument to be already
8dd17b19e722 subrepo: normalize path in the specific way for problematic encodings
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20033
diff changeset
309 normalized by "os.path.normpath", "os.path.realpath", and so on.
8dd17b19e722 subrepo: normalize path in the specific way for problematic encodings
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20033
diff changeset
310
8dd17b19e722 subrepo: normalize path in the specific way for problematic encodings
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20033
diff changeset
311 See also issue3033 for detail about need of this function.
8dd17b19e722 subrepo: normalize path in the specific way for problematic encodings
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20033
diff changeset
312
34261
cd022a11ec83 py3: use bytes os.sep in doctest of pathutil.py
Yuya Nishihara <yuya@tcha.org>
parents: 34146
diff changeset
313 >>> normasprefix(b'/foo/bar').replace(pycompat.ossep, b'/')
21568
8dd17b19e722 subrepo: normalize path in the specific way for problematic encodings
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20033
diff changeset
314 '/foo/bar/'
34261
cd022a11ec83 py3: use bytes os.sep in doctest of pathutil.py
Yuya Nishihara <yuya@tcha.org>
parents: 34146
diff changeset
315 >>> normasprefix(b'/').replace(pycompat.ossep, b'/')
21568
8dd17b19e722 subrepo: normalize path in the specific way for problematic encodings
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20033
diff changeset
316 '/'
45957
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 44924
diff changeset
317 """
21568
8dd17b19e722 subrepo: normalize path in the specific way for problematic encodings
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20033
diff changeset
318 d, p = os.path.splitdrive(path)
30619
cfe66dcf45c0 py3: replace os.sep with pycompat.ossep (part 2 of 4)
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30342
diff changeset
319 if len(p) != len(pycompat.ossep):
cfe66dcf45c0 py3: replace os.sep with pycompat.ossep (part 2 of 4)
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30342
diff changeset
320 return path + pycompat.ossep
21568
8dd17b19e722 subrepo: normalize path in the specific way for problematic encodings
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20033
diff changeset
321 else:
8dd17b19e722 subrepo: normalize path in the specific way for problematic encodings
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20033
diff changeset
322 return path
25281
660b178f49c7 pathutil: add dirname and join functions
Durham Goode <durham@fb.com>
parents: 25022
diff changeset
323
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 38593
diff changeset
324
51304
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51302
diff changeset
325 def finddirs(path: bytes) -> Iterator[bytes]:
43677
0b7733719d21 utils: move finddirs() to pathutil
Martin von Zweigbergk <martinvonz@google.com>
parents: 43571
diff changeset
326 pos = path.rfind(b'/')
0b7733719d21 utils: move finddirs() to pathutil
Martin von Zweigbergk <martinvonz@google.com>
parents: 43571
diff changeset
327 while pos != -1:
0b7733719d21 utils: move finddirs() to pathutil
Martin von Zweigbergk <martinvonz@google.com>
parents: 43571
diff changeset
328 yield path[:pos]
0b7733719d21 utils: move finddirs() to pathutil
Martin von Zweigbergk <martinvonz@google.com>
parents: 43571
diff changeset
329 pos = path.rfind(b'/', 0, pos)
0b7733719d21 utils: move finddirs() to pathutil
Martin von Zweigbergk <martinvonz@google.com>
parents: 43571
diff changeset
330 yield b''
0b7733719d21 utils: move finddirs() to pathutil
Martin von Zweigbergk <martinvonz@google.com>
parents: 43571
diff changeset
331
0b7733719d21 utils: move finddirs() to pathutil
Martin von Zweigbergk <martinvonz@google.com>
parents: 43571
diff changeset
332
49980
7623d79f872c pathutil: add the more efficient finddir iterator
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49979
diff changeset
333 def finddirs_rev_noroot(path: bytes) -> Iterator[bytes]:
7623d79f872c pathutil: add the more efficient finddir iterator
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49979
diff changeset
334 pos = path.find(pycompat.ossep)
7623d79f872c pathutil: add the more efficient finddir iterator
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49979
diff changeset
335 while pos != -1:
7623d79f872c pathutil: add the more efficient finddir iterator
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49979
diff changeset
336 yield path[:pos]
7623d79f872c pathutil: add the more efficient finddir iterator
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49979
diff changeset
337 pos = path.find(pycompat.ossep, pos + 1)
7623d79f872c pathutil: add the more efficient finddir iterator
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49979
diff changeset
338
7623d79f872c pathutil: add the more efficient finddir iterator
Arseniy Alekseyev <aalekseyev@janestreet.com>
parents: 49979
diff changeset
339
52906
bde94bd8e8a2 typing: use a protocol to annotate `pathutil.dirs` in repository.py
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 52883
diff changeset
340 class dirs(int_misc.IDirs):
43571
c21aca51b392 utils: move the `dirs` definition in pathutil (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43077
diff changeset
341 '''a multiset of directory names from a set of file paths'''
c21aca51b392 utils: move the `dirs` definition in pathutil (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43077
diff changeset
342
47972
e02f9af7aed1 pathutil: replace the `skip` argument of `dirs` with a boolean
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47541
diff changeset
343 def __init__(self, map, only_tracked=False):
45957
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 44924
diff changeset
344 """
44630
11f284c8c5e4 pathutil: document that dirs map type implies manifest/dirstate processing
Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
parents: 44392
diff changeset
345 a dict map indicates a dirstate while a list indicates a manifest
45957
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 44924
diff changeset
346 """
43571
c21aca51b392 utils: move the `dirs` definition in pathutil (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43077
diff changeset
347 self._dirs = {}
c21aca51b392 utils: move the `dirs` definition in pathutil (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43077
diff changeset
348 addpath = self.addpath
47972
e02f9af7aed1 pathutil: replace the `skip` argument of `dirs` with a boolean
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47541
diff changeset
349 if isinstance(map, dict) and only_tracked:
49004
f254fc73d956 global: bulk replace simple pycompat.iteritems(x) with x.items()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48966
diff changeset
350 for f, s in map.items():
47972
e02f9af7aed1 pathutil: replace the `skip` argument of `dirs` with a boolean
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47541
diff changeset
351 if s.state != b'r':
43571
c21aca51b392 utils: move the `dirs` definition in pathutil (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43077
diff changeset
352 addpath(f)
47972
e02f9af7aed1 pathutil: replace the `skip` argument of `dirs` with a boolean
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47541
diff changeset
353 elif only_tracked:
e02f9af7aed1 pathutil: replace the `skip` argument of `dirs` with a boolean
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47541
diff changeset
354 msg = b"`only_tracked` is only supported with a dict source"
e02f9af7aed1 pathutil: replace the `skip` argument of `dirs` with a boolean
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47541
diff changeset
355 raise error.ProgrammingError(msg)
43571
c21aca51b392 utils: move the `dirs` definition in pathutil (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43077
diff changeset
356 else:
c21aca51b392 utils: move the `dirs` definition in pathutil (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43077
diff changeset
357 for f in map:
c21aca51b392 utils: move the `dirs` definition in pathutil (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43077
diff changeset
358 addpath(f)
c21aca51b392 utils: move the `dirs` definition in pathutil (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43077
diff changeset
359
51304
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51302
diff changeset
360 def addpath(self, path: bytes) -> None:
43571
c21aca51b392 utils: move the `dirs` definition in pathutil (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43077
diff changeset
361 dirs = self._dirs
43677
0b7733719d21 utils: move finddirs() to pathutil
Martin von Zweigbergk <martinvonz@google.com>
parents: 43571
diff changeset
362 for base in finddirs(path):
43571
c21aca51b392 utils: move the `dirs` definition in pathutil (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43077
diff changeset
363 if base.endswith(b'/'):
c21aca51b392 utils: move the `dirs` definition in pathutil (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43077
diff changeset
364 raise ValueError(
c21aca51b392 utils: move the `dirs` definition in pathutil (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43077
diff changeset
365 "found invalid consecutive slashes in path: %r" % base
c21aca51b392 utils: move the `dirs` definition in pathutil (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43077
diff changeset
366 )
c21aca51b392 utils: move the `dirs` definition in pathutil (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43077
diff changeset
367 if base in dirs:
c21aca51b392 utils: move the `dirs` definition in pathutil (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43077
diff changeset
368 dirs[base] += 1
c21aca51b392 utils: move the `dirs` definition in pathutil (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43077
diff changeset
369 return
c21aca51b392 utils: move the `dirs` definition in pathutil (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43077
diff changeset
370 dirs[base] = 1
c21aca51b392 utils: move the `dirs` definition in pathutil (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43077
diff changeset
371
51304
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51302
diff changeset
372 def delpath(self, path: bytes) -> None:
43571
c21aca51b392 utils: move the `dirs` definition in pathutil (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43077
diff changeset
373 dirs = self._dirs
43677
0b7733719d21 utils: move finddirs() to pathutil
Martin von Zweigbergk <martinvonz@google.com>
parents: 43571
diff changeset
374 for base in finddirs(path):
43571
c21aca51b392 utils: move the `dirs` definition in pathutil (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43077
diff changeset
375 if dirs[base] > 1:
c21aca51b392 utils: move the `dirs` definition in pathutil (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43077
diff changeset
376 dirs[base] -= 1
c21aca51b392 utils: move the `dirs` definition in pathutil (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43077
diff changeset
377 return
c21aca51b392 utils: move the `dirs` definition in pathutil (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43077
diff changeset
378 del dirs[base]
c21aca51b392 utils: move the `dirs` definition in pathutil (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43077
diff changeset
379
c21aca51b392 utils: move the `dirs` definition in pathutil (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43077
diff changeset
380 def __iter__(self):
c21aca51b392 utils: move the `dirs` definition in pathutil (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43077
diff changeset
381 return iter(self._dirs)
c21aca51b392 utils: move the `dirs` definition in pathutil (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43077
diff changeset
382
51304
f15cb5111a1e pytype: move some type comment to proper annotation
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51302
diff changeset
383 def __contains__(self, d: bytes) -> bool:
43571
c21aca51b392 utils: move the `dirs` definition in pathutil (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43077
diff changeset
384 return d in self._dirs
c21aca51b392 utils: move the `dirs` definition in pathutil (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43077
diff changeset
385
c21aca51b392 utils: move the `dirs` definition in pathutil (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43077
diff changeset
386
50951
d718eddf01d9 safehasattr: drop usage in favor of hasattr
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49985
diff changeset
387 if hasattr(parsers, 'dirs'):
43571
c21aca51b392 utils: move the `dirs` definition in pathutil (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43077
diff changeset
388 dirs = parsers.dirs
c21aca51b392 utils: move the `dirs` definition in pathutil (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43077
diff changeset
389
c21aca51b392 utils: move the `dirs` definition in pathutil (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43077
diff changeset
390 if rustdirs is not None:
c21aca51b392 utils: move the `dirs` definition in pathutil (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43077
diff changeset
391 dirs = rustdirs
c21aca51b392 utils: move the `dirs` definition in pathutil (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43077
diff changeset
392
c21aca51b392 utils: move the `dirs` definition in pathutil (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 43077
diff changeset
393
25286
127a11f705d9 pathutil: demote two local functions to just be forwards
Augie Fackler <augie@google.com>
parents: 25285
diff changeset
394 # forward two methods from posixpath that do what we need, but we'd
127a11f705d9 pathutil: demote two local functions to just be forwards
Augie Fackler <augie@google.com>
parents: 25285
diff changeset
395 # rather not let our internals know that we're thinking in posix terms
127a11f705d9 pathutil: demote two local functions to just be forwards
Augie Fackler <augie@google.com>
parents: 25285
diff changeset
396 # - instead we'll let them be oblivious.
127a11f705d9 pathutil: demote two local functions to just be forwards
Augie Fackler <augie@google.com>
parents: 25285
diff changeset
397 join = posixpath.join
51305
8b2ea2246a5f pytype: convert type comment for inline variable too
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 51304
diff changeset
398 dirname: Callable[[bytes], bytes] = posixpath.dirname