%namespace name="commentblock" file="/changeset/changeset_file_comment.mako"/>
<%def name="diff_line_anchor(filename, line, type)"><%
return '%s_%s_%i' % (h.safeid(filename), type, line)
%>%def>
<%def name="action_class(action)">
<%
return {
'-': 'cb-deletion',
'+': 'cb-addition',
' ': 'cb-context',
}.get(action, 'cb-empty')
%>
%def>
<%def name="op_class(op_id)">
<%
return {
DEL_FILENODE: 'deletion', # file deleted
BIN_FILENODE: 'warning' # binary diff hidden
}.get(op_id, 'addition')
%>
%def>
<%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:
%endif
<%
collapse_all = len(diffset.files) > collapse_when_files_over
%>
%if c.diffmode == 'sideside':
%endif
%if ruler_at_chars:
%endif
%def>
<%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
%if filediff.limited_diff:
limited diff
%endif
%if RENAMED_FILENODE in filediff.patch['stats']['ops']:
renamed
%endif
%if COPIED_FILENODE in filediff.patch['stats']['ops']:
copied
%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 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']:
+${filediff.patch['stats']['added']}
%endif
%if filediff.patch['stats']['deleted']:
-${filediff.patch['stats']['deleted']}
%endif
%def>
<%def name="nice_mode(filemode)">
${filemode.startswith('100') and filemode[3:] or filemode}
%def>
<%def name="diff_menu(filediff, use_comments=False)">
%def>
<%def name="inline_comments_container(comments, inline_comments)">
%def>
<%!
def get_comments_for(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)
if comments and filename in comments:
file_comments = comments[filename]
if line_key in file_comments:
return file_comments[line_key]
%>
<%def name="render_hunk_lines_sideside(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(hunk.source_file_path, line.original.lineno, 'o')
if line.modified.lineno:
new_line_anchor = diff_line_anchor(hunk.target_file_path, line.modified.lineno, 'n')
%>
<% loc = None %>
%if line.original.get_comment_args:
<% loc = get_comments_for(inline_comments, *line.original.get_comment_args) %>
%endif
%if loc:
<% has_outdated = any([x.outdated for x in loc]) %>
% 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 loc:
${inline_comments_container(loc, inline_comments)}
%endif
|
%if line.modified.get_comment_args:
<% lmc = get_comments_for(inline_comments, *line.modified.get_comment_args) %>
%else:
<% lmc = None%>
%endif
%if lmc:
<% has_outdated = any([x.outdated for x in lmc]) %>
% 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 lmc:
${inline_comments_container(lmc, inline_comments)}
%endif
|
%endfor
%def>
<%def name="render_hunk_lines_unified(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(hunk.source_file_path, old_line_no, 'o')
if new_line_no:
new_line_anchor = diff_line_anchor(hunk.target_file_path, new_line_no, 'n')
%>
%if comments_args:
<% comments = get_comments_for(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>
<%def name="render_add_comment_button()">
%def>
<%def name="render_diffset_menu()">
%def>