Patchwork matcher: make e.g. 'relpath:.' lead to fast paths

login
register
mail settings
Submitter Martin von Zweigbergk
Date March 25, 2015, 6:10 p.m.
Message ID <ceb8a0ada1179719f2d2.1427307021@martinvonz.mtv.corp.google.com>
Download mbox | patch
Permalink /patch/8264/
State Accepted
Commit d44d53bc9a1ea53709c7d8685a08e323ab4724e0
Headers show

Comments

Martin von Zweigbergk - March 25, 2015, 6:10 p.m.
# HG changeset patch
# User Martin von Zweigbergk <martinvonz@google.com>
# Date 1416441418 28800
#      Wed Nov 19 15:56:58 2014 -0800
# Node ID ceb8a0ada1179719f2d28ddb09a669d81d7227d2
# Parent  a0cb16381f4d89940520187e14baaec5e92455e3
matcher: make e.g. 'relpath:.' lead to fast paths

Several commands take the fast path when match.always() is
true. However, when the user passes "." on the command line, that
results in a matcher for which match.always() == False. Let's make it
so such matchers return True, and have an empty list of .files(). This
makes e.g. "hg log ." as fast as "hg log" and "hg revert ." as fast as
"hg revert --all" (when run from repo root).
Matt Mackall - March 25, 2015, 11:01 p.m.
On Wed, 2015-03-25 at 11:10 -0700, Martin von Zweigbergk wrote:
> # HG changeset patch
> # User Martin von Zweigbergk <martinvonz@google.com>
> # Date 1416441418 28800
> #      Wed Nov 19 15:56:58 2014 -0800
> # Node ID ceb8a0ada1179719f2d28ddb09a669d81d7227d2
> # Parent  a0cb16381f4d89940520187e14baaec5e92455e3
> matcher: make e.g. 'relpath:.' lead to fast paths

Queued for default, thanks.

Patch

diff -r a0cb16381f4d -r ceb8a0ada117 mercurial/match.py
--- a/mercurial/match.py	Sat Jan 17 12:39:44 2015 +0900
+++ b/mercurial/match.py	Wed Nov 19 15:56:58 2014 -0800
@@ -34,6 +34,15 @@ 
         other.append((kind, pat))
     return fset, other
 
+def _kindpatsalwaysmatch(kindpats):
+    """"Checks whether the kindspats match everything, as e.g.
+    'relpath:.' does.
+    """
+    for kind, pat in kindpats:
+        if pat != '' or kind not in ['relpath', 'glob']:
+            return False
+    return True
+
 class match(object):
     def __init__(self, root, cwd, patterns, include=[], exclude=[],
                  default='glob', exact=False, auditor=None, ctx=None):
@@ -83,10 +92,11 @@ 
             matchfns.append(self.exact)
         elif patterns:
             kindpats = _normalize(patterns, default, root, cwd, auditor)
-            self._files = _roots(kindpats)
-            self._anypats = self._anypats or _anypats(kindpats)
-            self.patternspat, pm = _buildmatch(ctx, kindpats, '$')
-            matchfns.append(pm)
+            if not _kindpatsalwaysmatch(kindpats):
+                self._files = _roots(kindpats)
+                self._anypats = self._anypats or _anypats(kindpats)
+                self.patternspat, pm = _buildmatch(ctx, kindpats, '$')
+                matchfns.append(pm)
 
         if not matchfns:
             m = util.always
diff -r a0cb16381f4d -r ceb8a0ada117 mercurial/scmutil.py
--- a/mercurial/scmutil.py	Sat Jan 17 12:39:44 2015 +0900
+++ b/mercurial/scmutil.py	Wed Nov 19 15:56:58 2014 -0800
@@ -725,6 +725,8 @@ 
     def badfn(f, msg):
         ctx.repo().ui.warn("%s: %s\n" % (m.rel(f), msg))
     m.bad = badfn
+    if m.always():
+        pats = []
     return m, pats
 
 def match(ctx, pats=[], opts={}, globbed=False, default='relpath'):