Changeset - a07e04ef7bb4
[Not reviewed]
codereview
0 6 0
Marcin Kuzminski - 13 years ago 2012-05-27 23:29:18
marcin@python-works.com
Implemented basic compare view(for pull requests) for mercurial.
6 files changed with 61 insertions and 26 deletions:
0 comments (0 inline, 0 general)
rhodecode/controllers/branches.py
Show inline comments
 
@@ -21,20 +21,21 @@
 
# GNU General Public License for more details.
 
#
 
# You should have received a copy of the GNU General Public License
 
# 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__)
 

	
 

	
 
class BranchesController(BaseRepoController):
 

	
 
    @LoginRequired()
rhodecode/controllers/compare.py
Show inline comments
 
@@ -22,17 +22,19 @@
 
# GNU General Public License for more details.
 
#
 
# You should have received a copy of the GNU General Public License
 
# 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
 

	
 
from rhodecode.model.db import Repository
 

	
 
@@ -86,18 +88,21 @@ class CompareController(BaseRepoControll
 

	
 
    def _get_changesets(self, org_repo, org_ref, other_repo, other_ref):
 
        changesets = []
 
        #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
 

	
 
    def index(self, ref):
 
        org_repo, org_ref, other_repo, other_ref = self._handle_ref(ref)
 
@@ -109,22 +114,21 @@ class CompareController(BaseRepoControll
 
                                           org_ref,
 
                                           other_repo.scm_instance,
 
                                           other_ref)
 

	
 
        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')
 

	
 

	
 

	
 
        
rhodecode/lib/vcs/nodes.py
Show inline comments
 
@@ -428,14 +428,16 @@ class FileNode(Node):
 
class RemovedFileNode(FileNode):
 
    """
 
    Dummy FileNode class - trying to access any public attribute except path,
 
    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):
 
        """
 
        :param path: relative path to the node
 
        """
 
        super(RemovedFileNode, self).__init__(path=path)
rhodecode/public/css/style.css
Show inline comments
 
@@ -2330,31 +2330,31 @@ h3.files_location {
 
	float: left;
 
	text-align: center;
 
	font-size: 9px;
 
    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;
 
	padding-left: 20px;
 
	margin-top: 7px;
 
	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;
 
	padding-left: 20px;
 
	margin-top: 7px;
 
	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;
 
	padding-left: 20px;
 
	margin-top: 7px;
 
	text-align: left;
rhodecode/templates/changeset/diff_block.html
Show inline comments
 
## -*- 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">
 
            <div class="changeset_header">
 
                <div class="changeset_file">
 
                    ${h.link_to_if(change!='removed',h.safe_unicode(filenode.path),h.url('files_home',repo_name=c.repo_name,
 
@@ -36,6 +36,26 @@
 
        </div>
 
    </div>
 
    %endif
 
%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
rhodecode/templates/compare/compare_diff.html
Show inline comments
 
## -*- coding: utf-8 -*-
 
<%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()">
 
    ${h.link_to(u'Home',h.url('/'))}
 
    &raquo;
 
    ${h.link_to(c.repo_name,h.url('summary_home',repo_name=c.repo_name))}
 
    &raquo;
 
    TODO! 
 
    ${_('Compare')}
 
</%def>
 

	
 
<%def name="page_nav()">
 
    ${self.menu('changelog')}
 
</%def>
 

	
 
@@ -50,19 +50,27 @@
 
                </tr>
 
            %endfor
 
            </table>
 
            </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>
 

	
 
    </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(){
 

	
 
          YUE.on(YUQ('.diff-menu-activate'),'click',function(e){
0 comments (0 inline, 0 general)