Changeset - 15f4825890fe
[Not reviewed]
default
0 1 0
Mads Kiilerich - 12 years ago 2013-06-26 00:39:23
madski@unity3d.com
compare: let _get_changesets work on the already resolved revisions
1 file changed with 6 insertions and 28 deletions:
0 comments (0 inline, 0 general)
rhodecode/controllers/compare.py
Show inline comments
 
@@ -87,60 +87,38 @@ class CompareController(BaseRepoControll
 
                return None
 
            h.flash(h.literal(_('There are no changesets yet')),
 
                    category='warning')
 
            redirect(url('summary_home', repo_name=repo.repo_name))
 

	
 
        except RepositoryError, e:
 
            log.error(traceback.format_exc())
 
            h.flash(str(e), category='warning')
 
            if not partial:
 
                redirect(h.url('summary_home', repo_name=repo.repo_name))
 
            raise HTTPBadRequest()
 

	
 
    def _get_changesets(self, alias, org_repo, org_ref, other_repo, other_ref, merge):
 
    def _get_changesets(self, alias, org_repo, org_rev, other_repo, other_rev, merge):
 
        """
 
        Returns a list of changesets that can be merged from org_repo@org_ref
 
        to other_repo@other_ref ... and the ancestor that would be used for merge
 

	
 
        :param org_repo:
 
        :param org_ref:
 
        :param other_repo:
 
        :param other_ref:
 
        :param tmp:
 
        Returns a list of changesets that can be merged from org_repo@org_rev
 
        to other_repo@other_rev ... and the ancestor that would be used for merge
 
        """
 

	
 
        ancestor = None
 

	
 
        if org_rev == other_rev:
 
            changesets = []
 
            if merge:
 
                ancestor = org_rev
 

	
 
        elif alias == 'hg':
 
            # lookup up the exact node id
 
            _revset_predicates = {
 
                    'branch': 'branch',
 
                    'book': 'bookmark',
 
                    'tag': 'tag',
 
                    'rev': 'id',
 
                }
 

	
 
            org_rev_spec = "max(%s(%%s))" % _revset_predicates[org_ref[0]]
 
            org_revs = org_repo._repo.revs(org_rev_spec, safe_str(org_ref[1]))
 
            org_rev = org_repo._repo[org_revs[-1] if org_revs else -1].hex()
 

	
 
            other_revs_spec = "max(%s(%%s))" % _revset_predicates[other_ref[0]]
 
            other_revs = other_repo._repo.revs(other_revs_spec, safe_str(other_ref[1]))
 
            other_rev = other_repo._repo[other_revs[-1] if other_revs else -1].hex()
 

	
 
            #case two independent repos
 
            if org_repo != other_repo:
 
                hgrepo = unionrepo.unionrepository(other_repo.baseui,
 
                                                   other_repo.path,
 
                                                   org_repo.path)
 
                # all the changesets we are looking for will be in other_repo,
 
                # so rev numbers from hgrepo can be used in other_repo
 

	
 
            #no remote compare do it on the same repository
 
            else:
 
                hgrepo = other_repo._repo
 

	
 
@@ -157,25 +135,25 @@ class CompareController(BaseRepoControll
 
                revs = hgrepo.revs("id(%s) :: id(%s) - id(%s)",
 
                                   org_rev, other_rev, org_rev)
 

	
 
            changesets = [other_repo.get_changeset(rev) for rev in revs]
 

	
 
        elif alias == 'git':
 
            if org_repo != other_repo:
 
                raise Exception('Comparing of different GIT repositories is not'
 
                                'allowed. Got %s != %s' % (org_repo, other_repo))
 

	
 
            so, se = org_repo.run_git_command(
 
                'log --reverse --pretty="format: %%H" -s -p %s..%s'
 
                    % (org_ref[1], other_ref[1])
 
                    % (org_rev, other_rev)
 
            )
 
            changesets = [org_repo.get_changeset(cs)
 
                          for cs in re.findall(r'[0-9a-fA-F]{40}', so)]
 

	
 
        return changesets, ancestor
 

	
 
    @LoginRequired()
 
    @HasRepoPermissionAnyDecorator('repository.read', 'repository.write',
 
                                   'repository.admin')
 
    def index(self, org_ref_type, org_ref, other_ref_type, other_ref):
 
        # org_ref will be evaluated in org_repo
 
        org_repo = c.rhodecode_db_repo.repo_name
 
@@ -226,26 +204,26 @@ class CompareController(BaseRepoControll
 

	
 
        org_rev = self.__get_rev_or_redirect(ref=org_ref, repo=org_repo, partial=partial)
 
        other_rev = self.__get_rev_or_redirect(ref=other_ref, repo=other_repo, partial=partial)
 

	
 
        c.org_repo = org_repo
 
        c.other_repo = other_repo
 
        c.org_ref = org_ref[1]
 
        c.other_ref = other_ref[1]
 
        c.org_ref_type = org_ref[0]
 
        c.other_ref_type = other_ref[0]
 

	
 
        c.cs_ranges, c.ancestor = self._get_changesets(org_repo.scm_instance.alias,
 
                                                       org_repo.scm_instance, org_ref,
 
                                                       other_repo.scm_instance, other_ref,
 
                                                       org_repo.scm_instance, org_rev,
 
                                                       other_repo.scm_instance, other_rev,
 
                                                       merge)
 

	
 
        c.statuses = c.rhodecode_db_repo.statuses([x.raw_id for x in
 
                                                   c.cs_ranges])
 
        if merge and not c.ancestor:
 
            log.error('Unable to find ancestor revision')
 

	
 
        if partial:
 
            return render('compare/compare_cs.html')
 

	
 
        if c.ancestor:
 
            assert merge
0 comments (0 inline, 0 general)