# HG changeset patch # User Marcin Kuzminski # Date 2017-07-17 22:07:43 # Node ID f3f88cc80f61cbb8a1a258a89f116549e6ffaa60 # Parent 02c0c21b99ffc0756f9be19106105183887b1fd4 changelog: ported to pyramid views. diff --git a/rhodecode/apps/repository/__init__.py b/rhodecode/apps/repository/__init__.py --- a/rhodecode/apps/repository/__init__.py +++ b/rhodecode/apps/repository/__init__.py @@ -139,6 +139,17 @@ def includeme(config): name='repo_stats', pattern='/{repo_name:.*?[^/]}/repo_stats/{commit_id}', repo_route=True) + # Changelog + config.add_route( + name='repo_changelog', + pattern='/{repo_name:.*?[^/]}/changelog', repo_route=True) + config.add_route( + name='repo_changelog_file', + pattern='/{repo_name:.*?[^/]}/changelog/{commit_id}/{f_path:.*}', repo_route=True) + config.add_route( + name='repo_changelog_elements', + pattern='/{repo_name:.*?[^/]}/changelog_elements', repo_route=True) + # Tags config.add_route( name='tags_home', diff --git a/rhodecode/tests/functional/test_changelog.py b/rhodecode/apps/repository/tests/test_repo_changelog.py rename from rhodecode/tests/functional/test_changelog.py rename to rhodecode/apps/repository/tests/test_repo_changelog.py --- a/rhodecode/tests/functional/test_changelog.py +++ b/rhodecode/apps/repository/tests/test_repo_changelog.py @@ -22,20 +22,32 @@ import re import pytest -from rhodecode.controllers.changelog import DEFAULT_CHANGELOG_SIZE -from rhodecode.tests import url, TestController -from rhodecode.tests.utils import AssertResponse - +from rhodecode.apps.repository.views.repo_changelog import DEFAULT_CHANGELOG_SIZE +from rhodecode.tests import TestController MATCH_HASH = re.compile(r'r(\d+):[\da-f]+') +def route_path(name, params=None, **kwargs): + import urllib + + base_url = { + 'repo_changelog':'/{repo_name}/changelog', + 'repo_changelog_file':'/{repo_name}/changelog/{commit_id}/{f_path}', + 'repo_changelog_elements':'/{repo_name}/changelog_elements', + }[name].format(**kwargs) + + if params: + base_url = '{}?{}'.format(base_url, urllib.urlencode(params)) + return base_url + + class TestChangelogController(TestController): - def test_index(self, backend): + def test_changelog(self, backend): self.log_user() - response = self.app.get(url(controller='changelog', action='index', - repo_name=backend.repo_name)) + response = self.app.get( + route_path('repo_changelog', repo_name=backend.repo_name)) first_idx = -1 last_idx = -DEFAULT_CHANGELOG_SIZE @@ -43,39 +55,30 @@ class TestChangelogController(TestContro response, first_idx, last_idx, backend) @pytest.mark.backends("hg", "git") - def test_index_filtered_by_branch(self, backend): + def test_changelog_filtered_by_branch(self, backend): self.log_user() self.app.get( - url( - controller='changelog', - action='index', - repo_name=backend.repo_name, - branch=backend.default_branch_name), + route_path('repo_changelog', repo_name=backend.repo_name, + params=dict(branch=backend.default_branch_name)), status=200) @pytest.mark.backends("svn") - def test_index_filtered_by_branch_svn(self, autologin_user, backend): + def test_changelog_filtered_by_branch_svn(self, autologin_user, backend): repo = backend['svn-simple-layout'] response = self.app.get( - url( - controller='changelog', - action='index', - repo_name=repo.repo_name, - branch='trunk'), + route_path('repo_changelog', repo_name=repo.repo_name, + params=dict(branch='trunk')), status=200) self.assert_commits_on_page( response, indexes=[15, 12, 7, 3, 2, 1]) - def test_index_filtered_by_wrong_branch(self, backend): + def test_changelog_filtered_by_wrong_branch(self, backend): self.log_user() branch = 'wrong-branch-name' response = self.app.get( - url( - controller='changelog', - action='index', - repo_name=backend.repo_name, - branch=branch), + route_path('repo_changelog', repo_name=backend.repo_name, + params=dict(branch=branch)), status=302) expected_url = '/{repo}/changelog/{branch}'.format( repo=backend.repo_name, branch=branch) @@ -89,7 +92,7 @@ class TestChangelogController(TestContro assert found_indexes == indexes @pytest.mark.xfail_backends("svn", reason="Depends on branch support") - def test_index_filtered_by_branch_with_merges( + def test_changelog_filtered_by_branch_with_merges( self, autologin_user, backend): # Note: The changelog of branch "b" does not contain the commit "a1" @@ -104,33 +107,27 @@ class TestChangelogController(TestContro backend.create_repo(commits) self.app.get( - url('changelog_home', - controller='changelog', - action='index', - repo_name=backend.repo_name, - branch='b'), + route_path('repo_changelog', repo_name=backend.repo_name, + params=dict(branch='b')), status=200) @pytest.mark.backends("hg") - def test_index_closed_branches(self, autologin_user, backend): + def test_changelog_closed_branches(self, autologin_user, backend): repo = backend['closed_branch'] response = self.app.get( - url( - controller='changelog', - action='index', - repo_name=repo.repo_name, - branch='experimental'), + route_path('repo_changelog', repo_name=repo.repo_name, + params=dict(branch='experimental')), status=200) self.assert_commits_on_page( response, indexes=[3, 1]) - def test_index_pagination(self, backend): + def test_changelog_pagination(self, backend): self.log_user() # pagination, walk up to page 6 - changelog_url = url( - controller='changelog', action='index', - repo_name=backend.repo_name) + changelog_url = route_path( + 'repo_changelog', repo_name=backend.repo_name) + for page in range(1, 7): response = self.app.get(changelog_url, {'page': page}) @@ -166,27 +163,33 @@ class TestChangelogController(TestContro first_commit_of_next_page.idx, first_commit_of_next_page.short_id) assert first_span_of_next_page not in response - def test_index_with_filenode(self, backend): + @pytest.mark.parametrize('test_path', [ + 'vcs/exceptions.py', + '/vcs/exceptions.py', + '//vcs/exceptions.py' + ]) + def test_changelog_with_filenode(self, backend, test_path): self.log_user() - response = self.app.get(url( - controller='changelog', action='index', revision='tip', - f_path='/vcs/exceptions.py', repo_name=backend.repo_name)) + response = self.app.get( + route_path('repo_changelog_file', repo_name=backend.repo_name, + commit_id='tip', f_path=test_path), + ) # history commits messages response.mustcontain('Added exceptions module, this time for real') response.mustcontain('Added not implemented hg backend test case') response.mustcontain('Added BaseChangeset class') - def test_index_with_filenode_that_is_dirnode(self, backend): + def test_changelog_with_filenode_that_is_dirnode(self, backend): self.log_user() - response = self.app.get(url(controller='changelog', action='index', - revision='tip', f_path='/tests', - repo_name=backend.repo_name)) - assert response.status == '302 Found' + self.app.get( + route_path('repo_changelog_file', repo_name=backend.repo_name, + commit_id='tip', f_path='/tests'), + status=302) - def test_index_with_filenode_not_existing(self, backend): + def test_changelog_with_filenode_not_existing(self, backend): self.log_user() - response = self.app.get(url(controller='changelog', action='index', - revision='tip', f_path='/wrong_path', - repo_name=backend.repo_name)) - assert response.status == '302 Found' + self.app.get( + route_path('repo_changelog_file', repo_name=backend.repo_name, + commit_id='tip', f_path='wrong_path'), + status=302) diff --git a/rhodecode/apps/repository/views/repo_changelog.py b/rhodecode/apps/repository/views/repo_changelog.py new file mode 100644 --- /dev/null +++ b/rhodecode/apps/repository/views/repo_changelog.py @@ -0,0 +1,302 @@ +# -*- coding: utf-8 -*- + +# Copyright (C) 2010-2017 RhodeCode GmbH +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License, version 3 +# (only), as published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +# This program is dual-licensed. If you wish to learn more about the +# RhodeCode Enterprise Edition, including its added features, Support services, +# and proprietary license terms, please see https://rhodecode.com/licenses/ + + +import logging + +from pyramid.httpexceptions import HTTPNotFound, HTTPFound +from pyramid.view import view_config +from pyramid.renderers import render +from pyramid.response import Response + +from rhodecode.apps._base import RepoAppView +import rhodecode.lib.helpers as h +from rhodecode.lib.auth import ( + LoginRequired, HasRepoPermissionAnyDecorator) + +from rhodecode.lib.ext_json import json +from rhodecode.lib.graphmod import _colored, _dagwalker +from rhodecode.lib.helpers import RepoPage +from rhodecode.lib.utils2 import safe_int, safe_str +from rhodecode.lib.vcs.exceptions import ( + RepositoryError, CommitDoesNotExistError, + CommitError, NodeDoesNotExistError, EmptyRepositoryError) + +log = logging.getLogger(__name__) + +DEFAULT_CHANGELOG_SIZE = 20 + + +class RepoChangelogView(RepoAppView): + + def _get_commit_or_redirect(self, commit_id, redirect_after=True): + """ + This is a safe way to get commit. If an error occurs it redirects to + tip with proper message + + :param commit_id: id of commit to fetch + :param redirect_after: toggle redirection + """ + _ = self.request.translate + + try: + return self.rhodecode_vcs_repo.get_commit(commit_id) + except EmptyRepositoryError: + if not redirect_after: + return None + + h.flash(h.literal( + _('There are no commits yet')), category='warning') + raise HTTPFound( + h.route_path('repo_summary', repo_name=self.db_repo_name)) + + except (CommitDoesNotExistError, LookupError): + msg = _('No such commit exists for this repository') + h.flash(msg, category='error') + raise HTTPNotFound() + except RepositoryError as e: + h.flash(safe_str(h.escape(e)), category='error') + raise HTTPNotFound() + + def _graph(self, repo, commits, prev_data=None, next_data=None): + """ + Generates a DAG graph for repo + + :param repo: repo instance + :param commits: list of commits + """ + if not commits: + return json.dumps([]) + + def serialize(commit, parents=True): + data = dict( + raw_id=commit.raw_id, + idx=commit.idx, + branch=commit.branch, + ) + if parents: + data['parents'] = [ + serialize(x, parents=False) for x in commit.parents] + return data + + prev_data = prev_data or [] + next_data = next_data or [] + + current = [serialize(x) for x in commits] + commits = prev_data + current + next_data + + dag = _dagwalker(repo, commits) + + data = [[commit_id, vtx, edges, branch] + for commit_id, vtx, edges, branch in _colored(dag)] + return json.dumps(data), json.dumps(current) + + def _check_if_valid_branch(self, branch_name, repo_name, f_path): + if branch_name not in self.rhodecode_vcs_repo.branches_all: + h.flash('Branch {} is not found.'.format(h.escape(branch_name)), + category='warning') + redirect_url = h.route_path( + 'repo_changelog_file', repo_name=repo_name, + commit_id=branch_name, f_path=f_path or '') + raise HTTPFound(redirect_url) + + def _load_changelog_data( + self, c, collection, page, chunk_size, branch_name=None, + dynamic=False): + + def url_generator(**kw): + query_params = {} + query_params.update(kw) + return h.route_path( + 'repo_changelog', + repo_name=c.rhodecode_db_repo.repo_name, _query=query_params) + + c.total_cs = len(collection) + c.showing_commits = min(chunk_size, c.total_cs) + c.pagination = RepoPage(collection, page=page, item_count=c.total_cs, + items_per_page=chunk_size, branch=branch_name, + url=url_generator) + + c.next_page = c.pagination.next_page + c.prev_page = c.pagination.previous_page + + if dynamic: + if self.request.GET.get('chunk') != 'next': + c.next_page = None + if self.request.GET.get('chunk') != 'prev': + c.prev_page = None + + page_commit_ids = [x.raw_id for x in c.pagination] + c.comments = c.rhodecode_db_repo.get_comments(page_commit_ids) + c.statuses = c.rhodecode_db_repo.statuses(page_commit_ids) + + def load_default_context(self): + c = self._get_local_tmpl_context(include_app_defaults=True) + + # TODO(marcink): remove repo_info and use c.rhodecode_db_repo instead + c.repo_info = self.db_repo + c.rhodecode_repo = self.rhodecode_vcs_repo + + self._register_global_c(c) + return c + + @LoginRequired() + @HasRepoPermissionAnyDecorator( + 'repository.read', 'repository.write', 'repository.admin') + @view_config( + route_name='repo_changelog', request_method='GET', + renderer='rhodecode:templates/changelog/changelog.mako') + @view_config( + route_name='repo_changelog_file', request_method='GET', + renderer='rhodecode:templates/changelog/changelog.mako') + def repo_changelog(self): + c = self.load_default_context() + + commit_id = self.request.matchdict.get('commit_id') + f_path = self._get_f_path(self.request.matchdict) + + chunk_size = 20 + + c.branch_name = branch_name = self.request.GET.get('branch') or '' + c.book_name = book_name = self.request.GET.get('bookmark') or '' + hist_limit = safe_int(self.request.GET.get('limit')) or None + + p = safe_int(self.request.GET.get('page', 1), 1) + + c.selected_name = branch_name or book_name + if not commit_id and branch_name: + self._check_if_valid_branch(branch_name, self.db_repo_name, f_path) + + c.changelog_for_path = f_path + pre_load = ['author', 'branch', 'date', 'message', 'parents'] + commit_ids = [] + + partial_xhr = self.request.environ.get('HTTP_X_PARTIAL_XHR') + + try: + if f_path: + log.debug('generating changelog for path %s', f_path) + # get the history for the file ! + base_commit = self.rhodecode_vcs_repo.get_commit(commit_id) + try: + collection = base_commit.get_file_history( + f_path, limit=hist_limit, pre_load=pre_load) + if collection and partial_xhr: + # for ajax call we remove first one since we're looking + # at it right now in the context of a file commit + collection.pop(0) + except (NodeDoesNotExistError, CommitError): + # this node is not present at tip! + try: + commit = self._get_commit_or_redirect(commit_id) + collection = commit.get_file_history(f_path) + except RepositoryError as e: + h.flash(safe_str(e), category='warning') + redirect_url = h.route_path( + 'repo_changelog', repo_name=self.db_repo_name) + raise HTTPFound(redirect_url) + collection = list(reversed(collection)) + else: + collection = self.rhodecode_vcs_repo.get_commits( + branch_name=branch_name, pre_load=pre_load) + + self._load_changelog_data( + c, collection, p, chunk_size, c.branch_name, dynamic=f_path) + + except EmptyRepositoryError as e: + h.flash(safe_str(h.escape(e)), category='warning') + raise HTTPFound( + h.route_path('repo_summary', repo_name=self.db_repo_name)) + except (RepositoryError, CommitDoesNotExistError, Exception) as e: + log.exception(safe_str(e)) + h.flash(safe_str(h.escape(e)), category='error') + raise HTTPFound( + h.route_path('repo_changelog', repo_name=self.db_repo_name)) + + if partial_xhr or self.request.environ.get('HTTP_X_PJAX'): + # loading from ajax, we don't want the first result, it's popped + # in the code above + html = render( + 'rhodecode:templates/changelog/changelog_file_history.mako', + self._get_template_context(c), self.request) + return Response(html) + + if not f_path: + commit_ids = c.pagination + + c.graph_data, c.graph_commits = self._graph( + self.rhodecode_vcs_repo, commit_ids) + + return self._get_template_context(c) + + @LoginRequired() + @HasRepoPermissionAnyDecorator( + 'repository.read', 'repository.write', 'repository.admin') + @view_config( + route_name='repo_changelog_elements', request_method=('GET', 'POST'), + renderer='rhodecode:templates/changelog/changelog_elements.mako', + xhr=True) + def repo_changelog_elements(self): + c = self.load_default_context() + chunk_size = 20 + + def wrap_for_error(err): + html = '' \ + 'ERROR: {}' \ + ''.format(err) + return Response(html) + + c.branch_name = branch_name = self.request.GET.get('branch') or '' + c.book_name = book_name = self.request.GET.get('bookmark') or '' + + c.selected_name = branch_name or book_name + if branch_name and branch_name not in self.rhodecode_vcs_repo.branches_all: + return wrap_for_error( + safe_str('Branch: {} is not valid'.format(branch_name))) + + pre_load = ['author', 'branch', 'date', 'message', 'parents'] + collection = self.rhodecode_vcs_repo.get_commits( + branch_name=branch_name, pre_load=pre_load) + + p = safe_int(self.request.GET.get('page', 1), 1) + try: + self._load_changelog_data( + c, collection, p, chunk_size, dynamic=True) + except EmptyRepositoryError as e: + return wrap_for_error(safe_str(e)) + except (RepositoryError, CommitDoesNotExistError, Exception) as e: + log.exception('Failed to fetch commits') + return wrap_for_error(safe_str(e)) + + prev_data = None + next_data = None + + prev_graph = json.loads(self.request.POST.get('graph', '')) + + if self.request.GET.get('chunk') == 'prev': + next_data = prev_graph + elif self.request.GET.get('chunk') == 'next': + prev_data = prev_graph + + c.graph_data, c.graph_commits = self._graph( + self.rhodecode_vcs_repo, c.pagination, + prev_data=prev_data, next_data=next_data) + + return self._get_template_context(c) diff --git a/rhodecode/config/routing.py b/rhodecode/config/routing.py --- a/rhodecode/config/routing.py +++ b/rhodecode/config/routing.py @@ -274,7 +274,6 @@ def make_map(config): m.connect('edit_user_perms_summary', '/users/{user_id}/edit/permissions_summary', action='edit_perms_summary', conditions={'method': ['GET']}) - # ADMIN USER GROUPS REST ROUTES with rmap.submapper(path_prefix=ADMIN_PREFIX, controller='admin/user_groups') as m: @@ -698,21 +697,6 @@ def make_map(config): conditions={'function': check_repo, 'method': ['DELETE']}, requirements=URL_NAME_REQUIREMENTS, jsroute=True) - rmap.connect('changelog_home', '/{repo_name}/changelog', jsroute=True, - controller='changelog', conditions={'function': check_repo}, - requirements=URL_NAME_REQUIREMENTS) - - rmap.connect('changelog_file_home', - '/{repo_name}/changelog/{revision}/{f_path}', - controller='changelog', f_path=None, - conditions={'function': check_repo}, - requirements=URL_NAME_REQUIREMENTS, jsroute=True) - - rmap.connect('changelog_elements', '/{repo_name}/changelog_details', - controller='changelog', action='changelog_elements', - conditions={'function': check_repo}, - requirements=URL_NAME_REQUIREMENTS, jsroute=True) - rmap.connect('repo_fork_create_home', '/{repo_name}/fork', controller='forks', action='fork_create', conditions={'function': check_repo, 'method': ['POST']}, diff --git a/rhodecode/controllers/changelog.py b/rhodecode/controllers/changelog.py deleted file mode 100644 --- a/rhodecode/controllers/changelog.py +++ /dev/null @@ -1,257 +0,0 @@ -# -*- coding: utf-8 -*- - -# Copyright (C) 2010-2017 RhodeCode GmbH -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License, version 3 -# (only), as published by the Free Software Foundation. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -# This program is dual-licensed. If you wish to learn more about the -# RhodeCode Enterprise Edition, including its added features, Support services, -# and proprietary license terms, please see https://rhodecode.com/licenses/ - -""" -changelog controller for rhodecode -""" - -import logging - -from pylons import request, url, session, tmpl_context as c -from pylons.controllers.util import redirect -from pylons.i18n.translation import _ -from webob.exc import HTTPNotFound, HTTPBadRequest - -import rhodecode.lib.helpers as h -from rhodecode.lib.auth import ( - LoginRequired, HasRepoPermissionAnyDecorator, XHRRequired) -from rhodecode.lib.base import BaseRepoController, render -from rhodecode.lib.ext_json import json -from rhodecode.lib.graphmod import _colored, _dagwalker -from rhodecode.lib.helpers import RepoPage -from rhodecode.lib.utils2 import safe_int, safe_str -from rhodecode.lib.vcs.exceptions import ( - RepositoryError, CommitDoesNotExistError, - CommitError, NodeDoesNotExistError, EmptyRepositoryError) - -log = logging.getLogger(__name__) - -DEFAULT_CHANGELOG_SIZE = 20 - - -class ChangelogController(BaseRepoController): - - def __before__(self): - super(ChangelogController, self).__before__() - c.affected_files_cut_off = 60 - - def __get_commit_or_redirect( - self, commit_id, repo, redirect_after=True, partial=False): - """ - This is a safe way to get a commit. If an error occurs it - redirects to a commit with a proper message. If partial is set - then it does not do redirect raise and throws an exception instead. - - :param commit_id: commit to fetch - :param repo: repo instance - """ - try: - return c.rhodecode_repo.get_commit(commit_id) - except EmptyRepositoryError: - if not redirect_after: - return None - h.flash(_('There are no commits yet'), category='warning') - redirect(url('changelog_home', repo_name=repo.repo_name)) - except RepositoryError as e: - log.exception(safe_str(e)) - h.flash(safe_str(h.escape(e)), category='warning') - if not partial: - redirect(h.url('changelog_home', repo_name=repo.repo_name)) - raise HTTPBadRequest() - - def _graph(self, repo, commits, prev_data=None, next_data=None): - """ - Generates a DAG graph for repo - - :param repo: repo instance - :param commits: list of commits - """ - if not commits: - return json.dumps([]) - - def serialize(commit, parents=True): - data = dict( - raw_id=commit.raw_id, - idx=commit.idx, - branch=commit.branch, - ) - if parents: - data['parents'] = [ - serialize(x, parents=False) for x in commit.parents] - return data - - prev_data = prev_data or [] - next_data = next_data or [] - - current = [serialize(x) for x in commits] - commits = prev_data + current + next_data - - dag = _dagwalker(repo, commits) - - data = [[commit_id, vtx, edges, branch] - for commit_id, vtx, edges, branch in _colored(dag)] - return json.dumps(data), json.dumps(current) - - def _check_if_valid_branch(self, branch_name, repo_name, f_path): - if branch_name not in c.rhodecode_repo.branches_all: - h.flash('Branch {} is not found.'.format(h.escape(branch_name)), - category='warning') - redirect(url('changelog_file_home', repo_name=repo_name, - revision=branch_name, f_path=f_path or '')) - - def _load_changelog_data(self, collection, page, chunk_size, branch_name=None, dynamic=False): - c.total_cs = len(collection) - c.showing_commits = min(chunk_size, c.total_cs) - c.pagination = RepoPage(collection, page=page, item_count=c.total_cs, - items_per_page=chunk_size, branch=branch_name) - - c.next_page = c.pagination.next_page - c.prev_page = c.pagination.previous_page - - if dynamic: - if request.GET.get('chunk') != 'next': - c.next_page = None - if request.GET.get('chunk') != 'prev': - c.prev_page = None - - page_commit_ids = [x.raw_id for x in c.pagination] - c.comments = c.rhodecode_db_repo.get_comments(page_commit_ids) - c.statuses = c.rhodecode_db_repo.statuses(page_commit_ids) - - @LoginRequired() - @HasRepoPermissionAnyDecorator('repository.read', 'repository.write', - 'repository.admin') - def index(self, repo_name, revision=None, f_path=None): - commit_id = revision - chunk_size = 20 - - c.branch_name = branch_name = request.GET.get('branch', None) - c.book_name = book_name = request.GET.get('bookmark', None) - hist_limit = safe_int(request.GET.get('limit')) or None - - p = safe_int(request.GET.get('page', 1), 1) - - c.selected_name = branch_name or book_name - if not commit_id and branch_name: - self._check_if_valid_branch(branch_name, repo_name, f_path) - - c.changelog_for_path = f_path - pre_load = ['author', 'branch', 'date', 'message', 'parents'] - commit_ids = [] - - try: - if f_path: - log.debug('generating changelog for path %s', f_path) - # get the history for the file ! - base_commit = c.rhodecode_repo.get_commit(revision) - try: - collection = base_commit.get_file_history( - f_path, limit=hist_limit, pre_load=pre_load) - if (collection - and request.environ.get('HTTP_X_PARTIAL_XHR')): - # for ajax call we remove first one since we're looking - # at it right now in the context of a file commit - collection.pop(0) - except (NodeDoesNotExistError, CommitError): - # this node is not present at tip! - try: - commit = self.__get_commit_or_redirect( - commit_id, repo_name) - collection = commit.get_file_history(f_path) - except RepositoryError as e: - h.flash(safe_str(e), category='warning') - redirect(h.url('changelog_home', repo_name=repo_name)) - collection = list(reversed(collection)) - else: - collection = c.rhodecode_repo.get_commits( - branch_name=branch_name, pre_load=pre_load) - - self._load_changelog_data( - collection, p, chunk_size, c.branch_name, dynamic=f_path) - - except EmptyRepositoryError as e: - h.flash(safe_str(h.escape(e)), category='warning') - return redirect(h.route_path('repo_summary', repo_name=repo_name)) - except (RepositoryError, CommitDoesNotExistError, Exception) as e: - log.exception(safe_str(e)) - h.flash(safe_str(h.escape(e)), category='error') - return redirect(url('changelog_home', repo_name=repo_name)) - - if (request.environ.get('HTTP_X_PARTIAL_XHR') - or request.environ.get('HTTP_X_PJAX')): - # loading from ajax, we don't want the first result, it's popped - return render('changelog/changelog_file_history.mako') - - if not f_path: - commit_ids = c.pagination - - c.graph_data, c.graph_commits = self._graph( - c.rhodecode_repo, commit_ids) - - return render('changelog/changelog.mako') - - @LoginRequired() - @XHRRequired() - @HasRepoPermissionAnyDecorator( - 'repository.read', 'repository.write', 'repository.admin') - def changelog_elements(self, repo_name): - commit_id = None - chunk_size = 20 - - def wrap_for_error(err): - return 'ERROR: {}'.format(err) - - c.branch_name = branch_name = request.GET.get('branch', None) - c.book_name = book_name = request.GET.get('bookmark', None) - - p = safe_int(request.GET.get('page', 1), 1) - - c.selected_name = branch_name or book_name - if not commit_id and branch_name: - if branch_name not in c.rhodecode_repo.branches_all: - return wrap_for_error( - safe_str('Missing branch: {}'.format(branch_name))) - - pre_load = ['author', 'branch', 'date', 'message', 'parents'] - collection = c.rhodecode_repo.get_commits( - branch_name=branch_name, pre_load=pre_load) - - try: - self._load_changelog_data(collection, p, chunk_size, dynamic=True) - except EmptyRepositoryError as e: - return wrap_for_error(safe_str(e)) - except (RepositoryError, CommitDoesNotExistError, Exception) as e: - log.exception('Failed to fetch commits') - return wrap_for_error(safe_str(e)) - - prev_data = None - next_data = None - - prev_graph = json.loads(request.POST.get('graph', '')) - - if request.GET.get('chunk') == 'prev': - next_data = prev_graph - elif request.GET.get('chunk') == 'next': - prev_data = prev_graph - - c.graph_data, c.graph_commits = self._graph( - c.rhodecode_repo, c.pagination, - prev_data=prev_data, next_data=next_data) - return render('changelog/changelog_elements.mako') diff --git a/rhodecode/controllers/changeset.py b/rhodecode/controllers/changeset.py --- a/rhodecode/controllers/changeset.py +++ b/rhodecode/controllers/changeset.py @@ -149,7 +149,6 @@ class ChangesetController(BaseRepoContro def __before__(self): super(ChangesetController, self).__before__() - c.affected_files_cut_off = 60 def _index(self, commit_id_range, method): c.ignorews_url = _ignorews_url diff --git a/rhodecode/controllers/journal.py b/rhodecode/controllers/journal.py --- a/rhodecode/controllers/journal.py +++ b/rhodecode/controllers/journal.py @@ -129,9 +129,8 @@ class JournalController(BaseController): desc = action_extra() _url = None if entry.repository is not None: - _url = url('changelog_home', - repo_name=entry.repository.repo_name, - qualified=True) + _url = h.route_url('repo_changelog', + repo_name=entry.repository.repo_name) feed.add_item(title=title, pubdate=entry.action_date, @@ -172,9 +171,8 @@ class JournalController(BaseController): desc = action_extra() _url = None if entry.repository is not None: - _url = url('changelog_home', - repo_name=entry.repository.repo_name, - qualified=True) + _url = h.route_url('repo_changelog', + repo_name=entry.repository.repo_name) feed.add_item(title=title, pubdate=entry.action_date, diff --git a/rhodecode/lib/base.py b/rhodecode/lib/base.py --- a/rhodecode/lib/base.py +++ b/rhodecode/lib/base.py @@ -324,6 +324,8 @@ def attach_context_attributes(context, r context.visual.rhodecode_support_url = \ rc_config.get('rhodecode_support_url') or h.route_url('rhodecode_support') + context.visual.affected_files_cut_off = 60 + context.pre_code = rc_config.get('rhodecode_pre_code') context.post_code = rc_config.get('rhodecode_post_code') context.rhodecode_name = rc_config.get('rhodecode_title') diff --git a/rhodecode/public/js/rhodecode/base/keyboard-bindings.js b/rhodecode/public/js/rhodecode/base/keyboard-bindings.js --- a/rhodecode/public/js/rhodecode/base/keyboard-bindings.js +++ b/rhodecode/public/js/rhodecode/base/keyboard-bindings.js @@ -66,7 +66,7 @@ function setRCMouseBindings(repoName, re }); Mousetrap.bind(['g c'], function(e) { window.location = pyroutes.url( - 'changelog_home', {'repo_name': repoName}); + 'repo_changelog', {'repo_name': repoName}); }); Mousetrap.bind(['g F'], function(e) { window.location = pyroutes.url( diff --git a/rhodecode/public/js/rhodecode/routes.js b/rhodecode/public/js/rhodecode/routes.js --- a/rhodecode/public/js/rhodecode/routes.js +++ b/rhodecode/public/js/rhodecode/routes.js @@ -30,9 +30,6 @@ function registerRCRoutes() { pyroutes.register('pullrequest_update', '/%(repo_name)s/pull-request/%(pull_request_id)s', ['repo_name', 'pull_request_id']); pyroutes.register('pullrequest_comment', '/%(repo_name)s/pull-request-comment/%(pull_request_id)s', ['repo_name', 'pull_request_id']); pyroutes.register('pullrequest_comment_delete', '/%(repo_name)s/pull-request-comment/%(comment_id)s/delete', ['repo_name', 'comment_id']); - pyroutes.register('changelog_home', '/%(repo_name)s/changelog', ['repo_name']); - pyroutes.register('changelog_file_home', '/%(repo_name)s/changelog/%(revision)s/%(f_path)s', ['repo_name', 'revision', 'f_path']); - pyroutes.register('changelog_elements', '/%(repo_name)s/changelog_details', ['repo_name']); pyroutes.register('favicon', '/favicon.ico', []); pyroutes.register('robots', '/robots.txt', []); pyroutes.register('auth_home', '/_admin/auth*traverse', []); @@ -124,6 +121,9 @@ function registerRCRoutes() { pyroutes.register('repo_refs_data', '/%(repo_name)s/refs-data', ['repo_name']); pyroutes.register('repo_refs_changelog_data', '/%(repo_name)s/refs-data-changelog', ['repo_name']); pyroutes.register('repo_stats', '/%(repo_name)s/repo_stats/%(commit_id)s', ['repo_name', 'commit_id']); + pyroutes.register('repo_changelog', '/%(repo_name)s/changelog', ['repo_name']); + pyroutes.register('repo_changelog_file', '/%(repo_name)s/changelog/%(commit_id)s/%(f_path)s', ['repo_name', 'commit_id', 'f_path']); + pyroutes.register('repo_changelog_elements', '/%(repo_name)s/changelog_elements', ['repo_name']); pyroutes.register('tags_home', '/%(repo_name)s/tags', ['repo_name']); pyroutes.register('branches_home', '/%(repo_name)s/branches', ['repo_name']); pyroutes.register('bookmarks_home', '/%(repo_name)s/bookmarks', ['repo_name']); diff --git a/rhodecode/public/js/src/rhodecode/changelog.js b/rhodecode/public/js/src/rhodecode/changelog.js --- a/rhodecode/public/js/src/rhodecode/changelog.js +++ b/rhodecode/public/js/src/rhodecode/changelog.js @@ -105,7 +105,7 @@ var CommitsController = function () { urlData['branch'] = branch; } - return pyroutes.url('changelog_elements', urlData); + return pyroutes.url('repo_changelog_elements', urlData); }; this.loadNext = function (node, page, branch) { diff --git a/rhodecode/templates/base/base.mako b/rhodecode/templates/base/base.mako --- a/rhodecode/templates/base/base.mako +++ b/rhodecode/templates/base/base.mako @@ -226,7 +226,7 @@
${self.breadcrumbs('breadcrumbs_light')}
- ${ungettext('showing %d out of %d commit', 'showing %d out of %d commits', c.showing_commits) % (c.showing_commits, c.total_cs)} + ${_ungettext('showing %d out of %d commit', 'showing %d out of %d commits', c.showing_commits) % (c.showing_commits, c.total_cs)}
@@ -230,7 +230,7 @@ $("#clear_filter").on("click", function() { var filter = {'repo_name': '${c.repo_name}'}; - window.location = pyroutes.url('changelog_home', filter); + window.location = pyroutes.url('repo_changelog', filter); }); $("#branch_filter").select2({ @@ -280,7 +280,7 @@ else if (data.type == 'book'){ filter["bookmark"] = selected; } - window.location = pyroutes.url('changelog_home', filter); + window.location = pyroutes.url('repo_changelog', filter); }); commitsController = new CommitsController(); diff --git a/rhodecode/templates/changelog/changelog_elements.mako b/rhodecode/templates/changelog/changelog_elements.mako --- a/rhodecode/templates/changelog/changelog_elements.mako +++ b/rhodecode/templates/changelog/changelog_elements.mako @@ -101,7 +101,7 @@ ## branch %if commit.branch: - ${h.shorter(commit.branch)} + ${h.shorter(commit.branch)} %endif diff --git a/rhodecode/templates/data_table/_dt_elements.mako b/rhodecode/templates/data_table/_dt_elements.mako --- a/rhodecode/templates/data_table/_dt_elements.mako +++ b/rhodecode/templates/data_table/_dt_elements.mako @@ -14,7 +14,7 @@
  • - + ${_('Changelog')}
  • diff --git a/rhodecode/templates/files/files.mako b/rhodecode/templates/files/files.mako --- a/rhodecode/templates/files/files.mako +++ b/rhodecode/templates/files/files.mako @@ -219,9 +219,9 @@ if (path.indexOf("#") >= 0) { path = path.slice(0, path.indexOf("#")); } - var url = pyroutes.url('changelog_file_home', + var url = pyroutes.url('repo_changelog_file', {'repo_name': templateContext.repo_name, - 'revision': state.rev, 'f_path': path, 'limit': 6}); + 'commit_id': state.rev, 'f_path': path, 'limit': 6}); $('#file_history_container').show(); $('#file_history_container').html('
    {0}
    '.format(_gettext('Loading ...'))); diff --git a/rhodecode/templates/files/files_edit.mako b/rhodecode/templates/files/files_edit.mako --- a/rhodecode/templates/files/files_edit.mako +++ b/rhodecode/templates/files/files_edit.mako @@ -51,7 +51,7 @@ ${h.format_byte_size_binary(c.file.size)} ${c.file.mimetype}
    - + ${_('history')} diff --git a/rhodecode/templates/files/files_source.mako b/rhodecode/templates/files/files_source.mako --- a/rhodecode/templates/files/files_source.mako +++ b/rhodecode/templates/files/files_source.mako @@ -16,7 +16,7 @@ ${_('History')} - | %if c.annotate: diff --git a/rhodecode/templates/pullrequests/pullrequest_show.mako b/rhodecode/templates/pullrequests/pullrequest_show.mako --- a/rhodecode/templates/pullrequests/pullrequest_show.mako +++ b/rhodecode/templates/pullrequests/pullrequest_show.mako @@ -75,7 +75,7 @@ ## branch link is only valid if it is a branch %if c.pull_request.source_ref_parts.type == 'branch': - ${c.pull_request.source_ref_parts.type}: ${c.pull_request.source_ref_parts.name} + ${c.pull_request.source_ref_parts.type}: ${c.pull_request.source_ref_parts.name} %else: ${c.pull_request.source_ref_parts.type}: ${c.pull_request.source_ref_parts.name} %endif @@ -107,7 +107,7 @@ ## branch link is only valid if it is a branch %if c.pull_request.target_ref_parts.type == 'branch': - ${c.pull_request.target_ref_parts.type}: ${c.pull_request.target_ref_parts.name} + ${c.pull_request.target_ref_parts.type}: ${c.pull_request.target_ref_parts.name} %else: ${c.pull_request.target_ref_parts.type}: ${c.pull_request.target_ref_parts.name} %endif diff --git a/rhodecode/templates/search/search_content.mako b/rhodecode/templates/search/search_content.mako --- a/rhodecode/templates/search/search_content.mako +++ b/rhodecode/templates/search/search_content.mako @@ -65,7 +65,7 @@ for line_number in matching_lines: %endif
    - + ${_('Show Full History')} | ${h.link_to(_('Annotation'), h.route_path('repo_files:annotated', repo_name=entry.get('repository',''),commit_id=entry.get('commit_id', 'tip'),f_path=entry.get('f_path','')))} diff --git a/rhodecode/templates/summary/components.mako b/rhodecode/templates/summary/components.mako --- a/rhodecode/templates/summary/components.mako +++ b/rhodecode/templates/summary/components.mako @@ -94,7 +94,7 @@ % if commit_rev == -1: ${_ungettext('%(num)s Commit', '%(num)s Commits', 0) % {'num': 0}}, % else: - + ${_ungettext('%(num)s Commit', '%(num)s Commits', commit_rev) % {'num': commit_rev}}, % endif diff --git a/rhodecode/templates/summary/summary_commits.mako b/rhodecode/templates/summary/summary_commits.mako --- a/rhodecode/templates/summary/summary_commits.mako +++ b/rhodecode/templates/summary/summary_commits.mako @@ -74,7 +74,7 @@ ## branch %if cs.branch: - ${h.shorter(cs.branch)} + ${h.shorter(cs.branch)} %endif
    diff --git a/rhodecode/tests/functional/test_pullrequests.py b/rhodecode/tests/functional/test_pullrequests.py --- a/rhodecode/tests/functional/test_pullrequests.py +++ b/rhodecode/tests/functional/test_pullrequests.py @@ -36,6 +36,19 @@ from rhodecode.tests import ( from rhodecode.tests.utils import AssertResponse +def route_path(name, params=None, **kwargs): + import urllib + + base_url = { + 'repo_changelog':'/{repo_name}/changelog', + 'repo_changelog_file':'/{repo_name}/changelog/{commit_id}/{f_path}', + }[name].format(**kwargs) + + if params: + base_url = '{}?{}'.format(base_url, urllib.urlencode(params)) + return base_url + + @pytest.mark.usefixtures('app', 'autologin_user') @pytest.mark.backends("git", "hg") class TestPullrequestsController(object): @@ -912,14 +925,14 @@ class TestPullrequestsController(object) target_children = target.getchildren() assert len(target_children) == 1 - expected_origin_link = url( - 'changelog_home', + expected_origin_link = route_path( + 'repo_changelog', repo_name=pull_request.source_repo.scm_instance().name, - branch='origin') - expected_target_link = url( - 'changelog_home', + params=dict(branch='origin')) + expected_target_link = route_path( + 'repo_changelog', repo_name=pull_request.target_repo.scm_instance().name, - branch='target') + params=dict(branch='target')) assert origin_children[0].attrib['href'] == expected_origin_link assert origin_children[0].text == 'branch: origin' assert target_children[0].attrib['href'] == expected_target_link