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