Changeset - f905f45c457e
[Not reviewed]
default
1 5 0
Marcin Kuzminski - 16 years ago 2010-05-17 01:51:47
marcin@python-works.com
moved diff libs to vcs. updated htmls and css for diff and source
6 files changed with 21 insertions and 251 deletions:
0 comments (0 inline, 0 general)
pylons_app/controllers/files.py
Show inline comments
 
import logging
 

	
 
from pylons import request, response, session, tmpl_context as c, url, config, app_globals as g
 
from pylons.controllers.util import abort, redirect
 

	
 
from pylons_app.lib.base import BaseController, render
 
from pylons_app.lib.utils import get_repo_slug
 
from pylons_app.model.hg_model import HgModel
 
from difflib import unified_diff
 
from pylons_app.lib.differ import render_udiff
 
from vcs.utils import diffs as differ
 
from vcs.exceptions import RepositoryError, ChangesetError
 
        
 
log = logging.getLogger(__name__)
 

	
 
class FilesController(BaseController):
 
    def __before__(self):
 
        c.repos_prefix = config['repos_name']
 
        c.repo_name = get_repo_slug(request)
 

	
 
    def index(self, repo_name, revision, f_path):
 
        hg_model = HgModel()
 
        c.repo = repo = hg_model.get_repo(c.repo_name)
 
@@ -74,39 +73,32 @@ class FilesController(BaseController):
 
    def archivefile(self, repo_name, revision, fileformat):
 
        return '%s %s %s' % (repo_name, revision, fileformat)
 
    
 
    def diff(self, repo_name, f_path):
 
        hg_model = HgModel()
 
        diff1 = request.GET.get('diff1')
 
        diff2 = request.GET.get('diff2')
 
        c.no_changes = diff1 == diff2
 
        c.f_path = f_path
 
        c.repo = hg_model.get_repo(c.repo_name)
 
        c.changeset_1 = c.repo.get_changeset(diff1)
 
        c.changeset_2 = c.repo.get_changeset(diff2)
 
        f1 = c.changeset_1.get_node(f_path)
 
        f2 = c.changeset_2.get_node(f_path)
 

	
 
        c.diff1 = 'r%s:%s' % (c.changeset_1.revision, c.changeset_1._short)
 
        c.diff2 = 'r%s:%s' % (c.changeset_2.revision, c.changeset_2._short)
 

	
 
        f_udiff = unified_diff(f1.content.splitlines(True),
 
                               f2.content.splitlines(True),
 
                               f1.name,
 
                               f2.name)
 
        
 
        
 
        c.diff_files = render_udiff(udiff=f_udiff, differ='difflib')
 
        print c.diff_files
 
        if len(c.diff_files) < 1:
 
            c.no_changes = True
 
        f_udiff = differ.get_udiff(c.changeset_1.get_node(f_path),
 
                            c.changeset_2.get_node(f_path))
 
        c.differ = differ.DiffProcessor(f_udiff)
 
        return render('files/file_diff.html')
 
    
 
    def _get_history(self, repo, node, f_path):
 
        from vcs.nodes import NodeKind
 
        if not node.kind is NodeKind.FILE:
 
            return []
 
        changesets = node.history
 
        hist_l = []
 
        for chs in changesets:
 
            n_desc = 'r%s:%s' % (chs.revision, chs._short)
 
            hist_l.append((chs._short, n_desc,))
 
        return hist_l
pylons_app/lib/differ.py
Show inline comments
 
deleted file
pylons_app/public/css/diff.css
Show inline comments
 
@@ -15,24 +15,32 @@ div.diffblock .code-header{
 
	padding:10px 0 10px 0;
 
}
 
div.diffblock .code-header span{
 
	margin-left:25px;
 
	font-weight: bold;
 
}
 
div.diffblock .code-body{
 
	background: #EEEEEE;
 
}
 

	
 
.code-difftable{
 
	border-collapse: collapse;
 
	width: 99%;
 
}
 
.code-difftable td:target *{
 
	background:  repeat scroll 0 0 #FFFFBE !important;
 
	text-decoration: underline;
 
}
 
.code-difftable .context{
 
	background:none repeat scroll 0 0 #DDE7EF;
 
}
 
.code-difftable .add{
 
	background:none repeat scroll 0 0 #DDFFDD;
 
}
 
.code-difftable .add ins{
 
	background:none repeat scroll 0 0 #AAFFAA;
 
	text-decoration:none;
 
}
 

	
 
.code-difftable .del{
 
	background:none repeat scroll 0 0 #FFDDDD;
 
}
pylons_app/public/css/pygments.css
Show inline comments
 
@@ -5,28 +5,32 @@ div.codeblock {
 
    background: #f8f8f8;
 
    font-size: 100%;
 
    line-height: 100%;
 
    /* new */
 
    line-height: 125%;
 
}
 
div.codeblock .code-header{
 
	border-bottom: 1px solid #CCCCCC;
 
	background: #EEEEEE;
 
	color:blue;
 
	padding:10px 0 10px 0;
 
}
 
div.codeblock .code-header span{
 
div.codeblock .code-header .revision{
 
	margin-left:25px;
 
	font-weight: bold;
 
}
 
div.codeblock .code-header .commit{
 
	margin-left:25px;
 
	font-weight: normal;
 
}
 

	
 
.code-highlight {
 
    padding: 0px;
 
    margin-top: 5px;
 
    margin-bottom: 5px;
 
    border-left: 2px solid #ccc;
 
}
 
.code-highlight pre, .linenodiv pre { 
 
	padding: 5px;
 
    margin: 0;
 
}
 
.linenos a { text-decoration: none; }
pylons_app/templates/files/file_diff.html
Show inline comments
 
@@ -25,35 +25,17 @@
 
<link rel="stylesheet" href="/css/diff.css" type="text/css" />
 
</%def>
 
<%def name="main()">
 
    <h2 class="no-link no-border">${'%s:  %s %s %s' % (_('File diff'),c.diff2,'&rarr;',c.diff1)|n}</h2>
 
<div id="body" class="diffblock">
 
	<div class="code-header">
 
		<span>${h.link_to(c.f_path,h.url('files_home',repo_name=c.repo_name,revision=c.diff2.split(':')[1],f_path=c.f_path))}</span>
 
	</div>
 
	<div class="code-body">
 
 			%if c.no_changes:
 
            	${_('No changes')}
 
            %else:        
 
	            <table class='code-difftable'>
 
	            %for diff in c.diff_files:
 
		            %for x in diff['chunks']:
 
		                %for y in x:
 
		                    <tr class="line ${y['action']}">
 
		                        <td id="#${diff['filename']}_O${y['old_lineno']}" class="lineno old">
 
		                              <pre><a href="#${diff['filename']}_O${y['old_lineno']}">${y['old_lineno']}</a></pre>
 
		                        </td>		                    
 
		                        <td id="#${diff['filename']}_N${y['new_lineno']}"class="lineno new">
 
		                              <pre><a href="#${diff['filename']}_N${y['new_lineno']}">${y['new_lineno']}</a></pre>
 
		                        </td>                        
 
		                       <td class="code">
 
		                           <pre>${y['line']|n}</pre>
 
		                       </td>
 
		                    </tr>
 
		                %endfor$
 
		            %endfor
 
		        %endfor
 
	            </table>
 
				${c.differ.as_HTML()|n}
 
            %endif
 
	</div>
 
</div>
 
</%def>    
 
\ No newline at end of file
pylons_app/templates/files/files_source.html
Show inline comments
 
@@ -8,19 +8,19 @@
 
	<dt>${_('History')}</dt>
 
	<dd>
 
		${h.form(h.url('files_diff_home',repo_name=c.repo_name,f_path=c.f_path),method='GET')}
 
		${h.hidden('diff2',c.files_list.last_changeset._short)}
 
		${h.select('diff1','',c.file_history)}
 
		${h.submit('diff','diff')}
 
		${h.end_form()}
 
	</dd>
 
					
 
</dl>		
 
<div id="body" class="codeblock">
 
	<div class="code-header">
 
		<span>${c.files_list.name}@r${c.files_list.last_changeset.revision}:${c.files_list.last_changeset._short}</span>
 
		 <span style="font-size:70%">"${c.file_msg}"</span>
 
		<div class="revision">${c.files_list.name}@r${c.files_list.last_changeset.revision}:${c.files_list.last_changeset._short}</div>
 
		<div class="commit" style="font-size:70%">"${c.file_msg}"</div>
 
	</div>
 
	<div class="code-body">
 
		${h.pygmentize(c.files_list.content,linenos=True,anchorlinenos=True,cssclass="code-highlight")}
 
	</div>
 
</div>
 
\ No newline at end of file
0 comments (0 inline, 0 general)