Patchwork match: more accurately report when we're always going to match

login
register
mail settings
Submitter Bryan O'Sullivan
Date Feb. 20, 2013, 8:39 p.m.
Message ID <7c4e5ad8fa43d211c2d0.1361392778@australite.thefacebook.com>
Download mbox | patch
Permalink /patch/1038/
State Accepted
Commit 8728579f6bdc794723dd452c704b96012c7fec20
Headers show

Comments

Bryan O'Sullivan - Feb. 20, 2013, 8:39 p.m.
# HG changeset patch
# User Bryan O'Sullivan <bryano@fb.com>
# Date 1361392772 28800
# Node ID 7c4e5ad8fa43d211c2d068f981b91acf350be3df
# Parent  67ee5291969274900517384d864da73c7928552e
match: more accurately report when we're always going to match

This improves the performance of log --patch and --stat by about
20% for moderately large manifests (e.g. mozilla-central) for the
common case of no -I/-X patterns.
Augie Fackler - Feb. 21, 2013, 3:44 p.m.
LGTM

On Wed, Feb 20, 2013 at 3:39 PM, Bryan O'Sullivan <bos@serpentine.com> wrote:
> # HG changeset patch
> # User Bryan O'Sullivan <bryano@fb.com>
> # Date 1361392772 28800
> # Node ID 7c4e5ad8fa43d211c2d068f981b91acf350be3df
> # Parent  67ee5291969274900517384d864da73c7928552e
> match: more accurately report when we're always going to match
>
> This improves the performance of log --patch and --stat by about
> 20% for moderately large manifests (e.g. mozilla-central) for the
> common case of no -I/-X patterns.
>
> diff --git a/mercurial/match.py b/mercurial/match.py
> --- a/mercurial/match.py
> +++ b/mercurial/match.py
> @@ -62,6 +62,7 @@ class match(object):
>          self._files = []
>          self._anypats = bool(include or exclude)
>          self._ctx = ctx
> +        self._always = False
>
>          if include:
>              pats = _normalize(include, 'glob', root, cwd, auditor)
> @@ -103,6 +104,7 @@ class match(object):
>                      m = lambda f: not em(f)
>                  else:
>                      m = lambda f: True
> +                    self._always = True
>
>          self.matchfn = m
>          self._fmap = set(self._files)
> @@ -130,7 +132,7 @@ class match(object):
>      def anypats(self):
>          return self._anypats
>      def always(self):
> -        return False
> +        return self._always
>
>  class exact(match):
>      def __init__(self, root, cwd, files):
> @@ -139,8 +141,7 @@ class exact(match):
>  class always(match):
>      def __init__(self, root, cwd):
>          match.__init__(self, root, cwd, [])
> -    def always(self):
> -        return True
> +        self._always = True
>
>  class narrowmatcher(match):
>      """Adapt a matcher to work on a subdirectory only.
> @@ -175,6 +176,7 @@ class narrowmatcher(match):
>          self._cwd = matcher._cwd
>          self._path = path
>          self._matcher = matcher
> +        self._always = matcher._always
>
>          self._files = [f[len(path) + 1:] for f in matcher._files
>                         if f.startswith(path + "/")]
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel

Patch

diff --git a/mercurial/match.py b/mercurial/match.py
--- a/mercurial/match.py
+++ b/mercurial/match.py
@@ -62,6 +62,7 @@  class match(object):
         self._files = []
         self._anypats = bool(include or exclude)
         self._ctx = ctx
+        self._always = False
 
         if include:
             pats = _normalize(include, 'glob', root, cwd, auditor)
@@ -103,6 +104,7 @@  class match(object):
                     m = lambda f: not em(f)
                 else:
                     m = lambda f: True
+                    self._always = True
 
         self.matchfn = m
         self._fmap = set(self._files)
@@ -130,7 +132,7 @@  class match(object):
     def anypats(self):
         return self._anypats
     def always(self):
-        return False
+        return self._always
 
 class exact(match):
     def __init__(self, root, cwd, files):
@@ -139,8 +141,7 @@  class exact(match):
 class always(match):
     def __init__(self, root, cwd):
         match.__init__(self, root, cwd, [])
-    def always(self):
-        return True
+        self._always = True
 
 class narrowmatcher(match):
     """Adapt a matcher to work on a subdirectory only.
@@ -175,6 +176,7 @@  class narrowmatcher(match):
         self._cwd = matcher._cwd
         self._path = path
         self._matcher = matcher
+        self._always = matcher._always
 
         self._files = [f[len(path) + 1:] for f in matcher._files
                        if f.startswith(path + "/")]