match: move entire uipath() implementation to basematcher
Even though most matchers will always want to use the relative path in
uipath(), when we add support for intersecting matcher, we will want
to control which form to use for any kind of matcher without knowing
the type (see next patch), so we need the implementation on the base
class.
Also rename the attribute from "pathrestricted" to "relativeuipath"
since there actually are cases where we match everything but still use
relative paths (like when the user runs "hg files .." from inside
mercurial/).
--- a/mercurial/match.py Thu May 25 12:09:09 2017 +0200
+++ b/mercurial/match.py Thu May 25 14:32:56 2017 -0700
@@ -209,11 +209,12 @@
class basematcher(object):
- def __init__(self, root, cwd, badfn=None):
+ def __init__(self, root, cwd, badfn=None, relativeuipath=True):
self._root = root
self._cwd = cwd
if badfn is not None:
self.bad = badfn
+ self._relativeuipath = relativeuipath
def __call__(self, fn):
return self.matchfn(fn)
@@ -248,7 +249,7 @@
'''Convert repo path to a display path. If patterns or -I/-X were used
to create this matcher, the display path will be relative to cwd.
Otherwise it is relative to the root of the repo.'''
- return self.rel(f)
+ return (self._relativeuipath and self.rel(f)) or self.abs(f)
@propertycache
def _files(self):
@@ -307,14 +308,14 @@
def __init__(self, root, cwd, normalize, patterns, include=None,
default='glob', exact=False, auditor=None, ctx=None,
listsubrepos=False, warn=None, badfn=None):
- super(matcher, self).__init__(root, cwd, badfn)
+ super(matcher, self).__init__(root, cwd, badfn,
+ relativeuipath=bool(include or patterns))
if include is None:
include = []
self._anypats = bool(include)
self._anyincludepats = False
self._always = False
- self._pathrestricted = bool(include or patterns)
self.patternspat = None
self.includepat = None
@@ -362,9 +363,6 @@
self.matchfn = m
- def uipath(self, f):
- return (self._pathrestricted and self.rel(f)) or self.abs(f)
-
@propertycache
def _dirs(self):
return set(util.dirs(self._fileset)) | {'.'}