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