##// END OF EJS Templates
diffs: add new diffs to pull request page
dan -
r1159:ac92afc0 default
parent child Browse files
Show More
@@ -43,7 +43,7 b' from rhodecode.lib.utils import action_l'
43 from rhodecode.lib.utils2 import safe_unicode
43 from rhodecode.lib.utils2 import safe_unicode
44 from rhodecode.lib.vcs.backends.base import EmptyCommit
44 from rhodecode.lib.vcs.backends.base import EmptyCommit
45 from rhodecode.lib.vcs.exceptions import (
45 from rhodecode.lib.vcs.exceptions import (
46 RepositoryError, CommitDoesNotExistError)
46 RepositoryError, CommitDoesNotExistError, NodeDoesNotExistError)
47 from rhodecode.model.db import ChangesetComment, ChangesetStatus
47 from rhodecode.model.db import ChangesetComment, ChangesetStatus
48 from rhodecode.model.changeset_status import ChangesetStatusModel
48 from rhodecode.model.changeset_status import ChangesetStatusModel
49 from rhodecode.model.comment import ChangesetCommentsModel
49 from rhodecode.model.comment import ChangesetCommentsModel
@@ -35,7 +35,7 b' from sqlalchemy.sql import func'
35 from sqlalchemy.sql.expression import or_
35 from sqlalchemy.sql.expression import or_
36
36
37 from rhodecode import events
37 from rhodecode import events
38 from rhodecode.lib import auth, diffs, helpers as h
38 from rhodecode.lib import auth, diffs, helpers as h, codeblocks
39 from rhodecode.lib.ext_json import json
39 from rhodecode.lib.ext_json import json
40 from rhodecode.lib.base import (
40 from rhodecode.lib.base import (
41 BaseRepoController, render, vcs_operation_context)
41 BaseRepoController, render, vcs_operation_context)
@@ -43,11 +43,13 b' from rhodecode.lib.auth import ('
43 LoginRequired, HasRepoPermissionAnyDecorator, NotAnonymous,
43 LoginRequired, HasRepoPermissionAnyDecorator, NotAnonymous,
44 HasAcceptedRepoType, XHRRequired)
44 HasAcceptedRepoType, XHRRequired)
45 from rhodecode.lib.channelstream import channelstream_request
45 from rhodecode.lib.channelstream import channelstream_request
46 from rhodecode.lib.compat import OrderedDict
46 from rhodecode.lib.utils import jsonify
47 from rhodecode.lib.utils import jsonify
47 from rhodecode.lib.utils2 import safe_int, safe_str, str2bool, safe_unicode
48 from rhodecode.lib.utils2 import safe_int, safe_str, str2bool, safe_unicode
48 from rhodecode.lib.vcs.backends.base import EmptyCommit, UpdateFailureReason
49 from rhodecode.lib.vcs.backends.base import EmptyCommit, UpdateFailureReason
49 from rhodecode.lib.vcs.exceptions import (
50 from rhodecode.lib.vcs.exceptions import (
50 EmptyRepositoryError, CommitDoesNotExistError, RepositoryRequirementError)
51 EmptyRepositoryError, CommitDoesNotExistError, RepositoryRequirementError,
52 NodeDoesNotExistError)
51 from rhodecode.lib.diffs import LimitedDiffContainer
53 from rhodecode.lib.diffs import LimitedDiffContainer
52 from rhodecode.model.changeset_status import ChangesetStatusModel
54 from rhodecode.model.changeset_status import ChangesetStatusModel
53 from rhodecode.model.comment import ChangesetCommentsModel
55 from rhodecode.model.comment import ChangesetCommentsModel
@@ -64,7 +66,7 b' class PullrequestsController(BaseRepoCon'
64 def __before__(self):
66 def __before__(self):
65 super(PullrequestsController, self).__before__()
67 super(PullrequestsController, self).__before__()
66
68
67 def _load_compare_data(self, pull_request, enable_comments=True):
69 def _load_compare_data(self, pull_request, inline_comments, enable_comments=True):
68 """
70 """
69 Load context data needed for generating compare diff
71 Load context data needed for generating compare diff
70
72
@@ -117,6 +119,7 b' class PullrequestsController(BaseRepoCon'
117 except RepositoryRequirementError:
119 except RepositoryRequirementError:
118 c.missing_requirements = True
120 c.missing_requirements = True
119
121
122 c.changes = {}
120 c.missing_commits = False
123 c.missing_commits = False
121 if (c.missing_requirements or
124 if (c.missing_requirements or
122 isinstance(source_commit, EmptyCommit) or
125 isinstance(source_commit, EmptyCommit) or
@@ -126,11 +129,31 b' class PullrequestsController(BaseRepoCon'
126 else:
129 else:
127 vcs_diff = PullRequestModel().get_diff(pull_request)
130 vcs_diff = PullRequestModel().get_diff(pull_request)
128 diff_processor = diffs.DiffProcessor(
131 diff_processor = diffs.DiffProcessor(
129 vcs_diff, format='gitdiff', diff_limit=diff_limit,
132 vcs_diff, format='newdiff', diff_limit=diff_limit,
130 file_limit=file_limit, show_full_diff=c.fulldiff)
133 file_limit=file_limit, show_full_diff=c.fulldiff)
131 _parsed = diff_processor.prepare()
134 _parsed = diff_processor.prepare()
132
135
133 c.limited_diff = isinstance(_parsed, LimitedDiffContainer)
136 commit_changes = OrderedDict()
137 _parsed = diff_processor.prepare()
138 c.limited_diff = isinstance(_parsed, diffs.LimitedDiffContainer)
139
140 _parsed = diff_processor.prepare()
141
142 def _node_getter(commit):
143 def get_node(fname):
144 try:
145 return commit.get_node(fname)
146 except NodeDoesNotExistError:
147 return None
148 return get_node
149
150 c.diffset = codeblocks.DiffSet(
151 repo_name=c.repo_name,
152 source_node_getter=_node_getter(target_commit),
153 target_node_getter=_node_getter(source_commit),
154 comments=inline_comments
155 ).render_patchset(_parsed, target_commit.raw_id, source_commit.raw_id)
156
134
157
135 c.files = []
158 c.files = []
136 c.changes = {}
159 c.changes = {}
@@ -139,17 +162,17 b' class PullrequestsController(BaseRepoCon'
139 c.included_files = []
162 c.included_files = []
140 c.deleted_files = []
163 c.deleted_files = []
141
164
142 for f in _parsed:
165 # for f in _parsed:
143 st = f['stats']
166 # st = f['stats']
144 c.lines_added += st['added']
167 # c.lines_added += st['added']
145 c.lines_deleted += st['deleted']
168 # c.lines_deleted += st['deleted']
146
169
147 fid = h.FID('', f['filename'])
170 # fid = h.FID('', f['filename'])
148 c.files.append([fid, f['operation'], f['filename'], f['stats']])
171 # c.files.append([fid, f['operation'], f['filename'], f['stats']])
149 c.included_files.append(f['filename'])
172 # c.included_files.append(f['filename'])
150 html_diff = diff_processor.as_html(enable_comments=enable_comments,
173 # html_diff = diff_processor.as_html(enable_comments=enable_comments,
151 parsed_lines=[f])
174 # parsed_lines=[f])
152 c.changes[fid] = [f['operation'], f['filename'], html_diff, f]
175 # c.changes[fid] = [f['operation'], f['filename'], html_diff, f]
153
176
154 def _extract_ordering(self, request):
177 def _extract_ordering(self, request):
155 column_index = safe_int(request.GET.get('order[0][column]'))
178 column_index = safe_int(request.GET.get('order[0][column]'))
@@ -703,23 +726,13 b' class PullrequestsController(BaseRepoCon'
703 c.pr_merge_status = False
726 c.pr_merge_status = False
704 # load compare data into template context
727 # load compare data into template context
705 enable_comments = not c.pull_request.is_closed()
728 enable_comments = not c.pull_request.is_closed()
706 self._load_compare_data(c.pull_request, enable_comments=enable_comments)
707
729
708 # this is a hack to properly display links, when creating PR, the
709 # compare view and others uses different notation, and
710 # compare_commits.html renders links based on the target_repo.
711 # We need to swap that here to generate it properly on the html side
712 c.target_repo = c.source_repo
713
730
714 # inline comments
731 # inline comments
715 c.inline_cnt = 0
716 c.inline_comments = cc_model.get_inline_comments(
732 c.inline_comments = cc_model.get_inline_comments(
717 c.rhodecode_db_repo.repo_id,
733 c.rhodecode_db_repo.repo_id,
718 pull_request=pull_request_id).items()
734 pull_request=pull_request_id)
719 # count inline comments
735 c.inline_cnt = len(c.inline_comments)
720 for __, lines in c.inline_comments:
721 for comments in lines.values():
722 c.inline_cnt += len(comments)
723
736
724 # outdated comments
737 # outdated comments
725 c.outdated_cnt = 0
738 c.outdated_cnt = 0
@@ -736,6 +749,15 b' class PullrequestsController(BaseRepoCon'
736 else:
749 else:
737 c.outdated_comments = {}
750 c.outdated_comments = {}
738
751
752 self._load_compare_data(
753 c.pull_request, c.inline_comments, enable_comments=enable_comments)
754
755 # this is a hack to properly display links, when creating PR, the
756 # compare view and others uses different notation, and
757 # compare_commits.html renders links based on the target_repo.
758 # We need to swap that here to generate it properly on the html side
759 c.target_repo = c.source_repo
760
739 # comments
761 # comments
740 c.comments = cc_model.get_comments(c.rhodecode_db_repo.repo_id,
762 c.comments = cc_model.get_comments(c.rhodecode_db_repo.repo_id,
741 pull_request=pull_request_id)
763 pull_request=pull_request_id)
@@ -710,7 +710,13 b' input.filediff-collapse-state {'
710 background: @alert3-inner;
710 background: @alert3-inner;
711 border: 1px solid @alert3;
711 border: 1px solid @alert3;
712 }
712 }
713 &.diffset-comments-disabled {
714 .cb-comment-box-opener, .comment-inline-form, .cb-comment-add-button {
715 display: none !important;
713 }
716 }
717 }
718 }
719
714 .pill {
720 .pill {
715 display: block;
721 display: block;
716 float: left;
722 float: left;
@@ -1024,6 +1030,7 b' table.cb {'
1024 }
1030 }
1025 }
1031 }
1026
1032
1033
1027 td {
1034 td {
1028 vertical-align: top;
1035 vertical-align: top;
1029 padding: 0;
1036 padding: 0;
@@ -34,9 +34,12 b" return h.url('', **new_args)"
34 # add a ruler at to the output
34 # add a ruler at to the output
35 ruler_at_chars=0,
35 ruler_at_chars=0,
36
36
37 # turn on inline comments
37 # show inline comments
38 use_comments=False,
38 use_comments=False,
39
39
40 # disable new comments
41 disable_new_comments=False,
42
40 )">
43 )">
41
44
42 %if use_comments:
45 %if use_comments:
@@ -127,8 +130,7 b' collapse_all = len(diffset.files) > coll'
127 left: ${ruler_at_chars + 5}ch;
130 left: ${ruler_at_chars + 5}ch;
128 </style>
131 </style>
129 %endif
132 %endif
130
133 <div class="diffset ${disable_new_comments and 'diffset-comments-disabled'}">
131 <div class="diffset">
132 <div class="diffset-heading ${diffset.limited_diff and 'diffset-heading-warning' or ''}">
134 <div class="diffset-heading ${diffset.limited_diff and 'diffset-heading-warning' or ''}">
133 %if commit:
135 %if commit:
134 <div class="pull-right">
136 <div class="pull-right">
@@ -299,142 +299,17 b''
299 </div>
299 </div>
300 % if not c.missing_commits:
300 % if not c.missing_commits:
301 <%include file="/compare/compare_commits.html" />
301 <%include file="/compare/compare_commits.html" />
302 ## FILES
302 <div class="cs_files">
303 <div class="cs_files_title">
303 <%namespace name="cbdiffs" file="/codeblocks/diffs.html"/>
304 <span class="cs_files_expand">
304 ${cbdiffs.render_diffset_menu()}
305 <span id="expand_all_files">${_('Expand All')}</span> | <span id="collapse_all_files">${_('Collapse All')}</span>
305 ${cbdiffs.render_diffset(
306 </span>
306 c.diffset, use_comments=True,
307 <h2>
307 collapse_when_files_over=30,
308 ${diff_block.diff_summary_text(len(c.files), c.lines_added, c.lines_deleted, c.limited_diff)}
308 disable_new_comments=c.pull_request.is_closed())}
309 </h2>
309
310 </div>
310 </div>
311 % endif
311 % endif
312 <div class="cs_files">
313 %if not c.files and not c.missing_commits:
314 <span class="empty_data">${_('No files')}</span>
315 %endif
316 <table class="compare_view_files">
317 <%namespace name="diff_block" file="/changeset/diff_block.html"/>
318 %for FID, change, path, stats in c.files:
319 <tr class="cs_${change} collapse_file" fid="${FID}">
320 <td class="cs_icon_td">
321 <span class="collapse_file_icon" fid="${FID}"></span>
322 </td>
323 <td class="cs_icon_td">
324 <div class="flag_status not_reviewed hidden"></div>
325 </td>
326 <td class="cs_${change}" id="a_${FID}">
327 <div class="node">
328 <a href="#a_${FID}">
329 <i class="icon-file-${change.lower()}"></i>
330 ${h.safe_unicode(path)}
331 </a>
332 </div>
312 </div>
333 </td>
334 <td>
335 <div class="changes pull-right">${h.fancy_file_stats(stats)}</div>
336 <div class="comment-bubble pull-right" data-path="${path}">
337 <i class="icon-comment"></i>
338 </div>
339 </td>
340 </tr>
341 <tr fid="${FID}" id="diff_${FID}" class="diff_links">
342 <td></td>
343 <td></td>
344 <td class="cs_${change}">
345 %if c.target_repo.repo_name == c.repo_name:
346 ${diff_block.diff_menu(c.repo_name, h.safe_unicode(path), c.target_ref, c.source_ref, change)}
347 %else:
348 ## this is slightly different case later, since the other repo can have this
349 ## file in other state than the origin repo
350 ${diff_block.diff_menu(c.target_repo.repo_name, h.safe_unicode(path), c.target_ref, c.source_ref, change)}
351 %endif
352 </td>
353 <td class="td-actions rc-form">
354 <div data-comment-id="${FID}" class="btn-link show-inline-comments comments-visible">
355 <span class="comments-show">${_('Show comments')}</span>
356 <span class="comments-hide">${_('Hide comments')}</span>
357 </div>
358 </td>
359 </tr>
360 <tr id="tr_${FID}">
361 <td></td>
362 <td></td>
363 <td class="injected_diff" colspan="2">
364 ${diff_block.diff_block_simple([c.changes[FID]])}
365 </td>
366 </tr>
367
368 ## Loop through inline comments
369 % if c.outdated_comments.get(path,False):
370 <tr class="outdated">
371 <td></td>
372 <td></td>
373 <td colspan="2">
374 <p>${_('Outdated Inline Comments')}:</p>
375 </td>
376 </tr>
377 <tr class="outdated">
378 <td></td>
379 <td></td>
380 <td colspan="2" class="outdated_comment_block">
381 % for line, comments in c.outdated_comments[path].iteritems():
382 <div class="inline-comment-placeholder" path="${path}" target_id="${h.safeid(h.safe_unicode(path))}">
383 % for co in comments:
384 ${comment.comment_block_outdated(co)}
385 % endfor
386 </div>
387 % endfor
388 </td>
389 </tr>
390 % endif
391 %endfor
392 ## Loop through inline comments for deleted files
393 %for path in c.deleted_files:
394 <tr class="outdated deleted">
395 <td></td>
396 <td></td>
397 <td>${path}</td>
398 </tr>
399 <tr class="outdated deleted">
400 <td></td>
401 <td></td>
402 <td>(${_('Removed')})</td>
403 </tr>
404 % if path in c.outdated_comments:
405 <tr class="outdated deleted">
406 <td></td>
407 <td></td>
408 <td colspan="2">
409 <p>${_('Outdated Inline Comments')}:</p>
410 </td>
411 </tr>
412 <tr class="outdated">
413 <td></td>
414 <td></td>
415 <td colspan="2" class="outdated_comment_block">
416 % for line, comments in c.outdated_comments[path].iteritems():
417 <div class="inline-comment-placeholder" path="${path}" target_id="${h.safeid(h.safe_unicode(path))}">
418 % for co in comments:
419 ${comment.comment_block_outdated(co)}
420 % endfor
421 </div>
422 % endfor
423 </td>
424 </tr>
425 % endif
426 %endfor
427 </table>
428 </div>
429 % if c.limited_diff:
430 <h5>${_('Commit was too big and was cut off...')} <a href="${h.url.current(fulldiff=1, **request.GET.mixed())}" onclick="return confirm('${_("Showing a huge diff might take some time and resources")}')">${_('Show full diff')}</a></h5>
431 % endif
432 </div>
433 </div>
434
435 % if c.limited_diff:
436 <p>${_('Commit was too big and was cut off...')} <a href="${h.url.current(fulldiff=1, **request.GET.mixed())}" onclick="return confirm('${_("Showing a huge diff might take some time and resources")}')">${_('Show full diff')}</a></p>
437 % endif
438
313
439 ## template for inline comment form
314 ## template for inline comment form
440 <%namespace name="comment" file="/changeset/changeset_file_comment.html"/>
315 <%namespace name="comment" file="/changeset/changeset_file_comment.html"/>
General Comments 0
You need to be logged in to leave comments. Login now