Changeset - bf96fd1920c1
[Not reviewed]
beta
0 9 0
Marcin Kuzminski - 13 years ago 2012-11-16 21:27:04
marcin@python-works.com
Enabled compare engine for tags
Implemented compare engine for git repositories
9 files changed with 89 insertions and 44 deletions:
0 comments (0 inline, 0 general)
rhodecode/controllers/compare.py
Show inline comments
 
@@ -99,15 +99,20 @@ class CompareController(BaseRepoControll
 
        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
 

	
 
        if c.org_repo.scm_instance.alias != 'hg':
 
            log.error('Review not available for GIT REPOS')
 
        if c.org_repo != c.other_repo and h.is_git(c.rhodecode_repo):
 
            log.error('compare of two remote repos not available for GIT REPOS')
 
            raise HTTPNotFound
 

	
 
        if c.org_repo.scm_instance.alias != c.other_repo.scm_instance.alias:
 
            log.error('compare of two different kind of remote repos not available')
 
            raise HTTPNotFound
 

	
 
        partial = request.environ.get('HTTP_X_PARTIAL_XHR')
 
        self.__get_cs_or_redirect(rev=org_ref, repo=org_repo, partial=partial)
 
        self.__get_cs_or_redirect(rev=other_ref, repo=other_repo, partial=partial)
 

	
 
        c.cs_ranges, discovery_data = PullRequestModel().get_compare_data(
 
                                    org_repo, org_ref, other_repo, other_ref
rhodecode/controllers/forks.py
Show inline comments
 
@@ -96,14 +96,14 @@ class ForksController(BaseRepoController
 
            c.stats_percentage = 0
 
        else:
 
            c.stats_percentage = '%.2f' % ((float((last_rev)) /
 
                                            c.repo_last_rev) * 100)
 

	
 
        defaults = RepoModel()._get_defaults(repo_name)
 
        # add prefix to fork
 
        defaults['repo_name'] = 'fork-' + defaults['repo_name']
 
        # add suffix to fork
 
        defaults['repo_name'] = '%s-fork' % defaults['repo_name']
 
        return defaults
 

	
 
    @HasRepoPermissionAnyDecorator('repository.read', 'repository.write',
 
                                   'repository.admin')
 
    def forks(self, repo_name):
 
        p = safe_int(request.params.get('page', 1), 1)
rhodecode/lib/diffs.py
Show inline comments
 
@@ -717,19 +717,27 @@ def differ(org_repo, org_ref, other_repo
 
    :type other_ref:
 
    """
 

	
 
    bundlerepo = None
 
    ignore_whitespace = ignore_whitespace
 
    context = context
 
    org_repo = org_repo.scm_instance._repo
 
    org_repo_scm = org_repo.scm_instance
 
    org_repo = org_repo_scm._repo
 
    other_repo = other_repo.scm_instance._repo
 
    opts = diffopts(git=True, ignorews=ignore_whitespace, context=context)
 
    org_ref = org_ref[1]
 
    other_ref = other_ref[1]
 

	
 
    if org_repo != other_repo and bundle_compare:
 
    if org_repo == other_repo:
 
        log.debug('running diff between %s@%s and %s@%s'
 
                  % (org_repo, org_ref, other_repo, other_ref))
 
        _diff = org_repo_scm.get_diff(rev1=other_ref, rev2=org_ref,
 
            ignore_whitespace=ignore_whitespace, context=context)
 
        return _diff
 

	
 
    elif bundle_compare:
 

	
 
        common, incoming, rheads = discovery_data
 
        other_repo_peer = localrepo.locallegacypeer(other_repo.local())
 
        # create a bundle (uncompressed if other repo is not local)
 
        if other_repo_peer.capable('getbundle') and incoming:
 
            # disable repo hooks here since it's just bundle !
 
@@ -757,11 +765,7 @@ def differ(org_repo, org_ref, other_repo
 
                                            bundlestream=unbundle)
 

	
 
        return ''.join(patch.diff(bundlerepo or org_repo,
 
                                  node1=org_repo[org_ref].node(),
 
                                  node2=other_repo[other_ref].node(),
 
                                  opts=opts))
 
    else:
 
        log.debug('running diff between %s@%s and %s@%s'
 
                  % (org_repo, org_ref, other_repo, other_ref))
 
        return ''.join(patch.diff(org_repo, node1=org_ref, node2=other_ref,
 
                                  opts=opts))
 

	
rhodecode/model/pull_request.py
Show inline comments
 
@@ -23,12 +23,13 @@
 
# 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
 
import datetime
 
import re
 

	
 
from pylons.i18n.translation import _
 

	
 
from rhodecode.model.meta import Session
 
from rhodecode.lib import helpers as h
 
from rhodecode.model import BaseModel
 
@@ -141,13 +142,13 @@ class PullRequestModel(BaseModel):
 
    def close_pull_request(self, pull_request):
 
        pull_request = self.__get_pull_request(pull_request)
 
        pull_request.status = PullRequest.STATUS_CLOSED
 
        pull_request.updated_on = datetime.datetime.now()
 
        self.sa.add(pull_request)
 

	
 
    def _get_changesets(self, org_repo, org_ref, other_repo, other_ref,
 
    def _get_changesets(self, alias, org_repo, org_ref, other_repo, other_ref,
 
                        discovery_data):
 
        """
 
        Returns a list of changesets that are incoming from org_repo@org_ref
 
        to other_repo@other_ref
 

	
 
        :param org_repo:
 
@@ -170,29 +171,39 @@ class PullRequestModel(BaseModel):
 
                        force=True)
 
            revs = obj.missing
 

	
 
            for cs in reversed(map(binascii.hexlify, revs)):
 
                changesets.append(org_repo.get_changeset(cs))
 
        else:
 
            _revset_predicates = {
 
                    'branch': 'branch',
 
                    'book': 'bookmark',
 
                    'tag': 'tag',
 
                    'rev': 'id',
 
                }
 
            #no remote compare do it on the same repository
 
            if alias == 'hg':
 
                _revset_predicates = {
 
                        'branch': 'branch',
 
                        'book': 'bookmark',
 
                        'tag': 'tag',
 
                        'rev': 'id',
 
                    }
 

	
 
            revs = [
 
                "ancestors(%s('%s')) and not ancestors(%s('%s'))" % (
 
                    _revset_predicates[org_ref[0]], org_ref[1],
 
                    _revset_predicates[other_ref[0]], other_ref[1]
 
               )
 
            ]
 
                revs = [
 
                    "ancestors(%s('%s')) and not ancestors(%s('%s'))" % (
 
                        _revset_predicates[org_ref[0]], org_ref[1],
 
                        _revset_predicates[other_ref[0]], other_ref[1]
 
                   )
 
                ]
 

	
 
            out = scmutil.revrange(org_repo._repo, revs)
 
            for cs in reversed(out):
 
                changesets.append(org_repo.get_changeset(cs))
 
                out = scmutil.revrange(org_repo._repo, revs)
 
                for cs in reversed(out):
 
                    changesets.append(org_repo.get_changeset(cs))
 
            elif alias == 'git':
 
                so, se = org_repo.run_git_command(
 
                    'log --pretty="format: %%H" -s -p %s..%s' % (org_ref[1],
 
                                                                     other_ref[1])
 
                )
 
                ids = re.findall(r'[0-9a-fA-F]{40}', so)
 
                for cs in reversed(ids):
 
                    changesets.append(org_repo.get_changeset(cs))
 

	
 
        return changesets
 

	
 
    def _get_discovery(self, org_repo, org_ref, other_repo, other_ref):
 
        """
 
        Get's mercurial discovery data used to calculate difference between
 
@@ -228,13 +239,14 @@ class PullRequestModel(BaseModel):
 
                  force=True
 
        )
 
        return tmp
 

	
 
    def get_compare_data(self, org_repo, org_ref, other_repo, other_ref):
 
        """
 
        Returns a tuple of incomming changesets, and discoverydata cache
 
        Returns a tuple of incomming changesets, and discoverydata cache for
 
        mercurial repositories
 

	
 
        :param org_repo:
 
        :type org_repo:
 
        :param org_ref:
 
        :type org_ref:
 
        :param other_repo:
 
@@ -246,17 +258,20 @@ class PullRequestModel(BaseModel):
 
        if len(org_ref) != 2 or not isinstance(org_ref, (list, tuple)):
 
            raise Exception('org_ref must be a two element list/tuple')
 

	
 
        if len(other_ref) != 2 or not isinstance(org_ref, (list, tuple)):
 
            raise Exception('other_ref must be a two element list/tuple')
 

	
 
        discovery_data = self._get_discovery(org_repo.scm_instance,
 
                                           org_ref,
 
                                           other_repo.scm_instance,
 
                                           other_ref)
 
        cs_ranges = self._get_changesets(org_repo.scm_instance,
 
                                         org_ref,
 
                                         other_repo.scm_instance,
 
                                         other_ref,
 
        org_repo_scm = org_repo.scm_instance
 
        other_repo_scm = other_repo.scm_instance
 

	
 
        alias = org_repo.scm_instance.alias
 
        discovery_data = [None, None, None]
 
        if alias == 'hg':
 
            discovery_data = self._get_discovery(org_repo_scm, org_ref,
 
                                               other_repo_scm, other_ref)
 
        cs_ranges = self._get_changesets(alias,
 
                                         org_repo_scm, org_ref,
 
                                         other_repo_scm, other_ref,
 
                                         discovery_data)
 

	
 
        return cs_ranges, discovery_data
rhodecode/templates/branches/branches.html
Show inline comments
 
@@ -41,14 +41,13 @@ YUE.on('compare_branches','click',functi
 
	if(org && other){
 
	    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},
rhodecode/templates/branches/branches_data.html
Show inline comments
 
%if c.repo_branches:
 
   <div id="table_wrap" class="yui-skin-sam">
 
    <table id="branches_data">
 
      <thead>
 
        <tr>
 
            <th class="left">${_('name')}</th>
 
            <th class="left">${_('date')}</th>
 
            <th class="left">${_('author')}</th>
 
            <th class="left">${_('revision')}</th>
 
            <th class="left">${_('compare')}</th>
 
            <th class="left">${_('Name')}</th>
 
            <th class="left">${_('Date')}</th>
 
            <th class="left">${_('Author')}</th>
 
            <th class="left">${_('Revision')}</th>
 
            <th class="left">${_('Compare')}</th>
 
        </tr>
 
      </thead>
 
		%for cnt,branch in enumerate(c.repo_branches.items()):
 
		<tr class="parity${cnt%2}">
 
            <td>
 
                <span class="logtags">
rhodecode/templates/changelog/changelog.html
Show inline comments
 
@@ -34,13 +34,13 @@ ${_('%s Changelog') % c.repo_name} - ${c
 
				<div id="graph_content">
 
                    <div class="info_box" style="clear: both;padding: 10px 6px;vertical-align: right;text-align: right;">
 
                    <a href="#" class="ui-btn small" id="rev_range_container" style="display:none"></a>
 
                    <a href="#" class="ui-btn small" id="rev_range_clear" style="display:none">${_('Clear selection')}</a>
 

	
 
                    %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=request.GET.get('branch') or 'default',other_ref_type='branch',other_ref='default',repo=c.rhodecode_db_repo.fork.repo_name)}" class="ui-btn small">${_('Compare fork')}</a>
 
                        <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=request.GET.get('branch') or 'default',other_ref_type='branch',other_ref='default',repo=c.rhodecode_db_repo.fork.repo_name)}" class="ui-btn small">${_('Compare fork with parent')}</a>
 
                    %endif
 
                    %if h.is_hg(c.rhodecode_repo):
 
                    <a id="open_new_pr" href="${h.url('pullrequest_home',repo_name=c.repo_name)}" class="ui-btn small">${_('Open new pull request')}</a>
 
                    %endif
 
                    </div>
 
					<div class="container_header">
rhodecode/templates/tags/tags.html
Show inline comments
 
@@ -22,38 +22,55 @@
 
<div class="box">
 
    <!-- box / title -->
 
    <div class="title">
 
        ${self.breadcrumbs()}
 
    </div>
 
    <!-- end box / title -->
 
    %if c.repo_tags:
 
    <div class="info_box" id="compare_tags" style="clear: both;padding: 10px 19px;vertical-align: right;text-align: right;"><a href="#" class="ui-btn small">${_('Compare tags')}</a></div>
 
    %endif    
 
    <div class="table">
 
        <%include file='tags_data.html'/>
 
    </div>
 
</div>
 
<script type="text/javascript">
 
YUE.on('compare_tags','click',function(e){
 
    YUE.preventDefault(e);
 
    var org = YUQ('input[name=compare_org]:checked')[0];
 
    var other = YUQ('input[name=compare_other]:checked')[0];
 

	
 
    if(org && other){
 
        var compare_url = "${h.url('compare_url',repo_name=c.repo_name,org_ref_type='tag',org_ref='__ORG__',other_ref_type='tag',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 }},
 
    {key:"compare",label:"${_('Compare')}",sortable:false,},        
 
];
 

	
 
var myDataSource = new YAHOO.util.DataSource(YUD.get("tags_data"));
 

	
 
myDataSource.responseType = YAHOO.util.DataSource.TYPE_HTMLTABLE;
 

	
 
myDataSource.responseSchema = {
 
    fields: [
 
        {key:"name"},
 
        {key:"date"},
 
        {key:"author"},
 
        {key:"revision"},
 
        {key:"compare"},
 
    ]
 
};
 

	
 
var myDataTable = new YAHOO.widget.DataTable("table_wrap", myColumnDefs, myDataSource,
 
        {
 
         sortedBy:{key:"name",dir:"asc"},
rhodecode/templates/tags/tags_data.html
Show inline comments
 
@@ -4,12 +4,13 @@
 
      <thead>
 
    	<tr>
 
            <th class="left">${_('Name')}</th>
 
            <th class="left">${_('Date')}</th>
 
            <th class="left">${_('Author')}</th>
 
            <th class="left">${_('Revision')}</th>
 
            <th class="left">${_('Compare')}</th>
 
    	</tr>
 
      </thead>
 
		%for cnt,tag in enumerate(c.repo_tags.items()):
 
		<tr class="parity${cnt%2}">
 
            <td>
 
                <span class="logtags">
 
@@ -22,12 +23,16 @@
 
	        <td title="${tag[1].author}">${h.person(tag[1].author)}</td>
 
	        <td>
 
                <div>
 
                    <pre><a href="${h.url('files_home',repo_name=c.repo_name,revision=tag[1].raw_id)}">r${tag[1].revision}:${h.short_id(tag[1].raw_id)}</a></pre>
 
                </div>
 
            </td>
 
            <td>
 
                <input class="branch-compare" type="radio" name="compare_org" value="${tag[0]}"/>
 
                <input class="branch-compare" type="radio" name="compare_other" value="${tag[0]}"/>
 
            </td>            
 
		</tr>
 
		%endfor
 
    </table>
 
   </div>
 
%else:
 
	${_('There are no tags yet')}
0 comments (0 inline, 0 general)