Mercurial > public > mercurial-scm > hg-stable
diff mercurial/pathutil.py @ 43076:2372284d9457
formatting: blacken the codebase
This is using my patch to black
(https://github.com/psf/black/pull/826) so we don't un-wrap collection
literals.
Done with:
hg files 'set:**.py - mercurial/thirdparty/** - "contrib/python-zstandard/**"' | xargs black -S
# skip-blame mass-reformatting only
# no-check-commit reformats foo_bar functions
Differential Revision: https://phab.mercurial-scm.org/D6971
author | Augie Fackler <augie@google.com> |
---|---|
date | Sun, 06 Oct 2019 09:45:02 -0400 |
parents | 21be76e07148 |
children | 687b865b95ad |
line wrap: on
line diff
--- a/mercurial/pathutil.py Sat Oct 05 10:29:34 2019 -0400 +++ b/mercurial/pathutil.py Sun Oct 06 09:45:02 2019 -0400 @@ -13,9 +13,11 @@ util, ) + def _lowerclean(s): return encoding.hfsignoreclean(s.lower()) + class pathauditor(object): '''ensure that a filesystem path contains no banned components. the following properties of a path are checked: @@ -63,25 +65,30 @@ if util.endswithsep(path): raise error.Abort(_("path ends in directory separator: %s") % path) parts = util.splitpath(path) - if (os.path.splitdrive(path)[0] + if ( + os.path.splitdrive(path)[0] or _lowerclean(parts[0]) in ('.hg', '.hg.', '') - or pycompat.ospardir in parts): + or pycompat.ospardir in parts + ): raise error.Abort(_("path contains illegal component: %s") % path) # Windows shortname aliases for p in parts: if "~" in p: first, last = p.split("~", 1) if last.isdigit() and first.upper() in ["HG", "HG8B6C"]: - raise error.Abort(_("path contains illegal component: %s") - % path) + raise error.Abort( + _("path contains illegal component: %s") % path + ) if '.hg' in _lowerclean(path): lparts = [_lowerclean(p.lower()) for p in parts] for p in '.hg', '.hg.': if p in lparts[1:]: pos = lparts.index(p) base = os.path.join(*parts[:pos]) - raise error.Abort(_("path '%s' is inside nested repo %r") - % (path, pycompat.bytestr(base))) + raise error.Abort( + _("path '%s' is inside nested repo %r") + % (path, pycompat.bytestr(base)) + ) normparts = util.splitpath(normpath) assert len(parts) == len(normparts) @@ -93,8 +100,8 @@ # This means we won't accidentally traverse a symlink into some other # filesystem (which is potentially expensive to access). for i in range(len(parts)): - prefix = pycompat.ossep.join(parts[:i + 1]) - normprefix = pycompat.ossep.join(normparts[:i + 1]) + prefix = pycompat.ossep.join(parts[: i + 1]) + normprefix = pycompat.ossep.join(normparts[: i + 1]) if normprefix in self.auditeddir: continue if self._realfs: @@ -119,11 +126,14 @@ raise else: if stat.S_ISLNK(st.st_mode): - msg = (_('path %r traverses symbolic link %r') - % (pycompat.bytestr(path), pycompat.bytestr(prefix))) + msg = _('path %r traverses symbolic link %r') % ( + pycompat.bytestr(path), + pycompat.bytestr(prefix), + ) raise error.Abort(msg) - elif (stat.S_ISDIR(st.st_mode) and - os.path.isdir(os.path.join(curpath, '.hg'))): + elif stat.S_ISDIR(st.st_mode) and os.path.isdir( + os.path.join(curpath, '.hg') + ): if not self.callback or not self.callback(curpath): msg = _("path '%s' is inside nested repo %r") raise error.Abort(msg % (path, pycompat.bytestr(prefix))) @@ -135,6 +145,7 @@ except (OSError, error.Abort): return False + def canonpath(root, cwd, myname, auditor=None): '''return the canonical path of myname, given cwd and root @@ -188,7 +199,7 @@ if auditor is None: auditor = pathauditor(root) if name != rootsep and name.startswith(rootsep): - name = name[len(rootsep):] + name = name[len(rootsep) :] auditor(name) return util.pconvert(name) elif name == root: @@ -228,12 +239,14 @@ relpath = util.pathto(root, cwd, '') if relpath.endswith(pycompat.ossep): relpath = relpath[:-1] - hint = (_("consider using '--cwd %s'") % relpath) + hint = _("consider using '--cwd %s'") % relpath except error.Abort: pass - raise error.Abort(_("%s not under root '%s'") % (myname, root), - hint=hint) + raise error.Abort( + _("%s not under root '%s'") % (myname, root), hint=hint + ) + def normasprefix(path): '''normalize the specified path as path prefix @@ -257,6 +270,7 @@ else: return path + # forward two methods from posixpath that do what we need, but we'd # rather not let our internals know that we're thinking in posix terms # - instead we'll let them be oblivious.