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