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