changeset 31025:6cf2857526c7

scmutil: proxy revrange() through repo to break import cycles This was one of the hardest import cycles as scmutil is widely used and revset functions are likely to depend on a variety of modules. New repo.anyrevs() does not expand user aliases by default to copy the behavior of the existing repo.revs(). I don't want to add new function to localrepository, but this function is quite similar to repo.revs() so it won't increase the complexity of the localrepository class so much.
author Yuya Nishihara <yuya@tcha.org>
date Sun, 19 Feb 2017 20:00:18 +0900
parents 0b8356705de6
children 9c827087df38
files mercurial/destutil.py mercurial/localrepo.py mercurial/scmutil.py mercurial/tags.py
diffstat 4 files changed, 17 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/destutil.py	Sun Feb 19 18:19:33 2017 +0900
+++ b/mercurial/destutil.py	Sun Feb 19 20:00:18 2017 +0900
@@ -12,6 +12,7 @@
     bookmarks,
     error,
     obsolete,
+    scmutil,
 )
 
 def _destupdateobs(repo, clean):
@@ -342,9 +343,6 @@
 
 def desthistedit(ui, repo):
     """Default base revision to edit for `hg histedit`."""
-    # Avoid cycle: scmutil -> revset -> destutil
-    from . import scmutil
-
     default = ui.config('histedit', 'defaultrev', histeditdefaultrevset)
     if default:
         revs = scmutil.revrange(repo, [default])
--- a/mercurial/localrepo.py	Sun Feb 19 18:19:33 2017 +0900
+++ b/mercurial/localrepo.py	Sun Feb 19 20:00:18 2017 +0900
@@ -577,7 +577,8 @@
         %-formatting to escape certain types. See ``revsetlang.formatspec``.
 
         Revset aliases from the configuration are not expanded. To expand
-        user aliases, consider calling ``scmutil.revrange()``.
+        user aliases, consider calling ``scmutil.revrange()`` or
+        ``repo.anyrevs([expr], user=True)``.
 
         Returns a revset.abstractsmartset, which is a list-like interface
         that contains integer revisions.
@@ -598,6 +599,18 @@
         for r in self.revs(expr, *args):
             yield self[r]
 
+    def anyrevs(self, specs, user=False):
+        '''Find revisions matching one of the given revsets.
+
+        Revset aliases from the configuration are not expanded by default. To
+        expand user aliases, specify ``user=True``.
+        '''
+        if user:
+            m = revset.matchany(self.ui, specs, repo=self)
+        else:
+            m = revset.matchany(None, specs)
+        return m(self)
+
     def url(self):
         return 'file:' + self.root
 
--- a/mercurial/scmutil.py	Sun Feb 19 18:19:33 2017 +0900
+++ b/mercurial/scmutil.py	Sun Feb 19 20:00:18 2017 +0900
@@ -29,7 +29,6 @@
     pathutil,
     phases,
     pycompat,
-    revset,
     revsetlang,
     similar,
     util,
@@ -950,8 +949,7 @@
         if isinstance(spec, int):
             spec = revsetlang.formatspec('rev(%d)', spec)
         allspecs.append(spec)
-    m = revset.matchany(repo.ui, allspecs, repo)
-    return m(repo)
+    return repo.anyrevs(allspecs, user=True)
 
 def meaningfulparents(repo, ctx):
     """Return list of meaningful (or all if debug) parentrevs for rev.
--- a/mercurial/tags.py	Sun Feb 19 18:19:33 2017 +0900
+++ b/mercurial/tags.py	Sun Feb 19 20:00:18 2017 +0900
@@ -24,6 +24,7 @@
 from . import (
     encoding,
     error,
+    scmutil,
     util,
 )
 
@@ -277,8 +278,6 @@
     If the cache is not up to date, the caller is responsible for reading tag
     info from each returned head. (See findglobaltags().)
     '''
-    from . import scmutil  # avoid cycle
-
     try:
         cachefile = repo.vfs(_filename(repo), 'r')
         # force reading the file for static-http