# HG changeset patch # User Marcin Kuzminski # Date 2010-10-05 16:25:08 # Node ID d8778cde98f0e3e74b0c7f0832c115765cf0714c # Parent a99e23e6c1e8f8ac1f7577b76519e69868278c27 added limits to single file diffs changed changeset to use .size for cut off diff --git a/pylons_app/controllers/changeset.py b/pylons_app/controllers/changeset.py --- a/pylons_app/controllers/changeset.py +++ b/pylons_app/controllers/changeset.py @@ -67,6 +67,10 @@ class ChangesetController(BaseController except IndexError: c.changeset_old = None c.changes = [] + + #=================================================================== + # ADDED FILES + #=================================================================== c.sum_added = 0 for node in c.changeset.added: @@ -74,17 +78,21 @@ class ChangesetController(BaseController if filenode_old.is_binary or node.is_binary: diff = wrap_to_table(_('binary file')) else: - c.sum_added += len(node.content) + c.sum_added += node.size if c.sum_added < cut_off_limit: f_udiff = differ.get_udiff(filenode_old, node) diff = differ.DiffProcessor(f_udiff).as_html() else: - diff = wrap_to_table(_('Changeset is to big see raw changeset')) + diff = wrap_to_table(_('Changeset is to big and was cut' + ' off, see raw changeset instead')) cs1 = None cs2 = node.last_changeset.short_id c.changes.append(('added', node, diff, cs1, cs2)) + #=================================================================== + # CHANGED FILES + #=================================================================== c.sum_removed = 0 for node in c.changeset.changed: try: @@ -95,17 +103,21 @@ class ChangesetController(BaseController if filenode_old.is_binary or node.is_binary: diff = wrap_to_table(_('binary file')) else: - c.sum_removed += len(node.content) + c.sum_removed += node.size if c.sum_removed < cut_off_limit: f_udiff = differ.get_udiff(filenode_old, node) diff = differ.DiffProcessor(f_udiff).as_html() else: - diff = wrap_to_table(_('Changeset is to big see raw changeset')) + diff = wrap_to_table(_('Changeset is to big and was cut' + ' off, see raw changeset instead')) cs1 = filenode_old.last_changeset.short_id cs2 = node.last_changeset.short_id c.changes.append(('changed', node, diff, cs1, cs2)) + #=================================================================== + # REMOVED FILES + #=================================================================== for node in c.changeset.removed: c.changes.append(('removed', node, None, None, None)) diff --git a/pylons_app/controllers/files.py b/pylons_app/controllers/files.py --- a/pylons_app/controllers/files.py +++ b/pylons_app/controllers/files.py @@ -24,6 +24,7 @@ files controller for pylons """ from mercurial import archival from pylons import request, response, session, tmpl_context as c, url +from pylons.i18n.translation import _ from pylons.controllers.util import redirect from pylons_app.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator from pylons_app.lib.base import BaseController, render @@ -155,26 +156,27 @@ class FilesController(BaseController): c.repo = hg_model.get_repo(c.repo_name) try: - if diff1 not in ['', None, 'None', '0' * 12]: + if diff1 not in ['', None, 'None', '0' * 12, '0' * 40]: c.changeset_1 = c.repo.get_changeset(diff1) node1 = c.changeset_1.get_node(f_path) else: c.changeset_1 = EmptyChangeset() - node1 = FileNode('.', '') - if diff2 not in ['', None, 'None', '0' * 12]: + node1 = FileNode('.', '', changeset=c.changeset_1) + + if diff2 not in ['', None, 'None', '0' * 12, '0' * 40]: c.changeset_2 = c.repo.get_changeset(diff2) node2 = c.changeset_2.get_node(f_path) else: c.changeset_2 = EmptyChangeset() - node2 = FileNode('.', '') + node2 = FileNode('.', '', changeset=c.changeset_2) except RepositoryError: return redirect(url('files_home', repo_name=c.repo_name, f_path=f_path)) c.diff1 = 'r%s:%s' % (c.changeset_1.revision, c.changeset_1.short_id) c.diff2 = 'r%s:%s' % (c.changeset_2.revision, c.changeset_2.short_id) + f_udiff = differ.get_udiff(node1, node2) - diff = differ.DiffProcessor(f_udiff) if c.action == 'download': @@ -187,10 +189,16 @@ class FilesController(BaseController): elif c.action == 'raw': c.cur_diff = '
%s
' % h.escape(diff.raw_diff()) elif c.action == 'diff': - c.cur_diff = diff.as_html() + if node1.size > c.file_size_limit or node2.size > c.file_size_limit: + c.cur_diff = _('Diff is to big to display') + else: + c.cur_diff = diff.as_html() else: #default option - c.cur_diff = diff.as_html() + if node1.size > c.file_size_limit or node2.size > c.file_size_limit: + c.cur_diff = _('Diff is to big to display') + else: + c.cur_diff = diff.as_html() if not c.cur_diff: c.no_changes = True return render('files/file_diff.html') diff --git a/pylons_app/lib/utils.py b/pylons_app/lib/utils.py --- a/pylons_app/lib/utils.py +++ b/pylons_app/lib/utils.py @@ -251,11 +251,14 @@ def invalidate_cache(name, *args): region_invalidate(_full_changelog_cached, None, *args) class EmptyChangeset(BaseChangeset): + """ + An dummy empty changeset. + """ revision = -1 message = '' author = '' - + date = '' @LazyProperty def raw_id(self): """ @@ -268,6 +271,15 @@ class EmptyChangeset(BaseChangeset): def short_id(self): return self.raw_id[:12] + def get_file_changeset(self, path): + return self + + def get_file_content(self, path): + return u'' + + def get_file_size(self, path): + return 0 + def repo2db_mapper(initial_repo_list, remove_obsolete=False): """ maps all found repositories into db