Patchwork [3,of,3] match: also optimize "path:." to use alwaysmatcher

login
register
mail settings
Submitter via Mercurial-devel
Date July 10, 2017, 6:44 a.m.
Message ID <42df87114da18c9fcd52.1499669083@martinvonz.svl.corp.google.com>
Download mbox | patch
Permalink /patch/22199/
State Accepted
Headers show

Comments

via Mercurial-devel - July 10, 2017, 6:44 a.m.
# HG changeset patch
# User Martin von Zweigbergk <martinvonz@google.com>
# Date 1499667389 25200
#      Sun Jul 09 23:16:29 2017 -0700
# Node ID 42df87114da18c9fcd52bcee2f7ab42e3ce76f63
# Parent  3d7c440a43018d9a4b8c181131de86b57c50d2ce
match: also optimize "path:." to use alwaysmatcher

The default pattern type from the command line is "relpath:". It's
probably rare, but if the user explicitly types "path:." instead of
just "." (or "relpath:."), let's allow for the same fast paths (which
is the main benefit of using an alwaysmatcher).
Yuya Nishihara - July 10, 2017, 2:13 p.m.
On Sun, 09 Jul 2017 23:44:43 -0700, Martin von Zweigbergk via Mercurial-devel wrote:
> # HG changeset patch
> # User Martin von Zweigbergk <martinvonz@google.com>
> # Date 1499667389 25200
> #      Sun Jul 09 23:16:29 2017 -0700
> # Node ID 42df87114da18c9fcd52bcee2f7ab42e3ce76f63
> # Parent  3d7c440a43018d9a4b8c181131de86b57c50d2ce
> match: also optimize "path:." to use alwaysmatcher
> 
> The default pattern type from the command line is "relpath:". It's
> probably rare, but if the user explicitly types "path:." instead of
> just "." (or "relpath:."), let's allow for the same fast paths (which
> is the main benefit of using an alwaysmatcher).
> 
> diff --git a/mercurial/match.py b/mercurial/match.py
> --- a/mercurial/match.py
> +++ b/mercurial/match.py
> @@ -81,7 +81,7 @@
>      'relpath:.' does.
>      """
>      for kind, pat, source in kindpats:
> -        if pat != '' or kind not in ['relpath', 'glob']:
> +        if pat != '' or kind not in ['path', 'relpath', 'glob']:
>              return False
>      return True

As you said, 'path:' is normalized to pat='.', and pat isn't yet compiled
into an empty regexp pattern.
via Mercurial-devel - July 10, 2017, 4:03 p.m.
On Mon, Jul 10, 2017 at 7:13 AM, Yuya Nishihara <yuya@tcha.org> wrote:
> On Sun, 09 Jul 2017 23:44:43 -0700, Martin von Zweigbergk via Mercurial-devel wrote:
>> # HG changeset patch
>> # User Martin von Zweigbergk <martinvonz@google.com>
>> # Date 1499667389 25200
>> #      Sun Jul 09 23:16:29 2017 -0700
>> # Node ID 42df87114da18c9fcd52bcee2f7ab42e3ce76f63
>> # Parent  3d7c440a43018d9a4b8c181131de86b57c50d2ce
>> match: also optimize "path:." to use alwaysmatcher
>>
>> The default pattern type from the command line is "relpath:". It's
>> probably rare, but if the user explicitly types "path:." instead of
>> just "." (or "relpath:."), let's allow for the same fast paths (which
>> is the main benefit of using an alwaysmatcher).
>>
>> diff --git a/mercurial/match.py b/mercurial/match.py
>> --- a/mercurial/match.py
>> +++ b/mercurial/match.py
>> @@ -81,7 +81,7 @@
>>      'relpath:.' does.
>>      """
>>      for kind, pat, source in kindpats:
>> -        if pat != '' or kind not in ['relpath', 'glob']:
>> +        if pat != '' or kind not in ['path', 'relpath', 'glob']:
>>              return False
>>      return True
>
> As you said, 'path:' is normalized to pat='.', and pat isn't yet compiled
> into an empty regexp pattern.

Heh, good point. I should perhaps clean up the patches I have for
making it so we always use empty string for the root dir (except for
CLI, of course).

Patch

diff --git a/mercurial/match.py b/mercurial/match.py
--- a/mercurial/match.py
+++ b/mercurial/match.py
@@ -81,7 +81,7 @@ 
     'relpath:.' does.
     """
     for kind, pat, source in kindpats:
-        if pat != '' or kind not in ['relpath', 'glob']:
+        if pat != '' or kind not in ['path', 'relpath', 'glob']:
             return False
     return True