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