##// END OF EJS Templates
added limits to single file diffs...
marcink -
r544:d8778cde default
parent child Browse files
Show More
@@ -67,6 +67,10 b' class ChangesetController(BaseController'
67 67 except IndexError:
68 68 c.changeset_old = None
69 69 c.changes = []
70
71 #===================================================================
72 # ADDED FILES
73 #===================================================================
70 74 c.sum_added = 0
71 75 for node in c.changeset.added:
72 76
@@ -74,17 +78,21 b' class ChangesetController(BaseController'
74 78 if filenode_old.is_binary or node.is_binary:
75 79 diff = wrap_to_table(_('binary file'))
76 80 else:
77 c.sum_added += len(node.content)
81 c.sum_added += node.size
78 82 if c.sum_added < cut_off_limit:
79 83 f_udiff = differ.get_udiff(filenode_old, node)
80 84 diff = differ.DiffProcessor(f_udiff).as_html()
81 85 else:
82 diff = wrap_to_table(_('Changeset is to big see raw changeset'))
86 diff = wrap_to_table(_('Changeset is to big and was cut'
87 ' off, see raw changeset instead'))
83 88
84 89 cs1 = None
85 90 cs2 = node.last_changeset.short_id
86 91 c.changes.append(('added', node, diff, cs1, cs2))
87 92
93 #===================================================================
94 # CHANGED FILES
95 #===================================================================
88 96 c.sum_removed = 0
89 97 for node in c.changeset.changed:
90 98 try:
@@ -95,17 +103,21 b' class ChangesetController(BaseController'
95 103 if filenode_old.is_binary or node.is_binary:
96 104 diff = wrap_to_table(_('binary file'))
97 105 else:
98 c.sum_removed += len(node.content)
106 c.sum_removed += node.size
99 107 if c.sum_removed < cut_off_limit:
100 108 f_udiff = differ.get_udiff(filenode_old, node)
101 109 diff = differ.DiffProcessor(f_udiff).as_html()
102 110 else:
103 diff = wrap_to_table(_('Changeset is to big see raw changeset'))
111 diff = wrap_to_table(_('Changeset is to big and was cut'
112 ' off, see raw changeset instead'))
104 113
105 114 cs1 = filenode_old.last_changeset.short_id
106 115 cs2 = node.last_changeset.short_id
107 116 c.changes.append(('changed', node, diff, cs1, cs2))
108 117
118 #===================================================================
119 # REMOVED FILES
120 #===================================================================
109 121 for node in c.changeset.removed:
110 122 c.changes.append(('removed', node, None, None, None))
111 123
@@ -24,6 +24,7 b' files controller for pylons'
24 24 """
25 25 from mercurial import archival
26 26 from pylons import request, response, session, tmpl_context as c, url
27 from pylons.i18n.translation import _
27 28 from pylons.controllers.util import redirect
28 29 from pylons_app.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator
29 30 from pylons_app.lib.base import BaseController, render
@@ -155,26 +156,27 b' class FilesController(BaseController):'
155 156 c.repo = hg_model.get_repo(c.repo_name)
156 157
157 158 try:
158 if diff1 not in ['', None, 'None', '0' * 12]:
159 if diff1 not in ['', None, 'None', '0' * 12, '0' * 40]:
159 160 c.changeset_1 = c.repo.get_changeset(diff1)
160 161 node1 = c.changeset_1.get_node(f_path)
161 162 else:
162 163 c.changeset_1 = EmptyChangeset()
163 node1 = FileNode('.', '')
164 if diff2 not in ['', None, 'None', '0' * 12]:
164 node1 = FileNode('.', '', changeset=c.changeset_1)
165
166 if diff2 not in ['', None, 'None', '0' * 12, '0' * 40]:
165 167 c.changeset_2 = c.repo.get_changeset(diff2)
166 168 node2 = c.changeset_2.get_node(f_path)
167 169 else:
168 170 c.changeset_2 = EmptyChangeset()
169 node2 = FileNode('.', '')
171 node2 = FileNode('.', '', changeset=c.changeset_2)
170 172 except RepositoryError:
171 173 return redirect(url('files_home',
172 174 repo_name=c.repo_name, f_path=f_path))
173 175
174 176 c.diff1 = 'r%s:%s' % (c.changeset_1.revision, c.changeset_1.short_id)
175 177 c.diff2 = 'r%s:%s' % (c.changeset_2.revision, c.changeset_2.short_id)
178
176 179 f_udiff = differ.get_udiff(node1, node2)
177
178 180 diff = differ.DiffProcessor(f_udiff)
179 181
180 182 if c.action == 'download':
@@ -187,10 +189,16 b' class FilesController(BaseController):'
187 189 elif c.action == 'raw':
188 190 c.cur_diff = '<pre class="raw">%s</pre>' % h.escape(diff.raw_diff())
189 191 elif c.action == 'diff':
190 c.cur_diff = diff.as_html()
192 if node1.size > c.file_size_limit or node2.size > c.file_size_limit:
193 c.cur_diff = _('Diff is to big to display')
194 else:
195 c.cur_diff = diff.as_html()
191 196 else:
192 197 #default option
193 c.cur_diff = diff.as_html()
198 if node1.size > c.file_size_limit or node2.size > c.file_size_limit:
199 c.cur_diff = _('Diff is to big to display')
200 else:
201 c.cur_diff = diff.as_html()
194 202
195 203 if not c.cur_diff: c.no_changes = True
196 204 return render('files/file_diff.html')
@@ -251,11 +251,14 b' def invalidate_cache(name, *args):'
251 251 region_invalidate(_full_changelog_cached, None, *args)
252 252
253 253 class EmptyChangeset(BaseChangeset):
254 """
255 An dummy empty changeset.
256 """
254 257
255 258 revision = -1
256 259 message = ''
257 260 author = ''
258
261 date = ''
259 262 @LazyProperty
260 263 def raw_id(self):
261 264 """
@@ -268,6 +271,15 b' class EmptyChangeset(BaseChangeset):'
268 271 def short_id(self):
269 272 return self.raw_id[:12]
270 273
274 def get_file_changeset(self, path):
275 return self
276
277 def get_file_content(self, path):
278 return u''
279
280 def get_file_size(self, path):
281 return 0
282
271 283 def repo2db_mapper(initial_repo_list, remove_obsolete=False):
272 284 """
273 285 maps all found repositories into db
General Comments 0
You need to be logged in to leave comments. Login now