Show More
@@ -1,219 +1,225 | |||||
1 | # color.py color output for the status and qseries commands |
|
1 | # color.py color output for the status and qseries commands | |
2 | # |
|
2 | # | |
3 | # Copyright (C) 2007 Kevin Christen <kevin.christen@gmail.com> |
|
3 | # Copyright (C) 2007 Kevin Christen <kevin.christen@gmail.com> | |
4 | # |
|
4 | # | |
5 | # This program is free software; you can redistribute it and/or modify it |
|
5 | # This program is free software; you can redistribute it and/or modify it | |
6 | # under the terms of the GNU General Public License as published by the |
|
6 | # under the terms of the GNU General Public License as published by the | |
7 | # Free Software Foundation; either version 2 of the License, or (at your |
|
7 | # Free Software Foundation; either version 2 of the License, or (at your | |
8 | # option) any later version. |
|
8 | # option) any later version. | |
9 | # |
|
9 | # | |
10 | # This program is distributed in the hope that it will be useful, but |
|
10 | # This program is distributed in the hope that it will be useful, but | |
11 | # WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | # WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
|
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General | |
13 | # Public License for more details. |
|
13 | # Public License for more details. | |
14 | # |
|
14 | # | |
15 | # You should have received a copy of the GNU General Public License along |
|
15 | # You should have received a copy of the GNU General Public License along | |
16 | # with this program; if not, write to the Free Software Foundation, Inc., |
|
16 | # with this program; if not, write to the Free Software Foundation, Inc., | |
17 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
|
17 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 |
|
18 | |||
19 | '''add color output to the status and qseries commands |
|
19 | '''add color output to the status and qseries commands | |
20 |
|
20 | |||
21 | This extension modifies the status command to add color to its output to |
|
21 | This extension modifies the status command to add color to its output to | |
22 | reflect file status, and the qseries command to add color to reflect patch |
|
22 | reflect file status, and the qseries command to add color to reflect patch | |
23 | status (applied, unapplied, missing). Other effects in addition to color, |
|
23 | status (applied, unapplied, missing). Other effects in addition to color, | |
24 | like bold and underlined text, are also available. Effects are rendered |
|
24 | like bold and underlined text, are also available. Effects are rendered | |
25 | with the ECMA-48 SGR control function (aka ANSI escape codes). This module |
|
25 | with the ECMA-48 SGR control function (aka ANSI escape codes). This module | |
26 | also provides the render_text function, which can be used to add effects to |
|
26 | also provides the render_text function, which can be used to add effects to | |
27 | any text. |
|
27 | any text. | |
28 |
|
28 | |||
29 | To enable this extension, add this to your .hgrc file: |
|
29 | To enable this extension, add this to your .hgrc file: | |
30 | [extensions] |
|
30 | [extensions] | |
31 | color = |
|
31 | color = | |
32 |
|
32 | |||
33 | Default effects my be overriden from the .hgrc file: |
|
33 | Default effects my be overriden from the .hgrc file: | |
34 |
|
34 | |||
35 | [color] |
|
35 | [color] | |
36 | status.modified = blue bold underline red_background |
|
36 | status.modified = blue bold underline red_background | |
37 | status.added = green bold |
|
37 | status.added = green bold | |
38 | status.removed = red bold blue_background |
|
38 | status.removed = red bold blue_background | |
39 | status.deleted = cyan bold underline |
|
39 | status.deleted = cyan bold underline | |
40 | status.unknown = magenta bold underline |
|
40 | status.unknown = magenta bold underline | |
41 | status.ignored = black bold |
|
41 | status.ignored = black bold | |
42 |
|
42 | |||
43 | 'none' turns off all effects |
|
43 | # 'none' turns off all effects | |
44 | status.clean = none |
|
44 | status.clean = none | |
45 | status.copied = none |
|
45 | status.copied = none | |
46 |
|
46 | |||
47 | qseries.applied = blue bold underline |
|
47 | qseries.applied = blue bold underline | |
48 | qseries.unapplied = black bold |
|
48 | qseries.unapplied = black bold | |
49 | qseries.missing = red bold |
|
49 | qseries.missing = red bold | |
50 | ''' |
|
50 | ''' | |
51 |
|
51 | |||
52 | import re, sys |
|
52 | import re, sys | |
53 |
|
53 | |||
54 | from mercurial import commands, cmdutil |
|
54 | from mercurial import commands, cmdutil | |
55 | from mercurial.i18n import _ |
|
55 | from mercurial.i18n import _ | |
56 |
|
56 | |||
57 | # start and stop parameters for effects |
|
57 | # start and stop parameters for effects | |
58 | _effect_params = { 'none': (0, 0), |
|
58 | _effect_params = { 'none': (0, 0), | |
59 | 'black': (30, 39), |
|
59 | 'black': (30, 39), | |
60 | 'red': (31, 39), |
|
60 | 'red': (31, 39), | |
61 | 'green': (32, 39), |
|
61 | 'green': (32, 39), | |
62 | 'yellow': (33, 39), |
|
62 | 'yellow': (33, 39), | |
63 | 'blue': (34, 39), |
|
63 | 'blue': (34, 39), | |
64 | 'magenta': (35, 39), |
|
64 | 'magenta': (35, 39), | |
65 | 'cyan': (36, 39), |
|
65 | 'cyan': (36, 39), | |
66 | 'white': (37, 39), |
|
66 | 'white': (37, 39), | |
67 | 'bold': (1, 22), |
|
67 | 'bold': (1, 22), | |
68 | 'italic': (3, 23), |
|
68 | 'italic': (3, 23), | |
69 | 'underline': (4, 24), |
|
69 | 'underline': (4, 24), | |
70 | 'inverse': (7, 27), |
|
70 | 'inverse': (7, 27), | |
71 | 'black_background': (40, 49), |
|
71 | 'black_background': (40, 49), | |
72 | 'red_background': (41, 49), |
|
72 | 'red_background': (41, 49), | |
73 | 'green_background': (42, 49), |
|
73 | 'green_background': (42, 49), | |
74 | 'yellow_background': (43, 49), |
|
74 | 'yellow_background': (43, 49), | |
75 | 'blue_background': (44, 49), |
|
75 | 'blue_background': (44, 49), | |
76 | 'purple_background': (45, 49), |
|
76 | 'purple_background': (45, 49), | |
77 | 'cyan_background': (46, 49), |
|
77 | 'cyan_background': (46, 49), | |
78 | 'white_background': (47, 49), } |
|
78 | 'white_background': (47, 49), } | |
79 |
|
79 | |||
80 | def render_effects(text, *effects): |
|
80 | def render_effects(text, *effects): | |
81 | 'Wrap text in commands to turn on each effect.' |
|
81 | 'Wrap text in commands to turn on each effect.' | |
82 | start = [] |
|
82 | start = [ str(_effect_params['none'][0]) ] | |
83 | stop = [] |
|
83 | stop = [] | |
84 | for effect in effects: |
|
84 | for effect in effects: | |
85 | start.append(str(_effect_params[effect][0])) |
|
85 | start.append(str(_effect_params[effect][0])) | |
86 | stop.append(str(_effect_params[effect][1])) |
|
86 | stop.append(str(_effect_params[effect][1])) | |
|
87 | stop.append(str(_effect_params['none'][1])) | |||
87 | start = '\033[' + ';'.join(start) + 'm' |
|
88 | start = '\033[' + ';'.join(start) + 'm' | |
88 | stop = '\033[' + ';'.join(stop) + 'm' |
|
89 | stop = '\033[' + ';'.join(stop) + 'm' | |
89 | return start + text + stop |
|
90 | return start + text + stop | |
90 |
|
91 | |||
91 | def colorstatus(statusfunc, ui, repo, *pats, **opts): |
|
92 | def colorstatus(statusfunc, ui, repo, *pats, **opts): | |
92 | '''run the status command with colored output''' |
|
93 | '''run the status command with colored output''' | |
93 |
|
94 | |||
94 | delimiter = opts['print0'] and '\0' or '\n' |
|
95 | delimiter = opts['print0'] and '\0' or '\n' | |
95 |
|
96 | |||
96 | # run status and capture it's output |
|
97 | # run status and capture it's output | |
97 | ui.pushbuffer() |
|
98 | ui.pushbuffer() | |
98 | retval = statusfunc(ui, repo, *pats, **opts) |
|
99 | retval = statusfunc(ui, repo, *pats, **opts) | |
99 | # filter out empty strings |
|
100 | # filter out empty strings | |
100 | lines = [ line for line in ui.popbuffer().split(delimiter) if line ] |
|
101 | lines = [ line for line in ui.popbuffer().split(delimiter) if line ] | |
101 |
|
102 | |||
102 | if opts['no_status']: |
|
103 | if opts['no_status']: | |
103 | # if --no-status, run the command again without that option to get |
|
104 | # if --no-status, run the command again without that option to get | |
104 | # output with status abbreviations |
|
105 | # output with status abbreviations | |
105 | opts['no_status'] = False |
|
106 | opts['no_status'] = False | |
106 | ui.pushbuffer() |
|
107 | ui.pushbuffer() | |
107 | statusfunc(ui, repo, *pats, **opts) |
|
108 | statusfunc(ui, repo, *pats, **opts) | |
108 | # filter out empty strings |
|
109 | # filter out empty strings | |
109 | lines_with_status = [ line for |
|
110 | lines_with_status = [ line for | |
110 | line in ui.popbuffer().split(delimiter) if line ] |
|
111 | line in ui.popbuffer().split(delimiter) if line ] | |
111 | else: |
|
112 | else: | |
112 | lines_with_status = lines |
|
113 | lines_with_status = lines | |
113 |
|
114 | |||
114 | # apply color to output and display it |
|
115 | # apply color to output and display it | |
115 | for i in xrange(0, len(lines)): |
|
116 | for i in xrange(0, len(lines)): | |
116 | status = _status_abbreviations[lines_with_status[i][0]] |
|
117 | status = _status_abbreviations[lines_with_status[i][0]] | |
117 | effects = _status_effects[status] |
|
118 | effects = _status_effects[status] | |
118 | if effects: |
|
119 | if effects: | |
119 | lines[i] = render_effects(lines[i], *effects) |
|
120 | lines[i] = render_effects(lines[i], *effects) | |
120 | sys.stdout.write(lines[i] + delimiter) |
|
121 | sys.stdout.write(lines[i] + delimiter) | |
121 | return retval |
|
122 | return retval | |
122 |
|
123 | |||
123 | _status_abbreviations = { 'M': 'modified', |
|
124 | _status_abbreviations = { 'M': 'modified', | |
124 | 'A': 'added', |
|
125 | 'A': 'added', | |
125 | 'R': 'removed', |
|
126 | 'R': 'removed', | |
126 | '!': 'deleted', |
|
127 | '!': 'deleted', | |
127 | '?': 'unknown', |
|
128 | '?': 'unknown', | |
128 | 'I': 'ignored', |
|
129 | 'I': 'ignored', | |
129 | 'C': 'clean', |
|
130 | 'C': 'clean', | |
130 | ' ': 'copied', } |
|
131 | ' ': 'copied', } | |
131 |
|
132 | |||
132 | _status_effects = { 'modified': ('blue', 'bold'), |
|
133 | _status_effects = { 'modified': ('blue', 'bold'), | |
133 | 'added': ('green', 'bold'), |
|
134 | 'added': ('green', 'bold'), | |
134 | 'removed': ('red', 'bold'), |
|
135 | 'removed': ('red', 'bold'), | |
135 | 'deleted': ('cyan', 'bold', 'underline'), |
|
136 | 'deleted': ('cyan', 'bold', 'underline'), | |
136 | 'unknown': ('magenta', 'bold', 'underline'), |
|
137 | 'unknown': ('magenta', 'bold', 'underline'), | |
137 | 'ignored': ('black', 'bold'), |
|
138 | 'ignored': ('black', 'bold'), | |
138 | 'clean': ('none', ), |
|
139 | 'clean': ('none', ), | |
139 | 'copied': ('none', ), } |
|
140 | 'copied': ('none', ), } | |
140 |
|
141 | |||
141 | def colorqseries(qseriesfunc, ui, repo, *dummy, **opts): |
|
142 | def colorqseries(qseriesfunc, ui, repo, *dummy, **opts): | |
142 | '''run the qseries command with colored output''' |
|
143 | '''run the qseries command with colored output''' | |
143 | ui.pushbuffer() |
|
144 | ui.pushbuffer() | |
144 | retval = qseriesfunc(ui, repo, **opts) |
|
145 | retval = qseriesfunc(ui, repo, **opts) | |
145 | patches = ui.popbuffer().splitlines() |
|
146 | patches = ui.popbuffer().splitlines() | |
146 | for patch in patches: |
|
147 | for patch in patches: | |
|
148 | patchname = patch | |||
|
149 | if opts['summary']: | |||
|
150 | patchname = patchname.split(': ')[0] | |||
|
151 | if ui.verbose: | |||
|
152 | patchname = patchname.split(' ', 2)[-1] | |||
|
153 | ||||
147 | if opts['missing']: |
|
154 | if opts['missing']: | |
148 | effects = _patch_effects['missing'] |
|
155 | effects = _patch_effects['missing'] | |
149 |
# Determine if patch is applied. |
|
156 | # Determine if patch is applied. | |
150 | # line in the applied patch list, in case --summary has been used |
|
|||
151 | # and output line isn't just the patch name. |
|
|||
152 | elif [ applied for applied in repo.mq.applied |
|
157 | elif [ applied for applied in repo.mq.applied | |
153 |
if patch |
|
158 | if patchname == applied.name ]: | |
154 | effects = _patch_effects['applied'] |
|
159 | effects = _patch_effects['applied'] | |
155 | else: |
|
160 | else: | |
156 | effects = _patch_effects['unapplied'] |
|
161 | effects = _patch_effects['unapplied'] | |
157 | sys.stdout.write(render_effects(patch, *effects) + '\n') |
|
162 | sys.stdout.write(render_effects(patch, *effects) + '\n') | |
158 | return retval |
|
163 | return retval | |
159 |
|
164 | |||
160 | _patch_effects = { 'applied': ('blue', 'bold', 'underline'), |
|
165 | _patch_effects = { 'applied': ('blue', 'bold', 'underline'), | |
161 | 'missing': ('red', 'bold'), |
|
166 | 'missing': ('red', 'bold'), | |
162 | 'unapplied': ('black', 'bold'), } |
|
167 | 'unapplied': ('black', 'bold'), } | |
163 |
|
168 | |||
164 | def uisetup(ui): |
|
169 | def uisetup(ui): | |
165 | '''Initialize the extension.''' |
|
170 | '''Initialize the extension.''' | |
166 | nocoloropt = ('', 'no-color', None, _("don't colorize output")) |
|
171 | nocoloropt = ('', 'no-color', None, _("don't colorize output")) | |
167 | _decoratecmd(ui, 'status', commands.table, colorstatus, nocoloropt) |
|
172 | _decoratecmd(ui, 'status', commands.table, colorstatus, nocoloropt) | |
168 | _configcmdeffects(ui, 'status', _status_effects); |
|
173 | _configcmdeffects(ui, 'status', _status_effects); | |
169 |
if ui.config('extensions', 'hgext.mq' |
|
174 | if ui.config('extensions', 'hgext.mq') is not None or \ | |
|
175 | ui.config('extensions', 'mq') is not None: | |||
170 | from hgext import mq |
|
176 | from hgext import mq | |
171 | _decoratecmd(ui, 'qseries', mq.cmdtable, colorqseries, nocoloropt) |
|
177 | _decoratecmd(ui, 'qseries', mq.cmdtable, colorqseries, nocoloropt) | |
172 | _configcmdeffects(ui, 'qseries', _patch_effects); |
|
178 | _configcmdeffects(ui, 'qseries', _patch_effects); | |
173 |
|
179 | |||
174 | def _decoratecmd(ui, cmd, table, delegate, *delegateoptions): |
|
180 | def _decoratecmd(ui, cmd, table, delegate, *delegateoptions): | |
175 | '''Replace the function that implements cmd in table with a decorator. |
|
181 | '''Replace the function that implements cmd in table with a decorator. | |
176 |
|
182 | |||
177 | The decorator that becomes the new implementation of cmd calls |
|
183 | The decorator that becomes the new implementation of cmd calls | |
178 | delegate. The delegate's first argument is the replaced function, |
|
184 | delegate. The delegate's first argument is the replaced function, | |
179 | followed by the normal Mercurial command arguments (ui, repo, ...). If |
|
185 | followed by the normal Mercurial command arguments (ui, repo, ...). If | |
180 | the delegate adds command options, supply them as delegateoptions. |
|
186 | the delegate adds command options, supply them as delegateoptions. | |
181 | ''' |
|
187 | ''' | |
182 | cmdkey, cmdentry = _cmdtableitem(ui, cmd, table) |
|
188 | cmdkey, cmdentry = _cmdtableitem(ui, cmd, table) | |
183 | decorator = lambda ui, repo, *args, **opts: \ |
|
189 | decorator = lambda ui, repo, *args, **opts: \ | |
184 | _colordecorator(delegate, cmdentry[0], |
|
190 | _colordecorator(delegate, cmdentry[0], | |
185 | ui, repo, *args, **opts) |
|
191 | ui, repo, *args, **opts) | |
186 | # make sure 'hg help cmd' still works |
|
192 | # make sure 'hg help cmd' still works | |
187 | decorator.__doc__ = cmdentry[0].__doc__ |
|
193 | decorator.__doc__ = cmdentry[0].__doc__ | |
188 | decoratorentry = (decorator,) + cmdentry[1:] |
|
194 | decoratorentry = (decorator,) + cmdentry[1:] | |
189 | for option in delegateoptions: |
|
195 | for option in delegateoptions: | |
190 | decoratorentry[1].append(option) |
|
196 | decoratorentry[1].append(option) | |
191 | table[cmdkey] = decoratorentry |
|
197 | table[cmdkey] = decoratorentry | |
192 |
|
198 | |||
193 | def _cmdtableitem(ui, cmd, table): |
|
199 | def _cmdtableitem(ui, cmd, table): | |
194 | '''Return key, value from table for cmd, or None if not found.''' |
|
200 | '''Return key, value from table for cmd, or None if not found.''' | |
195 | aliases, entry = cmdutil.findcmd(ui, cmd, table) |
|
201 | aliases, entry = cmdutil.findcmd(ui, cmd, table) | |
196 | for candidatekey, candidateentry in table.iteritems(): |
|
202 | for candidatekey, candidateentry in table.iteritems(): | |
197 | if candidateentry is entry: |
|
203 | if candidateentry is entry: | |
198 | return candidatekey, entry |
|
204 | return candidatekey, entry | |
199 |
|
205 | |||
200 | def _colordecorator(colorfunc, nocolorfunc, ui, repo, *args, **opts): |
|
206 | def _colordecorator(colorfunc, nocolorfunc, ui, repo, *args, **opts): | |
201 | '''Delegate to colorfunc or nocolorfunc, depending on conditions. |
|
207 | '''Delegate to colorfunc or nocolorfunc, depending on conditions. | |
202 |
|
208 | |||
203 | Delegate to colorfunc unless --no-color option is set or output is not |
|
209 | Delegate to colorfunc unless --no-color option is set or output is not | |
204 | to a tty. |
|
210 | to a tty. | |
205 | ''' |
|
211 | ''' | |
206 | if opts['no_color'] or not sys.stdout.isatty(): |
|
212 | if opts['no_color'] or not sys.stdout.isatty(): | |
207 | return nocolorfunc(ui, repo, *args, **opts) |
|
213 | return nocolorfunc(ui, repo, *args, **opts) | |
208 | return colorfunc(nocolorfunc, ui, repo, *args, **opts) |
|
214 | return colorfunc(nocolorfunc, ui, repo, *args, **opts) | |
209 |
|
215 | |||
210 | def _configcmdeffects(ui, cmdname, effectsmap): |
|
216 | def _configcmdeffects(ui, cmdname, effectsmap): | |
211 | '''Override default effects for cmdname with those from .hgrc file. |
|
217 | '''Override default effects for cmdname with those from .hgrc file. | |
212 |
|
218 | |||
213 | Entries in the .hgrc file are in the [color] section, and look like |
|
219 | Entries in the .hgrc file are in the [color] section, and look like | |
214 | 'cmdname'.'status' (for instance, 'status.modified = blue bold inverse'). |
|
220 | 'cmdname'.'status' (for instance, 'status.modified = blue bold inverse'). | |
215 | ''' |
|
221 | ''' | |
216 | for status in effectsmap: |
|
222 | for status in effectsmap: | |
217 | effects = ui.config('color', cmdname + '.' + status) |
|
223 | effects = ui.config('color', cmdname + '.' + status) | |
218 | if effects: |
|
224 | if effects: | |
219 | effectsmap[status] = re.split('\W+', effects) |
|
225 | effectsmap[status] = re.split('\W+', effects) |
@@ -1,606 +1,605 | |||||
1 | # |
|
1 | # | |
2 | # Copyright 21 May 2005 - (c) 2005 Jake Edge <jake@edge2.net> |
|
2 | # Copyright 21 May 2005 - (c) 2005 Jake Edge <jake@edge2.net> | |
3 | # Copyright 2005-2007 Matt Mackall <mpm@selenic.com> |
|
3 | # Copyright 2005-2007 Matt Mackall <mpm@selenic.com> | |
4 | # |
|
4 | # | |
5 | # This software may be used and distributed according to the terms |
|
5 | # This software may be used and distributed according to the terms | |
6 | # of the GNU General Public License, incorporated herein by reference. |
|
6 | # of the GNU General Public License, incorporated herein by reference. | |
7 |
|
7 | |||
8 | import os, mimetypes, re, cgi |
|
8 | import os, mimetypes, re, cgi | |
9 | import webutil |
|
9 | import webutil | |
10 | from mercurial import revlog, archival, templatefilters |
|
10 | from mercurial import revlog, archival, templatefilters | |
11 | from mercurial.node import short, hex, nullid |
|
11 | from mercurial.node import short, hex, nullid | |
12 | from mercurial.util import binary, datestr |
|
12 | from mercurial.util import binary, datestr | |
13 | from mercurial.repo import RepoError |
|
13 | from mercurial.repo import RepoError | |
14 | from common import paritygen, staticfile, get_contact, ErrorResponse |
|
14 | from common import paritygen, staticfile, get_contact, ErrorResponse | |
15 | from common import HTTP_OK, HTTP_NOT_FOUND |
|
15 | from common import HTTP_OK, HTTP_NOT_FOUND | |
16 | from mercurial import graphmod, util |
|
16 | from mercurial import graphmod, util | |
17 |
|
17 | |||
18 | # __all__ is populated with the allowed commands. Be sure to add to it if |
|
18 | # __all__ is populated with the allowed commands. Be sure to add to it if | |
19 | # you're adding a new command, or the new command won't work. |
|
19 | # you're adding a new command, or the new command won't work. | |
20 |
|
20 | |||
21 | __all__ = [ |
|
21 | __all__ = [ | |
22 | 'log', 'rawfile', 'file', 'changelog', 'shortlog', 'changeset', 'rev', |
|
22 | 'log', 'rawfile', 'file', 'changelog', 'shortlog', 'changeset', 'rev', | |
23 | 'manifest', 'tags', 'summary', 'filediff', 'diff', 'annotate', 'filelog', |
|
23 | 'manifest', 'tags', 'summary', 'filediff', 'diff', 'annotate', 'filelog', | |
24 | 'archive', 'static', 'graph', |
|
24 | 'archive', 'static', 'graph', | |
25 | ] |
|
25 | ] | |
26 |
|
26 | |||
27 | def log(web, req, tmpl): |
|
27 | def log(web, req, tmpl): | |
28 | if 'file' in req.form and req.form['file'][0]: |
|
28 | if 'file' in req.form and req.form['file'][0]: | |
29 | return filelog(web, req, tmpl) |
|
29 | return filelog(web, req, tmpl) | |
30 | else: |
|
30 | else: | |
31 | return changelog(web, req, tmpl) |
|
31 | return changelog(web, req, tmpl) | |
32 |
|
32 | |||
33 | def rawfile(web, req, tmpl): |
|
33 | def rawfile(web, req, tmpl): | |
34 | path = webutil.cleanpath(web.repo, req.form.get('file', [''])[0]) |
|
34 | path = webutil.cleanpath(web.repo, req.form.get('file', [''])[0]) | |
35 | if not path: |
|
35 | if not path: | |
36 | content = manifest(web, req, tmpl) |
|
36 | content = manifest(web, req, tmpl) | |
37 | req.respond(HTTP_OK, web.ctype) |
|
37 | req.respond(HTTP_OK, web.ctype) | |
38 | return content |
|
38 | return content | |
39 |
|
39 | |||
40 | try: |
|
40 | try: | |
41 | fctx = webutil.filectx(web.repo, req) |
|
41 | fctx = webutil.filectx(web.repo, req) | |
42 | except revlog.LookupError, inst: |
|
42 | except revlog.LookupError, inst: | |
43 | try: |
|
43 | try: | |
44 | content = manifest(web, req, tmpl) |
|
44 | content = manifest(web, req, tmpl) | |
45 | req.respond(HTTP_OK, web.ctype) |
|
45 | req.respond(HTTP_OK, web.ctype) | |
46 | return content |
|
46 | return content | |
47 | except ErrorResponse: |
|
47 | except ErrorResponse: | |
48 | raise inst |
|
48 | raise inst | |
49 |
|
49 | |||
50 | path = fctx.path() |
|
50 | path = fctx.path() | |
51 | text = fctx.data() |
|
51 | text = fctx.data() | |
52 | mt = mimetypes.guess_type(path)[0] |
|
52 | mt = mimetypes.guess_type(path)[0] | |
53 | if mt is None or binary(text): |
|
53 | if mt is None or binary(text): | |
54 | mt = mt or 'application/octet-stream' |
|
54 | mt = mt or 'application/octet-stream' | |
55 |
|
55 | |||
56 | req.respond(HTTP_OK, mt, path, len(text)) |
|
56 | req.respond(HTTP_OK, mt, path, len(text)) | |
57 | return [text] |
|
57 | return [text] | |
58 |
|
58 | |||
59 | def _filerevision(web, tmpl, fctx): |
|
59 | def _filerevision(web, tmpl, fctx): | |
60 | f = fctx.path() |
|
60 | f = fctx.path() | |
61 | text = fctx.data() |
|
61 | text = fctx.data() | |
62 | fl = fctx.filelog() |
|
62 | fl = fctx.filelog() | |
63 | n = fctx.filenode() |
|
63 | n = fctx.filenode() | |
64 | parity = paritygen(web.stripecount) |
|
64 | parity = paritygen(web.stripecount) | |
65 |
|
65 | |||
66 | if binary(text): |
|
66 | if binary(text): | |
67 | mt = mimetypes.guess_type(f)[0] or 'application/octet-stream' |
|
67 | mt = mimetypes.guess_type(f)[0] or 'application/octet-stream' | |
68 | text = '(binary:%s)' % mt |
|
68 | text = '(binary:%s)' % mt | |
69 |
|
69 | |||
70 | def lines(): |
|
70 | def lines(): | |
71 | for lineno, t in enumerate(text.splitlines(1)): |
|
71 | for lineno, t in enumerate(text.splitlines(1)): | |
72 | yield {"line": t, |
|
72 | yield {"line": t, | |
73 | "lineid": "l%d" % (lineno + 1), |
|
73 | "lineid": "l%d" % (lineno + 1), | |
74 | "linenumber": "% 6d" % (lineno + 1), |
|
74 | "linenumber": "% 6d" % (lineno + 1), | |
75 | "parity": parity.next()} |
|
75 | "parity": parity.next()} | |
76 |
|
76 | |||
77 | return tmpl("filerevision", |
|
77 | return tmpl("filerevision", | |
78 | file=f, |
|
78 | file=f, | |
79 | path=webutil.up(f), |
|
79 | path=webutil.up(f), | |
80 | text=lines(), |
|
80 | text=lines(), | |
81 | rev=fctx.rev(), |
|
81 | rev=fctx.rev(), | |
82 | node=hex(fctx.node()), |
|
82 | node=hex(fctx.node()), | |
83 | author=fctx.user(), |
|
83 | author=fctx.user(), | |
84 | date=fctx.date(), |
|
84 | date=fctx.date(), | |
85 | desc=fctx.description(), |
|
85 | desc=fctx.description(), | |
86 | branch=webutil.nodebranchnodefault(fctx), |
|
86 | branch=webutil.nodebranchnodefault(fctx), | |
87 | parent=webutil.siblings(fctx.parents()), |
|
87 | parent=webutil.siblings(fctx.parents()), | |
88 | child=webutil.siblings(fctx.children()), |
|
88 | child=webutil.siblings(fctx.children()), | |
89 | rename=webutil.renamelink(fctx), |
|
89 | rename=webutil.renamelink(fctx), | |
90 | permissions=fctx.manifest().flags(f)) |
|
90 | permissions=fctx.manifest().flags(f)) | |
91 |
|
91 | |||
92 | def file(web, req, tmpl): |
|
92 | def file(web, req, tmpl): | |
93 | path = webutil.cleanpath(web.repo, req.form.get('file', [''])[0]) |
|
93 | path = webutil.cleanpath(web.repo, req.form.get('file', [''])[0]) | |
94 | if path: |
|
94 | if not path: | |
|
95 | return manifest(web, req, tmpl) | |||
|
96 | try: | |||
|
97 | return _filerevision(web, tmpl, webutil.filectx(web.repo, req)) | |||
|
98 | except revlog.LookupError, inst: | |||
95 | try: |
|
99 | try: | |
96 | return _filerevision(web, tmpl, webutil.filectx(web.repo, req)) |
|
100 | return manifest(web, req, tmpl) | |
97 |
except |
|
101 | except ErrorResponse: | |
98 |
|
|
102 | raise inst | |
99 |
|
||||
100 | try: |
|
|||
101 | return manifest(web, req, tmpl) |
|
|||
102 | except ErrorResponse: |
|
|||
103 | raise inst |
|
|||
104 |
|
103 | |||
105 | def _search(web, tmpl, query): |
|
104 | def _search(web, tmpl, query): | |
106 |
|
105 | |||
107 | def changelist(**map): |
|
106 | def changelist(**map): | |
108 | cl = web.repo.changelog |
|
107 | cl = web.repo.changelog | |
109 | count = 0 |
|
108 | count = 0 | |
110 | qw = query.lower().split() |
|
109 | qw = query.lower().split() | |
111 |
|
110 | |||
112 | def revgen(): |
|
111 | def revgen(): | |
113 | for i in xrange(len(cl) - 1, 0, -100): |
|
112 | for i in xrange(len(cl) - 1, 0, -100): | |
114 | l = [] |
|
113 | l = [] | |
115 | for j in xrange(max(0, i - 100), i + 1): |
|
114 | for j in xrange(max(0, i - 100), i + 1): | |
116 | ctx = web.repo[j] |
|
115 | ctx = web.repo[j] | |
117 | l.append(ctx) |
|
116 | l.append(ctx) | |
118 | l.reverse() |
|
117 | l.reverse() | |
119 | for e in l: |
|
118 | for e in l: | |
120 | yield e |
|
119 | yield e | |
121 |
|
120 | |||
122 | for ctx in revgen(): |
|
121 | for ctx in revgen(): | |
123 | miss = 0 |
|
122 | miss = 0 | |
124 | for q in qw: |
|
123 | for q in qw: | |
125 | if not (q in ctx.user().lower() or |
|
124 | if not (q in ctx.user().lower() or | |
126 | q in ctx.description().lower() or |
|
125 | q in ctx.description().lower() or | |
127 | q in " ".join(ctx.files()).lower()): |
|
126 | q in " ".join(ctx.files()).lower()): | |
128 | miss = 1 |
|
127 | miss = 1 | |
129 | break |
|
128 | break | |
130 | if miss: |
|
129 | if miss: | |
131 | continue |
|
130 | continue | |
132 |
|
131 | |||
133 | count += 1 |
|
132 | count += 1 | |
134 | n = ctx.node() |
|
133 | n = ctx.node() | |
135 | showtags = webutil.showtag(web.repo, tmpl, 'changelogtag', n) |
|
134 | showtags = webutil.showtag(web.repo, tmpl, 'changelogtag', n) | |
136 |
|
135 | |||
137 | yield tmpl('searchentry', |
|
136 | yield tmpl('searchentry', | |
138 | parity=parity.next(), |
|
137 | parity=parity.next(), | |
139 | author=ctx.user(), |
|
138 | author=ctx.user(), | |
140 | parent=webutil.siblings(ctx.parents()), |
|
139 | parent=webutil.siblings(ctx.parents()), | |
141 | child=webutil.siblings(ctx.children()), |
|
140 | child=webutil.siblings(ctx.children()), | |
142 | changelogtag=showtags, |
|
141 | changelogtag=showtags, | |
143 | desc=ctx.description(), |
|
142 | desc=ctx.description(), | |
144 | date=ctx.date(), |
|
143 | date=ctx.date(), | |
145 | files=web.listfilediffs(tmpl, ctx.files(), n), |
|
144 | files=web.listfilediffs(tmpl, ctx.files(), n), | |
146 | rev=ctx.rev(), |
|
145 | rev=ctx.rev(), | |
147 | node=hex(n), |
|
146 | node=hex(n), | |
148 | tags=webutil.nodetagsdict(web.repo, n), |
|
147 | tags=webutil.nodetagsdict(web.repo, n), | |
149 | inbranch=webutil.nodeinbranch(web.repo, ctx), |
|
148 | inbranch=webutil.nodeinbranch(web.repo, ctx), | |
150 | branches=webutil.nodebranchdict(web.repo, ctx)) |
|
149 | branches=webutil.nodebranchdict(web.repo, ctx)) | |
151 |
|
150 | |||
152 | if count >= web.maxchanges: |
|
151 | if count >= web.maxchanges: | |
153 | break |
|
152 | break | |
154 |
|
153 | |||
155 | cl = web.repo.changelog |
|
154 | cl = web.repo.changelog | |
156 | parity = paritygen(web.stripecount) |
|
155 | parity = paritygen(web.stripecount) | |
157 |
|
156 | |||
158 | return tmpl('search', |
|
157 | return tmpl('search', | |
159 | query=query, |
|
158 | query=query, | |
160 | node=hex(cl.tip()), |
|
159 | node=hex(cl.tip()), | |
161 | entries=changelist, |
|
160 | entries=changelist, | |
162 | archives=web.archivelist("tip")) |
|
161 | archives=web.archivelist("tip")) | |
163 |
|
162 | |||
164 | def changelog(web, req, tmpl, shortlog = False): |
|
163 | def changelog(web, req, tmpl, shortlog = False): | |
165 | if 'node' in req.form: |
|
164 | if 'node' in req.form: | |
166 | ctx = webutil.changectx(web.repo, req) |
|
165 | ctx = webutil.changectx(web.repo, req) | |
167 | else: |
|
166 | else: | |
168 | if 'rev' in req.form: |
|
167 | if 'rev' in req.form: | |
169 | hi = req.form['rev'][0] |
|
168 | hi = req.form['rev'][0] | |
170 | else: |
|
169 | else: | |
171 | hi = len(web.repo) - 1 |
|
170 | hi = len(web.repo) - 1 | |
172 | try: |
|
171 | try: | |
173 | ctx = web.repo[hi] |
|
172 | ctx = web.repo[hi] | |
174 | except RepoError: |
|
173 | except RepoError: | |
175 | return _search(web, tmpl, hi) # XXX redirect to 404 page? |
|
174 | return _search(web, tmpl, hi) # XXX redirect to 404 page? | |
176 |
|
175 | |||
177 | def changelist(limit=0, **map): |
|
176 | def changelist(limit=0, **map): | |
178 | cl = web.repo.changelog |
|
177 | cl = web.repo.changelog | |
179 | l = [] # build a list in forward order for efficiency |
|
178 | l = [] # build a list in forward order for efficiency | |
180 | for i in xrange(start, end): |
|
179 | for i in xrange(start, end): | |
181 | ctx = web.repo[i] |
|
180 | ctx = web.repo[i] | |
182 | n = ctx.node() |
|
181 | n = ctx.node() | |
183 | showtags = webutil.showtag(web.repo, tmpl, 'changelogtag', n) |
|
182 | showtags = webutil.showtag(web.repo, tmpl, 'changelogtag', n) | |
184 |
|
183 | |||
185 | l.insert(0, {"parity": parity.next(), |
|
184 | l.insert(0, {"parity": parity.next(), | |
186 | "author": ctx.user(), |
|
185 | "author": ctx.user(), | |
187 | "parent": webutil.siblings(ctx.parents(), i - 1), |
|
186 | "parent": webutil.siblings(ctx.parents(), i - 1), | |
188 | "child": webutil.siblings(ctx.children(), i + 1), |
|
187 | "child": webutil.siblings(ctx.children(), i + 1), | |
189 | "changelogtag": showtags, |
|
188 | "changelogtag": showtags, | |
190 | "desc": ctx.description(), |
|
189 | "desc": ctx.description(), | |
191 | "date": ctx.date(), |
|
190 | "date": ctx.date(), | |
192 | "files": web.listfilediffs(tmpl, ctx.files(), n), |
|
191 | "files": web.listfilediffs(tmpl, ctx.files(), n), | |
193 | "rev": i, |
|
192 | "rev": i, | |
194 | "node": hex(n), |
|
193 | "node": hex(n), | |
195 | "tags": webutil.nodetagsdict(web.repo, n), |
|
194 | "tags": webutil.nodetagsdict(web.repo, n), | |
196 | "inbranch": webutil.nodeinbranch(web.repo, ctx), |
|
195 | "inbranch": webutil.nodeinbranch(web.repo, ctx), | |
197 | "branches": webutil.nodebranchdict(web.repo, ctx) |
|
196 | "branches": webutil.nodebranchdict(web.repo, ctx) | |
198 | }) |
|
197 | }) | |
199 |
|
198 | |||
200 | if limit > 0: |
|
199 | if limit > 0: | |
201 | l = l[:limit] |
|
200 | l = l[:limit] | |
202 |
|
201 | |||
203 | for e in l: |
|
202 | for e in l: | |
204 | yield e |
|
203 | yield e | |
205 |
|
204 | |||
206 | maxchanges = shortlog and web.maxshortchanges or web.maxchanges |
|
205 | maxchanges = shortlog and web.maxshortchanges or web.maxchanges | |
207 | cl = web.repo.changelog |
|
206 | cl = web.repo.changelog | |
208 | count = len(cl) |
|
207 | count = len(cl) | |
209 | pos = ctx.rev() |
|
208 | pos = ctx.rev() | |
210 | start = max(0, pos - maxchanges + 1) |
|
209 | start = max(0, pos - maxchanges + 1) | |
211 | end = min(count, start + maxchanges) |
|
210 | end = min(count, start + maxchanges) | |
212 | pos = end - 1 |
|
211 | pos = end - 1 | |
213 | parity = paritygen(web.stripecount, offset=start-end) |
|
212 | parity = paritygen(web.stripecount, offset=start-end) | |
214 |
|
213 | |||
215 | changenav = webutil.revnavgen(pos, maxchanges, count, web.repo.changectx) |
|
214 | changenav = webutil.revnavgen(pos, maxchanges, count, web.repo.changectx) | |
216 |
|
215 | |||
217 | return tmpl(shortlog and 'shortlog' or 'changelog', |
|
216 | return tmpl(shortlog and 'shortlog' or 'changelog', | |
218 | changenav=changenav, |
|
217 | changenav=changenav, | |
219 | node=hex(ctx.node()), |
|
218 | node=hex(ctx.node()), | |
220 | rev=pos, changesets=count, |
|
219 | rev=pos, changesets=count, | |
221 | entries=lambda **x: changelist(limit=0,**x), |
|
220 | entries=lambda **x: changelist(limit=0,**x), | |
222 | latestentry=lambda **x: changelist(limit=1,**x), |
|
221 | latestentry=lambda **x: changelist(limit=1,**x), | |
223 | archives=web.archivelist("tip")) |
|
222 | archives=web.archivelist("tip")) | |
224 |
|
223 | |||
225 | def shortlog(web, req, tmpl): |
|
224 | def shortlog(web, req, tmpl): | |
226 | return changelog(web, req, tmpl, shortlog = True) |
|
225 | return changelog(web, req, tmpl, shortlog = True) | |
227 |
|
226 | |||
228 | def changeset(web, req, tmpl): |
|
227 | def changeset(web, req, tmpl): | |
229 | ctx = webutil.changectx(web.repo, req) |
|
228 | ctx = webutil.changectx(web.repo, req) | |
230 | n = ctx.node() |
|
229 | n = ctx.node() | |
231 | showtags = webutil.showtag(web.repo, tmpl, 'changesettag', n) |
|
230 | showtags = webutil.showtag(web.repo, tmpl, 'changesettag', n) | |
232 | parents = ctx.parents() |
|
231 | parents = ctx.parents() | |
233 | p1 = parents[0].node() |
|
232 | p1 = parents[0].node() | |
234 |
|
233 | |||
235 | files = [] |
|
234 | files = [] | |
236 | parity = paritygen(web.stripecount) |
|
235 | parity = paritygen(web.stripecount) | |
237 | for f in ctx.files(): |
|
236 | for f in ctx.files(): | |
238 | files.append(tmpl("filenodelink", |
|
237 | files.append(tmpl("filenodelink", | |
239 | node=hex(n), file=f, |
|
238 | node=hex(n), file=f, | |
240 | parity=parity.next())) |
|
239 | parity=parity.next())) | |
241 |
|
240 | |||
242 | diffs = web.diff(tmpl, p1, n, None) |
|
241 | diffs = web.diff(tmpl, p1, n, None) | |
243 | return tmpl('changeset', |
|
242 | return tmpl('changeset', | |
244 | diff=diffs, |
|
243 | diff=diffs, | |
245 | rev=ctx.rev(), |
|
244 | rev=ctx.rev(), | |
246 | node=hex(n), |
|
245 | node=hex(n), | |
247 | parent=webutil.siblings(parents), |
|
246 | parent=webutil.siblings(parents), | |
248 | child=webutil.siblings(ctx.children()), |
|
247 | child=webutil.siblings(ctx.children()), | |
249 | changesettag=showtags, |
|
248 | changesettag=showtags, | |
250 | author=ctx.user(), |
|
249 | author=ctx.user(), | |
251 | desc=ctx.description(), |
|
250 | desc=ctx.description(), | |
252 | date=ctx.date(), |
|
251 | date=ctx.date(), | |
253 | files=files, |
|
252 | files=files, | |
254 | archives=web.archivelist(hex(n)), |
|
253 | archives=web.archivelist(hex(n)), | |
255 | tags=webutil.nodetagsdict(web.repo, n), |
|
254 | tags=webutil.nodetagsdict(web.repo, n), | |
256 | branch=webutil.nodebranchnodefault(ctx), |
|
255 | branch=webutil.nodebranchnodefault(ctx), | |
257 | inbranch=webutil.nodeinbranch(web.repo, ctx), |
|
256 | inbranch=webutil.nodeinbranch(web.repo, ctx), | |
258 | branches=webutil.nodebranchdict(web.repo, ctx)) |
|
257 | branches=webutil.nodebranchdict(web.repo, ctx)) | |
259 |
|
258 | |||
260 | rev = changeset |
|
259 | rev = changeset | |
261 |
|
260 | |||
262 | def manifest(web, req, tmpl): |
|
261 | def manifest(web, req, tmpl): | |
263 | ctx = webutil.changectx(web.repo, req) |
|
262 | ctx = webutil.changectx(web.repo, req) | |
264 | path = webutil.cleanpath(web.repo, req.form.get('file', [''])[0]) |
|
263 | path = webutil.cleanpath(web.repo, req.form.get('file', [''])[0]) | |
265 | mf = ctx.manifest() |
|
264 | mf = ctx.manifest() | |
266 | node = ctx.node() |
|
265 | node = ctx.node() | |
267 |
|
266 | |||
268 | files = {} |
|
267 | files = {} | |
269 | parity = paritygen(web.stripecount) |
|
268 | parity = paritygen(web.stripecount) | |
270 |
|
269 | |||
271 | if path and path[-1] != "/": |
|
270 | if path and path[-1] != "/": | |
272 | path += "/" |
|
271 | path += "/" | |
273 | l = len(path) |
|
272 | l = len(path) | |
274 | abspath = "/" + path |
|
273 | abspath = "/" + path | |
275 |
|
274 | |||
276 | for f, n in mf.items(): |
|
275 | for f, n in mf.items(): | |
277 | if f[:l] != path: |
|
276 | if f[:l] != path: | |
278 | continue |
|
277 | continue | |
279 | remain = f[l:] |
|
278 | remain = f[l:] | |
280 | if "/" in remain: |
|
279 | if "/" in remain: | |
281 | short = remain[:remain.index("/") + 1] # bleah |
|
280 | short = remain[:remain.index("/") + 1] # bleah | |
282 | files[short] = (f, None) |
|
281 | files[short] = (f, None) | |
283 | else: |
|
282 | else: | |
284 | short = os.path.basename(remain) |
|
283 | short = os.path.basename(remain) | |
285 | files[short] = (f, n) |
|
284 | files[short] = (f, n) | |
286 |
|
285 | |||
287 | if not files: |
|
286 | if not files: | |
288 | raise ErrorResponse(HTTP_NOT_FOUND, 'path not found: ' + path) |
|
287 | raise ErrorResponse(HTTP_NOT_FOUND, 'path not found: ' + path) | |
289 |
|
288 | |||
290 | def filelist(**map): |
|
289 | def filelist(**map): | |
291 | for f in util.sort(files): |
|
290 | for f in util.sort(files): | |
292 | full, fnode = files[f] |
|
291 | full, fnode = files[f] | |
293 | if not fnode: |
|
292 | if not fnode: | |
294 | continue |
|
293 | continue | |
295 |
|
294 | |||
296 | fctx = ctx.filectx(full) |
|
295 | fctx = ctx.filectx(full) | |
297 | yield {"file": full, |
|
296 | yield {"file": full, | |
298 | "parity": parity.next(), |
|
297 | "parity": parity.next(), | |
299 | "basename": f, |
|
298 | "basename": f, | |
300 | "date": fctx.date(), |
|
299 | "date": fctx.date(), | |
301 | "size": fctx.size(), |
|
300 | "size": fctx.size(), | |
302 | "permissions": mf.flags(full)} |
|
301 | "permissions": mf.flags(full)} | |
303 |
|
302 | |||
304 | def dirlist(**map): |
|
303 | def dirlist(**map): | |
305 | for f in util.sort(files): |
|
304 | for f in util.sort(files): | |
306 | full, fnode = files[f] |
|
305 | full, fnode = files[f] | |
307 | if fnode: |
|
306 | if fnode: | |
308 | continue |
|
307 | continue | |
309 |
|
308 | |||
310 | yield {"parity": parity.next(), |
|
309 | yield {"parity": parity.next(), | |
311 | "path": "%s%s" % (abspath, f), |
|
310 | "path": "%s%s" % (abspath, f), | |
312 | "basename": f[:-1]} |
|
311 | "basename": f[:-1]} | |
313 |
|
312 | |||
314 | return tmpl("manifest", |
|
313 | return tmpl("manifest", | |
315 | rev=ctx.rev(), |
|
314 | rev=ctx.rev(), | |
316 | node=hex(node), |
|
315 | node=hex(node), | |
317 | path=abspath, |
|
316 | path=abspath, | |
318 | up=webutil.up(abspath), |
|
317 | up=webutil.up(abspath), | |
319 | upparity=parity.next(), |
|
318 | upparity=parity.next(), | |
320 | fentries=filelist, |
|
319 | fentries=filelist, | |
321 | dentries=dirlist, |
|
320 | dentries=dirlist, | |
322 | archives=web.archivelist(hex(node)), |
|
321 | archives=web.archivelist(hex(node)), | |
323 | tags=webutil.nodetagsdict(web.repo, node), |
|
322 | tags=webutil.nodetagsdict(web.repo, node), | |
324 | inbranch=webutil.nodeinbranch(web.repo, ctx), |
|
323 | inbranch=webutil.nodeinbranch(web.repo, ctx), | |
325 | branches=webutil.nodebranchdict(web.repo, ctx)) |
|
324 | branches=webutil.nodebranchdict(web.repo, ctx)) | |
326 |
|
325 | |||
327 | def tags(web, req, tmpl): |
|
326 | def tags(web, req, tmpl): | |
328 | i = web.repo.tagslist() |
|
327 | i = web.repo.tagslist() | |
329 | i.reverse() |
|
328 | i.reverse() | |
330 | parity = paritygen(web.stripecount) |
|
329 | parity = paritygen(web.stripecount) | |
331 |
|
330 | |||
332 | def entries(notip=False,limit=0, **map): |
|
331 | def entries(notip=False,limit=0, **map): | |
333 | count = 0 |
|
332 | count = 0 | |
334 | for k, n in i: |
|
333 | for k, n in i: | |
335 | if notip and k == "tip": |
|
334 | if notip and k == "tip": | |
336 | continue |
|
335 | continue | |
337 | if limit > 0 and count >= limit: |
|
336 | if limit > 0 and count >= limit: | |
338 | continue |
|
337 | continue | |
339 | count = count + 1 |
|
338 | count = count + 1 | |
340 | yield {"parity": parity.next(), |
|
339 | yield {"parity": parity.next(), | |
341 | "tag": k, |
|
340 | "tag": k, | |
342 | "date": web.repo[n].date(), |
|
341 | "date": web.repo[n].date(), | |
343 | "node": hex(n)} |
|
342 | "node": hex(n)} | |
344 |
|
343 | |||
345 | return tmpl("tags", |
|
344 | return tmpl("tags", | |
346 | node=hex(web.repo.changelog.tip()), |
|
345 | node=hex(web.repo.changelog.tip()), | |
347 | entries=lambda **x: entries(False,0, **x), |
|
346 | entries=lambda **x: entries(False,0, **x), | |
348 | entriesnotip=lambda **x: entries(True,0, **x), |
|
347 | entriesnotip=lambda **x: entries(True,0, **x), | |
349 | latestentry=lambda **x: entries(True,1, **x)) |
|
348 | latestentry=lambda **x: entries(True,1, **x)) | |
350 |
|
349 | |||
351 | def summary(web, req, tmpl): |
|
350 | def summary(web, req, tmpl): | |
352 | i = web.repo.tagslist() |
|
351 | i = web.repo.tagslist() | |
353 | i.reverse() |
|
352 | i.reverse() | |
354 |
|
353 | |||
355 | def tagentries(**map): |
|
354 | def tagentries(**map): | |
356 | parity = paritygen(web.stripecount) |
|
355 | parity = paritygen(web.stripecount) | |
357 | count = 0 |
|
356 | count = 0 | |
358 | for k, n in i: |
|
357 | for k, n in i: | |
359 | if k == "tip": # skip tip |
|
358 | if k == "tip": # skip tip | |
360 | continue |
|
359 | continue | |
361 |
|
360 | |||
362 | count += 1 |
|
361 | count += 1 | |
363 | if count > 10: # limit to 10 tags |
|
362 | if count > 10: # limit to 10 tags | |
364 | break |
|
363 | break | |
365 |
|
364 | |||
366 | yield tmpl("tagentry", |
|
365 | yield tmpl("tagentry", | |
367 | parity=parity.next(), |
|
366 | parity=parity.next(), | |
368 | tag=k, |
|
367 | tag=k, | |
369 | node=hex(n), |
|
368 | node=hex(n), | |
370 | date=web.repo[n].date()) |
|
369 | date=web.repo[n].date()) | |
371 |
|
370 | |||
372 | def branches(**map): |
|
371 | def branches(**map): | |
373 | parity = paritygen(web.stripecount) |
|
372 | parity = paritygen(web.stripecount) | |
374 |
|
373 | |||
375 | b = web.repo.branchtags() |
|
374 | b = web.repo.branchtags() | |
376 | l = [(-web.repo.changelog.rev(n), n, t) for t, n in b.items()] |
|
375 | l = [(-web.repo.changelog.rev(n), n, t) for t, n in b.items()] | |
377 | for r,n,t in util.sort(l): |
|
376 | for r,n,t in util.sort(l): | |
378 | yield {'parity': parity.next(), |
|
377 | yield {'parity': parity.next(), | |
379 | 'branch': t, |
|
378 | 'branch': t, | |
380 | 'node': hex(n), |
|
379 | 'node': hex(n), | |
381 | 'date': web.repo[n].date()} |
|
380 | 'date': web.repo[n].date()} | |
382 |
|
381 | |||
383 | def changelist(**map): |
|
382 | def changelist(**map): | |
384 | parity = paritygen(web.stripecount, offset=start-end) |
|
383 | parity = paritygen(web.stripecount, offset=start-end) | |
385 | l = [] # build a list in forward order for efficiency |
|
384 | l = [] # build a list in forward order for efficiency | |
386 | for i in xrange(start, end): |
|
385 | for i in xrange(start, end): | |
387 | ctx = web.repo[i] |
|
386 | ctx = web.repo[i] | |
388 | n = ctx.node() |
|
387 | n = ctx.node() | |
389 | hn = hex(n) |
|
388 | hn = hex(n) | |
390 |
|
389 | |||
391 | l.insert(0, tmpl( |
|
390 | l.insert(0, tmpl( | |
392 | 'shortlogentry', |
|
391 | 'shortlogentry', | |
393 | parity=parity.next(), |
|
392 | parity=parity.next(), | |
394 | author=ctx.user(), |
|
393 | author=ctx.user(), | |
395 | desc=ctx.description(), |
|
394 | desc=ctx.description(), | |
396 | date=ctx.date(), |
|
395 | date=ctx.date(), | |
397 | rev=i, |
|
396 | rev=i, | |
398 | node=hn, |
|
397 | node=hn, | |
399 | tags=webutil.nodetagsdict(web.repo, n), |
|
398 | tags=webutil.nodetagsdict(web.repo, n), | |
400 | inbranch=webutil.nodeinbranch(web.repo, ctx), |
|
399 | inbranch=webutil.nodeinbranch(web.repo, ctx), | |
401 | branches=webutil.nodebranchdict(web.repo, ctx))) |
|
400 | branches=webutil.nodebranchdict(web.repo, ctx))) | |
402 |
|
401 | |||
403 | yield l |
|
402 | yield l | |
404 |
|
403 | |||
405 | cl = web.repo.changelog |
|
404 | cl = web.repo.changelog | |
406 | count = len(cl) |
|
405 | count = len(cl) | |
407 | start = max(0, count - web.maxchanges) |
|
406 | start = max(0, count - web.maxchanges) | |
408 | end = min(count, start + web.maxchanges) |
|
407 | end = min(count, start + web.maxchanges) | |
409 |
|
408 | |||
410 | return tmpl("summary", |
|
409 | return tmpl("summary", | |
411 | desc=web.config("web", "description", "unknown"), |
|
410 | desc=web.config("web", "description", "unknown"), | |
412 | owner=get_contact(web.config) or "unknown", |
|
411 | owner=get_contact(web.config) or "unknown", | |
413 | lastchange=cl.read(cl.tip())[2], |
|
412 | lastchange=cl.read(cl.tip())[2], | |
414 | tags=tagentries, |
|
413 | tags=tagentries, | |
415 | branches=branches, |
|
414 | branches=branches, | |
416 | shortlog=changelist, |
|
415 | shortlog=changelist, | |
417 | node=hex(cl.tip()), |
|
416 | node=hex(cl.tip()), | |
418 | archives=web.archivelist("tip")) |
|
417 | archives=web.archivelist("tip")) | |
419 |
|
418 | |||
420 | def filediff(web, req, tmpl): |
|
419 | def filediff(web, req, tmpl): | |
421 | fctx = webutil.filectx(web.repo, req) |
|
420 | fctx = webutil.filectx(web.repo, req) | |
422 | n = fctx.node() |
|
421 | n = fctx.node() | |
423 | path = fctx.path() |
|
422 | path = fctx.path() | |
424 | parents = fctx.parents() |
|
423 | parents = fctx.parents() | |
425 | p1 = parents and parents[0].node() or nullid |
|
424 | p1 = parents and parents[0].node() or nullid | |
426 |
|
425 | |||
427 | diffs = web.diff(tmpl, p1, n, [path]) |
|
426 | diffs = web.diff(tmpl, p1, n, [path]) | |
428 | return tmpl("filediff", |
|
427 | return tmpl("filediff", | |
429 | file=path, |
|
428 | file=path, | |
430 | node=hex(n), |
|
429 | node=hex(n), | |
431 | rev=fctx.rev(), |
|
430 | rev=fctx.rev(), | |
432 | date=fctx.date(), |
|
431 | date=fctx.date(), | |
433 | desc=fctx.description(), |
|
432 | desc=fctx.description(), | |
434 | author=fctx.user(), |
|
433 | author=fctx.user(), | |
435 | rename=webutil.renamelink(fctx), |
|
434 | rename=webutil.renamelink(fctx), | |
436 | branch=webutil.nodebranchnodefault(fctx), |
|
435 | branch=webutil.nodebranchnodefault(fctx), | |
437 | parent=webutil.siblings(parents), |
|
436 | parent=webutil.siblings(parents), | |
438 | child=webutil.siblings(fctx.children()), |
|
437 | child=webutil.siblings(fctx.children()), | |
439 | diff=diffs) |
|
438 | diff=diffs) | |
440 |
|
439 | |||
441 | diff = filediff |
|
440 | diff = filediff | |
442 |
|
441 | |||
443 | def annotate(web, req, tmpl): |
|
442 | def annotate(web, req, tmpl): | |
444 | fctx = webutil.filectx(web.repo, req) |
|
443 | fctx = webutil.filectx(web.repo, req) | |
445 | f = fctx.path() |
|
444 | f = fctx.path() | |
446 | n = fctx.filenode() |
|
445 | n = fctx.filenode() | |
447 | fl = fctx.filelog() |
|
446 | fl = fctx.filelog() | |
448 | parity = paritygen(web.stripecount) |
|
447 | parity = paritygen(web.stripecount) | |
449 |
|
448 | |||
450 | def annotate(**map): |
|
449 | def annotate(**map): | |
451 | last = None |
|
450 | last = None | |
452 | if binary(fctx.data()): |
|
451 | if binary(fctx.data()): | |
453 | mt = (mimetypes.guess_type(fctx.path())[0] |
|
452 | mt = (mimetypes.guess_type(fctx.path())[0] | |
454 | or 'application/octet-stream') |
|
453 | or 'application/octet-stream') | |
455 | lines = enumerate([((fctx.filectx(fctx.filerev()), 1), |
|
454 | lines = enumerate([((fctx.filectx(fctx.filerev()), 1), | |
456 | '(binary:%s)' % mt)]) |
|
455 | '(binary:%s)' % mt)]) | |
457 | else: |
|
456 | else: | |
458 | lines = enumerate(fctx.annotate(follow=True, linenumber=True)) |
|
457 | lines = enumerate(fctx.annotate(follow=True, linenumber=True)) | |
459 | for lineno, ((f, targetline), l) in lines: |
|
458 | for lineno, ((f, targetline), l) in lines: | |
460 | fnode = f.filenode() |
|
459 | fnode = f.filenode() | |
461 |
|
460 | |||
462 | if last != fnode: |
|
461 | if last != fnode: | |
463 | last = fnode |
|
462 | last = fnode | |
464 |
|
463 | |||
465 | yield {"parity": parity.next(), |
|
464 | yield {"parity": parity.next(), | |
466 | "node": hex(f.node()), |
|
465 | "node": hex(f.node()), | |
467 | "rev": f.rev(), |
|
466 | "rev": f.rev(), | |
468 | "author": f.user(), |
|
467 | "author": f.user(), | |
469 | "desc": f.description(), |
|
468 | "desc": f.description(), | |
470 | "file": f.path(), |
|
469 | "file": f.path(), | |
471 | "targetline": targetline, |
|
470 | "targetline": targetline, | |
472 | "line": l, |
|
471 | "line": l, | |
473 | "lineid": "l%d" % (lineno + 1), |
|
472 | "lineid": "l%d" % (lineno + 1), | |
474 | "linenumber": "% 6d" % (lineno + 1)} |
|
473 | "linenumber": "% 6d" % (lineno + 1)} | |
475 |
|
474 | |||
476 | return tmpl("fileannotate", |
|
475 | return tmpl("fileannotate", | |
477 | file=f, |
|
476 | file=f, | |
478 | annotate=annotate, |
|
477 | annotate=annotate, | |
479 | path=webutil.up(f), |
|
478 | path=webutil.up(f), | |
480 | rev=fctx.rev(), |
|
479 | rev=fctx.rev(), | |
481 | node=hex(fctx.node()), |
|
480 | node=hex(fctx.node()), | |
482 | author=fctx.user(), |
|
481 | author=fctx.user(), | |
483 | date=fctx.date(), |
|
482 | date=fctx.date(), | |
484 | desc=fctx.description(), |
|
483 | desc=fctx.description(), | |
485 | rename=webutil.renamelink(fctx), |
|
484 | rename=webutil.renamelink(fctx), | |
486 | branch=webutil.nodebranchnodefault(fctx), |
|
485 | branch=webutil.nodebranchnodefault(fctx), | |
487 | parent=webutil.siblings(fctx.parents()), |
|
486 | parent=webutil.siblings(fctx.parents()), | |
488 | child=webutil.siblings(fctx.children()), |
|
487 | child=webutil.siblings(fctx.children()), | |
489 | permissions=fctx.manifest().flags(f)) |
|
488 | permissions=fctx.manifest().flags(f)) | |
490 |
|
489 | |||
491 | def filelog(web, req, tmpl): |
|
490 | def filelog(web, req, tmpl): | |
492 | fctx = webutil.filectx(web.repo, req) |
|
491 | fctx = webutil.filectx(web.repo, req) | |
493 | f = fctx.path() |
|
492 | f = fctx.path() | |
494 | fl = fctx.filelog() |
|
493 | fl = fctx.filelog() | |
495 | count = len(fl) |
|
494 | count = len(fl) | |
496 | pagelen = web.maxshortchanges |
|
495 | pagelen = web.maxshortchanges | |
497 | pos = fctx.filerev() |
|
496 | pos = fctx.filerev() | |
498 | start = max(0, pos - pagelen + 1) |
|
497 | start = max(0, pos - pagelen + 1) | |
499 | end = min(count, start + pagelen) |
|
498 | end = min(count, start + pagelen) | |
500 | pos = end - 1 |
|
499 | pos = end - 1 | |
501 | parity = paritygen(web.stripecount, offset=start-end) |
|
500 | parity = paritygen(web.stripecount, offset=start-end) | |
502 |
|
501 | |||
503 | def entries(limit=0, **map): |
|
502 | def entries(limit=0, **map): | |
504 | l = [] |
|
503 | l = [] | |
505 |
|
504 | |||
506 | for i in xrange(start, end): |
|
505 | for i in xrange(start, end): | |
507 | ctx = fctx.filectx(i) |
|
506 | ctx = fctx.filectx(i) | |
508 | n = fl.node(i) |
|
507 | n = fl.node(i) | |
509 |
|
508 | |||
510 | l.insert(0, {"parity": parity.next(), |
|
509 | l.insert(0, {"parity": parity.next(), | |
511 | "filerev": i, |
|
510 | "filerev": i, | |
512 | "file": f, |
|
511 | "file": f, | |
513 | "node": hex(ctx.node()), |
|
512 | "node": hex(ctx.node()), | |
514 | "author": ctx.user(), |
|
513 | "author": ctx.user(), | |
515 | "date": ctx.date(), |
|
514 | "date": ctx.date(), | |
516 | "rename": webutil.renamelink(fctx), |
|
515 | "rename": webutil.renamelink(fctx), | |
517 | "parent": webutil.siblings(fctx.parents()), |
|
516 | "parent": webutil.siblings(fctx.parents()), | |
518 | "child": webutil.siblings(fctx.children()), |
|
517 | "child": webutil.siblings(fctx.children()), | |
519 | "desc": ctx.description()}) |
|
518 | "desc": ctx.description()}) | |
520 |
|
519 | |||
521 | if limit > 0: |
|
520 | if limit > 0: | |
522 | l = l[:limit] |
|
521 | l = l[:limit] | |
523 |
|
522 | |||
524 | for e in l: |
|
523 | for e in l: | |
525 | yield e |
|
524 | yield e | |
526 |
|
525 | |||
527 | nodefunc = lambda x: fctx.filectx(fileid=x) |
|
526 | nodefunc = lambda x: fctx.filectx(fileid=x) | |
528 | nav = webutil.revnavgen(pos, pagelen, count, nodefunc) |
|
527 | nav = webutil.revnavgen(pos, pagelen, count, nodefunc) | |
529 | return tmpl("filelog", file=f, node=hex(fctx.node()), nav=nav, |
|
528 | return tmpl("filelog", file=f, node=hex(fctx.node()), nav=nav, | |
530 | entries=lambda **x: entries(limit=0, **x), |
|
529 | entries=lambda **x: entries(limit=0, **x), | |
531 | latestentry=lambda **x: entries(limit=1, **x)) |
|
530 | latestentry=lambda **x: entries(limit=1, **x)) | |
532 |
|
531 | |||
533 |
|
532 | |||
534 | def archive(web, req, tmpl): |
|
533 | def archive(web, req, tmpl): | |
535 | type_ = req.form.get('type', [None])[0] |
|
534 | type_ = req.form.get('type', [None])[0] | |
536 | allowed = web.configlist("web", "allow_archive") |
|
535 | allowed = web.configlist("web", "allow_archive") | |
537 | key = req.form['node'][0] |
|
536 | key = req.form['node'][0] | |
538 |
|
537 | |||
539 | if not (type_ in web.archives and (type_ in allowed or |
|
538 | if not (type_ in web.archives and (type_ in allowed or | |
540 | web.configbool("web", "allow" + type_, False))): |
|
539 | web.configbool("web", "allow" + type_, False))): | |
541 | msg = 'Unsupported archive type: %s' % type_ |
|
540 | msg = 'Unsupported archive type: %s' % type_ | |
542 | raise ErrorResponse(HTTP_NOT_FOUND, msg) |
|
541 | raise ErrorResponse(HTTP_NOT_FOUND, msg) | |
543 |
|
542 | |||
544 | reponame = re.sub(r"\W+", "-", os.path.basename(web.reponame)) |
|
543 | reponame = re.sub(r"\W+", "-", os.path.basename(web.reponame)) | |
545 | cnode = web.repo.lookup(key) |
|
544 | cnode = web.repo.lookup(key) | |
546 | arch_version = key |
|
545 | arch_version = key | |
547 | if cnode == key or key == 'tip': |
|
546 | if cnode == key or key == 'tip': | |
548 | arch_version = short(cnode) |
|
547 | arch_version = short(cnode) | |
549 | name = "%s-%s" % (reponame, arch_version) |
|
548 | name = "%s-%s" % (reponame, arch_version) | |
550 | mimetype, artype, extension, encoding = web.archive_specs[type_] |
|
549 | mimetype, artype, extension, encoding = web.archive_specs[type_] | |
551 | headers = [ |
|
550 | headers = [ | |
552 | ('Content-Type', mimetype), |
|
551 | ('Content-Type', mimetype), | |
553 | ('Content-Disposition', 'attachment; filename=%s%s' % (name, extension)) |
|
552 | ('Content-Disposition', 'attachment; filename=%s%s' % (name, extension)) | |
554 | ] |
|
553 | ] | |
555 | if encoding: |
|
554 | if encoding: | |
556 | headers.append(('Content-Encoding', encoding)) |
|
555 | headers.append(('Content-Encoding', encoding)) | |
557 | req.header(headers) |
|
556 | req.header(headers) | |
558 | req.respond(HTTP_OK) |
|
557 | req.respond(HTTP_OK) | |
559 | archival.archive(web.repo, req, cnode, artype, prefix=name) |
|
558 | archival.archive(web.repo, req, cnode, artype, prefix=name) | |
560 | return [] |
|
559 | return [] | |
561 |
|
560 | |||
562 |
|
561 | |||
563 | def static(web, req, tmpl): |
|
562 | def static(web, req, tmpl): | |
564 | fname = req.form['file'][0] |
|
563 | fname = req.form['file'][0] | |
565 | # a repo owner may set web.static in .hg/hgrc to get any file |
|
564 | # a repo owner may set web.static in .hg/hgrc to get any file | |
566 | # readable by the user running the CGI script |
|
565 | # readable by the user running the CGI script | |
567 | static = web.config("web", "static", |
|
566 | static = web.config("web", "static", | |
568 | os.path.join(web.templatepath, "static"), |
|
567 | os.path.join(web.templatepath, "static"), | |
569 | untrusted=False) |
|
568 | untrusted=False) | |
570 | return [staticfile(static, fname, req)] |
|
569 | return [staticfile(static, fname, req)] | |
571 |
|
570 | |||
572 | def graph(web, req, tmpl): |
|
571 | def graph(web, req, tmpl): | |
573 | rev = webutil.changectx(web.repo, req).rev() |
|
572 | rev = webutil.changectx(web.repo, req).rev() | |
574 | bg_height = 39 |
|
573 | bg_height = 39 | |
575 |
|
574 | |||
576 | max_rev = len(web.repo) - 1 |
|
575 | max_rev = len(web.repo) - 1 | |
577 | revcount = min(max_rev, int(req.form.get('revcount', [25])[0])) |
|
576 | revcount = min(max_rev, int(req.form.get('revcount', [25])[0])) | |
578 | revnode = web.repo.changelog.node(rev) |
|
577 | revnode = web.repo.changelog.node(rev) | |
579 | revnode_hex = hex(revnode) |
|
578 | revnode_hex = hex(revnode) | |
580 | uprev = min(max_rev, rev + revcount) |
|
579 | uprev = min(max_rev, rev + revcount) | |
581 | downrev = max(0, rev - revcount) |
|
580 | downrev = max(0, rev - revcount) | |
582 | lessrev = max(0, rev - revcount / 2) |
|
581 | lessrev = max(0, rev - revcount / 2) | |
583 |
|
582 | |||
584 | maxchanges = web.maxshortchanges or web.maxchanges |
|
583 | maxchanges = web.maxshortchanges or web.maxchanges | |
585 | count = len(web.repo) |
|
584 | count = len(web.repo) | |
586 | changenav = webutil.revnavgen(rev, maxchanges, count, web.repo.changectx) |
|
585 | changenav = webutil.revnavgen(rev, maxchanges, count, web.repo.changectx) | |
587 |
|
586 | |||
588 | tree = list(graphmod.graph(web.repo, rev, rev - revcount)) |
|
587 | tree = list(graphmod.graph(web.repo, rev, rev - revcount)) | |
589 | canvasheight = (len(tree) + 1) * bg_height - 27; |
|
588 | canvasheight = (len(tree) + 1) * bg_height - 27; | |
590 |
|
589 | |||
591 | data = [] |
|
590 | data = [] | |
592 | for i, (ctx, vtx, edges) in enumerate(tree): |
|
591 | for i, (ctx, vtx, edges) in enumerate(tree): | |
593 | node = short(ctx.node()) |
|
592 | node = short(ctx.node()) | |
594 | age = templatefilters.age(ctx.date()) |
|
593 | age = templatefilters.age(ctx.date()) | |
595 | desc = templatefilters.firstline(ctx.description()) |
|
594 | desc = templatefilters.firstline(ctx.description()) | |
596 | desc = cgi.escape(desc) |
|
595 | desc = cgi.escape(desc) | |
597 | user = cgi.escape(templatefilters.person(ctx.user())) |
|
596 | user = cgi.escape(templatefilters.person(ctx.user())) | |
598 | branch = ctx.branch() |
|
597 | branch = ctx.branch() | |
599 | branch = branch, web.repo.branchtags().get(branch) == ctx.node() |
|
598 | branch = branch, web.repo.branchtags().get(branch) == ctx.node() | |
600 | data.append((node, vtx, edges, desc, user, age, branch, ctx.tags())) |
|
599 | data.append((node, vtx, edges, desc, user, age, branch, ctx.tags())) | |
601 |
|
600 | |||
602 | return tmpl('graph', rev=rev, revcount=revcount, uprev=uprev, |
|
601 | return tmpl('graph', rev=rev, revcount=revcount, uprev=uprev, | |
603 | lessrev=lessrev, revcountmore=revcount and 2 * revcount or 1, |
|
602 | lessrev=lessrev, revcountmore=revcount and 2 * revcount or 1, | |
604 | revcountless=revcount / 2, downrev=downrev, |
|
603 | revcountless=revcount / 2, downrev=downrev, | |
605 | canvasheight=canvasheight, bg_height=bg_height, |
|
604 | canvasheight=canvasheight, bg_height=bg_height, | |
606 | jsdata=data, node=revnode_hex, changenav=changenav) |
|
605 | jsdata=data, node=revnode_hex, changenav=changenav) |
General Comments 0
You need to be logged in to leave comments.
Login now