Patchwork match: added matchessubrepo method to matcher

login
register
mail settings
Submitter Hannes Oldenburg
Date Aug. 9, 2016, 9:51 a.m.
Message ID <83d4910236336c3a72cf.1470736317@localhost.localdomain>
Download mbox | patch
Permalink /patch/16228/
State Accepted
Headers show

Comments

Hannes Oldenburg - Aug. 9, 2016, 9:51 a.m.
# HG changeset patch
# User Hannes Oldenburg <hannes.christian.oldenburg@gmail.com>
# Date 1470733371 0
#      Tue Aug 09 09:02:51 2016 +0000
# Node ID 83d4910236336c3a72cff356f9f002d0e0710efc
# Parent  12c72545f8627845c56b070a27eff88adefd7c16
match: added matchessubrepo method to matcher

Previously there were three local implementations of this
function in cmdutil.files, cmdutil.remove and scmutil.addremove.
Pierre-Yves David - Aug. 10, 2016, 2:24 a.m.
On 08/09/2016 11:51 AM, Hannes Oldenburg wrote:
> # HG changeset patch
> # User Hannes Oldenburg <hannes.christian.oldenburg@gmail.com>
> # Date 1470733371 0
> #      Tue Aug 09 09:02:51 2016 +0000
> # Node ID 83d4910236336c3a72cff356f9f002d0e0710efc
> # Parent  12c72545f8627845c56b070a27eff88adefd7c16
> match: added matchessubrepo method to matcher

Patch looks good to me and tests are happy. Pushed, thanks.
Yuya Nishihara - Aug. 10, 2016, 12:40 p.m.
On Tue, 09 Aug 2016 09:51:57 +0000, Hannes Oldenburg wrote:
> # HG changeset patch
> # User Hannes Oldenburg <hannes.christian.oldenburg@gmail.com>
> # Date 1470733371 0
> #      Tue Aug 09 09:02:51 2016 +0000
> # Node ID 83d4910236336c3a72cff356f9f002d0e0710efc
> # Parent  12c72545f8627845c56b070a27eff88adefd7c16
> match: added matchessubrepo method to matcher

> +++ b/mercurial/match.py	Tue Aug 09 09:02:51 2016 +0000
> @@ -320,6 +320,10 @@
>              kindpats.append((kind, pat, ''))
>          return kindpats
>  
> +    def matchessubrepo(self, subpath):
> +        return (self.exact(subpath)
> +                or any(f.startswith(subpath + '/') for f in self.files()))

This function isn't restricted to subrepos. Maybe it could be called by
more generic name such as m.anysubtreeof(f).
Pierre-Yves David - Aug. 10, 2016, 12:52 p.m.
On 08/10/2016 02:40 PM, Yuya Nishihara wrote:
> On Tue, 09 Aug 2016 09:51:57 +0000, Hannes Oldenburg wrote:
>> # HG changeset patch
>> # User Hannes Oldenburg <hannes.christian.oldenburg@gmail.com>
>> # Date 1470733371 0
>> #      Tue Aug 09 09:02:51 2016 +0000
>> # Node ID 83d4910236336c3a72cff356f9f002d0e0710efc
>> # Parent  12c72545f8627845c56b070a27eff88adefd7c16
>> match: added matchessubrepo method to matcher
>
>> +++ b/mercurial/match.py	Tue Aug 09 09:02:51 2016 +0000
>> @@ -320,6 +320,10 @@
>>              kindpats.append((kind, pat, ''))
>>          return kindpats
>>
>> +    def matchessubrepo(self, subpath):
>> +        return (self.exact(subpath)
>> +                or any(f.startswith(subpath + '/') for f in self.files()))
>
> This function isn't restricted to subrepos. Maybe it could be called by
> more generic name such as m.anysubtreeof(f).

matchessubpath ?
Hannes Oldenburg - Aug. 13, 2016, 1:27 a.m.
Should i send a new patch that renames the method to matchessubpath or a
new version of the patch?

On Wed, Aug 10, 2016 at 12:52 PM, Pierre-Yves David <
pierre-yves.david@ens-lyon.org> wrote:

>
>
> On 08/10/2016 02:40 PM, Yuya Nishihara wrote:
>
>> On Tue, 09 Aug 2016 09:51:57 +0000, Hannes Oldenburg wrote:
>>
>>> # HG changeset patch
>>> # User Hannes Oldenburg <hannes.christian.oldenburg@gmail.com>
>>> # Date 1470733371 0
>>> #      Tue Aug 09 09:02:51 2016 +0000
>>> # Node ID 83d4910236336c3a72cff356f9f002d0e0710efc
>>> # Parent  12c72545f8627845c56b070a27eff88adefd7c16
>>> match: added matchessubrepo method to matcher
>>>
>>
>> +++ b/mercurial/match.py        Tue Aug 09 09:02:51 2016 +0000
>>> @@ -320,6 +320,10 @@
>>>              kindpats.append((kind, pat, ''))
>>>          return kindpats
>>>
>>> +    def matchessubrepo(self, subpath):
>>> +        return (self.exact(subpath)
>>> +                or any(f.startswith(subpath + '/') for f in
>>> self.files()))
>>>
>>
>> This function isn't restricted to subrepos. Maybe it could be called by
>> more generic name such as m.anysubtreeof(f).
>>
>
> matchessubpath ?
>
> --
> Pierre-Yves David
>
Yuya Nishihara - Aug. 13, 2016, 1:33 p.m.
On Sat, 13 Aug 2016 01:27:48 +0000, Hannes Oldenburg wrote:
> Should i send a new patch that renames the method to matchessubpath or a
> new version of the patch?

New patch to rename, please. But I'm not sure if subpath is better. "subpath"
out of subrepo context sounds like lower component of a path, e.g.

  dir, subpath = path.split('/', 1)

but "subpath" as subrepo's path is upper component.

Patch

diff -r 12c72545f862 -r 83d491023633 mercurial/cmdutil.py
--- a/mercurial/cmdutil.py	Sun Aug 07 14:06:20 2016 +0000
+++ b/mercurial/cmdutil.py	Tue Aug 09 09:02:51 2016 +0000
@@ -2415,11 +2415,7 @@ 
         ret = 0
 
     for subpath in sorted(ctx.substate):
-        def matchessubrepo(subpath):
-            return (m.exact(subpath)
-                    or any(f.startswith(subpath + '/') for f in m.files()))
-
-        if subrepos or matchessubrepo(subpath):
+        if subrepos or m.matchessubrepo(subpath):
             sub = ctx.sub(subpath)
             try:
                 submatch = matchmod.subdirmatcher(subpath, m)
@@ -2450,16 +2446,8 @@ 
     total = len(subs)
     count = 0
     for subpath in subs:
-        def matchessubrepo(matcher, subpath):
-            if matcher.exact(subpath):
-                return True
-            for f in matcher.files():
-                if f.startswith(subpath):
-                    return True
-            return False
-
         count += 1
-        if subrepos or matchessubrepo(m, subpath):
+        if subrepos or m.matchessubrepo(subpath):
             ui.progress(_('searching'), count, total=total, unit=_('subrepos'))
 
             sub = wctx.sub(subpath)
diff -r 12c72545f862 -r 83d491023633 mercurial/match.py
--- a/mercurial/match.py	Sun Aug 07 14:06:20 2016 +0000
+++ b/mercurial/match.py	Tue Aug 09 09:02:51 2016 +0000
@@ -320,6 +320,10 @@ 
             kindpats.append((kind, pat, ''))
         return kindpats
 
+    def matchessubrepo(self, subpath):
+        return (self.exact(subpath)
+                or any(f.startswith(subpath + '/') for f in self.files()))
+
 def exact(root, cwd, files, badfn=None):
     return match(root, cwd, files, exact=True, badfn=badfn)
 
diff -r 12c72545f862 -r 83d491023633 mercurial/scmutil.py
--- a/mercurial/scmutil.py	Sun Aug 07 14:06:20 2016 +0000
+++ b/mercurial/scmutil.py	Tue Aug 09 09:02:51 2016 +0000
@@ -950,17 +950,9 @@ 
     ret = 0
     join = lambda f: os.path.join(prefix, f)
 
-    def matchessubrepo(matcher, subpath):
-        if matcher.exact(subpath):
-            return True
-        for f in matcher.files():
-            if f.startswith(subpath):
-                return True
-        return False
-
     wctx = repo[None]
     for subpath in sorted(wctx.substate):
-        if opts.get('subrepos') or matchessubrepo(m, subpath):
+        if opts.get('subrepos') or m.matchessubrepo(subpath):
             sub = wctx.sub(subpath)
             try:
                 submatch = matchmod.subdirmatcher(subpath, m)