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