61 normpath = self.normcase(path) |
61 normpath = self.normcase(path) |
62 if normpath in self.audited: |
62 if normpath in self.audited: |
63 return |
63 return |
64 # AIX ignores "/" at end of path, others raise EISDIR. |
64 # AIX ignores "/" at end of path, others raise EISDIR. |
65 if util.endswithsep(path): |
65 if util.endswithsep(path): |
66 raise error.Abort(_("path ends in directory separator: %s") % path) |
66 raise error.Abort(_(b"path ends in directory separator: %s") % path) |
67 parts = util.splitpath(path) |
67 parts = util.splitpath(path) |
68 if ( |
68 if ( |
69 os.path.splitdrive(path)[0] |
69 os.path.splitdrive(path)[0] |
70 or _lowerclean(parts[0]) in ('.hg', '.hg.', '') |
70 or _lowerclean(parts[0]) in (b'.hg', b'.hg.', b'') |
71 or pycompat.ospardir in parts |
71 or pycompat.ospardir in parts |
72 ): |
72 ): |
73 raise error.Abort(_("path contains illegal component: %s") % path) |
73 raise error.Abort(_(b"path contains illegal component: %s") % path) |
74 # Windows shortname aliases |
74 # Windows shortname aliases |
75 for p in parts: |
75 for p in parts: |
76 if "~" in p: |
76 if b"~" in p: |
77 first, last = p.split("~", 1) |
77 first, last = p.split(b"~", 1) |
78 if last.isdigit() and first.upper() in ["HG", "HG8B6C"]: |
78 if last.isdigit() and first.upper() in [b"HG", b"HG8B6C"]: |
79 raise error.Abort( |
79 raise error.Abort( |
80 _("path contains illegal component: %s") % path |
80 _(b"path contains illegal component: %s") % path |
81 ) |
81 ) |
82 if '.hg' in _lowerclean(path): |
82 if b'.hg' in _lowerclean(path): |
83 lparts = [_lowerclean(p.lower()) for p in parts] |
83 lparts = [_lowerclean(p.lower()) for p in parts] |
84 for p in '.hg', '.hg.': |
84 for p in b'.hg', b'.hg.': |
85 if p in lparts[1:]: |
85 if p in lparts[1:]: |
86 pos = lparts.index(p) |
86 pos = lparts.index(p) |
87 base = os.path.join(*parts[:pos]) |
87 base = os.path.join(*parts[:pos]) |
88 raise error.Abort( |
88 raise error.Abort( |
89 _("path '%s' is inside nested repo %r") |
89 _(b"path '%s' is inside nested repo %r") |
90 % (path, pycompat.bytestr(base)) |
90 % (path, pycompat.bytestr(base)) |
91 ) |
91 ) |
92 |
92 |
93 normparts = util.splitpath(normpath) |
93 normparts = util.splitpath(normpath) |
94 assert len(parts) == len(normparts) |
94 assert len(parts) == len(normparts) |
124 # They must be ignored for patterns can be checked too. |
124 # They must be ignored for patterns can be checked too. |
125 if err.errno not in (errno.ENOENT, errno.ENOTDIR, errno.EINVAL): |
125 if err.errno not in (errno.ENOENT, errno.ENOTDIR, errno.EINVAL): |
126 raise |
126 raise |
127 else: |
127 else: |
128 if stat.S_ISLNK(st.st_mode): |
128 if stat.S_ISLNK(st.st_mode): |
129 msg = _('path %r traverses symbolic link %r') % ( |
129 msg = _(b'path %r traverses symbolic link %r') % ( |
130 pycompat.bytestr(path), |
130 pycompat.bytestr(path), |
131 pycompat.bytestr(prefix), |
131 pycompat.bytestr(prefix), |
132 ) |
132 ) |
133 raise error.Abort(msg) |
133 raise error.Abort(msg) |
134 elif stat.S_ISDIR(st.st_mode) and os.path.isdir( |
134 elif stat.S_ISDIR(st.st_mode) and os.path.isdir( |
135 os.path.join(curpath, '.hg') |
135 os.path.join(curpath, b'.hg') |
136 ): |
136 ): |
137 if not self.callback or not self.callback(curpath): |
137 if not self.callback or not self.callback(curpath): |
138 msg = _("path '%s' is inside nested repo %r") |
138 msg = _(b"path '%s' is inside nested repo %r") |
139 raise error.Abort(msg % (path, pycompat.bytestr(prefix))) |
139 raise error.Abort(msg % (path, pycompat.bytestr(prefix))) |
140 |
140 |
141 def check(self, path): |
141 def check(self, path): |
142 try: |
142 try: |
143 self(path) |
143 self(path) |
201 if name != rootsep and name.startswith(rootsep): |
201 if name != rootsep and name.startswith(rootsep): |
202 name = name[len(rootsep) :] |
202 name = name[len(rootsep) :] |
203 auditor(name) |
203 auditor(name) |
204 return util.pconvert(name) |
204 return util.pconvert(name) |
205 elif name == root: |
205 elif name == root: |
206 return '' |
206 return b'' |
207 else: |
207 else: |
208 # Determine whether `name' is in the hierarchy at or beneath `root', |
208 # Determine whether `name' is in the hierarchy at or beneath `root', |
209 # by iterating name=dirname(name) until that causes no change (can't |
209 # by iterating name=dirname(name) until that causes no change (can't |
210 # check name == '/', because that doesn't work on windows). The list |
210 # check name == '/', because that doesn't work on windows). The list |
211 # `rel' holds the reversed list of components making up the relative |
211 # `rel' holds the reversed list of components making up the relative |
234 # instead of cwd. Detect that case, and provide a hint to the user. |
234 # instead of cwd. Detect that case, and provide a hint to the user. |
235 hint = None |
235 hint = None |
236 try: |
236 try: |
237 if cwd != root: |
237 if cwd != root: |
238 canonpath(root, root, myname, auditor) |
238 canonpath(root, root, myname, auditor) |
239 relpath = util.pathto(root, cwd, '') |
239 relpath = util.pathto(root, cwd, b'') |
240 if relpath.endswith(pycompat.ossep): |
240 if relpath.endswith(pycompat.ossep): |
241 relpath = relpath[:-1] |
241 relpath = relpath[:-1] |
242 hint = _("consider using '--cwd %s'") % relpath |
242 hint = _(b"consider using '--cwd %s'") % relpath |
243 except error.Abort: |
243 except error.Abort: |
244 pass |
244 pass |
245 |
245 |
246 raise error.Abort( |
246 raise error.Abort( |
247 _("%s not under root '%s'") % (myname, root), hint=hint |
247 _(b"%s not under root '%s'") % (myname, root), hint=hint |
248 ) |
248 ) |
249 |
249 |
250 |
250 |
251 def normasprefix(path): |
251 def normasprefix(path): |
252 '''normalize the specified path as path prefix |
252 '''normalize the specified path as path prefix |