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