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