Mercurial > hg-stable
annotate mercurial/hgweb/hgweb_mod.py @ 3263:3207e30bf468
hgweb: support for generating and parsing NWI URLs
author | Brendan Cully <brendan@kublai.com> |
---|---|
date | Wed, 04 Oct 2006 17:04:40 -0700 |
parents | 329ac0c0c0e8 |
children | b4f16bf59a5d |
rev | line source |
---|---|
2391
d351a3be3371
Fixing up comment headers for split up code.
Eric Hopper <hopper@omnifarious.org>
parents:
2361
diff
changeset
|
1 # hgweb/hgweb_mod.py - Web interface for a repository. |
131 | 2 # |
238
3b92f8fe47ae
hgweb.py: kill #! line, clean up copyright notice
mpm@selenic.com
parents:
222
diff
changeset
|
3 # Copyright 21 May 2005 - (c) 2005 Jake Edge <jake@edge2.net> |
2859 | 4 # Copyright 2005, 2006 Matt Mackall <mpm@selenic.com> |
131 | 5 # |
6 # This software may be used and distributed according to the terms | |
7 # of the GNU General Public License, incorporated herein by reference. | |
8 | |
2356
2db831b33e8f
Final stage of the hgweb split up.
Eric Hopper <hopper@omnifarious.org>
parents:
2355
diff
changeset
|
9 import os |
2db831b33e8f
Final stage of the hgweb split up.
Eric Hopper <hopper@omnifarious.org>
parents:
2355
diff
changeset
|
10 import os.path |
1777
a2316878f19d
[hgweb] Static content serving
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
1703
diff
changeset
|
11 import mimetypes |
2311
b832b6eb65ab
Moving hgweb.py into it's own module in preparation for breaking it up.
Eric Hopper <hopper@omnifarious.org>
parents:
2275
diff
changeset
|
12 from mercurial.demandload import demandload |
2514
419c42223bee
Really fix http headers for web UI and issue 254.
Eric Hopper <hopper@omnifarious.org>
parents:
2509
diff
changeset
|
13 demandload(globals(), "re zlib ConfigParser mimetools cStringIO sys tempfile") |
2888
3848488244fc
Move ui.diffopts to patch.diffopts where it belongs
Matt Mackall <mpm@selenic.com>
parents:
2876
diff
changeset
|
14 demandload(globals(), "mercurial:mdiff,ui,hg,util,archival,streamclone,patch") |
2612
ffb895f16925
add support for streaming clone.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2580
diff
changeset
|
15 demandload(globals(), "mercurial:templater") |
2356
2db831b33e8f
Final stage of the hgweb split up.
Eric Hopper <hopper@omnifarious.org>
parents:
2355
diff
changeset
|
16 demandload(globals(), "mercurial.hgweb.common:get_mtime,staticfile") |
2311
b832b6eb65ab
Moving hgweb.py into it's own module in preparation for breaking it up.
Eric Hopper <hopper@omnifarious.org>
parents:
2275
diff
changeset
|
17 from mercurial.node import * |
b832b6eb65ab
Moving hgweb.py into it's own module in preparation for breaking it up.
Eric Hopper <hopper@omnifarious.org>
parents:
2275
diff
changeset
|
18 from mercurial.i18n import gettext as _ |
138 | 19 |
2356
2db831b33e8f
Final stage of the hgweb split up.
Eric Hopper <hopper@omnifarious.org>
parents:
2355
diff
changeset
|
20 def _up(p): |
1063
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
21 if p[0] != "/": |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
22 p = "/" + p |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
23 if p[-1] == "/": |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
24 p = p[:-1] |
138 | 25 up = os.path.dirname(p) |
26 if up == "/": | |
27 return "/" | |
28 return up + "/" | |
131 | 29 |
1559
59b3639df0a9
Convert all classes to new-style classes by deriving them from object.
Eric Hopper <hopper@omnifarious.org>
parents:
1554
diff
changeset
|
30 class hgweb(object): |
987 | 31 def __init__(self, repo, name=None): |
32 if type(repo) == type(""): | |
1213 | 33 self.repo = hg.repository(ui.ui(), repo) |
987 | 34 else: |
35 self.repo = repo | |
133
fb84d3e71042
added template support for some hgweb output, also, template files for
jake@edge2.net
parents:
132
diff
changeset
|
36 |
258 | 37 self.mtime = -1 |
1172
3f30a5e7e15b
Use path relative to document root as reponame if published via a web server.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1170
diff
changeset
|
38 self.reponame = name |
1078 | 39 self.archives = 'zip', 'gz', 'bz2' |
2666
ebf033bc8eb2
hgweb: Configurable zebra stripes
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
2622
diff
changeset
|
40 self.stripecount = 1 |
2436
f910b91dd912
hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2434
diff
changeset
|
41 self.templatepath = self.repo.ui.config("web", "templates", |
f910b91dd912
hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2434
diff
changeset
|
42 templater.templatepath()) |
131 | 43 |
258 | 44 def refresh(self): |
1418
68f81ba07b2a
Make hgweb work when the repository is empty (no 00changelog.i)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1416
diff
changeset
|
45 mtime = get_mtime(self.repo.root) |
68f81ba07b2a
Make hgweb work when the repository is empty (no 00changelog.i)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1416
diff
changeset
|
46 if mtime != self.mtime: |
68f81ba07b2a
Make hgweb work when the repository is empty (no 00changelog.i)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1416
diff
changeset
|
47 self.mtime = mtime |
1213 | 48 self.repo = hg.repository(self.repo.ui, self.repo.root) |
1275
a1a84dd489ff
Fix cut and paste error in hgweb.py
Florian La Roche <laroche@redhat.com>
parents:
1260
diff
changeset
|
49 self.maxchanges = int(self.repo.ui.config("web", "maxchanges", 10)) |
2666
ebf033bc8eb2
hgweb: Configurable zebra stripes
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
2622
diff
changeset
|
50 self.stripecount = int(self.repo.ui.config("web", "stripes", 1)) |
2684
783220e5d2d1
[hgweb] Implemented shortlog (gitweb templates only)
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
2683
diff
changeset
|
51 self.maxshortchanges = int(self.repo.ui.config("web", "maxshortchanges", 60)) |
1275
a1a84dd489ff
Fix cut and paste error in hgweb.py
Florian La Roche <laroche@redhat.com>
parents:
1260
diff
changeset
|
52 self.maxfiles = int(self.repo.ui.config("web", "maxfiles", 10)) |
964
3f37720e7dc7
hgweb: Make maxfiles, maxchanges, and allowpull proper config options
mpm@selenic.com
parents:
957
diff
changeset
|
53 self.allowpull = self.repo.ui.configbool("web", "allowpull", True) |
258 | 54 |
1498
78590fb4a82b
hgweb: Added archive download buttons to manifest page.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1473
diff
changeset
|
55 def archivelist(self, nodeid): |
2500
76ff5efe8181
Fixed [web] allow_archive for comma separated parameters by using ui.configlist.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2466
diff
changeset
|
56 allowed = self.repo.ui.configlist("web", "allow_archive") |
3260
1f1af9b273e8
hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents:
3231
diff
changeset
|
57 for i, spec in self.archive_specs.iteritems(): |
2359
a392eaa81f29
Allow comma to separate types in allow_archive, too. Use longer variable name.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2358
diff
changeset
|
58 if i in allowed or self.repo.ui.configbool("web", "allow" + i): |
3260
1f1af9b273e8
hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents:
3231
diff
changeset
|
59 yield {"type" : i, "extension" : spec[2], "node" : nodeid} |
1498
78590fb4a82b
hgweb: Added archive download buttons to manifest page.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1473
diff
changeset
|
60 |
138 | 61 def listfiles(self, files, mf): |
62 for f in files[:self.maxfiles]: | |
1062 | 63 yield self.t("filenodelink", node=hex(mf[f]), file=f) |
138 | 64 if len(files) > self.maxfiles: |
65 yield self.t("fileellipses") | |
66 | |
67 def listfilediffs(self, files, changeset): | |
68 for f in files[:self.maxfiles]: | |
1062 | 69 yield self.t("filedifflink", node=hex(changeset), file=f) |
138 | 70 if len(files) > self.maxfiles: |
71 yield self.t("fileellipses") | |
72 | |
3208
e7b7906cc47e
hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents:
3206
diff
changeset
|
73 def siblings(self, siblings=[], hiderev=None, **args): |
e7b7906cc47e
hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents:
3206
diff
changeset
|
74 siblings = [s for s in siblings if s.node() != nullid] |
e7b7906cc47e
hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents:
3206
diff
changeset
|
75 if len(siblings) == 1 and siblings[0].rev() == hiderev: |
1416
19d2776f1725
hgweb: hide trivial parent (like in show_changeset)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1411
diff
changeset
|
76 return |
1606
ba625c8083d8
- duplicate the parent link logic to show child links
Muli Ben-Yehuda <mulix@mulix.org>
parents:
1579
diff
changeset
|
77 for s in siblings: |
3208
e7b7906cc47e
hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents:
3206
diff
changeset
|
78 yield dict(node=hex(s.node()), rev=s.rev(), **args) |
569
3e347929f5f9
[PATCH 1/5]: cleaning the template parent management in hgweb
mpm@selenic.com
parents:
568
diff
changeset
|
79 |
1653
e8a3df8b62b3
hgweb: show copy/rename links in file history
Matt Mackall <mpm@selenic.com>
parents:
1650
diff
changeset
|
80 def renamelink(self, fl, node): |
e8a3df8b62b3
hgweb: show copy/rename links in file history
Matt Mackall <mpm@selenic.com>
parents:
1650
diff
changeset
|
81 r = fl.renamed(node) |
e8a3df8b62b3
hgweb: show copy/rename links in file history
Matt Mackall <mpm@selenic.com>
parents:
1650
diff
changeset
|
82 if r: |
e8a3df8b62b3
hgweb: show copy/rename links in file history
Matt Mackall <mpm@selenic.com>
parents:
1650
diff
changeset
|
83 return [dict(file=r[0], node=hex(r[1]))] |
e8a3df8b62b3
hgweb: show copy/rename links in file history
Matt Mackall <mpm@selenic.com>
parents:
1650
diff
changeset
|
84 return [] |
e8a3df8b62b3
hgweb: show copy/rename links in file history
Matt Mackall <mpm@selenic.com>
parents:
1650
diff
changeset
|
85 |
568 | 86 def showtag(self, t1, node=nullid, **args): |
87 for t in self.repo.nodetags(node): | |
1062 | 88 yield self.t(t1, tag=t, **args) |
568 | 89 |
138 | 90 def diff(self, node1, node2, files): |
1626
f2b1df3dbcbb
make the order of the arguments for filterfiles consistent
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1619
diff
changeset
|
91 def filterfiles(filters, files): |
1627
11cd38286fdb
fix for hgweb.filterfiles
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1626
diff
changeset
|
92 l = [x for x in files if x in filters] |
515 | 93 |
1626
f2b1df3dbcbb
make the order of the arguments for filterfiles consistent
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1619
diff
changeset
|
94 for t in filters: |
1627
11cd38286fdb
fix for hgweb.filterfiles
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1626
diff
changeset
|
95 if t and t[-1] != os.sep: |
1626
f2b1df3dbcbb
make the order of the arguments for filterfiles consistent
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1619
diff
changeset
|
96 t += os.sep |
f2b1df3dbcbb
make the order of the arguments for filterfiles consistent
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1619
diff
changeset
|
97 l += [x for x in files if x.startswith(t)] |
138 | 98 return l |
131 | 99 |
172
e9b1147db448
hgweb: alternating colors for multifile diffs
mpm@selenic.com
parents:
168
diff
changeset
|
100 parity = [0] |
e9b1147db448
hgweb: alternating colors for multifile diffs
mpm@selenic.com
parents:
168
diff
changeset
|
101 def diffblock(diff, f, fn): |
e9b1147db448
hgweb: alternating colors for multifile diffs
mpm@selenic.com
parents:
168
diff
changeset
|
102 yield self.t("diffblock", |
1063
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
103 lines=prettyprintlines(diff), |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
104 parity=parity[0], |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
105 file=f, |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
106 filenode=hex(fn or nullid)) |
172
e9b1147db448
hgweb: alternating colors for multifile diffs
mpm@selenic.com
parents:
168
diff
changeset
|
107 parity[0] = 1 - parity[0] |
515 | 108 |
172
e9b1147db448
hgweb: alternating colors for multifile diffs
mpm@selenic.com
parents:
168
diff
changeset
|
109 def prettyprintlines(diff): |
138 | 110 for l in diff.splitlines(1): |
201
f918a6fa2572
hgweb: add template filters, template style maps, and raw pages
mpm@selenic.com
parents:
198
diff
changeset
|
111 if l.startswith('+'): |
1062 | 112 yield self.t("difflineplus", line=l) |
201
f918a6fa2572
hgweb: add template filters, template style maps, and raw pages
mpm@selenic.com
parents:
198
diff
changeset
|
113 elif l.startswith('-'): |
1062 | 114 yield self.t("difflineminus", line=l) |
201
f918a6fa2572
hgweb: add template filters, template style maps, and raw pages
mpm@selenic.com
parents:
198
diff
changeset
|
115 elif l.startswith('@'): |
1062 | 116 yield self.t("difflineat", line=l) |
138 | 117 else: |
1062 | 118 yield self.t("diffline", line=l) |
131 | 119 |
138 | 120 r = self.repo |
121 cl = r.changelog | |
122 mf = r.manifest | |
123 change1 = cl.read(node1) | |
124 change2 = cl.read(node2) | |
125 mmap1 = mf.read(change1[0]) | |
126 mmap2 = mf.read(change2[0]) | |
1333
901c645c1943
hgweb: fix date bug in hgweb diff generation
mpm@selenic.com
parents:
1324
diff
changeset
|
127 date1 = util.datestr(change1[2]) |
901c645c1943
hgweb: fix date bug in hgweb diff generation
mpm@selenic.com
parents:
1324
diff
changeset
|
128 date2 = util.datestr(change2[2]) |
131 | 129 |
2876
cf86bbb8ed68
hgweb: repo.changes() is now called repo.status()
Giorgos Keramidas <keramida@ceid.upatras.gr>
parents:
2874
diff
changeset
|
130 modified, added, removed, deleted, unknown = r.status(node1, node2)[:5] |
645
a55048b2ae3a
this patch permits hgweb to show the deleted files in the changeset diff
kreijack@inwind.REMOVEME.it
parents:
635
diff
changeset
|
131 if files: |
1626
f2b1df3dbcbb
make the order of the arguments for filterfiles consistent
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1619
diff
changeset
|
132 modified, added, removed = map(lambda x: filterfiles(files, x), |
1618
ff339dd21976
Renamed c, a, d, u to modified, added, removed, unknown for users of changes()
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1606
diff
changeset
|
133 (modified, added, removed)) |
131 | 134 |
2927
ee6ed2b29e1a
Fix hgweb's patch display in changeset view.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2888
diff
changeset
|
135 diffopts = patch.diffopts(self.repo.ui) |
1618
ff339dd21976
Renamed c, a, d, u to modified, added, removed, unknown for users of changes()
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1606
diff
changeset
|
136 for f in modified: |
138 | 137 to = r.file(f).read(mmap1[f]) |
138 tn = r.file(f).read(mmap2[f]) | |
1637 | 139 yield diffblock(mdiff.unidiff(to, date1, tn, date2, f, |
2874
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2859
diff
changeset
|
140 opts=diffopts), f, tn) |
1618
ff339dd21976
Renamed c, a, d, u to modified, added, removed, unknown for users of changes()
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1606
diff
changeset
|
141 for f in added: |
265
7ca05593bd30
hgweb: fix non-existent source or destination for diff
mpm@selenic.com
parents:
258
diff
changeset
|
142 to = None |
138 | 143 tn = r.file(f).read(mmap2[f]) |
1637 | 144 yield diffblock(mdiff.unidiff(to, date1, tn, date2, f, |
2874
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2859
diff
changeset
|
145 opts=diffopts), f, tn) |
1618
ff339dd21976
Renamed c, a, d, u to modified, added, removed, unknown for users of changes()
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1606
diff
changeset
|
146 for f in removed: |
138 | 147 to = r.file(f).read(mmap1[f]) |
265
7ca05593bd30
hgweb: fix non-existent source or destination for diff
mpm@selenic.com
parents:
258
diff
changeset
|
148 tn = None |
1637 | 149 yield diffblock(mdiff.unidiff(to, date1, tn, date2, f, |
2874
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2859
diff
changeset
|
150 opts=diffopts), f, tn) |
131 | 151 |
3220
325278542ea8
hgweb: use contexts in more handlers
Brendan Cully <brendan@kublai.com>
parents:
3208
diff
changeset
|
152 def changelog(self, ctx, shortlog=False): |
325278542ea8
hgweb: use contexts in more handlers
Brendan Cully <brendan@kublai.com>
parents:
3208
diff
changeset
|
153 pos = ctx.rev() |
857
41b344235bb7
[PATCH] Propagate the template map though recursively
Jeff Sipek <jeffpc@optonline.net>
parents:
839
diff
changeset
|
154 def changenav(**map): |
1703
41d884f741ca
fix changenav for maxchanges != 10
Johannes Stezenbach <js@linuxtv.org>
parents:
1653
diff
changeset
|
155 def seq(factor, maxchanges=None): |
41d884f741ca
fix changenav for maxchanges != 10
Johannes Stezenbach <js@linuxtv.org>
parents:
1653
diff
changeset
|
156 if maxchanges: |
41d884f741ca
fix changenav for maxchanges != 10
Johannes Stezenbach <js@linuxtv.org>
parents:
1653
diff
changeset
|
157 yield maxchanges |
41d884f741ca
fix changenav for maxchanges != 10
Johannes Stezenbach <js@linuxtv.org>
parents:
1653
diff
changeset
|
158 if maxchanges >= 20 and maxchanges <= 40: |
41d884f741ca
fix changenav for maxchanges != 10
Johannes Stezenbach <js@linuxtv.org>
parents:
1653
diff
changeset
|
159 yield 50 |
41d884f741ca
fix changenav for maxchanges != 10
Johannes Stezenbach <js@linuxtv.org>
parents:
1653
diff
changeset
|
160 else: |
41d884f741ca
fix changenav for maxchanges != 10
Johannes Stezenbach <js@linuxtv.org>
parents:
1653
diff
changeset
|
161 yield 1 * factor |
41d884f741ca
fix changenav for maxchanges != 10
Johannes Stezenbach <js@linuxtv.org>
parents:
1653
diff
changeset
|
162 yield 3 * factor |
138 | 163 for f in seq(factor * 10): |
164 yield f | |
131 | 165 |
173
8da1df932c16
hgweb: make navigation of changesets a bit nicer
mpm@selenic.com
parents:
172
diff
changeset
|
166 l = [] |
1703
41d884f741ca
fix changenav for maxchanges != 10
Johannes Stezenbach <js@linuxtv.org>
parents:
1653
diff
changeset
|
167 last = 0 |
2684
783220e5d2d1
[hgweb] Implemented shortlog (gitweb templates only)
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
2683
diff
changeset
|
168 maxchanges = shortlog and self.maxshortchanges or self.maxchanges |
783220e5d2d1
[hgweb] Implemented shortlog (gitweb templates only)
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
2683
diff
changeset
|
169 for f in seq(1, maxchanges): |
783220e5d2d1
[hgweb] Implemented shortlog (gitweb templates only)
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
2683
diff
changeset
|
170 if f < maxchanges or f <= last: |
1063
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
171 continue |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
172 if f > count: |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
173 break |
1703
41d884f741ca
fix changenav for maxchanges != 10
Johannes Stezenbach <js@linuxtv.org>
parents:
1653
diff
changeset
|
174 last = f |
173
8da1df932c16
hgweb: make navigation of changesets a bit nicer
mpm@selenic.com
parents:
172
diff
changeset
|
175 r = "%d" % f |
1063
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
176 if pos + f < count: |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
177 l.append(("+" + r, pos + f)) |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
178 if pos - f >= 0: |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
179 l.insert(0, ("-" + r, pos - f)) |
173
8da1df932c16
hgweb: make navigation of changesets a bit nicer
mpm@selenic.com
parents:
172
diff
changeset
|
180 |
975
bdd7c53fca00
hgweb: Changed changelog page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
974
diff
changeset
|
181 yield {"rev": 0, "label": "(0)"} |
515 | 182 |
173
8da1df932c16
hgweb: make navigation of changesets a bit nicer
mpm@selenic.com
parents:
172
diff
changeset
|
183 for label, rev in l: |
975
bdd7c53fca00
hgweb: Changed changelog page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
974
diff
changeset
|
184 yield {"label": label, "rev": rev} |
173
8da1df932c16
hgweb: make navigation of changesets a bit nicer
mpm@selenic.com
parents:
172
diff
changeset
|
185 |
1409
964baa35faf8
hgweb: add shortcuts for all the web commands / fix empty arg bug
Matt Mackall <mpm@selenic.com>
parents:
1407
diff
changeset
|
186 yield {"label": "tip", "rev": "tip"} |
131 | 187 |
857
41b344235bb7
[PATCH] Propagate the template map though recursively
Jeff Sipek <jeffpc@optonline.net>
parents:
839
diff
changeset
|
188 def changelist(**map): |
142 | 189 parity = (start - end) & 1 |
138 | 190 cl = self.repo.changelog |
191 l = [] # build a list in forward order for efficiency | |
351 | 192 for i in range(start, end): |
3208
e7b7906cc47e
hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents:
3206
diff
changeset
|
193 ctx = self.repo.changectx(i) |
e7b7906cc47e
hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents:
3206
diff
changeset
|
194 n = ctx.node() |
131 | 195 |
1063
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
196 l.insert(0, {"parity": parity, |
3208
e7b7906cc47e
hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents:
3206
diff
changeset
|
197 "author": ctx.user(), |
e7b7906cc47e
hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents:
3206
diff
changeset
|
198 "parent": self.siblings(ctx.parents(), i - 1), |
e7b7906cc47e
hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents:
3206
diff
changeset
|
199 "child": self.siblings(ctx.children(), i + 1), |
1063
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
200 "changelogtag": self.showtag("changelogtag",n), |
3208
e7b7906cc47e
hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents:
3206
diff
changeset
|
201 "desc": ctx.description(), |
e7b7906cc47e
hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents:
3206
diff
changeset
|
202 "date": ctx.date(), |
e7b7906cc47e
hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents:
3206
diff
changeset
|
203 "files": self.listfilediffs(ctx.files(), n), |
1063
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
204 "rev": i, |
3208
e7b7906cc47e
hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents:
3206
diff
changeset
|
205 "node": hex(n)}) |
142 | 206 parity = 1 - parity |
138 | 207 |
1063
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
208 for e in l: |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
209 yield e |
131 | 210 |
2684
783220e5d2d1
[hgweb] Implemented shortlog (gitweb templates only)
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
2683
diff
changeset
|
211 maxchanges = shortlog and self.maxshortchanges or self.maxchanges |
168 | 212 cl = self.repo.changelog |
213 count = cl.count() | |
2684
783220e5d2d1
[hgweb] Implemented shortlog (gitweb templates only)
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
2683
diff
changeset
|
214 start = max(0, pos - maxchanges + 1) |
783220e5d2d1
[hgweb] Implemented shortlog (gitweb templates only)
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
2683
diff
changeset
|
215 end = min(count, start + maxchanges) |
351 | 216 pos = end - 1 |
138 | 217 |
2684
783220e5d2d1
[hgweb] Implemented shortlog (gitweb templates only)
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
2683
diff
changeset
|
218 yield self.t(shortlog and 'shortlog' or 'changelog', |
1062 | 219 changenav=changenav, |
3205 | 220 node=hex(cl.tip()), |
2170
29eeb2717915
Add archive download links to tip on main changeset list page
Colin McMillen <mcmillen@cs.cmu.edu>
parents:
2148
diff
changeset
|
221 rev=pos, changesets=count, entries=changelist, |
29eeb2717915
Add archive download links to tip on main changeset list page
Colin McMillen <mcmillen@cs.cmu.edu>
parents:
2148
diff
changeset
|
222 archives=self.archivelist("tip")) |
131 | 223 |
538 | 224 def search(self, query): |
225 | |
857
41b344235bb7
[PATCH] Propagate the template map though recursively
Jeff Sipek <jeffpc@optonline.net>
parents:
839
diff
changeset
|
226 def changelist(**map): |
538 | 227 cl = self.repo.changelog |
228 count = 0 | |
229 qw = query.lower().split() | |
230 | |
231 def revgen(): | |
232 for i in range(cl.count() - 1, 0, -100): | |
233 l = [] | |
234 for j in range(max(0, i - 100), i): | |
3208
e7b7906cc47e
hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents:
3206
diff
changeset
|
235 ctx = self.repo.changectx(j) |
e7b7906cc47e
hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents:
3206
diff
changeset
|
236 l.append(ctx) |
1023 | 237 l.reverse() |
538 | 238 for e in l: |
239 yield e | |
240 | |
3208
e7b7906cc47e
hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents:
3206
diff
changeset
|
241 for ctx in revgen(): |
538 | 242 miss = 0 |
243 for q in qw: | |
3208
e7b7906cc47e
hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents:
3206
diff
changeset
|
244 if not (q in ctx.user().lower() or |
e7b7906cc47e
hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents:
3206
diff
changeset
|
245 q in ctx.description().lower() or |
e7b7906cc47e
hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents:
3206
diff
changeset
|
246 q in " ".join(ctx.files()[:20]).lower()): |
538 | 247 miss = 1 |
248 break | |
1063
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
249 if miss: |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
250 continue |
538 | 251 |
252 count += 1 | |
3208
e7b7906cc47e
hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents:
3206
diff
changeset
|
253 n = ctx.node() |
538 | 254 |
1063
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
255 yield self.t('searchentry', |
2666
ebf033bc8eb2
hgweb: Configurable zebra stripes
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
2622
diff
changeset
|
256 parity=self.stripes(count), |
3208
e7b7906cc47e
hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents:
3206
diff
changeset
|
257 author=ctx.user(), |
e7b7906cc47e
hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents:
3206
diff
changeset
|
258 parent=self.siblings(ctx.parents()), |
e7b7906cc47e
hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents:
3206
diff
changeset
|
259 child=self.siblings(ctx.children()), |
1063
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
260 changelogtag=self.showtag("changelogtag",n), |
3208
e7b7906cc47e
hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents:
3206
diff
changeset
|
261 desc=ctx.description(), |
e7b7906cc47e
hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents:
3206
diff
changeset
|
262 date=ctx.date(), |
e7b7906cc47e
hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents:
3206
diff
changeset
|
263 files=self.listfilediffs(ctx.files(), n), |
e7b7906cc47e
hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents:
3206
diff
changeset
|
264 rev=ctx.rev(), |
e7b7906cc47e
hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents:
3206
diff
changeset
|
265 node=hex(n)) |
538 | 266 |
1063
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
267 if count >= self.maxchanges: |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
268 break |
538 | 269 |
270 cl = self.repo.changelog | |
271 | |
272 yield self.t('search', | |
1062 | 273 query=query, |
3205 | 274 node=hex(cl.tip()), |
1062 | 275 entries=changelist) |
538 | 276 |
3220
325278542ea8
hgweb: use contexts in more handlers
Brendan Cully <brendan@kublai.com>
parents:
3208
diff
changeset
|
277 def changeset(self, ctx): |
3208
e7b7906cc47e
hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents:
3206
diff
changeset
|
278 n = ctx.node() |
e7b7906cc47e
hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents:
3206
diff
changeset
|
279 parents = ctx.parents() |
e7b7906cc47e
hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents:
3206
diff
changeset
|
280 p1 = parents[0].node() |
515 | 281 |
133
fb84d3e71042
added template support for some hgweb output, also, template files for
jake@edge2.net
parents:
132
diff
changeset
|
282 files = [] |
3179
76ab39df0917
gitweb: cosmetic fixes.
Brendan Cully <brendan@kublai.com>
parents:
3178
diff
changeset
|
283 parity = 0 |
3208
e7b7906cc47e
hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents:
3206
diff
changeset
|
284 for f in ctx.files(): |
138 | 285 files.append(self.t("filenodelink", |
3206
79fd7a92f3e2
hgweb: kill off #filenode#
Brendan Cully <brendan@kublai.com>
parents:
3205
diff
changeset
|
286 node=hex(n), file=f, |
3179
76ab39df0917
gitweb: cosmetic fixes.
Brendan Cully <brendan@kublai.com>
parents:
3178
diff
changeset
|
287 parity=parity)) |
76ab39df0917
gitweb: cosmetic fixes.
Brendan Cully <brendan@kublai.com>
parents:
3178
diff
changeset
|
288 parity = 1 - parity |
138 | 289 |
857
41b344235bb7
[PATCH] Propagate the template map though recursively
Jeff Sipek <jeffpc@optonline.net>
parents:
839
diff
changeset
|
290 def diff(**map): |
645
a55048b2ae3a
this patch permits hgweb to show the deleted files in the changeset diff
kreijack@inwind.REMOVEME.it
parents:
635
diff
changeset
|
291 yield self.diff(p1, n, None) |
131 | 292 |
138 | 293 yield self.t('changeset', |
1062 | 294 diff=diff, |
3208
e7b7906cc47e
hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents:
3206
diff
changeset
|
295 rev=ctx.rev(), |
e7b7906cc47e
hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents:
3206
diff
changeset
|
296 node=hex(n), |
e7b7906cc47e
hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents:
3206
diff
changeset
|
297 parent=self.siblings(parents), |
e7b7906cc47e
hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents:
3206
diff
changeset
|
298 child=self.siblings(ctx.children()), |
1062 | 299 changesettag=self.showtag("changesettag",n), |
3208
e7b7906cc47e
hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents:
3206
diff
changeset
|
300 author=ctx.user(), |
e7b7906cc47e
hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents:
3206
diff
changeset
|
301 desc=ctx.description(), |
e7b7906cc47e
hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents:
3206
diff
changeset
|
302 date=ctx.date(), |
1076
01db658cc78a
tarball support v0.3
Wojciech Milkowski <wmilkowski@interia.pl>
parents:
1073
diff
changeset
|
303 files=files, |
3220
325278542ea8
hgweb: use contexts in more handlers
Brendan Cully <brendan@kublai.com>
parents:
3208
diff
changeset
|
304 archives=self.archivelist(hex(n))) |
131 | 305 |
3206
79fd7a92f3e2
hgweb: kill off #filenode#
Brendan Cully <brendan@kublai.com>
parents:
3205
diff
changeset
|
306 def filelog(self, fctx): |
79fd7a92f3e2
hgweb: kill off #filenode#
Brendan Cully <brendan@kublai.com>
parents:
3205
diff
changeset
|
307 f = fctx.path() |
79fd7a92f3e2
hgweb: kill off #filenode#
Brendan Cully <brendan@kublai.com>
parents:
3205
diff
changeset
|
308 fl = fctx.filelog() |
138 | 309 count = fl.count() |
310 | |
857
41b344235bb7
[PATCH] Propagate the template map though recursively
Jeff Sipek <jeffpc@optonline.net>
parents:
839
diff
changeset
|
311 def entries(**map): |
138 | 312 l = [] |
142 | 313 parity = (count - 1) & 1 |
515 | 314 |
138 | 315 for i in range(count): |
3208
e7b7906cc47e
hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents:
3206
diff
changeset
|
316 ctx = fctx.filectx(i) |
138 | 317 n = fl.node(i) |
133
fb84d3e71042
added template support for some hgweb output, also, template files for
jake@edge2.net
parents:
132
diff
changeset
|
318 |
978
ea67e5b37043
hgweb: Changed file revision page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
977
diff
changeset
|
319 l.insert(0, {"parity": parity, |
ea67e5b37043
hgweb: Changed file revision page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
977
diff
changeset
|
320 "filerev": i, |
ea67e5b37043
hgweb: Changed file revision page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
977
diff
changeset
|
321 "file": f, |
3206
79fd7a92f3e2
hgweb: kill off #filenode#
Brendan Cully <brendan@kublai.com>
parents:
3205
diff
changeset
|
322 "node": hex(ctx.node()), |
79fd7a92f3e2
hgweb: kill off #filenode#
Brendan Cully <brendan@kublai.com>
parents:
3205
diff
changeset
|
323 "author": ctx.user(), |
79fd7a92f3e2
hgweb: kill off #filenode#
Brendan Cully <brendan@kublai.com>
parents:
3205
diff
changeset
|
324 "date": ctx.date(), |
1653
e8a3df8b62b3
hgweb: show copy/rename links in file history
Matt Mackall <mpm@selenic.com>
parents:
1650
diff
changeset
|
325 "rename": self.renamelink(fl, n), |
3208
e7b7906cc47e
hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents:
3206
diff
changeset
|
326 "parent": self.siblings(fctx.parents(), file=f), |
e7b7906cc47e
hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents:
3206
diff
changeset
|
327 "child": self.siblings(fctx.children(), file=f), |
3206
79fd7a92f3e2
hgweb: kill off #filenode#
Brendan Cully <brendan@kublai.com>
parents:
3205
diff
changeset
|
328 "desc": ctx.description()}) |
142 | 329 parity = 1 - parity |
138 | 330 |
1063
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
331 for e in l: |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
332 yield e |
138 | 333 |
3206
79fd7a92f3e2
hgweb: kill off #filenode#
Brendan Cully <brendan@kublai.com>
parents:
3205
diff
changeset
|
334 yield self.t("filelog", file=f, node=hex(fctx.node()), entries=entries) |
131 | 335 |
3206
79fd7a92f3e2
hgweb: kill off #filenode#
Brendan Cully <brendan@kublai.com>
parents:
3205
diff
changeset
|
336 def filerevision(self, fctx): |
79fd7a92f3e2
hgweb: kill off #filenode#
Brendan Cully <brendan@kublai.com>
parents:
3205
diff
changeset
|
337 f = fctx.path() |
79fd7a92f3e2
hgweb: kill off #filenode#
Brendan Cully <brendan@kublai.com>
parents:
3205
diff
changeset
|
338 text = fctx.data() |
79fd7a92f3e2
hgweb: kill off #filenode#
Brendan Cully <brendan@kublai.com>
parents:
3205
diff
changeset
|
339 fl = fctx.filelog() |
79fd7a92f3e2
hgweb: kill off #filenode#
Brendan Cully <brendan@kublai.com>
parents:
3205
diff
changeset
|
340 n = fctx.filenode() |
142 | 341 |
1411
e2ba788545bf
hgweb: make viewing of non-text work in hgweb
Matt Mackall <mpm@selenic.com>
parents:
1409
diff
changeset
|
342 mt = mimetypes.guess_type(f)[0] |
e2ba788545bf
hgweb: make viewing of non-text work in hgweb
Matt Mackall <mpm@selenic.com>
parents:
1409
diff
changeset
|
343 rawtext = text |
e2ba788545bf
hgweb: make viewing of non-text work in hgweb
Matt Mackall <mpm@selenic.com>
parents:
1409
diff
changeset
|
344 if util.binary(text): |
2103
caccf539c9a4
Use application/octet-stream as the content-type of unknown binary files
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
2095
diff
changeset
|
345 mt = mt or 'application/octet-stream' |
caccf539c9a4
Use application/octet-stream as the content-type of unknown binary files
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
2095
diff
changeset
|
346 text = "(binary:%s)" % mt |
2095
0bf2a9e5eff1
Don't send "Content-Type: none"
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
1964
diff
changeset
|
347 mt = mt or 'text/plain' |
1411
e2ba788545bf
hgweb: make viewing of non-text work in hgweb
Matt Mackall <mpm@selenic.com>
parents:
1409
diff
changeset
|
348 |
142 | 349 def lines(): |
350 for l, t in enumerate(text.splitlines(1)): | |
976
5d5ab159d197
hgweb: Changed file page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
975
diff
changeset
|
351 yield {"line": t, |
5d5ab159d197
hgweb: Changed file page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
975
diff
changeset
|
352 "linenumber": "% 6d" % (l + 1), |
2666
ebf033bc8eb2
hgweb: Configurable zebra stripes
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
2622
diff
changeset
|
353 "parity": self.stripes(l)} |
359 | 354 |
1063
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
355 yield self.t("filerevision", |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
356 file=f, |
2356
2db831b33e8f
Final stage of the hgweb split up.
Eric Hopper <hopper@omnifarious.org>
parents:
2355
diff
changeset
|
357 path=_up(f), |
1062 | 358 text=lines(), |
1411
e2ba788545bf
hgweb: make viewing of non-text work in hgweb
Matt Mackall <mpm@selenic.com>
parents:
1409
diff
changeset
|
359 raw=rawtext, |
e2ba788545bf
hgweb: make viewing of non-text work in hgweb
Matt Mackall <mpm@selenic.com>
parents:
1409
diff
changeset
|
360 mimetype=mt, |
3206
79fd7a92f3e2
hgweb: kill off #filenode#
Brendan Cully <brendan@kublai.com>
parents:
3205
diff
changeset
|
361 rev=fctx.rev(), |
79fd7a92f3e2
hgweb: kill off #filenode#
Brendan Cully <brendan@kublai.com>
parents:
3205
diff
changeset
|
362 node=hex(fctx.node()), |
79fd7a92f3e2
hgweb: kill off #filenode#
Brendan Cully <brendan@kublai.com>
parents:
3205
diff
changeset
|
363 author=fctx.user(), |
79fd7a92f3e2
hgweb: kill off #filenode#
Brendan Cully <brendan@kublai.com>
parents:
3205
diff
changeset
|
364 date=fctx.date(), |
3208
e7b7906cc47e
hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents:
3206
diff
changeset
|
365 parent=self.siblings(fctx.parents(), file=f), |
e7b7906cc47e
hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents:
3206
diff
changeset
|
366 child=self.siblings(fctx.children(), file=f), |
1653
e8a3df8b62b3
hgweb: show copy/rename links in file history
Matt Mackall <mpm@selenic.com>
parents:
1650
diff
changeset
|
367 rename=self.renamelink(fl, n), |
3206
79fd7a92f3e2
hgweb: kill off #filenode#
Brendan Cully <brendan@kublai.com>
parents:
3205
diff
changeset
|
368 permissions=fctx.manifest().execf(f)) |
138 | 369 |
3206
79fd7a92f3e2
hgweb: kill off #filenode#
Brendan Cully <brendan@kublai.com>
parents:
3205
diff
changeset
|
370 def fileannotate(self, fctx): |
79fd7a92f3e2
hgweb: kill off #filenode#
Brendan Cully <brendan@kublai.com>
parents:
3205
diff
changeset
|
371 f = fctx.path() |
3173
3466bd7b9754
hgweb: use filectx.annotate instead of filelog
Brendan Cully <brendan@kublai.com>
parents:
3131
diff
changeset
|
372 n = fctx.filenode() |
3466bd7b9754
hgweb: use filectx.annotate instead of filelog
Brendan Cully <brendan@kublai.com>
parents:
3131
diff
changeset
|
373 fl = fctx.filelog() |
131 | 374 |
857
41b344235bb7
[PATCH] Propagate the template map though recursively
Jeff Sipek <jeffpc@optonline.net>
parents:
839
diff
changeset
|
375 def annotate(**map): |
2666
ebf033bc8eb2
hgweb: Configurable zebra stripes
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
2622
diff
changeset
|
376 parity = 0 |
142 | 377 last = None |
3175
fc379b91f602
hgweb: make annotate line revisions point to annotation for that rev
Brendan Cully <brendan@kublai.com>
parents:
3173
diff
changeset
|
378 for f, l in fctx.annotate(follow=True): |
fc379b91f602
hgweb: make annotate line revisions point to annotation for that rev
Brendan Cully <brendan@kublai.com>
parents:
3173
diff
changeset
|
379 fnode = f.filenode() |
3173
3466bd7b9754
hgweb: use filectx.annotate instead of filelog
Brendan Cully <brendan@kublai.com>
parents:
3131
diff
changeset
|
380 name = self.repo.ui.shortuser(f.user()) |
131 | 381 |
3175
fc379b91f602
hgweb: make annotate line revisions point to annotation for that rev
Brendan Cully <brendan@kublai.com>
parents:
3173
diff
changeset
|
382 if last != fnode: |
142 | 383 parity = 1 - parity |
3175
fc379b91f602
hgweb: make annotate line revisions point to annotation for that rev
Brendan Cully <brendan@kublai.com>
parents:
3173
diff
changeset
|
384 last = fnode |
142 | 385 |
977
289975641886
hgweb: Changed annotate page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
976
diff
changeset
|
386 yield {"parity": parity, |
3178
0d0d7317bbc8
hgweb: yield filenode as well as node in annotate, use filenode in annotateline
Brendan Cully <brendan@kublai.com>
parents:
3177
diff
changeset
|
387 "node": hex(f.node()), |
3173
3466bd7b9754
hgweb: use filectx.annotate instead of filelog
Brendan Cully <brendan@kublai.com>
parents:
3131
diff
changeset
|
388 "rev": f.rev(), |
977
289975641886
hgweb: Changed annotate page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
976
diff
changeset
|
389 "author": name, |
3173
3466bd7b9754
hgweb: use filectx.annotate instead of filelog
Brendan Cully <brendan@kublai.com>
parents:
3131
diff
changeset
|
390 "file": f.path(), |
977
289975641886
hgweb: Changed annotate page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
976
diff
changeset
|
391 "line": l} |
138 | 392 |
393 yield self.t("fileannotate", | |
1063
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
394 file=f, |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
395 annotate=annotate, |
2356
2db831b33e8f
Final stage of the hgweb split up.
Eric Hopper <hopper@omnifarious.org>
parents:
2355
diff
changeset
|
396 path=_up(f), |
3173
3466bd7b9754
hgweb: use filectx.annotate instead of filelog
Brendan Cully <brendan@kublai.com>
parents:
3131
diff
changeset
|
397 rev=fctx.rev(), |
3177
8683c7a637ad
hgweb: fix changeset link in annotate view.
Brendan Cully <brendan@kublai.com>
parents:
3175
diff
changeset
|
398 node=hex(fctx.node()), |
3173
3466bd7b9754
hgweb: use filectx.annotate instead of filelog
Brendan Cully <brendan@kublai.com>
parents:
3131
diff
changeset
|
399 author=fctx.user(), |
3466bd7b9754
hgweb: use filectx.annotate instead of filelog
Brendan Cully <brendan@kublai.com>
parents:
3131
diff
changeset
|
400 date=fctx.date(), |
1653
e8a3df8b62b3
hgweb: show copy/rename links in file history
Matt Mackall <mpm@selenic.com>
parents:
1650
diff
changeset
|
401 rename=self.renamelink(fl, n), |
3208
e7b7906cc47e
hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents:
3206
diff
changeset
|
402 parent=self.siblings(fctx.parents(), file=f), |
e7b7906cc47e
hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents:
3206
diff
changeset
|
403 child=self.siblings(fctx.children(), file=f), |
3173
3466bd7b9754
hgweb: use filectx.annotate instead of filelog
Brendan Cully <brendan@kublai.com>
parents:
3131
diff
changeset
|
404 permissions=fctx.manifest().execf(f)) |
136 | 405 |
3205 | 406 def manifest(self, ctx, path): |
407 mf = ctx.manifest() | |
408 node = ctx.node() | |
138 | 409 |
410 files = {} | |
515 | 411 |
138 | 412 p = path[1:] |
1649
beb7da710c8a
hgweb: fix breakage on manifest subdirs from path cleaning
Matt Mackall <mpm@selenic.com>
parents:
1646
diff
changeset
|
413 if p and p[-1] != "/": |
beb7da710c8a
hgweb: fix breakage on manifest subdirs from path cleaning
Matt Mackall <mpm@selenic.com>
parents:
1646
diff
changeset
|
414 p += "/" |
138 | 415 l = len(p) |
131 | 416 |
138 | 417 for f,n in mf.items(): |
418 if f[:l] != p: | |
419 continue | |
420 remain = f[l:] | |
421 if "/" in remain: | |
2579
0875cda033fd
use __contains__, index or split instead of str.find
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
2558
diff
changeset
|
422 short = remain[:remain.index("/") + 1] # bleah |
142 | 423 files[short] = (f, None) |
138 | 424 else: |
425 short = os.path.basename(remain) | |
426 files[short] = (f, n) | |
131 | 427 |
857
41b344235bb7
[PATCH] Propagate the template map though recursively
Jeff Sipek <jeffpc@optonline.net>
parents:
839
diff
changeset
|
428 def filelist(**map): |
142 | 429 parity = 0 |
138 | 430 fl = files.keys() |
431 fl.sort() | |
432 for f in fl: | |
433 full, fnode = files[f] | |
979
87d40e085e08
hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
978
diff
changeset
|
434 if not fnode: |
87d40e085e08
hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
978
diff
changeset
|
435 continue |
87d40e085e08
hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
978
diff
changeset
|
436 |
87d40e085e08
hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
978
diff
changeset
|
437 yield {"file": full, |
87d40e085e08
hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
978
diff
changeset
|
438 "filenode": hex(fnode), |
2666
ebf033bc8eb2
hgweb: Configurable zebra stripes
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
2622
diff
changeset
|
439 "parity": self.stripes(parity), |
979
87d40e085e08
hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
978
diff
changeset
|
440 "basename": f, |
2857
18cf5349a361
Fix some bugs introduced during the manifest refactoring
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
2840
diff
changeset
|
441 "permissions": mf.execf(full)} |
2666
ebf033bc8eb2
hgweb: Configurable zebra stripes
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
2622
diff
changeset
|
442 parity += 1 |
138 | 443 |
979
87d40e085e08
hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
978
diff
changeset
|
444 def dirlist(**map): |
87d40e085e08
hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
978
diff
changeset
|
445 parity = 0 |
87d40e085e08
hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
978
diff
changeset
|
446 fl = files.keys() |
87d40e085e08
hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
978
diff
changeset
|
447 fl.sort() |
87d40e085e08
hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
978
diff
changeset
|
448 for f in fl: |
87d40e085e08
hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
978
diff
changeset
|
449 full, fnode = files[f] |
87d40e085e08
hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
978
diff
changeset
|
450 if fnode: |
87d40e085e08
hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
978
diff
changeset
|
451 continue |
87d40e085e08
hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
978
diff
changeset
|
452 |
2666
ebf033bc8eb2
hgweb: Configurable zebra stripes
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
2622
diff
changeset
|
453 yield {"parity": self.stripes(parity), |
979
87d40e085e08
hgweb: Changed manifest page to list format syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
978
diff
changeset
|
454 "path": os.path.join(path, f), |
980 | 455 "basename": f[:-1]} |
2666
ebf033bc8eb2
hgweb: Configurable zebra stripes
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
2622
diff
changeset
|
456 parity += 1 |
982
8d2e24bae760
hgweb: convert index entries to list expansion style
mpm@selenic.com
parents:
981
diff
changeset
|
457 |
138 | 458 yield self.t("manifest", |
3205 | 459 rev=ctx.rev(), |
1062 | 460 node=hex(node), |
461 path=path, | |
2356
2db831b33e8f
Final stage of the hgweb split up.
Eric Hopper <hopper@omnifarious.org>
parents:
2355
diff
changeset
|
462 up=_up(path), |
1062 | 463 fentries=filelist, |
1498
78590fb4a82b
hgweb: Added archive download buttons to manifest page.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1473
diff
changeset
|
464 dentries=dirlist, |
78590fb4a82b
hgweb: Added archive download buttons to manifest page.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1473
diff
changeset
|
465 archives=self.archivelist(hex(node))) |
131 | 466 |
168 | 467 def tags(self): |
468 cl = self.repo.changelog | |
469 | |
343 | 470 i = self.repo.tagslist() |
471 i.reverse() | |
168 | 472 |
1767
adbc392dfd9e
implement entriesnotip for tags in hgweb.py ; change entries to entriesnotip in templates/tags-rss.tmpl
Peter van Dijk <peter@dataloss.nl>
parents:
1653
diff
changeset
|
473 def entries(notip=False, **map): |
168 | 474 parity = 0 |
475 for k,n in i: | |
1767
adbc392dfd9e
implement entriesnotip for tags in hgweb.py ; change entries to entriesnotip in templates/tags-rss.tmpl
Peter van Dijk <peter@dataloss.nl>
parents:
1653
diff
changeset
|
476 if notip and k == "tip": continue |
2666
ebf033bc8eb2
hgweb: Configurable zebra stripes
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
2622
diff
changeset
|
477 yield {"parity": self.stripes(parity), |
974
aedb47764f29
Added support for #foo%bar# syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
938
diff
changeset
|
478 "tag": k, |
1579
85803ec2daab
Remove tabs, and trailing whitespace from hgweb.py
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
1575
diff
changeset
|
479 "date": cl.read(n)[2], |
974
aedb47764f29
Added support for #foo%bar# syntax
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
938
diff
changeset
|
480 "node": hex(n)} |
2666
ebf033bc8eb2
hgweb: Configurable zebra stripes
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
2622
diff
changeset
|
481 parity += 1 |
168 | 482 |
483 yield self.t("tags", | |
3205 | 484 node=hex(self.repo.changelog.tip()), |
1767
adbc392dfd9e
implement entriesnotip for tags in hgweb.py ; change entries to entriesnotip in templates/tags-rss.tmpl
Peter van Dijk <peter@dataloss.nl>
parents:
1653
diff
changeset
|
485 entries=lambda **x: entries(False, **x), |
adbc392dfd9e
implement entriesnotip for tags in hgweb.py ; change entries to entriesnotip in templates/tags-rss.tmpl
Peter van Dijk <peter@dataloss.nl>
parents:
1653
diff
changeset
|
486 entriesnotip=lambda **x: entries(True, **x)) |
168 | 487 |
1572
385b8872b8e3
[hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
1559
diff
changeset
|
488 def summary(self): |
385b8872b8e3
[hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
1559
diff
changeset
|
489 cl = self.repo.changelog |
385b8872b8e3
[hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
1559
diff
changeset
|
490 |
385b8872b8e3
[hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
1559
diff
changeset
|
491 i = self.repo.tagslist() |
385b8872b8e3
[hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
1559
diff
changeset
|
492 i.reverse() |
385b8872b8e3
[hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
1559
diff
changeset
|
493 |
385b8872b8e3
[hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
1559
diff
changeset
|
494 def tagentries(**map): |
385b8872b8e3
[hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
1559
diff
changeset
|
495 parity = 0 |
1579
85803ec2daab
Remove tabs, and trailing whitespace from hgweb.py
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
1575
diff
changeset
|
496 count = 0 |
1572
385b8872b8e3
[hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
1559
diff
changeset
|
497 for k,n in i: |
1579
85803ec2daab
Remove tabs, and trailing whitespace from hgweb.py
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
1575
diff
changeset
|
498 if k == "tip": # skip tip |
1572
385b8872b8e3
[hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
1559
diff
changeset
|
499 continue; |
385b8872b8e3
[hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
1559
diff
changeset
|
500 |
385b8872b8e3
[hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
1559
diff
changeset
|
501 count += 1 |
1579
85803ec2daab
Remove tabs, and trailing whitespace from hgweb.py
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
1575
diff
changeset
|
502 if count > 10: # limit to 10 tags |
1572
385b8872b8e3
[hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
1559
diff
changeset
|
503 break; |
385b8872b8e3
[hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
1559
diff
changeset
|
504 |
385b8872b8e3
[hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
1559
diff
changeset
|
505 c = cl.read(n) |
385b8872b8e3
[hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
1559
diff
changeset
|
506 t = c[2] |
1579
85803ec2daab
Remove tabs, and trailing whitespace from hgweb.py
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
1575
diff
changeset
|
507 |
1572
385b8872b8e3
[hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
1559
diff
changeset
|
508 yield self.t("tagentry", |
2666
ebf033bc8eb2
hgweb: Configurable zebra stripes
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
2622
diff
changeset
|
509 parity = self.stripes(parity), |
1572
385b8872b8e3
[hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
1559
diff
changeset
|
510 tag = k, |
385b8872b8e3
[hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
1559
diff
changeset
|
511 node = hex(n), |
3205 | 512 date = t) |
2666
ebf033bc8eb2
hgweb: Configurable zebra stripes
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
2622
diff
changeset
|
513 parity += 1 |
1579
85803ec2daab
Remove tabs, and trailing whitespace from hgweb.py
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
1575
diff
changeset
|
514 |
1572
385b8872b8e3
[hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
1559
diff
changeset
|
515 def changelist(**map): |
385b8872b8e3
[hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
1559
diff
changeset
|
516 parity = 0 |
385b8872b8e3
[hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
1559
diff
changeset
|
517 cl = self.repo.changelog |
385b8872b8e3
[hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
1559
diff
changeset
|
518 l = [] # build a list in forward order for efficiency |
385b8872b8e3
[hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
1559
diff
changeset
|
519 for i in range(start, end): |
385b8872b8e3
[hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
1559
diff
changeset
|
520 n = cl.node(i) |
385b8872b8e3
[hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
1559
diff
changeset
|
521 changes = cl.read(n) |
385b8872b8e3
[hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
1559
diff
changeset
|
522 hn = hex(n) |
385b8872b8e3
[hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
1559
diff
changeset
|
523 t = changes[2] |
385b8872b8e3
[hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
1559
diff
changeset
|
524 |
385b8872b8e3
[hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
1559
diff
changeset
|
525 l.insert(0, self.t( |
385b8872b8e3
[hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
1559
diff
changeset
|
526 'shortlogentry', |
385b8872b8e3
[hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
1559
diff
changeset
|
527 parity = parity, |
385b8872b8e3
[hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
1559
diff
changeset
|
528 author = changes[1], |
385b8872b8e3
[hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
1559
diff
changeset
|
529 desc = changes[4], |
385b8872b8e3
[hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
1559
diff
changeset
|
530 date = t, |
385b8872b8e3
[hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
1559
diff
changeset
|
531 rev = i, |
385b8872b8e3
[hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
1559
diff
changeset
|
532 node = hn)) |
385b8872b8e3
[hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
1559
diff
changeset
|
533 parity = 1 - parity |
385b8872b8e3
[hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
1559
diff
changeset
|
534 |
385b8872b8e3
[hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
1559
diff
changeset
|
535 yield l |
385b8872b8e3
[hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
1559
diff
changeset
|
536 |
385b8872b8e3
[hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
1559
diff
changeset
|
537 count = cl.count() |
385b8872b8e3
[hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
1559
diff
changeset
|
538 start = max(0, count - self.maxchanges) |
385b8872b8e3
[hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
1559
diff
changeset
|
539 end = min(count, start + self.maxchanges) |
385b8872b8e3
[hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
1559
diff
changeset
|
540 |
385b8872b8e3
[hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
1559
diff
changeset
|
541 yield self.t("summary", |
1579
85803ec2daab
Remove tabs, and trailing whitespace from hgweb.py
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
1575
diff
changeset
|
542 desc = self.repo.ui.config("web", "description", "unknown"), |
85803ec2daab
Remove tabs, and trailing whitespace from hgweb.py
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
1575
diff
changeset
|
543 owner = (self.repo.ui.config("ui", "username") or # preferred |
1572
385b8872b8e3
[hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
1559
diff
changeset
|
544 self.repo.ui.config("web", "contact") or # deprecated |
385b8872b8e3
[hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
1559
diff
changeset
|
545 self.repo.ui.config("web", "author", "unknown")), # also |
1579
85803ec2daab
Remove tabs, and trailing whitespace from hgweb.py
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
1575
diff
changeset
|
546 lastchange = (0, 0), # FIXME |
1572
385b8872b8e3
[hgweb] Initial import of the "gitweb" style
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
1559
diff
changeset
|
547 tags = tagentries, |
2683
8a798185809d
[hgweb] Fixed up gitweb templates
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
2622
diff
changeset
|
548 shortlog = changelist, |
3205 | 549 node = hex(self.repo.changelog.tip()), |
2683
8a798185809d
[hgweb] Fixed up gitweb templates
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
2622
diff
changeset
|
550 archives=self.archivelist("tip")) |
1579
85803ec2daab
Remove tabs, and trailing whitespace from hgweb.py
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
1575
diff
changeset
|
551 |
3220
325278542ea8
hgweb: use contexts in more handlers
Brendan Cully <brendan@kublai.com>
parents:
3208
diff
changeset
|
552 def filediff(self, fctx): |
325278542ea8
hgweb: use contexts in more handlers
Brendan Cully <brendan@kublai.com>
parents:
3208
diff
changeset
|
553 n = fctx.node() |
325278542ea8
hgweb: use contexts in more handlers
Brendan Cully <brendan@kublai.com>
parents:
3208
diff
changeset
|
554 path = fctx.path() |
325278542ea8
hgweb: use contexts in more handlers
Brendan Cully <brendan@kublai.com>
parents:
3208
diff
changeset
|
555 parents = fctx.changectx().parents() |
3208
e7b7906cc47e
hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents:
3206
diff
changeset
|
556 p1 = parents[0].node() |
515 | 557 |
857
41b344235bb7
[PATCH] Propagate the template map though recursively
Jeff Sipek <jeffpc@optonline.net>
parents:
839
diff
changeset
|
558 def diff(**map): |
3220
325278542ea8
hgweb: use contexts in more handlers
Brendan Cully <brendan@kublai.com>
parents:
3208
diff
changeset
|
559 yield self.diff(p1, n, [path]) |
131 | 560 |
138 | 561 yield self.t("filediff", |
3220
325278542ea8
hgweb: use contexts in more handlers
Brendan Cully <brendan@kublai.com>
parents:
3208
diff
changeset
|
562 file=path, |
3208
e7b7906cc47e
hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents:
3206
diff
changeset
|
563 node=hex(n), |
3220
325278542ea8
hgweb: use contexts in more handlers
Brendan Cully <brendan@kublai.com>
parents:
3208
diff
changeset
|
564 rev=fctx.rev(), |
3208
e7b7906cc47e
hgweb: teach siblings and callers to use contexts
Brendan Cully <brendan@kublai.com>
parents:
3206
diff
changeset
|
565 parent=self.siblings(parents), |
3220
325278542ea8
hgweb: use contexts in more handlers
Brendan Cully <brendan@kublai.com>
parents:
3208
diff
changeset
|
566 child=self.siblings(fctx.children()), |
1062 | 567 diff=diff) |
515 | 568 |
2113
633d733e7b11
make hgweb use new archival module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2103
diff
changeset
|
569 archive_specs = { |
2361
d3adb454c5a9
Fix automatic decompression of tarballs with Firefox.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2359
diff
changeset
|
570 'bz2': ('application/x-tar', 'tbz2', '.tar.bz2', None), |
d3adb454c5a9
Fix automatic decompression of tarballs with Firefox.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2359
diff
changeset
|
571 'gz': ('application/x-tar', 'tgz', '.tar.gz', None), |
2113
633d733e7b11
make hgweb use new archival module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2103
diff
changeset
|
572 'zip': ('application/zip', 'zip', '.zip', None), |
633d733e7b11
make hgweb use new archival module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2103
diff
changeset
|
573 } |
1076
01db658cc78a
tarball support v0.3
Wojciech Milkowski <wmilkowski@interia.pl>
parents:
1073
diff
changeset
|
574 |
2394
a8f1049d1d2d
hgweb: fix errors and warnings found by pychecker
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
2391
diff
changeset
|
575 def archive(self, req, cnode, type_): |
2113
633d733e7b11
make hgweb use new archival module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2103
diff
changeset
|
576 reponame = re.sub(r"\W+", "-", os.path.basename(self.reponame)) |
633d733e7b11
make hgweb use new archival module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2103
diff
changeset
|
577 name = "%s-%s" % (reponame, short(cnode)) |
2394
a8f1049d1d2d
hgweb: fix errors and warnings found by pychecker
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
2391
diff
changeset
|
578 mimetype, artype, extension, encoding = self.archive_specs[type_] |
2113
633d733e7b11
make hgweb use new archival module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2103
diff
changeset
|
579 headers = [('Content-type', mimetype), |
633d733e7b11
make hgweb use new archival module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2103
diff
changeset
|
580 ('Content-disposition', 'attachment; filename=%s%s' % |
633d733e7b11
make hgweb use new archival module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2103
diff
changeset
|
581 (name, extension))] |
633d733e7b11
make hgweb use new archival module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2103
diff
changeset
|
582 if encoding: |
633d733e7b11
make hgweb use new archival module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2103
diff
changeset
|
583 headers.append(('Content-encoding', encoding)) |
633d733e7b11
make hgweb use new archival module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2103
diff
changeset
|
584 req.header(headers) |
633d733e7b11
make hgweb use new archival module.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2103
diff
changeset
|
585 archival.archive(self.repo, req.out, cnode, artype, prefix=name) |
1076
01db658cc78a
tarball support v0.3
Wojciech Milkowski <wmilkowski@interia.pl>
parents:
1073
diff
changeset
|
586 |
138 | 587 # add tags to things |
588 # tags -> list of changesets corresponding to tags | |
589 # find tag, changeset, file | |
131 | 590 |
2436
f910b91dd912
hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2434
diff
changeset
|
591 def cleanpath(self, path): |
f910b91dd912
hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2434
diff
changeset
|
592 p = util.normpath(path) |
f910b91dd912
hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2434
diff
changeset
|
593 if p[:2] == "..": |
f910b91dd912
hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2434
diff
changeset
|
594 raise Exception("suspicious path") |
f910b91dd912
hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2434
diff
changeset
|
595 return p |
f910b91dd912
hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2434
diff
changeset
|
596 |
2535
b8ccf6386db7
Arrange for old copies of CGI scripts to still work.
Eric Hopper <hopper@omnifarious.org>
parents:
2534
diff
changeset
|
597 def run(self): |
2538
f4b7d71c1c60
Cleanup hgweb and hgwebdir's run method a bit.
Eric Hopper <hopper@omnifarious.org>
parents:
2535
diff
changeset
|
598 if not os.environ.get('GATEWAY_INTERFACE', '').startswith("CGI/1."): |
2535
b8ccf6386db7
Arrange for old copies of CGI scripts to still work.
Eric Hopper <hopper@omnifarious.org>
parents:
2534
diff
changeset
|
599 raise RuntimeError("This function is only intended to be called while running as a CGI script.") |
b8ccf6386db7
Arrange for old copies of CGI scripts to still work.
Eric Hopper <hopper@omnifarious.org>
parents:
2534
diff
changeset
|
600 import mercurial.hgweb.wsgicgi as wsgicgi |
b8ccf6386db7
Arrange for old copies of CGI scripts to still work.
Eric Hopper <hopper@omnifarious.org>
parents:
2534
diff
changeset
|
601 from request import wsgiapplication |
b8ccf6386db7
Arrange for old copies of CGI scripts to still work.
Eric Hopper <hopper@omnifarious.org>
parents:
2534
diff
changeset
|
602 def make_web_app(): |
2538
f4b7d71c1c60
Cleanup hgweb and hgwebdir's run method a bit.
Eric Hopper <hopper@omnifarious.org>
parents:
2535
diff
changeset
|
603 return self |
2535
b8ccf6386db7
Arrange for old copies of CGI scripts to still work.
Eric Hopper <hopper@omnifarious.org>
parents:
2534
diff
changeset
|
604 wsgicgi.launch(wsgiapplication(make_web_app)) |
b8ccf6386db7
Arrange for old copies of CGI scripts to still work.
Eric Hopper <hopper@omnifarious.org>
parents:
2534
diff
changeset
|
605 |
b8ccf6386db7
Arrange for old copies of CGI scripts to still work.
Eric Hopper <hopper@omnifarious.org>
parents:
2534
diff
changeset
|
606 def run_wsgi(self, req): |
857
41b344235bb7
[PATCH] Propagate the template map though recursively
Jeff Sipek <jeffpc@optonline.net>
parents:
839
diff
changeset
|
607 def header(**map): |
2514
419c42223bee
Really fix http headers for web UI and issue 254.
Eric Hopper <hopper@omnifarious.org>
parents:
2509
diff
changeset
|
608 header_file = cStringIO.StringIO(''.join(self.t("header", **map))) |
419c42223bee
Really fix http headers for web UI and issue 254.
Eric Hopper <hopper@omnifarious.org>
parents:
2509
diff
changeset
|
609 msg = mimetools.Message(header_file, 0) |
419c42223bee
Really fix http headers for web UI and issue 254.
Eric Hopper <hopper@omnifarious.org>
parents:
2509
diff
changeset
|
610 req.header(msg.items()) |
419c42223bee
Really fix http headers for web UI and issue 254.
Eric Hopper <hopper@omnifarious.org>
parents:
2509
diff
changeset
|
611 yield header_file.read() |
857
41b344235bb7
[PATCH] Propagate the template map though recursively
Jeff Sipek <jeffpc@optonline.net>
parents:
839
diff
changeset
|
612 |
2534
d5a3cc6520d5
Fix raw files in the web UI.
Eric Hopper <hopper@omnifarious.org>
parents:
2514
diff
changeset
|
613 def rawfileheader(**map): |
d5a3cc6520d5
Fix raw files in the web UI.
Eric Hopper <hopper@omnifarious.org>
parents:
2514
diff
changeset
|
614 req.header([('Content-type', map['mimetype']), |
d5a3cc6520d5
Fix raw files in the web UI.
Eric Hopper <hopper@omnifarious.org>
parents:
2514
diff
changeset
|
615 ('Content-disposition', 'filename=%s' % map['file']), |
d5a3cc6520d5
Fix raw files in the web UI.
Eric Hopper <hopper@omnifarious.org>
parents:
2514
diff
changeset
|
616 ('Content-length', str(len(map['raw'])))]) |
d5a3cc6520d5
Fix raw files in the web UI.
Eric Hopper <hopper@omnifarious.org>
parents:
2514
diff
changeset
|
617 yield '' |
d5a3cc6520d5
Fix raw files in the web UI.
Eric Hopper <hopper@omnifarious.org>
parents:
2514
diff
changeset
|
618 |
857
41b344235bb7
[PATCH] Propagate the template map though recursively
Jeff Sipek <jeffpc@optonline.net>
parents:
839
diff
changeset
|
619 def footer(**map): |
2148
c72e618c1204
Add MOTD display to hgweb and hgwebdir.
Colin McMillen <mcmillen@cs.cmu.edu>
parents:
2127
diff
changeset
|
620 yield self.t("footer", |
c72e618c1204
Add MOTD display to hgweb and hgwebdir.
Colin McMillen <mcmillen@cs.cmu.edu>
parents:
2127
diff
changeset
|
621 motd=self.repo.ui.config("web", "motd", ""), |
c72e618c1204
Add MOTD display to hgweb and hgwebdir.
Colin McMillen <mcmillen@cs.cmu.edu>
parents:
2127
diff
changeset
|
622 **map) |
1409
964baa35faf8
hgweb: add shortcuts for all the web commands / fix empty arg bug
Matt Mackall <mpm@selenic.com>
parents:
1407
diff
changeset
|
623 |
1406
34cb3957d875
hgweb: allow urls to be shorter by using shortcuts
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1402
diff
changeset
|
624 def expand_form(form): |
34cb3957d875
hgweb: allow urls to be shorter by using shortcuts
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1402
diff
changeset
|
625 shortcuts = { |
1409
964baa35faf8
hgweb: add shortcuts for all the web commands / fix empty arg bug
Matt Mackall <mpm@selenic.com>
parents:
1407
diff
changeset
|
626 'cl': [('cmd', ['changelog']), ('rev', None)], |
2684
783220e5d2d1
[hgweb] Implemented shortlog (gitweb templates only)
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
2683
diff
changeset
|
627 'sl': [('cmd', ['shortlog']), ('rev', None)], |
1406
34cb3957d875
hgweb: allow urls to be shorter by using shortcuts
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1402
diff
changeset
|
628 'cs': [('cmd', ['changeset']), ('node', None)], |
1409
964baa35faf8
hgweb: add shortcuts for all the web commands / fix empty arg bug
Matt Mackall <mpm@selenic.com>
parents:
1407
diff
changeset
|
629 'f': [('cmd', ['file']), ('filenode', None)], |
964baa35faf8
hgweb: add shortcuts for all the web commands / fix empty arg bug
Matt Mackall <mpm@selenic.com>
parents:
1407
diff
changeset
|
630 'fl': [('cmd', ['filelog']), ('filenode', None)], |
964baa35faf8
hgweb: add shortcuts for all the web commands / fix empty arg bug
Matt Mackall <mpm@selenic.com>
parents:
1407
diff
changeset
|
631 'fd': [('cmd', ['filediff']), ('node', None)], |
964baa35faf8
hgweb: add shortcuts for all the web commands / fix empty arg bug
Matt Mackall <mpm@selenic.com>
parents:
1407
diff
changeset
|
632 'fa': [('cmd', ['annotate']), ('filenode', None)], |
964baa35faf8
hgweb: add shortcuts for all the web commands / fix empty arg bug
Matt Mackall <mpm@selenic.com>
parents:
1407
diff
changeset
|
633 'mf': [('cmd', ['manifest']), ('manifest', None)], |
964baa35faf8
hgweb: add shortcuts for all the web commands / fix empty arg bug
Matt Mackall <mpm@selenic.com>
parents:
1407
diff
changeset
|
634 'ca': [('cmd', ['archive']), ('node', None)], |
964baa35faf8
hgweb: add shortcuts for all the web commands / fix empty arg bug
Matt Mackall <mpm@selenic.com>
parents:
1407
diff
changeset
|
635 'tags': [('cmd', ['tags'])], |
964baa35faf8
hgweb: add shortcuts for all the web commands / fix empty arg bug
Matt Mackall <mpm@selenic.com>
parents:
1407
diff
changeset
|
636 'tip': [('cmd', ['changeset']), ('node', ['tip'])], |
1777
a2316878f19d
[hgweb] Static content serving
Josef "Jeff" Sipek <jeffpc@optonline.net>
parents:
1703
diff
changeset
|
637 'static': [('cmd', ['static']), ('file', None)] |
1406
34cb3957d875
hgweb: allow urls to be shorter by using shortcuts
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1402
diff
changeset
|
638 } |
1409
964baa35faf8
hgweb: add shortcuts for all the web commands / fix empty arg bug
Matt Mackall <mpm@selenic.com>
parents:
1407
diff
changeset
|
639 |
1406
34cb3957d875
hgweb: allow urls to be shorter by using shortcuts
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1402
diff
changeset
|
640 for k in shortcuts.iterkeys(): |
34cb3957d875
hgweb: allow urls to be shorter by using shortcuts
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1402
diff
changeset
|
641 if form.has_key(k): |
34cb3957d875
hgweb: allow urls to be shorter by using shortcuts
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1402
diff
changeset
|
642 for name, value in shortcuts[k]: |
34cb3957d875
hgweb: allow urls to be shorter by using shortcuts
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1402
diff
changeset
|
643 if value is None: |
34cb3957d875
hgweb: allow urls to be shorter by using shortcuts
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1402
diff
changeset
|
644 value = form[k] |
34cb3957d875
hgweb: allow urls to be shorter by using shortcuts
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1402
diff
changeset
|
645 form[name] = value |
34cb3957d875
hgweb: allow urls to be shorter by using shortcuts
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1402
diff
changeset
|
646 del form[k] |
857
41b344235bb7
[PATCH] Propagate the template map though recursively
Jeff Sipek <jeffpc@optonline.net>
parents:
839
diff
changeset
|
647 |
3260
1f1af9b273e8
hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents:
3231
diff
changeset
|
648 def rewrite_request(req): |
1f1af9b273e8
hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents:
3231
diff
changeset
|
649 '''translate new web interface to traditional format''' |
1f1af9b273e8
hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents:
3231
diff
changeset
|
650 |
3263
3207e30bf468
hgweb: support for generating and parsing NWI URLs
Brendan Cully <brendan@kublai.com>
parents:
3261
diff
changeset
|
651 def spliturl(req): |
3207e30bf468
hgweb: support for generating and parsing NWI URLs
Brendan Cully <brendan@kublai.com>
parents:
3261
diff
changeset
|
652 def firstitem(query): |
3207e30bf468
hgweb: support for generating and parsing NWI URLs
Brendan Cully <brendan@kublai.com>
parents:
3261
diff
changeset
|
653 return query.split('&', 1)[0].split(';', 1)[0] |
3207e30bf468
hgweb: support for generating and parsing NWI URLs
Brendan Cully <brendan@kublai.com>
parents:
3261
diff
changeset
|
654 |
3207e30bf468
hgweb: support for generating and parsing NWI URLs
Brendan Cully <brendan@kublai.com>
parents:
3261
diff
changeset
|
655 base = '' |
3207e30bf468
hgweb: support for generating and parsing NWI URLs
Brendan Cully <brendan@kublai.com>
parents:
3261
diff
changeset
|
656 if req.env.has_key('REPO_NAME'): |
3207e30bf468
hgweb: support for generating and parsing NWI URLs
Brendan Cully <brendan@kublai.com>
parents:
3261
diff
changeset
|
657 base = '/' + req.env['REPO_NAME'] |
3207e30bf468
hgweb: support for generating and parsing NWI URLs
Brendan Cully <brendan@kublai.com>
parents:
3261
diff
changeset
|
658 elif req.env.get('SCRIPT_NAME'): |
3207e30bf468
hgweb: support for generating and parsing NWI URLs
Brendan Cully <brendan@kublai.com>
parents:
3261
diff
changeset
|
659 base = req.env['SCRIPT_NAME'] |
3207e30bf468
hgweb: support for generating and parsing NWI URLs
Brendan Cully <brendan@kublai.com>
parents:
3261
diff
changeset
|
660 |
3207e30bf468
hgweb: support for generating and parsing NWI URLs
Brendan Cully <brendan@kublai.com>
parents:
3261
diff
changeset
|
661 pi = req.env.get('PATH_INFO') |
3207e30bf468
hgweb: support for generating and parsing NWI URLs
Brendan Cully <brendan@kublai.com>
parents:
3261
diff
changeset
|
662 if pi: |
3207e30bf468
hgweb: support for generating and parsing NWI URLs
Brendan Cully <brendan@kublai.com>
parents:
3261
diff
changeset
|
663 if pi.startswith(base): |
3207e30bf468
hgweb: support for generating and parsing NWI URLs
Brendan Cully <brendan@kublai.com>
parents:
3261
diff
changeset
|
664 if len(pi) > len(base): |
3207e30bf468
hgweb: support for generating and parsing NWI URLs
Brendan Cully <brendan@kublai.com>
parents:
3261
diff
changeset
|
665 base += '/' |
3207e30bf468
hgweb: support for generating and parsing NWI URLs
Brendan Cully <brendan@kublai.com>
parents:
3261
diff
changeset
|
666 query = pi[len(base):] |
3207e30bf468
hgweb: support for generating and parsing NWI URLs
Brendan Cully <brendan@kublai.com>
parents:
3261
diff
changeset
|
667 else: |
3207e30bf468
hgweb: support for generating and parsing NWI URLs
Brendan Cully <brendan@kublai.com>
parents:
3261
diff
changeset
|
668 if req.env.has_key('REPO_NAME'): |
3207e30bf468
hgweb: support for generating and parsing NWI URLs
Brendan Cully <brendan@kublai.com>
parents:
3261
diff
changeset
|
669 # We are using hgwebdir |
3207e30bf468
hgweb: support for generating and parsing NWI URLs
Brendan Cully <brendan@kublai.com>
parents:
3261
diff
changeset
|
670 base += '/' |
3207e30bf468
hgweb: support for generating and parsing NWI URLs
Brendan Cully <brendan@kublai.com>
parents:
3261
diff
changeset
|
671 else: |
3207e30bf468
hgweb: support for generating and parsing NWI URLs
Brendan Cully <brendan@kublai.com>
parents:
3261
diff
changeset
|
672 base += '?' |
3207e30bf468
hgweb: support for generating and parsing NWI URLs
Brendan Cully <brendan@kublai.com>
parents:
3261
diff
changeset
|
673 query = firstitem(req.env['QUERY_STRING']) |
3207e30bf468
hgweb: support for generating and parsing NWI URLs
Brendan Cully <brendan@kublai.com>
parents:
3261
diff
changeset
|
674 else: |
3207e30bf468
hgweb: support for generating and parsing NWI URLs
Brendan Cully <brendan@kublai.com>
parents:
3261
diff
changeset
|
675 base += '/' |
3207e30bf468
hgweb: support for generating and parsing NWI URLs
Brendan Cully <brendan@kublai.com>
parents:
3261
diff
changeset
|
676 query = pi[1:] |
3207e30bf468
hgweb: support for generating and parsing NWI URLs
Brendan Cully <brendan@kublai.com>
parents:
3261
diff
changeset
|
677 else: |
3207e30bf468
hgweb: support for generating and parsing NWI URLs
Brendan Cully <brendan@kublai.com>
parents:
3261
diff
changeset
|
678 base += '?' |
3207e30bf468
hgweb: support for generating and parsing NWI URLs
Brendan Cully <brendan@kublai.com>
parents:
3261
diff
changeset
|
679 query = firstitem(req.env['QUERY_STRING']) |
3207e30bf468
hgweb: support for generating and parsing NWI URLs
Brendan Cully <brendan@kublai.com>
parents:
3261
diff
changeset
|
680 |
3207e30bf468
hgweb: support for generating and parsing NWI URLs
Brendan Cully <brendan@kublai.com>
parents:
3261
diff
changeset
|
681 return (base, query) |
3207e30bf468
hgweb: support for generating and parsing NWI URLs
Brendan Cully <brendan@kublai.com>
parents:
3261
diff
changeset
|
682 |
3207e30bf468
hgweb: support for generating and parsing NWI URLs
Brendan Cully <brendan@kublai.com>
parents:
3261
diff
changeset
|
683 req.url, query = spliturl(req) |
3207e30bf468
hgweb: support for generating and parsing NWI URLs
Brendan Cully <brendan@kublai.com>
parents:
3261
diff
changeset
|
684 |
3260
1f1af9b273e8
hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents:
3231
diff
changeset
|
685 if req.form.has_key('cmd'): |
1f1af9b273e8
hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents:
3231
diff
changeset
|
686 # old style |
1f1af9b273e8
hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents:
3231
diff
changeset
|
687 return |
1f1af9b273e8
hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents:
3231
diff
changeset
|
688 |
1f1af9b273e8
hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents:
3231
diff
changeset
|
689 args = query.split('/', 2) |
1f1af9b273e8
hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents:
3231
diff
changeset
|
690 if not args or not args[0]: |
1f1af9b273e8
hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents:
3231
diff
changeset
|
691 return |
1f1af9b273e8
hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents:
3231
diff
changeset
|
692 |
1f1af9b273e8
hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents:
3231
diff
changeset
|
693 cmd = args.pop(0) |
3261
329ac0c0c0e8
hgweb: extract raw prefix from NWI commands
Brendan Cully <brendan@kublai.com>
parents:
3260
diff
changeset
|
694 style = cmd.rfind('-') |
329ac0c0c0e8
hgweb: extract raw prefix from NWI commands
Brendan Cully <brendan@kublai.com>
parents:
3260
diff
changeset
|
695 if style != -1: |
329ac0c0c0e8
hgweb: extract raw prefix from NWI commands
Brendan Cully <brendan@kublai.com>
parents:
3260
diff
changeset
|
696 req.form['style'] = [cmd[:style]] |
329ac0c0c0e8
hgweb: extract raw prefix from NWI commands
Brendan Cully <brendan@kublai.com>
parents:
3260
diff
changeset
|
697 cmd = cmd[style+1:] |
3263
3207e30bf468
hgweb: support for generating and parsing NWI URLs
Brendan Cully <brendan@kublai.com>
parents:
3261
diff
changeset
|
698 # avoid accepting e.g. style parameter as command |
3207e30bf468
hgweb: support for generating and parsing NWI URLs
Brendan Cully <brendan@kublai.com>
parents:
3261
diff
changeset
|
699 if hasattr(self, 'do_' + cmd): |
3207e30bf468
hgweb: support for generating and parsing NWI URLs
Brendan Cully <brendan@kublai.com>
parents:
3261
diff
changeset
|
700 req.form['cmd'] = [cmd] |
3260
1f1af9b273e8
hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents:
3231
diff
changeset
|
701 |
1f1af9b273e8
hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents:
3231
diff
changeset
|
702 if args and args[0]: |
1f1af9b273e8
hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents:
3231
diff
changeset
|
703 node = args.pop(0) |
1f1af9b273e8
hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents:
3231
diff
changeset
|
704 req.form['node'] = [node] |
1f1af9b273e8
hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents:
3231
diff
changeset
|
705 if args: |
1f1af9b273e8
hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents:
3231
diff
changeset
|
706 req.form['file'] = args |
1f1af9b273e8
hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents:
3231
diff
changeset
|
707 |
1f1af9b273e8
hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents:
3231
diff
changeset
|
708 if cmd == 'static': |
1f1af9b273e8
hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents:
3231
diff
changeset
|
709 req.form['file'] = req.form['node'] |
1f1af9b273e8
hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents:
3231
diff
changeset
|
710 elif cmd == 'archive': |
1f1af9b273e8
hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents:
3231
diff
changeset
|
711 fn = req.form['node'][0] |
1f1af9b273e8
hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents:
3231
diff
changeset
|
712 for type_, spec in self.archive_specs.iteritems(): |
1f1af9b273e8
hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents:
3231
diff
changeset
|
713 ext = spec[2] |
1f1af9b273e8
hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents:
3231
diff
changeset
|
714 if fn.endswith(ext): |
1f1af9b273e8
hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents:
3231
diff
changeset
|
715 req.form['node'] = [fn[:-len(ext)]] |
1f1af9b273e8
hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents:
3231
diff
changeset
|
716 req.form['type'] = [type_] |
1f1af9b273e8
hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents:
3231
diff
changeset
|
717 |
258 | 718 self.refresh() |
132 | 719 |
1406
34cb3957d875
hgweb: allow urls to be shorter by using shortcuts
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1402
diff
changeset
|
720 expand_form(req.form) |
3260
1f1af9b273e8
hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents:
3231
diff
changeset
|
721 rewrite_request(req) |
1406
34cb3957d875
hgweb: allow urls to be shorter by using shortcuts
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents:
1402
diff
changeset
|
722 |
2436
f910b91dd912
hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2434
diff
changeset
|
723 m = os.path.join(self.templatepath, "map") |
986 | 724 style = self.repo.ui.config("web", "style", "") |
1159
b6f5a947e62e
Change use of global sys.stdout, sys.stdin os.environ to a hgrequest object.
Vincent Wagelaar <vincent@ricardis.tudelft.nl>
parents:
1143
diff
changeset
|
725 if req.form.has_key('style'): |
b6f5a947e62e
Change use of global sys.stdout, sys.stdin os.environ to a hgrequest object.
Vincent Wagelaar <vincent@ricardis.tudelft.nl>
parents:
1143
diff
changeset
|
726 style = req.form['style'][0] |
986 | 727 if style: |
728 b = os.path.basename("map-" + style) | |
2436
f910b91dd912
hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2434
diff
changeset
|
729 p = os.path.join(self.templatepath, b) |
1063
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
730 if os.path.isfile(p): |
58eefdfb8472
Some more spacing/indentation/linebreak cleanups to hgweb.py.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1062
diff
changeset
|
731 m = p |
515 | 732 |
3263
3207e30bf468
hgweb: support for generating and parsing NWI URLs
Brendan Cully <brendan@kublai.com>
parents:
3261
diff
changeset
|
733 if not req.url: |
3207e30bf468
hgweb: support for generating and parsing NWI URLs
Brendan Cully <brendan@kublai.com>
parents:
3261
diff
changeset
|
734 port = req.env["SERVER_PORT"] |
3207e30bf468
hgweb: support for generating and parsing NWI URLs
Brendan Cully <brendan@kublai.com>
parents:
3261
diff
changeset
|
735 port = port != "80" and (":" + port) or "" |
3207e30bf468
hgweb: support for generating and parsing NWI URLs
Brendan Cully <brendan@kublai.com>
parents:
3261
diff
changeset
|
736 uri = req.env["REQUEST_URI"] |
3207e30bf468
hgweb: support for generating and parsing NWI URLs
Brendan Cully <brendan@kublai.com>
parents:
3261
diff
changeset
|
737 if "?" in uri: |
3207e30bf468
hgweb: support for generating and parsing NWI URLs
Brendan Cully <brendan@kublai.com>
parents:
3261
diff
changeset
|
738 uri = uri.split("?")[0] |
3207e30bf468
hgweb: support for generating and parsing NWI URLs
Brendan Cully <brendan@kublai.com>
parents:
3261
diff
changeset
|
739 req.url = "http://%s%s%s" % (req.env["SERVER_NAME"], port, uri) |
3207e30bf468
hgweb: support for generating and parsing NWI URLs
Brendan Cully <brendan@kublai.com>
parents:
3261
diff
changeset
|
740 |
1172
3f30a5e7e15b
Use path relative to document root as reponame if published via a web server.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1170
diff
changeset
|
741 if not self.reponame: |
3f30a5e7e15b
Use path relative to document root as reponame if published via a web server.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1170
diff
changeset
|
742 self.reponame = (self.repo.ui.config("web", "name") |
3263
3207e30bf468
hgweb: support for generating and parsing NWI URLs
Brendan Cully <brendan@kublai.com>
parents:
3261
diff
changeset
|
743 or req.env.get('REPO_NAME') |
3207e30bf468
hgweb: support for generating and parsing NWI URLs
Brendan Cully <brendan@kublai.com>
parents:
3261
diff
changeset
|
744 or req.url.strip('/') or self.repo.root) |
601 | 745 |
1896
f8f818a04f5b
move hgweb template code out to templater
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1796
diff
changeset
|
746 self.t = templater.templater(m, templater.common_filters, |
3263
3207e30bf468
hgweb: support for generating and parsing NWI URLs
Brendan Cully <brendan@kublai.com>
parents:
3261
diff
changeset
|
747 defaults={"url": req.url, |
1964
778281d46bb2
fix template bug that made hgweb break.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1920
diff
changeset
|
748 "repo": self.reponame, |
778281d46bb2
fix template bug that made hgweb break.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1920
diff
changeset
|
749 "header": header, |
778281d46bb2
fix template bug that made hgweb break.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1920
diff
changeset
|
750 "footer": footer, |
2534
d5a3cc6520d5
Fix raw files in the web UI.
Eric Hopper <hopper@omnifarious.org>
parents:
2514
diff
changeset
|
751 "rawfileheader": rawfileheader, |
1964
778281d46bb2
fix template bug that made hgweb break.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
1920
diff
changeset
|
752 }) |
201
f918a6fa2572
hgweb: add template filters, template style maps, and raw pages
mpm@selenic.com
parents:
198
diff
changeset
|
753 |
1159
b6f5a947e62e
Change use of global sys.stdout, sys.stdin os.environ to a hgrequest object.
Vincent Wagelaar <vincent@ricardis.tudelft.nl>
parents:
1143
diff
changeset
|
754 if not req.form.has_key('cmd'): |
b6f5a947e62e
Change use of global sys.stdout, sys.stdin os.environ to a hgrequest object.
Vincent Wagelaar <vincent@ricardis.tudelft.nl>
parents:
1143
diff
changeset
|
755 req.form['cmd'] = [self.t.cache['default'],] |
937 | 756 |
2119
f62195054c5b
Cleaned hgweb.py a little bit
Alexander Schremmer <alex AT alexanderweb DOT de>
parents:
2113
diff
changeset
|
757 cmd = req.form['cmd'][0] |
575 | 758 |
2436
f910b91dd912
hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2434
diff
changeset
|
759 method = getattr(self, 'do_' + cmd, None) |
f910b91dd912
hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2434
diff
changeset
|
760 if method: |
f910b91dd912
hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2434
diff
changeset
|
761 method(req) |
132 | 762 else: |
1159
b6f5a947e62e
Change use of global sys.stdout, sys.stdin os.environ to a hgrequest object.
Vincent Wagelaar <vincent@ricardis.tudelft.nl>
parents:
1143
diff
changeset
|
763 req.write(self.t("error")) |
2436
f910b91dd912
hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2434
diff
changeset
|
764 |
3226
5c6028778c5a
hgweb: add methods to get contexts from request
Brendan Cully <brendan@kublai.com>
parents:
3220
diff
changeset
|
765 def changectx(self, req): |
5c6028778c5a
hgweb: add methods to get contexts from request
Brendan Cully <brendan@kublai.com>
parents:
3220
diff
changeset
|
766 if req.form.has_key('node'): |
5c6028778c5a
hgweb: add methods to get contexts from request
Brendan Cully <brendan@kublai.com>
parents:
3220
diff
changeset
|
767 changeid = req.form['node'][0] |
5c6028778c5a
hgweb: add methods to get contexts from request
Brendan Cully <brendan@kublai.com>
parents:
3220
diff
changeset
|
768 else: |
5c6028778c5a
hgweb: add methods to get contexts from request
Brendan Cully <brendan@kublai.com>
parents:
3220
diff
changeset
|
769 changeid = req.form['manifest'][0] |
5c6028778c5a
hgweb: add methods to get contexts from request
Brendan Cully <brendan@kublai.com>
parents:
3220
diff
changeset
|
770 try: |
5c6028778c5a
hgweb: add methods to get contexts from request
Brendan Cully <brendan@kublai.com>
parents:
3220
diff
changeset
|
771 ctx = self.repo.changectx(changeid) |
5c6028778c5a
hgweb: add methods to get contexts from request
Brendan Cully <brendan@kublai.com>
parents:
3220
diff
changeset
|
772 except hg.RepoError: |
5c6028778c5a
hgweb: add methods to get contexts from request
Brendan Cully <brendan@kublai.com>
parents:
3220
diff
changeset
|
773 man = self.repo.manifest |
5c6028778c5a
hgweb: add methods to get contexts from request
Brendan Cully <brendan@kublai.com>
parents:
3220
diff
changeset
|
774 mn = man.lookup(changeid) |
5c6028778c5a
hgweb: add methods to get contexts from request
Brendan Cully <brendan@kublai.com>
parents:
3220
diff
changeset
|
775 ctx = self.repo.changectx(man.linkrev(mn)) |
5c6028778c5a
hgweb: add methods to get contexts from request
Brendan Cully <brendan@kublai.com>
parents:
3220
diff
changeset
|
776 |
5c6028778c5a
hgweb: add methods to get contexts from request
Brendan Cully <brendan@kublai.com>
parents:
3220
diff
changeset
|
777 return ctx |
5c6028778c5a
hgweb: add methods to get contexts from request
Brendan Cully <brendan@kublai.com>
parents:
3220
diff
changeset
|
778 |
5c6028778c5a
hgweb: add methods to get contexts from request
Brendan Cully <brendan@kublai.com>
parents:
3220
diff
changeset
|
779 def filectx(self, req): |
5c6028778c5a
hgweb: add methods to get contexts from request
Brendan Cully <brendan@kublai.com>
parents:
3220
diff
changeset
|
780 path = self.cleanpath(req.form['file'][0]) |
5c6028778c5a
hgweb: add methods to get contexts from request
Brendan Cully <brendan@kublai.com>
parents:
3220
diff
changeset
|
781 if req.form.has_key('node'): |
5c6028778c5a
hgweb: add methods to get contexts from request
Brendan Cully <brendan@kublai.com>
parents:
3220
diff
changeset
|
782 changeid = req.form['node'][0] |
5c6028778c5a
hgweb: add methods to get contexts from request
Brendan Cully <brendan@kublai.com>
parents:
3220
diff
changeset
|
783 else: |
5c6028778c5a
hgweb: add methods to get contexts from request
Brendan Cully <brendan@kublai.com>
parents:
3220
diff
changeset
|
784 changeid = req.form['filenode'][0] |
5c6028778c5a
hgweb: add methods to get contexts from request
Brendan Cully <brendan@kublai.com>
parents:
3220
diff
changeset
|
785 try: |
5c6028778c5a
hgweb: add methods to get contexts from request
Brendan Cully <brendan@kublai.com>
parents:
3220
diff
changeset
|
786 ctx = self.repo.changectx(changeid) |
5c6028778c5a
hgweb: add methods to get contexts from request
Brendan Cully <brendan@kublai.com>
parents:
3220
diff
changeset
|
787 fctx = ctx.filectx(path) |
5c6028778c5a
hgweb: add methods to get contexts from request
Brendan Cully <brendan@kublai.com>
parents:
3220
diff
changeset
|
788 except hg.RepoError: |
5c6028778c5a
hgweb: add methods to get contexts from request
Brendan Cully <brendan@kublai.com>
parents:
3220
diff
changeset
|
789 fctx = self.repo.filectx(path, fileid=changeid) |
5c6028778c5a
hgweb: add methods to get contexts from request
Brendan Cully <brendan@kublai.com>
parents:
3220
diff
changeset
|
790 |
5c6028778c5a
hgweb: add methods to get contexts from request
Brendan Cully <brendan@kublai.com>
parents:
3220
diff
changeset
|
791 return fctx |
5c6028778c5a
hgweb: add methods to get contexts from request
Brendan Cully <brendan@kublai.com>
parents:
3220
diff
changeset
|
792 |
2666
ebf033bc8eb2
hgweb: Configurable zebra stripes
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
2622
diff
changeset
|
793 def stripes(self, parity): |
ebf033bc8eb2
hgweb: Configurable zebra stripes
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
2622
diff
changeset
|
794 "make horizontal stripes for easier reading" |
ebf033bc8eb2
hgweb: Configurable zebra stripes
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
2622
diff
changeset
|
795 if self.stripecount: |
ebf033bc8eb2
hgweb: Configurable zebra stripes
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
2622
diff
changeset
|
796 return (1 + parity / self.stripecount) & 1 |
ebf033bc8eb2
hgweb: Configurable zebra stripes
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
2622
diff
changeset
|
797 else: |
ebf033bc8eb2
hgweb: Configurable zebra stripes
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
2622
diff
changeset
|
798 return 0 |
ebf033bc8eb2
hgweb: Configurable zebra stripes
Frank Kingswood <frank@kingswood-consulting.co.uk>
parents:
2622
diff
changeset
|
799 |
3260
1f1af9b273e8
hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents:
3231
diff
changeset
|
800 def do_log(self, req): |
1f1af9b273e8
hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents:
3231
diff
changeset
|
801 if req.form.has_key('file') and req.form['file'][0]: |
1f1af9b273e8
hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents:
3231
diff
changeset
|
802 self.do_filelog(req) |
1f1af9b273e8
hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents:
3231
diff
changeset
|
803 else: |
1f1af9b273e8
hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents:
3231
diff
changeset
|
804 self.do_changelog(req) |
1f1af9b273e8
hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents:
3231
diff
changeset
|
805 |
1f1af9b273e8
hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents:
3231
diff
changeset
|
806 def do_rev(self, req): |
1f1af9b273e8
hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents:
3231
diff
changeset
|
807 self.do_changeset(req) |
1f1af9b273e8
hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents:
3231
diff
changeset
|
808 |
1f1af9b273e8
hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents:
3231
diff
changeset
|
809 def do_file(self, req): |
1f1af9b273e8
hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents:
3231
diff
changeset
|
810 path = req.form.get('file', [''])[0] |
1f1af9b273e8
hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents:
3231
diff
changeset
|
811 if path: |
1f1af9b273e8
hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents:
3231
diff
changeset
|
812 try: |
1f1af9b273e8
hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents:
3231
diff
changeset
|
813 req.write(self.filerevision(self.filectx(req))) |
1f1af9b273e8
hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents:
3231
diff
changeset
|
814 return |
1f1af9b273e8
hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents:
3231
diff
changeset
|
815 except hg.RepoError: |
1f1af9b273e8
hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents:
3231
diff
changeset
|
816 pass |
1f1af9b273e8
hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents:
3231
diff
changeset
|
817 path = self.cleanpath(path) |
1f1af9b273e8
hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents:
3231
diff
changeset
|
818 |
1f1af9b273e8
hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents:
3231
diff
changeset
|
819 req.write(self.manifest(self.changectx(req), '/' + path)) |
1f1af9b273e8
hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents:
3231
diff
changeset
|
820 |
1f1af9b273e8
hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents:
3231
diff
changeset
|
821 def do_diff(self, req): |
1f1af9b273e8
hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents:
3231
diff
changeset
|
822 self.do_filediff(req) |
1f1af9b273e8
hgweb: accept NewWebInterface URLs
Brendan Cully <brendan@kublai.com>
parents:
3231
diff
changeset
|
823 |
3226
5c6028778c5a
hgweb: add methods to get contexts from request
Brendan Cully <brendan@kublai.com>
parents:
3220
diff
changeset
|
824 def do_changelog(self, req, shortlog = False): |
5c6028778c5a
hgweb: add methods to get contexts from request
Brendan Cully <brendan@kublai.com>
parents:
3220
diff
changeset
|
825 if req.form.has_key('node'): |
5c6028778c5a
hgweb: add methods to get contexts from request
Brendan Cully <brendan@kublai.com>
parents:
3220
diff
changeset
|
826 ctx = self.changectx(req) |
3220
325278542ea8
hgweb: use contexts in more handlers
Brendan Cully <brendan@kublai.com>
parents:
3208
diff
changeset
|
827 else: |
3226
5c6028778c5a
hgweb: add methods to get contexts from request
Brendan Cully <brendan@kublai.com>
parents:
3220
diff
changeset
|
828 if req.form.has_key('rev'): |
5c6028778c5a
hgweb: add methods to get contexts from request
Brendan Cully <brendan@kublai.com>
parents:
3220
diff
changeset
|
829 hi = req.form['rev'][0] |
5c6028778c5a
hgweb: add methods to get contexts from request
Brendan Cully <brendan@kublai.com>
parents:
3220
diff
changeset
|
830 else: |
5c6028778c5a
hgweb: add methods to get contexts from request
Brendan Cully <brendan@kublai.com>
parents:
3220
diff
changeset
|
831 hi = self.repo.changelog.count() - 1 |
5c6028778c5a
hgweb: add methods to get contexts from request
Brendan Cully <brendan@kublai.com>
parents:
3220
diff
changeset
|
832 try: |
5c6028778c5a
hgweb: add methods to get contexts from request
Brendan Cully <brendan@kublai.com>
parents:
3220
diff
changeset
|
833 ctx = self.repo.changectx(hi) |
5c6028778c5a
hgweb: add methods to get contexts from request
Brendan Cully <brendan@kublai.com>
parents:
3220
diff
changeset
|
834 except hg.RepoError: |
5c6028778c5a
hgweb: add methods to get contexts from request
Brendan Cully <brendan@kublai.com>
parents:
3220
diff
changeset
|
835 req.write(self.search(hi)) # XXX redirect to 404 page? |
5c6028778c5a
hgweb: add methods to get contexts from request
Brendan Cully <brendan@kublai.com>
parents:
3220
diff
changeset
|
836 return |
2436
f910b91dd912
hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2434
diff
changeset
|
837 |
3226
5c6028778c5a
hgweb: add methods to get contexts from request
Brendan Cully <brendan@kublai.com>
parents:
3220
diff
changeset
|
838 req.write(self.changelog(ctx, shortlog = shortlog)) |
2436
f910b91dd912
hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2434
diff
changeset
|
839 |
2684
783220e5d2d1
[hgweb] Implemented shortlog (gitweb templates only)
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
2683
diff
changeset
|
840 def do_shortlog(self, req): |
3226
5c6028778c5a
hgweb: add methods to get contexts from request
Brendan Cully <brendan@kublai.com>
parents:
3220
diff
changeset
|
841 self.do_changelog(req, shortlog = True) |
2684
783220e5d2d1
[hgweb] Implemented shortlog (gitweb templates only)
Josef "Jeff" Sipek <jeffpc@josefsipek.net>
parents:
2683
diff
changeset
|
842 |
2436
f910b91dd912
hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2434
diff
changeset
|
843 def do_changeset(self, req): |
3220
325278542ea8
hgweb: use contexts in more handlers
Brendan Cully <brendan@kublai.com>
parents:
3208
diff
changeset
|
844 ctx = self.repo.changectx(req.form['node'][0]) |
325278542ea8
hgweb: use contexts in more handlers
Brendan Cully <brendan@kublai.com>
parents:
3208
diff
changeset
|
845 req.write(self.changeset(ctx)) |
2436
f910b91dd912
hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2434
diff
changeset
|
846 |
f910b91dd912
hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2434
diff
changeset
|
847 def do_manifest(self, req): |
3226
5c6028778c5a
hgweb: add methods to get contexts from request
Brendan Cully <brendan@kublai.com>
parents:
3220
diff
changeset
|
848 req.write(self.manifest(self.changectx(req), |
2436
f910b91dd912
hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2434
diff
changeset
|
849 self.cleanpath(req.form['path'][0]))) |
f910b91dd912
hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2434
diff
changeset
|
850 |
f910b91dd912
hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2434
diff
changeset
|
851 def do_tags(self, req): |
f910b91dd912
hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2434
diff
changeset
|
852 req.write(self.tags()) |
f910b91dd912
hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2434
diff
changeset
|
853 |
f910b91dd912
hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2434
diff
changeset
|
854 def do_summary(self, req): |
f910b91dd912
hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2434
diff
changeset
|
855 req.write(self.summary()) |
f910b91dd912
hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2434
diff
changeset
|
856 |
f910b91dd912
hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2434
diff
changeset
|
857 def do_filediff(self, req): |
3226
5c6028778c5a
hgweb: add methods to get contexts from request
Brendan Cully <brendan@kublai.com>
parents:
3220
diff
changeset
|
858 req.write(self.filediff(self.filectx(req))) |
2436
f910b91dd912
hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2434
diff
changeset
|
859 |
f910b91dd912
hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2434
diff
changeset
|
860 def do_annotate(self, req): |
3226
5c6028778c5a
hgweb: add methods to get contexts from request
Brendan Cully <brendan@kublai.com>
parents:
3220
diff
changeset
|
861 req.write(self.fileannotate(self.filectx(req))) |
2436
f910b91dd912
hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2434
diff
changeset
|
862 |
f910b91dd912
hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2434
diff
changeset
|
863 def do_filelog(self, req): |
3226
5c6028778c5a
hgweb: add methods to get contexts from request
Brendan Cully <brendan@kublai.com>
parents:
3220
diff
changeset
|
864 req.write(self.filelog(self.filectx(req))) |
2436
f910b91dd912
hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2434
diff
changeset
|
865 |
f910b91dd912
hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2434
diff
changeset
|
866 def do_heads(self, req): |
f910b91dd912
hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2434
diff
changeset
|
867 resp = " ".join(map(hex, self.repo.heads())) + "\n" |
f910b91dd912
hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2434
diff
changeset
|
868 req.httphdr("application/mercurial-0.1", length=len(resp)) |
f910b91dd912
hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2434
diff
changeset
|
869 req.write(resp) |
f910b91dd912
hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2434
diff
changeset
|
870 |
f910b91dd912
hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2434
diff
changeset
|
871 def do_branches(self, req): |
f910b91dd912
hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2434
diff
changeset
|
872 nodes = [] |
f910b91dd912
hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2434
diff
changeset
|
873 if req.form.has_key('nodes'): |
f910b91dd912
hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2434
diff
changeset
|
874 nodes = map(bin, req.form['nodes'][0].split(" ")) |
f910b91dd912
hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2434
diff
changeset
|
875 resp = cStringIO.StringIO() |
f910b91dd912
hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2434
diff
changeset
|
876 for b in self.repo.branches(nodes): |
f910b91dd912
hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2434
diff
changeset
|
877 resp.write(" ".join(map(hex, b)) + "\n") |
f910b91dd912
hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2434
diff
changeset
|
878 resp = resp.getvalue() |
f910b91dd912
hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2434
diff
changeset
|
879 req.httphdr("application/mercurial-0.1", length=len(resp)) |
f910b91dd912
hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2434
diff
changeset
|
880 req.write(resp) |
f910b91dd912
hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2434
diff
changeset
|
881 |
f910b91dd912
hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2434
diff
changeset
|
882 def do_between(self, req): |
f910b91dd912
hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2434
diff
changeset
|
883 if req.form.has_key('pairs'): |
f910b91dd912
hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2434
diff
changeset
|
884 pairs = [map(bin, p.split("-")) |
f910b91dd912
hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2434
diff
changeset
|
885 for p in req.form['pairs'][0].split(" ")] |
f910b91dd912
hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2434
diff
changeset
|
886 resp = cStringIO.StringIO() |
f910b91dd912
hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2434
diff
changeset
|
887 for b in self.repo.between(pairs): |
f910b91dd912
hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2434
diff
changeset
|
888 resp.write(" ".join(map(hex, b)) + "\n") |
f910b91dd912
hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2434
diff
changeset
|
889 resp = resp.getvalue() |
f910b91dd912
hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2434
diff
changeset
|
890 req.httphdr("application/mercurial-0.1", length=len(resp)) |
f910b91dd912
hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2434
diff
changeset
|
891 req.write(resp) |
f910b91dd912
hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2434
diff
changeset
|
892 |
f910b91dd912
hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2434
diff
changeset
|
893 def do_changegroup(self, req): |
f910b91dd912
hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2434
diff
changeset
|
894 req.httphdr("application/mercurial-0.1") |
f910b91dd912
hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2434
diff
changeset
|
895 nodes = [] |
f910b91dd912
hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2434
diff
changeset
|
896 if not self.allowpull: |
f910b91dd912
hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2434
diff
changeset
|
897 return |
f910b91dd912
hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2434
diff
changeset
|
898 |
f910b91dd912
hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2434
diff
changeset
|
899 if req.form.has_key('roots'): |
f910b91dd912
hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2434
diff
changeset
|
900 nodes = map(bin, req.form['roots'][0].split(" ")) |
f910b91dd912
hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2434
diff
changeset
|
901 |
f910b91dd912
hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2434
diff
changeset
|
902 z = zlib.compressobj() |
f910b91dd912
hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2434
diff
changeset
|
903 f = self.repo.changegroup(nodes, 'serve') |
f910b91dd912
hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2434
diff
changeset
|
904 while 1: |
f910b91dd912
hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2434
diff
changeset
|
905 chunk = f.read(4096) |
f910b91dd912
hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2434
diff
changeset
|
906 if not chunk: |
f910b91dd912
hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2434
diff
changeset
|
907 break |
f910b91dd912
hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2434
diff
changeset
|
908 req.write(z.compress(chunk)) |
f910b91dd912
hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2434
diff
changeset
|
909 |
f910b91dd912
hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2434
diff
changeset
|
910 req.write(z.flush()) |
f910b91dd912
hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2434
diff
changeset
|
911 |
f910b91dd912
hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2434
diff
changeset
|
912 def do_archive(self, req): |
f910b91dd912
hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2434
diff
changeset
|
913 changeset = self.repo.lookup(req.form['node'][0]) |
f910b91dd912
hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2434
diff
changeset
|
914 type_ = req.form['type'][0] |
2500
76ff5efe8181
Fixed [web] allow_archive for comma separated parameters by using ui.configlist.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2466
diff
changeset
|
915 allowed = self.repo.ui.configlist("web", "allow_archive") |
2436
f910b91dd912
hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2434
diff
changeset
|
916 if (type_ in self.archives and (type_ in allowed or |
f910b91dd912
hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2434
diff
changeset
|
917 self.repo.ui.configbool("web", "allow" + type_, False))): |
f910b91dd912
hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2434
diff
changeset
|
918 self.archive(req, changeset, type_) |
f910b91dd912
hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2434
diff
changeset
|
919 return |
f910b91dd912
hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2434
diff
changeset
|
920 |
f910b91dd912
hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2434
diff
changeset
|
921 req.write(self.t("error")) |
f910b91dd912
hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2434
diff
changeset
|
922 |
f910b91dd912
hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2434
diff
changeset
|
923 def do_static(self, req): |
f910b91dd912
hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2434
diff
changeset
|
924 fname = req.form['file'][0] |
f910b91dd912
hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2434
diff
changeset
|
925 static = self.repo.ui.config("web", "static", |
f910b91dd912
hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2434
diff
changeset
|
926 os.path.join(self.templatepath, |
f910b91dd912
hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2434
diff
changeset
|
927 "static")) |
2514
419c42223bee
Really fix http headers for web UI and issue 254.
Eric Hopper <hopper@omnifarious.org>
parents:
2509
diff
changeset
|
928 req.write(staticfile(static, fname, req) |
2436
f910b91dd912
hgweb: split "verbs" into methods.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2434
diff
changeset
|
929 or self.t("error", error="%r not found" % fname)) |
2442
c660691fb45d
http: query server for capabilities
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2436
diff
changeset
|
930 |
c660691fb45d
http: query server for capabilities
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2436
diff
changeset
|
931 def do_capabilities(self, req): |
2621
5a5852a417b1
clone: disable stream support on server side by default.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2612
diff
changeset
|
932 caps = ['unbundle'] |
2622
064aef9162cc
rename stream hgrc option to compressed.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2621
diff
changeset
|
933 if self.repo.ui.configbool('server', 'uncompressed'): |
2621
5a5852a417b1
clone: disable stream support on server side by default.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2612
diff
changeset
|
934 caps.append('stream=%d' % self.repo.revlogversion) |
5a5852a417b1
clone: disable stream support on server side by default.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2612
diff
changeset
|
935 resp = ' '.join(caps) |
2442
c660691fb45d
http: query server for capabilities
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2436
diff
changeset
|
936 req.httphdr("application/mercurial-0.1", length=len(resp)) |
c660691fb45d
http: query server for capabilities
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2436
diff
changeset
|
937 req.write(resp) |
c660691fb45d
http: query server for capabilities
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2436
diff
changeset
|
938 |
2466
e10665147d26
push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2464
diff
changeset
|
939 def check_perm(self, req, op, default): |
e10665147d26
push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2464
diff
changeset
|
940 '''check permission for operation based on user auth. |
e10665147d26
push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2464
diff
changeset
|
941 return true if op allowed, else false. |
e10665147d26
push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2464
diff
changeset
|
942 default is policy to use if no config given.''' |
e10665147d26
push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2464
diff
changeset
|
943 |
e10665147d26
push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2464
diff
changeset
|
944 user = req.env.get('REMOTE_USER') |
e10665147d26
push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2464
diff
changeset
|
945 |
2501
b73552a00b20
Make "[web] allow_push, deny_push" and "[http_proxy] no" use ui.configlist.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2500
diff
changeset
|
946 deny = self.repo.ui.configlist('web', 'deny_' + op) |
2466
e10665147d26
push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2464
diff
changeset
|
947 if deny and (not user or deny == ['*'] or user in deny): |
e10665147d26
push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2464
diff
changeset
|
948 return False |
e10665147d26
push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2464
diff
changeset
|
949 |
2501
b73552a00b20
Make "[web] allow_push, deny_push" and "[http_proxy] no" use ui.configlist.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
2500
diff
changeset
|
950 allow = self.repo.ui.configlist('web', 'allow_' + op) |
2466
e10665147d26
push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2464
diff
changeset
|
951 return (allow and (allow == ['*'] or user in allow)) or default |
e10665147d26
push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2464
diff
changeset
|
952 |
2464
09b1c9ef317c
push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2442
diff
changeset
|
953 def do_unbundle(self, req): |
2466
e10665147d26
push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2464
diff
changeset
|
954 def bail(response, headers={}): |
e10665147d26
push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2464
diff
changeset
|
955 length = int(req.env['CONTENT_LENGTH']) |
e10665147d26
push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2464
diff
changeset
|
956 for s in util.filechunkiter(req, limit=length): |
e10665147d26
push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2464
diff
changeset
|
957 # drain incoming bundle, else client will not see |
e10665147d26
push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2464
diff
changeset
|
958 # response when run outside cgi script |
e10665147d26
push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2464
diff
changeset
|
959 pass |
e10665147d26
push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2464
diff
changeset
|
960 req.httphdr("application/mercurial-0.1", headers=headers) |
e10665147d26
push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2464
diff
changeset
|
961 req.write('0\n') |
e10665147d26
push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2464
diff
changeset
|
962 req.write(response) |
e10665147d26
push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2464
diff
changeset
|
963 |
e10665147d26
push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2464
diff
changeset
|
964 # require ssl by default, auth info cannot be sniffed and |
e10665147d26
push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2464
diff
changeset
|
965 # replayed |
e10665147d26
push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2464
diff
changeset
|
966 ssl_req = self.repo.ui.configbool('web', 'push_ssl', True) |
2673
109a22f5434a
hooks: add url to changegroup, incoming, prechangegroup, pretxnchangegroup hooks
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2666
diff
changeset
|
967 if ssl_req: |
109a22f5434a
hooks: add url to changegroup, incoming, prechangegroup, pretxnchangegroup hooks
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2666
diff
changeset
|
968 if not req.env.get('HTTPS'): |
109a22f5434a
hooks: add url to changegroup, incoming, prechangegroup, pretxnchangegroup hooks
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2666
diff
changeset
|
969 bail(_('ssl required\n')) |
109a22f5434a
hooks: add url to changegroup, incoming, prechangegroup, pretxnchangegroup hooks
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2666
diff
changeset
|
970 return |
109a22f5434a
hooks: add url to changegroup, incoming, prechangegroup, pretxnchangegroup hooks
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2666
diff
changeset
|
971 proto = 'https' |
109a22f5434a
hooks: add url to changegroup, incoming, prechangegroup, pretxnchangegroup hooks
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2666
diff
changeset
|
972 else: |
109a22f5434a
hooks: add url to changegroup, incoming, prechangegroup, pretxnchangegroup hooks
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2666
diff
changeset
|
973 proto = 'http' |
2466
e10665147d26
push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2464
diff
changeset
|
974 |
e10665147d26
push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2464
diff
changeset
|
975 # do not allow push unless explicitly allowed |
e10665147d26
push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2464
diff
changeset
|
976 if not self.check_perm(req, 'push', False): |
e10665147d26
push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2464
diff
changeset
|
977 bail(_('push not authorized\n'), |
e10665147d26
push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2464
diff
changeset
|
978 headers={'status': '401 Unauthorized'}) |
e10665147d26
push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2464
diff
changeset
|
979 return |
e10665147d26
push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2464
diff
changeset
|
980 |
e10665147d26
push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2464
diff
changeset
|
981 req.httphdr("application/mercurial-0.1") |
e10665147d26
push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2464
diff
changeset
|
982 |
2464
09b1c9ef317c
push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2442
diff
changeset
|
983 their_heads = req.form['heads'][0].split(' ') |
09b1c9ef317c
push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2442
diff
changeset
|
984 |
09b1c9ef317c
push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2442
diff
changeset
|
985 def check_heads(): |
09b1c9ef317c
push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2442
diff
changeset
|
986 heads = map(hex, self.repo.heads()) |
09b1c9ef317c
push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2442
diff
changeset
|
987 return their_heads == [hex('force')] or their_heads == heads |
09b1c9ef317c
push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2442
diff
changeset
|
988 |
09b1c9ef317c
push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2442
diff
changeset
|
989 # fail early if possible |
09b1c9ef317c
push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2442
diff
changeset
|
990 if not check_heads(): |
2466
e10665147d26
push over http: server side authorization support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2464
diff
changeset
|
991 bail(_('unsynced changes\n')) |
2464
09b1c9ef317c
push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2442
diff
changeset
|
992 return |
09b1c9ef317c
push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2442
diff
changeset
|
993 |
09b1c9ef317c
push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2442
diff
changeset
|
994 # do not lock repo until all changegroup data is |
09b1c9ef317c
push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2442
diff
changeset
|
995 # streamed. save to temporary file. |
09b1c9ef317c
push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2442
diff
changeset
|
996 |
09b1c9ef317c
push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2442
diff
changeset
|
997 fd, tempname = tempfile.mkstemp(prefix='hg-unbundle-') |
09b1c9ef317c
push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2442
diff
changeset
|
998 fp = os.fdopen(fd, 'wb+') |
09b1c9ef317c
push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2442
diff
changeset
|
999 try: |
09b1c9ef317c
push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2442
diff
changeset
|
1000 length = int(req.env['CONTENT_LENGTH']) |
09b1c9ef317c
push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2442
diff
changeset
|
1001 for s in util.filechunkiter(req, limit=length): |
09b1c9ef317c
push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2442
diff
changeset
|
1002 fp.write(s) |
09b1c9ef317c
push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2442
diff
changeset
|
1003 |
09b1c9ef317c
push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2442
diff
changeset
|
1004 lock = self.repo.lock() |
09b1c9ef317c
push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2442
diff
changeset
|
1005 try: |
09b1c9ef317c
push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2442
diff
changeset
|
1006 if not check_heads(): |
09b1c9ef317c
push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2442
diff
changeset
|
1007 req.write('0\n') |
09b1c9ef317c
push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2442
diff
changeset
|
1008 req.write(_('unsynced changes\n')) |
09b1c9ef317c
push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2442
diff
changeset
|
1009 return |
09b1c9ef317c
push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2442
diff
changeset
|
1010 |
09b1c9ef317c
push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2442
diff
changeset
|
1011 fp.seek(0) |
09b1c9ef317c
push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2442
diff
changeset
|
1012 |
09b1c9ef317c
push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2442
diff
changeset
|
1013 # send addchangegroup output to client |
09b1c9ef317c
push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2442
diff
changeset
|
1014 |
09b1c9ef317c
push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2442
diff
changeset
|
1015 old_stdout = sys.stdout |
09b1c9ef317c
push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2442
diff
changeset
|
1016 sys.stdout = cStringIO.StringIO() |
09b1c9ef317c
push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2442
diff
changeset
|
1017 |
09b1c9ef317c
push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2442
diff
changeset
|
1018 try: |
2673
109a22f5434a
hooks: add url to changegroup, incoming, prechangegroup, pretxnchangegroup hooks
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2666
diff
changeset
|
1019 url = 'remote:%s:%s' % (proto, |
109a22f5434a
hooks: add url to changegroup, incoming, prechangegroup, pretxnchangegroup hooks
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2666
diff
changeset
|
1020 req.env.get('REMOTE_HOST', '')) |
109a22f5434a
hooks: add url to changegroup, incoming, prechangegroup, pretxnchangegroup hooks
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2666
diff
changeset
|
1021 ret = self.repo.addchangegroup(fp, 'serve', url) |
2464
09b1c9ef317c
push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2442
diff
changeset
|
1022 finally: |
2558
1120302009d7
hgweb: fix unbundle.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
2538
diff
changeset
|
1023 val = sys.stdout.getvalue() |
2464
09b1c9ef317c
push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2442
diff
changeset
|
1024 sys.stdout = old_stdout |
2558
1120302009d7
hgweb: fix unbundle.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
2538
diff
changeset
|
1025 req.write('%d\n' % ret) |
1120302009d7
hgweb: fix unbundle.
Alexis S. L. Carvalho <alexis@cecm.usp.br>
parents:
2538
diff
changeset
|
1026 req.write(val) |
2464
09b1c9ef317c
push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2442
diff
changeset
|
1027 finally: |
09b1c9ef317c
push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2442
diff
changeset
|
1028 lock.release() |
09b1c9ef317c
push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2442
diff
changeset
|
1029 finally: |
09b1c9ef317c
push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2442
diff
changeset
|
1030 fp.close() |
09b1c9ef317c
push over http: server support.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2442
diff
changeset
|
1031 os.unlink(tempname) |
2612
ffb895f16925
add support for streaming clone.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2580
diff
changeset
|
1032 |
ffb895f16925
add support for streaming clone.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2580
diff
changeset
|
1033 def do_stream_out(self, req): |
ffb895f16925
add support for streaming clone.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2580
diff
changeset
|
1034 req.httphdr("application/mercurial-0.1") |
ffb895f16925
add support for streaming clone.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2580
diff
changeset
|
1035 streamclone.stream_out(self.repo, req) |