##// END OF EJS Templates
Implemented basic compare view(for pull requests) for mercurial.
marcink -
r2348:a07e04ef codereview
parent child Browse files
Show More
@@ -24,14 +24,15 b''
24 24 # along with this program. If not, see <http://www.gnu.org/licenses/>.
25 25
26 26 import logging
27 import binascii
27 28
28 29 from pylons import tmpl_context as c
29 import binascii
30 30
31 31 from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator
32 32 from rhodecode.lib.base import BaseRepoController, render
33 33 from rhodecode.lib.compat import OrderedDict
34 34 from rhodecode.lib.utils2 import safe_unicode
35
35 36 log = logging.getLogger(__name__)
36 37
37 38
@@ -25,11 +25,13 b''
25 25 # along with this program. If not, see <http://www.gnu.org/licenses/>.
26 26 import logging
27 27 import traceback
28 import binascii
28 29
29 30 from webob.exc import HTTPNotFound
30 31 from pylons import request, response, session, tmpl_context as c, url
31 32 from pylons.controllers.util import abort, redirect
32 33
34 from rhodecode.lib import helpers as h
33 35 from rhodecode.lib.base import BaseRepoController, render
34 36 from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator
35 37 from rhodecode.lib import diffs
@@ -89,12 +91,15 b' class CompareController(BaseRepoControll'
89 91 #case two independent repos
90 92 if org_repo != other_repo:
91 93 from mercurial import discovery
92 import binascii
93 94 out = discovery.findcommonoutgoing(org_repo._repo, other_repo._repo)
94 95 for cs in map(binascii.hexlify, out.missing):
95 96 changesets.append(org_repo.get_changeset(cs))
96 97 else:
97 for cs in map(binascii.hexlify, out):
98 revs = ['ancestors(%s) and not ancestors(%s)' % (org_ref[1],
99 other_ref[1])]
100 from mercurial import scmutil
101 out = scmutil.revrange(org_repo._repo, revs)
102 for cs in reversed(out):
98 103 changesets.append(org_repo.get_changeset(cs))
99 104
100 105 return changesets
@@ -112,19 +117,18 b' class CompareController(BaseRepoControll'
112 117
113 118 c.org_ref = org_ref[1]
114 119 c.other_ref = other_ref[1]
115 cs1 = org_repo.scm_instance.get_changeset(org_ref[1])
116 cs2 = other_repo.scm_instance.get_changeset(other_ref[1])
117 120
118 121 _diff = diffs.differ(org_repo, org_ref, other_repo, other_ref)
119 122 diff_processor = diffs.DiffProcessor(_diff, format='gitdiff')
123 _parsed = diff_processor.prepare()
120 124
121 diff = diff_processor.as_html(enable_comments=False)
122 stats = diff_processor.stat()
125 c.files = []
126 c.changes = {}
123 127
124 c.changes = [('change?', None, diff, cs1, cs2, stats,)]
128 for f in _parsed:
129 fid = h.FID('', f['filename'])
130 c.files.append([fid, f['operation'], f['filename'], f['stats']])
131 diff = diff_processor.as_html(enable_comments=False, diff_lines=[f])
132 c.changes[fid] = [f['operation'], f['filename'], diff]
125 133
126 134 return render('compare/compare_diff.html')
127
128
129
130
@@ -431,8 +431,10 b' class RemovedFileNode(FileNode):'
431 431 name, kind or state (or methods/attributes checking those two) would raise
432 432 RemovedFileNodeError.
433 433 """
434 ALLOWED_ATTRIBUTES = ['name', 'path', 'state', 'is_root', 'is_file',
435 'is_dir', 'kind', 'added', 'changed', 'not_changed', 'removed']
434 ALLOWED_ATTRIBUTES = [
435 'name', 'path', 'state', 'is_root', 'is_file', 'is_dir', 'kind',
436 'added', 'changed', 'not_changed', 'removed'
437 ]
436 438
437 439 def __init__(self, path):
438 440 """
@@ -2333,7 +2333,7 b' h3.files_location {'
2333 2333 padding: 2px 0px 2px 0px;
2334 2334 }
2335 2335
2336 .cs_files .cs_added {
2336 .cs_files .cs_added,.cs_files .cs_A {
2337 2337 background: url("../images/icons/page_white_add.png") no-repeat scroll
2338 2338 3px;
2339 2339 height: 16px;
@@ -2342,7 +2342,7 b' h3.files_location {'
2342 2342 text-align: left;
2343 2343 }
2344 2344
2345 .cs_files .cs_changed {
2345 .cs_files .cs_changed,.cs_files .cs_M {
2346 2346 background: url("../images/icons/page_white_edit.png") no-repeat scroll
2347 2347 3px;
2348 2348 height: 16px;
@@ -2351,7 +2351,7 b' h3.files_location {'
2351 2351 text-align: left;
2352 2352 }
2353 2353
2354 .cs_files .cs_removed {
2354 .cs_files .cs_removed,.cs_files .cs_D {
2355 2355 background: url("../images/icons/page_white_delete.png") no-repeat
2356 2356 scroll 3px;
2357 2357 height: 16px;
@@ -1,12 +1,12 b''
1 1 ## -*- coding: utf-8 -*-
2 2 ##usage:
3 3 ## <%namespace name="diff_block" file="/changeset/diff_block.html"/>
4 ## ${diff_block.diff_block(changes)}
4 ## ${diff_block.diff_block(change)}
5 5 ##
6 <%def name="diff_block(changes)">
6 <%def name="diff_block(change)">
7 7
8 %for change,filenode,diff,cs1,cs2,stat in changes:
9 %if change !='removed':
8 %for op,filenode,diff,cs1,cs2,stat in change:
9 %if op !='removed':
10 10 <div id="${h.FID(filenode.changeset.raw_id,filenode.path)}_target" style="clear:both;margin-top:25px"></div>
11 11 <div id="${h.FID(filenode.changeset.raw_id,filenode.path)}" class="diffblock margined comm">
12 12 <div class="code-header">
@@ -39,3 +39,23 b''
39 39 %endfor
40 40
41 41 </%def>
42
43 <%def name="diff_block_simple(change)">
44
45 %for op,filenode_path,diff in change:
46 <div id="${h.FID('',filenode_path)}_target" style="clear:both;margin-top:25px"></div>
47 <div id="${h.FID('',filenode_path)}" class="diffblock margined comm">
48 <div class="code-header">
49 <div class="changeset_header">
50 <div class="changeset_file">
51 <a href="#">${h.safe_unicode(filenode_path)}</a>
52 </div>
53 </div>
54 </div>
55 <div class="code-body">
56 <div class="full_f_path" path="${h.safe_unicode(filenode_path)}"></div>
57 ${diff|n}
58 </div>
59 </div>
60 %endfor
61 </%def> No newline at end of file
@@ -2,7 +2,7 b''
2 2 <%inherit file="/base/base.html"/>
3 3
4 4 <%def name="title()">
5 TODO FIll this in
5 ${c.repo_name} ${_('Compare')} ${'%s@%s' % (c.org_repo.repo_name, c.org_ref)} -> ${'%s@%s' % (c.other_repo.repo_name, c.other_ref)}
6 6 </%def>
7 7
8 8 <%def name="breadcrumbs_links()">
@@ -10,7 +10,7 b''
10 10 &raquo;
11 11 ${h.link_to(c.repo_name,h.url('summary_home',repo_name=c.repo_name))}
12 12 &raquo;
13 TODO!
13 ${_('Compare')}
14 14 </%def>
15 15
16 16 <%def name="page_nav()">
@@ -53,13 +53,21 b''
53 53 </div>
54 54 <div style="font-size:1.1em;font-weight: bold;clear:both;padding-top:10px">${_('Files affected')}</div>
55 55 <div class="cs_files">
56 %for change,filenode,diff,cs1,cs2,st in c.changes[cs.raw_id]:
57 <div class="cs_${change}">${h.link_to(h.safe_unicode(filenode.path),h.url.current(anchor=h.FID(cs.raw_id,filenode.path)))}</div>
56 %for fid, change, f, stat in c.files:
57 <div class="cs_${change}">
58 <div class="node">${h.link_to(h.safe_unicode(f),h.url.current(anchor=fid))}</div>
59 <div class="changes">${h.fancy_file_stats(stat)}</div>
60 </div>
58 61 %endfor
59 62 </div>
60 63 </div>
64 </div>
61 65
62 </div>
66 ## diff block
67 <%namespace name="diff_block" file="/changeset/diff_block.html"/>
68 %for fid, change, f, stat in c.files:
69 ${diff_block.diff_block_simple([c.changes[fid]])}
70 %endfor
63 71
64 72 <script type="text/javascript">
65 73
General Comments 0
You need to be logged in to leave comments. Login now