hgweb: extract _getview to own function
authorGregory Szorc <gregory.szorc@gmail.com>
Sat, 22 Aug 2015 16:44:36 -0700
changeset 26208 c87566ac3c49
parent 26207 13d664127ee9
child 26209 7917746c9a67
hgweb: extract _getview to own function While we're refactoring code, we might as well remove a method that doesn't need to be a method.
mercurial/hgweb/hgweb_mod.py
--- a/mercurial/hgweb/hgweb_mod.py	Sat Aug 22 16:41:02 2015 -0700
+++ b/mercurial/hgweb/hgweb_mod.py	Sat Aug 22 16:44:36 2015 -0700
@@ -224,7 +224,7 @@
             # we trust caller to give us a private copy
             r = repo
 
-        r = self._getview(r)
+        r = getwebview(r)
         r.ui.setconfig('ui', 'report_untrusted', 'off', 'hgweb')
         r.baseui.setconfig('ui', 'report_untrusted', 'off', 'hgweb')
         r.ui.setconfig('ui', 'nontty', 'true', 'hgweb')
@@ -239,26 +239,6 @@
         self.mtime = -1
         self.reponame = name
 
-    def _getview(self, repo):
-        """The 'web.view' config controls changeset filter to hgweb. Possible
-        values are ``served``, ``visible`` and ``all``. Default is ``served``.
-        The ``served`` filter only shows changesets that can be pulled from the
-        hgweb instance.  The``visible`` filter includes secret changesets but
-        still excludes "hidden" one.
-
-        See the repoview module for details.
-
-        The option has been around undocumented since Mercurial 2.5, but no
-        user ever asked about it. So we better keep it undocumented for now."""
-        viewconfig = repo.ui.config('web', 'view', 'served',
-                                    untrusted=True)
-        if viewconfig == 'all':
-            return repo.unfiltered()
-        elif viewconfig in repoview.filtertable:
-            return repo.filtered(viewconfig)
-        else:
-            return repo.filtered('served')
-
     def refresh(self):
         repostate = []
         mtime = 0
@@ -273,7 +253,7 @@
         # changes made less than a second ago
         if repostate != self.repostate:
             r = hg.repository(self.repo.baseui, self.repo.url())
-            self.repo = self._getview(r)
+            self.repo = getwebview(r)
             # update these last to avoid threads seeing empty settings
             self.repostate = repostate
             # mtime is needed for ETag
@@ -444,3 +424,24 @@
     def check_perm(self, rctx, req, op):
         for permhook in permhooks:
             permhook(rctx, req, op)
+
+def getwebview(repo):
+    """The 'web.view' config controls changeset filter to hgweb. Possible
+    values are ``served``, ``visible`` and ``all``. Default is ``served``.
+    The ``served`` filter only shows changesets that can be pulled from the
+    hgweb instance.  The``visible`` filter includes secret changesets but
+    still excludes "hidden" one.
+
+    See the repoview module for details.
+
+    The option has been around undocumented since Mercurial 2.5, but no
+    user ever asked about it. So we better keep it undocumented for now."""
+    viewconfig = repo.ui.config('web', 'view', 'served',
+                                untrusted=True)
+    if viewconfig == 'all':
+        return repo.unfiltered()
+    elif viewconfig in repoview.filtertable:
+        return repo.filtered(viewconfig)
+    else:
+        return repo.filtered('served')
+