# HG changeset patch # User Marcin Kuzminski # Date 2018-10-17 11:49:16 # Node ID 5d8c725fde053bcf730f0f2d9b189f7ada99d586 # Parent dc7450ba72f5e1198eef19cc20569710b5cb7f4a diffs: make line anchors commit aware. This fixes duplicate anchor problem on range diffs. diff --git a/rhodecode/templates/codeblocks/diffs.mako b/rhodecode/templates/codeblocks/diffs.mako --- a/rhodecode/templates/codeblocks/diffs.mako +++ b/rhodecode/templates/codeblocks/diffs.mako @@ -1,7 +1,7 @@ <%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 name="diff_line_anchor(commit, filename, line, type)"><% +return '%s_%s_%i' % (h.md5_safe(commit+filename), type, line) %> <%def name="action_class(action)"> @@ -174,7 +174,7 @@ collapse_all = len(diffset.files) > coll ## new/deleted/empty content case % if not filediff.hunks: ## Comment container, on "fakes" hunk that contains all data to render comments - ${render_hunk_lines(c.user_session_attrs["diffmode"], filediff.hunk_ops, use_comments=use_comments, inline_comments=inline_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: @@ -214,7 +214,7 @@ collapse_all = len(diffset.files) > coll ${hunk.section_header} - ${render_hunk_lines(c.user_session_attrs["diffmode"], hunk, use_comments=use_comments, inline_comments=inline_comments)} + ${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'], {}) %> @@ -549,15 +549,15 @@ def get_comments_for(diff_type, comments return data %> -<%def name="render_hunk_lines_sideside(hunk, use_comments=False, inline_comments=None)"> - +<%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(hunk.source_file_path, line.original.lineno, 'o') + 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(hunk.target_file_path, line.modified.lineno, 'n') + new_line_anchor = diff_line_anchor(filediff.raw_id, hunk.target_file_path, line.modified.lineno, 'n') %> @@ -649,14 +649,15 @@ def get_comments_for(diff_type, comments -<%def name="render_hunk_lines_unified(hunk, use_comments=False, inline_comments=None)"> +<%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(hunk.source_file_path, old_line_no, 'o') + 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(hunk.target_file_path, new_line_no, 'n') + new_line_anchor = diff_line_anchor(filediff.raw_id, hunk.target_file_path, new_line_no, 'n') %> @@ -714,11 +715,11 @@ def get_comments_for(diff_type, comments -<%def name="render_hunk_lines(diff_mode, hunk, use_comments, inline_comments)"> +<%def name="render_hunk_lines(filediff, diff_mode, hunk, use_comments, inline_comments)"> % if diff_mode == 'unified': - ${render_hunk_lines_unified(hunk, use_comments=use_comments, inline_comments=inline_comments)} + ${render_hunk_lines_unified(filediff, hunk, use_comments=use_comments, inline_comments=inline_comments)} % elif diff_mode == 'sideside': - ${render_hunk_lines_sideside(hunk, use_comments=use_comments, inline_comments=inline_comments)} + ${render_hunk_lines_sideside(filediff, hunk, use_comments=use_comments, inline_comments=inline_comments)} % else: unknown diff mode