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