diff --git a/rhodecode/controllers/changeset.py b/rhodecode/controllers/changeset.py --- a/rhodecode/controllers/changeset.py +++ b/rhodecode/controllers/changeset.py @@ -43,7 +43,7 @@ from rhodecode.lib.utils import action_l from rhodecode.lib.utils2 import safe_unicode from rhodecode.lib.vcs.backends.base import EmptyCommit from rhodecode.lib.vcs.exceptions import ( - RepositoryError, CommitDoesNotExistError) + RepositoryError, CommitDoesNotExistError, NodeDoesNotExistError) from rhodecode.model.db import ChangesetComment, ChangesetStatus from rhodecode.model.changeset_status import ChangesetStatusModel from rhodecode.model.comment import ChangesetCommentsModel diff --git a/rhodecode/controllers/pullrequests.py b/rhodecode/controllers/pullrequests.py --- a/rhodecode/controllers/pullrequests.py +++ b/rhodecode/controllers/pullrequests.py @@ -35,7 +35,7 @@ from sqlalchemy.sql import func from sqlalchemy.sql.expression import or_ from rhodecode import events -from rhodecode.lib import auth, diffs, helpers as h +from rhodecode.lib import auth, diffs, helpers as h, codeblocks from rhodecode.lib.ext_json import json from rhodecode.lib.base import ( BaseRepoController, render, vcs_operation_context) @@ -43,11 +43,13 @@ from rhodecode.lib.auth import ( LoginRequired, HasRepoPermissionAnyDecorator, NotAnonymous, HasAcceptedRepoType, XHRRequired) from rhodecode.lib.channelstream import channelstream_request +from rhodecode.lib.compat import OrderedDict from rhodecode.lib.utils import jsonify from rhodecode.lib.utils2 import safe_int, safe_str, str2bool, safe_unicode from rhodecode.lib.vcs.backends.base import EmptyCommit, UpdateFailureReason from rhodecode.lib.vcs.exceptions import ( - EmptyRepositoryError, CommitDoesNotExistError, RepositoryRequirementError) + EmptyRepositoryError, CommitDoesNotExistError, RepositoryRequirementError, + NodeDoesNotExistError) from rhodecode.lib.diffs import LimitedDiffContainer from rhodecode.model.changeset_status import ChangesetStatusModel from rhodecode.model.comment import ChangesetCommentsModel @@ -64,7 +66,7 @@ class PullrequestsController(BaseRepoCon def __before__(self): super(PullrequestsController, self).__before__() - def _load_compare_data(self, pull_request, enable_comments=True): + def _load_compare_data(self, pull_request, inline_comments, enable_comments=True): """ Load context data needed for generating compare diff @@ -117,6 +119,7 @@ class PullrequestsController(BaseRepoCon except RepositoryRequirementError: c.missing_requirements = True + c.changes = {} c.missing_commits = False if (c.missing_requirements or isinstance(source_commit, EmptyCommit) or @@ -126,11 +129,31 @@ class PullrequestsController(BaseRepoCon else: vcs_diff = PullRequestModel().get_diff(pull_request) diff_processor = diffs.DiffProcessor( - vcs_diff, format='gitdiff', diff_limit=diff_limit, + vcs_diff, format='newdiff', diff_limit=diff_limit, file_limit=file_limit, show_full_diff=c.fulldiff) _parsed = diff_processor.prepare() - c.limited_diff = isinstance(_parsed, LimitedDiffContainer) + commit_changes = OrderedDict() + _parsed = diff_processor.prepare() + c.limited_diff = isinstance(_parsed, diffs.LimitedDiffContainer) + + _parsed = diff_processor.prepare() + + def _node_getter(commit): + def get_node(fname): + try: + return commit.get_node(fname) + except NodeDoesNotExistError: + return None + return get_node + + c.diffset = codeblocks.DiffSet( + repo_name=c.repo_name, + source_node_getter=_node_getter(target_commit), + target_node_getter=_node_getter(source_commit), + comments=inline_comments + ).render_patchset(_parsed, target_commit.raw_id, source_commit.raw_id) + c.files = [] c.changes = {} @@ -139,17 +162,17 @@ class PullrequestsController(BaseRepoCon c.included_files = [] c.deleted_files = [] - for f in _parsed: - st = f['stats'] - c.lines_added += st['added'] - c.lines_deleted += st['deleted'] + # for f in _parsed: + # st = f['stats'] + # c.lines_added += st['added'] + # c.lines_deleted += st['deleted'] - fid = h.FID('', f['filename']) - c.files.append([fid, f['operation'], f['filename'], f['stats']]) - c.included_files.append(f['filename']) - html_diff = diff_processor.as_html(enable_comments=enable_comments, - parsed_lines=[f]) - c.changes[fid] = [f['operation'], f['filename'], html_diff, f] + # fid = h.FID('', f['filename']) + # c.files.append([fid, f['operation'], f['filename'], f['stats']]) + # c.included_files.append(f['filename']) + # html_diff = diff_processor.as_html(enable_comments=enable_comments, + # parsed_lines=[f]) + # c.changes[fid] = [f['operation'], f['filename'], html_diff, f] def _extract_ordering(self, request): column_index = safe_int(request.GET.get('order[0][column]')) @@ -703,23 +726,13 @@ class PullrequestsController(BaseRepoCon c.pr_merge_status = False # load compare data into template context enable_comments = not c.pull_request.is_closed() - self._load_compare_data(c.pull_request, enable_comments=enable_comments) - # this is a hack to properly display links, when creating PR, the - # compare view and others uses different notation, and - # compare_commits.html renders links based on the target_repo. - # We need to swap that here to generate it properly on the html side - c.target_repo = c.source_repo # inline comments - c.inline_cnt = 0 c.inline_comments = cc_model.get_inline_comments( c.rhodecode_db_repo.repo_id, - pull_request=pull_request_id).items() - # count inline comments - for __, lines in c.inline_comments: - for comments in lines.values(): - c.inline_cnt += len(comments) + pull_request=pull_request_id) + c.inline_cnt = len(c.inline_comments) # outdated comments c.outdated_cnt = 0 @@ -736,6 +749,15 @@ class PullrequestsController(BaseRepoCon else: c.outdated_comments = {} + self._load_compare_data( + c.pull_request, c.inline_comments, enable_comments=enable_comments) + + # this is a hack to properly display links, when creating PR, the + # compare view and others uses different notation, and + # compare_commits.html renders links based on the target_repo. + # We need to swap that here to generate it properly on the html side + c.target_repo = c.source_repo + # comments c.comments = cc_model.get_comments(c.rhodecode_db_repo.repo_id, pull_request=pull_request_id) diff --git a/rhodecode/public/css/code-block.less b/rhodecode/public/css/code-block.less --- a/rhodecode/public/css/code-block.less +++ b/rhodecode/public/css/code-block.less @@ -710,7 +710,13 @@ input.filediff-collapse-state { background: @alert3-inner; border: 1px solid @alert3; } + &.diffset-comments-disabled { + .cb-comment-box-opener, .comment-inline-form, .cb-comment-add-button { + display: none !important; + } + } } + .pill { display: block; float: left; @@ -1024,6 +1030,7 @@ table.cb { } } + td { vertical-align: top; padding: 0; diff --git a/rhodecode/templates/codeblocks/diffs.html b/rhodecode/templates/codeblocks/diffs.html --- a/rhodecode/templates/codeblocks/diffs.html +++ b/rhodecode/templates/codeblocks/diffs.html @@ -34,9 +34,12 @@ return h.url('', **new_args) # add a ruler at to the output ruler_at_chars=0, - # turn on inline comments + # show inline comments use_comments=False, + # disable new comments + disable_new_comments=False, + )"> %if use_comments: @@ -127,8 +130,7 @@ collapse_all = len(diffset.files) > coll left: ${ruler_at_chars + 5}ch; %endif - -
+
%if commit:
diff --git a/rhodecode/templates/pullrequests/pullrequest_show.html b/rhodecode/templates/pullrequests/pullrequest_show.html --- a/rhodecode/templates/pullrequests/pullrequest_show.html +++ b/rhodecode/templates/pullrequests/pullrequest_show.html @@ -299,143 +299,18 @@
% if not c.missing_commits: <%include file="/compare/compare_commits.html" /> - ## FILES -
- - ${_('Expand All')} | ${_('Collapse All')} - -

- ${diff_block.diff_summary_text(len(c.files), c.lines_added, c.lines_deleted, c.limited_diff)} -

-
- % endif
- %if not c.files and not c.missing_commits: - ${_('No files')} - %endif - - <%namespace name="diff_block" file="/changeset/diff_block.html"/> - %for FID, change, path, stats in c.files: - - - - - - - - - - - - - - - - - + <%namespace name="cbdiffs" file="/codeblocks/diffs.html"/> + ${cbdiffs.render_diffset_menu()} + ${cbdiffs.render_diffset( + c.diffset, use_comments=True, + collapse_when_files_over=30, + disable_new_comments=c.pull_request.is_closed())} - ## Loop through inline comments - % if c.outdated_comments.get(path,False): - - - - - - - - - - - % endif - %endfor - ## Loop through inline comments for deleted files - %for path in c.deleted_files: - - - - - - - - - - - % if path in c.outdated_comments: - - - - - - - - - - - % endif - %endfor -
- - - - - - -
${h.fancy_file_stats(stats)}
-
- -
-
- ${diff_block.diff_block_simple([c.changes[FID]])} -
-

${_('Outdated Inline Comments')}:

-
- % for line, comments in c.outdated_comments[path].iteritems(): -
- % for co in comments: - ${comment.comment_block_outdated(co)} - % endfor -
- % endfor -
${path}
(${_('Removed')})
-

${_('Outdated Inline Comments')}:

-
- % for line, comments in c.outdated_comments[path].iteritems(): -
- % for co in comments: - ${comment.comment_block_outdated(co)} - % endfor -
- % endfor -
-
- % if c.limited_diff: -
${_('Commit was too big and was cut off...')} ${_('Show full diff')}
+
% endif -
- % if c.limited_diff: -

${_('Commit was too big and was cut off...')} ${_('Show full diff')}

- % endif - ## template for inline comment form <%namespace name="comment" file="/changeset/changeset_file_comment.html"/> ${comment.comment_inline_form()}