##// END OF EJS Templates
Add a multi-repository server...
mpm@selenic.com -
r941:4cf418c2 default
parent child Browse files
Show More
@@ -0,0 +1,17
1 #!/usr/bin/env python
2 #
3 # An example CGI script to export multiple hgweb repos, edit as necessary
4
5 import cgi, cgitb, os, sys, ConfigParser
6 cgitb.enable()
7
8 # sys.path.insert(0, "/path/to/python/lib") # if not a system-wide install
9 from mercurial import hgweb
10
11 # The config file looks like this:
12 # [paths]
13 # virtual/path = /real/path
14 # virtual/path = /real/path
15
16 h = hgweb.hgwebdir("hgweb.config")
17 h.run()
@@ -0,0 +1,18
1 #header#
2 <title>Mercurial repositories index</title>
3 </head>
4 <body>
5
6 <h2>Mercurial Repositories</h2>
7
8 <table>
9 <tr>
10 <td>Name</td>
11 <td>Description</td>
12 <td>Author</td>
13 <td>Last change</td>
14 <tr>
15 #entries#
16 </table>
17
18 #footer#
@@ -1,820 +1,874
1 # hgweb.py - web interface to a mercurial repository
1 # hgweb.py - web interface to a mercurial repository
2 #
2 #
3 # Copyright 21 May 2005 - (c) 2005 Jake Edge <jake@edge2.net>
3 # Copyright 21 May 2005 - (c) 2005 Jake Edge <jake@edge2.net>
4 # Copyright 2005 Matt Mackall <mpm@selenic.com>
4 # Copyright 2005 Matt Mackall <mpm@selenic.com>
5 #
5 #
6 # This software may be used and distributed according to the terms
6 # This software may be used and distributed according to the terms
7 # of the GNU General Public License, incorporated herein by reference.
7 # of the GNU General Public License, incorporated herein by reference.
8
8
9 import os, cgi, time, re, difflib, socket, sys, zlib
9 import os, cgi, time, re, difflib, socket, sys, zlib
10 from mercurial.hg import *
10 from mercurial.hg import *
11 from mercurial.ui import *
11 from mercurial.ui import *
12
12
13 def templatepath():
13 def templatepath():
14 for f in "templates", "../templates":
14 for f in "templates", "../templates":
15 p = os.path.join(os.path.dirname(__file__), f)
15 p = os.path.join(os.path.dirname(__file__), f)
16 if os.path.isdir(p): return p
16 if os.path.isdir(p): return p
17
17
18 def age(t):
18 def age(t):
19 def plural(t, c):
19 def plural(t, c):
20 if c == 1: return t
20 if c == 1: return t
21 return t + "s"
21 return t + "s"
22 def fmt(t, c):
22 def fmt(t, c):
23 return "%d %s" % (c, plural(t, c))
23 return "%d %s" % (c, plural(t, c))
24
24
25 now = time.time()
25 now = time.time()
26 delta = max(1, int(now - t))
26 delta = max(1, int(now - t))
27
27
28 scales = [["second", 1],
28 scales = [["second", 1],
29 ["minute", 60],
29 ["minute", 60],
30 ["hour", 3600],
30 ["hour", 3600],
31 ["day", 3600 * 24],
31 ["day", 3600 * 24],
32 ["week", 3600 * 24 * 7],
32 ["week", 3600 * 24 * 7],
33 ["month", 3600 * 24 * 30],
33 ["month", 3600 * 24 * 30],
34 ["year", 3600 * 24 * 365]]
34 ["year", 3600 * 24 * 365]]
35
35
36 scales.reverse()
36 scales.reverse()
37
37
38 for t, s in scales:
38 for t, s in scales:
39 n = delta / s
39 n = delta / s
40 if n >= 2 or s == 1: return fmt(t, n)
40 if n >= 2 or s == 1: return fmt(t, n)
41
41
42 def nl2br(text):
42 def nl2br(text):
43 return text.replace('\n', '<br/>\n')
43 return text.replace('\n', '<br/>\n')
44
44
45 def obfuscate(text):
45 def obfuscate(text):
46 return ''.join([ '&#%d;' % ord(c) for c in text ])
46 return ''.join([ '&#%d;' % ord(c) for c in text ])
47
47
48 def up(p):
48 def up(p):
49 if p[0] != "/": p = "/" + p
49 if p[0] != "/": p = "/" + p
50 if p[-1] == "/": p = p[:-1]
50 if p[-1] == "/": p = p[:-1]
51 up = os.path.dirname(p)
51 up = os.path.dirname(p)
52 if up == "/":
52 if up == "/":
53 return "/"
53 return "/"
54 return up + "/"
54 return up + "/"
55
55
56 def httphdr(type):
56 def httphdr(type):
57 sys.stdout.write('Content-type: %s\n\n' % type)
57 sys.stdout.write('Content-type: %s\n\n' % type)
58
58
59 def write(*things):
59 def write(*things):
60 for thing in things:
60 for thing in things:
61 if hasattr(thing, "__iter__"):
61 if hasattr(thing, "__iter__"):
62 for part in thing:
62 for part in thing:
63 write(part)
63 write(part)
64 else:
64 else:
65 sys.stdout.write(str(thing))
65 sys.stdout.write(str(thing))
66
66
67 def template(tmpl, filters = {}, **map):
67 def template(tmpl, filters = {}, **map):
68 while tmpl:
68 while tmpl:
69 m = re.search(r"#([a-zA-Z0-9]+)((\|[a-zA-Z0-9]+)*)#", tmpl)
69 m = re.search(r"#([a-zA-Z0-9]+)((\|[a-zA-Z0-9]+)*)#", tmpl)
70 if m:
70 if m:
71 yield tmpl[:m.start(0)]
71 yield tmpl[:m.start(0)]
72 v = map.get(m.group(1), "")
72 v = map.get(m.group(1), "")
73 v = callable(v) and v(**map) or v
73 v = callable(v) and v(**map) or v
74
74
75 fl = m.group(2)
75 fl = m.group(2)
76 if fl:
76 if fl:
77 for f in fl.split("|")[1:]:
77 for f in fl.split("|")[1:]:
78 v = filters[f](v)
78 v = filters[f](v)
79
79
80 yield v
80 yield v
81 tmpl = tmpl[m.end(0):]
81 tmpl = tmpl[m.end(0):]
82 else:
82 else:
83 yield tmpl
83 yield tmpl
84 return
84 return
85
85
86 class templater:
86 class templater:
87 def __init__(self, mapfile, filters = {}, defaults = {}):
87 def __init__(self, mapfile, filters = {}, defaults = {}):
88 self.cache = {}
88 self.cache = {}
89 self.map = {}
89 self.map = {}
90 self.base = os.path.dirname(mapfile)
90 self.base = os.path.dirname(mapfile)
91 self.filters = filters
91 self.filters = filters
92 self.defaults = defaults
92 self.defaults = defaults
93
93
94 for l in file(mapfile):
94 for l in file(mapfile):
95 m = re.match(r'(\S+)\s*=\s*"(.*)"$', l)
95 m = re.match(r'(\S+)\s*=\s*"(.*)"$', l)
96 if m:
96 if m:
97 self.cache[m.group(1)] = m.group(2)
97 self.cache[m.group(1)] = m.group(2)
98 else:
98 else:
99 m = re.match(r'(\S+)\s*=\s*(\S+)', l)
99 m = re.match(r'(\S+)\s*=\s*(\S+)', l)
100 if m:
100 if m:
101 self.map[m.group(1)] = os.path.join(self.base, m.group(2))
101 self.map[m.group(1)] = os.path.join(self.base, m.group(2))
102 else:
102 else:
103 raise "unknown map entry '%s'" % l
103 raise "unknown map entry '%s'" % l
104
104
105 def __call__(self, t, **map):
105 def __call__(self, t, **map):
106 m = self.defaults.copy()
106 m = self.defaults.copy()
107 m.update(map)
107 m.update(map)
108 try:
108 try:
109 tmpl = self.cache[t]
109 tmpl = self.cache[t]
110 except KeyError:
110 except KeyError:
111 tmpl = self.cache[t] = file(self.map[t]).read()
111 tmpl = self.cache[t] = file(self.map[t]).read()
112 return template(tmpl, self.filters, **m)
112 return template(tmpl, self.filters, **m)
113
113
114 def rfc822date(x):
114 def rfc822date(x):
115 return time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime(x))
115 return time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime(x))
116
116
117 common_filters = {
118 "escape": cgi.escape,
119 "age": age,
120 "date": (lambda x: time.asctime(time.gmtime(x))),
121 "addbreaks": nl2br,
122 "obfuscate": obfuscate,
123 "short": (lambda x: x[:12]),
124 "firstline": (lambda x: x.splitlines(1)[0]),
125 "permissions": (lambda x: x and "-rwxr-xr-x" or "-rw-r--r--"),
126 "rfc822date": rfc822date,
127 }
128
117 class hgweb:
129 class hgweb:
118 maxchanges = 10
130 maxchanges = 10
119 maxfiles = 10
131 maxfiles = 10
120
132
121 def __init__(self, path, name, templates = ""):
133 def __init__(self, path, name=None, templates=""):
122 self.templates = templates
134 self.templates = templates
123 self.reponame = name
135 self.reponame = name
124 self.path = path
136 self.path = path
125 self.mtime = -1
137 self.mtime = -1
126 self.viewonly = 0
138 self.viewonly = 0
127
139
128 self.filters = {
129 "escape": cgi.escape,
130 "age": age,
131 "date": (lambda x: time.asctime(time.gmtime(x))),
132 "addbreaks": nl2br,
133 "obfuscate": obfuscate,
134 "short": (lambda x: x[:12]),
135 "firstline": (lambda x: x.splitlines(1)[0]),
136 "permissions": (lambda x: x and "-rwxr-xr-x" or "-rw-r--r--"),
137 "rfc822date": rfc822date,
138 }
139
140 def refresh(self):
140 def refresh(self):
141 s = os.stat(os.path.join(self.path, ".hg", "00changelog.i"))
141 s = os.stat(os.path.join(self.path, ".hg", "00changelog.i"))
142 if s.st_mtime != self.mtime:
142 if s.st_mtime != self.mtime:
143 self.mtime = s.st_mtime
143 self.mtime = s.st_mtime
144 self.repo = repository(ui(), self.path)
144 self.repo = repository(ui(), self.path)
145
145
146 def date(self, cs):
146 def date(self, cs):
147 return time.asctime(time.gmtime(float(cs[2].split(' ')[0])))
147 return time.asctime(time.gmtime(float(cs[2].split(' ')[0])))
148
148
149 def listfiles(self, files, mf):
149 def listfiles(self, files, mf):
150 for f in files[:self.maxfiles]:
150 for f in files[:self.maxfiles]:
151 yield self.t("filenodelink", node = hex(mf[f]), file = f)
151 yield self.t("filenodelink", node = hex(mf[f]), file = f)
152 if len(files) > self.maxfiles:
152 if len(files) > self.maxfiles:
153 yield self.t("fileellipses")
153 yield self.t("fileellipses")
154
154
155 def listfilediffs(self, files, changeset):
155 def listfilediffs(self, files, changeset):
156 for f in files[:self.maxfiles]:
156 for f in files[:self.maxfiles]:
157 yield self.t("filedifflink", node = hex(changeset), file = f)
157 yield self.t("filedifflink", node = hex(changeset), file = f)
158 if len(files) > self.maxfiles:
158 if len(files) > self.maxfiles:
159 yield self.t("fileellipses")
159 yield self.t("fileellipses")
160
160
161 def parents(self, t1, nodes=[], rev=None,**args):
161 def parents(self, t1, nodes=[], rev=None,**args):
162 if not rev: rev = lambda x: ""
162 if not rev: rev = lambda x: ""
163 for node in nodes:
163 for node in nodes:
164 if node != nullid:
164 if node != nullid:
165 yield self.t(t1, node = hex(node), rev = rev(node), **args)
165 yield self.t(t1, node = hex(node), rev = rev(node), **args)
166
166
167 def showtag(self, t1, node=nullid, **args):
167 def showtag(self, t1, node=nullid, **args):
168 for t in self.repo.nodetags(node):
168 for t in self.repo.nodetags(node):
169 yield self.t(t1, tag = t, **args)
169 yield self.t(t1, tag = t, **args)
170
170
171 def diff(self, node1, node2, files):
171 def diff(self, node1, node2, files):
172 def filterfiles(list, files):
172 def filterfiles(list, files):
173 l = [ x for x in list if x in files ]
173 l = [ x for x in list if x in files ]
174
174
175 for f in files:
175 for f in files:
176 if f[-1] != os.sep: f += os.sep
176 if f[-1] != os.sep: f += os.sep
177 l += [ x for x in list if x.startswith(f) ]
177 l += [ x for x in list if x.startswith(f) ]
178 return l
178 return l
179
179
180 parity = [0]
180 parity = [0]
181 def diffblock(diff, f, fn):
181 def diffblock(diff, f, fn):
182 yield self.t("diffblock",
182 yield self.t("diffblock",
183 lines = prettyprintlines(diff),
183 lines = prettyprintlines(diff),
184 parity = parity[0],
184 parity = parity[0],
185 file = f,
185 file = f,
186 filenode = hex(fn or nullid))
186 filenode = hex(fn or nullid))
187 parity[0] = 1 - parity[0]
187 parity[0] = 1 - parity[0]
188
188
189 def prettyprintlines(diff):
189 def prettyprintlines(diff):
190 for l in diff.splitlines(1):
190 for l in diff.splitlines(1):
191 if l.startswith('+'):
191 if l.startswith('+'):
192 yield self.t("difflineplus", line = l)
192 yield self.t("difflineplus", line = l)
193 elif l.startswith('-'):
193 elif l.startswith('-'):
194 yield self.t("difflineminus", line = l)
194 yield self.t("difflineminus", line = l)
195 elif l.startswith('@'):
195 elif l.startswith('@'):
196 yield self.t("difflineat", line = l)
196 yield self.t("difflineat", line = l)
197 else:
197 else:
198 yield self.t("diffline", line = l)
198 yield self.t("diffline", line = l)
199
199
200 r = self.repo
200 r = self.repo
201 cl = r.changelog
201 cl = r.changelog
202 mf = r.manifest
202 mf = r.manifest
203 change1 = cl.read(node1)
203 change1 = cl.read(node1)
204 change2 = cl.read(node2)
204 change2 = cl.read(node2)
205 mmap1 = mf.read(change1[0])
205 mmap1 = mf.read(change1[0])
206 mmap2 = mf.read(change2[0])
206 mmap2 = mf.read(change2[0])
207 date1 = self.date(change1)
207 date1 = self.date(change1)
208 date2 = self.date(change2)
208 date2 = self.date(change2)
209
209
210 c, a, d, u = r.changes(node1, node2)
210 c, a, d, u = r.changes(node1, node2)
211 if files:
211 if files:
212 c, a, d = map(lambda x: filterfiles(x, files), (c, a, d))
212 c, a, d = map(lambda x: filterfiles(x, files), (c, a, d))
213
213
214 for f in c:
214 for f in c:
215 to = r.file(f).read(mmap1[f])
215 to = r.file(f).read(mmap1[f])
216 tn = r.file(f).read(mmap2[f])
216 tn = r.file(f).read(mmap2[f])
217 yield diffblock(mdiff.unidiff(to, date1, tn, date2, f), f, tn)
217 yield diffblock(mdiff.unidiff(to, date1, tn, date2, f), f, tn)
218 for f in a:
218 for f in a:
219 to = None
219 to = None
220 tn = r.file(f).read(mmap2[f])
220 tn = r.file(f).read(mmap2[f])
221 yield diffblock(mdiff.unidiff(to, date1, tn, date2, f), f, tn)
221 yield diffblock(mdiff.unidiff(to, date1, tn, date2, f), f, tn)
222 for f in d:
222 for f in d:
223 to = r.file(f).read(mmap1[f])
223 to = r.file(f).read(mmap1[f])
224 tn = None
224 tn = None
225 yield diffblock(mdiff.unidiff(to, date1, tn, date2, f), f, tn)
225 yield diffblock(mdiff.unidiff(to, date1, tn, date2, f), f, tn)
226
226
227 def changelog(self, pos):
227 def changelog(self, pos):
228 def changenav(**map):
228 def changenav(**map):
229 def seq(factor = 1):
229 def seq(factor = 1):
230 yield 1 * factor
230 yield 1 * factor
231 yield 3 * factor
231 yield 3 * factor
232 #yield 5 * factor
232 #yield 5 * factor
233 for f in seq(factor * 10):
233 for f in seq(factor * 10):
234 yield f
234 yield f
235
235
236 l = []
236 l = []
237 for f in seq():
237 for f in seq():
238 if f < self.maxchanges / 2: continue
238 if f < self.maxchanges / 2: continue
239 if f > count: break
239 if f > count: break
240 r = "%d" % f
240 r = "%d" % f
241 if pos + f < count: l.append(("+" + r, pos + f))
241 if pos + f < count: l.append(("+" + r, pos + f))
242 if pos - f >= 0: l.insert(0, ("-" + r, pos - f))
242 if pos - f >= 0: l.insert(0, ("-" + r, pos - f))
243
243
244 yield self.t("naventry", rev = 0, label="(0)")
244 yield self.t("naventry", rev = 0, label="(0)")
245
245
246 for label, rev in l:
246 for label, rev in l:
247 yield self.t("naventry", label = label, rev = rev)
247 yield self.t("naventry", label = label, rev = rev)
248
248
249 yield self.t("naventry", label="tip")
249 yield self.t("naventry", label="tip")
250
250
251 def changelist(**map):
251 def changelist(**map):
252 parity = (start - end) & 1
252 parity = (start - end) & 1
253 cl = self.repo.changelog
253 cl = self.repo.changelog
254 l = [] # build a list in forward order for efficiency
254 l = [] # build a list in forward order for efficiency
255 for i in range(start, end):
255 for i in range(start, end):
256 n = cl.node(i)
256 n = cl.node(i)
257 changes = cl.read(n)
257 changes = cl.read(n)
258 hn = hex(n)
258 hn = hex(n)
259 t = float(changes[2].split(' ')[0])
259 t = float(changes[2].split(' ')[0])
260
260
261 l.insert(0, self.t(
261 l.insert(0, self.t(
262 'changelogentry',
262 'changelogentry',
263 parity = parity,
263 parity = parity,
264 author = changes[1],
264 author = changes[1],
265 parent = self.parents("changelogparent",
265 parent = self.parents("changelogparent",
266 cl.parents(n), cl.rev),
266 cl.parents(n), cl.rev),
267 changelogtag = self.showtag("changelogtag",n),
267 changelogtag = self.showtag("changelogtag",n),
268 manifest = hex(changes[0]),
268 manifest = hex(changes[0]),
269 desc = changes[4],
269 desc = changes[4],
270 date = t,
270 date = t,
271 files = self.listfilediffs(changes[3], n),
271 files = self.listfilediffs(changes[3], n),
272 rev = i,
272 rev = i,
273 node = hn))
273 node = hn))
274 parity = 1 - parity
274 parity = 1 - parity
275
275
276 yield l
276 yield l
277
277
278 cl = self.repo.changelog
278 cl = self.repo.changelog
279 mf = cl.read(cl.tip())[0]
279 mf = cl.read(cl.tip())[0]
280 count = cl.count()
280 count = cl.count()
281 start = max(0, pos - self.maxchanges + 1)
281 start = max(0, pos - self.maxchanges + 1)
282 end = min(count, start + self.maxchanges)
282 end = min(count, start + self.maxchanges)
283 pos = end - 1
283 pos = end - 1
284
284
285 yield self.t('changelog',
285 yield self.t('changelog',
286 changenav = changenav,
286 changenav = changenav,
287 manifest = hex(mf),
287 manifest = hex(mf),
288 rev = pos, changesets = count, entries = changelist)
288 rev = pos, changesets = count, entries = changelist)
289
289
290 def search(self, query):
290 def search(self, query):
291
291
292 def changelist(**map):
292 def changelist(**map):
293 cl = self.repo.changelog
293 cl = self.repo.changelog
294 count = 0
294 count = 0
295 qw = query.lower().split()
295 qw = query.lower().split()
296
296
297 def revgen():
297 def revgen():
298 for i in range(cl.count() - 1, 0, -100):
298 for i in range(cl.count() - 1, 0, -100):
299 l = []
299 l = []
300 for j in range(max(0, i - 100), i):
300 for j in range(max(0, i - 100), i):
301 n = cl.node(j)
301 n = cl.node(j)
302 changes = cl.read(n)
302 changes = cl.read(n)
303 l.insert(0, (n, j, changes))
303 l.insert(0, (n, j, changes))
304 for e in l:
304 for e in l:
305 yield e
305 yield e
306
306
307 for n, i, changes in revgen():
307 for n, i, changes in revgen():
308 miss = 0
308 miss = 0
309 for q in qw:
309 for q in qw:
310 if not (q in changes[1].lower() or
310 if not (q in changes[1].lower() or
311 q in changes[4].lower() or
311 q in changes[4].lower() or
312 q in " ".join(changes[3][:20]).lower()):
312 q in " ".join(changes[3][:20]).lower()):
313 miss = 1
313 miss = 1
314 break
314 break
315 if miss: continue
315 if miss: continue
316
316
317 count += 1
317 count += 1
318 hn = hex(n)
318 hn = hex(n)
319 t = float(changes[2].split(' ')[0])
319 t = float(changes[2].split(' ')[0])
320
320
321 yield self.t(
321 yield self.t(
322 'searchentry',
322 'searchentry',
323 parity = count & 1,
323 parity = count & 1,
324 author = changes[1],
324 author = changes[1],
325 parent = self.parents("changelogparent",
325 parent = self.parents("changelogparent",
326 cl.parents(n), cl.rev),
326 cl.parents(n), cl.rev),
327 changelogtag = self.showtag("changelogtag",n),
327 changelogtag = self.showtag("changelogtag",n),
328 manifest = hex(changes[0]),
328 manifest = hex(changes[0]),
329 desc = changes[4],
329 desc = changes[4],
330 date = t,
330 date = t,
331 files = self.listfilediffs(changes[3], n),
331 files = self.listfilediffs(changes[3], n),
332 rev = i,
332 rev = i,
333 node = hn)
333 node = hn)
334
334
335 if count >= self.maxchanges: break
335 if count >= self.maxchanges: break
336
336
337 cl = self.repo.changelog
337 cl = self.repo.changelog
338 mf = cl.read(cl.tip())[0]
338 mf = cl.read(cl.tip())[0]
339
339
340 yield self.t('search',
340 yield self.t('search',
341 query = query,
341 query = query,
342 manifest = hex(mf),
342 manifest = hex(mf),
343 entries = changelist)
343 entries = changelist)
344
344
345 def changeset(self, nodeid):
345 def changeset(self, nodeid):
346 n = bin(nodeid)
346 n = bin(nodeid)
347 cl = self.repo.changelog
347 cl = self.repo.changelog
348 changes = cl.read(n)
348 changes = cl.read(n)
349 p1 = cl.parents(n)[0]
349 p1 = cl.parents(n)[0]
350 t = float(changes[2].split(' ')[0])
350 t = float(changes[2].split(' ')[0])
351
351
352 files = []
352 files = []
353 mf = self.repo.manifest.read(changes[0])
353 mf = self.repo.manifest.read(changes[0])
354 for f in changes[3]:
354 for f in changes[3]:
355 files.append(self.t("filenodelink",
355 files.append(self.t("filenodelink",
356 filenode = hex(mf.get(f, nullid)), file = f))
356 filenode = hex(mf.get(f, nullid)), file = f))
357
357
358 def diff(**map):
358 def diff(**map):
359 yield self.diff(p1, n, None)
359 yield self.diff(p1, n, None)
360
360
361 yield self.t('changeset',
361 yield self.t('changeset',
362 diff = diff,
362 diff = diff,
363 rev = cl.rev(n),
363 rev = cl.rev(n),
364 node = nodeid,
364 node = nodeid,
365 parent = self.parents("changesetparent",
365 parent = self.parents("changesetparent",
366 cl.parents(n), cl.rev),
366 cl.parents(n), cl.rev),
367 changesettag = self.showtag("changesettag",n),
367 changesettag = self.showtag("changesettag",n),
368 manifest = hex(changes[0]),
368 manifest = hex(changes[0]),
369 author = changes[1],
369 author = changes[1],
370 desc = changes[4],
370 desc = changes[4],
371 date = t,
371 date = t,
372 files = files)
372 files = files)
373
373
374 def filelog(self, f, filenode):
374 def filelog(self, f, filenode):
375 cl = self.repo.changelog
375 cl = self.repo.changelog
376 fl = self.repo.file(f)
376 fl = self.repo.file(f)
377 count = fl.count()
377 count = fl.count()
378
378
379 def entries(**map):
379 def entries(**map):
380 l = []
380 l = []
381 parity = (count - 1) & 1
381 parity = (count - 1) & 1
382
382
383 for i in range(count):
383 for i in range(count):
384
384
385 n = fl.node(i)
385 n = fl.node(i)
386 lr = fl.linkrev(n)
386 lr = fl.linkrev(n)
387 cn = cl.node(lr)
387 cn = cl.node(lr)
388 cs = cl.read(cl.node(lr))
388 cs = cl.read(cl.node(lr))
389 t = float(cs[2].split(' ')[0])
389 t = float(cs[2].split(' ')[0])
390
390
391 l.insert(0, self.t("filelogentry",
391 l.insert(0, self.t("filelogentry",
392 parity = parity,
392 parity = parity,
393 filenode = hex(n),
393 filenode = hex(n),
394 filerev = i,
394 filerev = i,
395 file = f,
395 file = f,
396 node = hex(cn),
396 node = hex(cn),
397 author = cs[1],
397 author = cs[1],
398 date = t,
398 date = t,
399 parent = self.parents("filelogparent",
399 parent = self.parents("filelogparent",
400 fl.parents(n), fl.rev, file=f),
400 fl.parents(n), fl.rev, file=f),
401 desc = cs[4]))
401 desc = cs[4]))
402 parity = 1 - parity
402 parity = 1 - parity
403
403
404 yield l
404 yield l
405
405
406 yield self.t("filelog",
406 yield self.t("filelog",
407 file = f,
407 file = f,
408 filenode = filenode,
408 filenode = filenode,
409 entries = entries)
409 entries = entries)
410
410
411 def filerevision(self, f, node):
411 def filerevision(self, f, node):
412 fl = self.repo.file(f)
412 fl = self.repo.file(f)
413 n = bin(node)
413 n = bin(node)
414 text = fl.read(n)
414 text = fl.read(n)
415 changerev = fl.linkrev(n)
415 changerev = fl.linkrev(n)
416 cl = self.repo.changelog
416 cl = self.repo.changelog
417 cn = cl.node(changerev)
417 cn = cl.node(changerev)
418 cs = cl.read(cn)
418 cs = cl.read(cn)
419 t = float(cs[2].split(' ')[0])
419 t = float(cs[2].split(' ')[0])
420 mfn = cs[0]
420 mfn = cs[0]
421
421
422 def lines():
422 def lines():
423 for l, t in enumerate(text.splitlines(1)):
423 for l, t in enumerate(text.splitlines(1)):
424 yield self.t("fileline", line = t,
424 yield self.t("fileline", line = t,
425 linenumber = "% 6d" % (l + 1),
425 linenumber = "% 6d" % (l + 1),
426 parity = l & 1)
426 parity = l & 1)
427
427
428 yield self.t("filerevision", file = f,
428 yield self.t("filerevision", file = f,
429 filenode = node,
429 filenode = node,
430 path = up(f),
430 path = up(f),
431 text = lines(),
431 text = lines(),
432 rev = changerev,
432 rev = changerev,
433 node = hex(cn),
433 node = hex(cn),
434 manifest = hex(mfn),
434 manifest = hex(mfn),
435 author = cs[1],
435 author = cs[1],
436 date = t,
436 date = t,
437 parent = self.parents("filerevparent",
437 parent = self.parents("filerevparent",
438 fl.parents(n), fl.rev, file=f),
438 fl.parents(n), fl.rev, file=f),
439 permissions = self.repo.manifest.readflags(mfn)[f])
439 permissions = self.repo.manifest.readflags(mfn)[f])
440
440
441 def fileannotate(self, f, node):
441 def fileannotate(self, f, node):
442 bcache = {}
442 bcache = {}
443 ncache = {}
443 ncache = {}
444 fl = self.repo.file(f)
444 fl = self.repo.file(f)
445 n = bin(node)
445 n = bin(node)
446 changerev = fl.linkrev(n)
446 changerev = fl.linkrev(n)
447
447
448 cl = self.repo.changelog
448 cl = self.repo.changelog
449 cn = cl.node(changerev)
449 cn = cl.node(changerev)
450 cs = cl.read(cn)
450 cs = cl.read(cn)
451 t = float(cs[2].split(' ')[0])
451 t = float(cs[2].split(' ')[0])
452 mfn = cs[0]
452 mfn = cs[0]
453
453
454 def annotate(**map):
454 def annotate(**map):
455 parity = 1
455 parity = 1
456 last = None
456 last = None
457 for r, l in fl.annotate(n):
457 for r, l in fl.annotate(n):
458 try:
458 try:
459 cnode = ncache[r]
459 cnode = ncache[r]
460 except KeyError:
460 except KeyError:
461 cnode = ncache[r] = self.repo.changelog.node(r)
461 cnode = ncache[r] = self.repo.changelog.node(r)
462
462
463 try:
463 try:
464 name = bcache[r]
464 name = bcache[r]
465 except KeyError:
465 except KeyError:
466 cl = self.repo.changelog.read(cnode)
466 cl = self.repo.changelog.read(cnode)
467 name = cl[1]
467 name = cl[1]
468 f = name.find('@')
468 f = name.find('@')
469 if f >= 0:
469 if f >= 0:
470 name = name[:f]
470 name = name[:f]
471 f = name.find('<')
471 f = name.find('<')
472 if f >= 0:
472 if f >= 0:
473 name = name[f+1:]
473 name = name[f+1:]
474 bcache[r] = name
474 bcache[r] = name
475
475
476 if last != cnode:
476 if last != cnode:
477 parity = 1 - parity
477 parity = 1 - parity
478 last = cnode
478 last = cnode
479
479
480 yield self.t("annotateline",
480 yield self.t("annotateline",
481 parity = parity,
481 parity = parity,
482 node = hex(cnode),
482 node = hex(cnode),
483 rev = r,
483 rev = r,
484 author = name,
484 author = name,
485 file = f,
485 file = f,
486 line = l)
486 line = l)
487
487
488 yield self.t("fileannotate",
488 yield self.t("fileannotate",
489 file = f,
489 file = f,
490 filenode = node,
490 filenode = node,
491 annotate = annotate,
491 annotate = annotate,
492 path = up(f),
492 path = up(f),
493 rev = changerev,
493 rev = changerev,
494 node = hex(cn),
494 node = hex(cn),
495 manifest = hex(mfn),
495 manifest = hex(mfn),
496 author = cs[1],
496 author = cs[1],
497 date = t,
497 date = t,
498 parent = self.parents("fileannotateparent",
498 parent = self.parents("fileannotateparent",
499 fl.parents(n), fl.rev, file=f),
499 fl.parents(n), fl.rev, file=f),
500 permissions = self.repo.manifest.readflags(mfn)[f])
500 permissions = self.repo.manifest.readflags(mfn)[f])
501
501
502 def manifest(self, mnode, path):
502 def manifest(self, mnode, path):
503 mf = self.repo.manifest.read(bin(mnode))
503 mf = self.repo.manifest.read(bin(mnode))
504 rev = self.repo.manifest.rev(bin(mnode))
504 rev = self.repo.manifest.rev(bin(mnode))
505 node = self.repo.changelog.node(rev)
505 node = self.repo.changelog.node(rev)
506 mff=self.repo.manifest.readflags(bin(mnode))
506 mff=self.repo.manifest.readflags(bin(mnode))
507
507
508 files = {}
508 files = {}
509
509
510 p = path[1:]
510 p = path[1:]
511 l = len(p)
511 l = len(p)
512
512
513 for f,n in mf.items():
513 for f,n in mf.items():
514 if f[:l] != p:
514 if f[:l] != p:
515 continue
515 continue
516 remain = f[l:]
516 remain = f[l:]
517 if "/" in remain:
517 if "/" in remain:
518 short = remain[:remain.find("/") + 1] # bleah
518 short = remain[:remain.find("/") + 1] # bleah
519 files[short] = (f, None)
519 files[short] = (f, None)
520 else:
520 else:
521 short = os.path.basename(remain)
521 short = os.path.basename(remain)
522 files[short] = (f, n)
522 files[short] = (f, n)
523
523
524 def filelist(**map):
524 def filelist(**map):
525 parity = 0
525 parity = 0
526 fl = files.keys()
526 fl = files.keys()
527 fl.sort()
527 fl.sort()
528 for f in fl:
528 for f in fl:
529 full, fnode = files[f]
529 full, fnode = files[f]
530 if fnode:
530 if fnode:
531 yield self.t("manifestfileentry",
531 yield self.t("manifestfileentry",
532 file = full,
532 file = full,
533 manifest = mnode,
533 manifest = mnode,
534 filenode = hex(fnode),
534 filenode = hex(fnode),
535 parity = parity,
535 parity = parity,
536 basename = f,
536 basename = f,
537 permissions = mff[full])
537 permissions = mff[full])
538 else:
538 else:
539 yield self.t("manifestdirentry",
539 yield self.t("manifestdirentry",
540 parity = parity,
540 parity = parity,
541 path = os.path.join(path, f),
541 path = os.path.join(path, f),
542 manifest = mnode, basename = f[:-1])
542 manifest = mnode, basename = f[:-1])
543 parity = 1 - parity
543 parity = 1 - parity
544
544
545 yield self.t("manifest",
545 yield self.t("manifest",
546 manifest = mnode,
546 manifest = mnode,
547 rev = rev,
547 rev = rev,
548 node = hex(node),
548 node = hex(node),
549 path = path,
549 path = path,
550 up = up(path),
550 up = up(path),
551 entries = filelist)
551 entries = filelist)
552
552
553 def tags(self):
553 def tags(self):
554 cl = self.repo.changelog
554 cl = self.repo.changelog
555 mf = cl.read(cl.tip())[0]
555 mf = cl.read(cl.tip())[0]
556
556
557 i = self.repo.tagslist()
557 i = self.repo.tagslist()
558 i.reverse()
558 i.reverse()
559
559
560 def entries(**map):
560 def entries(**map):
561 parity = 0
561 parity = 0
562 for k,n in i:
562 for k,n in i:
563 yield self.t("tagentry",
563 yield self.t("tagentry",
564 parity = parity,
564 parity = parity,
565 tag = k,
565 tag = k,
566 node = hex(n))
566 node = hex(n))
567 parity = 1 - parity
567 parity = 1 - parity
568
568
569 yield self.t("tags",
569 yield self.t("tags",
570 manifest = hex(mf),
570 manifest = hex(mf),
571 entries = entries)
571 entries = entries)
572
572
573 def filediff(self, file, changeset):
573 def filediff(self, file, changeset):
574 n = bin(changeset)
574 n = bin(changeset)
575 cl = self.repo.changelog
575 cl = self.repo.changelog
576 p1 = cl.parents(n)[0]
576 p1 = cl.parents(n)[0]
577 cs = cl.read(n)
577 cs = cl.read(n)
578 mf = self.repo.manifest.read(cs[0])
578 mf = self.repo.manifest.read(cs[0])
579
579
580 def diff(**map):
580 def diff(**map):
581 yield self.diff(p1, n, file)
581 yield self.diff(p1, n, file)
582
582
583 yield self.t("filediff",
583 yield self.t("filediff",
584 file = file,
584 file = file,
585 filenode = hex(mf.get(file, nullid)),
585 filenode = hex(mf.get(file, nullid)),
586 node = changeset,
586 node = changeset,
587 rev = self.repo.changelog.rev(n),
587 rev = self.repo.changelog.rev(n),
588 parent = self.parents("filediffparent",
588 parent = self.parents("filediffparent",
589 cl.parents(n), cl.rev),
589 cl.parents(n), cl.rev),
590 diff = diff)
590 diff = diff)
591
591
592 # add tags to things
592 # add tags to things
593 # tags -> list of changesets corresponding to tags
593 # tags -> list of changesets corresponding to tags
594 # find tag, changeset, file
594 # find tag, changeset, file
595
595
596 def run(self):
596 def run(self):
597 def header(**map):
597 def header(**map):
598 yield self.t("header", **map)
598 yield self.t("header", **map)
599
599
600 def footer(**map):
600 def footer(**map):
601 yield self.t("footer", **map)
601 yield self.t("footer", **map)
602
602
603 self.refresh()
603 self.refresh()
604 args = cgi.parse()
604 args = cgi.parse()
605
605
606 t = self.templates or self.repo.ui.config("web", "templates",
606 t = self.templates or self.repo.ui.config("web", "templates",
607 templatepath())
607 templatepath())
608 m = os.path.join(t, "map")
608 m = os.path.join(t, "map")
609 if args.has_key('style'):
609 if args.has_key('style'):
610 b = os.path.basename("map-" + args['style'][0])
610 b = os.path.basename("map-" + args['style'][0])
611 p = os.path.join(self.templates, b)
611 p = os.path.join(self.templates, b)
612 if os.path.isfile(p): m = p
612 if os.path.isfile(p): m = p
613
613
614 port = os.environ["SERVER_PORT"]
614 port = os.environ["SERVER_PORT"]
615 port = port != "80" and (":" + port) or ""
615 port = port != "80" and (":" + port) or ""
616 uri = os.environ["REQUEST_URI"]
616 uri = os.environ["REQUEST_URI"]
617 if "?" in uri: uri = uri.split("?")[0]
617 if "?" in uri: uri = uri.split("?")[0]
618 url = "http://%s%s%s" % (os.environ["SERVER_NAME"], port, uri)
618 url = "http://%s%s%s" % (os.environ["SERVER_NAME"], port, uri)
619
619
620 name = self.reponame or self.repo.ui.config("web", "name", os.getcwd())
620 name = self.reponame or self.repo.ui.config("web", "name", os.getcwd())
621
621
622 self.t = templater(m, self.filters,
622 self.t = templater(m, common_filters,
623 {"url":url,
623 {"url":url,
624 "repo":name,
624 "repo":name,
625 "header":header,
625 "header":header,
626 "footer":footer,
626 "footer":footer,
627 })
627 })
628
628
629 if not args.has_key('cmd'):
629 if not args.has_key('cmd'):
630 args['cmd'] = [self.t.cache['default'],]
630 args['cmd'] = [self.t.cache['default'],]
631
631
632 if args['cmd'][0] == 'changelog':
632 if args['cmd'][0] == 'changelog':
633 c = self.repo.changelog.count() - 1
633 c = self.repo.changelog.count() - 1
634 hi = c
634 hi = c
635 if args.has_key('rev'):
635 if args.has_key('rev'):
636 hi = args['rev'][0]
636 hi = args['rev'][0]
637 try:
637 try:
638 hi = self.repo.changelog.rev(self.repo.lookup(hi))
638 hi = self.repo.changelog.rev(self.repo.lookup(hi))
639 except RepoError:
639 except RepoError:
640 write(self.search(hi))
640 write(self.search(hi))
641 return
641 return
642
642
643 write(self.changelog(hi))
643 write(self.changelog(hi))
644
644
645 elif args['cmd'][0] == 'changeset':
645 elif args['cmd'][0] == 'changeset':
646 write(self.changeset(args['node'][0]))
646 write(self.changeset(args['node'][0]))
647
647
648 elif args['cmd'][0] == 'manifest':
648 elif args['cmd'][0] == 'manifest':
649 write(self.manifest(args['manifest'][0], args['path'][0]))
649 write(self.manifest(args['manifest'][0], args['path'][0]))
650
650
651 elif args['cmd'][0] == 'tags':
651 elif args['cmd'][0] == 'tags':
652 write(self.tags())
652 write(self.tags())
653
653
654 elif args['cmd'][0] == 'filediff':
654 elif args['cmd'][0] == 'filediff':
655 write(self.filediff(args['file'][0], args['node'][0]))
655 write(self.filediff(args['file'][0], args['node'][0]))
656
656
657 elif args['cmd'][0] == 'file':
657 elif args['cmd'][0] == 'file':
658 write(self.filerevision(args['file'][0], args['filenode'][0]))
658 write(self.filerevision(args['file'][0], args['filenode'][0]))
659
659
660 elif args['cmd'][0] == 'annotate':
660 elif args['cmd'][0] == 'annotate':
661 write(self.fileannotate(args['file'][0], args['filenode'][0]))
661 write(self.fileannotate(args['file'][0], args['filenode'][0]))
662
662
663 elif args['cmd'][0] == 'filelog':
663 elif args['cmd'][0] == 'filelog':
664 write(self.filelog(args['file'][0], args['filenode'][0]))
664 write(self.filelog(args['file'][0], args['filenode'][0]))
665
665
666 elif args['cmd'][0] == 'heads':
666 elif args['cmd'][0] == 'heads':
667 httphdr("application/mercurial-0.1")
667 httphdr("application/mercurial-0.1")
668 h = self.repo.heads()
668 h = self.repo.heads()
669 sys.stdout.write(" ".join(map(hex, h)) + "\n")
669 sys.stdout.write(" ".join(map(hex, h)) + "\n")
670
670
671 elif args['cmd'][0] == 'branches':
671 elif args['cmd'][0] == 'branches':
672 httphdr("application/mercurial-0.1")
672 httphdr("application/mercurial-0.1")
673 nodes = []
673 nodes = []
674 if args.has_key('nodes'):
674 if args.has_key('nodes'):
675 nodes = map(bin, args['nodes'][0].split(" "))
675 nodes = map(bin, args['nodes'][0].split(" "))
676 for b in self.repo.branches(nodes):
676 for b in self.repo.branches(nodes):
677 sys.stdout.write(" ".join(map(hex, b)) + "\n")
677 sys.stdout.write(" ".join(map(hex, b)) + "\n")
678
678
679 elif args['cmd'][0] == 'between':
679 elif args['cmd'][0] == 'between':
680 httphdr("application/mercurial-0.1")
680 httphdr("application/mercurial-0.1")
681 nodes = []
681 nodes = []
682 if args.has_key('pairs'):
682 if args.has_key('pairs'):
683 pairs = [ map(bin, p.split("-"))
683 pairs = [ map(bin, p.split("-"))
684 for p in args['pairs'][0].split(" ") ]
684 for p in args['pairs'][0].split(" ") ]
685 for b in self.repo.between(pairs):
685 for b in self.repo.between(pairs):
686 sys.stdout.write(" ".join(map(hex, b)) + "\n")
686 sys.stdout.write(" ".join(map(hex, b)) + "\n")
687
687
688 elif args['cmd'][0] == 'changegroup':
688 elif args['cmd'][0] == 'changegroup':
689 httphdr("application/mercurial-0.1")
689 httphdr("application/mercurial-0.1")
690 nodes = []
690 nodes = []
691 if self.viewonly:
691 if self.viewonly:
692 return
692 return
693
693
694 if args.has_key('roots'):
694 if args.has_key('roots'):
695 nodes = map(bin, args['roots'][0].split(" "))
695 nodes = map(bin, args['roots'][0].split(" "))
696
696
697 z = zlib.compressobj()
697 z = zlib.compressobj()
698 f = self.repo.changegroup(nodes)
698 f = self.repo.changegroup(nodes)
699 while 1:
699 while 1:
700 chunk = f.read(4096)
700 chunk = f.read(4096)
701 if not chunk: break
701 if not chunk: break
702 sys.stdout.write(z.compress(chunk))
702 sys.stdout.write(z.compress(chunk))
703
703
704 sys.stdout.write(z.flush())
704 sys.stdout.write(z.flush())
705
705
706 else:
706 else:
707 write(self.t("error"))
707 write(self.t("error"))
708
708
709 def create_server(path, name, templates, address, port, use_ipv6 = False,
709 def create_server(path, name, templates, address, port, use_ipv6 = False,
710 accesslog = sys.stdout, errorlog = sys.stderr):
710 accesslog = sys.stdout, errorlog = sys.stderr):
711
711
712 def openlog(opt, default):
712 def openlog(opt, default):
713 if opt and opt != '-':
713 if opt and opt != '-':
714 return open(opt, 'w')
714 return open(opt, 'w')
715 return default
715 return default
716
716
717 u = ui()
717 u = ui()
718 repo = repository(u, path)
718 repo = repository(u, path)
719 if not address:
719 if not address:
720 address = u.config("web", "address", "")
720 address = u.config("web", "address", "")
721 if not port:
721 if not port:
722 port = int(u.config("web", "port", 8000))
722 port = int(u.config("web", "port", 8000))
723 if not use_ipv6:
723 if not use_ipv6:
724 use_ipv6 = u.configbool("web", "ipv6")
724 use_ipv6 = u.configbool("web", "ipv6")
725
725
726 accesslog = openlog(accesslog or u.config("web", "accesslog", "-"),
726 accesslog = openlog(accesslog or u.config("web", "accesslog", "-"),
727 sys.stdout)
727 sys.stdout)
728 errorlog = openlog(errorlog or u.config("web", "errorlog", "-"),
728 errorlog = openlog(errorlog or u.config("web", "errorlog", "-"),
729 sys.stderr)
729 sys.stderr)
730
730
731 import BaseHTTPServer
731 import BaseHTTPServer
732
732
733 class IPv6HTTPServer(BaseHTTPServer.HTTPServer):
733 class IPv6HTTPServer(BaseHTTPServer.HTTPServer):
734 address_family = getattr(socket, 'AF_INET6', None)
734 address_family = getattr(socket, 'AF_INET6', None)
735
735
736 def __init__(self, *args, **kwargs):
736 def __init__(self, *args, **kwargs):
737 if self.address_family is None:
737 if self.address_family is None:
738 raise RepoError('IPv6 not available on this system')
738 raise RepoError('IPv6 not available on this system')
739 BaseHTTPServer.HTTPServer.__init__(self, *args, **kwargs)
739 BaseHTTPServer.HTTPServer.__init__(self, *args, **kwargs)
740
740
741 class hgwebhandler(BaseHTTPServer.BaseHTTPRequestHandler):
741 class hgwebhandler(BaseHTTPServer.BaseHTTPRequestHandler):
742 def log_error(self, format, *args):
742 def log_error(self, format, *args):
743 errorlog.write("%s - - [%s] %s\n" % (self.address_string(),
743 errorlog.write("%s - - [%s] %s\n" % (self.address_string(),
744 self.log_date_time_string(),
744 self.log_date_time_string(),
745 format % args))
745 format % args))
746
746
747 def log_message(self, format, *args):
747 def log_message(self, format, *args):
748 accesslog.write("%s - - [%s] %s\n" % (self.address_string(),
748 accesslog.write("%s - - [%s] %s\n" % (self.address_string(),
749 self.log_date_time_string(),
749 self.log_date_time_string(),
750 format % args))
750 format % args))
751
751
752 def do_POST(self):
752 def do_POST(self):
753 try:
753 try:
754 self.do_hgweb()
754 self.do_hgweb()
755 except socket.error, inst:
755 except socket.error, inst:
756 if inst.args[0] != 32: raise
756 if inst.args[0] != 32: raise
757
757
758 def do_GET(self):
758 def do_GET(self):
759 self.do_POST()
759 self.do_POST()
760
760
761 def do_hgweb(self):
761 def do_hgweb(self):
762 query = ""
762 query = ""
763 p = self.path.find("?")
763 p = self.path.find("?")
764 if p:
764 if p:
765 query = self.path[p + 1:]
765 query = self.path[p + 1:]
766 query = query.replace('+', ' ')
766 query = query.replace('+', ' ')
767
767
768 env = {}
768 env = {}
769 env['GATEWAY_INTERFACE'] = 'CGI/1.1'
769 env['GATEWAY_INTERFACE'] = 'CGI/1.1'
770 env['REQUEST_METHOD'] = self.command
770 env['REQUEST_METHOD'] = self.command
771 env['SERVER_NAME'] = self.server.server_name
771 env['SERVER_NAME'] = self.server.server_name
772 env['SERVER_PORT'] = str(self.server.server_port)
772 env['SERVER_PORT'] = str(self.server.server_port)
773 env['REQUEST_URI'] = "/"
773 env['REQUEST_URI'] = "/"
774 if query:
774 if query:
775 env['QUERY_STRING'] = query
775 env['QUERY_STRING'] = query
776 host = self.address_string()
776 host = self.address_string()
777 if host != self.client_address[0]:
777 if host != self.client_address[0]:
778 env['REMOTE_HOST'] = host
778 env['REMOTE_HOST'] = host
779 env['REMOTE_ADDR'] = self.client_address[0]
779 env['REMOTE_ADDR'] = self.client_address[0]
780
780
781 if self.headers.typeheader is None:
781 if self.headers.typeheader is None:
782 env['CONTENT_TYPE'] = self.headers.type
782 env['CONTENT_TYPE'] = self.headers.type
783 else:
783 else:
784 env['CONTENT_TYPE'] = self.headers.typeheader
784 env['CONTENT_TYPE'] = self.headers.typeheader
785 length = self.headers.getheader('content-length')
785 length = self.headers.getheader('content-length')
786 if length:
786 if length:
787 env['CONTENT_LENGTH'] = length
787 env['CONTENT_LENGTH'] = length
788 accept = []
788 accept = []
789 for line in self.headers.getallmatchingheaders('accept'):
789 for line in self.headers.getallmatchingheaders('accept'):
790 if line[:1] in "\t\n\r ":
790 if line[:1] in "\t\n\r ":
791 accept.append(line.strip())
791 accept.append(line.strip())
792 else:
792 else:
793 accept = accept + line[7:].split(',')
793 accept = accept + line[7:].split(',')
794 env['HTTP_ACCEPT'] = ','.join(accept)
794 env['HTTP_ACCEPT'] = ','.join(accept)
795
795
796 os.environ.update(env)
796 os.environ.update(env)
797
797
798 save = sys.argv, sys.stdin, sys.stdout, sys.stderr
798 save = sys.argv, sys.stdin, sys.stdout, sys.stderr
799 try:
799 try:
800 sys.stdin = self.rfile
800 sys.stdin = self.rfile
801 sys.stdout = self.wfile
801 sys.stdout = self.wfile
802 sys.argv = ["hgweb.py"]
802 sys.argv = ["hgweb.py"]
803 if '=' not in query:
803 if '=' not in query:
804 sys.argv.append(query)
804 sys.argv.append(query)
805 self.send_response(200, "Script output follows")
805 self.send_response(200, "Script output follows")
806 hg.run()
806 hg.run()
807 finally:
807 finally:
808 sys.argv, sys.stdin, sys.stdout, sys.stderr = save
808 sys.argv, sys.stdin, sys.stdout, sys.stderr = save
809
809
810 hg = hgweb(path, name, templates)
810 hg = hgweb(path, name, templates)
811 if use_ipv6:
811 if use_ipv6:
812 return IPv6HTTPServer((address, port), hgwebhandler)
812 return IPv6HTTPServer((address, port), hgwebhandler)
813 else:
813 else:
814 return BaseHTTPServer.HTTPServer((address, port), hgwebhandler)
814 return BaseHTTPServer.HTTPServer((address, port), hgwebhandler)
815
815
816 def server(path, name, templates, address, port, use_ipv6 = False,
816 def server(path, name, templates, address, port, use_ipv6 = False,
817 accesslog = sys.stdout, errorlog = sys.stderr):
817 accesslog = sys.stdout, errorlog = sys.stderr):
818 httpd = create_server(path, name, templates, address, port, use_ipv6,
818 httpd = create_server(path, name, templates, address, port, use_ipv6,
819 accesslog, errorlog)
819 accesslog, errorlog)
820 httpd.serve_forever()
820 httpd.serve_forever()
821
822 # This is a stopgap
823 class hgwebdir:
824 def __init__(self, config):
825 self.cp = ConfigParser.SafeConfigParser()
826 self.cp.read(config)
827
828 def run(self):
829 try:
830 virtual = os.environ["PATH_INFO"]
831 except:
832 virtual = ""
833
834 if virtual:
835 real = self.cp.get("paths", virtual[1:])
836 h = hgweb.hgweb(real)
837 h.run()
838 return
839
840 def header(**map):
841 yield tmpl("header", **map)
842
843 def footer(**map):
844 yield tmpl("footer", **map)
845
846 templates = templatepath()
847 m = os.path.join(templates, "map")
848 tmpl = templater(m, common_filters,
849 {"header": header, "footer": footer})
850
851 def entries(**map):
852 parity = 0
853 for v,r in self.cp.items("paths"):
854 cp2 = ConfigParser.SafeConfigParser()
855 cp2.read(os.path.join(r, ".hg", "hgrc"))
856
857 def get(sec, val, default):
858 try:
859 return cp2.get(sec, val)
860 except:
861 return default
862
863 yield tmpl("indexentry",
864 author = get("web", "author", "unknown"),
865 name = get("web", "name", v),
866 url = os.environ["REQUEST_URI"] + "/" + v,
867 parity = parity,
868 shortdesc = get("web", "description", "unknown"),
869 lastupdate = os.stat(os.path.join(r, ".hg",
870 "00changelog.d")).st_mtime)
871
872 parity = 1 - parity
873
874 write(tmpl("index", entries = entries))
@@ -1,37 +1,39
1 default = "changelog"
1 default = "changelog"
2 header = header.tmpl
2 header = header.tmpl
3 footer = footer.tmpl
3 footer = footer.tmpl
4 search = search.tmpl
4 search = search.tmpl
5 changelog = changelog.tmpl
5 changelog = changelog.tmpl
6 naventry = "<a href="?cmd=changelog;rev=#rev#">#label#</a> "
6 naventry = "<a href="?cmd=changelog;rev=#rev#">#label#</a> "
7 filedifflink = "<a href="?cmd=filediff;node=#node#;file=#file#">#file#</a> "
7 filedifflink = "<a href="?cmd=filediff;node=#node#;file=#file#">#file#</a> "
8 filenodelink = "<a href="?cmd=file;filenode=#filenode#;file=#file#">#file#</a> "
8 filenodelink = "<a href="?cmd=file;filenode=#filenode#;file=#file#">#file#</a> "
9 fileellipses = "..."
9 fileellipses = "..."
10 changelogentry = changelogentry.tmpl
10 changelogentry = changelogentry.tmpl
11 searchentry = changelogentry.tmpl
11 searchentry = changelogentry.tmpl
12 changeset = changeset.tmpl
12 changeset = changeset.tmpl
13 manifest = manifest.tmpl
13 manifest = manifest.tmpl
14 manifestdirentry = "<tr class="parity#parity#"><td><tt>drwxr-xr-x</tt>&nbsp;<td><a href="?cmd=manifest;manifest=#manifest#;path=#path#">#basename#/</a>"
14 manifestdirentry = "<tr class="parity#parity#"><td><tt>drwxr-xr-x</tt>&nbsp;<td><a href="?cmd=manifest;manifest=#manifest#;path=#path#">#basename#/</a>"
15 manifestfileentry = "<tr class="parity#parity#"><td><tt>#permissions|permissions#</tt>&nbsp;<td><a href="?cmd=file;filenode=#filenode#;file=#file#">#basename#</a>"
15 manifestfileentry = "<tr class="parity#parity#"><td><tt>#permissions|permissions#</tt>&nbsp;<td><a href="?cmd=file;filenode=#filenode#;file=#file#">#basename#</a>"
16 filerevision = filerevision.tmpl
16 filerevision = filerevision.tmpl
17 fileannotate = fileannotate.tmpl
17 fileannotate = fileannotate.tmpl
18 filediff = filediff.tmpl
18 filediff = filediff.tmpl
19 filelog = filelog.tmpl
19 filelog = filelog.tmpl
20 fileline = "<div class="parity#parity#"><span class="lineno">#linenumber# </span>#line|escape#</div>"
20 fileline = "<div class="parity#parity#"><span class="lineno">#linenumber# </span>#line|escape#</div>"
21 filelogentry = filelogentry.tmpl
21 filelogentry = filelogentry.tmpl
22 annotateline = "<tr class="parity#parity#"><td class="annotate"><a href="?cmd=changeset;node=#node#">#author|obfuscate#@#rev#</a></td><td><pre>#line|escape#</pre></td></tr>"
22 annotateline = "<tr class="parity#parity#"><td class="annotate"><a href="?cmd=changeset;node=#node#">#author|obfuscate#@#rev#</a></td><td><pre>#line|escape#</pre></td></tr>"
23 difflineplus = "<span class="plusline">#line|escape#</span>"
23 difflineplus = "<span class="plusline">#line|escape#</span>"
24 difflineminus = "<span class="minusline">#line|escape#</span>"
24 difflineminus = "<span class="minusline">#line|escape#</span>"
25 difflineat = "<span class="atline">#line|escape#</span>"
25 difflineat = "<span class="atline">#line|escape#</span>"
26 diffline = "#line|escape#"
26 diffline = "#line|escape#"
27 changelogparent = "<tr><th class="parent">parent #rev#:</th><td class="parent"><a href="?cmd=changeset;node=#node#">#node|short#</a></td></tr>"
27 changelogparent = "<tr><th class="parent">parent #rev#:</th><td class="parent"><a href="?cmd=changeset;node=#node#">#node|short#</a></td></tr>"
28 changesetparent = "<tr><th class="parent">parent #rev#:</th><td class="parent"><a href="?cmd=changeset;node=#node#">#node|short#</a></td></tr>"
28 changesetparent = "<tr><th class="parent">parent #rev#:</th><td class="parent"><a href="?cmd=changeset;node=#node#">#node|short#</a></td></tr>"
29 filerevparent = "<tr><td class="metatag">parent:</td><td><a href="?cmd=file;file=#file#;filenode=#node#">#node|short#</a></td></tr>"
29 filerevparent = "<tr><td class="metatag">parent:</td><td><a href="?cmd=file;file=#file#;filenode=#node#">#node|short#</a></td></tr>"
30 fileannotateparent = "<tr><td class="metatag">parent:</td><td><a href="?cmd=annotate;file=#file#;filenode=#node#">#node|short#</a></td></tr>"
30 fileannotateparent = "<tr><td class="metatag">parent:</td><td><a href="?cmd=annotate;file=#file#;filenode=#node#">#node|short#</a></td></tr>"
31 tags = tags.tmpl
31 tags = tags.tmpl
32 tagentry = "<li class="tagEntry parity#parity#"><span class="node">#node#</span> <a href="?cmd=changeset;node=#node#">#tag#</a></li>"
32 tagentry = "<li class="tagEntry parity#parity#"><span class="node">#node#</span> <a href="?cmd=changeset;node=#node#">#tag#</a></li>"
33 diffblock = "<pre class="parity#parity#">#lines#</pre>"
33 diffblock = "<pre class="parity#parity#">#lines#</pre>"
34 changelogtag = "<tr><th class="tag">tag:</th><td class="tag">#tag#</td></tr>"
34 changelogtag = "<tr><th class="tag">tag:</th><td class="tag">#tag#</td></tr>"
35 changesettag = "<tr><th class="tag">tag:</th><td class="tag">#tag#</td></tr>"
35 changesettag = "<tr><th class="tag">tag:</th><td class="tag">#tag#</td></tr>"
36 filediffparent = "<tr><th class="parent">parent #rev#:</th><td class="parent"><a href="?cmd=changeset;node=#node#">#node|short#</a></td></tr>"
36 filediffparent = "<tr><th class="parent">parent #rev#:</th><td class="parent"><a href="?cmd=changeset;node=#node#">#node|short#</a></td></tr>"
37 filelogparent = "<tr><td align="right">parent #rev#:&nbsp;</td><td><a href="?cmd=file;file=#file#;filenode=#node#">#node|short#</a></td></tr>"
37 filelogparent = "<tr><td align="right">parent #rev#:&nbsp;</td><td><a href="?cmd=file;file=#file#;filenode=#node#">#node|short#</a></td></tr>"
38 indexentry = "<tr class="parity#parity#"><td><a href="#url#">#name#</a></td><td>#shortdesc#</td><td>#author# <i>#email|obfuscate#</i></td><td>#lastupdate|age# ago</td></tr>"
39 index = index.tmpl
General Comments 0
You need to be logged in to leave comments. Login now