diff --git a/rhodecode/controllers/compare.py b/rhodecode/controllers/compare.py --- a/rhodecode/controllers/compare.py +++ b/rhodecode/controllers/compare.py @@ -89,6 +89,15 @@ class CompareController(BaseRepoControll # 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 @@ class CompareController(BaseRepoControll 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 @@ class CompareController(BaseRepoControll 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 --git a/rhodecode/controllers/pullrequests.py b/rhodecode/controllers/pullrequests.py --- a/rhodecode/controllers/pullrequests.py +++ b/rhodecode/controllers/pullrequests.py @@ -196,9 +196,9 @@ class PullrequestsController(BaseRepoCon 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 @@ class PullrequestsController(BaseRepoCon 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 @@ class PullrequestsController(BaseRepoCon 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 --git a/rhodecode/model/forms.py b/rhodecode/model/forms.py --- a/rhodecode/model/forms.py +++ b/rhodecode/model/forms.py @@ -395,4 +395,7 @@ def PullRequestForm(repo_id): 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 --git a/rhodecode/model/pull_request.py b/rhodecode/model/pull_request.py --- a/rhodecode/model/pull_request.py +++ b/rhodecode/model/pull_request.py @@ -161,7 +161,7 @@ class PullRequestModel(BaseModel): 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 @@ class PullRequestModel(BaseModel): 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 @@ class PullRequestModel(BaseModel): 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 @@ class PullRequestModel(BaseModel): 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 --git a/rhodecode/templates/changelog/changelog.html b/rhodecode/templates/changelog/changelog.html --- a/rhodecode/templates/changelog/changelog.html +++ b/rhodecode/templates/changelog/changelog.html @@ -37,7 +37,7 @@ ${_('Compare fork with parent')} + ${_('Compare fork with parent')} %endif %if h.is_hg(c.rhodecode_repo): ${_('Open new pull request')} diff --git a/rhodecode/templates/compare/compare_cs.html b/rhodecode/templates/compare/compare_cs.html --- a/rhodecode/templates/compare/compare_cs.html +++ b/rhodecode/templates/compare/compare_cs.html @@ -1,9 +1,9 @@ ## Changesets table !
%if c.rhodecode_db_repo.fork: -