diff --git a/rhodecode/apps/repository/views/repo_pull_requests.py b/rhodecode/apps/repository/views/repo_pull_requests.py --- a/rhodecode/apps/repository/views/repo_pull_requests.py +++ b/rhodecode/apps/repository/views/repo_pull_requests.py @@ -357,6 +357,9 @@ class RepoPullRequestsView(RepoAppView, pull_request_id=pull_request_id)) versions = pull_request_display_obj.versions() + + c.commit_versions = PullRequestModel().pr_commits_versions(versions) + # used to store per-commit range diffs c.changes = collections.OrderedDict() diff --git a/rhodecode/model/db.py b/rhodecode/model/db.py --- a/rhodecode/model/db.py +++ b/rhodecode/model/db.py @@ -3821,8 +3821,12 @@ class ChangesetComment(Base, BaseModel): return q.all() @classmethod - def get_index_from_version(cls, pr_version, versions): - num_versions = [x.pull_request_version_id for x in versions] + def get_index_from_version(cls, pr_version, versions=None, num_versions=None): + + if versions is not None: + num_versions = [x.pull_request_version_id for x in versions] + + num_versions = num_versions or [] try: return num_versions.index(pr_version) + 1 except (IndexError, ValueError): 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 @@ -610,6 +610,20 @@ class PullRequestModel(BaseModel): return _org_pull_request_obj, pull_request_obj, \ pull_request_display_obj, at_version + def pr_commits_versions(self, versions): + """ + Maps the pull-request commits into all known PR versions. This way we can obtain + each pr version the commit was introduced in. + """ + commit_versions = collections.defaultdict(list) + num_versions = [x.pull_request_version_id for x in versions] + for ver in versions: + for commit_id in ver.revisions: + ver_idx = ChangesetComment.get_index_from_version( + ver.pull_request_version_id, num_versions=num_versions) + commit_versions[commit_id].append(ver_idx) + return commit_versions + def create(self, created_by, source_repo, source_ref, target_repo, target_ref, revisions, reviewers, observers, title, description=None, common_ancestor_id=None, diff --git a/rhodecode/templates/compare/compare_commits.mako b/rhodecode/templates/compare/compare_commits.mako --- a/rhodecode/templates/compare/compare_commits.mako +++ b/rhodecode/templates/compare/compare_commits.mako @@ -12,6 +12,9 @@
ver | + % endif${_('Time')} | ${_('Author')} | ${_('Commit')} | @@ -30,6 +33,11 @@ class="compare_select" style="${'display: none' if c.collapse_all_commits else ''}" > + % if hasattr(c, 'commit_versions'): +
+ ${('v{}'.format(c.commit_versions[commit.raw_id][0]) if c.commit_versions[commit.raw_id] else 'latest')}
+ |
+ % endif
${h.age_component(commit.date)} |
---|