Mercurial > public > mercurial-scm > hg
comparison mercurial/hgweb/hgweb_mod.py @ 13958:71f51cc71652 stable
hgweb: detect change based on changelog size too
Before, there was a race between an access and a modification made
within the same second.
author | Martin Geisler <mg@lazybytes.net> |
---|---|
date | Tue, 19 Apr 2011 15:15:56 +0200 |
parents | 61a898576888 |
children | 141f88ae5276 |
comparison
equal
deleted
inserted
replaced
13957:044e1356327d | 13958:71f51cc71652 |
---|---|
6 # This software may be used and distributed according to the terms of the | 6 # This software may be used and distributed according to the terms of the |
7 # GNU General Public License version 2 or any later version. | 7 # GNU General Public License version 2 or any later version. |
8 | 8 |
9 import os | 9 import os |
10 from mercurial import ui, hg, hook, error, encoding, templater | 10 from mercurial import ui, hg, hook, error, encoding, templater |
11 from common import get_mtime, ErrorResponse, permhooks, caching | 11 from common import get_stat, ErrorResponse, permhooks, caching |
12 from common import HTTP_OK, HTTP_NOT_MODIFIED, HTTP_BAD_REQUEST | 12 from common import HTTP_OK, HTTP_NOT_MODIFIED, HTTP_BAD_REQUEST |
13 from common import HTTP_NOT_FOUND, HTTP_SERVER_ERROR | 13 from common import HTTP_NOT_FOUND, HTTP_SERVER_ERROR |
14 from request import wsgirequest | 14 from request import wsgirequest |
15 import webcommands, protocol, webutil | 15 import webcommands, protocol, webutil |
16 | 16 |
36 | 36 |
37 self.repo.ui.setconfig('ui', 'report_untrusted', 'off') | 37 self.repo.ui.setconfig('ui', 'report_untrusted', 'off') |
38 self.repo.ui.setconfig('ui', 'interactive', 'off') | 38 self.repo.ui.setconfig('ui', 'interactive', 'off') |
39 hook.redirect(True) | 39 hook.redirect(True) |
40 self.mtime = -1 | 40 self.mtime = -1 |
41 self.size = -1 | |
41 self.reponame = name | 42 self.reponame = name |
42 self.archives = 'zip', 'gz', 'bz2' | 43 self.archives = 'zip', 'gz', 'bz2' |
43 self.stripecount = 1 | 44 self.stripecount = 1 |
44 # a repo owner may set web.templates in .hg/hgrc to get any file | 45 # a repo owner may set web.templates in .hg/hgrc to get any file |
45 # readable by the user running the CGI script | 46 # readable by the user running the CGI script |
60 untrusted=untrusted) | 61 untrusted=untrusted) |
61 | 62 |
62 def refresh(self, request=None): | 63 def refresh(self, request=None): |
63 if request: | 64 if request: |
64 self.repo.ui.environ = request.env | 65 self.repo.ui.environ = request.env |
65 mtime = get_mtime(self.repo.spath) | 66 st = get_stat(self.repo.spath) |
66 if mtime != self.mtime: | 67 # compare changelog size in addition to mtime to catch |
67 self.mtime = mtime | 68 # rollbacks made less than a second ago |
69 if st.st_mtime != self.mtime or st.st_size != self.size: | |
70 self.mtime = st.st_mtime | |
71 self.size = st.st_size | |
68 self.repo = hg.repository(self.repo.ui, self.repo.root) | 72 self.repo = hg.repository(self.repo.ui, self.repo.root) |
69 self.maxchanges = int(self.config("web", "maxchanges", 10)) | 73 self.maxchanges = int(self.config("web", "maxchanges", 10)) |
70 self.stripecount = int(self.config("web", "stripes", 1)) | 74 self.stripecount = int(self.config("web", "stripes", 1)) |
71 self.maxshortchanges = int(self.config("web", "maxshortchanges", 60)) | 75 self.maxshortchanges = int(self.config("web", "maxshortchanges", 60)) |
72 self.maxfiles = int(self.config("web", "maxfiles", 10)) | 76 self.maxfiles = int(self.config("web", "maxfiles", 10)) |