changeset 3010:bf96fd1920c1 beta

Enabled compare engine for tags Implemented compare engine for git repositories
author Marcin Kuzminski <marcin@python-works.com>
date Fri, 16 Nov 2012 21:27:04 +0100
parents f0e19116f154
children 25d77aef2729
files rhodecode/controllers/compare.py rhodecode/controllers/forks.py rhodecode/lib/diffs.py rhodecode/model/pull_request.py rhodecode/templates/branches/branches.html rhodecode/templates/branches/branches_data.html rhodecode/templates/changelog/changelog.html rhodecode/templates/tags/tags.html rhodecode/templates/tags/tags_data.html
diffstat 9 files changed, 89 insertions(+), 44 deletions(-) [+]
line wrap: on
line diff
--- a/rhodecode/controllers/compare.py	Fri Nov 16 21:09:50 2012 +0100
+++ b/rhodecode/controllers/compare.py	Fri Nov 16 21:27:04 2012 +0100
@@ -102,9 +102,14 @@
             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)
--- a/rhodecode/controllers/forks.py	Fri Nov 16 21:09:50 2012 +0100
+++ b/rhodecode/controllers/forks.py	Fri Nov 16 21:27:04 2012 +0100
@@ -99,8 +99,8 @@
                                             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',
--- a/rhodecode/lib/diffs.py	Fri Nov 16 21:09:50 2012 +0100
+++ b/rhodecode/lib/diffs.py	Fri Nov 16 21:27:04 2012 +0100
@@ -720,13 +720,21 @@
     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())
@@ -760,8 +768,4 @@
                                   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))
+
--- a/rhodecode/model/pull_request.py	Fri Nov 16 21:09:50 2012 +0100
+++ b/rhodecode/model/pull_request.py	Fri Nov 16 21:27:04 2012 +0100
@@ -26,6 +26,7 @@
 import logging
 import binascii
 import datetime
+import re
 
 from pylons.i18n.translation import _
 
@@ -144,7 +145,7 @@
         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
@@ -173,23 +174,33 @@
             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
 
@@ -231,7 +242,8 @@
 
     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:
@@ -249,14 +261,17 @@
         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
--- a/rhodecode/templates/branches/branches.html	Fri Nov 16 21:09:50 2012 +0100
+++ b/rhodecode/templates/branches/branches.html	Fri Nov 16 21:27:04 2012 +0100
@@ -44,8 +44,7 @@
 		                   .replace('__OTHER__',other.value);
 		window.location=u;
 	}
-
-})
+});
 // main table sorting
 var myColumnDefs = [
     {key:"name",label:"${_('Name')}",sortable:true},
--- a/rhodecode/templates/branches/branches_data.html	Fri Nov 16 21:09:50 2012 +0100
+++ b/rhodecode/templates/branches/branches_data.html	Fri Nov 16 21:27:04 2012 +0100
@@ -3,11 +3,11 @@
     <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()):
--- a/rhodecode/templates/changelog/changelog.html	Fri Nov 16 21:09:50 2012 +0100
+++ b/rhodecode/templates/changelog/changelog.html	Fri Nov 16 21:27:04 2012 +0100
@@ -37,7 +37,7 @@
                     <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>
--- a/rhodecode/templates/tags/tags.html	Fri Nov 16 21:09:50 2012 +0100
+++ b/rhodecode/templates/tags/tags.html	Fri Nov 16 21:27:04 2012 +0100
@@ -25,11 +25,26 @@
         ${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 = [
@@ -39,6 +54,7 @@
     {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"));
@@ -51,6 +67,7 @@
         {key:"date"},
         {key:"author"},
         {key:"revision"},
+        {key:"compare"},
     ]
 };
 
--- a/rhodecode/templates/tags/tags_data.html	Fri Nov 16 21:09:50 2012 +0100
+++ b/rhodecode/templates/tags/tags_data.html	Fri Nov 16 21:27:04 2012 +0100
@@ -7,6 +7,7 @@
             <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()):
@@ -25,6 +26,10 @@
                     <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>