Patchwork [1,of,9] match: move entire uipath() implementation to basematcher

login
register
mail settings
Submitter via Mercurial-devel
Date May 26, 2017, 11:32 p.m.
Message ID <166063322d9e2171297a.1495841567@martinvonz.svl.corp.google.com>
Download mbox | patch
Permalink /patch/20940/
State Accepted
Headers show

Comments

via Mercurial-devel - May 26, 2017, 11:32 p.m.
# HG changeset patch
# User Martin von Zweigbergk <martinvonz@google.com>
# Date 1495747976 25200
#      Thu May 25 14:32:56 2017 -0700
# Node ID 166063322d9e2171297a11862e5a7922bca2b1e1
# Parent  12e241b2713ce44897c0bd19e8e16163b1b5d6e7
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/).
Yuya Nishihara - May 28, 2017, 2:47 p.m.
On Fri, 26 May 2017 16:32:47 -0700, Martin von Zweigbergk via Mercurial-devel wrote:
> # HG changeset patch
> # User Martin von Zweigbergk <martinvonz@google.com>
> # Date 1495747976 25200
> #      Thu May 25 14:32:56 2017 -0700
> # Node ID 166063322d9e2171297a11862e5a7922bca2b1e1
> # Parent  12e241b2713ce44897c0bd19e8e16163b1b5d6e7
> match: move entire uipath() implementation to basematcher

These look straightforward. Queued, thanks.

Patch

diff --git a/mercurial/match.py b/mercurial/match.py
--- a/mercurial/match.py
+++ b/mercurial/match.py
@@ -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)) | {'.'}