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