70 """ |
70 """ |
71 def __init__(self, app): |
71 def __init__(self, app): |
72 object.__setattr__(self, 'app', app) |
72 object.__setattr__(self, 'app', app) |
73 object.__setattr__(self, 'repo', app.repo) |
73 object.__setattr__(self, 'repo', app.repo) |
74 |
74 |
|
75 object.__setattr__(self, 'maxchanges', |
|
76 self.configint('web', 'maxchanges', 10)) |
|
77 object.__setattr__(self, 'stripecount', |
|
78 self.configint('web', 'stripes', 1)) |
|
79 object.__setattr__(self, 'maxshortchanges', |
|
80 self.configint('web', 'maxshortchanges', 60)) |
|
81 object.__setattr__(self, 'maxfiles', |
|
82 self.configint('web', 'maxfiles', 10)) |
|
83 object.__setattr__(self, 'allowpull', |
|
84 self.configbool('web', 'allowpull', True)) |
|
85 |
75 # Proxy unknown reads and writes to the application instance |
86 # Proxy unknown reads and writes to the application instance |
76 # until everything is moved to us. |
87 # until everything is moved to us. |
77 def __getattr__(self, name): |
88 def __getattr__(self, name): |
78 return getattr(self.app, name) |
89 return getattr(self.app, name) |
79 |
90 |
80 def __setattr__(self, name, value): |
91 def __setattr__(self, name, value): |
81 return setattr(self.app, name, value) |
92 return setattr(self.app, name, value) |
|
93 |
|
94 # Servers are often run by a user different from the repo owner. |
|
95 # Trust the settings from the .hg/hgrc files by default. |
|
96 def config(self, section, name, default=None, untrusted=True): |
|
97 return self.repo.ui.config(section, name, default, |
|
98 untrusted=untrusted) |
|
99 |
|
100 def configbool(self, section, name, default=False, untrusted=True): |
|
101 return self.repo.ui.configbool(section, name, default, |
|
102 untrusted=untrusted) |
|
103 |
|
104 def configint(self, section, name, default=None, untrusted=True): |
|
105 return self.repo.ui.configint(section, name, default, |
|
106 untrusted=untrusted) |
|
107 |
|
108 def configlist(self, section, name, default=None, untrusted=True): |
|
109 return self.repo.ui.configlist(section, name, default, |
|
110 untrusted=untrusted) |
82 |
111 |
83 class hgweb(object): |
112 class hgweb(object): |
84 """HTTP server for individual repositories. |
113 """HTTP server for individual repositories. |
85 |
114 |
86 Instances of this class serve HTTP responses for a particular |
115 Instances of this class serve HTTP responses for a particular |
115 hook.redirect(True) |
144 hook.redirect(True) |
116 self.repostate = ((-1, -1), (-1, -1)) |
145 self.repostate = ((-1, -1), (-1, -1)) |
117 self.mtime = -1 |
146 self.mtime = -1 |
118 self.reponame = name |
147 self.reponame = name |
119 self.archives = 'zip', 'gz', 'bz2' |
148 self.archives = 'zip', 'gz', 'bz2' |
120 self.stripecount = 1 |
|
121 # a repo owner may set web.templates in .hg/hgrc to get any file |
149 # a repo owner may set web.templates in .hg/hgrc to get any file |
122 # readable by the user running the CGI script |
150 # readable by the user running the CGI script |
123 self.templatepath = self.config('web', 'templates') |
151 self.templatepath = self.config('web', 'templates') |
124 self.websubtable = self.loadwebsub() |
152 self.websubtable = self.loadwebsub() |
125 |
153 |
168 # we need to compare file size in addition to mtime to catch |
196 # we need to compare file size in addition to mtime to catch |
169 # changes made less than a second ago |
197 # changes made less than a second ago |
170 if repostate != self.repostate: |
198 if repostate != self.repostate: |
171 r = hg.repository(self.repo.baseui, self.repo.url()) |
199 r = hg.repository(self.repo.baseui, self.repo.url()) |
172 self.repo = self._getview(r) |
200 self.repo = self._getview(r) |
173 self.maxchanges = int(self.config("web", "maxchanges", 10)) |
|
174 self.stripecount = int(self.config("web", "stripes", 1)) |
|
175 self.maxshortchanges = int(self.config("web", "maxshortchanges", |
|
176 60)) |
|
177 self.maxfiles = int(self.config("web", "maxfiles", 10)) |
|
178 self.allowpull = self.configbool("web", "allowpull", True) |
|
179 encoding.encoding = self.config("web", "encoding", |
201 encoding.encoding = self.config("web", "encoding", |
180 encoding.encoding) |
202 encoding.encoding) |
181 # update these last to avoid threads seeing empty settings |
203 # update these last to avoid threads seeing empty settings |
182 self.repostate = repostate |
204 self.repostate = repostate |
183 # mtime is needed for ETag |
205 # mtime is needed for ETag |