author | Ollivier Robert <roberto@keltia.freenix.fr> |
Sat, 27 Aug 2005 23:43:13 -0700 | |
changeset 1121 | 14a69c4988cd |
parent 1120 | df25ee778ac2 |
child 1122 | fb008a1a0a32 |
permissions | -rw-r--r-- |
238
3b92f8fe47ae
hgweb.py: kill #! line, clean up copyright notice
mpm@selenic.com
parents:
222
diff
changeset
|
1 |
# hgweb.py - web interface to a mercurial repository |
131 | 2 |
# |
238
3b92f8fe47ae
hgweb.py: kill #! line, clean up copyright notice
mpm@selenic.com
parents:
222
diff
changeset
|
3 |
# Copyright 21 May 2005 - (c) 2005 Jake Edge <jake@edge2.net> |
575 | 4 |
# Copyright 2005 Matt Mackall <mpm@selenic.com> |
131 | 5 |
# |
6 |
# This software may be used and distributed according to the terms |
|
7 |
# of the GNU General Public License, incorporated herein by reference. |
|
8 |
||
1099 | 9 |
import os, cgi, time, re, socket, sys, zlib |
1112
87cbfaf79124
hgweb: add mdiff / fix sorting of archives
mpm@selenic.com
parents:
1099
diff
changeset
|
10 |
import mdiff |
1099 | 11 |
from hg import * |
12 |
from ui import * |
|
13 |
||
138 | 14 |
|
157
2653740d8118
Install the templates where they can be found by hgweb.py
mpm@selenic.com
parents:
156
diff
changeset
|
15 |
def templatepath(): |
201
f918a6fa2572
hgweb: add template filters, template style maps, and raw pages
mpm@selenic.com
parents:
198
diff
changeset
|
16 |
for f in "templates", "../templates": |
157
2653740d8118
Install the templates where they can be found by hgweb.py
mpm@selenic.com
parents:
156
diff
changeset
|
17 |
p = os.path.join(os.path.dirname(__file__), f) |
1063
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
18 |
if os.path.isdir(p): |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
19 |
return p |
157
2653740d8118
Install the templates where they can be found by hgweb.py
mpm@selenic.com
parents:
156
diff
changeset
|
20 |
|
138 | 21 |
def age(t): |
22 |
def plural(t, c): |
|
1063
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
23 |
if c == 1: |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
24 |
return t |
138 | 25 |
return t + "s" |
26 |
def fmt(t, c): |
|
27 |
return "%d %s" % (c, plural(t, c)) |
|
28 |
||
29 |
now = time.time() |
|
30 |
delta = max(1, int(now - t)) |
|
31 |
||
32 |
scales = [["second", 1], |
|
33 |
["minute", 60], |
|
34 |
["hour", 3600], |
|
35 |
["day", 3600 * 24], |
|
36 |
["week", 3600 * 24 * 7], |
|
37 |
["month", 3600 * 24 * 30], |
|
38 |
["year", 3600 * 24 * 365]] |
|
39 |
||
40 |
scales.reverse() |
|
41 |
||
42 |
for t, s in scales: |
|
43 |
n = delta / s |
|
1063
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
44 |
if n >= 2 or s == 1: |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
45 |
return fmt(t, n) |
131 | 46 |
|
47 |
def nl2br(text): |
|
201
f918a6fa2572
hgweb: add template filters, template style maps, and raw pages
mpm@selenic.com
parents:
198
diff
changeset
|
48 |
return text.replace('\n', '<br/>\n') |
131 | 49 |
|
50 |
def obfuscate(text): |
|
1063
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
51 |
return ''.join(['&#%d;' % ord(c) for c in text]) |
138 | 52 |
|
53 |
def up(p): |
|
1063
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
54 |
if p[0] != "/": |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
55 |
p = "/" + p |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
56 |
if p[-1] == "/": |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
57 |
p = p[:-1] |
138 | 58 |
up = os.path.dirname(p) |
59 |
if up == "/": |
|
60 |
return "/" |
|
61 |
return up + "/" |
|
131 | 62 |
|
1076
01db658cc78a
tarball support v0.3
Wojciech Milkowski <wmilkowski@interia.pl>
parents:
1073
diff
changeset
|
63 |
def httphdr(type, file="", size=0): |
01db658cc78a
tarball support v0.3
Wojciech Milkowski <wmilkowski@interia.pl>
parents:
1073
diff
changeset
|
64 |
sys.stdout.write('Content-type: %s\n' % type) |
01db658cc78a
tarball support v0.3
Wojciech Milkowski <wmilkowski@interia.pl>
parents:
1073
diff
changeset
|
65 |
if file: |
01db658cc78a
tarball support v0.3
Wojciech Milkowski <wmilkowski@interia.pl>
parents:
1073
diff
changeset
|
66 |
sys.stdout.write('Content-disposition: attachment; filename=%s\n' |
01db658cc78a
tarball support v0.3
Wojciech Milkowski <wmilkowski@interia.pl>
parents:
1073
diff
changeset
|
67 |
% file) |
01db658cc78a
tarball support v0.3
Wojciech Milkowski <wmilkowski@interia.pl>
parents:
1073
diff
changeset
|
68 |
if size > 0: |
01db658cc78a
tarball support v0.3
Wojciech Milkowski <wmilkowski@interia.pl>
parents:
1073
diff
changeset
|
69 |
sys.stdout.write('Content-length: %d\n' % size) |
01db658cc78a
tarball support v0.3
Wojciech Milkowski <wmilkowski@interia.pl>
parents:
1073
diff
changeset
|
70 |
sys.stdout.write('\n') |
131 | 71 |
|
1120
df25ee778ac2
Handle a nonexistent repository with a 404 error.
Ollivier Robert <roberto@keltia.freenix.fr>
parents:
1119
diff
changeset
|
72 |
def httpnotfound(filename): |
df25ee778ac2
Handle a nonexistent repository with a 404 error.
Ollivier Robert <roberto@keltia.freenix.fr>
parents:
1119
diff
changeset
|
73 |
sys.stdout.write("Status: 404\r\n\r\n") |
df25ee778ac2
Handle a nonexistent repository with a 404 error.
Ollivier Robert <roberto@keltia.freenix.fr>
parents:
1119
diff
changeset
|
74 |
sys.stdout.write("File not found: (%s)" % (filename, )) |
df25ee778ac2
Handle a nonexistent repository with a 404 error.
Ollivier Robert <roberto@keltia.freenix.fr>
parents:
1119
diff
changeset
|
75 |
|
135 | 76 |
def write(*things): |
77 |
for thing in things: |
|
78 |
if hasattr(thing, "__iter__"): |
|
79 |
for part in thing: |
|
80 |
write(part) |
|
81 |
else: |
|
1087 | 82 |
try: |
83 |
sys.stdout.write(str(thing)) |
|
84 |
except socket.error, x: |
|
85 |
if x[0] != errno.ECONNRESET: |
|
86 |
raise |
|
135 | 87 |
|
138 | 88 |
class templater: |
1062 | 89 |
def __init__(self, mapfile, filters={}, defaults={}): |
138 | 90 |
self.cache = {} |
91 |
self.map = {} |
|
92 |
self.base = os.path.dirname(mapfile) |
|
201
f918a6fa2572
hgweb: add template filters, template style maps, and raw pages
mpm@selenic.com
parents:
198
diff
changeset
|
93 |
self.filters = filters |
601 | 94 |
self.defaults = defaults |
515 | 95 |
|
138 | 96 |
for l in file(mapfile): |
97 |
m = re.match(r'(\S+)\s*=\s*"(.*)"$', l) |
|
133
fb84d3e71042
added template support for some hgweb output, also, template files for
jake@edge2.net
parents:
132
diff
changeset
|
98 |
if m: |
138 | 99 |
self.cache[m.group(1)] = m.group(2) |
100 |
else: |
|
101 |
m = re.match(r'(\S+)\s*=\s*(\S+)', l) |
|
102 |
if m: |
|
103 |
self.map[m.group(1)] = os.path.join(self.base, m.group(2)) |
|
133
fb84d3e71042
added template support for some hgweb output, also, template files for
jake@edge2.net
parents:
132
diff
changeset
|
104 |
else: |
1073
7b35a980b982
[PATCH] raise exceptions with Exception subclasses
Bart Trojanowski <bart@jukie.net>
parents:
1063
diff
changeset
|
105 |
raise LookupError("unknown map entry '%s'" % l) |
133
fb84d3e71042
added template support for some hgweb output, also, template files for
jake@edge2.net
parents:
132
diff
changeset
|
106 |
|
138 | 107 |
def __call__(self, t, **map): |
601 | 108 |
m = self.defaults.copy() |
109 |
m.update(map) |
|
138 | 110 |
try: |
111 |
tmpl = self.cache[t] |
|
112 |
except KeyError: |
|
113 |
tmpl = self.cache[t] = file(self.map[t]).read() |
|
974
aedb47764f29
Added support for #foo%bar# syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
938
diff
changeset
|
114 |
return self.template(tmpl, self.filters, **m) |
aedb47764f29
Added support for #foo%bar# syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
938
diff
changeset
|
115 |
|
1062 | 116 |
def template(self, tmpl, filters={}, **map): |
974
aedb47764f29
Added support for #foo%bar# syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
938
diff
changeset
|
117 |
while tmpl: |
aedb47764f29
Added support for #foo%bar# syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
938
diff
changeset
|
118 |
m = re.search(r"#([a-zA-Z0-9]+)((%[a-zA-Z0-9]+)*)((\|[a-zA-Z0-9]+)*)#", tmpl) |
aedb47764f29
Added support for #foo%bar# syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
938
diff
changeset
|
119 |
if m: |
aedb47764f29
Added support for #foo%bar# syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
938
diff
changeset
|
120 |
yield tmpl[:m.start(0)] |
aedb47764f29
Added support for #foo%bar# syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
938
diff
changeset
|
121 |
v = map.get(m.group(1), "") |
aedb47764f29
Added support for #foo%bar# syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
938
diff
changeset
|
122 |
v = callable(v) and v(**map) or v |
aedb47764f29
Added support for #foo%bar# syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
938
diff
changeset
|
123 |
|
aedb47764f29
Added support for #foo%bar# syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
938
diff
changeset
|
124 |
format = m.group(2) |
aedb47764f29
Added support for #foo%bar# syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
938
diff
changeset
|
125 |
fl = m.group(4) |
aedb47764f29
Added support for #foo%bar# syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
938
diff
changeset
|
126 |
|
aedb47764f29
Added support for #foo%bar# syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
938
diff
changeset
|
127 |
if format: |
aedb47764f29
Added support for #foo%bar# syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
938
diff
changeset
|
128 |
q = v.__iter__ |
aedb47764f29
Added support for #foo%bar# syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
938
diff
changeset
|
129 |
for i in q(): |
aedb47764f29
Added support for #foo%bar# syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
938
diff
changeset
|
130 |
lm = map.copy() |
aedb47764f29
Added support for #foo%bar# syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
938
diff
changeset
|
131 |
lm.update(i) |
aedb47764f29
Added support for #foo%bar# syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
938
diff
changeset
|
132 |
yield self(format[1:], **lm) |
aedb47764f29
Added support for #foo%bar# syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
938
diff
changeset
|
133 |
|
aedb47764f29
Added support for #foo%bar# syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
938
diff
changeset
|
134 |
v = "" |
aedb47764f29
Added support for #foo%bar# syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
938
diff
changeset
|
135 |
|
aedb47764f29
Added support for #foo%bar# syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
938
diff
changeset
|
136 |
elif fl: |
aedb47764f29
Added support for #foo%bar# syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
938
diff
changeset
|
137 |
for f in fl.split("|")[1:]: |
aedb47764f29
Added support for #foo%bar# syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
938
diff
changeset
|
138 |
v = filters[f](v) |
aedb47764f29
Added support for #foo%bar# syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
938
diff
changeset
|
139 |
|
aedb47764f29
Added support for #foo%bar# syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
938
diff
changeset
|
140 |
yield v |
aedb47764f29
Added support for #foo%bar# syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
938
diff
changeset
|
141 |
tmpl = tmpl[m.end(0):] |
aedb47764f29
Added support for #foo%bar# syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
938
diff
changeset
|
142 |
else: |
aedb47764f29
Added support for #foo%bar# syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
938
diff
changeset
|
143 |
yield tmpl |
aedb47764f29
Added support for #foo%bar# syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
938
diff
changeset
|
144 |
return |
515 | 145 |
|
599 | 146 |
def rfc822date(x): |
601 | 147 |
return time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime(x)) |
599 | 148 |
|
941 | 149 |
common_filters = { |
150 |
"escape": cgi.escape, |
|
151 |
"age": age, |
|
152 |
"date": (lambda x: time.asctime(time.gmtime(x))), |
|
153 |
"addbreaks": nl2br, |
|
154 |
"obfuscate": obfuscate, |
|
155 |
"short": (lambda x: x[:12]), |
|
156 |
"firstline": (lambda x: x.splitlines(1)[0]), |
|
157 |
"permissions": (lambda x: x and "-rwxr-xr-x" or "-rw-r--r--"), |
|
158 |
"rfc822date": rfc822date, |
|
159 |
} |
|
160 |
||
138 | 161 |
class hgweb: |
987 | 162 |
def __init__(self, repo, name=None): |
163 |
if type(repo) == type(""): |
|
164 |
self.repo = repository(ui(), repo) |
|
165 |
else: |
|
166 |
self.repo = repo |
|
133
fb84d3e71042
added template support for some hgweb output, also, template files for
jake@edge2.net
parents:
132
diff
changeset
|
167 |
|
258 | 168 |
self.mtime = -1 |
987 | 169 |
self.reponame = name or self.repo.ui.config("web", "name", |
170 |
self.repo.root) |
|
1078 | 171 |
self.archives = 'zip', 'gz', 'bz2' |
131 | 172 |
|
258 | 173 |
def refresh(self): |
987 | 174 |
s = os.stat(os.path.join(self.repo.root, ".hg", "00changelog.i")) |
258 | 175 |
if s.st_mtime != self.mtime: |
322 | 176 |
self.mtime = s.st_mtime |
987 | 177 |
self.repo = repository(self.repo.ui, self.repo.root) |
964
3f37720e7dc7
hgweb: Make maxfiles, maxchanges, and allowpull proper config options
mpm@selenic.com
parents:
957
diff
changeset
|
178 |
self.maxchanges = self.repo.ui.config("web", "maxchanges", 10) |
3f37720e7dc7
hgweb: Make maxfiles, maxchanges, and allowpull proper config options
mpm@selenic.com
parents:
957
diff
changeset
|
179 |
self.maxfiles = self.repo.ui.config("web", "maxchanges", 10) |
3f37720e7dc7
hgweb: Make maxfiles, maxchanges, and allowpull proper config options
mpm@selenic.com
parents:
957
diff
changeset
|
180 |
self.allowpull = self.repo.ui.configbool("web", "allowpull", True) |
258 | 181 |
|
138 | 182 |
def date(self, cs): |
183 |
return time.asctime(time.gmtime(float(cs[2].split(' ')[0]))) |
|
184 |
||
185 |
def listfiles(self, files, mf): |
|
186 |
for f in files[:self.maxfiles]: |
|
1062 | 187 |
yield self.t("filenodelink", node=hex(mf[f]), file=f) |
138 | 188 |
if len(files) > self.maxfiles: |
189 |
yield self.t("fileellipses") |
|
190 |
||
191 |
def listfilediffs(self, files, changeset): |
|
192 |
for f in files[:self.maxfiles]: |
|
1062 | 193 |
yield self.t("filedifflink", node=hex(changeset), file=f) |
138 | 194 |
if len(files) > self.maxfiles: |
195 |
yield self.t("fileellipses") |
|
196 |
||
569
3e347929f5f9
[PATCH 1/5]: cleaning the template parent management in hgweb
mpm@selenic.com
parents:
568
diff
changeset
|
197 |
def parents(self, t1, nodes=[], rev=None,**args): |
1063
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
198 |
if not rev: |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
199 |
rev = lambda x: "" |
569
3e347929f5f9
[PATCH 1/5]: cleaning the template parent management in hgweb
mpm@selenic.com
parents:
568
diff
changeset
|
200 |
for node in nodes: |
3e347929f5f9
[PATCH 1/5]: cleaning the template parent management in hgweb
mpm@selenic.com
parents:
568
diff
changeset
|
201 |
if node != nullid: |
1062 | 202 |
yield self.t(t1, node=hex(node), rev=rev(node), **args) |
569
3e347929f5f9
[PATCH 1/5]: cleaning the template parent management in hgweb
mpm@selenic.com
parents:
568
diff
changeset
|
203 |
|
568 | 204 |
def showtag(self, t1, node=nullid, **args): |
205 |
for t in self.repo.nodetags(node): |
|
1062 | 206 |
yield self.t(t1, tag=t, **args) |
568 | 207 |
|
138 | 208 |
def diff(self, node1, node2, files): |
209 |
def filterfiles(list, files): |
|
1063
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
210 |
l = [x for x in list if x in files] |
515 | 211 |
|
138 | 212 |
for f in files: |
1063
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
213 |
if f[-1] != os.sep: |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
214 |
f += os.sep |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
215 |
l += [x for x in list if x.startswith(f)] |
138 | 216 |
return l |
131 | 217 |
|
172
e9b1147db448
hgweb: alternating colors for multifile diffs
mpm@selenic.com
parents:
168
diff
changeset
|
218 |
parity = [0] |
e9b1147db448
hgweb: alternating colors for multifile diffs
mpm@selenic.com
parents:
168
diff
changeset
|
219 |
def diffblock(diff, f, fn): |
e9b1147db448
hgweb: alternating colors for multifile diffs
mpm@selenic.com
parents:
168
diff
changeset
|
220 |
yield self.t("diffblock", |
1063
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
221 |
lines=prettyprintlines(diff), |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
222 |
parity=parity[0], |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
223 |
file=f, |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
224 |
filenode=hex(fn or nullid)) |
172
e9b1147db448
hgweb: alternating colors for multifile diffs
mpm@selenic.com
parents:
168
diff
changeset
|
225 |
parity[0] = 1 - parity[0] |
515 | 226 |
|
172
e9b1147db448
hgweb: alternating colors for multifile diffs
mpm@selenic.com
parents:
168
diff
changeset
|
227 |
def prettyprintlines(diff): |
138 | 228 |
for l in diff.splitlines(1): |
201
f918a6fa2572
hgweb: add template filters, template style maps, and raw pages
mpm@selenic.com
parents:
198
diff
changeset
|
229 |
if l.startswith('+'): |
1062 | 230 |
yield self.t("difflineplus", line=l) |
201
f918a6fa2572
hgweb: add template filters, template style maps, and raw pages
mpm@selenic.com
parents:
198
diff
changeset
|
231 |
elif l.startswith('-'): |
1062 | 232 |
yield self.t("difflineminus", line=l) |
201
f918a6fa2572
hgweb: add template filters, template style maps, and raw pages
mpm@selenic.com
parents:
198
diff
changeset
|
233 |
elif l.startswith('@'): |
1062 | 234 |
yield self.t("difflineat", line=l) |
138 | 235 |
else: |
1062 | 236 |
yield self.t("diffline", line=l) |
131 | 237 |
|
138 | 238 |
r = self.repo |
239 |
cl = r.changelog |
|
240 |
mf = r.manifest |
|
241 |
change1 = cl.read(node1) |
|
242 |
change2 = cl.read(node2) |
|
243 |
mmap1 = mf.read(change1[0]) |
|
244 |
mmap2 = mf.read(change2[0]) |
|
245 |
date1 = self.date(change1) |
|
246 |
date2 = self.date(change2) |
|
131 | 247 |
|
539 | 248 |
c, a, d, u = r.changes(node1, node2) |
645
a55048b2ae3a
this patch permits hgweb to show the deleted files in the changeset diff
kreijack@inwind.REMOVEME.it
parents:
635
diff
changeset
|
249 |
if files: |
a55048b2ae3a
this patch permits hgweb to show the deleted files in the changeset diff
kreijack@inwind.REMOVEME.it
parents:
635
diff
changeset
|
250 |
c, a, d = map(lambda x: filterfiles(x, files), (c, a, d)) |
131 | 251 |
|
138 | 252 |
for f in c: |
253 |
to = r.file(f).read(mmap1[f]) |
|
254 |
tn = r.file(f).read(mmap2[f]) |
|
172
e9b1147db448
hgweb: alternating colors for multifile diffs
mpm@selenic.com
parents:
168
diff
changeset
|
255 |
yield diffblock(mdiff.unidiff(to, date1, tn, date2, f), f, tn) |
138 | 256 |
for f in a: |
265
7ca05593bd30
hgweb: fix non-existent source or destination for diff
mpm@selenic.com
parents:
258
diff
changeset
|
257 |
to = None |
138 | 258 |
tn = r.file(f).read(mmap2[f]) |
172
e9b1147db448
hgweb: alternating colors for multifile diffs
mpm@selenic.com
parents:
168
diff
changeset
|
259 |
yield diffblock(mdiff.unidiff(to, date1, tn, date2, f), f, tn) |
138 | 260 |
for f in d: |
261 |
to = r.file(f).read(mmap1[f]) |
|
265
7ca05593bd30
hgweb: fix non-existent source or destination for diff
mpm@selenic.com
parents:
258
diff
changeset
|
262 |
tn = None |
172
e9b1147db448
hgweb: alternating colors for multifile diffs
mpm@selenic.com
parents:
168
diff
changeset
|
263 |
yield diffblock(mdiff.unidiff(to, date1, tn, date2, f), f, tn) |
131 | 264 |
|
180 | 265 |
def changelog(self, pos): |
857
41b344235bb7
[PATCH] Propagate the template map though recursively
Jeff Sipek <jeffpc@optonline.net>
parents:
839
diff
changeset
|
266 |
def changenav(**map): |
1062 | 267 |
def seq(factor=1): |
138 | 268 |
yield 1 * factor |
173
8da1df932c16
hgweb: make navigation of changesets a bit nicer
mpm@selenic.com
parents:
172
diff
changeset
|
269 |
yield 3 * factor |
8da1df932c16
hgweb: make navigation of changesets a bit nicer
mpm@selenic.com
parents:
172
diff
changeset
|
270 |
#yield 5 * factor |
138 | 271 |
for f in seq(factor * 10): |
272 |
yield f |
|
131 | 273 |
|
173
8da1df932c16
hgweb: make navigation of changesets a bit nicer
mpm@selenic.com
parents:
172
diff
changeset
|
274 |
l = [] |
8da1df932c16
hgweb: make navigation of changesets a bit nicer
mpm@selenic.com
parents:
172
diff
changeset
|
275 |
for f in seq(): |
1063
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
276 |
if f < self.maxchanges / 2: |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
277 |
continue |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
278 |
if f > count: |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
279 |
break |
173
8da1df932c16
hgweb: make navigation of changesets a bit nicer
mpm@selenic.com
parents:
172
diff
changeset
|
280 |
r = "%d" % f |
1063
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
281 |
if pos + f < count: |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
282 |
l.append(("+" + r, pos + f)) |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
283 |
if pos - f >= 0: |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
284 |
l.insert(0, ("-" + r, pos - f)) |
173
8da1df932c16
hgweb: make navigation of changesets a bit nicer
mpm@selenic.com
parents:
172
diff
changeset
|
285 |
|
975
bdd7c53fca00
hgweb: Changed changelog page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
974
diff
changeset
|
286 |
yield {"rev": 0, "label": "(0)"} |
515 | 287 |
|
173
8da1df932c16
hgweb: make navigation of changesets a bit nicer
mpm@selenic.com
parents:
172
diff
changeset
|
288 |
for label, rev in l: |
975
bdd7c53fca00
hgweb: Changed changelog page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
974
diff
changeset
|
289 |
yield {"label": label, "rev": rev} |
173
8da1df932c16
hgweb: make navigation of changesets a bit nicer
mpm@selenic.com
parents:
172
diff
changeset
|
290 |
|
975
bdd7c53fca00
hgweb: Changed changelog page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
974
diff
changeset
|
291 |
yield {"label": "tip", "rev": ""} |
131 | 292 |
|
857
41b344235bb7
[PATCH] Propagate the template map though recursively
Jeff Sipek <jeffpc@optonline.net>
parents:
839
diff
changeset
|
293 |
def changelist(**map): |
142 | 294 |
parity = (start - end) & 1 |
138 | 295 |
cl = self.repo.changelog |
296 |
l = [] # build a list in forward order for efficiency |
|
351 | 297 |
for i in range(start, end): |
138 | 298 |
n = cl.node(i) |
299 |
changes = cl.read(n) |
|
300 |
hn = hex(n) |
|
301 |
t = float(changes[2].split(' ')[0]) |
|
131 | 302 |
|
1063
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
303 |
l.insert(0, {"parity": parity, |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
304 |
"author": changes[1], |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
305 |
"parent": self.parents("changelogparent", |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
306 |
cl.parents(n), cl.rev), |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
307 |
"changelogtag": self.showtag("changelogtag",n), |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
308 |
"manifest": hex(changes[0]), |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
309 |
"desc": changes[4], |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
310 |
"date": t, |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
311 |
"files": self.listfilediffs(changes[3], n), |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
312 |
"rev": i, |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
313 |
"node": hn}) |
142 | 314 |
parity = 1 - parity |
138 | 315 |
|
1063
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
316 |
for e in l: |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
317 |
yield e |
131 | 318 |
|
168 | 319 |
cl = self.repo.changelog |
320 |
mf = cl.read(cl.tip())[0] |
|
321 |
count = cl.count() |
|
351 | 322 |
start = max(0, pos - self.maxchanges + 1) |
323 |
end = min(count, start + self.maxchanges) |
|
324 |
pos = end - 1 |
|
138 | 325 |
|
142 | 326 |
yield self.t('changelog', |
1062 | 327 |
changenav=changenav, |
328 |
manifest=hex(mf), |
|
329 |
rev=pos, changesets=count, entries=changelist) |
|
131 | 330 |
|
538 | 331 |
def search(self, query): |
332 |
||
857
41b344235bb7
[PATCH] Propagate the template map though recursively
Jeff Sipek <jeffpc@optonline.net>
parents:
839
diff
changeset
|
333 |
def changelist(**map): |
538 | 334 |
cl = self.repo.changelog |
335 |
count = 0 |
|
336 |
qw = query.lower().split() |
|
337 |
||
338 |
def revgen(): |
|
339 |
for i in range(cl.count() - 1, 0, -100): |
|
340 |
l = [] |
|
341 |
for j in range(max(0, i - 100), i): |
|
342 |
n = cl.node(j) |
|
343 |
changes = cl.read(n) |
|
1023 | 344 |
l.append((n, j, changes)) |
345 |
l.reverse() |
|
538 | 346 |
for e in l: |
347 |
yield e |
|
348 |
||
349 |
for n, i, changes in revgen(): |
|
350 |
miss = 0 |
|
351 |
for q in qw: |
|
352 |
if not (q in changes[1].lower() or |
|
353 |
q in changes[4].lower() or |
|
354 |
q in " ".join(changes[3][:20]).lower()): |
|
355 |
miss = 1 |
|
356 |
break |
|
1063
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
357 |
if miss: |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
358 |
continue |
538 | 359 |
|
360 |
count += 1 |
|
361 |
hn = hex(n) |
|
362 |
t = float(changes[2].split(' ')[0]) |
|
363 |
||
1063
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
364 |
yield self.t('searchentry', |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
365 |
parity=count & 1, |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
366 |
author=changes[1], |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
367 |
parent=self.parents("changelogparent", |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
368 |
cl.parents(n), cl.rev), |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
369 |
changelogtag=self.showtag("changelogtag",n), |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
370 |
manifest=hex(changes[0]), |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
371 |
desc=changes[4], |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
372 |
date=t, |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
373 |
files=self.listfilediffs(changes[3], n), |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
374 |
rev=i, |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
375 |
node=hn) |
538 | 376 |
|
1063
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
377 |
if count >= self.maxchanges: |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
378 |
break |
538 | 379 |
|
380 |
cl = self.repo.changelog |
|
381 |
mf = cl.read(cl.tip())[0] |
|
382 |
||
383 |
yield self.t('search', |
|
1062 | 384 |
query=query, |
385 |
manifest=hex(mf), |
|
386 |
entries=changelist) |
|
538 | 387 |
|
138 | 388 |
def changeset(self, nodeid): |
389 |
n = bin(nodeid) |
|
390 |
cl = self.repo.changelog |
|
391 |
changes = cl.read(n) |
|
598
f8d44a2e6928
[PATCH 4/5]: cleaning the template parent management in hgweb
mpm@selenic.com
parents:
582
diff
changeset
|
392 |
p1 = cl.parents(n)[0] |
138 | 393 |
t = float(changes[2].split(' ')[0]) |
515 | 394 |
|
133
fb84d3e71042
added template support for some hgweb output, also, template files for
jake@edge2.net
parents:
132
diff
changeset
|
395 |
files = [] |
138 | 396 |
mf = self.repo.manifest.read(changes[0]) |
131 | 397 |
for f in changes[3]: |
138 | 398 |
files.append(self.t("filenodelink", |
1063
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
399 |
filenode=hex(mf.get(f, nullid)), file=f)) |
138 | 400 |
|
857
41b344235bb7
[PATCH] Propagate the template map though recursively
Jeff Sipek <jeffpc@optonline.net>
parents:
839
diff
changeset
|
401 |
def diff(**map): |
645
a55048b2ae3a
this patch permits hgweb to show the deleted files in the changeset diff
kreijack@inwind.REMOVEME.it
parents:
635
diff
changeset
|
402 |
yield self.diff(p1, n, None) |
131 | 403 |
|
1078 | 404 |
def archivelist(): |
405 |
for i in self.archives: |
|
406 |
if self.repo.ui.configbool("web", "allow" + i, False): |
|
407 |
yield {"type" : i, "node" : nodeid} |
|
1077
b87aeccf73d9
tarball support v0.3 pt 2
Wojciech Milkowski <wmilkowski@interia.pl>
parents:
1076
diff
changeset
|
408 |
|
138 | 409 |
yield self.t('changeset', |
1062 | 410 |
diff=diff, |
411 |
rev=cl.rev(n), |
|
412 |
node=nodeid, |
|
413 |
parent=self.parents("changesetparent", |
|
1063
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
414 |
cl.parents(n), cl.rev), |
1062 | 415 |
changesettag=self.showtag("changesettag",n), |
416 |
manifest=hex(changes[0]), |
|
417 |
author=changes[1], |
|
418 |
desc=changes[4], |
|
419 |
date=t, |
|
1076
01db658cc78a
tarball support v0.3
Wojciech Milkowski <wmilkowski@interia.pl>
parents:
1073
diff
changeset
|
420 |
files=files, |
1078 | 421 |
archives=archivelist()) |
131 | 422 |
|
138 | 423 |
def filelog(self, f, filenode): |
424 |
cl = self.repo.changelog |
|
425 |
fl = self.repo.file(f) |
|
426 |
count = fl.count() |
|
427 |
||
857
41b344235bb7
[PATCH] Propagate the template map though recursively
Jeff Sipek <jeffpc@optonline.net>
parents:
839
diff
changeset
|
428 |
def entries(**map): |
138 | 429 |
l = [] |
142 | 430 |
parity = (count - 1) & 1 |
515 | 431 |
|
138 | 432 |
for i in range(count): |
433 |
n = fl.node(i) |
|
434 |
lr = fl.linkrev(n) |
|
435 |
cn = cl.node(lr) |
|
436 |
cs = cl.read(cl.node(lr)) |
|
437 |
t = float(cs[2].split(' ')[0]) |
|
133
fb84d3e71042
added template support for some hgweb output, also, template files for
jake@edge2.net
parents:
132
diff
changeset
|
438 |
|
978
ea67e5b37043
hgweb: Changed file revision page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
977
diff
changeset
|
439 |
l.insert(0, {"parity": parity, |
ea67e5b37043
hgweb: Changed file revision page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
977
diff
changeset
|
440 |
"filenode": hex(n), |
ea67e5b37043
hgweb: Changed file revision page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
977
diff
changeset
|
441 |
"filerev": i, |
ea67e5b37043
hgweb: Changed file revision page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
977
diff
changeset
|
442 |
"file": f, |
ea67e5b37043
hgweb: Changed file revision page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
977
diff
changeset
|
443 |
"node": hex(cn), |
ea67e5b37043
hgweb: Changed file revision page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
977
diff
changeset
|
444 |
"author": cs[1], |
ea67e5b37043
hgweb: Changed file revision page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
977
diff
changeset
|
445 |
"date": t, |
ea67e5b37043
hgweb: Changed file revision page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
977
diff
changeset
|
446 |
"parent": self.parents("filelogparent", |
1063
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
447 |
fl.parents(n), |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
448 |
fl.rev, file=f), |
978
ea67e5b37043
hgweb: Changed file revision page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
977
diff
changeset
|
449 |
"desc": cs[4]}) |
142 | 450 |
parity = 1 - parity |
138 | 451 |
|
1063
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
452 |
for e in l: |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
453 |
yield e |
138 | 454 |
|
1063
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
455 |
yield self.t("filelog", file=f, filenode=filenode, entries=entries) |
131 | 456 |
|
138 | 457 |
def filerevision(self, f, node): |
458 |
fl = self.repo.file(f) |
|
459 |
n = bin(node) |
|
201
f918a6fa2572
hgweb: add template filters, template style maps, and raw pages
mpm@selenic.com
parents:
198
diff
changeset
|
460 |
text = fl.read(n) |
138 | 461 |
changerev = fl.linkrev(n) |
462 |
cl = self.repo.changelog |
|
463 |
cn = cl.node(changerev) |
|
464 |
cs = cl.read(cn) |
|
465 |
t = float(cs[2].split(' ')[0]) |
|
466 |
mfn = cs[0] |
|
142 | 467 |
|
468 |
def lines(): |
|
469 |
for l, t in enumerate(text.splitlines(1)): |
|
976
5d5ab159d197
hgweb: Changed file page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
975
diff
changeset
|
470 |
yield {"line": t, |
5d5ab159d197
hgweb: Changed file page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
975
diff
changeset
|
471 |
"linenumber": "% 6d" % (l + 1), |
5d5ab159d197
hgweb: Changed file page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
975
diff
changeset
|
472 |
"parity": l & 1} |
359 | 473 |
|
1063
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
474 |
yield self.t("filerevision", |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
475 |
file=f, |
1062 | 476 |
filenode=node, |
477 |
path=up(f), |
|
478 |
text=lines(), |
|
479 |
rev=changerev, |
|
480 |
node=hex(cn), |
|
481 |
manifest=hex(mfn), |
|
482 |
author=cs[1], |
|
483 |
date=t, |
|
484 |
parent=self.parents("filerevparent", |
|
1063
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
485 |
fl.parents(n), fl.rev, file=f), |
1062 | 486 |
permissions=self.repo.manifest.readflags(mfn)[f]) |
138 | 487 |
|
488 |
def fileannotate(self, f, node): |
|
489 |
bcache = {} |
|
490 |
ncache = {} |
|
491 |
fl = self.repo.file(f) |
|
492 |
n = bin(node) |
|
493 |
changerev = fl.linkrev(n) |
|
494 |
||
495 |
cl = self.repo.changelog |
|
496 |
cn = cl.node(changerev) |
|
497 |
cs = cl.read(cn) |
|
498 |
t = float(cs[2].split(' ')[0]) |
|
499 |
mfn = cs[0] |
|
131 | 500 |
|
857
41b344235bb7
[PATCH] Propagate the template map though recursively
Jeff Sipek <jeffpc@optonline.net>
parents:
839
diff
changeset
|
501 |
def annotate(**map): |
142 | 502 |
parity = 1 |
503 |
last = None |
|
138 | 504 |
for r, l in fl.annotate(n): |
505 |
try: |
|
506 |
cnode = ncache[r] |
|
507 |
except KeyError: |
|
508 |
cnode = ncache[r] = self.repo.changelog.node(r) |
|
515 | 509 |
|
138 | 510 |
try: |
511 |
name = bcache[r] |
|
512 |
except KeyError: |
|
513 |
cl = self.repo.changelog.read(cnode) |
|
514 |
name = cl[1] |
|
515 |
f = name.find('@') |
|
516 |
if f >= 0: |
|
517 |
name = name[:f] |
|
534
ab0d1bfeee7c
[PATCH] Handle 'name firstname <email@server>' correctly in annotate
mpm@selenic.com
parents:
533
diff
changeset
|
518 |
f = name.find('<') |
ab0d1bfeee7c
[PATCH] Handle 'name firstname <email@server>' correctly in annotate
mpm@selenic.com
parents:
533
diff
changeset
|
519 |
if f >= 0: |
ab0d1bfeee7c
[PATCH] Handle 'name firstname <email@server>' correctly in annotate
mpm@selenic.com
parents:
533
diff
changeset
|
520 |
name = name[f+1:] |
138 | 521 |
bcache[r] = name |
131 | 522 |
|
142 | 523 |
if last != cnode: |
524 |
parity = 1 - parity |
|
525 |
last = cnode |
|
526 |
||
977
289975641886
hgweb: Changed annotate page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
976
diff
changeset
|
527 |
yield {"parity": parity, |
289975641886
hgweb: Changed annotate page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
976
diff
changeset
|
528 |
"node": hex(cnode), |
289975641886
hgweb: Changed annotate page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
976
diff
changeset
|
529 |
"rev": r, |
289975641886
hgweb: Changed annotate page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
976
diff
changeset
|
530 |
"author": name, |
289975641886
hgweb: Changed annotate page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
976
diff
changeset
|
531 |
"file": f, |
289975641886
hgweb: Changed annotate page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
976
diff
changeset
|
532 |
"line": l} |
138 | 533 |
|
534 |
yield self.t("fileannotate", |
|
1063
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
535 |
file=f, |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
536 |
filenode=node, |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
537 |
annotate=annotate, |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
538 |
path=up(f), |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
539 |
rev=changerev, |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
540 |
node=hex(cn), |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
541 |
manifest=hex(mfn), |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
542 |
author=cs[1], |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
543 |
date=t, |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
544 |
parent=self.parents("fileannotateparent", |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
545 |
fl.parents(n), fl.rev, file=f), |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
546 |
permissions=self.repo.manifest.readflags(mfn)[f]) |
136 | 547 |
|
138 | 548 |
def manifest(self, mnode, path): |
549 |
mf = self.repo.manifest.read(bin(mnode)) |
|
550 |
rev = self.repo.manifest.rev(bin(mnode)) |
|
551 |
node = self.repo.changelog.node(rev) |
|
359 | 552 |
mff=self.repo.manifest.readflags(bin(mnode)) |
138 | 553 |
|
554 |
files = {} |
|
515 | 555 |
|
138 | 556 |
p = path[1:] |
557 |
l = len(p) |
|
131 | 558 |
|
138 | 559 |
for f,n in mf.items(): |
560 |
if f[:l] != p: |
|
561 |
continue |
|
562 |
remain = f[l:] |
|
563 |
if "/" in remain: |
|
564 |
short = remain[:remain.find("/") + 1] # bleah |
|
142 | 565 |
files[short] = (f, None) |
138 | 566 |
else: |
567 |
short = os.path.basename(remain) |
|
568 |
files[short] = (f, n) |
|
131 | 569 |
|
857
41b344235bb7
[PATCH] Propagate the template map though recursively
Jeff Sipek <jeffpc@optonline.net>
parents:
839
diff
changeset
|
570 |
def filelist(**map): |
142 | 571 |
parity = 0 |
138 | 572 |
fl = files.keys() |
573 |
fl.sort() |
|
574 |
for f in fl: |
|
575 |
full, fnode = files[f] |
|
979
87d40e085e08
hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
978
diff
changeset
|
576 |
if not fnode: |
87d40e085e08
hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
978
diff
changeset
|
577 |
continue |
87d40e085e08
hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
978
diff
changeset
|
578 |
|
87d40e085e08
hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
978
diff
changeset
|
579 |
yield {"file": full, |
87d40e085e08
hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
978
diff
changeset
|
580 |
"manifest": mnode, |
87d40e085e08
hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
978
diff
changeset
|
581 |
"filenode": hex(fnode), |
87d40e085e08
hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
978
diff
changeset
|
582 |
"parity": parity, |
87d40e085e08
hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
978
diff
changeset
|
583 |
"basename": f, |
87d40e085e08
hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
978
diff
changeset
|
584 |
"permissions": mff[full]} |
142 | 585 |
parity = 1 - parity |
138 | 586 |
|
979
87d40e085e08
hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
978
diff
changeset
|
587 |
def dirlist(**map): |
87d40e085e08
hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
978
diff
changeset
|
588 |
parity = 0 |
87d40e085e08
hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
978
diff
changeset
|
589 |
fl = files.keys() |
87d40e085e08
hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
978
diff
changeset
|
590 |
fl.sort() |
87d40e085e08
hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
978
diff
changeset
|
591 |
for f in fl: |
87d40e085e08
hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
978
diff
changeset
|
592 |
full, fnode = files[f] |
87d40e085e08
hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
978
diff
changeset
|
593 |
if fnode: |
87d40e085e08
hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
978
diff
changeset
|
594 |
continue |
87d40e085e08
hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
978
diff
changeset
|
595 |
|
87d40e085e08
hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
978
diff
changeset
|
596 |
yield {"parity": parity, |
87d40e085e08
hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
978
diff
changeset
|
597 |
"path": os.path.join(path, f), |
87d40e085e08
hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
978
diff
changeset
|
598 |
"manifest": mnode, |
980 | 599 |
"basename": f[:-1]} |
979
87d40e085e08
hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
978
diff
changeset
|
600 |
parity = 1 - parity |
982
8d2e24bae760
hgweb: convert index entries to list expansion style
mpm@selenic.com
parents:
981
diff
changeset
|
601 |
|
138 | 602 |
yield self.t("manifest", |
1062 | 603 |
manifest=mnode, |
604 |
rev=rev, |
|
605 |
node=hex(node), |
|
606 |
path=path, |
|
607 |
up=up(path), |
|
608 |
fentries=filelist, |
|
609 |
dentries=dirlist) |
|
131 | 610 |
|
168 | 611 |
def tags(self): |
612 |
cl = self.repo.changelog |
|
613 |
mf = cl.read(cl.tip())[0] |
|
614 |
||
343 | 615 |
i = self.repo.tagslist() |
616 |
i.reverse() |
|
168 | 617 |
|
857
41b344235bb7
[PATCH] Propagate the template map though recursively
Jeff Sipek <jeffpc@optonline.net>
parents:
839
diff
changeset
|
618 |
def entries(**map): |
168 | 619 |
parity = 0 |
620 |
for k,n in i: |
|
974
aedb47764f29
Added support for #foo%bar# syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
938
diff
changeset
|
621 |
yield {"parity": parity, |
aedb47764f29
Added support for #foo%bar# syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
938
diff
changeset
|
622 |
"tag": k, |
aedb47764f29
Added support for #foo%bar# syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
938
diff
changeset
|
623 |
"node": hex(n)} |
168 | 624 |
parity = 1 - parity |
625 |
||
626 |
yield self.t("tags", |
|
1062 | 627 |
manifest=hex(mf), |
628 |
entries=entries) |
|
168 | 629 |
|
138 | 630 |
def filediff(self, file, changeset): |
631 |
n = bin(changeset) |
|
632 |
cl = self.repo.changelog |
|
633 |
p1 = cl.parents(n)[0] |
|
634 |
cs = cl.read(n) |
|
635 |
mf = self.repo.manifest.read(cs[0]) |
|
515 | 636 |
|
857
41b344235bb7
[PATCH] Propagate the template map though recursively
Jeff Sipek <jeffpc@optonline.net>
parents:
839
diff
changeset
|
637 |
def diff(**map): |
138 | 638 |
yield self.diff(p1, n, file) |
131 | 639 |
|
138 | 640 |
yield self.t("filediff", |
1062 | 641 |
file=file, |
642 |
filenode=hex(mf.get(file, nullid)), |
|
643 |
node=changeset, |
|
644 |
rev=self.repo.changelog.rev(n), |
|
645 |
parent=self.parents("filediffparent", |
|
1063
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
646 |
cl.parents(n), cl.rev), |
1062 | 647 |
diff=diff) |
515 | 648 |
|
1078 | 649 |
def archive(self, cnode, type): |
650 |
cs = self.repo.changelog.read(cnode) |
|
651 |
mnode = cs[0] |
|
652 |
mf = self.repo.manifest.read(mnode) |
|
653 |
rev = self.repo.manifest.rev(mnode) |
|
654 |
reponame = re.sub(r"\W+", "-", self.reponame) |
|
655 |
name = "%s-%s/" % (reponame, short(cnode)) |
|
656 |
||
1112
87cbfaf79124
hgweb: add mdiff / fix sorting of archives
mpm@selenic.com
parents:
1099
diff
changeset
|
657 |
files = mf.keys() |
87cbfaf79124
hgweb: add mdiff / fix sorting of archives
mpm@selenic.com
parents:
1099
diff
changeset
|
658 |
files.sort() |
87cbfaf79124
hgweb: add mdiff / fix sorting of archives
mpm@selenic.com
parents:
1099
diff
changeset
|
659 |
|
1077
b87aeccf73d9
tarball support v0.3 pt 2
Wojciech Milkowski <wmilkowski@interia.pl>
parents:
1076
diff
changeset
|
660 |
if type == 'zip': |
b87aeccf73d9
tarball support v0.3 pt 2
Wojciech Milkowski <wmilkowski@interia.pl>
parents:
1076
diff
changeset
|
661 |
import zipfile |
1076
01db658cc78a
tarball support v0.3
Wojciech Milkowski <wmilkowski@interia.pl>
parents:
1073
diff
changeset
|
662 |
|
1078 | 663 |
try: |
664 |
tmp = tempfile.mkstemp()[1] |
|
665 |
zf = zipfile.ZipFile(tmp, "w", zipfile.ZIP_DEFLATED) |
|
666 |
||
1112
87cbfaf79124
hgweb: add mdiff / fix sorting of archives
mpm@selenic.com
parents:
1099
diff
changeset
|
667 |
for f in files: |
1078 | 668 |
zf.writestr(name + f, self.repo.file(f).read(mf[f])) |
669 |
zf.close() |
|
1076
01db658cc78a
tarball support v0.3
Wojciech Milkowski <wmilkowski@interia.pl>
parents:
1073
diff
changeset
|
670 |
|
1078 | 671 |
f = open(tmp, 'r') |
672 |
httphdr('application/zip', name[:-1] + '.zip', |
|
673 |
os.path.getsize(tmp)) |
|
674 |
sys.stdout.write(f.read()) |
|
675 |
f.close() |
|
676 |
finally: |
|
677 |
os.unlink(tmp) |
|
1076
01db658cc78a
tarball support v0.3
Wojciech Milkowski <wmilkowski@interia.pl>
parents:
1073
diff
changeset
|
678 |
|
1077
b87aeccf73d9
tarball support v0.3 pt 2
Wojciech Milkowski <wmilkowski@interia.pl>
parents:
1076
diff
changeset
|
679 |
else: |
b87aeccf73d9
tarball support v0.3 pt 2
Wojciech Milkowski <wmilkowski@interia.pl>
parents:
1076
diff
changeset
|
680 |
import StringIO |
b87aeccf73d9
tarball support v0.3 pt 2
Wojciech Milkowski <wmilkowski@interia.pl>
parents:
1076
diff
changeset
|
681 |
import time |
b87aeccf73d9
tarball support v0.3 pt 2
Wojciech Milkowski <wmilkowski@interia.pl>
parents:
1076
diff
changeset
|
682 |
import tarfile |
1076
01db658cc78a
tarball support v0.3
Wojciech Milkowski <wmilkowski@interia.pl>
parents:
1073
diff
changeset
|
683 |
|
1077
b87aeccf73d9
tarball support v0.3 pt 2
Wojciech Milkowski <wmilkowski@interia.pl>
parents:
1076
diff
changeset
|
684 |
tf = tarfile.TarFile.open(mode='w|' + type, fileobj=sys.stdout) |
1078 | 685 |
mff = self.repo.manifest.readflags(mnode) |
1077
b87aeccf73d9
tarball support v0.3 pt 2
Wojciech Milkowski <wmilkowski@interia.pl>
parents:
1076
diff
changeset
|
686 |
mtime = int(time.time()) |
1076
01db658cc78a
tarball support v0.3
Wojciech Milkowski <wmilkowski@interia.pl>
parents:
1073
diff
changeset
|
687 |
|
1077
b87aeccf73d9
tarball support v0.3 pt 2
Wojciech Milkowski <wmilkowski@interia.pl>
parents:
1076
diff
changeset
|
688 |
httphdr('application/octet-stream', name[:-1] + '.tar.' + type) |
1112
87cbfaf79124
hgweb: add mdiff / fix sorting of archives
mpm@selenic.com
parents:
1099
diff
changeset
|
689 |
for fname in files: |
1078 | 690 |
rcont = self.repo.file(fname).read(mf[fname]) |
1077
b87aeccf73d9
tarball support v0.3 pt 2
Wojciech Milkowski <wmilkowski@interia.pl>
parents:
1076
diff
changeset
|
691 |
finfo = tarfile.TarInfo(name + fname) |
b87aeccf73d9
tarball support v0.3 pt 2
Wojciech Milkowski <wmilkowski@interia.pl>
parents:
1076
diff
changeset
|
692 |
finfo.mtime = mtime |
b87aeccf73d9
tarball support v0.3 pt 2
Wojciech Milkowski <wmilkowski@interia.pl>
parents:
1076
diff
changeset
|
693 |
finfo.size = len(rcont) |
b87aeccf73d9
tarball support v0.3 pt 2
Wojciech Milkowski <wmilkowski@interia.pl>
parents:
1076
diff
changeset
|
694 |
finfo.mode = mff[fname] and 0755 or 0644 |
b87aeccf73d9
tarball support v0.3 pt 2
Wojciech Milkowski <wmilkowski@interia.pl>
parents:
1076
diff
changeset
|
695 |
tf.addfile(finfo, StringIO.StringIO(rcont)) |
b87aeccf73d9
tarball support v0.3 pt 2
Wojciech Milkowski <wmilkowski@interia.pl>
parents:
1076
diff
changeset
|
696 |
tf.close() |
1076
01db658cc78a
tarball support v0.3
Wojciech Milkowski <wmilkowski@interia.pl>
parents:
1073
diff
changeset
|
697 |
|
138 | 698 |
# add tags to things |
699 |
# tags -> list of changesets corresponding to tags |
|
700 |
# find tag, changeset, file |
|
131 | 701 |
|
132 | 702 |
def run(self): |
857
41b344235bb7
[PATCH] Propagate the template map though recursively
Jeff Sipek <jeffpc@optonline.net>
parents:
839
diff
changeset
|
703 |
def header(**map): |
41b344235bb7
[PATCH] Propagate the template map though recursively
Jeff Sipek <jeffpc@optonline.net>
parents:
839
diff
changeset
|
704 |
yield self.t("header", **map) |
41b344235bb7
[PATCH] Propagate the template map though recursively
Jeff Sipek <jeffpc@optonline.net>
parents:
839
diff
changeset
|
705 |
|
41b344235bb7
[PATCH] Propagate the template map though recursively
Jeff Sipek <jeffpc@optonline.net>
parents:
839
diff
changeset
|
706 |
def footer(**map): |
41b344235bb7
[PATCH] Propagate the template map though recursively
Jeff Sipek <jeffpc@optonline.net>
parents:
839
diff
changeset
|
707 |
yield self.t("footer", **map) |
41b344235bb7
[PATCH] Propagate the template map though recursively
Jeff Sipek <jeffpc@optonline.net>
parents:
839
diff
changeset
|
708 |
|
258 | 709 |
self.refresh() |
132 | 710 |
args = cgi.parse() |
711 |
||
987 | 712 |
t = self.repo.ui.config("web", "templates", templatepath()) |
938 | 713 |
m = os.path.join(t, "map") |
986 | 714 |
style = self.repo.ui.config("web", "style", "") |
201
f918a6fa2572
hgweb: add template filters, template style maps, and raw pages
mpm@selenic.com
parents:
198
diff
changeset
|
715 |
if args.has_key('style'): |
986 | 716 |
style = args['style'][0] |
717 |
if style: |
|
718 |
b = os.path.basename("map-" + style) |
|
983 | 719 |
p = os.path.join(t, b) |
1063
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
720 |
if os.path.isfile(p): |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
721 |
m = p |
515 | 722 |
|
601 | 723 |
port = os.environ["SERVER_PORT"] |
724 |
port = port != "80" and (":" + port) or "" |
|
620
7369ec5d93f2
Attempt to handle RSS URIs properly
Matt Mackall <mpm@selenic.com>
parents:
605
diff
changeset
|
725 |
uri = os.environ["REQUEST_URI"] |
1063
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
726 |
if "?" in uri: |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
727 |
uri = uri.split("?")[0] |
620
7369ec5d93f2
Attempt to handle RSS URIs properly
Matt Mackall <mpm@selenic.com>
parents:
605
diff
changeset
|
728 |
url = "http://%s%s%s" % (os.environ["SERVER_NAME"], port, uri) |
601 | 729 |
|
941 | 730 |
self.t = templater(m, common_filters, |
1062 | 731 |
{"url": url, |
732 |
"repo": self.reponame, |
|
733 |
"header": header, |
|
734 |
"footer": footer, |
|
1063
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
735 |
}) |
201
f918a6fa2572
hgweb: add template filters, template style maps, and raw pages
mpm@selenic.com
parents:
198
diff
changeset
|
736 |
|
858
c333dfa8fa1a
[PATCH] Move default page name into map file
Jeff Sipek <jeffpc@optonline.net>
parents:
857
diff
changeset
|
737 |
if not args.has_key('cmd'): |
c333dfa8fa1a
[PATCH] Move default page name into map file
Jeff Sipek <jeffpc@optonline.net>
parents:
857
diff
changeset
|
738 |
args['cmd'] = [self.t.cache['default'],] |
937 | 739 |
|
858
c333dfa8fa1a
[PATCH] Move default page name into map file
Jeff Sipek <jeffpc@optonline.net>
parents:
857
diff
changeset
|
740 |
if args['cmd'][0] == 'changelog': |
538 | 741 |
c = self.repo.changelog.count() - 1 |
742 |
hi = c |
|
153
e8a360cd5a9f
changed pos to rev for changelog cmd, changed & to ;
jake@edge2.net
parents:
142
diff
changeset
|
743 |
if args.has_key('rev'): |
165 | 744 |
hi = args['rev'][0] |
166
39624c47060f
hgweb: don't blow up on search for unknown keys
mpm@selenic.com
parents:
165
diff
changeset
|
745 |
try: |
39624c47060f
hgweb: don't blow up on search for unknown keys
mpm@selenic.com
parents:
165
diff
changeset
|
746 |
hi = self.repo.changelog.rev(self.repo.lookup(hi)) |
688 | 747 |
except RepoError: |
538 | 748 |
write(self.search(hi)) |
749 |
return |
|
575 | 750 |
|
138 | 751 |
write(self.changelog(hi)) |
515 | 752 |
|
138 | 753 |
elif args['cmd'][0] == 'changeset': |
754 |
write(self.changeset(args['node'][0])) |
|
755 |
||
756 |
elif args['cmd'][0] == 'manifest': |
|
757 |
write(self.manifest(args['manifest'][0], args['path'][0])) |
|
758 |
||
168 | 759 |
elif args['cmd'][0] == 'tags': |
760 |
write(self.tags()) |
|
761 |
||
138 | 762 |
elif args['cmd'][0] == 'filediff': |
763 |
write(self.filediff(args['file'][0], args['node'][0])) |
|
131 | 764 |
|
132 | 765 |
elif args['cmd'][0] == 'file': |
138 | 766 |
write(self.filerevision(args['file'][0], args['filenode'][0])) |
131 | 767 |
|
138 | 768 |
elif args['cmd'][0] == 'annotate': |
769 |
write(self.fileannotate(args['file'][0], args['filenode'][0])) |
|
131 | 770 |
|
138 | 771 |
elif args['cmd'][0] == 'filelog': |
772 |
write(self.filelog(args['file'][0], args['filenode'][0])) |
|
136 | 773 |
|
222 | 774 |
elif args['cmd'][0] == 'heads': |
751
0b245edec124
When pulling from a non hg repository URL (e.g. http://www.kernel.org/hg)
Muli Ben-Yehuda <mulix@mulix.org>
parents:
688
diff
changeset
|
775 |
httphdr("application/mercurial-0.1") |
222 | 776 |
h = self.repo.heads() |
777 |
sys.stdout.write(" ".join(map(hex, h)) + "\n") |
|
778 |
||
132 | 779 |
elif args['cmd'][0] == 'branches': |
751
0b245edec124
When pulling from a non hg repository URL (e.g. http://www.kernel.org/hg)
Muli Ben-Yehuda <mulix@mulix.org>
parents:
688
diff
changeset
|
780 |
httphdr("application/mercurial-0.1") |
132 | 781 |
nodes = [] |
782 |
if args.has_key('nodes'): |
|
138 | 783 |
nodes = map(bin, args['nodes'][0].split(" ")) |
784 |
for b in self.repo.branches(nodes): |
|
785 |
sys.stdout.write(" ".join(map(hex, b)) + "\n") |
|
131 | 786 |
|
132 | 787 |
elif args['cmd'][0] == 'between': |
753 | 788 |
httphdr("application/mercurial-0.1") |
132 | 789 |
nodes = [] |
790 |
if args.has_key('pairs'): |
|
1063
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
791 |
pairs = [map(bin, p.split("-")) |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
792 |
for p in args['pairs'][0].split(" ")] |
138 | 793 |
for b in self.repo.between(pairs): |
794 |
sys.stdout.write(" ".join(map(hex, b)) + "\n") |
|
132 | 795 |
|
796 |
elif args['cmd'][0] == 'changegroup': |
|
751
0b245edec124
When pulling from a non hg repository URL (e.g. http://www.kernel.org/hg)
Muli Ben-Yehuda <mulix@mulix.org>
parents:
688
diff
changeset
|
797 |
httphdr("application/mercurial-0.1") |
132 | 798 |
nodes = [] |
964
3f37720e7dc7
hgweb: Make maxfiles, maxchanges, and allowpull proper config options
mpm@selenic.com
parents:
957
diff
changeset
|
799 |
if not self.allowpull: |
197 | 800 |
return |
801 |
||
132 | 802 |
if args.has_key('roots'): |
138 | 803 |
nodes = map(bin, args['roots'][0].split(" ")) |
131 | 804 |
|
132 | 805 |
z = zlib.compressobj() |
635
85e2209d401c
Protocol switch from using generators to stream-like objects.
Matt Mackall <mpm@selenic.com>
parents:
620
diff
changeset
|
806 |
f = self.repo.changegroup(nodes) |
85e2209d401c
Protocol switch from using generators to stream-like objects.
Matt Mackall <mpm@selenic.com>
parents:
620
diff
changeset
|
807 |
while 1: |
85e2209d401c
Protocol switch from using generators to stream-like objects.
Matt Mackall <mpm@selenic.com>
parents:
620
diff
changeset
|
808 |
chunk = f.read(4096) |
1063
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
809 |
if not chunk: |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
810 |
break |
132 | 811 |
sys.stdout.write(z.compress(chunk)) |
812 |
||
813 |
sys.stdout.write(z.flush()) |
|
131 | 814 |
|
1078 | 815 |
elif args['cmd'][0] == 'archive': |
816 |
changeset = bin(args['node'][0]) |
|
1076
01db658cc78a
tarball support v0.3
Wojciech Milkowski <wmilkowski@interia.pl>
parents:
1073
diff
changeset
|
817 |
type = args['type'][0] |
1078 | 818 |
if (type in self.archives and |
819 |
self.repo.ui.configbool("web", "allow" + type, False)): |
|
820 |
self.archive(changeset, type) |
|
821 |
return |
|
1077
b87aeccf73d9
tarball support v0.3 pt 2
Wojciech Milkowski <wmilkowski@interia.pl>
parents:
1076
diff
changeset
|
822 |
|
b87aeccf73d9
tarball support v0.3 pt 2
Wojciech Milkowski <wmilkowski@interia.pl>
parents:
1076
diff
changeset
|
823 |
write(self.t("error")) |
1076
01db658cc78a
tarball support v0.3
Wojciech Milkowski <wmilkowski@interia.pl>
parents:
1073
diff
changeset
|
824 |
|
132 | 825 |
else: |
138 | 826 |
write(self.t("error")) |
131 | 827 |
|
987 | 828 |
def create_server(repo): |
158
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
157
diff
changeset
|
829 |
|
938 | 830 |
def openlog(opt, default): |
831 |
if opt and opt != '-': |
|
832 |
return open(opt, 'w') |
|
833 |
return default |
|
834 |
||
987 | 835 |
address = repo.ui.config("web", "address", "") |
836 |
port = int(repo.ui.config("web", "port", 8000)) |
|
837 |
use_ipv6 = repo.ui.configbool("web", "ipv6") |
|
838 |
accesslog = openlog(repo.ui.config("web", "accesslog", "-"), sys.stdout) |
|
839 |
errorlog = openlog(repo.ui.config("web", "errorlog", "-"), sys.stderr) |
|
938 | 840 |
|
158
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
157
diff
changeset
|
841 |
import BaseHTTPServer |
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
157
diff
changeset
|
842 |
|
825
0108c602feb9
Add an option to hg serve to serve file using IPv6
Samuel Tardieu <sam@rfc1149.net>
parents:
753
diff
changeset
|
843 |
class IPv6HTTPServer(BaseHTTPServer.HTTPServer): |
881
16ce690c411d
Fix problem with "hg serve" on systems not providing IPv6.
Bryan O'Sullivan <bos@serpentine.com>
parents:
858
diff
changeset
|
844 |
address_family = getattr(socket, 'AF_INET6', None) |
16ce690c411d
Fix problem with "hg serve" on systems not providing IPv6.
Bryan O'Sullivan <bos@serpentine.com>
parents:
858
diff
changeset
|
845 |
|
16ce690c411d
Fix problem with "hg serve" on systems not providing IPv6.
Bryan O'Sullivan <bos@serpentine.com>
parents:
858
diff
changeset
|
846 |
def __init__(self, *args, **kwargs): |
16ce690c411d
Fix problem with "hg serve" on systems not providing IPv6.
Bryan O'Sullivan <bos@serpentine.com>
parents:
858
diff
changeset
|
847 |
if self.address_family is None: |
16ce690c411d
Fix problem with "hg serve" on systems not providing IPv6.
Bryan O'Sullivan <bos@serpentine.com>
parents:
858
diff
changeset
|
848 |
raise RepoError('IPv6 not available on this system') |
16ce690c411d
Fix problem with "hg serve" on systems not providing IPv6.
Bryan O'Sullivan <bos@serpentine.com>
parents:
858
diff
changeset
|
849 |
BaseHTTPServer.HTTPServer.__init__(self, *args, **kwargs) |
825
0108c602feb9
Add an option to hg serve to serve file using IPv6
Samuel Tardieu <sam@rfc1149.net>
parents:
753
diff
changeset
|
850 |
|
158
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
157
diff
changeset
|
851 |
class hgwebhandler(BaseHTTPServer.BaseHTTPRequestHandler): |
605
8e82fd763be2
[PATCH] Get "hg serve" to optionally log accesses and errors to files
mpm@selenic.com
parents:
603
diff
changeset
|
852 |
def log_error(self, format, *args): |
8e82fd763be2
[PATCH] Get "hg serve" to optionally log accesses and errors to files
mpm@selenic.com
parents:
603
diff
changeset
|
853 |
errorlog.write("%s - - [%s] %s\n" % (self.address_string(), |
8e82fd763be2
[PATCH] Get "hg serve" to optionally log accesses and errors to files
mpm@selenic.com
parents:
603
diff
changeset
|
854 |
self.log_date_time_string(), |
8e82fd763be2
[PATCH] Get "hg serve" to optionally log accesses and errors to files
mpm@selenic.com
parents:
603
diff
changeset
|
855 |
format % args)) |
937 | 856 |
|
605
8e82fd763be2
[PATCH] Get "hg serve" to optionally log accesses and errors to files
mpm@selenic.com
parents:
603
diff
changeset
|
857 |
def log_message(self, format, *args): |
8e82fd763be2
[PATCH] Get "hg serve" to optionally log accesses and errors to files
mpm@selenic.com
parents:
603
diff
changeset
|
858 |
accesslog.write("%s - - [%s] %s\n" % (self.address_string(), |
8e82fd763be2
[PATCH] Get "hg serve" to optionally log accesses and errors to files
mpm@selenic.com
parents:
603
diff
changeset
|
859 |
self.log_date_time_string(), |
8e82fd763be2
[PATCH] Get "hg serve" to optionally log accesses and errors to files
mpm@selenic.com
parents:
603
diff
changeset
|
860 |
format % args)) |
8e82fd763be2
[PATCH] Get "hg serve" to optionally log accesses and errors to files
mpm@selenic.com
parents:
603
diff
changeset
|
861 |
|
158
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
157
diff
changeset
|
862 |
def do_POST(self): |
271 | 863 |
try: |
864 |
self.do_hgweb() |
|
865 |
except socket.error, inst: |
|
1063
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
866 |
if inst.args[0] != 32: |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
867 |
raise |
158
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
157
diff
changeset
|
868 |
|
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
157
diff
changeset
|
869 |
def do_GET(self): |
271 | 870 |
self.do_POST() |
158
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
157
diff
changeset
|
871 |
|
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
157
diff
changeset
|
872 |
def do_hgweb(self): |
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
157
diff
changeset
|
873 |
query = "" |
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
157
diff
changeset
|
874 |
p = self.path.find("?") |
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
157
diff
changeset
|
875 |
if p: |
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
157
diff
changeset
|
876 |
query = self.path[p + 1:] |
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
157
diff
changeset
|
877 |
query = query.replace('+', ' ') |
515 | 878 |
|
158
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
157
diff
changeset
|
879 |
env = {} |
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
157
diff
changeset
|
880 |
env['GATEWAY_INTERFACE'] = 'CGI/1.1' |
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
157
diff
changeset
|
881 |
env['REQUEST_METHOD'] = self.command |
599 | 882 |
env['SERVER_NAME'] = self.server.server_name |
883 |
env['SERVER_PORT'] = str(self.server.server_port) |
|
884 |
env['REQUEST_URI'] = "/" |
|
158
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
157
diff
changeset
|
885 |
if query: |
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
157
diff
changeset
|
886 |
env['QUERY_STRING'] = query |
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
157
diff
changeset
|
887 |
host = self.address_string() |
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
157
diff
changeset
|
888 |
if host != self.client_address[0]: |
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
157
diff
changeset
|
889 |
env['REMOTE_HOST'] = host |
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
157
diff
changeset
|
890 |
env['REMOTE_ADDR'] = self.client_address[0] |
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
157
diff
changeset
|
891 |
|
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
157
diff
changeset
|
892 |
if self.headers.typeheader is None: |
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
157
diff
changeset
|
893 |
env['CONTENT_TYPE'] = self.headers.type |
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
157
diff
changeset
|
894 |
else: |
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
157
diff
changeset
|
895 |
env['CONTENT_TYPE'] = self.headers.typeheader |
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
157
diff
changeset
|
896 |
length = self.headers.getheader('content-length') |
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
157
diff
changeset
|
897 |
if length: |
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
157
diff
changeset
|
898 |
env['CONTENT_LENGTH'] = length |
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
157
diff
changeset
|
899 |
accept = [] |
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
157
diff
changeset
|
900 |
for line in self.headers.getallmatchingheaders('accept'): |
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
157
diff
changeset
|
901 |
if line[:1] in "\t\n\r ": |
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
157
diff
changeset
|
902 |
accept.append(line.strip()) |
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
157
diff
changeset
|
903 |
else: |
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
157
diff
changeset
|
904 |
accept = accept + line[7:].split(',') |
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
157
diff
changeset
|
905 |
env['HTTP_ACCEPT'] = ','.join(accept) |
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
157
diff
changeset
|
906 |
|
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
157
diff
changeset
|
907 |
os.environ.update(env) |
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
157
diff
changeset
|
908 |
|
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
157
diff
changeset
|
909 |
save = sys.argv, sys.stdin, sys.stdout, sys.stderr |
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
157
diff
changeset
|
910 |
try: |
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
157
diff
changeset
|
911 |
sys.stdin = self.rfile |
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
157
diff
changeset
|
912 |
sys.stdout = self.wfile |
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
157
diff
changeset
|
913 |
sys.argv = ["hgweb.py"] |
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
157
diff
changeset
|
914 |
if '=' not in query: |
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
157
diff
changeset
|
915 |
sys.argv.append(query) |
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
157
diff
changeset
|
916 |
self.send_response(200, "Script output follows") |
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
157
diff
changeset
|
917 |
hg.run() |
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
157
diff
changeset
|
918 |
finally: |
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
157
diff
changeset
|
919 |
sys.argv, sys.stdin, sys.stdout, sys.stderr = save |
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
157
diff
changeset
|
920 |
|
987 | 921 |
hg = hgweb(repo) |
825
0108c602feb9
Add an option to hg serve to serve file using IPv6
Samuel Tardieu <sam@rfc1149.net>
parents:
753
diff
changeset
|
922 |
if use_ipv6: |
0108c602feb9
Add an option to hg serve to serve file using IPv6
Samuel Tardieu <sam@rfc1149.net>
parents:
753
diff
changeset
|
923 |
return IPv6HTTPServer((address, port), hgwebhandler) |
0108c602feb9
Add an option to hg serve to serve file using IPv6
Samuel Tardieu <sam@rfc1149.net>
parents:
753
diff
changeset
|
924 |
else: |
0108c602feb9
Add an option to hg serve to serve file using IPv6
Samuel Tardieu <sam@rfc1149.net>
parents:
753
diff
changeset
|
925 |
return BaseHTTPServer.HTTPServer((address, port), hgwebhandler) |
603
bc5d058e65e9
[PATCH] Get "hg serve" to print the URL being served
mpm@selenic.com
parents:
601
diff
changeset
|
926 |
|
1062 | 927 |
def server(path, name, templates, address, port, use_ipv6=False, |
928 |
accesslog=sys.stdout, errorlog=sys.stderr): |
|
825
0108c602feb9
Add an option to hg serve to serve file using IPv6
Samuel Tardieu <sam@rfc1149.net>
parents:
753
diff
changeset
|
929 |
httpd = create_server(path, name, templates, address, port, use_ipv6, |
605
8e82fd763be2
[PATCH] Get "hg serve" to optionally log accesses and errors to files
mpm@selenic.com
parents:
603
diff
changeset
|
930 |
accesslog, errorlog) |
158
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
157
diff
changeset
|
931 |
httpd.serve_forever() |
941 | 932 |
|
933 |
# This is a stopgap |
|
934 |
class hgwebdir: |
|
935 |
def __init__(self, config): |
|
936 |
self.cp = ConfigParser.SafeConfigParser() |
|
937 |
self.cp.read(config) |
|
938 |
||
939 |
def run(self): |
|
940 |
try: |
|
941 |
virtual = os.environ["PATH_INFO"] |
|
942 |
except: |
|
943 |
virtual = "" |
|
944 |
||
1120
df25ee778ac2
Handle a nonexistent repository with a 404 error.
Ollivier Robert <roberto@keltia.freenix.fr>
parents:
1119
diff
changeset
|
945 |
virtual = virtual.strip('/') |
df25ee778ac2
Handle a nonexistent repository with a 404 error.
Ollivier Robert <roberto@keltia.freenix.fr>
parents:
1119
diff
changeset
|
946 |
|
df25ee778ac2
Handle a nonexistent repository with a 404 error.
Ollivier Robert <roberto@keltia.freenix.fr>
parents:
1119
diff
changeset
|
947 |
if len(virtual): |
df25ee778ac2
Handle a nonexistent repository with a 404 error.
Ollivier Robert <roberto@keltia.freenix.fr>
parents:
1119
diff
changeset
|
948 |
try: |
df25ee778ac2
Handle a nonexistent repository with a 404 error.
Ollivier Robert <roberto@keltia.freenix.fr>
parents:
1119
diff
changeset
|
949 |
real = self.cp.get("paths", virtual) |
1119
7fca9752d945
Protect against unknown repositories.
roberto@keltia.freenix.fr
parents:
1112
diff
changeset
|
950 |
h = hgweb(real) |
7fca9752d945
Protect against unknown repositories.
roberto@keltia.freenix.fr
parents:
1112
diff
changeset
|
951 |
h.run() |
7fca9752d945
Protect against unknown repositories.
roberto@keltia.freenix.fr
parents:
1112
diff
changeset
|
952 |
return |
1121
14a69c4988cd
NoOptionError is unknown there.
Ollivier Robert <roberto@keltia.freenix.fr>
parents:
1120
diff
changeset
|
953 |
except: |
1120
df25ee778ac2
Handle a nonexistent repository with a 404 error.
Ollivier Robert <roberto@keltia.freenix.fr>
parents:
1119
diff
changeset
|
954 |
httpnotfound(virtual) |
df25ee778ac2
Handle a nonexistent repository with a 404 error.
Ollivier Robert <roberto@keltia.freenix.fr>
parents:
1119
diff
changeset
|
955 |
return |
941 | 956 |
|
957 |
def header(**map): |
|
958 |
yield tmpl("header", **map) |
|
959 |
||
960 |
def footer(**map): |
|
961 |
yield tmpl("footer", **map) |
|
962 |
||
963 |
templates = templatepath() |
|
964 |
m = os.path.join(templates, "map") |
|
965 |
tmpl = templater(m, common_filters, |
|
966 |
{"header": header, "footer": footer}) |
|
967 |
||
968 |
def entries(**map): |
|
969 |
parity = 0 |
|
957 | 970 |
l = self.cp.items("paths") |
971 |
l.sort() |
|
972 |
for v,r in l: |
|
941 | 973 |
cp2 = ConfigParser.SafeConfigParser() |
974 |
cp2.read(os.path.join(r, ".hg", "hgrc")) |
|
975 |
||
976 |
def get(sec, val, default): |
|
977 |
try: |
|
978 |
return cp2.get(sec, val) |
|
979 |
except: |
|
980 |
return default |
|
981 |
||
1022 | 982 |
url = os.environ["REQUEST_URI"] + "/" + v |
983 |
url = url.replace("//", "/") |
|
984 |
||
1062 | 985 |
yield dict(author=get("web", "author", "unknown"), |
986 |
name=get("web", "name", v), |
|
987 |
url=url, |
|
988 |
parity=parity, |
|
989 |
shortdesc=get("web", "description", "unknown"), |
|
990 |
lastupdate=os.stat(os.path.join(r, ".hg", |
|
941 | 991 |
"00changelog.d")).st_mtime) |
992 |
||
993 |
parity = 1 - parity |
|
994 |
||
1062 | 995 |
write(tmpl("index", entries=entries)) |