changeset 41687:0531dff73d0b

match: delete unused root and cwd arguments from {always,never,exact}() (API) Differential Revision: https://phab.mercurial-scm.org/D5930
author Martin von Zweigbergk <martinvonz@google.com>
date Sat, 09 Feb 2019 22:50:53 -0800
parents ddbebce94665
children bfc49f1df615
files hgext/fsmonitor/__init__.py hgext/gpg.py hgext/largefiles/lfutil.py hgext/largefiles/overrides.py hgext/largefiles/reposetup.py hgext/remotefilelog/remotefilelogserver.py hgext/remotefilelog/shallowbundle.py hgext/remotefilelog/shallowrepo.py hgext/sparse.py hgext/transplant.py mercurial/changegroup.py mercurial/dirstate.py mercurial/fileset.py mercurial/hgweb/webutil.py mercurial/localrepo.py mercurial/match.py mercurial/narrowspec.py mercurial/revset.py mercurial/scmutil.py mercurial/sparse.py mercurial/subrepo.py mercurial/tags.py tests/test-manifest.py tests/test-match.py
diffstat 24 files changed, 54 insertions(+), 61 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/fsmonitor/__init__.py	Sun Feb 10 14:35:36 2019 -0800
+++ b/hgext/fsmonitor/__init__.py	Sat Feb 09 22:50:53 2019 -0800
@@ -476,7 +476,7 @@
 
     working = ctx2.rev() is None
     parentworking = working and ctx1 == self['.']
-    match = match or matchmod.always(self.root, self.getcwd())
+    match = match or matchmod.always()
 
     # Maybe we can use this opportunity to update Watchman's state.
     # Mercurial uses workingcommitctx and/or memctx to represent the part of
--- a/hgext/gpg.py	Sun Feb 10 14:35:36 2019 -0800
+++ b/hgext/gpg.py	Sat Feb 09 22:50:53 2019 -0800
@@ -297,7 +297,7 @@
         return
 
     if not opts["force"]:
-        msigs = match.exact(repo.root, '', ['.hgsigs'])
+        msigs = match.exact(['.hgsigs'])
         if any(repo.status(match=msigs, unknown=True, ignored=True)):
             raise error.Abort(_("working copy of .hgsigs is changed "),
                              hint=_("please commit .hgsigs manually"))
--- a/hgext/largefiles/lfutil.py	Sun Feb 10 14:35:36 2019 -0800
+++ b/hgext/largefiles/lfutil.py	Sat Feb 09 22:50:53 2019 -0800
@@ -168,7 +168,7 @@
 
 def lfdirstatestatus(lfdirstate, repo):
     pctx = repo['.']
-    match = matchmod.always(repo.root, repo.getcwd())
+    match = matchmod.always()
     unsure, s = lfdirstate.status(match, subrepos=[], ignored=False,
                                   clean=False, unknown=False)
     modified, clean = s.modified, s.clean
@@ -552,7 +552,7 @@
         # otherwise to update all standins if the largefiles are
         # large.
         lfdirstate = openlfdirstate(ui, repo)
-        dirtymatch = matchmod.always(repo.root, repo.getcwd())
+        dirtymatch = matchmod.always()
         unsure, s = lfdirstate.status(dirtymatch, subrepos=[], ignored=False,
                                       clean=False, unknown=False)
         modifiedfiles = unsure + s.modified + s.added + s.removed
--- a/hgext/largefiles/overrides.py	Sun Feb 10 14:35:36 2019 -0800
+++ b/hgext/largefiles/overrides.py	Sat Feb 09 22:50:53 2019 -0800
@@ -1222,9 +1222,8 @@
         return orig(repo, matcher, prefix, uipathfn, opts)
     # Get the list of missing largefiles so we can remove them
     lfdirstate = lfutil.openlfdirstate(repo.ui, repo)
-    unsure, s = lfdirstate.status(matchmod.always(repo.root, repo.getcwd()),
-                                  subrepos=[], ignored=False, clean=False,
-                                  unknown=False)
+    unsure, s = lfdirstate.status(matchmod.always(), subrepos=[],
+                                  ignored=False, clean=False, unknown=False)
 
     # Call into the normal remove code, but the removing of the standin, we want
     # to have handled by original addremove.  Monkey patching here makes sure
@@ -1414,10 +1413,8 @@
         # (*1) deprecated, but used internally (e.g: "rebase --collapse")
 
         lfdirstate = lfutil.openlfdirstate(repo.ui, repo)
-        unsure, s = lfdirstate.status(matchmod.always(repo.root,
-                                                    repo.getcwd()),
-                                      subrepos=[], ignored=False,
-                                      clean=True, unknown=False)
+        unsure, s = lfdirstate.status(matchmod.always(), subrepos=[],
+                                      ignored=False, clean=True, unknown=False)
         oldclean = set(s.clean)
         pctx = repo['.']
         dctx = repo[node]
--- a/hgext/largefiles/reposetup.py	Sun Feb 10 14:35:36 2019 -0800
+++ b/hgext/largefiles/reposetup.py	Sat Feb 09 22:50:53 2019 -0800
@@ -103,7 +103,7 @@
             parentworking = working and ctx1 == self['.']
 
             if match is None:
-                match = matchmod.always(self.root, self.getcwd())
+                match = matchmod.always()
 
             wlock = None
             try:
--- a/hgext/remotefilelog/remotefilelogserver.py	Sun Feb 10 14:35:36 2019 -0800
+++ b/hgext/remotefilelog/remotefilelogserver.py	Sat Feb 09 22:50:53 2019 -0800
@@ -54,7 +54,7 @@
                 elif cap.startswith("excludepattern="):
                     excludepattern = cap[len("excludepattern="):].split('\0')
 
-            m = match.always(repo.root, '')
+            m = match.always()
             if includepattern or excludepattern:
                 m = match.match(repo.root, '', None,
                     includepattern, excludepattern)
@@ -104,7 +104,7 @@
         oldnoflatmf = state.noflatmf
         try:
             state.shallowremote = True
-            state.match = match.always(repo.root, '')
+            state.match = match.always()
             state.noflatmf = other.get('noflatmanifest') == 'True'
             if includepattern or excludepattern:
                 state.match = match.match(repo.root, '', None,
--- a/hgext/remotefilelog/shallowbundle.py	Sun Feb 10 14:35:36 2019 -0800
+++ b/hgext/remotefilelog/shallowbundle.py	Sat Feb 09 22:50:53 2019 -0800
@@ -162,7 +162,7 @@
                 repo.shallowmatch = match.match(repo.root, '', None,
                     includepattern, excludepattern)
             else:
-                repo.shallowmatch = match.always(repo.root, '')
+                repo.shallowmatch = match.always()
         return orig(repo, outgoing, version, source, *args, **kwargs)
     finally:
         repo.shallowmatch = original
--- a/hgext/remotefilelog/shallowrepo.py	Sun Feb 10 14:35:36 2019 -0800
+++ b/hgext/remotefilelog/shallowrepo.py	Sat Feb 09 22:50:53 2019 -0800
@@ -289,7 +289,7 @@
 
     repo.__class__ = shallowrepository
 
-    repo.shallowmatch = match.always(repo.root, '')
+    repo.shallowmatch = match.always()
 
     makeunionstores(repo)
 
--- a/hgext/sparse.py	Sun Feb 10 14:35:36 2019 -0800
+++ b/hgext/sparse.py	Sat Feb 09 22:50:53 2019 -0800
@@ -199,7 +199,7 @@
     def walk(orig, self, match, subrepos, unknown, ignored, full=True):
         # hack to not exclude explicitly-specified paths so that they can
         # be warned later on e.g. dirstate.add()
-        em = matchmod.exact(None, None, match.files())
+        em = matchmod.exact(match.files())
         sm = matchmod.unionmatcher([self._sparsematcher, em])
         match = matchmod.intersectmatchers(match, sm)
         return orig(self, match, subrepos, unknown, ignored, full)
--- a/hgext/transplant.py	Sun Feb 10 14:35:36 2019 -0800
+++ b/hgext/transplant.py	Sat Feb 09 22:50:53 2019 -0800
@@ -325,9 +325,9 @@
         if merge:
             p1 = repo.dirstate.p1()
             repo.setparents(p1, node)
-            m = match.always(repo.root, '')
+            m = match.always()
         else:
-            m = match.exact(repo.root, '', files)
+            m = match.exact(files)
 
         n = repo.commit(message, user, date, extra=extra, match=m,
                         editor=self.getcommiteditor())
--- a/mercurial/changegroup.py	Sun Feb 10 14:35:36 2019 -0800
+++ b/mercurial/changegroup.py	Sat Feb 09 22:50:53 2019 -0800
@@ -1313,9 +1313,9 @@
     assert version in supportedoutgoingversions(repo)
 
     if matcher is None:
-        matcher = matchmod.always(repo.root, '')
+        matcher = matchmod.always()
     if oldmatcher is None:
-        oldmatcher = matchmod.never(repo.root, '')
+        oldmatcher = matchmod.never()
 
     if version == '01' and not matcher.always():
         raise error.ProgrammingError('version 01 changegroups do not support '
--- a/mercurial/dirstate.py	Sun Feb 10 14:35:36 2019 -0800
+++ b/mercurial/dirstate.py	Sat Feb 09 22:50:53 2019 -0800
@@ -148,7 +148,7 @@
     def _ignore(self):
         files = self._ignorefiles()
         if not files:
-            return matchmod.never(self._root, '')
+            return matchmod.never()
 
         pats = ['include:%s' % f for f in files]
         return matchmod.match(self._root, '', [], pats, warn=self._ui.warn)
--- a/mercurial/fileset.py	Sun Feb 10 14:35:36 2019 -0800
+++ b/mercurial/fileset.py	Sat Feb 09 22:50:53 2019 -0800
@@ -538,8 +538,7 @@
 
     def never(self):
         """Create a matcher to select nothing"""
-        repo = self.ctx.repo()
-        return matchmod.never(repo.root, repo.getcwd(), badfn=self._badfn)
+        return matchmod.never(badfn=self._badfn)
 
 def match(ctx, expr, badfn=None):
     """Create a matcher for a single fileset expression"""
--- a/mercurial/hgweb/webutil.py	Sun Feb 10 14:35:36 2019 -0800
+++ b/mercurial/hgweb/webutil.py	Sat Feb 09 22:50:53 2019 -0800
@@ -565,9 +565,9 @@
 def _diffsgen(context, repo, ctx, basectx, files, style, stripecount,
               linerange, lineidprefix):
     if files:
-        m = match.exact(repo.root, repo.getcwd(), files)
+        m = match.exact(files)
     else:
-        m = match.always(repo.root, repo.getcwd())
+        m = match.always()
 
     diffopts = patch.diffopts(repo.ui, untrusted=True)
     parity = paritygen(stripecount)
--- a/mercurial/localrepo.py	Sun Feb 10 14:35:36 2019 -0800
+++ b/mercurial/localrepo.py	Sat Feb 09 22:50:53 2019 -0800
@@ -1227,14 +1227,14 @@
     @storecache(narrowspec.FILENAME)
     def _storenarrowmatch(self):
         if repository.NARROW_REQUIREMENT not in self.requirements:
-            return matchmod.always(self.root, '')
+            return matchmod.always()
         include, exclude = self.narrowpats
         return narrowspec.match(self.root, include=include, exclude=exclude)
 
     @storecache(narrowspec.FILENAME)
     def _narrowmatch(self):
         if repository.NARROW_REQUIREMENT not in self.requirements:
-            return matchmod.always(self.root, '')
+            return matchmod.always()
         narrowspec.checkworkingcopynarrowspec(self)
         include, exclude = self.narrowpats
         return narrowspec.match(self.root, include=include, exclude=exclude)
@@ -1252,7 +1252,7 @@
             if includeexact and not self._narrowmatch.always():
                 # do not exclude explicitly-specified paths so that they can
                 # be warned later on
-                em = matchmod.exact(None, None, match.files())
+                em = matchmod.exact(match.files())
                 nm = matchmod.unionmatcher([self._narrowmatch, em])
                 return matchmod.intersectmatchers(match, nm)
             return matchmod.intersectmatchers(match, self._narrowmatch)
@@ -2400,7 +2400,7 @@
             raise error.Abort('%s: %s' % (f, msg))
 
         if not match:
-            match = matchmod.always(self.root, '')
+            match = matchmod.always()
 
         if not force:
             vdirs = []
--- a/mercurial/match.py	Sun Feb 10 14:35:36 2019 -0800
+++ b/mercurial/match.py	Sat Feb 09 22:50:53 2019 -0800
@@ -190,14 +190,14 @@
         m = differencematcher(m, em)
     return m
 
-def exact(root, cwd, files, badfn=None):
+def exact(files, badfn=None):
     return exactmatcher(files, badfn=badfn)
 
-def always(root, cwd, badfn=None):
-    return alwaysmatcher(badfn=badfn)
+def always(badfn=None):
+    return alwaysmatcher(badfn)
 
-def never(root, cwd, badfn=None):
-    return nevermatcher(badfn=badfn)
+def never(badfn=None):
+    return nevermatcher(badfn)
 
 def badmatch(match, badfn):
     """Make a copy of the given matcher, replacing its bad method with the given
--- a/mercurial/narrowspec.py	Sun Feb 10 14:35:36 2019 -0800
+++ b/mercurial/narrowspec.py	Sat Feb 09 22:50:53 2019 -0800
@@ -127,7 +127,7 @@
         # Passing empty include and empty exclude to matchmod.match()
         # gives a matcher that matches everything, so explicitly use
         # the nevermatcher.
-        return matchmod.never(root, '')
+        return matchmod.never()
     return matchmod.match(root, '', [], include=include or [],
                           exclude=exclude or [])
 
--- a/mercurial/revset.py	Sun Feb 10 14:35:36 2019 -0800
+++ b/mercurial/revset.py	Sat Feb 09 22:50:53 2019 -0800
@@ -2073,7 +2073,7 @@
     if len(args) != 0:
         pat = getstring(args[0], _("subrepo requires a pattern"))
 
-    m = matchmod.exact(repo.root, repo.root, ['.hgsubstate'])
+    m = matchmod.exact(['.hgsubstate'])
 
     def submatches(names):
         k, p, m = stringutil.stringmatcher(pat)
--- a/mercurial/scmutil.py	Sun Feb 10 14:35:36 2019 -0800
+++ b/mercurial/scmutil.py	Sat Feb 09 22:50:53 2019 -0800
@@ -821,11 +821,11 @@
 
 def matchall(repo):
     '''Return a matcher that will efficiently match everything.'''
-    return matchmod.always(repo.root, repo.getcwd())
+    return matchmod.always()
 
 def matchfiles(repo, files, badfn=None):
     '''Return a matcher that will efficiently match exactly these files.'''
-    return matchmod.exact(repo.root, repo.getcwd(), files, badfn=badfn)
+    return matchmod.exact(files, badfn=badfn)
 
 def parsefollowlinespattern(repo, rev, pat, msg):
     """Return a file name from `pat` pattern suitable for usage in followlines
--- a/mercurial/sparse.py	Sun Feb 10 14:35:36 2019 -0800
+++ b/mercurial/sparse.py	Sat Feb 09 22:50:53 2019 -0800
@@ -277,7 +277,7 @@
     """
     # If sparse isn't enabled, sparse matcher matches everything.
     if not enabled:
-        return matchmod.always(repo.root, '')
+        return matchmod.always()
 
     if not revs or revs == [None]:
         revs = [repo.changelog.rev(node)
@@ -305,7 +305,7 @@
             pass
 
     if not matchers:
-        result = matchmod.always(repo.root, '')
+        result = matchmod.always()
     elif len(matchers) == 1:
         result = matchers[0]
     else:
--- a/mercurial/subrepo.py	Sun Feb 10 14:35:36 2019 -0800
+++ b/mercurial/subrepo.py	Sat Feb 09 22:50:53 2019 -0800
@@ -323,7 +323,7 @@
 
     def matchfileset(self, expr, badfn=None):
         """Resolve the fileset expression for this repo"""
-        return matchmod.never(self.wvfs.base, '', badfn=badfn)
+        return matchmod.never(badfn=badfn)
 
     def printfiles(self, ui, m, fm, fmt, subrepos):
         """handle the files command for this subrepo"""
@@ -807,12 +807,11 @@
 
     @annotatesubrepoerror
     def matchfileset(self, expr, badfn=None):
-        repo = self._repo
         if self._ctx.rev() is None:
-            ctx = repo[None]
+            ctx = self._repo[None]
         else:
             rev = self._state[1]
-            ctx = repo[rev]
+            ctx = self._repo[rev]
 
         matchers = [ctx.matchfileset(expr, badfn=badfn)]
 
--- a/mercurial/tags.py	Sun Feb 10 14:35:36 2019 -0800
+++ b/mercurial/tags.py	Sat Feb 09 22:50:53 2019 -0800
@@ -536,7 +536,7 @@
     date: date tuple to use if committing'''
 
     if not local:
-        m = matchmod.exact(repo.root, '', ['.hgtags'])
+        m = matchmod.exact(['.hgtags'])
         if any(repo.status(match=m, unknown=True, ignored=True)):
             raise error.Abort(_('working copy of .hgtags is changed'),
                              hint=_('please commit .hgtags manually'))
@@ -610,7 +610,7 @@
     if '.hgtags' not in repo.dirstate:
         repo[None].add(['.hgtags'])
 
-    m = matchmod.exact(repo.root, '', ['.hgtags'])
+    m = matchmod.exact(['.hgtags'])
     tagnode = repo.commit(message, user, date, extra=extra, match=m,
                           editor=editor)
 
--- a/tests/test-manifest.py	Sun Feb 10 14:35:36 2019 -0800
+++ b/tests/test-manifest.py	Sat Feb 09 22:50:53 2019 -0800
@@ -289,8 +289,7 @@
         the resulting manifest.'''
         m = self.parsemanifest(A_HUGE_MANIFEST)
 
-        match = matchmod.exact(b'/', b'',
-                [b'file1', b'file200', b'file300'])
+        match = matchmod.exact([b'file1', b'file200', b'file300'])
         m2 = m.matches(match)
 
         w = (b'file1\0%sx\n'
@@ -304,9 +303,8 @@
         '''
         m = self.parsemanifest(A_DEEPER_MANIFEST)
 
-        match = matchmod.exact(b'/', b'',
-                [b'a/b/c/bar.txt', b'a/b/d/qux.py',
-                 b'readme.txt', b'nonexistent'])
+        match = matchmod.exact([b'a/b/c/bar.txt', b'a/b/d/qux.py',
+                                b'readme.txt', b'nonexistent'])
         m2 = m.matches(match)
 
         self.assertEqual(
@@ -329,7 +327,7 @@
         m = self.parsemanifest(A_HUGE_MANIFEST)
 
         flist = m.keys()[80:300]
-        match = matchmod.exact(b'/', b'', flist)
+        match = matchmod.exact(flist)
         m2 = m.matches(match)
 
         self.assertEqual(flist, m2.keys())
@@ -363,7 +361,7 @@
         against a directory.'''
         m = self.parsemanifest(A_DEEPER_MANIFEST)
 
-        match = matchmod.exact(b'/', b'', [b'a/b'])
+        match = matchmod.exact([b'a/b'])
         m2 = m.matches(match)
 
         self.assertEqual([], m2.keys())
--- a/tests/test-match.py	Sun Feb 10 14:35:36 2019 -0800
+++ b/tests/test-match.py	Sat Feb 09 22:50:53 2019 -0800
@@ -185,7 +185,7 @@
 class ExactMatcherTests(unittest.TestCase):
 
     def testVisitdir(self):
-        m = matchmod.exact(b'x', b'', files=[b'dir/subdir/foo.txt'])
+        m = matchmod.exact(files=[b'dir/subdir/foo.txt'])
         assert isinstance(m, matchmod.exactmatcher)
         self.assertTrue(m.visitdir(b'.'))
         self.assertTrue(m.visitdir(b'dir'))
@@ -196,7 +196,7 @@
         self.assertFalse(m.visitdir(b'folder'))
 
     def testVisitchildrenset(self):
-        m = matchmod.exact(b'x', b'', files=[b'dir/subdir/foo.txt'])
+        m = matchmod.exact(files=[b'dir/subdir/foo.txt'])
         assert isinstance(m, matchmod.exactmatcher)
         self.assertEqual(m.visitchildrenset(b'.'), {b'dir'})
         self.assertEqual(m.visitchildrenset(b'dir'), {b'subdir'})
@@ -206,11 +206,11 @@
         self.assertEqual(m.visitchildrenset(b'folder'), set())
 
     def testVisitchildrensetFilesAndDirs(self):
-        m = matchmod.exact(b'x', b'', files=[b'rootfile.txt',
-                                             b'a/file1.txt',
-                                             b'a/b/file2.txt',
-                                             # no file in a/b/c
-                                             b'a/b/c/d/file4.txt'])
+        m = matchmod.exact(files=[b'rootfile.txt',
+                                  b'a/file1.txt',
+                                  b'a/b/file2.txt',
+                                  # no file in a/b/c
+                                  b'a/b/c/d/file4.txt'])
         assert isinstance(m, matchmod.exactmatcher)
         self.assertEqual(m.visitchildrenset(b'.'), {b'a', b'rootfile.txt'})
         self.assertEqual(m.visitchildrenset(b'a'), {b'b', b'file1.txt'})