Changeset - ed50319aab94
[Not reviewed]
default
0 1 0
Mads Kiilerich - 12 years ago 2013-06-26 00:13:15
madski@unity3d.com
compare: make __get_cs_or_redirect more exact
1 file changed with 18 insertions and 4 deletions:
0 comments (0 inline, 0 general)
rhodecode/controllers/compare.py
Show inline comments
 
@@ -45,37 +45,51 @@ from rhodecode.model.db import Repositor
 
from webob.exc import HTTPBadRequest
 
from rhodecode.lib.diffs import LimitedDiffContainer
 

	
 

	
 
log = logging.getLogger(__name__)
 

	
 

	
 
class CompareController(BaseRepoController):
 

	
 
    def __before__(self):
 
        super(CompareController, self).__before__()
 

	
 
    def __get_cs_or_redirect(self, rev, repo, redirect_after=True,
 
    def __get_cs_or_redirect(self, ref, repo, redirect_after=True,
 
                             partial=False):
 
        """
 
        Safe way to get changeset if error occur it redirects to changeset with
 
        proper message. If partial is set then don't do redirect raise Exception
 
        instead
 

	
 
        :param rev: revision to fetch
 
        :param repo: repo instance
 
        """
 

	
 
        rev = ref[1] # default and used for git
 
        if repo.scm_instance.alias == 'hg':
 
            # lookup up the exact node id
 
            _revset_predicates = {
 
                    'branch': 'branch',
 
                    'book': 'bookmark',
 
                    'tag': 'tag',
 
                    'rev': 'id',
 
                }
 
            rev_spec = "max(%s(%%s))" % _revset_predicates[ref[0]]
 
            revs = repo.scm_instance._repo.revs(rev_spec, safe_str(ref[1]))
 
            if revs:
 
                rev = revs[-1]
 
            # else: TODO: just report 'not found'
 

	
 
        try:
 
            type_, rev = rev
 
            return repo.scm_instance.get_changeset(rev)
 
        except EmptyRepositoryError, e:
 
            if not redirect_after:
 
                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:
 
@@ -196,26 +210,26 @@ class CompareController(BaseRepoControll
 
        if other_repo is None:
 
            log.error('Could not find other repo %s' % other_repo)
 
            raise HTTPNotFound
 

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

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

	
 
        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)
 
        self.__get_cs_or_redirect(ref=org_ref, repo=org_repo, partial=partial)
 
        self.__get_cs_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,
 
                                                       merge)
0 comments (0 inline, 0 general)