changeset 3760:6302a1423a4e beta

Use changelog controller for displaying history of files. step 1 for removing obsolete shortlog
author Marcin Kuzminski <marcin@python-works.com>
date Mon, 15 Apr 2013 21:58:40 +0200
parents 12ca667b69b6
children 087b50ef7e17
files rhodecode/config/routing.py rhodecode/controllers/changelog.py rhodecode/templates/changelog/changelog.html rhodecode/templates/files/files_history_box.html rhodecode/tests/functional/test_changelog.py rhodecode/tests/functional/test_shortlog.py
diffstat 6 files changed, 106 insertions(+), 80 deletions(-) [+]
line wrap: on
line diff
--- a/rhodecode/config/routing.py	Wed Apr 03 15:56:12 2013 +0200
+++ b/rhodecode/config/routing.py	Mon Apr 15 21:58:40 2013 +0200
@@ -589,10 +589,6 @@
     rmap.connect('shortlog_home', '/{repo_name:.*?}/shortlog',
                 controller='shortlog', conditions=dict(function=check_repo))
 
-    rmap.connect('shortlog_file_home', '/{repo_name:.*?}/shortlog/{revision}/{f_path:.*}',
-                controller='shortlog', f_path=None,
-                conditions=dict(function=check_repo))
-
     rmap.connect('branches_home', '/{repo_name:.*?}/branches',
                 controller='branches', conditions=dict(function=check_repo))
 
@@ -605,6 +601,10 @@
     rmap.connect('changelog_home', '/{repo_name:.*?}/changelog',
                 controller='changelog', conditions=dict(function=check_repo))
 
+    rmap.connect('changelog_file_home', '/{repo_name:.*?}/changelog/{revision}/{f_path:.*}',
+                controller='changelog', f_path=None,
+                conditions=dict(function=check_repo))
+
     rmap.connect('changelog_details', '/{repo_name:.*?}/changelog_details/{cs}',
                 controller='changelog', action='changelog_details',
                 conditions=dict(function=check_repo))
--- a/rhodecode/controllers/changelog.py	Wed Apr 03 15:56:12 2013 +0200
+++ b/rhodecode/controllers/changelog.py	Mon Apr 15 21:58:40 2013 +0200
@@ -36,7 +36,8 @@
 from rhodecode.lib.helpers import RepoPage
 from rhodecode.lib.compat import json
 from rhodecode.lib.graphmod import _colored, _dagwalker
-from rhodecode.lib.vcs.exceptions import RepositoryError, ChangesetDoesNotExistError
+from rhodecode.lib.vcs.exceptions import RepositoryError, ChangesetDoesNotExistError,\
+    ChangesetError, NodeDoesNotExistError
 from rhodecode.lib.utils2 import safe_int
 
 log = logging.getLogger(__name__)
@@ -75,7 +76,7 @@
     @LoginRequired()
     @HasRepoPermissionAnyDecorator('repository.read', 'repository.write',
                                    'repository.admin')
-    def index(self):
+    def index(self, repo_name, revision=None, f_path=None):
         limit = 100
         default = 20
         if request.GET.get('size'):
@@ -88,9 +89,27 @@
         c.size = max(c.size, 1)
         p = safe_int(request.GET.get('page', 1), 1)
         branch_name = request.GET.get('branch', None)
+        c.changelog_for_path = f_path
         try:
-            collection = c.rhodecode_repo.get_changesets(start=0,
-                                                    branch_name=branch_name)
+
+            if f_path:
+                log.debug('generating changelog for path %s' % f_path)
+                # get the history for the file !
+                tip_cs = c.rhodecode_repo.get_changeset()
+                try:
+                    collection = tip_cs.get_file_history(f_path)
+                except (NodeDoesNotExistError, ChangesetError):
+                    #this node is not present at tip !
+                    try:
+                        cs = self.__get_cs_or_redirect(revision, repo_name)
+                        collection = cs.get_file_history(f_path)
+                    except RepositoryError, e:
+                        h.flash(str(e), category='warning')
+                        redirect(h.url('changelog_home', repo_name=repo_name))
+                collection = list(reversed(collection))
+            else:
+                collection = c.rhodecode_repo.get_changesets(start=0,
+                                                        branch_name=branch_name)
             c.total_cs = len(collection)
 
             c.pagination = RepoPage(collection, page=p, item_count=c.total_cs,
@@ -107,9 +126,10 @@
         c.branch_name = branch_name
         c.branch_filters = [('', _('All Branches'))] + \
             [(k, k) for k in c.rhodecode_repo.branches.keys()]
-
-        self._graph(c.rhodecode_repo, [x.revision for x in c.pagination],
-                    c.total_cs, c.size, p)
+        _revs = []
+        if not f_path:
+            _revs = [x.revision for x in c.pagination]
+        self._graph(c.rhodecode_repo, _revs, c.total_cs, c.size, p)
 
         return render('changelog/changelog.html')
 
--- a/rhodecode/templates/changelog/changelog.html	Wed Apr 03 15:56:12 2013 +0200
+++ b/rhodecode/templates/changelog/changelog.html	Mon Apr 15 21:58:40 2013 +0200
@@ -25,26 +25,28 @@
     <div class="table">
         % if c.pagination:
             <div id="graph">
-                <div class="info_box" style="clear: both;padding: 10px 6px;min-height: 12px;text-align: right;">
-                    <a href="#" class="ui-btn small" id="rev_range_container" style="display:none"></a>
-                    <a href="#" class="ui-btn small" id="rev_range_clear" style="display:none">${_('Clear selection')}</a>
+                <div style="display:${'none' if c.changelog_for_path else ''}">
+                    <div class="info_box" style="clear: both;padding: 10px 6px;min-height: 12px;text-align: right;">
+                        <a href="#" class="ui-btn small" id="rev_range_container" style="display:none"></a>
+                        <a href="#" class="ui-btn small" id="rev_range_clear" style="display:none">${_('Clear selection')}</a>
 
-                    %if c.rhodecode_db_repo.fork:
-                        <a id="compare_fork" title="${_('Compare fork with %s' % c.rhodecode_db_repo.fork.repo_name)}" href="${h.url('compare_url',repo_name=c.rhodecode_db_repo.fork.repo_name,org_ref_type='branch',org_ref='default',other_repo=c.repo_name,other_ref_type='branch',other_ref=request.GET.get('branch') or 'default',merge=1)}" class="ui-btn small">${_('Compare fork with parent')}</a>
-                    %endif
-                    %if h.is_hg(c.rhodecode_repo):
-                    <a id="open_new_pr" href="${h.url('pullrequest_home',repo_name=c.repo_name)}" class="ui-btn small">${_('Open new pull request')}</a>
-                    %endif
-                </div>
-                <div class="container_header">
-                    ${h.form(h.url.current(),method='get')}
-                    <div style="float:left">
-                        ${h.submit('set',_('Show'),class_="ui-btn")}
-                        ${h.text('size',size=1,value=c.size)}
-                        ${_('revisions')}
+                        %if c.rhodecode_db_repo.fork:
+                            <a id="compare_fork" title="${_('Compare fork with %s' % c.rhodecode_db_repo.fork.repo_name)}" href="${h.url('compare_url',repo_name=c.rhodecode_db_repo.fork.repo_name,org_ref_type='branch',org_ref='default',other_repo=c.repo_name,other_ref_type='branch',other_ref=request.GET.get('branch') or 'default',merge=1)}" class="ui-btn small">${_('Compare fork with parent')}</a>
+                        %endif
+                        %if h.is_hg(c.rhodecode_repo):
+                        <a id="open_new_pr" href="${h.url('pullrequest_home',repo_name=c.repo_name)}" class="ui-btn small">${_('Open new pull request')}</a>
+                        %endif
                     </div>
-                    ${h.end_form()}
-                    <div style="float:right">${h.select('branch_filter',c.branch_name,c.branch_filters)}</div>
+                    <div class="container_header">
+                        ${h.form(h.url.current(),method='get')}
+                        <div style="float:left">
+                            ${h.submit('set',_('Show'),class_="ui-btn")}
+                            ${h.text('size',size=1,value=c.size)}
+                            ${_('revisions')}
+                        </div>
+                        ${h.end_form()}
+                        <div style="float:right">${h.select('branch_filter',c.branch_name,c.branch_filters)}</div>
+                    </div>
                 </div>
                 <div id="graph_nodes">
                     <canvas id="graph_canvas"></canvas>
@@ -56,7 +58,11 @@
                 %for cnt,cs in enumerate(c.pagination):
                     <tr id="chg_${cnt+1}" class="container ${'tablerow%s' % (cnt%2)}">
                         <td class="checkbox">
-                            ${h.checkbox(cs.raw_id,class_="changeset_range")}
+                            %if c.changelog_for_path:
+                                ${h.checkbox(cs.raw_id,class_="changeset_range", disabled="disabled")}
+                            %else:
+                                ${h.checkbox(cs.raw_id,class_="changeset_range")}
+                            %endif
                         <td class="status">
                           %if c.statuses.get(cs.raw_id):
                             <div class="changeset-status-ico">
--- a/rhodecode/templates/files/files_history_box.html	Wed Apr 03 15:56:12 2013 +0200
+++ b/rhodecode/templates/files/files_history_box.html	Mon Apr 15 21:58:40 2013 +0200
@@ -8,7 +8,7 @@
             ${h.select('diff1',c.file_changeset.raw_id,c.file_history)}
             ${h.submit('diff',_('Diff to revision'),class_="ui-btn")}
             ${h.submit('show_rev',_('Show at revision'),class_="ui-btn")}
-            ${h.link_to(_('Show full history'),h.url('shortlog_file_home',repo_name=c.repo_name, revision=c.file_changeset.raw_id, f_path=c.f_path),class_="ui-btn")}
+            ${h.link_to(_('Show full history'),h.url('changelog_file_home',repo_name=c.repo_name, revision=c.file_changeset.raw_id, f_path=c.f_path),class_="ui-btn")}
             ${h.hidden('annotate', c.annotate)}
             ${h.end_form()}
             </div>
--- a/rhodecode/tests/functional/test_changelog.py	Wed Apr 03 15:56:12 2013 +0200
+++ b/rhodecode/tests/functional/test_changelog.py	Mon Apr 15 21:58:40 2013 +0200
@@ -124,3 +124,52 @@
         response.mustcontain(
             """<span class="changeset_hash">r515:636ed213f2f1</span>"""
         )
+
+    def test_index_hg_with_filenode(self):
+        self.log_user()
+        response = self.app.get(url(controller='changelog', action='index',
+                                    revision='tip', f_path='/vcs/exceptions.py',
+                                    repo_name=HG_REPO))
+        #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')
+        # Test response...
+
+    def test_index_git_with_filenode(self):
+        self.log_user()
+        response = self.app.get(url(controller='changelog', action='index',
+                                    revision='tip', f_path='/vcs/exceptions.py',
+                                    repo_name=GIT_REPO))
+        #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_hg_with_filenode_that_is_dirnode(self):
+        self.log_user()
+        response = self.app.get(url(controller='changelog', action='index',
+                                    revision='tip', f_path='/tests',
+                                    repo_name=HG_REPO))
+        self.assertEqual(response.status, '302 Found')
+
+    def test_index_git_with_filenode_that_is_dirnode(self):
+        self.log_user()
+        response = self.app.get(url(controller='changelog', action='index',
+                                    revision='tip', f_path='/tests',
+                                    repo_name=GIT_REPO))
+        self.assertEqual(response.status, '302 Found')
+
+    def test_index_hg_with_filenode_not_existing(self):
+        self.log_user()
+        response = self.app.get(url(controller='changelog', action='index',
+                                    revision='tip', f_path='/wrong_path',
+                                    repo_name=HG_REPO))
+        self.assertEqual(response.status, '302 Found')
+
+    def test_index_git_with_filenode_not_existing(self):
+        self.log_user()
+        response = self.app.get(url(controller='changelog', action='index',
+                                    revision='tip', f_path='/wrong_path',
+                                    repo_name=GIT_REPO))
+        self.assertEqual(response.status, '302 Found')
--- a/rhodecode/tests/functional/test_shortlog.py	Wed Apr 03 15:56:12 2013 +0200
+++ b/rhodecode/tests/functional/test_shortlog.py	Mon Apr 15 21:58:40 2013 +0200
@@ -14,52 +14,3 @@
         response = self.app.get(url(controller='shortlog', action='index',
                                     repo_name=GIT_REPO))
         # Test response...
-
-    def test_index_hg_with_filenode(self):
-        self.log_user()
-        response = self.app.get(url(controller='shortlog', action='index',
-                                    revision='tip', f_path='/vcs/exceptions.py',
-                                    repo_name=HG_REPO))
-        #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')
-        # Test response...
-
-    def test_index_git_with_filenode(self):
-        self.log_user()
-        response = self.app.get(url(controller='shortlog', action='index',
-                                    revision='tip', f_path='/vcs/exceptions.py',
-                                    repo_name=GIT_REPO))
-        #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_hg_with_filenode_that_is_dirnode(self):
-        self.log_user()
-        response = self.app.get(url(controller='shortlog', action='index',
-                                    revision='tip', f_path='/tests',
-                                    repo_name=HG_REPO))
-        self.assertEqual(response.status, '302 Found')
-
-    def test_index_git_with_filenode_that_is_dirnode(self):
-        self.log_user()
-        response = self.app.get(url(controller='shortlog', action='index',
-                                    revision='tip', f_path='/tests',
-                                    repo_name=GIT_REPO))
-        self.assertEqual(response.status, '302 Found')
-
-    def test_index_hg_with_filenode_not_existing(self):
-        self.log_user()
-        response = self.app.get(url(controller='shortlog', action='index',
-                                    revision='tip', f_path='/wrong_path',
-                                    repo_name=HG_REPO))
-        self.assertEqual(response.status, '302 Found')
-
-    def test_index_git_with_filenode_not_existing(self):
-        self.log_user()
-        response = self.app.get(url(controller='shortlog', action='index',
-                                    revision='tip', f_path='/wrong_path',
-                                    repo_name=GIT_REPO))
-        self.assertEqual(response.status, '302 Found')