changeset 2348:a07e04ef7bb4 codereview

Implemented basic compare view(for pull requests) for mercurial.
author Marcin Kuzminski <marcin@python-works.com>
date Sun, 27 May 2012 23:29:18 +0200
parents 58bcaf1b2fe2
children 0edbffa9e2e2
files rhodecode/controllers/branches.py rhodecode/controllers/compare.py rhodecode/lib/vcs/nodes.py rhodecode/public/css/style.css rhodecode/templates/changeset/diff_block.html rhodecode/templates/compare/compare_diff.html
diffstat 6 files changed, 63 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/rhodecode/controllers/branches.py	Sun May 27 23:28:22 2012 +0200
+++ b/rhodecode/controllers/branches.py	Sun May 27 23:29:18 2012 +0200
@@ -24,14 +24,15 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 import logging
+import binascii
 
 from pylons import tmpl_context as c
-import binascii
 
 from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator
 from rhodecode.lib.base import BaseRepoController, render
 from rhodecode.lib.compat import OrderedDict
 from rhodecode.lib.utils2 import safe_unicode
+
 log = logging.getLogger(__name__)
 
 
--- a/rhodecode/controllers/compare.py	Sun May 27 23:28:22 2012 +0200
+++ b/rhodecode/controllers/compare.py	Sun May 27 23:29:18 2012 +0200
@@ -25,11 +25,13 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 import logging
 import traceback
+import binascii
 
 from webob.exc import HTTPNotFound
 from pylons import request, response, session, tmpl_context as c, url
 from pylons.controllers.util import abort, redirect
 
+from rhodecode.lib import helpers as h
 from rhodecode.lib.base import BaseRepoController, render
 from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator
 from rhodecode.lib import diffs
@@ -89,12 +91,15 @@
         #case two independent repos
         if org_repo != other_repo:
             from mercurial import discovery
-            import binascii
             out = discovery.findcommonoutgoing(org_repo._repo, other_repo._repo)
             for cs in map(binascii.hexlify, out.missing):
                 changesets.append(org_repo.get_changeset(cs))
         else:
-            for cs in map(binascii.hexlify, out):
+            revs = ['ancestors(%s) and not ancestors(%s)' % (org_ref[1],
+                                                             other_ref[1])]
+            from mercurial import scmutil
+            out = scmutil.revrange(org_repo._repo, revs)
+            for cs in reversed(out):
                 changesets.append(org_repo.get_changeset(cs))
 
         return changesets
@@ -112,19 +117,18 @@
 
         c.org_ref = org_ref[1]
         c.other_ref = other_ref[1]
-        cs1 = org_repo.scm_instance.get_changeset(org_ref[1])
-        cs2 = other_repo.scm_instance.get_changeset(other_ref[1])
 
         _diff = diffs.differ(org_repo, org_ref, other_repo, other_ref)
         diff_processor = diffs.DiffProcessor(_diff, format='gitdiff')
+        _parsed = diff_processor.prepare()
 
-        diff = diff_processor.as_html(enable_comments=False)
-        stats = diff_processor.stat()
+        c.files = []
+        c.changes = {}
 
-        c.changes = [('change?', None, diff, cs1, cs2, stats,)]
+        for f in _parsed:
+            fid = h.FID('', f['filename'])
+            c.files.append([fid, f['operation'], f['filename'], f['stats']])
+            diff = diff_processor.as_html(enable_comments=False, diff_lines=[f])
+            c.changes[fid] = [f['operation'], f['filename'], diff]
 
         return render('compare/compare_diff.html')
-
-
-
-        
--- a/rhodecode/lib/vcs/nodes.py	Sun May 27 23:28:22 2012 +0200
+++ b/rhodecode/lib/vcs/nodes.py	Sun May 27 23:29:18 2012 +0200
@@ -431,8 +431,10 @@
     name, kind or state (or methods/attributes checking those two) would raise
     RemovedFileNodeError.
     """
-    ALLOWED_ATTRIBUTES = ['name', 'path', 'state', 'is_root', 'is_file',
-        'is_dir', 'kind', 'added', 'changed', 'not_changed', 'removed']
+    ALLOWED_ATTRIBUTES = [
+        'name', 'path', 'state', 'is_root', 'is_file', 'is_dir', 'kind', 
+        'added', 'changed', 'not_changed', 'removed'
+    ]
 
     def __init__(self, path):
         """
--- a/rhodecode/public/css/style.css	Sun May 27 23:28:22 2012 +0200
+++ b/rhodecode/public/css/style.css	Sun May 27 23:29:18 2012 +0200
@@ -2333,7 +2333,7 @@
     padding: 2px 0px 2px 0px;
 }
 
-.cs_files .cs_added {
+.cs_files .cs_added,.cs_files .cs_A {
 	background: url("../images/icons/page_white_add.png") no-repeat scroll
 		3px;
 	height: 16px;
@@ -2342,7 +2342,7 @@
 	text-align: left;
 }
 
-.cs_files .cs_changed {
+.cs_files .cs_changed,.cs_files .cs_M {
 	background: url("../images/icons/page_white_edit.png") no-repeat scroll
 		3px;
 	height: 16px;
@@ -2351,7 +2351,7 @@
 	text-align: left;
 }
 
-.cs_files .cs_removed {
+.cs_files .cs_removed,.cs_files .cs_D {
 	background: url("../images/icons/page_white_delete.png") no-repeat
 		scroll 3px;
 	height: 16px;
--- a/rhodecode/templates/changeset/diff_block.html	Sun May 27 23:28:22 2012 +0200
+++ b/rhodecode/templates/changeset/diff_block.html	Sun May 27 23:29:18 2012 +0200
@@ -1,12 +1,12 @@
 ## -*- coding: utf-8 -*-
 ##usage:
 ## <%namespace name="diff_block" file="/changeset/diff_block.html"/>
-## ${diff_block.diff_block(changes)}
+## ${diff_block.diff_block(change)}
 ##
-<%def name="diff_block(changes)">
+<%def name="diff_block(change)">
 
-%for change,filenode,diff,cs1,cs2,stat in changes:
-    %if change !='removed':
+%for op,filenode,diff,cs1,cs2,stat in change:
+    %if op !='removed':
     <div id="${h.FID(filenode.changeset.raw_id,filenode.path)}_target" style="clear:both;margin-top:25px"></div>
     <div id="${h.FID(filenode.changeset.raw_id,filenode.path)}" class="diffblock  margined comm">
         <div class="code-header">
@@ -39,3 +39,23 @@
 %endfor
 
 </%def>
+
+<%def name="diff_block_simple(change)">
+
+  %for op,filenode_path,diff in change:
+    <div id="${h.FID('',filenode_path)}_target" style="clear:both;margin-top:25px"></div>
+    <div id="${h.FID('',filenode_path)}" class="diffblock  margined comm">      
+      <div class="code-header">
+          <div class="changeset_header">
+              <div class="changeset_file">
+                  <a href="#">${h.safe_unicode(filenode_path)}</a>
+              </div>
+          </div>
+      </div>
+        <div class="code-body">
+            <div class="full_f_path" path="${h.safe_unicode(filenode_path)}"></div>
+            ${diff|n}
+        </div>
+    </div>
+  %endfor
+</%def>
\ No newline at end of file
--- a/rhodecode/templates/compare/compare_diff.html	Sun May 27 23:28:22 2012 +0200
+++ b/rhodecode/templates/compare/compare_diff.html	Sun May 27 23:29:18 2012 +0200
@@ -2,7 +2,7 @@
 <%inherit file="/base/base.html"/>
 
 <%def name="title()">
-    TODO FIll this in
+    ${c.repo_name} ${_('Compare')} ${'%s@%s' % (c.org_repo.repo_name, c.org_ref)} -> ${'%s@%s' % (c.other_repo.repo_name, c.other_ref)}
 </%def>
 
 <%def name="breadcrumbs_links()">
@@ -10,7 +10,7 @@
     &raquo;
     ${h.link_to(c.repo_name,h.url('summary_home',repo_name=c.repo_name))}
     &raquo;
-    TODO! 
+    ${_('Compare')}
 </%def>
 
 <%def name="page_nav()">
@@ -35,7 +35,7 @@
         <div id="changeset_compare_view_content">
             <div class="container">
             <table class="compare_view_commits noborder">
-            %for cnt,cs in enumerate(c.cs_ranges):
+            %for cnt, cs in enumerate(c.cs_ranges):
                 <tr>
                 <td><div class="gravatar"><img alt="gravatar" src="${h.gravatar_url(h.email(cs.author),14)}"/></div></td>
                 <td>${h.link_to('r%s:%s' % (cs.revision,h.short_id(cs.raw_id)),h.url('changeset_home',repo_name=c.repo_name,revision=cs.raw_id))}</td>
@@ -53,14 +53,22 @@
             </div>
             <div style="font-size:1.1em;font-weight: bold;clear:both;padding-top:10px">${_('Files affected')}</div>
             <div class="cs_files">
-              %for change,filenode,diff,cs1,cs2,st in c.changes[cs.raw_id]:
-                  <div class="cs_${change}">${h.link_to(h.safe_unicode(filenode.path),h.url.current(anchor=h.FID(cs.raw_id,filenode.path)))}</div>
+              %for fid, change, f, stat in c.files:              
+                  <div class="cs_${change}">
+                    <div class="node">${h.link_to(h.safe_unicode(f),h.url.current(anchor=fid))}</div>
+                    <div class="changes">${h.fancy_file_stats(stat)}</div>
+                  </div>
               %endfor
             </div>
         </div>
-
     </div>
-
+    
+    ## diff block
+    <%namespace name="diff_block" file="/changeset/diff_block.html"/>
+    %for fid, change, f, stat in c.files:
+      ${diff_block.diff_block_simple([c.changes[fid]])}
+    %endfor
+    
      <script type="text/javascript">
 
       YUE.onDOMReady(function(){