Patchwork [4,of,4] match: use match.prefix() in subdirmatcher

login
register
mail settings
Submitter via Mercurial-devel
Date May 18, 2017, 6:03 p.m.
Message ID <995b116349ea7a11858c.1495130626@martinvonz.svl.corp.google.com>
Download mbox | patch
Permalink /patch/20684/
State Accepted
Headers show

Comments

via Mercurial-devel - May 18, 2017, 6:03 p.m.
# HG changeset patch
# User Martin von Zweigbergk <martinvonz@google.com>
# Date 1495085595 25200
#      Wed May 17 22:33:15 2017 -0700
# Node ID 995b116349ea7a11858ce81df36bfdb345a18f0d
# Parent  786822a7d1d8c5c90f393ea2d0fc06cdb0a96a00
match: use match.prefix() in subdirmatcher

It seems like the subdirmatcher should be checking if the matcher it's
based on is matching prefixes. It was effectively doing that already
because "prefix() == not always() and not anypats() and not
isexact()", subdirmatcher was checking the first two parts of that
condition and I don't think it will ever be given an "exact" matcher
with it's directory name (because exact matchers are for matching
files, not directories). Still, let's switch to using prefix() for
clarity (and because I'm trying to remove code that reaches for
matchers internals).

Patch

diff --git a/mercurial/match.py b/mercurial/match.py
--- a/mercurial/match.py
+++ b/mercurial/match.py
@@ -385,9 +385,9 @@ 
         self._files = [f[len(path) + 1:] for f in matcher._files
                        if f.startswith(path + "/")]
 
-        # If the parent repo had a path to this subrepo and no patterns are
-        # specified, this submatcher always matches.
-        if not self._always and not matcher._anypats:
+        # If the parent repo had a path to this subrepo and the matcher is
+        # a prefix matcher, this submatcher always matches.
+        if matcher.prefix():
             self._always = any(f == path for f in matcher._files)
 
         self._anypats = matcher._anypats