Quantcast

[PATCH 1 of 4] match: make _fileroots a @propertycache and rename it to _fileset

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[PATCH 1 of 4] match: make _fileroots a @propertycache and rename it to _fileset

Martin von Zweigbergk via Mercurial-devel
# HG changeset patch
# User Martin von Zweigbergk <[hidden email]>
# Date 1495123477 25200
#      Thu May 18 09:04:37 2017 -0700
# Node ID 48275b23f01283fdf1ae6e630c2c63660528edfc
# Parent  0d6b3572ad924103128bb9cd296000fc6fd821ef
match: make _fileroots a @propertycache and rename it to _fileset

The files in the set are not necesserily roots of anything. Making it
a @propertycache will help towards extracting a base class for
matchers.

diff --git a/hgext/largefiles/overrides.py b/hgext/largefiles/overrides.py
--- a/hgext/largefiles/overrides.py
+++ b/hgext/largefiles/overrides.py
@@ -41,7 +41,7 @@
     m = copy.copy(match)
     lfile = lambda f: lfutil.standin(f) in manifest
     m._files = filter(lfile, m._files)
-    m._fileroots = set(m._files)
+    m._fileset = set(m._files)
     m._always = False
     origmatchfn = m.matchfn
     m.matchfn = lambda f: lfile(f) and origmatchfn(f)
@@ -56,7 +56,7 @@
     notlfile = lambda f: not (lfutil.isstandin(f) or lfutil.standin(f) in
             manifest or f in excluded)
     m._files = filter(notlfile, m._files)
-    m._fileroots = set(m._files)
+    m._fileset = set(m._files)
     m._always = False
     origmatchfn = m.matchfn
     m.matchfn = lambda f: notlfile(f) and origmatchfn(f)
@@ -368,7 +368,7 @@
             elif m._files[i] not in ctx and repo.wvfs.isdir(standin):
                 m._files.append(standin)
 
-        m._fileroots = set(m._files)
+        m._fileset = set(m._files)
         m._always = False
         origmatchfn = m.matchfn
         def lfmatchfn(f):
@@ -644,7 +644,7 @@
             m = copy.copy(match)
             lfile = lambda f: lfutil.standin(f) in manifest
             m._files = [lfutil.standin(f) for f in m._files if lfile(f)]
-            m._fileroots = set(m._files)
+            m._fileset = set(m._files)
             origmatchfn = m.matchfn
             def matchfn(f):
                 lfile = lfutil.splitstandin(f)
@@ -767,7 +767,7 @@
                 else:
                     matchfiles.append(f)
             m._files = matchfiles
-            m._fileroots = set(m._files)
+            m._fileset = set(m._files)
             origmatchfn = m.matchfn
             def matchfn(f):
                 lfile = lfutil.splitstandin(f)
diff --git a/mercurial/match.py b/mercurial/match.py
--- a/mercurial/match.py
+++ b/mercurial/match.py
@@ -188,7 +188,6 @@
                 return True
 
         self.matchfn = m
-        self._fileroots = set(self._files)
 
     def __call__(self, fn):
         return self.matchfn(fn)
@@ -235,8 +234,12 @@
         return self._files
 
     @propertycache
+    def _fileset(self):
+        return set(self._files)
+
+    @propertycache
     def _dirs(self):
-        return set(util.dirs(self._fileroots)) | {'.'}
+        return set(util.dirs(self._fileset)) | {'.'}
 
     def visitdir(self, dir):
         '''Decides whether a directory should be visited based on whether it
@@ -250,7 +253,7 @@
         This function's behavior is undefined if it has returned False for
         one of the dir's parent directories.
         '''
-        if self.prefix() and dir in self._fileroots:
+        if self.prefix() and dir in self._fileset:
             return 'all'
         if dir in self._excluderoots:
             return False
@@ -261,16 +264,16 @@
             not any(parent in self._includeroots
                     for parent in util.finddirs(dir))):
             return False
-        return (not self._fileroots or
-                '.' in self._fileroots or
-                dir in self._fileroots or
+        return (not self._fileset or
+                '.' in self._fileset or
+                dir in self._fileset or
                 dir in self._dirs or
-                any(parentdir in self._fileroots
+                any(parentdir in self._fileset
                     for parentdir in util.finddirs(dir)))
 
     def exact(self, f):
         '''Returns True if f is in .files().'''
-        return f in self._fileroots
+        return f in self._fileset
 
     def anypats(self):
         '''Matcher uses patterns or include/exclude.'''
@@ -399,7 +402,6 @@
                 return matcher.visitdir(self._path)
             return matcher.visitdir(self._path + "/" + dir)
         self.visitdir = visitdir
-        self._fileroots = set(self._files)
 
     def abs(self, f):
         return self._matcher.abs(self._path + "/" + f)
@@ -428,8 +430,8 @@
         # inexact case matches are treated as exact, and not noted without -v.
         if self._files:
             roots, dirs = _rootsanddirs(self._kp)
-            self._fileroots = set(roots)
-            self._fileroots.update(dirs)
+            self._fileset = set(roots)
+            self._fileset.update(dirs)
 
     def _normalize(self, patterns, default, root, cwd, auditor):
         self._kp = super(icasefsmatcher, self)._normalize(patterns, default,
_______________________________________________
Mercurial-devel mailing list
[hidden email]
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[PATCH 2 of 4] match: override visitdir() the usual way in subdirmatcher

Martin von Zweigbergk via Mercurial-devel
# HG changeset patch
# User Martin von Zweigbergk <[hidden email]>
# Date 1495127877 25200
#      Thu May 18 10:17:57 2017 -0700
# Node ID c387c5e78c2cbd703c791fc8b9515526d1ce6155
# Parent  48275b23f01283fdf1ae6e630c2c63660528edfc
match: override visitdir() the usual way in subdirmatcher

Just override the function instead of replacing it on each instance.

diff --git a/mercurial/match.py b/mercurial/match.py
--- a/mercurial/match.py
+++ b/mercurial/match.py
@@ -397,11 +397,6 @@
         # from the inputs. Instead, we override matchfn() and visitdir() to
         # call the original matcher with the subdirectory path prepended.
         self.matchfn = lambda fn: matcher.matchfn(self._path + "/" + fn)
-        def visitdir(dir):
-            if dir == '.':
-                return matcher.visitdir(self._path)
-            return matcher.visitdir(self._path + "/" + dir)
-        self.visitdir = visitdir
 
     def abs(self, f):
         return self._matcher.abs(self._path + "/" + f)
@@ -412,6 +407,13 @@
     def rel(self, f):
         return self._matcher.rel(self._path + "/" + f)
 
+    def visitdir(self, dir):
+        if dir == '.':
+            dir = self._path
+        else:
+            dir = self._path + "/" + dir
+        return self._matcher.visitdir(dir)
+
 class icasefsmatcher(match):
     """A matcher for wdir on case insensitive filesystems, which normalizes the
     given patterns to the case in the filesystem.
_______________________________________________
Mercurial-devel mailing list
[hidden email]
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[PATCH 3 of 4] match: avoid accessing match._pathrestricted from subdirmatcher

Martin von Zweigbergk via Mercurial-devel
In reply to this post by Martin von Zweigbergk via Mercurial-devel
# HG changeset patch
# User Martin von Zweigbergk <[hidden email]>
# Date 1494631881 25200
#      Fri May 12 16:31:21 2017 -0700
# Node ID 786822a7d1d8c5c90f393ea2d0fc06cdb0a96a00
# Parent  c387c5e78c2cbd703c791fc8b9515526d1ce6155
match: avoid accessing match._pathrestricted from subdirmatcher

Accessing only the public API wherever possible helps us refactor
matchers later.

diff --git a/mercurial/match.py b/mercurial/match.py
--- a/mercurial/match.py
+++ b/mercurial/match.py
@@ -381,7 +381,6 @@
         self._path = path
         self._matcher = matcher
         self._always = matcher._always
-        self._pathrestricted = matcher._pathrestricted
 
         self._files = [f[len(path) + 1:] for f in matcher._files
                        if f.startswith(path + "/")]
@@ -398,15 +397,18 @@
         # call the original matcher with the subdirectory path prepended.
         self.matchfn = lambda fn: matcher.matchfn(self._path + "/" + fn)
 
+    def bad(self, f, msg):
+        self._matcher.bad(self._path + "/" + f, msg)
+
     def abs(self, f):
         return self._matcher.abs(self._path + "/" + f)
 
-    def bad(self, f, msg):
-        self._matcher.bad(self._path + "/" + f, msg)
-
     def rel(self, f):
         return self._matcher.rel(self._path + "/" + f)
 
+    def uipath(self, f):
+        return self._matcher.uipath(self._path + "/" + f)
+
     def visitdir(self, dir):
         if dir == '.':
             dir = self._path
_______________________________________________
Mercurial-devel mailing list
[hidden email]
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[PATCH 4 of 4] match: use match.prefix() in subdirmatcher

Martin von Zweigbergk via Mercurial-devel
In reply to this post by Martin von Zweigbergk via Mercurial-devel
# HG changeset patch
# User Martin von Zweigbergk <[hidden email]>
# Date 1495085595 25200
#      Wed May 17 22:33:15 2017 -0700
# Node ID 995b116349ea7a11858ce81df36bfdb345a18f0d
# Parent  786822a7d1d8c5c90f393ea2d0fc06cdb0a96a00
match: use match.prefix() in subdirmatcher

It seems like the subdirmatcher should be checking if the matcher it's
based on is matching prefixes. It was effectively doing that already
because "prefix() == not always() and not anypats() and not
isexact()", subdirmatcher was checking the first two parts of that
condition and I don't think it will ever be given an "exact" matcher
with it's directory name (because exact matchers are for matching
files, not directories). Still, let's switch to using prefix() for
clarity (and because I'm trying to remove code that reaches for
matchers internals).

diff --git a/mercurial/match.py b/mercurial/match.py
--- a/mercurial/match.py
+++ b/mercurial/match.py
@@ -385,9 +385,9 @@
         self._files = [f[len(path) + 1:] for f in matcher._files
                        if f.startswith(path + "/")]
 
-        # If the parent repo had a path to this subrepo and no patterns are
-        # specified, this submatcher always matches.
-        if not self._always and not matcher._anypats:
+        # If the parent repo had a path to this subrepo and the matcher is
+        # a prefix matcher, this submatcher always matches.
+        if matcher.prefix():
             self._always = any(f == path for f in matcher._files)
 
         self._anypats = matcher._anypats
_______________________________________________
Mercurial-devel mailing list
[hidden email]
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [PATCH 1 of 4] match: make _fileroots a @propertycache and rename it to _fileset

Yuya Nishihara
In reply to this post by Martin von Zweigbergk via Mercurial-devel
On Thu, 18 May 2017 11:03:43 -0700, Martin von Zweigbergk via Mercurial-devel wrote:
> # HG changeset patch
> # User Martin von Zweigbergk <[hidden email]>
> # Date 1495123477 25200
> #      Thu May 18 09:04:37 2017 -0700
> # Node ID 48275b23f01283fdf1ae6e630c2c63660528edfc
> # Parent  0d6b3572ad924103128bb9cd296000fc6fd821ef
> match: make _fileroots a @propertycache and rename it to _fileset

Looks good overall. Queued, thanks.

> @@ -399,7 +402,6 @@
>                  return matcher.visitdir(self._path)
>              return matcher.visitdir(self._path + "/" + dir)
>          self.visitdir = visitdir
> -        self._fileroots = set(self._files)

This change should be fine as self._fileset is never be cached in __init__().
_______________________________________________
Mercurial-devel mailing list
[hidden email]
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [PATCH 1 of 4] match: make _fileroots a @propertycache and rename it to _fileset

Martin von Zweigbergk via Mercurial-devel
On Fri, May 19, 2017 at 7:32 AM, Yuya Nishihara <[hidden email]> wrote:

> On Thu, 18 May 2017 11:03:43 -0700, Martin von Zweigbergk via Mercurial-devel wrote:
>> # HG changeset patch
>> # User Martin von Zweigbergk <[hidden email]>
>> # Date 1495123477 25200
>> #      Thu May 18 09:04:37 2017 -0700
>> # Node ID 48275b23f01283fdf1ae6e630c2c63660528edfc
>> # Parent  0d6b3572ad924103128bb9cd296000fc6fd821ef
>> match: make _fileroots a @propertycache and rename it to _fileset
>
> Looks good overall. Queued, thanks.
>
>> @@ -399,7 +402,6 @@
>>                  return matcher.visitdir(self._path)
>>              return matcher.visitdir(self._path + "/" + dir)
>>          self.visitdir = visitdir
>> -        self._fileroots = set(self._files)
>
> This change should be fine as self._fileset is never be cached in __init__().

Even if it were, this would overwrite it (which is what this was meant
to do), no?

Anyway, I plan on dropping these few lines in a later patch, either
just sacrificing what the feature this code was for or rewriting it in
a better way (I'm not sure yet). I have another 20-30 matcher patches
coming up.
_______________________________________________
Mercurial-devel mailing list
[hidden email]
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [PATCH 1 of 4] match: make _fileroots a @propertycache and rename it to _fileset

Yuya Nishihara
On Fri, 19 May 2017 08:37:06 -0700, Martin von Zweigbergk wrote:

> On Fri, May 19, 2017 at 7:32 AM, Yuya Nishihara <[hidden email]> wrote:
> > On Thu, 18 May 2017 11:03:43 -0700, Martin von Zweigbergk via Mercurial-devel wrote:
> >> # HG changeset patch
> >> # User Martin von Zweigbergk <[hidden email]>
> >> # Date 1495123477 25200
> >> #      Thu May 18 09:04:37 2017 -0700
> >> # Node ID 48275b23f01283fdf1ae6e630c2c63660528edfc
> >> # Parent  0d6b3572ad924103128bb9cd296000fc6fd821ef
> >> match: make _fileroots a @propertycache and rename it to _fileset
> >
> > Looks good overall. Queued, thanks.
> >
> >> @@ -399,7 +402,6 @@
> >>                  return matcher.visitdir(self._path)
> >>              return matcher.visitdir(self._path + "/" + dir)
> >>          self.visitdir = visitdir
> >> -        self._fileroots = set(self._files)
> >
> > This change should be fine as self._fileset is never be cached in __init__().
>
> Even if it were, this would overwrite it (which is what this was meant
> to do), no?

Doh, I thought subdirmatcher would call match.__init__() before doing the
hack, (and if match.__init__() accessed to _fileset, set(_files) != _fileset.)
But I was wrong. :)
_______________________________________________
Mercurial-devel mailing list
[hidden email]
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [PATCH 1 of 4] match: make _fileroots a @propertycache and rename it to _fileset

Martin von Zweigbergk via Mercurial-devel
On Fri, May 19, 2017 at 9:07 AM, Yuya Nishihara <[hidden email]> wrote:

> On Fri, 19 May 2017 08:37:06 -0700, Martin von Zweigbergk wrote:
>> On Fri, May 19, 2017 at 7:32 AM, Yuya Nishihara <[hidden email]> wrote:
>> > On Thu, 18 May 2017 11:03:43 -0700, Martin von Zweigbergk via Mercurial-devel wrote:
>> >> # HG changeset patch
>> >> # User Martin von Zweigbergk <[hidden email]>
>> >> # Date 1495123477 25200
>> >> #      Thu May 18 09:04:37 2017 -0700
>> >> # Node ID 48275b23f01283fdf1ae6e630c2c63660528edfc
>> >> # Parent  0d6b3572ad924103128bb9cd296000fc6fd821ef
>> >> match: make _fileroots a @propertycache and rename it to _fileset
>> >
>> > Looks good overall. Queued, thanks.
>> >
>> >> @@ -399,7 +402,6 @@
>> >>                  return matcher.visitdir(self._path)
>> >>              return matcher.visitdir(self._path + "/" + dir)
>> >>          self.visitdir = visitdir
>> >> -        self._fileroots = set(self._files)
>> >
>> > This change should be fine as self._fileset is never be cached in __init__().
>>
>> Even if it were, this would overwrite it (which is what this was meant
>> to do), no?
>
> Doh, I thought subdirmatcher would call match.__init__() before doing the

It will eventually call into its base class's __init__() once I'm done
(although that will be a "basematcher" class, not the "match class
itself)).

> hack, (and if match.__init__() accessed to _fileset, set(_files) != _fileset.)
> But I was wrong. :)

There's a first time for everything :-) (I say that with admiration,
no sarcasm.)
_______________________________________________
Mercurial-devel mailing list
[hidden email]
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
Loading...