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
 
@@ -51,25 +51,39 @@ 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')
 
@@ -202,14 +216,14 @@ class CompareController(BaseRepoControll
 
            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]
0 comments (0 inline, 0 general)