# HG changeset patch # User Mads Kiilerich # Date 2013-02-01 23:13:10 # Node ID a07296564f6b8ec651ccc80d2e57c752045f6001 # Parent c9b0f1d363c7394258b3532b757d871c9a274e5f compare: show aggregated diff of what will be merged to other repo, using merge ancestor pull_request.get_compare_data will also now return the ancestor that would be used for actual merging. Showing a diff from that ancestor instead of the first 'new' changeset will give a more realistic diff that doesn't include merges. diff --git a/rhodecode/controllers/compare.py b/rhodecode/controllers/compare.py --- a/rhodecode/controllers/compare.py +++ b/rhodecode/controllers/compare.py @@ -126,9 +126,8 @@ class CompareController(BaseRepoControll org_ref = ('rev', rev_start) other_ref = ('rev', rev_end) - c.cs_ranges = PullRequestModel().get_compare_data( - org_repo, org_ref, other_repo, other_ref, - ) + 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]) @@ -141,15 +140,14 @@ class CompareController(BaseRepoControll c.org_ref = org_ref[1] c.other_ref = other_ref[1] - if c.cs_ranges and c.org_repo != c.other_repo: - # case we want a simple diff without incoming changesets, just - # for review purposes. Make the diff on the forked repo, with + if ancestor and c.org_repo != c.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 - org_ref = ('rev', getattr(c.cs_ranges[0].parents[0] - if c.cs_ranges[0].parents - else EmptyChangeset(), 'raw_id')) - log.debug('Changed org_ref from %s to %s' % (_org_ref, 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_limit = self.cut_off_limit if not fulldiff else None diff --git a/rhodecode/lib/diffs.py b/rhodecode/lib/diffs.py --- a/rhodecode/lib/diffs.py +++ b/rhodecode/lib/diffs.py @@ -713,4 +713,4 @@ def differ(org_repo, org_ref, other_repo ignore_whitespace=ignore_whitespace, context=context) return _diff - return '' + return '' # FIXME: when is it ever relevant to return nothing? 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 @@ -160,8 +160,8 @@ class PullRequestModel(BaseModel): def _get_changesets(self, alias, org_repo, org_ref, other_repo, other_ref): """ - Returns a list of changesets that are incoming from org_repo@org_ref - to 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: @@ -170,7 +170,7 @@ class PullRequestModel(BaseModel): :param tmp: """ - changesets = [] + ancestor = None if alias == 'hg': # lookup up the exact node id @@ -202,9 +202,14 @@ class PullRequestModel(BaseModel): revs = ["ancestors(id('%s')) and not ancestors(id('%s'))" % (other_rev, org_rev)] - out = scmutil.revrange(hgrepo, revs) - for cs in (out): - changesets.append(other_repo.get_changeset(cs)) + 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() elif alias == 'git': assert org_repo == other_repo, (org_repo, other_repo) # no git support for different repos @@ -212,11 +217,10 @@ class PullRequestModel(BaseModel): 'log --reverse --pretty="format: %%H" -s -p %s..%s' % (org_ref[1], other_ref[1]) ) - ids = re.findall(r'[0-9a-fA-F]{40}', so) - for cs in (ids): - changesets.append(org_repo.get_changeset(cs)) + changesets = [org_repo.get_changeset(cs) + for cs in re.findall(r'[0-9a-fA-F]{40}', so)] - return changesets + return changesets, ancestor def get_compare_data(self, org_repo, org_ref, other_repo, other_ref): """ @@ -242,7 +246,7 @@ class PullRequestModel(BaseModel): other_repo_scm = other_repo.scm_instance alias = org_repo.scm_instance.alias - cs_ranges = self._get_changesets(alias, - org_repo_scm, org_ref, - other_repo_scm, other_ref) - return cs_ranges + cs_ranges, ancestor = self._get_changesets(alias, + org_repo_scm, org_ref, + other_repo_scm, other_ref) + return cs_ranges, ancestor