Mercurial > hg-stable
annotate mercurial/hgweb.py @ 1498:78590fb4a82b
hgweb: Added archive download buttons to manifest page.
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Thu, 03 Nov 2005 18:45:27 +0100 |
parents | 7d66ce9895fa |
children | a91bfbbe88d3 |
rev | line source |
---|---|
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 | |
1213 | 9 import os, cgi, sys |
10 from demandload import demandload | |
1217 | 11 demandload(globals(), "mdiff time re socket zlib errno ui hg ConfigParser") |
1320
5f277e73778f
Fix up representation of dates in hgweb.
Bryan O'Sullivan <bos@serpentine.com>
parents:
1308
diff
changeset
|
12 demandload(globals(), "zipfile tempfile StringIO tarfile BaseHTTPServer util") |
1411
e2ba788545bf
hgweb: make viewing of non-text work in hgweb
Matt Mackall <mpm@selenic.com>
parents:
1409
diff
changeset
|
13 demandload(globals(), "mimetypes") |
1213 | 14 from node import * |
1400
cf9a1233738a
i18n first part: make '_' available for files who need it
Benoit Boissinot <benoit.boissinot@ens-lyon.org
parents:
1369
diff
changeset
|
15 from i18n import gettext as _ |
138 | 16 |
157
2653740d8118
Install the templates where they can be found by hgweb.py
mpm@selenic.com
parents:
156
diff
changeset
|
17 def templatepath(): |
201
f918a6fa2572
hgweb: add template filters, template style maps, and raw pages
mpm@selenic.com
parents:
198
diff
changeset
|
18 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
|
19 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
|
20 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
|
21 return p |
157
2653740d8118
Install the templates where they can be found by hgweb.py
mpm@selenic.com
parents:
156
diff
changeset
|
22 |
1320
5f277e73778f
Fix up representation of dates in hgweb.
Bryan O'Sullivan <bos@serpentine.com>
parents:
1308
diff
changeset
|
23 def age(x): |
138 | 24 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
|
25 if c == 1: |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
26 return t |
138 | 27 return t + "s" |
28 def fmt(t, c): | |
29 return "%d %s" % (c, plural(t, c)) | |
30 | |
31 now = time.time() | |
1324
77cd8068dbf4
hgweb: pass date tuples around rather than whole changesets for dates
mpm@selenic.com
parents:
1321
diff
changeset
|
32 then = x[0] |
1320
5f277e73778f
Fix up representation of dates in hgweb.
Bryan O'Sullivan <bos@serpentine.com>
parents:
1308
diff
changeset
|
33 delta = max(1, int(now - then)) |
138 | 34 |
35 scales = [["second", 1], | |
36 ["minute", 60], | |
37 ["hour", 3600], | |
38 ["day", 3600 * 24], | |
39 ["week", 3600 * 24 * 7], | |
40 ["month", 3600 * 24 * 30], | |
41 ["year", 3600 * 24 * 365]] | |
42 | |
43 scales.reverse() | |
44 | |
45 for t, s in scales: | |
46 n = delta / s | |
1063
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
47 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
|
48 return fmt(t, n) |
131 | 49 |
50 def nl2br(text): | |
201
f918a6fa2572
hgweb: add template filters, template style maps, and raw pages
mpm@selenic.com
parents:
198
diff
changeset
|
51 return text.replace('\n', '<br/>\n') |
131 | 52 |
53 def obfuscate(text): | |
1063
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
54 return ''.join(['&#%d;' % ord(c) for c in text]) |
138 | 55 |
56 def up(p): | |
1063
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
57 if p[0] != "/": |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
58 p = "/" + p |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
59 if p[-1] == "/": |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
60 p = p[:-1] |
138 | 61 up = os.path.dirname(p) |
62 if up == "/": | |
63 return "/" | |
64 return up + "/" | |
131 | 65 |
1418
68f81ba07b2a
Make hgweb work when the repository is empty (no 00changelog.i)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1416
diff
changeset
|
66 def get_mtime(repo_path): |
68f81ba07b2a
Make hgweb work when the repository is empty (no 00changelog.i)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1416
diff
changeset
|
67 hg_path = os.path.join(repo_path, ".hg") |
68f81ba07b2a
Make hgweb work when the repository is empty (no 00changelog.i)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1416
diff
changeset
|
68 cl_path = os.path.join(hg_path, "00changelog.i") |
68f81ba07b2a
Make hgweb work when the repository is empty (no 00changelog.i)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1416
diff
changeset
|
69 if os.path.exists(os.path.join(cl_path)): |
68f81ba07b2a
Make hgweb work when the repository is empty (no 00changelog.i)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1416
diff
changeset
|
70 return os.stat(cl_path).st_mtime |
68f81ba07b2a
Make hgweb work when the repository is empty (no 00changelog.i)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1416
diff
changeset
|
71 else: |
68f81ba07b2a
Make hgweb work when the repository is empty (no 00changelog.i)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1416
diff
changeset
|
72 return os.stat(hg_path).st_mtime |
68f81ba07b2a
Make hgweb work when the repository is empty (no 00changelog.i)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1416
diff
changeset
|
73 |
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
|
74 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
|
75 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
|
76 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
|
77 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
|
78 self.env = env or os.environ |
1407
db571bcaa35d
allow empty values for url so we can have /?tip
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1406
diff
changeset
|
79 self.form = cgi.parse(self.inp, self.env, keep_blank_values=1) |
131 | 80 |
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
|
81 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
|
82 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
|
83 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
|
84 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
|
85 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
|
86 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
|
87 try: |
1160
0da98529a476
Fix TypeError
Vincent Wagelaar <vincent@ricardis.tudelft.nl>
parents:
1159
diff
changeset
|
88 self.out.write(str(thing)) |
1174
9d9f4973c76a
Added missing 'import errno', and use errno for EPIPE, too.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1172
diff
changeset
|
89 except socket.error, inst: |
9d9f4973c76a
Added missing 'import errno', and use errno for EPIPE, too.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1172
diff
changeset
|
90 if inst[0] != errno.ECONNRESET: |
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
|
91 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
|
92 |
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 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
|
94 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
|
95 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
|
96 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
|
97 |
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
|
98 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
|
99 |
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
|
100 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
|
101 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
|
102 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
|
103 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
|
104 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
|
105 self.header(headers) |
135 | 106 |
138 | 107 class templater: |
1062 | 108 def __init__(self, mapfile, filters={}, defaults={}): |
138 | 109 self.cache = {} |
110 self.map = {} | |
111 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
|
112 self.filters = filters |
601 | 113 self.defaults = defaults |
515 | 114 |
138 | 115 for l in file(mapfile): |
116 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
|
117 if m: |
138 | 118 self.cache[m.group(1)] = m.group(2) |
119 else: | |
120 m = re.match(r'(\S+)\s*=\s*(\S+)', l) | |
121 if m: | |
122 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
|
123 else: |
1402
9d2c2e6b32b5
i18n part2: use '_' for all strings who are part of the user interface
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1400
diff
changeset
|
124 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
|
125 |
138 | 126 def __call__(self, t, **map): |
601 | 127 m = self.defaults.copy() |
128 m.update(map) | |
138 | 129 try: |
130 tmpl = self.cache[t] | |
131 except KeyError: | |
132 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
|
133 return self.template(tmpl, self.filters, **m) |
aedb47764f29
Added support for #foo%bar# syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
938
diff
changeset
|
134 |
1062 | 135 def template(self, tmpl, filters={}, **map): |
974
aedb47764f29
Added support for #foo%bar# syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
938
diff
changeset
|
136 while tmpl: |
aedb47764f29
Added support for #foo%bar# syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
938
diff
changeset
|
137 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
|
138 if m: |
aedb47764f29
Added support for #foo%bar# syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
938
diff
changeset
|
139 yield tmpl[:m.start(0)] |
aedb47764f29
Added support for #foo%bar# syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
938
diff
changeset
|
140 v = map.get(m.group(1), "") |
aedb47764f29
Added support for #foo%bar# syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
938
diff
changeset
|
141 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
|
142 |
aedb47764f29
Added support for #foo%bar# syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
938
diff
changeset
|
143 format = m.group(2) |
aedb47764f29
Added support for #foo%bar# syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
938
diff
changeset
|
144 fl = m.group(4) |
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 if format: |
aedb47764f29
Added support for #foo%bar# syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
938
diff
changeset
|
147 q = v.__iter__ |
aedb47764f29
Added support for #foo%bar# syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
938
diff
changeset
|
148 for i in q(): |
aedb47764f29
Added support for #foo%bar# syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
938
diff
changeset
|
149 lm = map.copy() |
aedb47764f29
Added support for #foo%bar# syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
938
diff
changeset
|
150 lm.update(i) |
aedb47764f29
Added support for #foo%bar# syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
938
diff
changeset
|
151 yield self(format[1:], **lm) |
aedb47764f29
Added support for #foo%bar# syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
938
diff
changeset
|
152 |
aedb47764f29
Added support for #foo%bar# syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
938
diff
changeset
|
153 v = "" |
aedb47764f29
Added support for #foo%bar# syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
938
diff
changeset
|
154 |
aedb47764f29
Added support for #foo%bar# syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
938
diff
changeset
|
155 elif fl: |
aedb47764f29
Added support for #foo%bar# syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
938
diff
changeset
|
156 for f in fl.split("|")[1:]: |
aedb47764f29
Added support for #foo%bar# syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
938
diff
changeset
|
157 v = filters[f](v) |
aedb47764f29
Added support for #foo%bar# syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
938
diff
changeset
|
158 |
aedb47764f29
Added support for #foo%bar# syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
938
diff
changeset
|
159 yield v |
aedb47764f29
Added support for #foo%bar# syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
938
diff
changeset
|
160 tmpl = tmpl[m.end(0):] |
aedb47764f29
Added support for #foo%bar# syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
938
diff
changeset
|
161 else: |
aedb47764f29
Added support for #foo%bar# syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
938
diff
changeset
|
162 yield tmpl |
aedb47764f29
Added support for #foo%bar# syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
938
diff
changeset
|
163 return |
515 | 164 |
941 | 165 common_filters = { |
166 "escape": cgi.escape, | |
1445
56281e086f38
hgweb: add strip and rstrip filters to handle summary
TK Soh <teekaysoh@yahoo.com>
parents:
1418
diff
changeset
|
167 "strip": lambda x: x.strip(), |
56281e086f38
hgweb: add strip and rstrip filters to handle summary
TK Soh <teekaysoh@yahoo.com>
parents:
1418
diff
changeset
|
168 "rstrip": lambda x: x.rstrip(), |
941 | 169 "age": age, |
1324
77cd8068dbf4
hgweb: pass date tuples around rather than whole changesets for dates
mpm@selenic.com
parents:
1321
diff
changeset
|
170 "date": lambda x: util.datestr(x), |
941 | 171 "addbreaks": nl2br, |
172 "obfuscate": obfuscate, | |
173 "short": (lambda x: x[:12]), | |
174 "firstline": (lambda x: x.splitlines(1)[0]), | |
175 "permissions": (lambda x: x and "-rwxr-xr-x" or "-rw-r--r--"), | |
1324
77cd8068dbf4
hgweb: pass date tuples around rather than whole changesets for dates
mpm@selenic.com
parents:
1321
diff
changeset
|
176 "rfc822date": lambda x: util.datestr(x, "%a, %d %b %Y %H:%M:%S"), |
941 | 177 } |
178 | |
138 | 179 class hgweb: |
987 | 180 def __init__(self, repo, name=None): |
181 if type(repo) == type(""): | |
1213 | 182 self.repo = hg.repository(ui.ui(), repo) |
987 | 183 else: |
184 self.repo = repo | |
133
fb84d3e71042
added template support for some hgweb output, also, template files for
jake@edge2.net
parents:
132
diff
changeset
|
185 |
258 | 186 self.mtime = -1 |
1172
3f30a5e7e15b
Use path relative to document root as reponame if published via a web server.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1170
diff
changeset
|
187 self.reponame = name |
1078 | 188 self.archives = 'zip', 'gz', 'bz2' |
131 | 189 |
258 | 190 def refresh(self): |
1418
68f81ba07b2a
Make hgweb work when the repository is empty (no 00changelog.i)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1416
diff
changeset
|
191 mtime = get_mtime(self.repo.root) |
68f81ba07b2a
Make hgweb work when the repository is empty (no 00changelog.i)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1416
diff
changeset
|
192 if mtime != self.mtime: |
68f81ba07b2a
Make hgweb work when the repository is empty (no 00changelog.i)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1416
diff
changeset
|
193 self.mtime = mtime |
1213 | 194 self.repo = hg.repository(self.repo.ui, self.repo.root) |
1275
a1a84dd489ff
Fix cut and paste error in hgweb.py
Florian La Roche <laroche@redhat.com>
parents:
1260
diff
changeset
|
195 self.maxchanges = int(self.repo.ui.config("web", "maxchanges", 10)) |
a1a84dd489ff
Fix cut and paste error in hgweb.py
Florian La Roche <laroche@redhat.com>
parents:
1260
diff
changeset
|
196 self.maxfiles = int(self.repo.ui.config("web", "maxfiles", 10)) |
964
3f37720e7dc7
hgweb: Make maxfiles, maxchanges, and allowpull proper config options
mpm@selenic.com
parents:
957
diff
changeset
|
197 self.allowpull = self.repo.ui.configbool("web", "allowpull", True) |
258 | 198 |
1498
78590fb4a82b
hgweb: Added archive download buttons to manifest page.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1473
diff
changeset
|
199 def archivelist(self, nodeid): |
78590fb4a82b
hgweb: Added archive download buttons to manifest page.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1473
diff
changeset
|
200 for i in self.archives: |
78590fb4a82b
hgweb: Added archive download buttons to manifest page.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1473
diff
changeset
|
201 if self.repo.ui.configbool("web", "allow" + i, False): |
78590fb4a82b
hgweb: Added archive download buttons to manifest page.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1473
diff
changeset
|
202 yield {"type" : i, "node" : nodeid} |
78590fb4a82b
hgweb: Added archive download buttons to manifest page.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1473
diff
changeset
|
203 |
138 | 204 def listfiles(self, files, mf): |
205 for f in files[:self.maxfiles]: | |
1062 | 206 yield self.t("filenodelink", node=hex(mf[f]), file=f) |
138 | 207 if len(files) > self.maxfiles: |
208 yield self.t("fileellipses") | |
209 | |
210 def listfilediffs(self, files, changeset): | |
211 for f in files[:self.maxfiles]: | |
1062 | 212 yield self.t("filedifflink", node=hex(changeset), file=f) |
138 | 213 if len(files) > self.maxfiles: |
214 yield self.t("fileellipses") | |
215 | |
1416
19d2776f1725
hgweb: hide trivial parent (like in show_changeset)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1411
diff
changeset
|
216 def parents(self, node, parents=[], rev=None, hide=False, **args): |
1063
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
217 if not rev: |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
218 rev = lambda x: "" |
1416
19d2776f1725
hgweb: hide trivial parent (like in show_changeset)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1411
diff
changeset
|
219 parents = [p for p in parents if p != nullid] |
19d2776f1725
hgweb: hide trivial parent (like in show_changeset)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1411
diff
changeset
|
220 if hide and len(parents) == 1 and rev(parents[0]) == rev(node) - 1: |
19d2776f1725
hgweb: hide trivial parent (like in show_changeset)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1411
diff
changeset
|
221 return |
19d2776f1725
hgweb: hide trivial parent (like in show_changeset)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1411
diff
changeset
|
222 for p in parents: |
19d2776f1725
hgweb: hide trivial parent (like in show_changeset)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1411
diff
changeset
|
223 yield dict(node=hex(p), rev=rev(p), **args) |
569
3e347929f5f9
[PATCH 1/5]: cleaning the template parent management in hgweb
mpm@selenic.com
parents:
568
diff
changeset
|
224 |
568 | 225 def showtag(self, t1, node=nullid, **args): |
226 for t in self.repo.nodetags(node): | |
1062 | 227 yield self.t(t1, tag=t, **args) |
568 | 228 |
138 | 229 def diff(self, node1, node2, files): |
230 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
|
231 l = [x for x in list if x in files] |
515 | 232 |
138 | 233 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
|
234 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
|
235 f += os.sep |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
236 l += [x for x in list if x.startswith(f)] |
138 | 237 return l |
131 | 238 |
172
e9b1147db448
hgweb: alternating colors for multifile diffs
mpm@selenic.com
parents:
168
diff
changeset
|
239 parity = [0] |
e9b1147db448
hgweb: alternating colors for multifile diffs
mpm@selenic.com
parents:
168
diff
changeset
|
240 def diffblock(diff, f, fn): |
e9b1147db448
hgweb: alternating colors for multifile diffs
mpm@selenic.com
parents:
168
diff
changeset
|
241 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
|
242 lines=prettyprintlines(diff), |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
243 parity=parity[0], |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
244 file=f, |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
245 filenode=hex(fn or nullid)) |
172
e9b1147db448
hgweb: alternating colors for multifile diffs
mpm@selenic.com
parents:
168
diff
changeset
|
246 parity[0] = 1 - parity[0] |
515 | 247 |
172
e9b1147db448
hgweb: alternating colors for multifile diffs
mpm@selenic.com
parents:
168
diff
changeset
|
248 def prettyprintlines(diff): |
138 | 249 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
|
250 if l.startswith('+'): |
1062 | 251 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
|
252 elif l.startswith('-'): |
1062 | 253 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
|
254 elif l.startswith('@'): |
1062 | 255 yield self.t("difflineat", line=l) |
138 | 256 else: |
1062 | 257 yield self.t("diffline", line=l) |
131 | 258 |
138 | 259 r = self.repo |
260 cl = r.changelog | |
261 mf = r.manifest | |
262 change1 = cl.read(node1) | |
263 change2 = cl.read(node2) | |
264 mmap1 = mf.read(change1[0]) | |
265 mmap2 = mf.read(change2[0]) | |
1333
901c645c1943
hgweb: fix date bug in hgweb diff generation
mpm@selenic.com
parents:
1324
diff
changeset
|
266 date1 = util.datestr(change1[2]) |
901c645c1943
hgweb: fix date bug in hgweb diff generation
mpm@selenic.com
parents:
1324
diff
changeset
|
267 date2 = util.datestr(change2[2]) |
131 | 268 |
539 | 269 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
|
270 if files: |
a55048b2ae3a
this patch permits hgweb to show the deleted files in the changeset diff
kreijack@inwind.REMOVEME.it
parents:
635
diff
changeset
|
271 c, a, d = map(lambda x: filterfiles(x, files), (c, a, d)) |
131 | 272 |
138 | 273 for f in c: |
274 to = r.file(f).read(mmap1[f]) | |
275 tn = r.file(f).read(mmap2[f]) | |
172
e9b1147db448
hgweb: alternating colors for multifile diffs
mpm@selenic.com
parents:
168
diff
changeset
|
276 yield diffblock(mdiff.unidiff(to, date1, tn, date2, f), f, tn) |
138 | 277 for f in a: |
265
7ca05593bd30
hgweb: fix non-existent source or destination for diff
mpm@selenic.com
parents:
258
diff
changeset
|
278 to = None |
138 | 279 tn = r.file(f).read(mmap2[f]) |
172
e9b1147db448
hgweb: alternating colors for multifile diffs
mpm@selenic.com
parents:
168
diff
changeset
|
280 yield diffblock(mdiff.unidiff(to, date1, tn, date2, f), f, tn) |
138 | 281 for f in d: |
282 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
|
283 tn = None |
172
e9b1147db448
hgweb: alternating colors for multifile diffs
mpm@selenic.com
parents:
168
diff
changeset
|
284 yield diffblock(mdiff.unidiff(to, date1, tn, date2, f), f, tn) |
131 | 285 |
180 | 286 def changelog(self, pos): |
857
41b344235bb7
[PATCH] Propagate the template map though recursively
Jeff Sipek <jeffpc@optonline.net>
parents:
839
diff
changeset
|
287 def changenav(**map): |
1062 | 288 def seq(factor=1): |
138 | 289 yield 1 * factor |
173
8da1df932c16
hgweb: make navigation of changesets a bit nicer
mpm@selenic.com
parents:
172
diff
changeset
|
290 yield 3 * factor |
8da1df932c16
hgweb: make navigation of changesets a bit nicer
mpm@selenic.com
parents:
172
diff
changeset
|
291 #yield 5 * factor |
138 | 292 for f in seq(factor * 10): |
293 yield f | |
131 | 294 |
173
8da1df932c16
hgweb: make navigation of changesets a bit nicer
mpm@selenic.com
parents:
172
diff
changeset
|
295 l = [] |
8da1df932c16
hgweb: make navigation of changesets a bit nicer
mpm@selenic.com
parents:
172
diff
changeset
|
296 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
|
297 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
|
298 continue |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
299 if f > count: |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
300 break |
173
8da1df932c16
hgweb: make navigation of changesets a bit nicer
mpm@selenic.com
parents:
172
diff
changeset
|
301 r = "%d" % f |
1063
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
302 if pos + f < count: |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
303 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
|
304 if pos - f >= 0: |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
305 l.insert(0, ("-" + r, pos - f)) |
173
8da1df932c16
hgweb: make navigation of changesets a bit nicer
mpm@selenic.com
parents:
172
diff
changeset
|
306 |
975
bdd7c53fca00
hgweb: Changed changelog page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
974
diff
changeset
|
307 yield {"rev": 0, "label": "(0)"} |
515 | 308 |
173
8da1df932c16
hgweb: make navigation of changesets a bit nicer
mpm@selenic.com
parents:
172
diff
changeset
|
309 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
|
310 yield {"label": label, "rev": rev} |
173
8da1df932c16
hgweb: make navigation of changesets a bit nicer
mpm@selenic.com
parents:
172
diff
changeset
|
311 |
1409
964baa35faf8
hgweb: add shortcuts for all the web commands / fix empty arg bug
Matt Mackall <mpm@selenic.com>
parents:
1407
diff
changeset
|
312 yield {"label": "tip", "rev": "tip"} |
131 | 313 |
857
41b344235bb7
[PATCH] Propagate the template map though recursively
Jeff Sipek <jeffpc@optonline.net>
parents:
839
diff
changeset
|
314 def changelist(**map): |
142 | 315 parity = (start - end) & 1 |
138 | 316 cl = self.repo.changelog |
317 l = [] # build a list in forward order for efficiency | |
351 | 318 for i in range(start, end): |
138 | 319 n = cl.node(i) |
320 changes = cl.read(n) | |
321 hn = hex(n) | |
131 | 322 |
1063
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
323 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
|
324 "author": changes[1], |
1416
19d2776f1725
hgweb: hide trivial parent (like in show_changeset)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1411
diff
changeset
|
325 "parent": self.parents(n, cl.parents(n), cl.rev, |
19d2776f1725
hgweb: hide trivial parent (like in show_changeset)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1411
diff
changeset
|
326 hide=True), |
1063
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
327 "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
|
328 "manifest": hex(changes[0]), |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
329 "desc": changes[4], |
1324
77cd8068dbf4
hgweb: pass date tuples around rather than whole changesets for dates
mpm@selenic.com
parents:
1321
diff
changeset
|
330 "date": changes[2], |
1063
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
331 "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
|
332 "rev": i, |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
333 "node": hn}) |
142 | 334 parity = 1 - parity |
138 | 335 |
1063
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
336 for e in l: |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
337 yield e |
131 | 338 |
168 | 339 cl = self.repo.changelog |
340 mf = cl.read(cl.tip())[0] | |
341 count = cl.count() | |
351 | 342 start = max(0, pos - self.maxchanges + 1) |
343 end = min(count, start + self.maxchanges) | |
344 pos = end - 1 | |
138 | 345 |
142 | 346 yield self.t('changelog', |
1062 | 347 changenav=changenav, |
348 manifest=hex(mf), | |
349 rev=pos, changesets=count, entries=changelist) | |
131 | 350 |
538 | 351 def search(self, query): |
352 | |
857
41b344235bb7
[PATCH] Propagate the template map though recursively
Jeff Sipek <jeffpc@optonline.net>
parents:
839
diff
changeset
|
353 def changelist(**map): |
538 | 354 cl = self.repo.changelog |
355 count = 0 | |
356 qw = query.lower().split() | |
357 | |
358 def revgen(): | |
359 for i in range(cl.count() - 1, 0, -100): | |
360 l = [] | |
361 for j in range(max(0, i - 100), i): | |
362 n = cl.node(j) | |
363 changes = cl.read(n) | |
1023 | 364 l.append((n, j, changes)) |
365 l.reverse() | |
538 | 366 for e in l: |
367 yield e | |
368 | |
369 for n, i, changes in revgen(): | |
370 miss = 0 | |
371 for q in qw: | |
372 if not (q in changes[1].lower() or | |
373 q in changes[4].lower() or | |
374 q in " ".join(changes[3][:20]).lower()): | |
375 miss = 1 | |
376 break | |
1063
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
377 if miss: |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
378 continue |
538 | 379 |
380 count += 1 | |
381 hn = hex(n) | |
382 | |
1063
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
383 yield self.t('searchentry', |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
384 parity=count & 1, |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
385 author=changes[1], |
1416
19d2776f1725
hgweb: hide trivial parent (like in show_changeset)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1411
diff
changeset
|
386 parent=self.parents(n, cl.parents(n), cl.rev), |
1063
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
387 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
|
388 manifest=hex(changes[0]), |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
389 desc=changes[4], |
1324
77cd8068dbf4
hgweb: pass date tuples around rather than whole changesets for dates
mpm@selenic.com
parents:
1321
diff
changeset
|
390 date=changes[2], |
1063
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
391 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
|
392 rev=i, |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
393 node=hn) |
538 | 394 |
1063
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
395 if count >= self.maxchanges: |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
396 break |
538 | 397 |
398 cl = self.repo.changelog | |
399 mf = cl.read(cl.tip())[0] | |
400 | |
401 yield self.t('search', | |
1062 | 402 query=query, |
403 manifest=hex(mf), | |
404 entries=changelist) | |
538 | 405 |
138 | 406 def changeset(self, nodeid): |
407 cl = self.repo.changelog | |
1369
b6d4ebebc35c
Allows abbreviated hashes in hgweb
Matt Mackall <mpm@selenic.com>
parents:
1348
diff
changeset
|
408 n = self.repo.lookup(nodeid) |
b6d4ebebc35c
Allows abbreviated hashes in hgweb
Matt Mackall <mpm@selenic.com>
parents:
1348
diff
changeset
|
409 nodeid = hex(n) |
138 | 410 changes = cl.read(n) |
598
f8d44a2e6928
[PATCH 4/5]: cleaning the template parent management in hgweb
mpm@selenic.com
parents:
582
diff
changeset
|
411 p1 = cl.parents(n)[0] |
515 | 412 |
133
fb84d3e71042
added template support for some hgweb output, also, template files for
jake@edge2.net
parents:
132
diff
changeset
|
413 files = [] |
138 | 414 mf = self.repo.manifest.read(changes[0]) |
131 | 415 for f in changes[3]: |
138 | 416 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
|
417 filenode=hex(mf.get(f, nullid)), file=f)) |
138 | 418 |
857
41b344235bb7
[PATCH] Propagate the template map though recursively
Jeff Sipek <jeffpc@optonline.net>
parents:
839
diff
changeset
|
419 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
|
420 yield self.diff(p1, n, None) |
131 | 421 |
138 | 422 yield self.t('changeset', |
1062 | 423 diff=diff, |
424 rev=cl.rev(n), | |
425 node=nodeid, | |
1416
19d2776f1725
hgweb: hide trivial parent (like in show_changeset)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1411
diff
changeset
|
426 parent=self.parents(n, 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], | |
1324
77cd8068dbf4
hgweb: pass date tuples around rather than whole changesets for dates
mpm@selenic.com
parents:
1321
diff
changeset
|
431 date=changes[2], |
1076
01db658cc78a
tarball support v0.3
Wojciech Milkowski <wmilkowski@interia.pl>
parents:
1073
diff
changeset
|
432 files=files, |
1498
78590fb4a82b
hgweb: Added archive download buttons to manifest page.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1473
diff
changeset
|
433 archives=self.archivelist(nodeid)) |
131 | 434 |
138 | 435 def filelog(self, f, filenode): |
436 cl = self.repo.changelog | |
437 fl = self.repo.file(f) | |
1369
b6d4ebebc35c
Allows abbreviated hashes in hgweb
Matt Mackall <mpm@selenic.com>
parents:
1348
diff
changeset
|
438 filenode = hex(fl.lookup(filenode)) |
138 | 439 count = fl.count() |
440 | |
857
41b344235bb7
[PATCH] Propagate the template map though recursively
Jeff Sipek <jeffpc@optonline.net>
parents:
839
diff
changeset
|
441 def entries(**map): |
138 | 442 l = [] |
142 | 443 parity = (count - 1) & 1 |
515 | 444 |
138 | 445 for i in range(count): |
446 n = fl.node(i) | |
447 lr = fl.linkrev(n) | |
448 cn = cl.node(lr) | |
449 cs = cl.read(cl.node(lr)) | |
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], |
1324
77cd8068dbf4
hgweb: pass date tuples around rather than whole changesets for dates
mpm@selenic.com
parents:
1321
diff
changeset
|
457 "date": cs[2], |
1416
19d2776f1725
hgweb: hide trivial parent (like in show_changeset)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1411
diff
changeset
|
458 "parent": self.parents(n, fl.parents(n), |
1063
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
459 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
|
460 "desc": cs[4]}) |
142 | 461 parity = 1 - parity |
138 | 462 |
1063
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
463 for e in l: |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
464 yield e |
138 | 465 |
1063
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
466 yield self.t("filelog", file=f, filenode=filenode, entries=entries) |
131 | 467 |
138 | 468 def filerevision(self, f, node): |
469 fl = self.repo.file(f) | |
1369
b6d4ebebc35c
Allows abbreviated hashes in hgweb
Matt Mackall <mpm@selenic.com>
parents:
1348
diff
changeset
|
470 n = fl.lookup(node) |
b6d4ebebc35c
Allows abbreviated hashes in hgweb
Matt Mackall <mpm@selenic.com>
parents:
1348
diff
changeset
|
471 node = hex(n) |
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 mfn = cs[0] | |
142 | 478 |
1411
e2ba788545bf
hgweb: make viewing of non-text work in hgweb
Matt Mackall <mpm@selenic.com>
parents:
1409
diff
changeset
|
479 mt = mimetypes.guess_type(f)[0] |
e2ba788545bf
hgweb: make viewing of non-text work in hgweb
Matt Mackall <mpm@selenic.com>
parents:
1409
diff
changeset
|
480 rawtext = text |
e2ba788545bf
hgweb: make viewing of non-text work in hgweb
Matt Mackall <mpm@selenic.com>
parents:
1409
diff
changeset
|
481 if util.binary(text): |
e2ba788545bf
hgweb: make viewing of non-text work in hgweb
Matt Mackall <mpm@selenic.com>
parents:
1409
diff
changeset
|
482 text = "(binary:%s)" % mt |
e2ba788545bf
hgweb: make viewing of non-text work in hgweb
Matt Mackall <mpm@selenic.com>
parents:
1409
diff
changeset
|
483 |
142 | 484 def lines(): |
485 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
|
486 yield {"line": t, |
5d5ab159d197
hgweb: Changed file page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
975
diff
changeset
|
487 "linenumber": "% 6d" % (l + 1), |
5d5ab159d197
hgweb: Changed file page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
975
diff
changeset
|
488 "parity": l & 1} |
359 | 489 |
1063
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
490 yield self.t("filerevision", |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
491 file=f, |
1062 | 492 filenode=node, |
493 path=up(f), | |
494 text=lines(), | |
1411
e2ba788545bf
hgweb: make viewing of non-text work in hgweb
Matt Mackall <mpm@selenic.com>
parents:
1409
diff
changeset
|
495 raw=rawtext, |
e2ba788545bf
hgweb: make viewing of non-text work in hgweb
Matt Mackall <mpm@selenic.com>
parents:
1409
diff
changeset
|
496 mimetype=mt, |
1062 | 497 rev=changerev, |
498 node=hex(cn), | |
499 manifest=hex(mfn), | |
500 author=cs[1], | |
1324
77cd8068dbf4
hgweb: pass date tuples around rather than whole changesets for dates
mpm@selenic.com
parents:
1321
diff
changeset
|
501 date=cs[2], |
1416
19d2776f1725
hgweb: hide trivial parent (like in show_changeset)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1411
diff
changeset
|
502 parent=self.parents(n, fl.parents(n), fl.rev, file=f), |
1062 | 503 permissions=self.repo.manifest.readflags(mfn)[f]) |
138 | 504 |
505 def fileannotate(self, f, node): | |
506 bcache = {} | |
507 ncache = {} | |
508 fl = self.repo.file(f) | |
1369
b6d4ebebc35c
Allows abbreviated hashes in hgweb
Matt Mackall <mpm@selenic.com>
parents:
1348
diff
changeset
|
509 n = fl.lookup(node) |
b6d4ebebc35c
Allows abbreviated hashes in hgweb
Matt Mackall <mpm@selenic.com>
parents:
1348
diff
changeset
|
510 node = hex(n) |
138 | 511 changerev = fl.linkrev(n) |
512 | |
513 cl = self.repo.changelog | |
514 cn = cl.node(changerev) | |
515 cs = cl.read(cn) | |
516 mfn = cs[0] | |
131 | 517 |
857
41b344235bb7
[PATCH] Propagate the template map though recursively
Jeff Sipek <jeffpc@optonline.net>
parents:
839
diff
changeset
|
518 def annotate(**map): |
142 | 519 parity = 1 |
520 last = None | |
138 | 521 for r, l in fl.annotate(n): |
522 try: | |
523 cnode = ncache[r] | |
524 except KeyError: | |
525 cnode = ncache[r] = self.repo.changelog.node(r) | |
515 | 526 |
138 | 527 try: |
528 name = bcache[r] | |
529 except KeyError: | |
530 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
|
531 bcache[r] = name = self.repo.ui.shortuser(cl[1]) |
131 | 532 |
142 | 533 if last != cnode: |
534 parity = 1 - parity | |
535 last = cnode | |
536 | |
977
289975641886
hgweb: Changed annotate page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
976
diff
changeset
|
537 yield {"parity": parity, |
289975641886
hgweb: Changed annotate page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
976
diff
changeset
|
538 "node": hex(cnode), |
289975641886
hgweb: Changed annotate page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
976
diff
changeset
|
539 "rev": r, |
289975641886
hgweb: Changed annotate page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
976
diff
changeset
|
540 "author": name, |
289975641886
hgweb: Changed annotate page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
976
diff
changeset
|
541 "file": f, |
289975641886
hgweb: Changed annotate page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
976
diff
changeset
|
542 "line": l} |
138 | 543 |
544 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
|
545 file=f, |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
546 filenode=node, |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
547 annotate=annotate, |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
548 path=up(f), |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
549 rev=changerev, |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
550 node=hex(cn), |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
551 manifest=hex(mfn), |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
552 author=cs[1], |
1324
77cd8068dbf4
hgweb: pass date tuples around rather than whole changesets for dates
mpm@selenic.com
parents:
1321
diff
changeset
|
553 date=cs[2], |
1416
19d2776f1725
hgweb: hide trivial parent (like in show_changeset)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1411
diff
changeset
|
554 parent=self.parents(n, fl.parents(n), fl.rev, file=f), |
1063
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
555 permissions=self.repo.manifest.readflags(mfn)[f]) |
136 | 556 |
138 | 557 def manifest(self, mnode, path): |
1369
b6d4ebebc35c
Allows abbreviated hashes in hgweb
Matt Mackall <mpm@selenic.com>
parents:
1348
diff
changeset
|
558 man = self.repo.manifest |
b6d4ebebc35c
Allows abbreviated hashes in hgweb
Matt Mackall <mpm@selenic.com>
parents:
1348
diff
changeset
|
559 mn = man.lookup(mnode) |
b6d4ebebc35c
Allows abbreviated hashes in hgweb
Matt Mackall <mpm@selenic.com>
parents:
1348
diff
changeset
|
560 mnode = hex(mn) |
b6d4ebebc35c
Allows abbreviated hashes in hgweb
Matt Mackall <mpm@selenic.com>
parents:
1348
diff
changeset
|
561 mf = man.read(mn) |
b6d4ebebc35c
Allows abbreviated hashes in hgweb
Matt Mackall <mpm@selenic.com>
parents:
1348
diff
changeset
|
562 rev = man.rev(mn) |
138 | 563 node = self.repo.changelog.node(rev) |
1369
b6d4ebebc35c
Allows abbreviated hashes in hgweb
Matt Mackall <mpm@selenic.com>
parents:
1348
diff
changeset
|
564 mff = man.readflags(mn) |
138 | 565 |
566 files = {} | |
515 | 567 |
138 | 568 p = path[1:] |
569 l = len(p) | |
131 | 570 |
138 | 571 for f,n in mf.items(): |
572 if f[:l] != p: | |
573 continue | |
574 remain = f[l:] | |
575 if "/" in remain: | |
576 short = remain[:remain.find("/") + 1] # bleah | |
142 | 577 files[short] = (f, None) |
138 | 578 else: |
579 short = os.path.basename(remain) | |
580 files[short] = (f, n) | |
131 | 581 |
857
41b344235bb7
[PATCH] Propagate the template map though recursively
Jeff Sipek <jeffpc@optonline.net>
parents:
839
diff
changeset
|
582 def filelist(**map): |
142 | 583 parity = 0 |
138 | 584 fl = files.keys() |
585 fl.sort() | |
586 for f in fl: | |
587 full, fnode = files[f] | |
979
87d40e085e08
hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
978
diff
changeset
|
588 if not fnode: |
87d40e085e08
hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
978
diff
changeset
|
589 continue |
87d40e085e08
hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
978
diff
changeset
|
590 |
87d40e085e08
hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
978
diff
changeset
|
591 yield {"file": full, |
87d40e085e08
hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
978
diff
changeset
|
592 "manifest": mnode, |
87d40e085e08
hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
978
diff
changeset
|
593 "filenode": hex(fnode), |
87d40e085e08
hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
978
diff
changeset
|
594 "parity": parity, |
87d40e085e08
hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
978
diff
changeset
|
595 "basename": f, |
87d40e085e08
hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
978
diff
changeset
|
596 "permissions": mff[full]} |
142 | 597 parity = 1 - parity |
138 | 598 |
979
87d40e085e08
hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
978
diff
changeset
|
599 def dirlist(**map): |
87d40e085e08
hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
978
diff
changeset
|
600 parity = 0 |
87d40e085e08
hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
978
diff
changeset
|
601 fl = files.keys() |
87d40e085e08
hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
978
diff
changeset
|
602 fl.sort() |
87d40e085e08
hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
978
diff
changeset
|
603 for f in fl: |
87d40e085e08
hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
978
diff
changeset
|
604 full, fnode = files[f] |
87d40e085e08
hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
978
diff
changeset
|
605 if fnode: |
87d40e085e08
hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
978
diff
changeset
|
606 continue |
87d40e085e08
hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
978
diff
changeset
|
607 |
87d40e085e08
hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
978
diff
changeset
|
608 yield {"parity": parity, |
87d40e085e08
hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
978
diff
changeset
|
609 "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
|
610 "manifest": mnode, |
980 | 611 "basename": f[:-1]} |
979
87d40e085e08
hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
978
diff
changeset
|
612 parity = 1 - parity |
982
8d2e24bae760
hgweb: convert index entries to list expansion style
mpm@selenic.com
parents:
981
diff
changeset
|
613 |
138 | 614 yield self.t("manifest", |
1062 | 615 manifest=mnode, |
616 rev=rev, | |
617 node=hex(node), | |
618 path=path, | |
619 up=up(path), | |
620 fentries=filelist, | |
1498
78590fb4a82b
hgweb: Added archive download buttons to manifest page.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1473
diff
changeset
|
621 dentries=dirlist, |
78590fb4a82b
hgweb: Added archive download buttons to manifest page.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1473
diff
changeset
|
622 archives=self.archivelist(hex(node))) |
131 | 623 |
168 | 624 def tags(self): |
625 cl = self.repo.changelog | |
626 mf = cl.read(cl.tip())[0] | |
627 | |
343 | 628 i = self.repo.tagslist() |
629 i.reverse() | |
168 | 630 |
857
41b344235bb7
[PATCH] Propagate the template map though recursively
Jeff Sipek <jeffpc@optonline.net>
parents:
839
diff
changeset
|
631 def entries(**map): |
168 | 632 parity = 0 |
633 for k,n in i: | |
974
aedb47764f29
Added support for #foo%bar# syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
938
diff
changeset
|
634 yield {"parity": parity, |
aedb47764f29
Added support for #foo%bar# syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
938
diff
changeset
|
635 "tag": k, |
aedb47764f29
Added support for #foo%bar# syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
938
diff
changeset
|
636 "node": hex(n)} |
168 | 637 parity = 1 - parity |
638 | |
639 yield self.t("tags", | |
1062 | 640 manifest=hex(mf), |
641 entries=entries) | |
168 | 642 |
138 | 643 def filediff(self, file, changeset): |
644 cl = self.repo.changelog | |
1369
b6d4ebebc35c
Allows abbreviated hashes in hgweb
Matt Mackall <mpm@selenic.com>
parents:
1348
diff
changeset
|
645 n = self.repo.lookup(changeset) |
b6d4ebebc35c
Allows abbreviated hashes in hgweb
Matt Mackall <mpm@selenic.com>
parents:
1348
diff
changeset
|
646 changeset = hex(n) |
138 | 647 p1 = cl.parents(n)[0] |
648 cs = cl.read(n) | |
649 mf = self.repo.manifest.read(cs[0]) | |
515 | 650 |
857
41b344235bb7
[PATCH] Propagate the template map though recursively
Jeff Sipek <jeffpc@optonline.net>
parents:
839
diff
changeset
|
651 def diff(**map): |
138 | 652 yield self.diff(p1, n, file) |
131 | 653 |
138 | 654 yield self.t("filediff", |
1062 | 655 file=file, |
656 filenode=hex(mf.get(file, nullid)), | |
657 node=changeset, | |
658 rev=self.repo.changelog.rev(n), | |
1416
19d2776f1725
hgweb: hide trivial parent (like in show_changeset)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1411
diff
changeset
|
659 parent=self.parents(n, cl.parents(n), cl.rev), |
1062 | 660 diff=diff) |
515 | 661 |
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
|
662 def archive(self, req, cnode, type): |
1078 | 663 cs = self.repo.changelog.read(cnode) |
664 mnode = cs[0] | |
665 mf = self.repo.manifest.read(mnode) | |
666 rev = self.repo.manifest.rev(mnode) | |
667 reponame = re.sub(r"\W+", "-", self.reponame) | |
668 name = "%s-%s/" % (reponame, short(cnode)) | |
669 | |
1112
87cbfaf79124
hgweb: add mdiff / fix sorting of archives
mpm@selenic.com
parents:
1099
diff
changeset
|
670 files = mf.keys() |
87cbfaf79124
hgweb: add mdiff / fix sorting of archives
mpm@selenic.com
parents:
1099
diff
changeset
|
671 files.sort() |
87cbfaf79124
hgweb: add mdiff / fix sorting of archives
mpm@selenic.com
parents:
1099
diff
changeset
|
672 |
1077
b87aeccf73d9
tarball support v0.3 pt 2
Wojciech Milkowski <wmilkowski@interia.pl>
parents:
1076
diff
changeset
|
673 if type == 'zip': |
1165
04be5eb73bb3
Fixed import needed to serve zip files which broke because of other changes.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1163
diff
changeset
|
674 tmp = tempfile.mkstemp()[1] |
1078 | 675 try: |
676 zf = zipfile.ZipFile(tmp, "w", zipfile.ZIP_DEFLATED) | |
677 | |
1112
87cbfaf79124
hgweb: add mdiff / fix sorting of archives
mpm@selenic.com
parents:
1099
diff
changeset
|
678 for f in files: |
1078 | 679 zf.writestr(name + f, self.repo.file(f).read(mf[f])) |
680 zf.close() | |
1076
01db658cc78a
tarball support v0.3
Wojciech Milkowski <wmilkowski@interia.pl>
parents:
1073
diff
changeset
|
681 |
1078 | 682 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
|
683 req.httphdr('application/zip', name[:-1] + '.zip', |
1078 | 684 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
|
685 req.write(f.read()) |
1078 | 686 f.close() |
687 finally: | |
688 os.unlink(tmp) | |
1076
01db658cc78a
tarball support v0.3
Wojciech Milkowski <wmilkowski@interia.pl>
parents:
1073
diff
changeset
|
689 |
1077
b87aeccf73d9
tarball support v0.3 pt 2
Wojciech Milkowski <wmilkowski@interia.pl>
parents:
1076
diff
changeset
|
690 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
|
691 tf = tarfile.TarFile.open(mode='w|' + type, fileobj=req.out) |
1078 | 692 mff = self.repo.manifest.readflags(mnode) |
1077
b87aeccf73d9
tarball support v0.3 pt 2
Wojciech Milkowski <wmilkowski@interia.pl>
parents:
1076
diff
changeset
|
693 mtime = int(time.time()) |
1076
01db658cc78a
tarball support v0.3
Wojciech Milkowski <wmilkowski@interia.pl>
parents:
1073
diff
changeset
|
694 |
1185
2ae9c319e6fe
Output Content-encoding for tar.gz and tar.bz2 snapshots
Edouard Gomez <ed.gomez@free.fr>
parents:
1182
diff
changeset
|
695 if type == "gz": |
2ae9c319e6fe
Output Content-encoding for tar.gz and tar.bz2 snapshots
Edouard Gomez <ed.gomez@free.fr>
parents:
1182
diff
changeset
|
696 encoding = "gzip" |
2ae9c319e6fe
Output Content-encoding for tar.gz and tar.bz2 snapshots
Edouard Gomez <ed.gomez@free.fr>
parents:
1182
diff
changeset
|
697 else: |
2ae9c319e6fe
Output Content-encoding for tar.gz and tar.bz2 snapshots
Edouard Gomez <ed.gomez@free.fr>
parents:
1182
diff
changeset
|
698 encoding = "x-bzip2" |
1308
2073e5a71008
Cleanup of tabs and trailing spaces.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1275
diff
changeset
|
699 req.header([('Content-type', 'application/x-tar'), |
1185
2ae9c319e6fe
Output Content-encoding for tar.gz and tar.bz2 snapshots
Edouard Gomez <ed.gomez@free.fr>
parents:
1182
diff
changeset
|
700 ('Content-disposition', 'attachment; filename=%s%s%s' % |
2ae9c319e6fe
Output Content-encoding for tar.gz and tar.bz2 snapshots
Edouard Gomez <ed.gomez@free.fr>
parents:
1182
diff
changeset
|
701 (name[:-1], '.tar.', type)), |
2ae9c319e6fe
Output Content-encoding for tar.gz and tar.bz2 snapshots
Edouard Gomez <ed.gomez@free.fr>
parents:
1182
diff
changeset
|
702 ('Content-encoding', encoding)]) |
1112
87cbfaf79124
hgweb: add mdiff / fix sorting of archives
mpm@selenic.com
parents:
1099
diff
changeset
|
703 for fname in files: |
1078 | 704 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
|
705 finfo = tarfile.TarInfo(name + fname) |
b87aeccf73d9
tarball support v0.3 pt 2
Wojciech Milkowski <wmilkowski@interia.pl>
parents:
1076
diff
changeset
|
706 finfo.mtime = mtime |
b87aeccf73d9
tarball support v0.3 pt 2
Wojciech Milkowski <wmilkowski@interia.pl>
parents:
1076
diff
changeset
|
707 finfo.size = len(rcont) |
b87aeccf73d9
tarball support v0.3 pt 2
Wojciech Milkowski <wmilkowski@interia.pl>
parents:
1076
diff
changeset
|
708 finfo.mode = mff[fname] and 0755 or 0644 |
b87aeccf73d9
tarball support v0.3 pt 2
Wojciech Milkowski <wmilkowski@interia.pl>
parents:
1076
diff
changeset
|
709 tf.addfile(finfo, StringIO.StringIO(rcont)) |
b87aeccf73d9
tarball support v0.3 pt 2
Wojciech Milkowski <wmilkowski@interia.pl>
parents:
1076
diff
changeset
|
710 tf.close() |
1076
01db658cc78a
tarball support v0.3
Wojciech Milkowski <wmilkowski@interia.pl>
parents:
1073
diff
changeset
|
711 |
138 | 712 # add tags to things |
713 # tags -> list of changesets corresponding to tags | |
714 # find tag, changeset, file | |
131 | 715 |
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
|
716 def run(self, req=hgrequest()): |
857
41b344235bb7
[PATCH] Propagate the template map though recursively
Jeff Sipek <jeffpc@optonline.net>
parents:
839
diff
changeset
|
717 def header(**map): |
41b344235bb7
[PATCH] Propagate the template map though recursively
Jeff Sipek <jeffpc@optonline.net>
parents:
839
diff
changeset
|
718 yield self.t("header", **map) |
41b344235bb7
[PATCH] Propagate the template map though recursively
Jeff Sipek <jeffpc@optonline.net>
parents:
839
diff
changeset
|
719 |
41b344235bb7
[PATCH] Propagate the template map though recursively
Jeff Sipek <jeffpc@optonline.net>
parents:
839
diff
changeset
|
720 def footer(**map): |
41b344235bb7
[PATCH] Propagate the template map though recursively
Jeff Sipek <jeffpc@optonline.net>
parents:
839
diff
changeset
|
721 yield self.t("footer", **map) |
1409
964baa35faf8
hgweb: add shortcuts for all the web commands / fix empty arg bug
Matt Mackall <mpm@selenic.com>
parents:
1407
diff
changeset
|
722 |
1406
34cb3957d875
hgweb: allow urls to be shorter by using shortcuts
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1402
diff
changeset
|
723 def expand_form(form): |
34cb3957d875
hgweb: allow urls to be shorter by using shortcuts
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1402
diff
changeset
|
724 shortcuts = { |
1409
964baa35faf8
hgweb: add shortcuts for all the web commands / fix empty arg bug
Matt Mackall <mpm@selenic.com>
parents:
1407
diff
changeset
|
725 'cl': [('cmd', ['changelog']), ('rev', None)], |
1406
34cb3957d875
hgweb: allow urls to be shorter by using shortcuts
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1402
diff
changeset
|
726 'cs': [('cmd', ['changeset']), ('node', None)], |
1409
964baa35faf8
hgweb: add shortcuts for all the web commands / fix empty arg bug
Matt Mackall <mpm@selenic.com>
parents:
1407
diff
changeset
|
727 'f': [('cmd', ['file']), ('filenode', None)], |
964baa35faf8
hgweb: add shortcuts for all the web commands / fix empty arg bug
Matt Mackall <mpm@selenic.com>
parents:
1407
diff
changeset
|
728 'fl': [('cmd', ['filelog']), ('filenode', None)], |
964baa35faf8
hgweb: add shortcuts for all the web commands / fix empty arg bug
Matt Mackall <mpm@selenic.com>
parents:
1407
diff
changeset
|
729 'fd': [('cmd', ['filediff']), ('node', None)], |
964baa35faf8
hgweb: add shortcuts for all the web commands / fix empty arg bug
Matt Mackall <mpm@selenic.com>
parents:
1407
diff
changeset
|
730 'fa': [('cmd', ['annotate']), ('filenode', None)], |
964baa35faf8
hgweb: add shortcuts for all the web commands / fix empty arg bug
Matt Mackall <mpm@selenic.com>
parents:
1407
diff
changeset
|
731 'mf': [('cmd', ['manifest']), ('manifest', None)], |
964baa35faf8
hgweb: add shortcuts for all the web commands / fix empty arg bug
Matt Mackall <mpm@selenic.com>
parents:
1407
diff
changeset
|
732 'ca': [('cmd', ['archive']), ('node', None)], |
964baa35faf8
hgweb: add shortcuts for all the web commands / fix empty arg bug
Matt Mackall <mpm@selenic.com>
parents:
1407
diff
changeset
|
733 'tags': [('cmd', ['tags'])], |
964baa35faf8
hgweb: add shortcuts for all the web commands / fix empty arg bug
Matt Mackall <mpm@selenic.com>
parents:
1407
diff
changeset
|
734 'tip': [('cmd', ['changeset']), ('node', ['tip'])], |
1406
34cb3957d875
hgweb: allow urls to be shorter by using shortcuts
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1402
diff
changeset
|
735 } |
1409
964baa35faf8
hgweb: add shortcuts for all the web commands / fix empty arg bug
Matt Mackall <mpm@selenic.com>
parents:
1407
diff
changeset
|
736 |
1406
34cb3957d875
hgweb: allow urls to be shorter by using shortcuts
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1402
diff
changeset
|
737 for k in shortcuts.iterkeys(): |
34cb3957d875
hgweb: allow urls to be shorter by using shortcuts
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1402
diff
changeset
|
738 if form.has_key(k): |
34cb3957d875
hgweb: allow urls to be shorter by using shortcuts
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1402
diff
changeset
|
739 for name, value in shortcuts[k]: |
34cb3957d875
hgweb: allow urls to be shorter by using shortcuts
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1402
diff
changeset
|
740 if value is None: |
34cb3957d875
hgweb: allow urls to be shorter by using shortcuts
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1402
diff
changeset
|
741 value = form[k] |
34cb3957d875
hgweb: allow urls to be shorter by using shortcuts
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1402
diff
changeset
|
742 form[name] = value |
34cb3957d875
hgweb: allow urls to be shorter by using shortcuts
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1402
diff
changeset
|
743 del form[k] |
857
41b344235bb7
[PATCH] Propagate the template map though recursively
Jeff Sipek <jeffpc@optonline.net>
parents:
839
diff
changeset
|
744 |
258 | 745 self.refresh() |
132 | 746 |
1406
34cb3957d875
hgweb: allow urls to be shorter by using shortcuts
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1402
diff
changeset
|
747 expand_form(req.form) |
34cb3957d875
hgweb: allow urls to be shorter by using shortcuts
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1402
diff
changeset
|
748 |
987 | 749 t = self.repo.ui.config("web", "templates", templatepath()) |
938 | 750 m = os.path.join(t, "map") |
986 | 751 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
|
752 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
|
753 style = req.form['style'][0] |
986 | 754 if style: |
755 b = os.path.basename("map-" + style) | |
983 | 756 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
|
757 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
|
758 m = p |
515 | 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 port = req.env["SERVER_PORT"] |
601 | 761 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
|
762 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
|
763 if "?" in uri: |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
764 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
|
765 url = "http://%s%s%s" % (req.env["SERVER_NAME"], port, uri) |
1172
3f30a5e7e15b
Use path relative to document root as reponame if published via a web server.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1170
diff
changeset
|
766 if not self.reponame: |
3f30a5e7e15b
Use path relative to document root as reponame if published via a web server.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1170
diff
changeset
|
767 self.reponame = (self.repo.ui.config("web", "name") |
3f30a5e7e15b
Use path relative to document root as reponame if published via a web server.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1170
diff
changeset
|
768 or uri.strip('/') or self.repo.root) |
601 | 769 |
941 | 770 self.t = templater(m, common_filters, |
1062 | 771 {"url": url, |
772 "repo": self.reponame, | |
773 "header": header, | |
774 "footer": footer, | |
1063
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
775 }) |
201
f918a6fa2572
hgweb: add template filters, template style maps, and raw pages
mpm@selenic.com
parents:
198
diff
changeset
|
776 |
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
|
777 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
|
778 req.form['cmd'] = [self.t.cache['default'],] |
937 | 779 |
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
|
780 if req.form['cmd'][0] == 'changelog': |
538 | 781 c = self.repo.changelog.count() - 1 |
782 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
|
783 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
|
784 hi = req.form['rev'][0] |
166
39624c47060f
hgweb: don't blow up on search for unknown keys
mpm@selenic.com
parents:
165
diff
changeset
|
785 try: |
39624c47060f
hgweb: don't blow up on search for unknown keys
mpm@selenic.com
parents:
165
diff
changeset
|
786 hi = self.repo.changelog.rev(self.repo.lookup(hi)) |
1219 | 787 except hg.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
|
788 req.write(self.search(hi)) |
538 | 789 return |
575 | 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 req.write(self.changelog(hi)) |
515 | 792 |
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
|
793 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
|
794 req.write(self.changeset(req.form['node'][0])) |
138 | 795 |
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 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
|
797 req.write(self.manifest(req.form['manifest'][0], req.form['path'][0])) |
138 | 798 |
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
|
799 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
|
800 req.write(self.tags()) |
168 | 801 |
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
|
802 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
|
803 req.write(self.filediff(req.form['file'][0], req.form['node'][0])) |
131 | 804 |
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
|
805 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
|
806 req.write(self.filerevision(req.form['file'][0], req.form['filenode'][0])) |
131 | 807 |
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
|
808 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
|
809 req.write(self.fileannotate(req.form['file'][0], req.form['filenode'][0])) |
131 | 810 |
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
|
811 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
|
812 req.write(self.filelog(req.form['file'][0], req.form['filenode'][0])) |
136 | 813 |
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
|
814 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
|
815 req.httphdr("application/mercurial-0.1") |
222 | 816 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
|
817 req.write(" ".join(map(hex, h)) + "\n") |
222 | 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] == '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
|
820 req.httphdr("application/mercurial-0.1") |
132 | 821 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
|
822 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
|
823 nodes = map(bin, req.form['nodes'][0].split(" ")) |
138 | 824 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
|
825 req.write(" ".join(map(hex, b)) + "\n") |
131 | 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 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
|
828 req.httphdr("application/mercurial-0.1") |
132 | 829 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
|
830 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
|
831 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
|
832 for p in req.form['pairs'][0].split(" ")] |
138 | 833 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
|
834 req.write(" ".join(map(hex, b)) + "\n") |
132 | 835 |
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
|
836 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
|
837 req.httphdr("application/mercurial-0.1") |
132 | 838 nodes = [] |
964
3f37720e7dc7
hgweb: Make maxfiles, maxchanges, and allowpull proper config options
mpm@selenic.com
parents:
957
diff
changeset
|
839 if not self.allowpull: |
197 | 840 return |
841 | |
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
|
842 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
|
843 nodes = map(bin, req.form['roots'][0].split(" ")) |
131 | 844 |
132 | 845 z = zlib.compressobj() |
635
85e2209d401c
Protocol switch from using generators to stream-like objects.
Matt Mackall <mpm@selenic.com>
parents:
620
diff
changeset
|
846 f = self.repo.changegroup(nodes) |
85e2209d401c
Protocol switch from using generators to stream-like objects.
Matt Mackall <mpm@selenic.com>
parents:
620
diff
changeset
|
847 while 1: |
85e2209d401c
Protocol switch from using generators to stream-like objects.
Matt Mackall <mpm@selenic.com>
parents:
620
diff
changeset
|
848 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
|
849 if not chunk: |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
850 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
|
851 req.write(z.compress(chunk)) |
132 | 852 |
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
|
853 req.write(z.flush()) |
131 | 854 |
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
|
855 elif req.form['cmd'][0] == 'archive': |
1369
b6d4ebebc35c
Allows abbreviated hashes in hgweb
Matt Mackall <mpm@selenic.com>
parents:
1348
diff
changeset
|
856 changeset = self.repo.lookup(req.form['node'][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
|
857 type = req.form['type'][0] |
1078 | 858 if (type in self.archives and |
859 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
|
860 self.archive(req, changeset, type) |
1078 | 861 return |
1077
b87aeccf73d9
tarball support v0.3 pt 2
Wojciech Milkowski <wmilkowski@interia.pl>
parents:
1076
diff
changeset
|
862 |
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
|
863 req.write(self.t("error")) |
1076
01db658cc78a
tarball support v0.3
Wojciech Milkowski <wmilkowski@interia.pl>
parents:
1073
diff
changeset
|
864 |
132 | 865 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
|
866 req.write(self.t("error")) |
131 | 867 |
987 | 868 def create_server(repo): |
158
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
157
diff
changeset
|
869 |
938 | 870 def openlog(opt, default): |
871 if opt and opt != '-': | |
872 return open(opt, 'w') | |
873 return default | |
874 | |
987 | 875 address = repo.ui.config("web", "address", "") |
876 port = int(repo.ui.config("web", "port", 8000)) | |
877 use_ipv6 = repo.ui.configbool("web", "ipv6") | |
878 accesslog = openlog(repo.ui.config("web", "accesslog", "-"), sys.stdout) | |
879 errorlog = openlog(repo.ui.config("web", "errorlog", "-"), sys.stderr) | |
938 | 880 |
825
0108c602feb9
Add an option to hg serve to serve file using IPv6
Samuel Tardieu <sam@rfc1149.net>
parents:
753
diff
changeset
|
881 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
|
882 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
|
883 |
16ce690c411d
Fix problem with "hg serve" on systems not providing IPv6.
Bryan O'Sullivan <bos@serpentine.com>
parents:
858
diff
changeset
|
884 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
|
885 if self.address_family is None: |
1402
9d2c2e6b32b5
i18n part2: use '_' for all strings who are part of the user interface
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1400
diff
changeset
|
886 raise hg.RepoError(_('IPv6 not available on this system')) |
881
16ce690c411d
Fix problem with "hg serve" on systems not providing IPv6.
Bryan O'Sullivan <bos@serpentine.com>
parents:
858
diff
changeset
|
887 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
|
888 |
158
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
157
diff
changeset
|
889 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
|
890 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
|
891 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
|
892 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
|
893 format % args)) |
937 | 894 |
605
8e82fd763be2
[PATCH] Get "hg serve" to optionally log accesses and errors to files
mpm@selenic.com
parents:
603
diff
changeset
|
895 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
|
896 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
|
897 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
|
898 format % args)) |
8e82fd763be2
[PATCH] Get "hg serve" to optionally log accesses and errors to files
mpm@selenic.com
parents:
603
diff
changeset
|
899 |
158
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
157
diff
changeset
|
900 def do_POST(self): |
271 | 901 try: |
902 self.do_hgweb() | |
903 except socket.error, inst: | |
1174
9d9f4973c76a
Added missing 'import errno', and use errno for EPIPE, too.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1172
diff
changeset
|
904 if inst[0] != errno.EPIPE: |
1063
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
905 raise |
158
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
157
diff
changeset
|
906 |
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
157
diff
changeset
|
907 def do_GET(self): |
271 | 908 self.do_POST() |
158
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
157
diff
changeset
|
909 |
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
157
diff
changeset
|
910 def do_hgweb(self): |
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
157
diff
changeset
|
911 query = "" |
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
157
diff
changeset
|
912 p = self.path.find("?") |
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
157
diff
changeset
|
913 if p: |
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
157
diff
changeset
|
914 query = self.path[p + 1:] |
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
157
diff
changeset
|
915 query = query.replace('+', ' ') |
515 | 916 |
158
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
157
diff
changeset
|
917 env = {} |
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
157
diff
changeset
|
918 env['GATEWAY_INTERFACE'] = 'CGI/1.1' |
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
157
diff
changeset
|
919 env['REQUEST_METHOD'] = self.command |
599 | 920 env['SERVER_NAME'] = self.server.server_name |
921 env['SERVER_PORT'] = str(self.server.server_port) | |
922 env['REQUEST_URI'] = "/" | |
158
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
157
diff
changeset
|
923 if query: |
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
157
diff
changeset
|
924 env['QUERY_STRING'] = query |
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
157
diff
changeset
|
925 host = self.address_string() |
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
157
diff
changeset
|
926 if host != self.client_address[0]: |
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
157
diff
changeset
|
927 env['REMOTE_HOST'] = host |
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
157
diff
changeset
|
928 env['REMOTE_ADDR'] = self.client_address[0] |
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
157
diff
changeset
|
929 |
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
157
diff
changeset
|
930 if self.headers.typeheader is None: |
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
157
diff
changeset
|
931 env['CONTENT_TYPE'] = self.headers.type |
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
157
diff
changeset
|
932 else: |
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
157
diff
changeset
|
933 env['CONTENT_TYPE'] = self.headers.typeheader |
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
157
diff
changeset
|
934 length = self.headers.getheader('content-length') |
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
157
diff
changeset
|
935 if length: |
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
157
diff
changeset
|
936 env['CONTENT_LENGTH'] = length |
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
157
diff
changeset
|
937 accept = [] |
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
157
diff
changeset
|
938 for line in self.headers.getallmatchingheaders('accept'): |
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
157
diff
changeset
|
939 if line[:1] in "\t\n\r ": |
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
157
diff
changeset
|
940 accept.append(line.strip()) |
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
157
diff
changeset
|
941 else: |
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
157
diff
changeset
|
942 accept = accept + line[7:].split(',') |
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
157
diff
changeset
|
943 env['HTTP_ACCEPT'] = ','.join(accept) |
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
157
diff
changeset
|
944 |
1180
fe3eb1628c40
Saving sys.argv and sys.stderr is not needed anymore
Vincent Wagelaar <vincent@ricardis.tudelft.nl>
parents:
1163
diff
changeset
|
945 req = hgrequest(self.rfile, self.wfile, env) |
fe3eb1628c40
Saving sys.argv and sys.stderr is not needed anymore
Vincent Wagelaar <vincent@ricardis.tudelft.nl>
parents:
1163
diff
changeset
|
946 self.send_response(200, "Script output follows") |
fe3eb1628c40
Saving sys.argv and sys.stderr is not needed anymore
Vincent Wagelaar <vincent@ricardis.tudelft.nl>
parents:
1163
diff
changeset
|
947 hg.run(req) |
158
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
157
diff
changeset
|
948 |
987 | 949 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
|
950 if use_ipv6: |
0108c602feb9
Add an option to hg serve to serve file using IPv6
Samuel Tardieu <sam@rfc1149.net>
parents:
753
diff
changeset
|
951 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
|
952 else: |
0108c602feb9
Add an option to hg serve to serve file using IPv6
Samuel Tardieu <sam@rfc1149.net>
parents:
753
diff
changeset
|
953 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
|
954 |
1062 | 955 def server(path, name, templates, address, port, use_ipv6=False, |
956 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
|
957 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
|
958 accesslog, errorlog) |
158
be7103467d2e
Add 'hg serve' command for stand-alone server
mpm@selenic.com
parents:
157
diff
changeset
|
959 httpd.serve_forever() |
941 | 960 |
961 # This is a stopgap | |
962 class hgwebdir: | |
963 def __init__(self, config): | |
1181
4f5001f5b4c3
Make sure the repository names don't have slashes at the at or else in some
Vincent Wagelaar <vincent@ricardis.tudelft.nl>
parents:
1180
diff
changeset
|
964 def cleannames(items): |
4f5001f5b4c3
Make sure the repository names don't have slashes at the at or else in some
Vincent Wagelaar <vincent@ricardis.tudelft.nl>
parents:
1180
diff
changeset
|
965 return [(name.strip('/'), path) for name, path in items] |
4f5001f5b4c3
Make sure the repository names don't have slashes at the at or else in some
Vincent Wagelaar <vincent@ricardis.tudelft.nl>
parents:
1180
diff
changeset
|
966 |
1143
4fffb3d84b7c
Allow list of (virtual, real) or dictionary to be passed to hgwebdir.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1142
diff
changeset
|
967 if type(config) == type([]): |
1181
4f5001f5b4c3
Make sure the repository names don't have slashes at the at or else in some
Vincent Wagelaar <vincent@ricardis.tudelft.nl>
parents:
1180
diff
changeset
|
968 self.repos = cleannames(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
|
969 elif type(config) == type({}): |
1181
4f5001f5b4c3
Make sure the repository names don't have slashes at the at or else in some
Vincent Wagelaar <vincent@ricardis.tudelft.nl>
parents:
1180
diff
changeset
|
970 self.repos = cleannames(config.items()) |
1143
4fffb3d84b7c
Allow list of (virtual, real) or dictionary to be passed to hgwebdir.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1142
diff
changeset
|
971 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
|
972 else: |
4fffb3d84b7c
Allow list of (virtual, real) or dictionary to be passed to hgwebdir.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1142
diff
changeset
|
973 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
|
974 cp.read(config) |
1181
4f5001f5b4c3
Make sure the repository names don't have slashes at the at or else in some
Vincent Wagelaar <vincent@ricardis.tudelft.nl>
parents:
1180
diff
changeset
|
975 self.repos = cleannames(cp.items("paths")) |
1143
4fffb3d84b7c
Allow list of (virtual, real) or dictionary to be passed to hgwebdir.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1142
diff
changeset
|
976 self.repos.sort() |
941 | 977 |
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
|
978 def run(self, req=hgrequest()): |
941 | 979 def header(**map): |
980 yield tmpl("header", **map) | |
981 | |
982 def footer(**map): | |
983 yield tmpl("footer", **map) | |
984 | |
1142
74d184a40a2e
Cleaned up hgweb.hgwebdir.run()
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1141
diff
changeset
|
985 m = os.path.join(templatepath(), "map") |
941 | 986 tmpl = templater(m, common_filters, |
987 {"header": header, "footer": footer}) | |
988 | |
989 def entries(**map): | |
990 parity = 0 | |
1141
033c968d7c66
Use ConfigParser only in hgwebdir.__init__()
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1140
diff
changeset
|
991 for name, path in self.repos: |
1213 | 992 u = ui.ui() |
1170
85555540a4e2
Make .hg/hgrc optional for repositories published by hgwebdir.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1165
diff
changeset
|
993 try: |
1473
7d66ce9895fa
make readconfig take a filename instead of a file pointer as argument
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1445
diff
changeset
|
994 u.readconfig(os.path.join(path, '.hg', 'hgrc')) |
1170
85555540a4e2
Make .hg/hgrc optional for repositories published by hgwebdir.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1165
diff
changeset
|
995 except IOError: |
85555540a4e2
Make .hg/hgrc optional for repositories published by hgwebdir.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1165
diff
changeset
|
996 pass |
1140
04d52b446e5e
Don't create repo objects in hgwebdir, ui object is enough.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1139
diff
changeset
|
997 get = u.config |
941 | 998 |
1181
4f5001f5b4c3
Make sure the repository names don't have slashes at the at or else in some
Vincent Wagelaar <vincent@ricardis.tudelft.nl>
parents:
1180
diff
changeset
|
999 url = ('/'.join([req.env["REQUEST_URI"].split('?')[0], name]) |
1142
74d184a40a2e
Cleaned up hgweb.hgwebdir.run()
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1141
diff
changeset
|
1000 .replace("//", "/")) |
1022 | 1001 |
1348 | 1002 # update time with local timezone |
1418
68f81ba07b2a
Make hgweb work when the repository is empty (no 00changelog.i)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1416
diff
changeset
|
1003 d = (get_mtime(path), util.makedate()[1]) |
1348 | 1004 |
1260
4603eef60237
hgweb: use ui:username rather than web:contact
mpm@selenic.com
parents:
1219
diff
changeset
|
1005 yield dict(contact=(get("ui", "username") or # preferred |
4603eef60237
hgweb: use ui:username rather than web:contact
mpm@selenic.com
parents:
1219
diff
changeset
|
1006 get("web", "contact") or # deprecated |
4603eef60237
hgweb: use ui:username rather than web:contact
mpm@selenic.com
parents:
1219
diff
changeset
|
1007 get("web", "author", "unknown")), # also |
1130
1ad52c7679e1
Longer variable names in hgwebdir: l->repos, v->name, r->path
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1129
diff
changeset
|
1008 name=get("web", "name", name), |
1062 | 1009 url=url, |
1010 parity=parity, | |
1011 shortdesc=get("web", "description", "unknown"), | |
1348 | 1012 lastupdate=d) |
941 | 1013 |
1014 parity = 1 - parity | |
1015 | |
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
|
1016 virtual = req.env.get("PATH_INFO", "").strip('/') |
1142
74d184a40a2e
Cleaned up hgweb.hgwebdir.run()
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1141
diff
changeset
|
1017 if virtual: |
1141
033c968d7c66
Use ConfigParser only in hgwebdir.__init__()
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1140
diff
changeset
|
1018 real = dict(self.repos).get(virtual) |
033c968d7c66
Use ConfigParser only in hgwebdir.__init__()
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1140
diff
changeset
|
1019 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
|
1020 hgweb(real).run(req) |
1123
457c23af92bd
Use a template for the error message.
Ollivier Robert <roberto@keltia.freenix.fr>
parents:
1122
diff
changeset
|
1021 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
|
1022 req.write(tmpl("notfound", repo=virtual)) |
1142
74d184a40a2e
Cleaned up hgweb.hgwebdir.run()
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1141
diff
changeset
|
1023 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
|
1024 req.write(tmpl("index", entries=entries)) |