comparison mercurial/hgweb/hgweb_mod.py @ 26208:c87566ac3c49

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.
author Gregory Szorc <gregory.szorc@gmail.com>
date Sat, 22 Aug 2015 16:44:36 -0700
parents 13d664127ee9
children 7917746c9a67
comparison
equal deleted inserted replaced
26207:13d664127ee9 26208:c87566ac3c49
222 r = hg.repository(u, repo) 222 r = hg.repository(u, repo)
223 else: 223 else:
224 # we trust caller to give us a private copy 224 # we trust caller to give us a private copy
225 r = repo 225 r = repo
226 226
227 r = self._getview(r) 227 r = getwebview(r)
228 r.ui.setconfig('ui', 'report_untrusted', 'off', 'hgweb') 228 r.ui.setconfig('ui', 'report_untrusted', 'off', 'hgweb')
229 r.baseui.setconfig('ui', 'report_untrusted', 'off', 'hgweb') 229 r.baseui.setconfig('ui', 'report_untrusted', 'off', 'hgweb')
230 r.ui.setconfig('ui', 'nontty', 'true', 'hgweb') 230 r.ui.setconfig('ui', 'nontty', 'true', 'hgweb')
231 r.baseui.setconfig('ui', 'nontty', 'true', 'hgweb') 231 r.baseui.setconfig('ui', 'nontty', 'true', 'hgweb')
232 # displaying bundling progress bar while serving feel wrong and may 232 # displaying bundling progress bar while serving feel wrong and may
236 self.repo = r 236 self.repo = r
237 hook.redirect(True) 237 hook.redirect(True)
238 self.repostate = None 238 self.repostate = None
239 self.mtime = -1 239 self.mtime = -1
240 self.reponame = name 240 self.reponame = name
241
242 def _getview(self, repo):
243 """The 'web.view' config controls changeset filter to hgweb. Possible
244 values are ``served``, ``visible`` and ``all``. Default is ``served``.
245 The ``served`` filter only shows changesets that can be pulled from the
246 hgweb instance. The``visible`` filter includes secret changesets but
247 still excludes "hidden" one.
248
249 See the repoview module for details.
250
251 The option has been around undocumented since Mercurial 2.5, but no
252 user ever asked about it. So we better keep it undocumented for now."""
253 viewconfig = repo.ui.config('web', 'view', 'served',
254 untrusted=True)
255 if viewconfig == 'all':
256 return repo.unfiltered()
257 elif viewconfig in repoview.filtertable:
258 return repo.filtered(viewconfig)
259 else:
260 return repo.filtered('served')
261 241
262 def refresh(self): 242 def refresh(self):
263 repostate = [] 243 repostate = []
264 mtime = 0 244 mtime = 0
265 # file of interrests mtime and size 245 # file of interrests mtime and size
271 repostate = tuple(repostate) 251 repostate = tuple(repostate)
272 # we need to compare file size in addition to mtime to catch 252 # we need to compare file size in addition to mtime to catch
273 # changes made less than a second ago 253 # changes made less than a second ago
274 if repostate != self.repostate: 254 if repostate != self.repostate:
275 r = hg.repository(self.repo.baseui, self.repo.url()) 255 r = hg.repository(self.repo.baseui, self.repo.url())
276 self.repo = self._getview(r) 256 self.repo = getwebview(r)
277 # update these last to avoid threads seeing empty settings 257 # update these last to avoid threads seeing empty settings
278 self.repostate = repostate 258 self.repostate = repostate
279 # mtime is needed for ETag 259 # mtime is needed for ETag
280 self.mtime = mtime 260 self.mtime = mtime
281 261
442 return tmpl('error', error=str(inst)) 422 return tmpl('error', error=str(inst))
443 423
444 def check_perm(self, rctx, req, op): 424 def check_perm(self, rctx, req, op):
445 for permhook in permhooks: 425 for permhook in permhooks:
446 permhook(rctx, req, op) 426 permhook(rctx, req, op)
427
428 def getwebview(repo):
429 """The 'web.view' config controls changeset filter to hgweb. Possible
430 values are ``served``, ``visible`` and ``all``. Default is ``served``.
431 The ``served`` filter only shows changesets that can be pulled from the
432 hgweb instance. The``visible`` filter includes secret changesets but
433 still excludes "hidden" one.
434
435 See the repoview module for details.
436
437 The option has been around undocumented since Mercurial 2.5, but no
438 user ever asked about it. So we better keep it undocumented for now."""
439 viewconfig = repo.ui.config('web', 'view', 'served',
440 untrusted=True)
441 if viewconfig == 'all':
442 return repo.unfiltered()
443 elif viewconfig in repoview.filtertable:
444 return repo.filtered(viewconfig)
445 else:
446 return repo.filtered('served')
447