Changeset - 01fe360a66c0
[Not reviewed]
beta
0 4 0
Marcin Kuzminski - 13 years ago 2013-02-19 01:57:59
marcin@python-works.com
fixed pull-requests with cherry picking changesets
- fixed tests for them
4 files changed with 128 insertions and 132 deletions:
0 comments (0 inline, 0 general)
rhodecode/controllers/compare.py
Show inline comments
 
@@ -40,9 +40,7 @@ from rhodecode.lib import diffs
 
from rhodecode.model.db import Repository
 
from rhodecode.model.pull_request import PullRequestModel
 
from webob.exc import HTTPBadRequest
 
from rhodecode.lib.utils2 import str2bool
 
from rhodecode.lib.diffs import LimitedDiffContainer
 
from rhodecode.lib.vcs.backends.base import EmptyChangeset
 

	
 
log = logging.getLogger(__name__)
 

	
 
@@ -99,32 +97,50 @@ class CompareController(BaseRepoControll
 
            other_repo=org_repo,
 
            other_ref_type=org_ref[0], other_ref=org_ref[1])
 

	
 
        c.org_repo = org_repo = Repository.get_by_repo_name(org_repo)
 
        c.other_repo = other_repo = Repository.get_by_repo_name(other_repo)
 
        partial = request.environ.get('HTTP_X_PARTIAL_XHR')
 

	
 
        org_repo = Repository.get_by_repo_name(org_repo)
 
        other_repo = Repository.get_by_repo_name(other_repo)
 

	
 
        if c.org_repo is None:
 
        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)
 

	
 
        if org_repo is None:
 
            log.error('Could not find org repo %s' % org_repo)
 
            raise HTTPNotFound
 
        if c.other_repo is None:
 
        if other_repo is None:
 
            log.error('Could not find other repo %s' % other_repo)
 
            raise HTTPNotFound
 

	
 
        if c.org_repo != c.other_repo and h.is_git(c.rhodecode_repo):
 
        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 c.org_repo.scm_instance.alias != c.other_repo.scm_instance.alias:
 
        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
 

	
 
        partial = request.environ.get('HTTP_X_PARTIAL_XHR')
 
        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)
 
        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:
 
            #replace our org_ref with given CS
 
            # 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
 
            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)
 
@@ -136,18 +152,13 @@ class CompareController(BaseRepoControll
 
        if partial:
 
            return render('compare/compare_cs.html')
 

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

	
 
        if ancestor  and c.org_repo != c.other_repo:
 
        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
 
            _org_ref = org_ref
 
            log.debug('Using ancestor %s as org_ref instead of %s', ancestor, _org_ref)
 
            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
 
@@ -227,13 +227,9 @@ class PullRequestModel(BaseModel):
 
        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)):
rhodecode/templates/pullrequests/pullrequest.html
Show inline comments
 
@@ -163,7 +163,6 @@
 
          var repo_name = sel_box.options[sel_box.selectedIndex].value;
 
          YUD.get('pull_request_overview_url').href = url;
 
          YUD.setStyle(YUD.get('pull_request_overview_url').parentElement,'display','');
 
          YUD.get('other_repo_gravatar').src = other_repos_info[repo_name]['gravatar'];
 
          YUD.get('other_repo_desc').innerHTML = other_repos_info[repo_name]['description'];
 
          YUD.get('other_ref').innerHTML = other_repos_info[repo_name]['revs'];
 
          // select back the revision that was just compared
rhodecode/tests/functional/test_compare.py
Show inline comments
 
@@ -27,7 +27,7 @@ def _fork_repo(fork_name, vcs_type, pare
 
        update_after_clone=False,
 
        fork_parent_id=Repository.get_by_repo_name(_REPO),
 
    )
 
    repo = RepoModel().create_fork(form_data, cur_user=TEST_USER_ADMIN_LOGIN)
 
    RepoModel().create_fork(form_data, cur_user=TEST_USER_ADMIN_LOGIN)
 

	
 
    Session().commit()
 
    return Repository.get_by_repo_name(fork_name)
 
@@ -87,7 +87,6 @@ class TestCompareController(TestControll
 

	
 
        #fork this repo
 
        repo2 = _fork_repo('one-fork', 'hg', parent='one')
 
        Session().commit()
 
        self.r2_id = repo2.repo_id
 

	
 
        #add two extra commit into fork
 
@@ -138,7 +137,6 @@ class TestCompareController(TestControll
 

	
 
        #fork this repo
 
        repo2 = _fork_repo('one-fork', 'hg', parent='one')
 
        Session().commit()
 
        self.r2_id = repo2.repo_id
 

	
 
        #now commit something to origin repo
 
@@ -178,18 +176,17 @@ class TestCompareController(TestControll
 
        response.mustcontain("""<a href="/%s/compare/branch@%s...branch@%s?as_form=None&amp;other_repo=%s">[swap]</a>""" % (repo2.repo_name, rev1, rev2, repo1.repo_name))
 

	
 
    def test_compare_cherry_pick_changesets_from_bottom(self):
 
        """
 
        repo1:
 
            cs1:
 
            cs2:
 
        repo1-fork- in which we will cherry pick bottom changesets
 
            cs1:
 
            cs2:
 
            cs3: x
 
            cs4: x
 
            cs5: x
 
            cs6:
 
        """
 

	
 
#        repo1:
 
#            cs0:
 
#            cs1:
 
#        repo1-fork- in which we will cherry pick bottom changesets
 
#            cs0:
 
#            cs1:
 
#            cs2: x
 
#            cs3: x
 
#            cs4: x
 
#            cs5:
 
        #make repo1, and cs1+cs2
 
        self.log_user()
 

	
 
@@ -200,25 +197,89 @@ class TestCompareController(TestControll
 
        self.r1_id = repo1.repo_id
 

	
 
        #commit something !
 
        cs1 = _commit_change(repo1.repo_name, filename='file1', content='line1\n',
 
        cs0 = _commit_change(repo1.repo_name, filename='file1', content='line1\n',
 
                             message='commit1', vcs_type='hg', parent=None,
 
                             newfile=True)
 
        cs2 = _commit_change(repo1.repo_name, filename='file1', content='line1\nline2\n',
 
                             message='commit2', vcs_type='hg', parent=cs1)
 
        cs1 = _commit_change(repo1.repo_name, filename='file1', content='line1\nline2\n',
 
                             message='commit2', vcs_type='hg', parent=cs0)
 
        #fork this repo
 
        repo2 = _fork_repo('repo1-fork', 'hg', parent='repo1')
 
        Session().commit()
 
        self.r2_id = repo2.repo_id
 
        #now make cs3-6
 
        cs3 = _commit_change(repo1.repo_name, filename='file1', content='line1\nline2\nline3\n',
 
                             message='commit3', vcs_type='hg', parent=cs2)
 
        cs4 = _commit_change(repo1.repo_name, filename='file1', content='line1\nline2\nline3\nline4\n',
 
                             message='commit4', vcs_type='hg', parent=cs3)
 
        cs5 = _commit_change(repo1.repo_name, filename='file1', content='line1\nline2\nline3\nline4\nline5\n',
 
                             message='commit5', vcs_type='hg', parent=cs4)
 
        cs6 = _commit_change(repo1.repo_name, filename='file1', content='line1\nline2\nline3\nline4\nline5\nline6\n',
 
                             message='commit6', vcs_type='hg', parent=cs5)
 
        cs2 = _commit_change(repo1.repo_name, filename='file1', content='line1\nline2\nline3\n',
 
                             message='commit3', vcs_type='hg', parent=cs1)
 
        cs3 = _commit_change(repo1.repo_name, filename='file1', content='line1\nline2\nline3\nline4\n',
 
                             message='commit4', vcs_type='hg', parent=cs2)
 
        cs4 = _commit_change(repo1.repo_name, filename='file1', content='line1\nline2\nline3\nline4\nline5\n',
 
                             message='commit5', vcs_type='hg', parent=cs3)
 
        cs5 = _commit_change(repo1.repo_name, filename='file1', content='line1\nline2\nline3\nline4\nline5\nline6\n',
 
                             message='commit6', vcs_type='hg', parent=cs4)
 

	
 
        rev1 = 'tip'
 
        rev2 = 'tip'
 

	
 
        response = self.app.get(url(controller='compare', action='index',
 
                                    repo_name=repo2.repo_name,
 
                                    org_ref_type="tag",
 
                                    org_ref=rev1,
 
                                    other_repo=repo1.repo_name,
 
                                    other_ref_type="tag",
 
                                    other_ref=rev2,
 
                                    rev_start=cs2.raw_id,
 
                                    rev_end=cs4.raw_id,
 
                                    ))
 
        response.mustcontain('%s@%s -&gt; %s@%s' % (repo2.repo_name, cs2.short_id, repo1.repo_name, cs4.short_id))
 
        response.mustcontain("""Showing 3 commits""")
 
        response.mustcontain("""1 file changed with 3 insertions and 0 deletions""")
 

	
 
        response.mustcontain("""<div class="message tooltip" title="commit3" style="white-space:normal">commit3</div>""")
 
        response.mustcontain("""<div class="message tooltip" title="commit4" style="white-space:normal">commit4</div>""")
 
        response.mustcontain("""<div class="message tooltip" title="commit5" style="white-space:normal">commit5</div>""")
 

	
 
        response.mustcontain("""<a href="/%s/changeset/%s">r2:%s</a>""" % (repo1.repo_name, cs2.raw_id, cs2.short_id))
 
        response.mustcontain("""<a href="/%s/changeset/%s">r3:%s</a>""" % (repo1.repo_name, cs3.raw_id, cs3.short_id))
 
        response.mustcontain("""<a href="/%s/changeset/%s">r4:%s</a>""" % (repo1.repo_name, cs4.raw_id, cs4.short_id))
 
        ## files
 
        response.mustcontain("""#C--826e8142e6ba">file1</a>""")
 

	
 
    def test_compare_cherry_pick_changesets_from_top(self):
 
#        repo1:
 
#            cs0:
 
#            cs1:
 
#        repo1-fork- in which we will cherry pick bottom changesets
 
#            cs0:
 
#            cs1:
 
#            cs2:
 
#            cs3: x
 
#            cs4: x
 
#            cs5: x
 
#
 
        #make repo1, and cs1+cs2
 
        self.log_user()
 
        repo1 = RepoModel().create_repo(repo_name='repo1', repo_type='hg',
 
                                        description='diff-test',
 
                                        owner=TEST_USER_ADMIN_LOGIN)
 
        Session().commit()
 
        self.r1_id = repo1.repo_id
 

	
 
        #commit something !
 
        cs0 = _commit_change(repo1.repo_name, filename='file1', content='line1\n',
 
                             message='commit1', vcs_type='hg', parent=None,
 
                             newfile=True)
 
        cs1 = _commit_change(repo1.repo_name, filename='file1', content='line1\nline2\n',
 
                             message='commit2', vcs_type='hg', parent=cs0)
 
        #fork this repo
 
        repo2 = _fork_repo('repo1-fork', 'hg', parent='repo1')
 
        self.r2_id = repo2.repo_id
 
        #now make cs3-6
 
        cs2 = _commit_change(repo1.repo_name, filename='file1', content='line1\nline2\nline3\n',
 
                             message='commit3', vcs_type='hg', parent=cs1)
 
        cs3 = _commit_change(repo1.repo_name, filename='file1', content='line1\nline2\nline3\nline4\n',
 
                             message='commit4', vcs_type='hg', parent=cs2)
 
        cs4 = _commit_change(repo1.repo_name, filename='file1', content='line1\nline2\nline3\nline4\nline5\n',
 
                             message='commit5', vcs_type='hg', parent=cs3)
 
        cs5 = _commit_change(repo1.repo_name, filename='file1', content='line1\nline2\nline3\nline4\nline5\nline6\n',
 
                             message='commit6', vcs_type='hg', parent=cs4)
 
        rev1 = 'tip'
 
        rev2 = 'tip'
 

	
 
@@ -232,91 +293,20 @@ class TestCompareController(TestControll
 
                                    rev_start=cs3.raw_id,
 
                                    rev_end=cs5.raw_id,
 
                                    ))
 
        response.mustcontain('%s@%s -&gt; %s@%s' % (repo2.repo_name, rev1, repo1.repo_name, rev2))
 

	
 
        response.mustcontain('%s@%s -&gt; %s@%s' % (repo2.repo_name, cs3.short_id, repo1.repo_name, cs5.short_id))
 
        response.mustcontain("""Showing 3 commits""")
 
        response.mustcontain("""1 file changed with 3 insertions and 0 deletions""")
 

	
 
        response.mustcontain("""<div class="message tooltip" title="commit3" style="white-space:normal">commit3</div>""")
 
        response.mustcontain("""<div class="message tooltip" title="commit4" style="white-space:normal">commit4</div>""")
 
        response.mustcontain("""<div class="message tooltip" title="commit5" style="white-space:normal">commit5</div>""")
 

	
 
        response.mustcontain("""<a href="/%s/changeset/%s">r3:%s</a>""" % (repo2.repo_name, cs3.raw_id, cs3.short_id))
 
        response.mustcontain("""<a href="/%s/changeset/%s">r4:%s</a>""" % (repo2.repo_name, cs4.raw_id, cs4.short_id))
 
        response.mustcontain("""<a href="/%s/changeset/%s">r5:%s</a>""" % (repo2.repo_name, cs5.raw_id, cs5.short_id))
 
        ## files
 
        response.mustcontain("""<a href="/%s/compare/tag@%s...tag@%s?other_repo=%s#C--826e8142e6ba">file1</a>""" % (repo2.repo_name, rev1, rev2, repo1.repo_name))
 
        #swap
 
        response.mustcontain("""<a href="/%s/compare/tag@%s...tag@%s?as_form=None&amp;other_repo=%s">[swap]</a>""" % (repo1.repo_name, rev1, rev2, repo2.repo_name))
 

	
 
    def test_compare_cherry_pick_changesets_from_top(self):
 
        """
 
        repo1:
 
            cs1:
 
            cs2:
 
        repo1-fork- in which we will cherry pick bottom changesets
 
            cs1:
 
            cs2:
 
            cs3:
 
            cs4: x
 
            cs5: x
 
            cs6: x
 
        """
 
        #make repo1, and cs1+cs2
 
        self.log_user()
 
        repo1 = RepoModel().create_repo(repo_name='repo1', repo_type='hg',
 
                                        description='diff-test',
 
                                        owner=TEST_USER_ADMIN_LOGIN)
 
        Session().commit()
 
        self.r1_id = repo1.repo_id
 
        response.mustcontain("""<div class="message tooltip" title="commit6" style="white-space:normal">commit6</div>""")
 

	
 
        #commit something !
 
        cs1 = _commit_change(repo1.repo_name, filename='file1', content='line1\n',
 
                             message='commit1', vcs_type='hg', parent=None,
 
                             newfile=True)
 
        cs2 = _commit_change(repo1.repo_name, filename='file1', content='line1\nline2\n',
 
                             message='commit2', vcs_type='hg', parent=cs1)
 
        #fork this repo
 
        repo2 = _fork_repo('repo1-fork', 'hg', parent='repo1')
 
        Session().commit()
 
        self.r2_id = repo1.repo_id
 
        #now make cs3-6
 
        cs3 = _commit_change(repo1.repo_name, filename='file1', content='line1\nline2\nline3\n',
 
                             message='commit3', vcs_type='hg', parent=cs2)
 
        cs4 = _commit_change(repo1.repo_name, filename='file1', content='line1\nline2\nline3\nline4\n',
 
                             message='commit4', vcs_type='hg', parent=cs3)
 
        cs5 = _commit_change(repo1.repo_name, filename='file1', content='line1\nline2\nline3\nline4\nline5\n',
 
                             message='commit5', vcs_type='hg', parent=cs4)
 
        cs6 = _commit_change(repo1.repo_name, filename='file1', content='line1\nline2\nline3\nline4\nline5\nline6\n',
 
                             message='commit6', vcs_type='hg', parent=cs5)
 
        rev1 = 'tip'
 
        rev2 = 'tip'
 

	
 
        response = self.app.get(url(controller='compare', action='index',
 
                                    repo_name=repo2.repo_name,
 
                                    org_ref_type="tag",
 
                                    org_ref=rev1,
 
                                    other_repo=repo1.repo_name,
 
                                    other_ref_type="tag",
 
                                    other_ref=rev2,
 
                                    rev_start=cs4.raw_id,
 
                                    rev_end=cs6.raw_id,
 
                                    ))
 

	
 
        response.mustcontain('%s@%s -&gt; %s@%s' % (repo2.repo_name, rev1, repo1.repo_name, rev2))
 
        response.mustcontain("""Showing 3 commits""")
 
        response.mustcontain("""1 file changed with 3 insertions and 0 deletions""")
 

	
 
        response.mustcontain("""<div class="message tooltip" title="commit3" style="white-space:normal">commit4</div>""")
 
        response.mustcontain("""<div class="message tooltip" title="commit4" style="white-space:normal">commit5</div>""")
 
        response.mustcontain("""<div class="message tooltip" title="commit5" style="white-space:normal">commit6</div>""")
 

	
 
        response.mustcontain("""<a href="/%s/changeset/%s">r4:%s</a>""" % (repo2.repo_name, cs4.raw_id, cs4.short_id))
 
        response.mustcontain("""<a href="/%s/changeset/%s">r5:%s</a>""" % (repo2.repo_name, cs5.raw_id, cs5.short_id))
 
        response.mustcontain("""<a href="/%s/changeset/%s">r6:%s</a>""" % (repo2.repo_name, cs6.raw_id, cs6.short_id))
 
        response.mustcontain("""<a href="/%s/changeset/%s">r3:%s</a>""" % (repo1.repo_name, cs3.raw_id, cs3.short_id))
 
        response.mustcontain("""<a href="/%s/changeset/%s">r4:%s</a>""" % (repo1.repo_name, cs4.raw_id, cs4.short_id))
 
        response.mustcontain("""<a href="/%s/changeset/%s">r5:%s</a>""" % (repo1.repo_name, cs5.raw_id, cs5.short_id))
 
        ## files
 
        response.mustcontain("""<a href="/%s/compare/tag@%s...tag@%s?other_repo=%s#C--826e8142e6ba">file1</a>""" % (repo2.repo_name, rev1, rev2, repo1.repo_name))
 
        #swap
 
        response.mustcontain("""<a href="/%s/compare/tag@%s...tag@%s?as_form=None&amp;other_repo=%s">[swap]</a>""" % (repo1.repo_name, rev1, rev2, repo2.repo_name))
 
        response.mustcontain("""#C--826e8142e6ba">file1</a>""")
 

	
 
    def test_compare_cherry_pick_changeset_mixed_branches(self):
 
        """
 
@@ -328,8 +318,8 @@ class TestCompareController(TestControll
 
    def test_compare_remote_branches_hg(self):
 
        self.log_user()
 

	
 
        _fork_repo(HG_FORK, 'hg')
 

	
 
        repo2 = _fork_repo(HG_FORK, 'hg')
 
        self.r2_id = repo2.repo_id
 
        rev1 = '56349e29c2af'
 
        rev2 = '7d4bc8ec6be5'
 

	
0 comments (0 inline, 0 general)