Mercurial > kallithea
changeset 3323:a07296564f6b beta
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.
author | Mads Kiilerich <madski@unity3d.com> |
---|---|
date | Fri, 01 Feb 2013 23:13:10 +0100 |
parents | c9b0f1d363c7 |
children | c9b85375776d |
files | rhodecode/controllers/compare.py rhodecode/lib/diffs.py rhodecode/model/pull_request.py |
diffstat | 3 files changed, 27 insertions(+), 25 deletions(-) [+] |
line wrap: on
line diff
--- a/rhodecode/controllers/compare.py Fri Feb 01 23:13:10 2013 +0100 +++ b/rhodecode/controllers/compare.py Fri Feb 01 23:13:10 2013 +0100 @@ -126,9 +126,8 @@ 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 @@ 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
--- a/rhodecode/lib/diffs.py Fri Feb 01 23:13:10 2013 +0100 +++ b/rhodecode/lib/diffs.py Fri Feb 01 23:13:10 2013 +0100 @@ -713,4 +713,4 @@ ignore_whitespace=ignore_whitespace, context=context) return _diff - return '' + return '' # FIXME: when is it ever relevant to return nothing?
--- a/rhodecode/model/pull_request.py Fri Feb 01 23:13:10 2013 +0100 +++ b/rhodecode/model/pull_request.py Fri Feb 01 23:13:10 2013 +0100 @@ -160,8 +160,8 @@ 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 @@ :param tmp: """ - changesets = [] + ancestor = None if alias == 'hg': # lookup up the exact node id @@ -202,9 +202,14 @@ 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 @@ '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 @@ 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