Changeset - bd5420ea396b
[Not reviewed]
beta
0 2 0
Marcin Kuzminski - 13 years ago 2013-02-19 23:42:37
marcin@python-works.com
better handling of EmptyChangeset case in cherry pick pull request
2 files changed with 13 insertions and 4 deletions:
0 comments (0 inline, 0 general)
rhodecode/controllers/compare.py
Show inline comments
 
@@ -116,49 +116,49 @@ class CompareController(BaseRepoControll
 
        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
 

	
 
        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]
 

	
 
        if rev_start and rev_end:
 
            # swap revs with cherry picked ones, save them for display
 
            #org_ref = ('rev', rev_start)
 
            #other_ref = ('rev', rev_end)
 
            c.org_ref = rev_start[:12]
 
            c.other_ref = rev_end[:12]
 
            # get parent of
 
            # rev start to include it in the diff
 
            _cs = other_repo.scm_instance.get_changeset(rev_start)
 
            rev_start = _cs.parents[0].raw_id if _cs.parents else EmptyChangeset()
 
            rev_start = _cs.parents[0].raw_id if _cs.parents else EmptyChangeset().raw_id
 
            org_ref = ('rev', rev_start)
 
            other_ref = ('rev', rev_end)
 
            #if we cherry pick it's not remote, make the other_repo org_repo
 
            org_repo = other_repo
 

	
 
        c.cs_ranges, ancestor = PullRequestModel().get_compare_data(
 
            org_repo, org_ref, other_repo, other_ref)
 

	
 
        c.statuses = c.rhodecode_db_repo.statuses([x.raw_id for x in
 
                                                   c.cs_ranges])
 
        # defines that we need hidden inputs with changesets
 
        c.as_form = request.GET.get('as_form', False)
 
        if partial:
 
            return render('compare/compare_cs.html')
 

	
 
        if ancestor and org_repo != other_repo:
 
            # case we want a simple diff without incoming changesets,
 
            # previewing what will be merged.
 
            # Make the diff on the forked repo, with
 
            # revision that is common ancestor
 
            log.debug('Using ancestor %s as org_ref instead of %s'
 
                      % (ancestor, org_ref))
 
            org_ref = ('rev', ancestor)
 
            org_repo = other_repo
rhodecode/model/pull_request.py
Show inline comments
 
@@ -18,48 +18,49 @@
 
# This program is distributed in the hope that it will be useful,
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
# GNU General Public License for more details.
 
#
 
# You should have received a copy of the GNU General Public License
 
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 

	
 
import logging
 
import datetime
 
import re
 

	
 
from pylons.i18n.translation import _
 

	
 
from rhodecode.model.meta import Session
 
from rhodecode.lib import helpers as h, unionrepo
 
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 scmutil
 
from rhodecode.lib.vcs.utils import safe_str
 
from rhodecode.lib.vcs.backends.base import EmptyChangeset
 

	
 
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):
 
        repo = self._get_repo(repo)
 
        return PullRequest.query()\
 
                .filter(PullRequest.other_repo == repo)\
 
                .order_by(PullRequest.created_on)\
 
                .all()
 

	
 
    def create(self, created_by, org_repo, org_ref, other_repo, other_ref,
 
               revisions, reviewers, title, description=None):
 
        from rhodecode.model.changeset_status import ChangesetStatusModel
 

	
 
        created_by_user = self._get_user(created_by)
 
        org_repo = self._get_repo(org_repo)
 
@@ -159,55 +160,63 @@ class PullRequestModel(BaseModel):
 
        self.sa.add(pull_request)
 

	
 
    def _get_changesets(self, alias, org_repo, org_ref, other_repo, other_ref):
 
        """
 
        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:
 
        """
 

	
 
        ancestor = None
 

	
 
        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)
 
            if org_ref[1] == EmptyChangeset().raw_id:
 
                org_rev = org_ref[1]
 
            else:
 
                org_rev = org_repo._repo[scmutil.revrange(org_repo._repo,
 
                                                          [org_rev_spec])[-1]]
 
            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)
 
            if other_ref[1] == EmptyChangeset().raw_id:
 
                other_rev = other_ref[1]
 
            else:
 
                other_rev = other_repo._repo[scmutil.revrange(other_repo._repo,
 
                                                        [other_rev_spec])[-1]]
 

	
 
            #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
 

	
 
            revs = ["ancestors(id('%s')) and not ancestors(id('%s'))" %
 
                    (other_rev, org_rev)]
 
            changesets = [other_repo.get_changeset(cs)
 
                          for cs in scmutil.revrange(hgrepo, revs)]
 

	
 
            if org_repo != other_repo:
 
                ancestors = scmutil.revrange(hgrepo,
 
                     ["ancestor(id('%s'), id('%s'))" % (org_rev, other_rev)])
 
                if len(ancestors) == 1:
 
                    ancestor = hgrepo[ancestors[0]].hex()
 

	
0 comments (0 inline, 0 general)