<%namespace name="commentblock" file="/changeset/changeset_file_comment.mako"/> <%def name="diff_line_anchor(commit, filename, line, type)"><% return '%s_%s_%i' % (h.md5_safe(commit+filename), type, line) %> <%def name="action_class(action)"> <% return { '-': 'cb-deletion', '+': 'cb-addition', ' ': 'cb-context', }.get(action, 'cb-empty') %> <%def name="op_class(op_id)"> <% return { DEL_FILENODE: 'deletion', # file deleted BIN_FILENODE: 'warning' # binary diff hidden }.get(op_id, 'addition') %> <%def name="render_diffset(diffset, commit=None, # collapse all file diff entries when there are more than this amount of files in the diff collapse_when_files_over=20, # collapse lines in the diff when more than this amount of lines changed in the file diff lines_changed_limit=500, # add a ruler at to the output ruler_at_chars=0, # show inline comments use_comments=False, # disable new comments disable_new_comments=False, # special file-comments that were deleted in previous versions # it's used for showing outdated comments for deleted files in a PR deleted_files_comments=None, # for cache purpose inline_comments=None, )"> %if use_comments:
${inline_comments_container([], inline_comments)}
%if c.rhodecode_user.username != h.DEFAULT_USER: ## render template for inline comments ${commentblock.comment_form(form_type='inline')} %else: ${h.form('', class_='inline-form comment-form-login', method='get')}
${_('You need to be logged in to leave comments.')} ${_('Login now')}
${h.end_form()} %endif
%endif <% collapse_all = len(diffset.files) > collapse_when_files_over %> %if c.user_session_attrs["diffmode"] == 'sideside': %endif %if ruler_at_chars: %endif
%if commit: %endif

## invidual commit % if commit: ${('r%s:%s' % (commit.idx,h.short_id(commit.raw_id)))} - ${h.age_component(commit.date)} % if diffset.limited_diff: - ${_('The requested commit is too big and content was truncated.')} ${_ungettext('%(num)s file changed.', '%(num)s files changed.', diffset.changed_files) % {'num': diffset.changed_files}} ${_('Show full diff')} % elif hasattr(c, 'commit_ranges') and len(c.commit_ranges) > 1: ## compare diff, has no file-selector and we want to show stats anyway ${_ungettext('{num} file changed: {linesadd} inserted, ''{linesdel} deleted', '{num} files changed: {linesadd} inserted, {linesdel} deleted', diffset.changed_files) \ .format(num=diffset.changed_files, linesadd=diffset.lines_added, linesdel=diffset.lines_deleted)} % endif % else: ## pull requests/compare ${_('File Changes')} % endif

%if diffset.has_hidden_changes:

${_('Some changes may be hidden')}

%elif not diffset.files:

${_('No files')}

%endif
## initial value could be marked as False later on <% over_lines_changed_limit = False %> %for i, filediff in enumerate(diffset.files): <% lines_changed = filediff.patch['stats']['added'] + filediff.patch['stats']['deleted'] over_lines_changed_limit = lines_changed > lines_changed_limit %> ## anchor with support of sticky header
${diff_menu(filediff, use_comments=use_comments)} ## new/deleted/empty content case % if not filediff.hunks: ## Comment container, on "fakes" hunk that contains all data to render comments ${render_hunk_lines(filediff, c.user_session_attrs["diffmode"], filediff.hunk_ops, use_comments=use_comments, inline_comments=inline_comments)} % endif %if filediff.limited_diff: %else: %if over_lines_changed_limit: %endif %endif % for hunk in filediff.hunks: ${render_hunk_lines(filediff, c.user_session_attrs["diffmode"], hunk, use_comments=use_comments, inline_comments=inline_comments)} % endfor <% unmatched_comments = (inline_comments or {}).get(filediff.patch['filename'], {}) %> ## outdated comments that do not fit into currently displayed lines % for lineno, comments in unmatched_comments.items(): %if c.user_session_attrs["diffmode"] == 'unified': % if loop.index == 0: % endif %elif c.user_session_attrs["diffmode"] == 'sideside': % if loop.index == 0: % endif %endif % endfor
${_('The requested commit is too big and content was truncated.')} ${_('Show full diff')}
${_('This diff has been collapsed as it changes many lines, (%i lines changed)' % lines_changed)} ${_('Show them')} ${_('Hide them')}
## TODO: dan: add ajax loading of more context here ## ## @@ -${hunk.source_start},${hunk.source_length} +${hunk.target_start},${hunk.target_length} ${hunk.section_header}
${_('Unmatched inline comments below')}
${inline_comments_container(comments, inline_comments)}
${_('Unmatched inline comments below')}
${_('Unmatched comments below')}
% if lineno.startswith('o'): ${inline_comments_container(comments, inline_comments)} % endif % if lineno.startswith('n'): ${inline_comments_container(comments, inline_comments)} % endif
%endfor ## outdated comments that are made for a file that has been deleted % for filename, comments_dict in (deleted_files_comments or {}).items(): <% display_state = 'display: none' open_comments_in_file = [x for x in comments_dict['comments'] if x.outdated is False] if open_comments_in_file: display_state = '' %>
% if c.user_session_attrs["diffmode"] == 'unified': %endif %if c.user_session_attrs["diffmode"] == 'unified': %elif c.user_session_attrs["diffmode"] == 'sideside': %endif
${_('File was deleted in this version. There are still outdated/unresolved comments attached to it.')}
${inline_comments_container(comments_dict['comments'], inline_comments)}
${inline_comments_container(comments_dict['comments'], inline_comments)}
% endfor
<%def name="diff_ops(filediff)"> <% from rhodecode.lib.diffs import NEW_FILENODE, DEL_FILENODE, \ MOD_FILENODE, RENAMED_FILENODE, CHMOD_FILENODE, BIN_FILENODE, COPIED_FILENODE %> %if filediff.source_file_path and filediff.target_file_path: %if filediff.source_file_path != filediff.target_file_path: ## file was renamed, or copied %if RENAMED_FILENODE in filediff.patch['stats']['ops']: ${filediff.target_file_path}${filediff.source_file_path} <% final_path = filediff.target_file_path %> %elif COPIED_FILENODE in filediff.patch['stats']['ops']: ${filediff.target_file_path} ⬅ ${filediff.source_file_path} <% final_path = filediff.target_file_path %> %endif %else: ## file was modified ${filediff.source_file_path} <% final_path = filediff.source_file_path %> %endif %else: %if filediff.source_file_path: ## file was deleted ${filediff.source_file_path} <% final_path = filediff.source_file_path %> %else: ## file was added ${filediff.target_file_path} <% final_path = filediff.target_file_path %> %endif %endif ## anchor link ## ops pills %if filediff.limited_diff: limited diff %endif %if NEW_FILENODE in filediff.patch['stats']['ops']: created %if filediff['target_mode'].startswith('120'): symlink %else: ${nice_mode(filediff['target_mode'])} %endif %endif %if RENAMED_FILENODE in filediff.patch['stats']['ops']: renamed %endif %if COPIED_FILENODE in filediff.patch['stats']['ops']: copied %endif %if DEL_FILENODE in filediff.patch['stats']['ops']: removed %endif %if CHMOD_FILENODE in filediff.patch['stats']['ops']: ${nice_mode(filediff['source_mode'])} ➡ ${nice_mode(filediff['target_mode'])} %endif %if BIN_FILENODE in filediff.patch['stats']['ops']: binary %if MOD_FILENODE in filediff.patch['stats']['ops']: modified %endif %endif ${('+' if filediff.patch['stats']['added'] else '')}${filediff.patch['stats']['added']} ${((h.safe_int(filediff.patch['stats']['deleted']) or 0) * -1)} <%def name="nice_mode(filemode)"> ${(filemode.startswith('100') and filemode[3:] or filemode)} <%def name="diff_menu(filediff, use_comments=False)">
%if filediff.diffset.source_ref: %if filediff.operation in ['D', 'M']: ${_('Show file before')} | %else: ${_('Show file before')} | %endif %if filediff.operation in ['A', 'M']: ${_('Show file after')} | %else: ${_('Show file after')} | %endif ${_('Raw diff')} | ${_('Download diff')} % if use_comments: | % endif ## TODO: dan: refactor ignorews_url and context_url into the diff renderer same as diffmode=unified/sideside. Also use ajax to load more context (by clicking hunks) %if hasattr(c, 'ignorews_url'): ${c.ignorews_url(request, h.FID(filediff.raw_id, filediff.patch['filename']))} %endif %if hasattr(c, 'context_url'): ${c.context_url(request, h.FID(filediff.raw_id, filediff.patch['filename']))} %endif %if use_comments: ${_('Show comments')}${_('Hide comments')} %endif %endif
<%def name="inline_comments_container(comments, inline_comments)">
%for comment in comments: ${commentblock.comment_block(comment, inline=True)} %endfor % if comments and comments[-1].outdated: % else: ${_('Add another comment')} % endif
<%! def get_comments_for(diff_type, comments, filename, line_version, line_number): if hasattr(filename, 'unicode_path'): filename = filename.unicode_path if not isinstance(filename, basestring): return None line_key = '{}{}'.format(line_version, line_number) ## e.g o37, n12 if comments and filename in comments: file_comments = comments[filename] if line_key in file_comments: data = file_comments.pop(line_key) return data %> <%def name="render_hunk_lines_sideside(filediff, hunk, use_comments=False, inline_comments=None)"> %for i, line in enumerate(hunk.sideside): <% old_line_anchor, new_line_anchor = None, None if line.original.lineno: old_line_anchor = diff_line_anchor(filediff.raw_id, hunk.source_file_path, line.original.lineno, 'o') if line.modified.lineno: new_line_anchor = diff_line_anchor(filediff.raw_id, hunk.target_file_path, line.modified.lineno, 'n') %>
<% line_old_comments = None %> %if line.original.get_comment_args: <% line_old_comments = get_comments_for('side-by-side', inline_comments, *line.original.get_comment_args) %> %endif %if line_old_comments: <% has_outdated = any([x.outdated for x in line_old_comments]) %> % if has_outdated: % else: % endif %endif
%if line.original.lineno: ${line.original.lineno} %endif %if use_comments and line.original.lineno: ${render_add_comment_button()} %endif ${line.original.action} ${line.original.content or '' | n} %if use_comments and line.original.lineno and line_old_comments: ${inline_comments_container(line_old_comments, inline_comments)} %endif
%if line.modified.get_comment_args: <% line_new_comments = get_comments_for('side-by-side', inline_comments, *line.modified.get_comment_args) %> %else: <% line_new_comments = None%> %endif %if line_new_comments: <% has_outdated = any([x.outdated for x in line_new_comments]) %> % if has_outdated: % else: % endif %endif
%if line.modified.lineno: ${line.modified.lineno} %endif %if use_comments and line.modified.lineno: ${render_add_comment_button()} %endif ${line.modified.action} ${line.modified.content or '' | n} %if use_comments and line.modified.lineno and line_new_comments: ${inline_comments_container(line_new_comments, inline_comments)} %endif %endfor <%def name="render_hunk_lines_unified(filediff, hunk, use_comments=False, inline_comments=None)"> %for old_line_no, new_line_no, action, content, comments_args in hunk.unified: <% old_line_anchor, new_line_anchor = None, None if old_line_no: old_line_anchor = diff_line_anchor(filediff.raw_id, hunk.source_file_path, old_line_no, 'o') if new_line_no: new_line_anchor = diff_line_anchor(filediff.raw_id, hunk.target_file_path, new_line_no, 'n') %>
%if comments_args: <% comments = get_comments_for('unified', inline_comments, *comments_args) %> %else: <% comments = None %> %endif % if comments: <% has_outdated = any([x.outdated for x in comments]) %> % if has_outdated: % else: % endif % endif
%if old_line_anchor: ${old_line_no} %endif %if new_line_anchor: ${new_line_no} %endif %if use_comments: ${render_add_comment_button()} %endif ${action} ${content or '' | n} %if use_comments and comments: ${inline_comments_container(comments, inline_comments)} %endif %endfor <%def name="render_hunk_lines(filediff, diff_mode, hunk, use_comments, inline_comments)"> % if diff_mode == 'unified': ${render_hunk_lines_unified(filediff, hunk, use_comments=use_comments, inline_comments=inline_comments)} % elif diff_mode == 'sideside': ${render_hunk_lines_sideside(filediff, hunk, use_comments=use_comments, inline_comments=inline_comments)} % else: unknown diff mode % endif file changes <%def name="render_add_comment_button()"> <%def name="render_diffset_menu(diffset=None, range_diff_on=None)">
## auto adjustable
% if diffset: %if diffset.limited_diff: <% file_placeholder = _ungettext('%(num)s file changed', '%(num)s files changed', diffset.changed_files) % {'num': diffset.changed_files} %> %else: <% file_placeholder = _ungettext('%(num)s file changed: %(linesadd)s inserted, ''%(linesdel)s deleted', '%(num)s files changed: %(linesadd)s inserted, %(linesdel)s deleted', diffset.changed_files) % {'num': diffset.changed_files, 'linesadd': diffset.lines_added, 'linesdel': diffset.lines_deleted}%> %endif ## case on range-diff placeholder needs to be updated % if range_diff_on is True: <% file_placeholder = _('Disabled on range diff') %> % endif % endif