annotate rhodecode/controllers/files.py @ 560:3072935bdeed

rewrote whoosh indexing to run internal repository.walk() instead of filesystem. Disabled default hg update hook (not needed since whoosh is not dependent on file system files to index)
author Marcin Kuzminski <marcin@python-works.com>
date Sat, 09 Oct 2010 00:22:19 +0200
parents 1e757ac98988
children 7e536d1af60d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
252
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 245
diff changeset
1 #!/usr/bin/env python
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 245
diff changeset
2 # encoding: utf-8
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 245
diff changeset
3 # files controller for pylons
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 245
diff changeset
4 # Copyright (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com>
318
fdf9f6ee5217 Implemented permissions into hg app, secured admin controllers, templates and repository specific controllers
Marcin Kuzminski <marcin@python-works.com>
parents: 275
diff changeset
5
252
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 245
diff changeset
6 # This program is free software; you can redistribute it and/or
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 245
diff changeset
7 # modify it under the terms of the GNU General Public License
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 245
diff changeset
8 # as published by the Free Software Foundation; version 2
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 245
diff changeset
9 # of the License or (at your opinion) any later version of the license.
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 245
diff changeset
10 #
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 245
diff changeset
11 # This program is distributed in the hope that it will be useful,
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 245
diff changeset
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 245
diff changeset
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 245
diff changeset
14 # GNU General Public License for more details.
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 245
diff changeset
15 #
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 245
diff changeset
16 # You should have received a copy of the GNU General Public License
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 245
diff changeset
17 # along with this program; if not, write to the Free Software
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 245
diff changeset
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 245
diff changeset
19 # MA 02110-1301, USA.
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 245
diff changeset
20 """
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 245
diff changeset
21 Created on April 21, 2010
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 245
diff changeset
22 files controller for pylons
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 245
diff changeset
23 @author: marcink
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 245
diff changeset
24 """
318
fdf9f6ee5217 Implemented permissions into hg app, secured admin controllers, templates and repository specific controllers
Marcin Kuzminski <marcin@python-works.com>
parents: 275
diff changeset
25 from mercurial import archival
fdf9f6ee5217 Implemented permissions into hg app, secured admin controllers, templates and repository specific controllers
Marcin Kuzminski <marcin@python-works.com>
parents: 275
diff changeset
26 from pylons import request, response, session, tmpl_context as c, url
544
d8778cde98f0 added limits to single file diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 512
diff changeset
27 from pylons.i18n.translation import _
318
fdf9f6ee5217 Implemented permissions into hg app, secured admin controllers, templates and repository specific controllers
Marcin Kuzminski <marcin@python-works.com>
parents: 275
diff changeset
28 from pylons.controllers.util import redirect
547
1e757ac98988 renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 544
diff changeset
29 from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator
1e757ac98988 renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 544
diff changeset
30 from rhodecode.lib.base import BaseController, render
1e757ac98988 renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 544
diff changeset
31 from rhodecode.lib.utils import EmptyChangeset
1e757ac98988 renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 544
diff changeset
32 from rhodecode.model.hg_model import HgModel
318
fdf9f6ee5217 Implemented permissions into hg app, secured admin controllers, templates and repository specific controllers
Marcin Kuzminski <marcin@python-works.com>
parents: 275
diff changeset
33 from vcs.exceptions import RepositoryError, ChangesetError
fdf9f6ee5217 Implemented permissions into hg app, secured admin controllers, templates and repository specific controllers
Marcin Kuzminski <marcin@python-works.com>
parents: 275
diff changeset
34 from vcs.nodes import FileNode
fdf9f6ee5217 Implemented permissions into hg app, secured admin controllers, templates and repository specific controllers
Marcin Kuzminski <marcin@python-works.com>
parents: 275
diff changeset
35 from vcs.utils import diffs as differ
fdf9f6ee5217 Implemented permissions into hg app, secured admin controllers, templates and repository specific controllers
Marcin Kuzminski <marcin@python-works.com>
parents: 275
diff changeset
36 import logging
547
1e757ac98988 renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 544
diff changeset
37 import rhodecode.lib.helpers as h
318
fdf9f6ee5217 Implemented permissions into hg app, secured admin controllers, templates and repository specific controllers
Marcin Kuzminski <marcin@python-works.com>
parents: 275
diff changeset
38 import tempfile
131
49c7e191c2cd Implemented mercurial style diff-lib
Marcin Kuzminski <marcin@python-works.com>
parents: 130
diff changeset
39
93
aec4c0071cb3 added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
40 log = logging.getLogger(__name__)
aec4c0071cb3 added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
41
aec4c0071cb3 added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
42 class FilesController(BaseController):
191
b68b2246e5a6 Authenticated controller with LoginRequired decorator, and cleaned __before__ (used in baseController now). fixed User for clone url with logged in session user.
Marcin Kuzminski <marcin@python-works.com>
parents: 160
diff changeset
43
b68b2246e5a6 Authenticated controller with LoginRequired decorator, and cleaned __before__ (used in baseController now). fixed User for clone url with logged in session user.
Marcin Kuzminski <marcin@python-works.com>
parents: 160
diff changeset
44 @LoginRequired()
318
fdf9f6ee5217 Implemented permissions into hg app, secured admin controllers, templates and repository specific controllers
Marcin Kuzminski <marcin@python-works.com>
parents: 275
diff changeset
45 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write',
fdf9f6ee5217 Implemented permissions into hg app, secured admin controllers, templates and repository specific controllers
Marcin Kuzminski <marcin@python-works.com>
parents: 275
diff changeset
46 'repository.admin')
99
5b57295601b6 Updated basic files browser with, pygments
Marcin Kuzminski <marcin@python-works.com>
parents: 93
diff changeset
47 def __before__(self):
191
b68b2246e5a6 Authenticated controller with LoginRequired decorator, and cleaned __before__ (used in baseController now). fixed User for clone url with logged in session user.
Marcin Kuzminski <marcin@python-works.com>
parents: 160
diff changeset
48 super(FilesController, self).__before__()
485
9836541b0509 added limit for showing pygemntized source codes larger than 250kb.
Marcin Kuzminski <marcin@python-works.com>
parents: 438
diff changeset
49 c.file_size_limit = 250 * 1024 #limit of file size to display
93
aec4c0071cb3 added empty controllers for branches tags files graph, routing and test for them
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
50
99
5b57295601b6 Updated basic files browser with, pygments
Marcin Kuzminski <marcin@python-works.com>
parents: 93
diff changeset
51 def index(self, repo_name, revision, f_path):
5b57295601b6 Updated basic files browser with, pygments
Marcin Kuzminski <marcin@python-works.com>
parents: 93
diff changeset
52 hg_model = HgModel()
5b57295601b6 Updated basic files browser with, pygments
Marcin Kuzminski <marcin@python-works.com>
parents: 93
diff changeset
53 c.repo = repo = hg_model.get_repo(c.repo_name)
149
b3c93efd1c97 Updated template for summary (archives links)
Marcin Kuzminski <marcin@python-works.com>
parents: 147
diff changeset
54 revision = request.POST.get('at_rev', None) or revision
145
3f01d02c2cc6 fixed error when browsing revisions on path that doesn't exist. Fixed files browsing. Fixed templates in branches and tags
Marcin Kuzminski <marcin@python-works.com>
parents: 142
diff changeset
55
149
b3c93efd1c97 Updated template for summary (archives links)
Marcin Kuzminski <marcin@python-works.com>
parents: 147
diff changeset
56 def get_next_rev(cur):
145
3f01d02c2cc6 fixed error when browsing revisions on path that doesn't exist. Fixed files browsing. Fixed templates in branches and tags
Marcin Kuzminski <marcin@python-works.com>
parents: 142
diff changeset
57 max_rev = len(c.repo.revisions) - 1
149
b3c93efd1c97 Updated template for summary (archives links)
Marcin Kuzminski <marcin@python-works.com>
parents: 147
diff changeset
58 r = cur + 1
b3c93efd1c97 Updated template for summary (archives links)
Marcin Kuzminski <marcin@python-works.com>
parents: 147
diff changeset
59 if r > max_rev:
b3c93efd1c97 Updated template for summary (archives links)
Marcin Kuzminski <marcin@python-works.com>
parents: 147
diff changeset
60 r = max_rev
b3c93efd1c97 Updated template for summary (archives links)
Marcin Kuzminski <marcin@python-works.com>
parents: 147
diff changeset
61 return r
b3c93efd1c97 Updated template for summary (archives links)
Marcin Kuzminski <marcin@python-works.com>
parents: 147
diff changeset
62
b3c93efd1c97 Updated template for summary (archives links)
Marcin Kuzminski <marcin@python-works.com>
parents: 147
diff changeset
63 def get_prev_rev(cur):
b3c93efd1c97 Updated template for summary (archives links)
Marcin Kuzminski <marcin@python-works.com>
parents: 147
diff changeset
64 r = cur - 1
b3c93efd1c97 Updated template for summary (archives links)
Marcin Kuzminski <marcin@python-works.com>
parents: 147
diff changeset
65 return r
b3c93efd1c97 Updated template for summary (archives links)
Marcin Kuzminski <marcin@python-works.com>
parents: 147
diff changeset
66
99
5b57295601b6 Updated basic files browser with, pygments
Marcin Kuzminski <marcin@python-works.com>
parents: 93
diff changeset
67 c.f_path = f_path
149
b3c93efd1c97 Updated template for summary (archives links)
Marcin Kuzminski <marcin@python-works.com>
parents: 147
diff changeset
68
147
873fd2dc62c2 Added rawfile support, and few fixes for file
Marcin Kuzminski <marcin@python-works.com>
parents: 145
diff changeset
69
138
5f42d751c719 fixed files when repository is empty
Marcin Kuzminski <marcin@python-works.com>
parents: 131
diff changeset
70 try:
149
b3c93efd1c97 Updated template for summary (archives links)
Marcin Kuzminski <marcin@python-works.com>
parents: 147
diff changeset
71 cur_rev = repo.get_changeset(revision).revision
512
d945c95ba4ac refactoring for new vcs implementation
Marcin Kuzminski <marcin@python-works.com>
parents: 485
diff changeset
72 prev_rev = repo.get_changeset(get_prev_rev(cur_rev)).short_id
d945c95ba4ac refactoring for new vcs implementation
Marcin Kuzminski <marcin@python-works.com>
parents: 485
diff changeset
73 next_rev = repo.get_changeset(get_next_rev(cur_rev)).short_id
149
b3c93efd1c97 Updated template for summary (archives links)
Marcin Kuzminski <marcin@python-works.com>
parents: 147
diff changeset
74
b3c93efd1c97 Updated template for summary (archives links)
Marcin Kuzminski <marcin@python-works.com>
parents: 147
diff changeset
75 c.url_prev = url('files_home', repo_name=c.repo_name,
b3c93efd1c97 Updated template for summary (archives links)
Marcin Kuzminski <marcin@python-works.com>
parents: 147
diff changeset
76 revision=prev_rev, f_path=f_path)
b3c93efd1c97 Updated template for summary (archives links)
Marcin Kuzminski <marcin@python-works.com>
parents: 147
diff changeset
77 c.url_next = url('files_home', repo_name=c.repo_name,
b3c93efd1c97 Updated template for summary (archives links)
Marcin Kuzminski <marcin@python-works.com>
parents: 147
diff changeset
78 revision=next_rev, f_path=f_path)
b3c93efd1c97 Updated template for summary (archives links)
Marcin Kuzminski <marcin@python-works.com>
parents: 147
diff changeset
79
b3c93efd1c97 Updated template for summary (archives links)
Marcin Kuzminski <marcin@python-works.com>
parents: 147
diff changeset
80 c.changeset = repo.get_changeset(revision)
147
873fd2dc62c2 Added rawfile support, and few fixes for file
Marcin Kuzminski <marcin@python-works.com>
parents: 145
diff changeset
81
512
d945c95ba4ac refactoring for new vcs implementation
Marcin Kuzminski <marcin@python-works.com>
parents: 485
diff changeset
82 c.cur_rev = c.changeset.short_id
142
f7218849798a Changeg graph to changelog, and changelog to shortlog
Marcin Kuzminski <marcin@python-works.com>
parents: 138
diff changeset
83 c.rev_nr = c.changeset.revision
138
5f42d751c719 fixed files when repository is empty
Marcin Kuzminski <marcin@python-works.com>
parents: 131
diff changeset
84 c.files_list = c.changeset.get_node(f_path)
5f42d751c719 fixed files when repository is empty
Marcin Kuzminski <marcin@python-works.com>
parents: 131
diff changeset
85 c.file_history = self._get_history(repo, c.files_list, f_path)
147
873fd2dc62c2 Added rawfile support, and few fixes for file
Marcin Kuzminski <marcin@python-works.com>
parents: 145
diff changeset
86
145
3f01d02c2cc6 fixed error when browsing revisions on path that doesn't exist. Fixed files browsing. Fixed templates in branches and tags
Marcin Kuzminski <marcin@python-works.com>
parents: 142
diff changeset
87 except (RepositoryError, ChangesetError):
138
5f42d751c719 fixed files when repository is empty
Marcin Kuzminski <marcin@python-works.com>
parents: 131
diff changeset
88 c.files_list = None
99
5b57295601b6 Updated basic files browser with, pygments
Marcin Kuzminski <marcin@python-works.com>
parents: 93
diff changeset
89
128
9deb6f1d5b90 Implemented file history.
Marcin Kuzminski <marcin@python-works.com>
parents: 106
diff changeset
90 return render('files/files.html')
9deb6f1d5b90 Implemented file history.
Marcin Kuzminski <marcin@python-works.com>
parents: 106
diff changeset
91
147
873fd2dc62c2 Added rawfile support, and few fixes for file
Marcin Kuzminski <marcin@python-works.com>
parents: 145
diff changeset
92 def rawfile(self, repo_name, revision, f_path):
873fd2dc62c2 Added rawfile support, and few fixes for file
Marcin Kuzminski <marcin@python-works.com>
parents: 145
diff changeset
93 hg_model = HgModel()
873fd2dc62c2 Added rawfile support, and few fixes for file
Marcin Kuzminski <marcin@python-works.com>
parents: 145
diff changeset
94 c.repo = hg_model.get_repo(c.repo_name)
873fd2dc62c2 Added rawfile support, and few fixes for file
Marcin Kuzminski <marcin@python-works.com>
parents: 145
diff changeset
95 file_node = c.repo.get_changeset(revision).get_node(f_path)
160
0f7f93df5802 implemented rawdiff and diff download into diff view.
Marcin Kuzminski <marcin@python-works.com>
parents: 158
diff changeset
96 response.content_type = file_node.mimetype
0f7f93df5802 implemented rawdiff and diff download into diff view.
Marcin Kuzminski <marcin@python-works.com>
parents: 158
diff changeset
97 response.content_disposition = 'attachment; filename=%s' \
147
873fd2dc62c2 Added rawfile support, and few fixes for file
Marcin Kuzminski <marcin@python-works.com>
parents: 145
diff changeset
98 % f_path.split('/')[-1]
873fd2dc62c2 Added rawfile support, and few fixes for file
Marcin Kuzminski <marcin@python-works.com>
parents: 145
diff changeset
99 return file_node.content
485
9836541b0509 added limit for showing pygemntized source codes larger than 250kb.
Marcin Kuzminski <marcin@python-works.com>
parents: 438
diff changeset
100
9836541b0509 added limit for showing pygemntized source codes larger than 250kb.
Marcin Kuzminski <marcin@python-works.com>
parents: 438
diff changeset
101 def raw(self, repo_name, revision, f_path):
9836541b0509 added limit for showing pygemntized source codes larger than 250kb.
Marcin Kuzminski <marcin@python-works.com>
parents: 438
diff changeset
102 hg_model = HgModel()
9836541b0509 added limit for showing pygemntized source codes larger than 250kb.
Marcin Kuzminski <marcin@python-works.com>
parents: 438
diff changeset
103 c.repo = hg_model.get_repo(c.repo_name)
9836541b0509 added limit for showing pygemntized source codes larger than 250kb.
Marcin Kuzminski <marcin@python-works.com>
parents: 438
diff changeset
104 file_node = c.repo.get_changeset(revision).get_node(f_path)
9836541b0509 added limit for showing pygemntized source codes larger than 250kb.
Marcin Kuzminski <marcin@python-works.com>
parents: 438
diff changeset
105 response.content_type = 'text/plain'
9836541b0509 added limit for showing pygemntized source codes larger than 250kb.
Marcin Kuzminski <marcin@python-works.com>
parents: 438
diff changeset
106
9836541b0509 added limit for showing pygemntized source codes larger than 250kb.
Marcin Kuzminski <marcin@python-works.com>
parents: 438
diff changeset
107 return file_node.content
147
873fd2dc62c2 Added rawfile support, and few fixes for file
Marcin Kuzminski <marcin@python-works.com>
parents: 145
diff changeset
108
191
b68b2246e5a6 Authenticated controller with LoginRequired decorator, and cleaned __before__ (used in baseController now). fixed User for clone url with logged in session user.
Marcin Kuzminski <marcin@python-works.com>
parents: 160
diff changeset
109 def annotate(self, repo_name, revision, f_path):
b68b2246e5a6 Authenticated controller with LoginRequired decorator, and cleaned __before__ (used in baseController now). fixed User for clone url with logged in session user.
Marcin Kuzminski <marcin@python-works.com>
parents: 160
diff changeset
110 hg_model = HgModel()
b68b2246e5a6 Authenticated controller with LoginRequired decorator, and cleaned __before__ (used in baseController now). fixed User for clone url with logged in session user.
Marcin Kuzminski <marcin@python-works.com>
parents: 160
diff changeset
111 c.repo = hg_model.get_repo(c.repo_name)
b68b2246e5a6 Authenticated controller with LoginRequired decorator, and cleaned __before__ (used in baseController now). fixed User for clone url with logged in session user.
Marcin Kuzminski <marcin@python-works.com>
parents: 160
diff changeset
112 cs = c.repo.get_changeset(revision)
b68b2246e5a6 Authenticated controller with LoginRequired decorator, and cleaned __before__ (used in baseController now). fixed User for clone url with logged in session user.
Marcin Kuzminski <marcin@python-works.com>
parents: 160
diff changeset
113 c.file = cs.get_node(f_path)
b68b2246e5a6 Authenticated controller with LoginRequired decorator, and cleaned __before__ (used in baseController now). fixed User for clone url with logged in session user.
Marcin Kuzminski <marcin@python-works.com>
parents: 160
diff changeset
114 c.file_msg = cs.get_file_message(f_path)
512
d945c95ba4ac refactoring for new vcs implementation
Marcin Kuzminski <marcin@python-works.com>
parents: 485
diff changeset
115 c.cur_rev = cs.short_id
375
3e55d9981c0e templating fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 349
diff changeset
116 c.rev_nr = cs.revision
191
b68b2246e5a6 Authenticated controller with LoginRequired decorator, and cleaned __before__ (used in baseController now). fixed User for clone url with logged in session user.
Marcin Kuzminski <marcin@python-works.com>
parents: 160
diff changeset
117 c.f_path = f_path
335
588c6147efc7 removed unneded value
Marcin Kuzminski <marcin@python-works.com>
parents: 318
diff changeset
118
191
b68b2246e5a6 Authenticated controller with LoginRequired decorator, and cleaned __before__ (used in baseController now). fixed User for clone url with logged in session user.
Marcin Kuzminski <marcin@python-works.com>
parents: 160
diff changeset
119 return render('files/files_annotate.html')
b68b2246e5a6 Authenticated controller with LoginRequired decorator, and cleaned __before__ (used in baseController now). fixed User for clone url with logged in session user.
Marcin Kuzminski <marcin@python-works.com>
parents: 160
diff changeset
120
149
b3c93efd1c97 Updated template for summary (archives links)
Marcin Kuzminski <marcin@python-works.com>
parents: 147
diff changeset
121 def archivefile(self, repo_name, revision, fileformat):
209
1a18994cdc3b Added archives support. Version bump
Marcin Kuzminski <marcin@python-works.com>
parents: 191
diff changeset
122 archive_specs = {
1a18994cdc3b Added archives support. Version bump
Marcin Kuzminski <marcin@python-works.com>
parents: 191
diff changeset
123 '.tar.bz2': ('application/x-tar', 'tbz2'),
1a18994cdc3b Added archives support. Version bump
Marcin Kuzminski <marcin@python-works.com>
parents: 191
diff changeset
124 '.tar.gz': ('application/x-tar', 'tgz'),
1a18994cdc3b Added archives support. Version bump
Marcin Kuzminski <marcin@python-works.com>
parents: 191
diff changeset
125 '.zip': ('application/zip', 'zip'),
1a18994cdc3b Added archives support. Version bump
Marcin Kuzminski <marcin@python-works.com>
parents: 191
diff changeset
126 }
1a18994cdc3b Added archives support. Version bump
Marcin Kuzminski <marcin@python-works.com>
parents: 191
diff changeset
127 if not archive_specs.has_key(fileformat):
1a18994cdc3b Added archives support. Version bump
Marcin Kuzminski <marcin@python-works.com>
parents: 191
diff changeset
128 return 'Unknown archive type %s' % fileformat
1a18994cdc3b Added archives support. Version bump
Marcin Kuzminski <marcin@python-works.com>
parents: 191
diff changeset
129
1a18994cdc3b Added archives support. Version bump
Marcin Kuzminski <marcin@python-works.com>
parents: 191
diff changeset
130 def read_in_chunks(file_object, chunk_size=1024 * 40):
1a18994cdc3b Added archives support. Version bump
Marcin Kuzminski <marcin@python-works.com>
parents: 191
diff changeset
131 """Lazy function (generator) to read a file piece by piece.
1a18994cdc3b Added archives support. Version bump
Marcin Kuzminski <marcin@python-works.com>
parents: 191
diff changeset
132 Default chunk size: 40k."""
1a18994cdc3b Added archives support. Version bump
Marcin Kuzminski <marcin@python-works.com>
parents: 191
diff changeset
133 while True:
1a18994cdc3b Added archives support. Version bump
Marcin Kuzminski <marcin@python-works.com>
parents: 191
diff changeset
134 data = file_object.read(chunk_size)
1a18994cdc3b Added archives support. Version bump
Marcin Kuzminski <marcin@python-works.com>
parents: 191
diff changeset
135 if not data:
1a18994cdc3b Added archives support. Version bump
Marcin Kuzminski <marcin@python-works.com>
parents: 191
diff changeset
136 break
1a18994cdc3b Added archives support. Version bump
Marcin Kuzminski <marcin@python-works.com>
parents: 191
diff changeset
137 yield data
1a18994cdc3b Added archives support. Version bump
Marcin Kuzminski <marcin@python-works.com>
parents: 191
diff changeset
138
1a18994cdc3b Added archives support. Version bump
Marcin Kuzminski <marcin@python-works.com>
parents: 191
diff changeset
139 archive = tempfile.TemporaryFile()
1a18994cdc3b Added archives support. Version bump
Marcin Kuzminski <marcin@python-works.com>
parents: 191
diff changeset
140 repo = HgModel().get_repo(repo_name).repo
1a18994cdc3b Added archives support. Version bump
Marcin Kuzminski <marcin@python-works.com>
parents: 191
diff changeset
141 fname = '%s-%s%s' % (repo_name, revision, fileformat)
1a18994cdc3b Added archives support. Version bump
Marcin Kuzminski <marcin@python-works.com>
parents: 191
diff changeset
142 archival.archive(repo, archive, revision, archive_specs[fileformat][1],
1a18994cdc3b Added archives support. Version bump
Marcin Kuzminski <marcin@python-works.com>
parents: 191
diff changeset
143 prefix='%s-%s' % (repo_name, revision))
1a18994cdc3b Added archives support. Version bump
Marcin Kuzminski <marcin@python-works.com>
parents: 191
diff changeset
144 response.content_type = archive_specs[fileformat][0]
1a18994cdc3b Added archives support. Version bump
Marcin Kuzminski <marcin@python-works.com>
parents: 191
diff changeset
145 response.content_disposition = 'attachment; filename=%s' % fname
1a18994cdc3b Added archives support. Version bump
Marcin Kuzminski <marcin@python-works.com>
parents: 191
diff changeset
146 archive.seek(0)
1a18994cdc3b Added archives support. Version bump
Marcin Kuzminski <marcin@python-works.com>
parents: 191
diff changeset
147 return read_in_chunks(archive)
149
b3c93efd1c97 Updated template for summary (archives links)
Marcin Kuzminski <marcin@python-works.com>
parents: 147
diff changeset
148
129
42d46deb124d implemented simple diffs for history of files.
Marcin Kuzminski <marcin@python-works.com>
parents: 128
diff changeset
149 def diff(self, repo_name, f_path):
42d46deb124d implemented simple diffs for history of files.
Marcin Kuzminski <marcin@python-works.com>
parents: 128
diff changeset
150 hg_model = HgModel()
42d46deb124d implemented simple diffs for history of files.
Marcin Kuzminski <marcin@python-works.com>
parents: 128
diff changeset
151 diff1 = request.GET.get('diff1')
42d46deb124d implemented simple diffs for history of files.
Marcin Kuzminski <marcin@python-works.com>
parents: 128
diff changeset
152 diff2 = request.GET.get('diff2')
337
fa3835d34fc1 fixed bug when diff command was different than available options
Marcin Kuzminski <marcin@python-works.com>
parents: 335
diff changeset
153 c.action = request.GET.get('diff')
131
49c7e191c2cd Implemented mercurial style diff-lib
Marcin Kuzminski <marcin@python-works.com>
parents: 130
diff changeset
154 c.no_changes = diff1 == diff2
129
42d46deb124d implemented simple diffs for history of files.
Marcin Kuzminski <marcin@python-works.com>
parents: 128
diff changeset
155 c.f_path = f_path
42d46deb124d implemented simple diffs for history of files.
Marcin Kuzminski <marcin@python-works.com>
parents: 128
diff changeset
156 c.repo = hg_model.get_repo(c.repo_name)
152
0c00fbaff55a Fixed differ to properly extract filenames, and dates from diff file. and swaped order of columns with lines nr in diff html
Marcin Kuzminski <marcin@python-works.com>
parents: 149
diff changeset
157
275
2d61aa00e855 fixed bugs when putting empty or unknown changesets into diff
Marcin Kuzminski <marcin@python-works.com>
parents: 272
diff changeset
158 try:
544
d8778cde98f0 added limits to single file diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 512
diff changeset
159 if diff1 not in ['', None, 'None', '0' * 12, '0' * 40]:
275
2d61aa00e855 fixed bugs when putting empty or unknown changesets into diff
Marcin Kuzminski <marcin@python-works.com>
parents: 272
diff changeset
160 c.changeset_1 = c.repo.get_changeset(diff1)
2d61aa00e855 fixed bugs when putting empty or unknown changesets into diff
Marcin Kuzminski <marcin@python-works.com>
parents: 272
diff changeset
161 node1 = c.changeset_1.get_node(f_path)
2d61aa00e855 fixed bugs when putting empty or unknown changesets into diff
Marcin Kuzminski <marcin@python-works.com>
parents: 272
diff changeset
162 else:
2d61aa00e855 fixed bugs when putting empty or unknown changesets into diff
Marcin Kuzminski <marcin@python-works.com>
parents: 272
diff changeset
163 c.changeset_1 = EmptyChangeset()
544
d8778cde98f0 added limits to single file diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 512
diff changeset
164 node1 = FileNode('.', '', changeset=c.changeset_1)
d8778cde98f0 added limits to single file diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 512
diff changeset
165
d8778cde98f0 added limits to single file diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 512
diff changeset
166 if diff2 not in ['', None, 'None', '0' * 12, '0' * 40]:
275
2d61aa00e855 fixed bugs when putting empty or unknown changesets into diff
Marcin Kuzminski <marcin@python-works.com>
parents: 272
diff changeset
167 c.changeset_2 = c.repo.get_changeset(diff2)
2d61aa00e855 fixed bugs when putting empty or unknown changesets into diff
Marcin Kuzminski <marcin@python-works.com>
parents: 272
diff changeset
168 node2 = c.changeset_2.get_node(f_path)
2d61aa00e855 fixed bugs when putting empty or unknown changesets into diff
Marcin Kuzminski <marcin@python-works.com>
parents: 272
diff changeset
169 else:
2d61aa00e855 fixed bugs when putting empty or unknown changesets into diff
Marcin Kuzminski <marcin@python-works.com>
parents: 272
diff changeset
170 c.changeset_2 = EmptyChangeset()
544
d8778cde98f0 added limits to single file diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 512
diff changeset
171 node2 = FileNode('.', '', changeset=c.changeset_2)
275
2d61aa00e855 fixed bugs when putting empty or unknown changesets into diff
Marcin Kuzminski <marcin@python-works.com>
parents: 272
diff changeset
172 except RepositoryError:
2d61aa00e855 fixed bugs when putting empty or unknown changesets into diff
Marcin Kuzminski <marcin@python-works.com>
parents: 272
diff changeset
173 return redirect(url('files_home',
2d61aa00e855 fixed bugs when putting empty or unknown changesets into diff
Marcin Kuzminski <marcin@python-works.com>
parents: 272
diff changeset
174 repo_name=c.repo_name, f_path=f_path))
2d61aa00e855 fixed bugs when putting empty or unknown changesets into diff
Marcin Kuzminski <marcin@python-works.com>
parents: 272
diff changeset
175
512
d945c95ba4ac refactoring for new vcs implementation
Marcin Kuzminski <marcin@python-works.com>
parents: 485
diff changeset
176 c.diff1 = 'r%s:%s' % (c.changeset_1.revision, c.changeset_1.short_id)
d945c95ba4ac refactoring for new vcs implementation
Marcin Kuzminski <marcin@python-works.com>
parents: 485
diff changeset
177 c.diff2 = 'r%s:%s' % (c.changeset_2.revision, c.changeset_2.short_id)
544
d8778cde98f0 added limits to single file diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 512
diff changeset
178
275
2d61aa00e855 fixed bugs when putting empty or unknown changesets into diff
Marcin Kuzminski <marcin@python-works.com>
parents: 272
diff changeset
179 f_udiff = differ.get_udiff(node1, node2)
160
0f7f93df5802 implemented rawdiff and diff download into diff view.
Marcin Kuzminski <marcin@python-works.com>
parents: 158
diff changeset
180 diff = differ.DiffProcessor(f_udiff)
0f7f93df5802 implemented rawdiff and diff download into diff view.
Marcin Kuzminski <marcin@python-works.com>
parents: 158
diff changeset
181
337
fa3835d34fc1 fixed bug when diff command was different than available options
Marcin Kuzminski <marcin@python-works.com>
parents: 335
diff changeset
182 if c.action == 'download':
160
0f7f93df5802 implemented rawdiff and diff download into diff view.
Marcin Kuzminski <marcin@python-works.com>
parents: 158
diff changeset
183 diff_name = '%s_vs_%s.diff' % (diff1, diff2)
0f7f93df5802 implemented rawdiff and diff download into diff view.
Marcin Kuzminski <marcin@python-works.com>
parents: 158
diff changeset
184 response.content_type = 'text/plain'
0f7f93df5802 implemented rawdiff and diff download into diff view.
Marcin Kuzminski <marcin@python-works.com>
parents: 158
diff changeset
185 response.content_disposition = 'attachment; filename=%s' \
0f7f93df5802 implemented rawdiff and diff download into diff view.
Marcin Kuzminski <marcin@python-works.com>
parents: 158
diff changeset
186 % diff_name
0f7f93df5802 implemented rawdiff and diff download into diff view.
Marcin Kuzminski <marcin@python-works.com>
parents: 158
diff changeset
187 return diff.raw_diff()
0f7f93df5802 implemented rawdiff and diff download into diff view.
Marcin Kuzminski <marcin@python-works.com>
parents: 158
diff changeset
188
337
fa3835d34fc1 fixed bug when diff command was different than available options
Marcin Kuzminski <marcin@python-works.com>
parents: 335
diff changeset
189 elif c.action == 'raw':
272
a83e86e3f580 fixed bug when displaying html not escaped data as raw diff.
Marcin Kuzminski <marcin@python-works.com>
parents: 267
diff changeset
190 c.cur_diff = '<pre class="raw">%s</pre>' % h.escape(diff.raw_diff())
337
fa3835d34fc1 fixed bug when diff command was different than available options
Marcin Kuzminski <marcin@python-works.com>
parents: 335
diff changeset
191 elif c.action == 'diff':
544
d8778cde98f0 added limits to single file diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 512
diff changeset
192 if node1.size > c.file_size_limit or node2.size > c.file_size_limit:
d8778cde98f0 added limits to single file diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 512
diff changeset
193 c.cur_diff = _('Diff is to big to display')
d8778cde98f0 added limits to single file diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 512
diff changeset
194 else:
d8778cde98f0 added limits to single file diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 512
diff changeset
195 c.cur_diff = diff.as_html()
337
fa3835d34fc1 fixed bug when diff command was different than available options
Marcin Kuzminski <marcin@python-works.com>
parents: 335
diff changeset
196 else:
fa3835d34fc1 fixed bug when diff command was different than available options
Marcin Kuzminski <marcin@python-works.com>
parents: 335
diff changeset
197 #default option
544
d8778cde98f0 added limits to single file diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 512
diff changeset
198 if node1.size > c.file_size_limit or node2.size > c.file_size_limit:
d8778cde98f0 added limits to single file diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 512
diff changeset
199 c.cur_diff = _('Diff is to big to display')
d8778cde98f0 added limits to single file diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 512
diff changeset
200 else:
d8778cde98f0 added limits to single file diffs
Marcin Kuzminski <marcin@python-works.com>
parents: 512
diff changeset
201 c.cur_diff = diff.as_html()
349
031152a540c5 Bugfix for empty diff
Marcin Kuzminski <marcin@python-works.com>
parents: 337
diff changeset
202
031152a540c5 Bugfix for empty diff
Marcin Kuzminski <marcin@python-works.com>
parents: 337
diff changeset
203 if not c.cur_diff: c.no_changes = True
129
42d46deb124d implemented simple diffs for history of files.
Marcin Kuzminski <marcin@python-works.com>
parents: 128
diff changeset
204 return render('files/file_diff.html')
42d46deb124d implemented simple diffs for history of files.
Marcin Kuzminski <marcin@python-works.com>
parents: 128
diff changeset
205
128
9deb6f1d5b90 Implemented file history.
Marcin Kuzminski <marcin@python-works.com>
parents: 106
diff changeset
206 def _get_history(self, repo, node, f_path):
9deb6f1d5b90 Implemented file history.
Marcin Kuzminski <marcin@python-works.com>
parents: 106
diff changeset
207 from vcs.nodes import NodeKind
9deb6f1d5b90 Implemented file history.
Marcin Kuzminski <marcin@python-works.com>
parents: 106
diff changeset
208 if not node.kind is NodeKind.FILE:
9deb6f1d5b90 Implemented file history.
Marcin Kuzminski <marcin@python-works.com>
parents: 106
diff changeset
209 return []
129
42d46deb124d implemented simple diffs for history of files.
Marcin Kuzminski <marcin@python-works.com>
parents: 128
diff changeset
210 changesets = node.history
128
9deb6f1d5b90 Implemented file history.
Marcin Kuzminski <marcin@python-works.com>
parents: 106
diff changeset
211 hist_l = []
9deb6f1d5b90 Implemented file history.
Marcin Kuzminski <marcin@python-works.com>
parents: 106
diff changeset
212 for chs in changesets:
512
d945c95ba4ac refactoring for new vcs implementation
Marcin Kuzminski <marcin@python-works.com>
parents: 485
diff changeset
213 n_desc = 'r%s:%s' % (chs.revision, chs.short_id)
d945c95ba4ac refactoring for new vcs implementation
Marcin Kuzminski <marcin@python-works.com>
parents: 485
diff changeset
214 hist_l.append((chs.short_id, n_desc,))
128
9deb6f1d5b90 Implemented file history.
Marcin Kuzminski <marcin@python-works.com>
parents: 106
diff changeset
215 return hist_l