Patchwork [3,of,5,hgweb-thread-isolation] hgweb: extract _getview to own function

login
register
mail settings
Submitter Gregory Szorc
Date Sept. 3, 2015, 11:16 p.m.
Message ID <a8cb273c131b506667b2.1441322178@gps-mbp.local>
Download mbox | patch
Permalink /patch/10389/
State Superseded
Commit c87566ac3c498b3355c3c95f2a878749eb4853c7
Headers show

Comments

Gregory Szorc - Sept. 3, 2015, 11:16 p.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1440287076 25200
#      Sat Aug 22 16:44:36 2015 -0700
# Node ID a8cb273c131b506667b26114d31eb4f5d7fc0680
# Parent  305b554e1ec3be68e6ca28022c2bc243845a4a8d
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.

Patch

diff --git a/mercurial/hgweb/hgweb_mod.py b/mercurial/hgweb/hgweb_mod.py
--- a/mercurial/hgweb/hgweb_mod.py
+++ b/mercurial/hgweb/hgweb_mod.py
@@ -224,9 +224,9 @@  class hgweb(object):
         else:
             # 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')
         r.baseui.setconfig('ui', 'nontty', 'true', 'hgweb')
@@ -239,28 +239,8 @@  class hgweb(object):
         self.repostate = None
         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 = []
         # file of interrests mtime and size
         for meth, fname in foi:
@@ -271,9 +251,9 @@  class hgweb(object):
         # we need to compare file size in addition to mtime to catch
         # 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
             self.mtime = st.st_mtime
@@ -442,4 +422,25 @@  class hgweb(object):
 
     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')
+