Changeset - 745dda7817ed
[Not reviewed]
codereview
0 4 0
Marcin Kuzminski - 13 years ago 2012-05-30 23:12:16
marcin@python-works.com
Rewrote url routes to make all validations and parsing for compare view + added compare fork button into forked repos
4 files changed with 26 insertions and 48 deletions:
0 comments (0 inline, 0 general)
rhodecode/config/routing.py
Show inline comments
 
@@ -407,28 +407,30 @@ def make_map(config):
 
                conditions=dict(function=check_repo))
 

	
 
    rmap.connect('changeset_comment_delete',
 
                 '/{repo_name:.*}/changeset/comment/{comment_id}/delete',
 
                controller='changeset', action='delete_comment',
 
                conditions=dict(function=check_repo, method=["DELETE"]))
 

	
 
    rmap.connect('raw_changeset_home',
 
                 '/{repo_name:.*}/raw-changeset/{revision}',
 
                 controller='changeset', action='raw_changeset',
 
                 revision='tip', conditions=dict(function=check_repo))
 

	
 
    rmap.connect('compare_home',
 
                 '/{repo_name:.*}/compare/{ref:.*}',
 
    rmap.connect('compare_url',
 
                 '/{repo_name:.*}/compare/{org_ref_type}@{org_ref}...{other_ref_type}@{other_ref}',
 
                 controller='compare', action='index',
 
                 conditions=dict(function=check_repo))
 
                 conditions=dict(function=check_repo),
 
                 requirements=dict(org_ref_type='(branch|book|tag)',
 
                                   other_ref_type='(branch|book|tag)'))
 

	
 
    rmap.connect('pullrequest_home',
 
                 '/{repo_name:.*}/pull-request/new',
 
                 controller='pullrequests', action='index',
 
                 conditions=dict(function=check_repo))
 

	
 
    rmap.connect('summary_home', '/{repo_name:.*}/summary',
 
                controller='summary', conditions=dict(function=check_repo))
 

	
 
    rmap.connect('shortlog_home', '/{repo_name:.*}/shortlog',
 
                controller='shortlog', conditions=dict(function=check_repo))
 

	
rhodecode/controllers/compare.py
Show inline comments
 
@@ -40,59 +40,24 @@ from rhodecode.model.db import Repositor
 

	
 
log = logging.getLogger(__name__)
 

	
 

	
 
class CompareController(BaseRepoController):
 

	
 
    @LoginRequired()
 
    @HasRepoPermissionAnyDecorator('repository.read', 'repository.write',
 
                                   'repository.admin')
 
    def __before__(self):
 
        super(CompareController, self).__before__()
 

	
 
    def _handle_ref(self, ref):
 
        """
 
        Parse the org...other string
 
        Possible formats are 
 
            `(branch|book|tag):<name>...(branch|book|tag):<othername>`
 

	
 
        :param ref: <orginal_reference>...<other_reference>
 
        :type ref: str
 
        """
 
        org_repo = c.rhodecode_db_repo.repo_name
 

	
 
        def org_parser(org):
 
            _repo = org_repo
 
            name, val = org.split(':')
 
            return _repo, (name, val)
 

	
 
        def other_parser(other):
 
            _other_repo = request.GET.get('repo')
 
            _repo = org_repo
 
            name, val = other.split(':')
 
            if _other_repo:
 
                _repo = _other_repo
 

	
 
            return _repo, (name, val)
 

	
 
        if '...' in ref:
 
            try:
 
                org, other = ref.split('...')
 
                org_repo, org_ref = org_parser(org)
 
                other_repo, other_ref = other_parser(other)
 
                return org_repo, org_ref, other_repo, other_ref
 
            except:
 
                log.error(traceback.format_exc())
 

	
 
        raise HTTPNotFound
 

	
 
    def _get_discovery(self, org_repo, org_ref, other_repo, other_ref):
 
        from mercurial import discovery
 
        other = org_repo._repo
 
        repo = other_repo._repo
 
        tip = other[org_ref[1]]
 
        log.debug('Doing discovery for %s@%s vs %s@%s' % (
 
                        org_repo, org_ref, other_repo, other_ref)
 
        )
 
        log.debug('Filter heads are %s[%s]' % (tip, org_ref[1]))
 
        tmp = discovery.findcommonincoming(
 
                  repo=repo,  # other_repo we check for incoming
 
@@ -116,31 +81,36 @@ class CompareController(BaseRepoControll
 
            for cs in reversed(map(binascii.hexlify, revs)):
 
                changesets.append(org_repo.get_changeset(cs))
 
        else:
 
            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)
 
    def index(self, org_ref_type, org_ref, other_ref_type, other_ref):
 

	
 
        c.swap_url = h.url('compare_home', repo_name=other_repo,
 
                           ref='%s...%s' % (':'.join(other_ref),
 
                                            ':'.join(org_ref)),
 
                           repo=org_repo)
 
        org_repo = c.rhodecode_db_repo.repo_name
 
        org_ref = (org_ref_type, org_ref)
 
        other_ref = (other_ref_type, other_ref)
 
        other_repo = request.GET.get('repo', org_repo)
 

	
 
        c.swap_url = h.url('compare_url', repo_name=other_repo,
 
              org_ref_type=other_ref[0], org_ref=other_ref[1],
 
              other_ref_type=org_ref[0], other_ref=org_ref[1],
 
              repo=org_repo)
 

	
 
        c.org_repo = org_repo = Repository.get_by_repo_name(org_repo)
 
        c.other_repo = other_repo = Repository.get_by_repo_name(other_repo)
 

	
 
        if c.org_repo is None or c.other_repo is None:
 
            log.error('Could not found repo %s or %s' % (org_repo, other_repo))
 
            raise HTTPNotFound
 

	
 
        discovery_data = self._get_discovery(org_repo.scm_instance,
 
                                           org_ref,
 
                                           other_repo.scm_instance,
 
                                           other_ref)
 
        c.cs_ranges = self._get_changesets(org_repo.scm_instance,
rhodecode/templates/branches/branches.html
Show inline comments
 
@@ -28,28 +28,29 @@
 
    %if c.repo_branches:
 
    <div class="info_box" id="compare_branches" style="clear: both;padding: 10px 19px;vertical-align: right;text-align: right;"><a href="#" class="ui-btn small">${_('Compare branches')}</a></div>
 
    %endif
 
    <div class="table">
 
        <%include file='branches_data.html'/>
 
    </div>
 
</div>
 
<script type="text/javascript">
 
YUE.on('compare_branches','click',function(e){
 
	YUE.preventDefault(e);
 
	var org = YUQ('input[name=compare_org]:checked')[0];
 
	var other = YUQ('input[name=compare_other]:checked')[0];
 
	var compare_url = "${h.url('compare_home',repo_name=c.repo_name,ref='__ORG__...__OTHER__')}";
 

	
 
	if(org && other){
 
		var u = compare_url.replace('__ORG__','branch:'+org.value)
 
		                   .replace('__OTHER__','branch:'+other.value);
 
	    var compare_url = "${h.url('compare_url',repo_name=c.repo_name,org_ref_type='branch',org_ref='__ORG__',other_ref_type='branch',other_ref='__OTHER__')}";
 
		var u = compare_url.replace('__ORG__',org.value)
 
		                   .replace('__OTHER__',other.value);
 
		window.location=u;
 
	}
 
	
 
})
 
// main table sorting
 
var myColumnDefs = [
 
    {key:"name",label:"${_('Name')}",sortable:true},
 
    {key:"date",label:"${_('Date')}",sortable:true,
 
        sortOptions: { sortFunction: dateSort }},
 
    {key:"author",label:"${_('Author')}",sortable:true},
 
    {key:"revision",label:"${_('Revision')}",sortable:true,
 
        sortOptions: { sortFunction: revisionSort }},
rhodecode/templates/changelog/changelog.html
Show inline comments
 
@@ -23,25 +23,30 @@ ${c.repo_name} ${_('Changelog')} - ${c.r
 
<div class="box">
 
    <!-- box / title -->
 
    <div class="title">
 
        ${self.breadcrumbs()}
 
    </div>
 
    <div class="table">
 
		% if c.pagination:
 
			<div id="graph">
 
				<div id="graph_nodes">
 
					<canvas id="graph_canvas"></canvas>
 
				</div>
 
				<div id="graph_content">
 
                    <div class="info_box" style="clear: both;padding: 10px 6px;vertical-align: right;text-align: right;"><a href="${h.url('pullrequest_home',repo_name=c.repo_name)}" class="ui-btn small">${_('Open new pull request')}</a></div>
 
                    <div class="info_box" style="clear: both;padding: 10px 6px;vertical-align: right;text-align: right;">
 
                    %if c.rhodecode_db_repo.fork:
 
                        <a title="${_('compare fork with %s' % c.rhodecode_db_repo.fork.repo_name)}" href="${h.url('compare_url',repo_name=c.repo_name,org_ref_type='branch',org_ref='default',other_ref_type='branch',other_ref='default',repo=c.rhodecode_db_repo.fork.repo_name)}" class="ui-btn small">${_('Compare fork')}</a>
 
                    %endif
 
                    <a href="${h.url('pullrequest_home',repo_name=c.repo_name)}" class="ui-btn small">${_('Open new pull request')}</a>
 
                    </div>
 
					<div class="container_header">
 
				        ${h.form(h.url.current(),method='get')}
 
				        <div class="info_box" style="float:left">
 
				          ${h.submit('set',_('Show'),class_="ui-btn")}
 
				          ${h.text('size',size=1,value=c.size)}
 
				          ${_('revisions')}
 
				        </div>
 
				        ${h.end_form()}
 
					<div id="rev_range_container" style="display:none"></div>
 
                    <div style="float:right">${h.select('branch_filter',c.branch_name,c.branch_filters)}</div>
 
					</div>
 

	
0 comments (0 inline, 0 general)