Changeset - 3c91ec4419a6
[Not reviewed]
beta
0 1 0
Mads Kiilerich - 13 years ago 2013-01-31 23:27:21
madski@unity3d.com
pull requeset: move stuff around, preparing for next change

- and make sure we don't pass unicode to Mercurial
1 file changed with 20 insertions and 16 deletions:
0 comments (0 inline, 0 general)
rhodecode/model/pull_request.py
Show inline comments
 
@@ -31,24 +31,25 @@ 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
 
from rhodecode.model.db import PullRequest, PullRequestReviewers, Notification,\
 
    ChangesetStatus
 
from rhodecode.model.notification import NotificationModel
 
from rhodecode.lib.utils2 import safe_unicode
 

	
 
from rhodecode.lib.vcs.utils.hgcompat import discovery, localrepo, scmutil, \
 
    findcommonoutgoing
 
from rhodecode.lib.vcs.utils import safe_str
 

	
 
log = logging.getLogger(__name__)
 

	
 

	
 
class PullRequestModel(BaseModel):
 

	
 
    cls = PullRequest
 

	
 
    def __get_pull_request(self, pull_request):
 
        return self._get_instance(PullRequest, pull_request)
 

	
 
    def get_all(self, repo):
 
@@ -165,83 +166,86 @@ class PullRequestModel(BaseModel):
 
        to other_repo@other_ref
 

	
 
        :param org_repo:
 
        :param org_ref:
 
        :param other_repo:
 
        :param other_ref:
 
        :param tmp:
 
        """
 

	
 
        changesets = []
 

	
 
        if alias == 'hg':
 
            # lookup up the exact node id
 
            _revset_predicates = {
 
                    'branch': 'branch',
 
                    'book': 'bookmark',
 
                    'tag': 'tag',
 
                    'rev': 'id',
 
                }
 
            org_rev_spec = "%s('%s')" % (_revset_predicates[org_ref[0]],
 
                                         safe_str(org_ref[1]))
 
            org_rev = scmutil.revsingle(org_repo._repo,
 
                                         org_rev_spec)
 
            other_rev_spec = "%s('%s')" % (_revset_predicates[other_ref[0]],
 
                                           safe_str(other_ref[1]))
 
            other_rev = scmutil.revsingle(other_repo._repo, other_rev_spec)
 

	
 
            #case two independent repos
 
            if org_repo != other_repo:
 
                revs = [
 
                    org_repo._repo.lookup(org_ref[1]),
 
                    org_repo._repo.lookup(other_ref[1]),
 
                    org_repo._repo.lookup(other_ref[1]), # lookup up in the wrong repo!
 
                ]
 
    
 
                obj = findcommonoutgoing(org_repo._repo,
 
                            localrepo.locallegacypeer(other_repo._repo.local()),
 
                            revs,
 
                            force=True)
 
                revs = obj.missing
 
    
 
                for cs in map(binascii.hexlify, revs):
 
                    _cs = org_repo.get_changeset(cs)
 
                    changesets.append(_cs)
 
                # in case we have revisions filter out the ones not in given range
 
                if org_ref[0] == 'rev' and other_ref[0] == 'rev':
 
                    revs = [x.raw_id for x in changesets]
 
                    start = org_ref[1]
 
                    stop = other_ref[1]
 
                    changesets = changesets[revs.index(start):revs.index(stop) + 1]
 

	
 
            #no remote compare do it on the same repository
 
            else:
 
                _revset_predicates = {
 
                        'branch': 'branch',
 
                        'book': 'bookmark',
 
                        'tag': 'tag',
 
                        'rev': 'id',
 
                    }
 

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

	
 
                revs = ["ancestors(id('%s')) and not ancestors(id('%s'))" %
 
                        (other_rev, org_rev)]
 
    
 
                out = scmutil.revrange(org_repo._repo, revs)
 
                for cs in (out):
 
                    changesets.append(org_repo.get_changeset(cs))
 

	
 
        elif alias == 'git':
 
            assert org_repo == other_repo, (org_repo, other_repo) # no git support for different repos
 
            so, se = org_repo.run_git_command(
 
                'log --reverse --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 (ids):
 
                changesets.append(org_repo.get_changeset(cs))
 

	
 
        return changesets
 

	
 
    def get_compare_data(self, org_repo, org_ref, other_repo, other_ref):
 
        """
 
        Returns incomming changesets for mercurial repositories
 
        Returns incoming changesets for mercurial repositories
 

	
 
        :param org_repo:
 
        :type org_repo:
 
        :param org_ref:
 
        :type org_ref:
 
        :param other_repo:
 
        :type other_repo:
 
        :param other_ref:
 
        :type other_ref:
 
        """
 

	
 
        if len(org_ref) != 2 or not isinstance(org_ref, (list, tuple)):
0 comments (0 inline, 0 general)