# HG changeset patch # User Mads Kiilerich # Date 1362480901 -3600 # Node ID 2053053e088272dbfca53eaad79df13ff4b0a263 # Parent b19b1723ff1007d407e6b60cf25ff15c613b4fc6 compare/pullrequest: introduce merge parameter This is more correct and flexible than the old way of looking on same/different repo. diff -r b19b1723ff10 -r 2053053e0882 rhodecode/controllers/compare.py --- a/rhodecode/controllers/compare.py Fri Mar 01 17:16:24 2013 +0100 +++ b/rhodecode/controllers/compare.py Tue Mar 05 11:55:01 2013 +0100 @@ -89,6 +89,15 @@ # other_ref will be evaluated in other_repo other_ref = (other_ref_type, other_ref) other_repo = request.GET.get('other_repo', org_repo) + # If merge is True: + # Show what org would get if merged with other: + # List changesets that are ancestors of other but not of org. + # New changesets in org is thus ignored. + # Diff will be from common ancestor, and merges of org to other will thus be ignored. + # If merge is False: + # Make a raw diff from org to other, no matter if related or not. + # Changesets in one and not in the other will be ignored + merge = bool(request.GET.get('merge')) # fulldiff disables cut_off_limit c.fulldiff = request.GET.get('fulldiff') # partial uses compare_cs.html template directly @@ -100,7 +109,8 @@ repo_name=other_repo, org_ref_type=other_ref[0], org_ref=other_ref[1], other_repo=org_repo, - other_ref_type=org_ref[0], other_ref=org_ref[1]) + other_ref_type=org_ref[0], other_ref=org_ref[1], + merge=merge or '') org_repo = Repository.get_by_repo_name(org_repo) other_repo = Repository.get_by_repo_name(other_repo) @@ -130,22 +140,23 @@ c.org_ref_type = org_ref[0] c.other_ref_type = other_ref[0] - c.cs_ranges, ancestor = PullRequestModel().get_compare_data( - org_repo, org_ref, other_repo, other_ref) + c.cs_ranges, c.ancestor = PullRequestModel().get_compare_data( + org_repo, org_ref, other_repo, other_ref, merge) c.statuses = c.rhodecode_db_repo.statuses([x.raw_id for x in c.cs_ranges]) if partial: + assert c.ancestor return render('compare/compare_cs.html') - if ancestor and org_repo != other_repo: + if c.ancestor: + assert merge # 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 + # Make the diff on the other repo (which is known to have other_ref) log.debug('Using ancestor %s as org_ref instead of %s' - % (ancestor, org_ref)) - org_ref = ('rev', ancestor) + % (c.ancestor, org_ref)) + org_ref = ('rev', c.ancestor) org_repo = other_repo diff_limit = self.cut_off_limit if not c.fulldiff else None diff -r b19b1723ff10 -r 2053053e0882 rhodecode/controllers/pullrequests.py --- a/rhodecode/controllers/pullrequests.py Fri Mar 01 17:16:24 2013 +0100 +++ b/rhodecode/controllers/pullrequests.py Tue Mar 05 11:55:01 2013 +0100 @@ -196,9 +196,9 @@ return redirect(url('pullrequest_home', repo_name=repo_name)) org_repo = _form['org_repo'] - org_ref = _form['org_ref'] + org_ref = 'rev:merge:%s' % _form['merge_rev'] other_repo = _form['other_repo'] - other_ref = _form['other_ref'] + other_ref = 'rev:ancestor:%s' % _form['ancestor_rev'] revisions = _form['revisions'] reviewers = _form['review_members'] @@ -281,10 +281,6 @@ c.cs_ranges = [org_repo.get_changeset(x) for x in pull_request.revisions] - other_ref = ('rev', getattr(c.cs_ranges[0].parents[0] - if c.cs_ranges[0].parents - else EmptyChangeset(), 'raw_id')) - c.statuses = org_repo.statuses([x.raw_id for x in c.cs_ranges]) c.org_ref = org_ref[1] @@ -385,6 +381,7 @@ c.changeset_statuses = ChangesetStatus.STATUSES c.as_form = False + c.ancestor = None # there is one - but right here we don't know which return render('/pullrequests/pullrequest_show.html') @NotAnonymous() diff -r b19b1723ff10 -r 2053053e0882 rhodecode/model/forms.py --- a/rhodecode/model/forms.py Fri Mar 01 17:16:24 2013 +0100 +++ b/rhodecode/model/forms.py Tue Mar 05 11:55:01 2013 +0100 @@ -395,4 +395,7 @@ pullrequest_title = v.UnicodeString(strip=True, required=True, min=3) pullrequest_desc = v.UnicodeString(strip=True, required=False) + ancestor_rev = v.UnicodeString(strip=True, required=True) + merge_rev = v.UnicodeString(strip=True, required=True) + return _PullRequestForm diff -r b19b1723ff10 -r 2053053e0882 rhodecode/model/pull_request.py --- a/rhodecode/model/pull_request.py Fri Mar 01 17:16:24 2013 +0100 +++ b/rhodecode/model/pull_request.py Tue Mar 05 11:55:01 2013 +0100 @@ -161,7 +161,7 @@ pull_request.updated_on = datetime.datetime.now() Session().add(pull_request) - def _get_changesets(self, alias, org_repo, org_ref, other_repo, other_ref): + def _get_changesets(self, alias, org_repo, org_ref, other_repo, other_ref, merge): """ 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 @@ -211,16 +211,21 @@ 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 merge: + revs = ["ancestors(id('%s')) and not ancestors(id('%s')) and not id('%s')" % + (other_rev, org_rev, org_rev)] - 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() + else: + # TODO: have both + and - changesets + revs = ["id('%s') :: id('%s') - id('%s')" % + (org_rev, other_rev, org_rev)] + + changesets = [other_repo.get_changeset(cs) + for cs in scmutil.revrange(hgrepo, revs)] elif alias == 'git': assert org_repo == other_repo, (org_repo, other_repo) # no git support for different repos @@ -233,7 +238,7 @@ return changesets, ancestor - def get_compare_data(self, org_repo, org_ref, other_repo, other_ref): + def get_compare_data(self, org_repo, org_ref, other_repo, other_ref, merge): """ Returns incoming changesets for mercurial repositories @@ -251,5 +256,6 @@ cs_ranges, ancestor = self._get_changesets(org_repo.scm_instance.alias, org_repo.scm_instance, org_ref, - other_repo.scm_instance, other_ref) + other_repo.scm_instance, other_ref, + merge) return cs_ranges, ancestor diff -r b19b1723ff10 -r 2053053e0882 rhodecode/templates/changelog/changelog.html --- a/rhodecode/templates/changelog/changelog.html Fri Mar 01 17:16:24 2013 +0100 +++ b/rhodecode/templates/changelog/changelog.html Tue Mar 05 11:55:01 2013 +0100 @@ -37,7 +37,7 @@ %if c.rhodecode_db_repo.fork: - ${_('Compare fork with parent')} + ${_('Compare fork with parent')} %endif %if h.is_hg(c.rhodecode_repo): ${_('Open new pull request')} diff -r b19b1723ff10 -r 2053053e0882 rhodecode/templates/compare/compare_cs.html --- a/rhodecode/templates/compare/compare_cs.html Fri Mar 01 17:16:24 2013 +0100 +++ b/rhodecode/templates/compare/compare_cs.html Tue Mar 05 11:55:01 2013 +0100 @@ -1,9 +1,9 @@ ## Changesets table !
- %if not c.cs_ranges: ${_('No changesets')} %else: +
%for cnt, cs in enumerate(c.cs_ranges): @@ -22,7 +22,15 @@ %endfor - +
gravatar
${h.urlify_commit(h.shorter(cs.message, 60),c.repo_name)}
+ %if c.ancestor: + ${_('Ancestor')}: + ${h.link_to(c.ancestor,h.url('changeset_home',repo_name=c.repo_name,revision=c.ancestor))} + + %endif + %if c.as_form: + ${h.hidden('ancestor_rev',c.ancestor)} + ${h.hidden('merge_rev',c.cs_ranges[-1].raw_id)} + %endif %endif -
diff -r b19b1723ff10 -r 2053053e0882 rhodecode/templates/pullrequests/pullrequest.html --- a/rhodecode/templates/pullrequests/pullrequest.html Fri Mar 01 17:16:24 2013 +0100 +++ b/rhodecode/templates/pullrequests/pullrequest.html Tue Mar 05 11:55:01 2013 +0100 @@ -133,6 +133,7 @@ other_ref_type='__org_ref_type__', other_ref='__org_ref__', as_form=True, + merge=True, )}"; var org_repo = YUQ('#pull_request_form #org_repo')[0].value; var org_ref = YUQ('#pull_request_form #org_ref')[0].value.split(':'); diff -r b19b1723ff10 -r 2053053e0882 rhodecode/tests/functional/test_compare.py --- a/rhodecode/tests/functional/test_compare.py Fri Mar 01 17:16:24 2013 +0100 +++ b/rhodecode/tests/functional/test_compare.py Tue Mar 05 11:55:01 2013 +0100 @@ -106,6 +106,7 @@ other_repo=repo2.repo_name, other_ref_type="branch", other_ref=rev1, + merge='1', )) response.mustcontain('%s@%s -> %s@%s' % (repo1.repo_name, rev2, repo2.repo_name, rev1)) @@ -118,9 +119,9 @@ response.mustcontain("""r1:%s""" % (repo2.repo_name, cs1.raw_id, cs1.short_id)) response.mustcontain("""r2:%s""" % (repo2.repo_name, cs2.raw_id, cs2.short_id)) ## files - response.mustcontain("""file1""" % (repo1.repo_name, rev2, rev1, repo2.repo_name)) + response.mustcontain("""file1""" % (repo1.repo_name, rev2, rev1, repo2.repo_name)) #swap - response.mustcontain("""[swap]""" % (repo2.repo_name, rev1, rev2, repo1.repo_name)) + response.mustcontain("""[swap]""" % (repo2.repo_name, rev1, rev2, repo1.repo_name)) def test_compare_forks_on_branch_extra_commits_origin_has_incomming_hg(self): self.log_user() @@ -160,6 +161,7 @@ other_repo=repo2.repo_name, other_ref_type="branch", other_ref=rev1, + merge='x', )) response.mustcontain('%s@%s -> %s@%s' % (repo1.repo_name, rev2, repo2.repo_name, rev1)) response.mustcontain("""Showing 2 commits""") @@ -171,9 +173,9 @@ response.mustcontain("""r1:%s""" % (repo2.repo_name, cs1.raw_id, cs1.short_id)) response.mustcontain("""r2:%s""" % (repo2.repo_name, cs2.raw_id, cs2.short_id)) ## files - response.mustcontain("""file1""" % (repo1.repo_name, rev2, rev1, repo2.repo_name)) + response.mustcontain("""file1""" % (repo1.repo_name, rev2, rev1, repo2.repo_name)) #swap - response.mustcontain("""[swap]""" % (repo2.repo_name, rev1, rev2, repo1.repo_name)) + response.mustcontain("""[swap]""" % (repo2.repo_name, rev1, rev2, repo1.repo_name)) def test_compare_cherry_pick_changesets_from_bottom(self): @@ -222,6 +224,7 @@ other_repo=repo1.repo_name, other_ref_type="rev", other_ref=cs4.short_id, + merge='True', )) response.mustcontain('%s@%s -> %s@%s' % (repo2.repo_name, cs1.short_id, repo1.repo_name, cs4.short_id)) response.mustcontain("""Showing 3 commits""") @@ -281,6 +284,7 @@ org_ref=cs2.short_id, # parent of cs3, not in repo2 other_ref_type="rev", other_ref=cs5.short_id, + merge='1', )) response.mustcontain('%s@%s -> %s@%s' % (repo1.repo_name, cs2.short_id, repo1.repo_name, cs5.short_id)) @@ -319,6 +323,7 @@ other_ref_type="rev", other_ref=rev2, other_repo=HG_FORK, + merge='1', )) response.mustcontain('%s@%s -> %s@%s' % (HG_REPO, rev1, HG_FORK, rev2)) ## outgoing changesets between those revisions @@ -328,9 +333,9 @@ response.mustcontain("""r6:%s""" % (HG_FORK, rev2)) ## files - response.mustcontain("""vcs/backends/hg.py""" % (HG_REPO, rev1, rev2, HG_FORK)) - response.mustcontain("""vcs/backends/__init__.py""" % (HG_REPO, rev1, rev2, HG_FORK)) - response.mustcontain("""vcs/backends/base.py""" % (HG_REPO, rev1, rev2, HG_FORK)) + response.mustcontain("""vcs/backends/hg.py""" % (HG_REPO, rev1, rev2, HG_FORK)) + response.mustcontain("""vcs/backends/__init__.py""" % (HG_REPO, rev1, rev2, HG_FORK)) + response.mustcontain("""vcs/backends/base.py""" % (HG_REPO, rev1, rev2, HG_FORK)) def test_org_repo_new_commits_after_forking_simple_diff(self): self.log_user() @@ -401,6 +406,7 @@ other_ref_type="branch", other_ref=rev2, other_repo=r1_name, + merge='1', )) response.mustcontain('%s@%s -> %s@%s' % (r2_name, rev1, r1_name, rev2)) response.mustcontain('No files') @@ -425,6 +431,7 @@ other_ref_type="branch", other_ref=rev2, other_repo=r1_name, + merge='1', )) response.mustcontain('%s@%s -> %s@%s' % (r2_name, rev1, r1_name, rev2))