# HG changeset patch # User Marcin Kuzminski # Date 1361235479 -3600 # Node ID 01fe360a66c09a38b32d1cf556634f46b035bf88 # Parent 8171dfafb5dbf6d38a2a9e7d6bd3e103668517e2 fixed pull-requests with cherry picking changesets - fixed tests for them diff -r 8171dfafb5db -r 01fe360a66c0 rhodecode/controllers/compare.py --- a/rhodecode/controllers/compare.py Mon Feb 18 22:56:54 2013 +0100 +++ b/rhodecode/controllers/compare.py Tue Feb 19 01:57:59 2013 +0100 @@ -40,9 +40,7 @@ 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 @@ 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 @@ 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 diff -r 8171dfafb5db -r 01fe360a66c0 rhodecode/model/pull_request.py --- a/rhodecode/model/pull_request.py Mon Feb 18 22:56:54 2013 +0100 +++ b/rhodecode/model/pull_request.py Tue Feb 19 01:57:59 2013 +0100 @@ -227,13 +227,9 @@ 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)): diff -r 8171dfafb5db -r 01fe360a66c0 rhodecode/templates/pullrequests/pullrequest.html --- a/rhodecode/templates/pullrequests/pullrequest.html Mon Feb 18 22:56:54 2013 +0100 +++ b/rhodecode/templates/pullrequests/pullrequest.html Tue Feb 19 01:57:59 2013 +0100 @@ -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 diff -r 8171dfafb5db -r 01fe360a66c0 rhodecode/tests/functional/test_compare.py --- a/rhodecode/tests/functional/test_compare.py Mon Feb 18 22:56:54 2013 +0100 +++ b/rhodecode/tests/functional/test_compare.py Tue Feb 19 01:57:59 2013 +0100 @@ -27,7 +27,7 @@ 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 @@ #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 @@ #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 @@ response.mustcontain("""[swap]""" % (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 @@ 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 -> %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("""
commit3
""") + response.mustcontain("""
commit4
""") + response.mustcontain("""
commit5
""") + + response.mustcontain("""r2:%s""" % (repo1.repo_name, cs2.raw_id, cs2.short_id)) + response.mustcontain("""r3:%s""" % (repo1.repo_name, cs3.raw_id, cs3.short_id)) + response.mustcontain("""r4:%s""" % (repo1.repo_name, cs4.raw_id, cs4.short_id)) + ## files + response.mustcontain("""#C--826e8142e6ba">file1""") + 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 @@ rev_start=cs3.raw_id, rev_end=cs5.raw_id, )) - response.mustcontain('%s@%s -> %s@%s' % (repo2.repo_name, rev1, repo1.repo_name, rev2)) + + response.mustcontain('%s@%s -> %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("""
commit3
""") response.mustcontain("""
commit4
""") response.mustcontain("""
commit5
""") - - response.mustcontain("""r3:%s""" % (repo2.repo_name, cs3.raw_id, cs3.short_id)) - response.mustcontain("""r4:%s""" % (repo2.repo_name, cs4.raw_id, cs4.short_id)) - response.mustcontain("""r5:%s""" % (repo2.repo_name, cs5.raw_id, cs5.short_id)) - ## files - response.mustcontain("""file1""" % (repo2.repo_name, rev1, rev2, repo1.repo_name)) - #swap - response.mustcontain("""[swap]""" % (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("""
commit6
""") - #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 -> %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("""
commit4
""") - response.mustcontain("""
commit5
""") - response.mustcontain("""
commit6
""") - - response.mustcontain("""r4:%s""" % (repo2.repo_name, cs4.raw_id, cs4.short_id)) - response.mustcontain("""r5:%s""" % (repo2.repo_name, cs5.raw_id, cs5.short_id)) - response.mustcontain("""r6:%s""" % (repo2.repo_name, cs6.raw_id, cs6.short_id)) + response.mustcontain("""r3:%s""" % (repo1.repo_name, cs3.raw_id, cs3.short_id)) + response.mustcontain("""r4:%s""" % (repo1.repo_name, cs4.raw_id, cs4.short_id)) + response.mustcontain("""r5:%s""" % (repo1.repo_name, cs5.raw_id, cs5.short_id)) ## files - response.mustcontain("""file1""" % (repo2.repo_name, rev1, rev2, repo1.repo_name)) - #swap - response.mustcontain("""[swap]""" % (repo1.repo_name, rev1, rev2, repo2.repo_name)) + response.mustcontain("""#C--826e8142e6ba">file1""") def test_compare_cherry_pick_changeset_mixed_branches(self): """ @@ -328,8 +318,8 @@ 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'