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