diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py --- a/mercurial/cmdutil.py +++ b/mercurial/cmdutil.py @@ -2415,11 +2415,7 @@ def files(ui, ctx, m, fm, fmt, subrepos) 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 @@ def remove(ui, repo, m, prefix, after, f 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 --git a/mercurial/match.py b/mercurial/match.py --- a/mercurial/match.py +++ b/mercurial/match.py @@ -320,6 +320,10 @@ class match(object): 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 --git a/mercurial/scmutil.py b/mercurial/scmutil.py --- a/mercurial/scmutil.py +++ b/mercurial/scmutil.py @@ -948,17 +948,9 @@ def addremove(repo, matcher, prefix, opt 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)