Show More
@@ -1,745 +1,728 b'' | |||
|
1 | 1 | # -*- coding: utf-8 -*- |
|
2 | 2 | |
|
3 | 3 | # Copyright (C) 2011-2018 RhodeCode GmbH |
|
4 | 4 | # |
|
5 | 5 | # This program is free software: you can redistribute it and/or modify |
|
6 | 6 | # it under the terms of the GNU Affero General Public License, version 3 |
|
7 | 7 | # (only), as published by the Free Software Foundation. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU Affero General Public License |
|
15 | 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
16 | 16 | # |
|
17 | 17 | # This program is dual-licensed. If you wish to learn more about the |
|
18 | 18 | # RhodeCode Enterprise Edition, including its added features, Support services, |
|
19 | 19 | # and proprietary license terms, please see https://rhodecode.com/licenses/ |
|
20 | 20 | |
|
21 | 21 | import logging |
|
22 | 22 | import difflib |
|
23 | 23 | from itertools import groupby |
|
24 | 24 | |
|
25 | 25 | from pygments import lex |
|
26 | 26 | from pygments.formatters.html import _get_ttype_class as pygment_token_class |
|
27 | 27 | from pygments.lexers.special import TextLexer, Token |
|
28 | 28 | |
|
29 | 29 | from rhodecode.lib.helpers import ( |
|
30 | 30 | get_lexer_for_filenode, html_escape, get_custom_lexer) |
|
31 | 31 | from rhodecode.lib.utils2 import AttributeDict, StrictAttributeDict |
|
32 | 32 | from rhodecode.lib.vcs.nodes import FileNode |
|
33 | 33 | from rhodecode.lib.vcs.exceptions import VCSError, NodeDoesNotExistError |
|
34 | 34 | from rhodecode.lib.diff_match_patch import diff_match_patch |
|
35 | 35 | from rhodecode.lib.diffs import LimitedDiffContainer |
|
36 | 36 | from pygments.lexers import get_lexer_by_name |
|
37 | 37 | |
|
38 | 38 | plain_text_lexer = get_lexer_by_name( |
|
39 | 39 | 'text', stripall=False, stripnl=False, ensurenl=False) |
|
40 | 40 | |
|
41 | 41 | |
|
42 | 42 | log = logging.getLogger(__name__) |
|
43 | 43 | |
|
44 | 44 | |
|
45 | 45 | def filenode_as_lines_tokens(filenode, lexer=None): |
|
46 | 46 | org_lexer = lexer |
|
47 | 47 | lexer = lexer or get_lexer_for_filenode(filenode) |
|
48 | 48 | log.debug('Generating file node pygment tokens for %s, %s, org_lexer:%s', |
|
49 | 49 | lexer, filenode, org_lexer) |
|
50 | 50 | tokens = tokenize_string(filenode.content, lexer) |
|
51 | 51 | lines = split_token_stream(tokens) |
|
52 | 52 | rv = list(lines) |
|
53 | 53 | return rv |
|
54 | 54 | |
|
55 | 55 | |
|
56 | 56 | def tokenize_string(content, lexer): |
|
57 | 57 | """ |
|
58 | 58 | Use pygments to tokenize some content based on a lexer |
|
59 | 59 | ensuring all original new lines and whitespace is preserved |
|
60 | 60 | """ |
|
61 | 61 | |
|
62 | 62 | lexer.stripall = False |
|
63 | 63 | lexer.stripnl = False |
|
64 | 64 | lexer.ensurenl = False |
|
65 | 65 | |
|
66 | 66 | if isinstance(lexer, TextLexer): |
|
67 | 67 | lexed = [(Token.Text, content)] |
|
68 | 68 | else: |
|
69 | 69 | lexed = lex(content, lexer) |
|
70 | 70 | |
|
71 | 71 | for token_type, token_text in lexed: |
|
72 | 72 | yield pygment_token_class(token_type), token_text |
|
73 | 73 | |
|
74 | 74 | |
|
75 | 75 | def split_token_stream(tokens): |
|
76 | 76 | """ |
|
77 | 77 | Take a list of (TokenType, text) tuples and split them by a string |
|
78 | 78 | |
|
79 | 79 | split_token_stream([(TEXT, 'some\ntext'), (TEXT, 'more\n')]) |
|
80 | 80 | [(TEXT, 'some'), (TEXT, 'text'), |
|
81 | 81 | (TEXT, 'more'), (TEXT, 'text')] |
|
82 | 82 | """ |
|
83 | 83 | |
|
84 | 84 | buffer = [] |
|
85 | 85 | for token_class, token_text in tokens: |
|
86 | 86 | parts = token_text.split('\n') |
|
87 | 87 | for part in parts[:-1]: |
|
88 | 88 | buffer.append((token_class, part)) |
|
89 | 89 | yield buffer |
|
90 | 90 | buffer = [] |
|
91 | 91 | |
|
92 | 92 | buffer.append((token_class, parts[-1])) |
|
93 | 93 | |
|
94 | 94 | if buffer: |
|
95 | 95 | yield buffer |
|
96 | 96 | |
|
97 | 97 | |
|
98 | 98 | def filenode_as_annotated_lines_tokens(filenode): |
|
99 | 99 | """ |
|
100 | 100 | Take a file node and return a list of annotations => lines, if no annotation |
|
101 | 101 | is found, it will be None. |
|
102 | 102 | |
|
103 | 103 | eg: |
|
104 | 104 | |
|
105 | 105 | [ |
|
106 | 106 | (annotation1, [ |
|
107 | 107 | (1, line1_tokens_list), |
|
108 | 108 | (2, line2_tokens_list), |
|
109 | 109 | ]), |
|
110 | 110 | (annotation2, [ |
|
111 | 111 | (3, line1_tokens_list), |
|
112 | 112 | ]), |
|
113 | 113 | (None, [ |
|
114 | 114 | (4, line1_tokens_list), |
|
115 | 115 | ]), |
|
116 | 116 | (annotation1, [ |
|
117 | 117 | (5, line1_tokens_list), |
|
118 | 118 | (6, line2_tokens_list), |
|
119 | 119 | ]) |
|
120 | 120 | ] |
|
121 | 121 | """ |
|
122 | 122 | |
|
123 | 123 | commit_cache = {} # cache commit_getter lookups |
|
124 | 124 | |
|
125 | 125 | def _get_annotation(commit_id, commit_getter): |
|
126 | 126 | if commit_id not in commit_cache: |
|
127 | 127 | commit_cache[commit_id] = commit_getter() |
|
128 | 128 | return commit_cache[commit_id] |
|
129 | 129 | |
|
130 | 130 | annotation_lookup = { |
|
131 | 131 | line_no: _get_annotation(commit_id, commit_getter) |
|
132 | 132 | for line_no, commit_id, commit_getter, line_content |
|
133 | 133 | in filenode.annotate |
|
134 | 134 | } |
|
135 | 135 | |
|
136 | 136 | annotations_lines = ((annotation_lookup.get(line_no), line_no, tokens) |
|
137 | 137 | for line_no, tokens |
|
138 | 138 | in enumerate(filenode_as_lines_tokens(filenode), 1)) |
|
139 | 139 | |
|
140 | 140 | grouped_annotations_lines = groupby(annotations_lines, lambda x: x[0]) |
|
141 | 141 | |
|
142 | 142 | for annotation, group in grouped_annotations_lines: |
|
143 | 143 | yield ( |
|
144 | 144 | annotation, [(line_no, tokens) |
|
145 | 145 | for (_, line_no, tokens) in group] |
|
146 | 146 | ) |
|
147 | 147 | |
|
148 | 148 | |
|
149 | 149 | def render_tokenstream(tokenstream): |
|
150 | 150 | result = [] |
|
151 | 151 | for token_class, token_ops_texts in rollup_tokenstream(tokenstream): |
|
152 | 152 | |
|
153 | 153 | if token_class: |
|
154 | 154 | result.append(u'<span class="%s">' % token_class) |
|
155 | 155 | else: |
|
156 | 156 | result.append(u'<span>') |
|
157 | 157 | |
|
158 | 158 | for op_tag, token_text in token_ops_texts: |
|
159 | 159 | |
|
160 | 160 | if op_tag: |
|
161 | 161 | result.append(u'<%s>' % op_tag) |
|
162 | 162 | |
|
163 | 163 | escaped_text = html_escape(token_text) |
|
164 | 164 | |
|
165 | 165 | # TODO: dan: investigate showing hidden characters like space/nl/tab |
|
166 | 166 | # escaped_text = escaped_text.replace(' ', '<sp> </sp>') |
|
167 | 167 | # escaped_text = escaped_text.replace('\n', '<nl>\n</nl>') |
|
168 | 168 | # escaped_text = escaped_text.replace('\t', '<tab>\t</tab>') |
|
169 | 169 | |
|
170 | 170 | result.append(escaped_text) |
|
171 | 171 | |
|
172 | 172 | if op_tag: |
|
173 | 173 | result.append(u'</%s>' % op_tag) |
|
174 | 174 | |
|
175 | 175 | result.append(u'</span>') |
|
176 | 176 | |
|
177 | 177 | html = ''.join(result) |
|
178 | 178 | return html |
|
179 | 179 | |
|
180 | 180 | |
|
181 | 181 | def rollup_tokenstream(tokenstream): |
|
182 | 182 | """ |
|
183 | 183 | Group a token stream of the format: |
|
184 | 184 | |
|
185 | 185 | ('class', 'op', 'text') |
|
186 | 186 | or |
|
187 | 187 | ('class', 'text') |
|
188 | 188 | |
|
189 | 189 | into |
|
190 | 190 | |
|
191 | 191 | [('class1', |
|
192 | 192 | [('op1', 'text'), |
|
193 | 193 | ('op2', 'text')]), |
|
194 | 194 | ('class2', |
|
195 | 195 | [('op3', 'text')])] |
|
196 | 196 | |
|
197 | 197 | This is used to get the minimal tags necessary when |
|
198 | 198 | rendering to html eg for a token stream ie. |
|
199 | 199 | |
|
200 | 200 | <span class="A"><ins>he</ins>llo</span> |
|
201 | 201 | vs |
|
202 | 202 | <span class="A"><ins>he</ins></span><span class="A">llo</span> |
|
203 | 203 | |
|
204 | 204 | If a 2 tuple is passed in, the output op will be an empty string. |
|
205 | 205 | |
|
206 | 206 | eg: |
|
207 | 207 | |
|
208 | 208 | >>> rollup_tokenstream([('classA', '', 'h'), |
|
209 | 209 | ('classA', 'del', 'ell'), |
|
210 | 210 | ('classA', '', 'o'), |
|
211 | 211 | ('classB', '', ' '), |
|
212 | 212 | ('classA', '', 'the'), |
|
213 | 213 | ('classA', '', 're'), |
|
214 | 214 | ]) |
|
215 | 215 | |
|
216 | 216 | [('classA', [('', 'h'), ('del', 'ell'), ('', 'o')], |
|
217 | 217 | ('classB', [('', ' ')], |
|
218 | 218 | ('classA', [('', 'there')]] |
|
219 | 219 | |
|
220 | 220 | """ |
|
221 | 221 | if tokenstream and len(tokenstream[0]) == 2: |
|
222 | 222 | tokenstream = ((t[0], '', t[1]) for t in tokenstream) |
|
223 | 223 | |
|
224 | 224 | result = [] |
|
225 | 225 | for token_class, op_list in groupby(tokenstream, lambda t: t[0]): |
|
226 | 226 | ops = [] |
|
227 | 227 | for token_op, token_text_list in groupby(op_list, lambda o: o[1]): |
|
228 | 228 | text_buffer = [] |
|
229 | 229 | for t_class, t_op, t_text in token_text_list: |
|
230 | 230 | text_buffer.append(t_text) |
|
231 | 231 | ops.append((token_op, ''.join(text_buffer))) |
|
232 | 232 | result.append((token_class, ops)) |
|
233 | 233 | return result |
|
234 | 234 | |
|
235 | 235 | |
|
236 | 236 | def tokens_diff(old_tokens, new_tokens, use_diff_match_patch=True): |
|
237 | 237 | """ |
|
238 | 238 | Converts a list of (token_class, token_text) tuples to a list of |
|
239 | 239 | (token_class, token_op, token_text) tuples where token_op is one of |
|
240 | 240 | ('ins', 'del', '') |
|
241 | 241 | |
|
242 | 242 | :param old_tokens: list of (token_class, token_text) tuples of old line |
|
243 | 243 | :param new_tokens: list of (token_class, token_text) tuples of new line |
|
244 | 244 | :param use_diff_match_patch: boolean, will use google's diff match patch |
|
245 | 245 | library which has options to 'smooth' out the character by character |
|
246 | 246 | differences making nicer ins/del blocks |
|
247 | 247 | """ |
|
248 | 248 | |
|
249 | 249 | old_tokens_result = [] |
|
250 | 250 | new_tokens_result = [] |
|
251 | 251 | |
|
252 | 252 | similarity = difflib.SequenceMatcher(None, |
|
253 | 253 | ''.join(token_text for token_class, token_text in old_tokens), |
|
254 | 254 | ''.join(token_text for token_class, token_text in new_tokens) |
|
255 | 255 | ).ratio() |
|
256 | 256 | |
|
257 | 257 | if similarity < 0.6: # return, the blocks are too different |
|
258 | 258 | for token_class, token_text in old_tokens: |
|
259 | 259 | old_tokens_result.append((token_class, '', token_text)) |
|
260 | 260 | for token_class, token_text in new_tokens: |
|
261 | 261 | new_tokens_result.append((token_class, '', token_text)) |
|
262 | 262 | return old_tokens_result, new_tokens_result, similarity |
|
263 | 263 | |
|
264 | 264 | token_sequence_matcher = difflib.SequenceMatcher(None, |
|
265 | 265 | [x[1] for x in old_tokens], |
|
266 | 266 | [x[1] for x in new_tokens]) |
|
267 | 267 | |
|
268 | 268 | for tag, o1, o2, n1, n2 in token_sequence_matcher.get_opcodes(): |
|
269 | 269 | # check the differences by token block types first to give a more |
|
270 | 270 | # nicer "block" level replacement vs character diffs |
|
271 | 271 | |
|
272 | 272 | if tag == 'equal': |
|
273 | 273 | for token_class, token_text in old_tokens[o1:o2]: |
|
274 | 274 | old_tokens_result.append((token_class, '', token_text)) |
|
275 | 275 | for token_class, token_text in new_tokens[n1:n2]: |
|
276 | 276 | new_tokens_result.append((token_class, '', token_text)) |
|
277 | 277 | elif tag == 'delete': |
|
278 | 278 | for token_class, token_text in old_tokens[o1:o2]: |
|
279 | 279 | old_tokens_result.append((token_class, 'del', token_text)) |
|
280 | 280 | elif tag == 'insert': |
|
281 | 281 | for token_class, token_text in new_tokens[n1:n2]: |
|
282 | 282 | new_tokens_result.append((token_class, 'ins', token_text)) |
|
283 | 283 | elif tag == 'replace': |
|
284 | 284 | # if same type token blocks must be replaced, do a diff on the |
|
285 | 285 | # characters in the token blocks to show individual changes |
|
286 | 286 | |
|
287 | 287 | old_char_tokens = [] |
|
288 | 288 | new_char_tokens = [] |
|
289 | 289 | for token_class, token_text in old_tokens[o1:o2]: |
|
290 | 290 | for char in token_text: |
|
291 | 291 | old_char_tokens.append((token_class, char)) |
|
292 | 292 | |
|
293 | 293 | for token_class, token_text in new_tokens[n1:n2]: |
|
294 | 294 | for char in token_text: |
|
295 | 295 | new_char_tokens.append((token_class, char)) |
|
296 | 296 | |
|
297 | 297 | old_string = ''.join([token_text for |
|
298 | 298 | token_class, token_text in old_char_tokens]) |
|
299 | 299 | new_string = ''.join([token_text for |
|
300 | 300 | token_class, token_text in new_char_tokens]) |
|
301 | 301 | |
|
302 | 302 | char_sequence = difflib.SequenceMatcher( |
|
303 | 303 | None, old_string, new_string) |
|
304 | 304 | copcodes = char_sequence.get_opcodes() |
|
305 | 305 | obuffer, nbuffer = [], [] |
|
306 | 306 | |
|
307 | 307 | if use_diff_match_patch: |
|
308 | 308 | dmp = diff_match_patch() |
|
309 | 309 | dmp.Diff_EditCost = 11 # TODO: dan: extract this to a setting |
|
310 | 310 | reps = dmp.diff_main(old_string, new_string) |
|
311 | 311 | dmp.diff_cleanupEfficiency(reps) |
|
312 | 312 | |
|
313 | 313 | a, b = 0, 0 |
|
314 | 314 | for op, rep in reps: |
|
315 | 315 | l = len(rep) |
|
316 | 316 | if op == 0: |
|
317 | 317 | for i, c in enumerate(rep): |
|
318 | 318 | obuffer.append((old_char_tokens[a+i][0], '', c)) |
|
319 | 319 | nbuffer.append((new_char_tokens[b+i][0], '', c)) |
|
320 | 320 | a += l |
|
321 | 321 | b += l |
|
322 | 322 | elif op == -1: |
|
323 | 323 | for i, c in enumerate(rep): |
|
324 | 324 | obuffer.append((old_char_tokens[a+i][0], 'del', c)) |
|
325 | 325 | a += l |
|
326 | 326 | elif op == 1: |
|
327 | 327 | for i, c in enumerate(rep): |
|
328 | 328 | nbuffer.append((new_char_tokens[b+i][0], 'ins', c)) |
|
329 | 329 | b += l |
|
330 | 330 | else: |
|
331 | 331 | for ctag, co1, co2, cn1, cn2 in copcodes: |
|
332 | 332 | if ctag == 'equal': |
|
333 | 333 | for token_class, token_text in old_char_tokens[co1:co2]: |
|
334 | 334 | obuffer.append((token_class, '', token_text)) |
|
335 | 335 | for token_class, token_text in new_char_tokens[cn1:cn2]: |
|
336 | 336 | nbuffer.append((token_class, '', token_text)) |
|
337 | 337 | elif ctag == 'delete': |
|
338 | 338 | for token_class, token_text in old_char_tokens[co1:co2]: |
|
339 | 339 | obuffer.append((token_class, 'del', token_text)) |
|
340 | 340 | elif ctag == 'insert': |
|
341 | 341 | for token_class, token_text in new_char_tokens[cn1:cn2]: |
|
342 | 342 | nbuffer.append((token_class, 'ins', token_text)) |
|
343 | 343 | elif ctag == 'replace': |
|
344 | 344 | for token_class, token_text in old_char_tokens[co1:co2]: |
|
345 | 345 | obuffer.append((token_class, 'del', token_text)) |
|
346 | 346 | for token_class, token_text in new_char_tokens[cn1:cn2]: |
|
347 | 347 | nbuffer.append((token_class, 'ins', token_text)) |
|
348 | 348 | |
|
349 | 349 | old_tokens_result.extend(obuffer) |
|
350 | 350 | new_tokens_result.extend(nbuffer) |
|
351 | 351 | |
|
352 | 352 | return old_tokens_result, new_tokens_result, similarity |
|
353 | 353 | |
|
354 | 354 | |
|
355 | 355 | def diffset_node_getter(commit): |
|
356 | 356 | def get_node(fname): |
|
357 | 357 | try: |
|
358 | 358 | return commit.get_node(fname) |
|
359 | 359 | except NodeDoesNotExistError: |
|
360 | 360 | return None |
|
361 | 361 | |
|
362 | 362 | return get_node |
|
363 | 363 | |
|
364 | 364 | |
|
365 | 365 | class DiffSet(object): |
|
366 | 366 | """ |
|
367 | 367 | An object for parsing the diff result from diffs.DiffProcessor and |
|
368 | 368 | adding highlighting, side by side/unified renderings and line diffs |
|
369 | 369 | """ |
|
370 | 370 | |
|
371 | HL_REAL = 'REAL' # highlights using original file, slow | |
|
372 | HL_FAST = 'FAST' # highlights using just the line, fast but not correct | |
|
373 | # in the case of multiline code | |
|
374 | HL_NONE = 'NONE' # no highlighting, fastest | |
|
371 | HL_REAL = 'REAL' # highlights using original file, slow | |
|
372 | HL_FAST = 'FAST' # highlights using just the line, fast but not correct | |
|
373 | # in the case of multiline code | |
|
374 | HL_NONE = 'NONE' # no highlighting, fastest | |
|
375 | 375 | |
|
376 | 376 | def __init__(self, highlight_mode=HL_REAL, repo_name=None, |
|
377 | 377 | source_repo_name=None, |
|
378 | 378 | source_node_getter=lambda filename: None, |
|
379 | 379 | target_node_getter=lambda filename: None, |
|
380 | 380 | source_nodes=None, target_nodes=None, |
|
381 |
|
|
|
382 | # use fast highlighting | |
|
383 | comments=None, | |
|
381 | # files over this size will use fast highlighting | |
|
382 | max_file_size_limit=150 * 1024, | |
|
384 | 383 | ): |
|
385 | 384 | |
|
386 | 385 | self.highlight_mode = highlight_mode |
|
387 | 386 | self.highlighted_filenodes = {} |
|
388 | 387 | self.source_node_getter = source_node_getter |
|
389 | 388 | self.target_node_getter = target_node_getter |
|
390 | 389 | self.source_nodes = source_nodes or {} |
|
391 | 390 | self.target_nodes = target_nodes or {} |
|
392 | 391 | self.repo_name = repo_name |
|
393 | 392 | self.source_repo_name = source_repo_name or repo_name |
|
394 | self.comments = comments or {} | |
|
395 | self.comments_store = self.comments.copy() | |
|
396 | 393 | self.max_file_size_limit = max_file_size_limit |
|
397 | 394 | |
|
398 | 395 | def render_patchset(self, patchset, source_ref=None, target_ref=None): |
|
399 | 396 | diffset = AttributeDict(dict( |
|
400 | 397 | lines_added=0, |
|
401 | 398 | lines_deleted=0, |
|
402 | 399 | changed_files=0, |
|
403 | 400 | files=[], |
|
404 | 401 | file_stats={}, |
|
405 | 402 | limited_diff=isinstance(patchset, LimitedDiffContainer), |
|
406 | 403 | repo_name=self.repo_name, |
|
407 | 404 | source_repo_name=self.source_repo_name, |
|
408 | 405 | source_ref=source_ref, |
|
409 | 406 | target_ref=target_ref, |
|
410 | 407 | )) |
|
411 | 408 | for patch in patchset: |
|
412 | 409 | diffset.file_stats[patch['filename']] = patch['stats'] |
|
413 | 410 | filediff = self.render_patch(patch) |
|
414 | 411 | filediff.diffset = StrictAttributeDict(dict( |
|
415 | 412 | source_ref=diffset.source_ref, |
|
416 | 413 | target_ref=diffset.target_ref, |
|
417 | 414 | repo_name=diffset.repo_name, |
|
418 | 415 | source_repo_name=diffset.source_repo_name, |
|
419 | 416 | )) |
|
420 | 417 | diffset.files.append(filediff) |
|
421 | 418 | diffset.changed_files += 1 |
|
422 | 419 | if not patch['stats']['binary']: |
|
423 | 420 | diffset.lines_added += patch['stats']['added'] |
|
424 | 421 | diffset.lines_deleted += patch['stats']['deleted'] |
|
425 | 422 | |
|
426 | 423 | return diffset |
|
427 | 424 | |
|
428 | 425 | _lexer_cache = {} |
|
429 | 426 | |
|
430 | 427 | def _get_lexer_for_filename(self, filename, filenode=None): |
|
431 | 428 | # cached because we might need to call it twice for source/target |
|
432 | 429 | if filename not in self._lexer_cache: |
|
433 | 430 | if filenode: |
|
434 | 431 | lexer = filenode.lexer |
|
435 | 432 | extension = filenode.extension |
|
436 | 433 | else: |
|
437 | 434 | lexer = FileNode.get_lexer(filename=filename) |
|
438 | 435 | extension = filename.split('.')[-1] |
|
439 | 436 | |
|
440 | 437 | lexer = get_custom_lexer(extension) or lexer |
|
441 | 438 | self._lexer_cache[filename] = lexer |
|
442 | 439 | return self._lexer_cache[filename] |
|
443 | 440 | |
|
444 | 441 | def render_patch(self, patch): |
|
445 | 442 | log.debug('rendering diff for %r', patch['filename']) |
|
446 | 443 | |
|
447 | 444 | source_filename = patch['original_filename'] |
|
448 | 445 | target_filename = patch['filename'] |
|
449 | 446 | |
|
450 | 447 | source_lexer = plain_text_lexer |
|
451 | 448 | target_lexer = plain_text_lexer |
|
452 | 449 | |
|
453 | 450 | if not patch['stats']['binary']: |
|
454 | 451 | if self.highlight_mode == self.HL_REAL: |
|
455 | 452 | if (source_filename and patch['operation'] in ('D', 'M') |
|
456 | 453 | and source_filename not in self.source_nodes): |
|
457 | 454 | self.source_nodes[source_filename] = ( |
|
458 | 455 | self.source_node_getter(source_filename)) |
|
459 | 456 | |
|
460 | 457 | if (target_filename and patch['operation'] in ('A', 'M') |
|
461 | 458 | and target_filename not in self.target_nodes): |
|
462 | 459 | self.target_nodes[target_filename] = ( |
|
463 | 460 | self.target_node_getter(target_filename)) |
|
464 | 461 | |
|
465 | 462 | elif self.highlight_mode == self.HL_FAST: |
|
466 | 463 | source_lexer = self._get_lexer_for_filename(source_filename) |
|
467 | 464 | target_lexer = self._get_lexer_for_filename(target_filename) |
|
468 | 465 | |
|
469 | 466 | source_file = self.source_nodes.get(source_filename, source_filename) |
|
470 | 467 | target_file = self.target_nodes.get(target_filename, target_filename) |
|
471 | 468 | |
|
472 | 469 | source_filenode, target_filenode = None, None |
|
473 | 470 | |
|
474 | 471 | # TODO: dan: FileNode.lexer works on the content of the file - which |
|
475 | 472 | # can be slow - issue #4289 explains a lexer clean up - which once |
|
476 | 473 | # done can allow caching a lexer for a filenode to avoid the file lookup |
|
477 | 474 | if isinstance(source_file, FileNode): |
|
478 | 475 | source_filenode = source_file |
|
479 | 476 | #source_lexer = source_file.lexer |
|
480 | 477 | source_lexer = self._get_lexer_for_filename(source_filename) |
|
481 | 478 | source_file.lexer = source_lexer |
|
482 | 479 | |
|
483 | 480 | if isinstance(target_file, FileNode): |
|
484 | 481 | target_filenode = target_file |
|
485 | 482 | #target_lexer = target_file.lexer |
|
486 | 483 | target_lexer = self._get_lexer_for_filename(target_filename) |
|
487 | 484 | target_file.lexer = target_lexer |
|
488 | 485 | |
|
489 | 486 | source_file_path, target_file_path = None, None |
|
490 | 487 | |
|
491 | 488 | if source_filename != '/dev/null': |
|
492 | 489 | source_file_path = source_filename |
|
493 | 490 | if target_filename != '/dev/null': |
|
494 | 491 | target_file_path = target_filename |
|
495 | 492 | |
|
496 | 493 | source_file_type = source_lexer.name |
|
497 | 494 | target_file_type = target_lexer.name |
|
498 | 495 | |
|
499 | 496 | filediff = AttributeDict({ |
|
500 | 497 | 'source_file_path': source_file_path, |
|
501 | 498 | 'target_file_path': target_file_path, |
|
502 | 499 | 'source_filenode': source_filenode, |
|
503 | 500 | 'target_filenode': target_filenode, |
|
504 | 501 | 'source_file_type': target_file_type, |
|
505 | 502 | 'target_file_type': source_file_type, |
|
506 | 503 | 'patch': {'filename': patch['filename'], 'stats': patch['stats']}, |
|
507 | 504 | 'operation': patch['operation'], |
|
508 | 505 | 'source_mode': patch['stats']['old_mode'], |
|
509 | 506 | 'target_mode': patch['stats']['new_mode'], |
|
510 | 507 | 'limited_diff': isinstance(patch, LimitedDiffContainer), |
|
511 | 508 | 'hunks': [], |
|
512 | 509 | 'diffset': self, |
|
513 | 510 | }) |
|
514 | 511 | |
|
515 | 512 | for hunk in patch['chunks'][1:]: |
|
516 | 513 | hunkbit = self.parse_hunk(hunk, source_file, target_file) |
|
517 | 514 | hunkbit.source_file_path = source_file_path |
|
518 | 515 | hunkbit.target_file_path = target_file_path |
|
519 | 516 | filediff.hunks.append(hunkbit) |
|
520 | 517 | |
|
521 | left_comments = {} | |
|
522 | if source_file_path in self.comments_store: | |
|
523 | for lineno, comments in self.comments_store[source_file_path].items(): | |
|
524 | left_comments[lineno] = comments | |
|
525 | ||
|
526 | if target_file_path in self.comments_store: | |
|
527 | for lineno, comments in self.comments_store[target_file_path].items(): | |
|
528 | left_comments[lineno] = comments | |
|
529 | ||
|
530 | # left comments are one that we couldn't place in diff lines. | |
|
531 | # could be outdated, or the diff changed and this line is no | |
|
532 | # longer available | |
|
533 | filediff.left_comments = left_comments | |
|
534 | ||
|
535 | 518 | return filediff |
|
536 | 519 | |
|
537 | 520 | def parse_hunk(self, hunk, source_file, target_file): |
|
538 | 521 | result = AttributeDict(dict( |
|
539 | 522 | source_start=hunk['source_start'], |
|
540 | 523 | source_length=hunk['source_length'], |
|
541 | 524 | target_start=hunk['target_start'], |
|
542 | 525 | target_length=hunk['target_length'], |
|
543 | 526 | section_header=hunk['section_header'], |
|
544 | 527 | lines=[], |
|
545 | 528 | )) |
|
546 | 529 | before, after = [], [] |
|
547 | 530 | |
|
548 | 531 | for line in hunk['lines']: |
|
549 | 532 | |
|
550 | 533 | if line['action'] == 'unmod': |
|
551 | 534 | result.lines.extend( |
|
552 | 535 | self.parse_lines(before, after, source_file, target_file)) |
|
553 | 536 | after.append(line) |
|
554 | 537 | before.append(line) |
|
555 | 538 | elif line['action'] == 'add': |
|
556 | 539 | after.append(line) |
|
557 | 540 | elif line['action'] == 'del': |
|
558 | 541 | before.append(line) |
|
559 | 542 | elif line['action'] == 'old-no-nl': |
|
560 | 543 | before.append(line) |
|
561 | 544 | elif line['action'] == 'new-no-nl': |
|
562 | 545 | after.append(line) |
|
563 | 546 | |
|
564 | 547 | result.lines.extend( |
|
565 | 548 | self.parse_lines(before, after, source_file, target_file)) |
|
566 | 549 | result.unified = list(self.as_unified(result.lines)) |
|
567 | 550 | result.sideside = result.lines |
|
568 | 551 | |
|
569 | 552 | return result |
|
570 | 553 | |
|
571 | 554 | def parse_lines(self, before_lines, after_lines, source_file, target_file): |
|
572 | 555 | # TODO: dan: investigate doing the diff comparison and fast highlighting |
|
573 | 556 | # on the entire before and after buffered block lines rather than by |
|
574 | 557 | # line, this means we can get better 'fast' highlighting if the context |
|
575 | 558 | # allows it - eg. |
|
576 | 559 | # line 4: """ |
|
577 | 560 | # line 5: this gets highlighted as a string |
|
578 | 561 | # line 6: """ |
|
579 | 562 | |
|
580 | 563 | lines = [] |
|
581 | 564 | |
|
582 | 565 | before_newline = AttributeDict() |
|
583 | 566 | after_newline = AttributeDict() |
|
584 | 567 | if before_lines and before_lines[-1]['action'] == 'old-no-nl': |
|
585 | 568 | before_newline_line = before_lines.pop(-1) |
|
586 | 569 | before_newline.content = '\n {}'.format( |
|
587 | 570 | render_tokenstream( |
|
588 | 571 | [(x[0], '', x[1]) |
|
589 | 572 | for x in [('nonl', before_newline_line['line'])]])) |
|
590 | 573 | |
|
591 | 574 | if after_lines and after_lines[-1]['action'] == 'new-no-nl': |
|
592 | 575 | after_newline_line = after_lines.pop(-1) |
|
593 | 576 | after_newline.content = '\n {}'.format( |
|
594 | 577 | render_tokenstream( |
|
595 | 578 | [(x[0], '', x[1]) |
|
596 | 579 | for x in [('nonl', after_newline_line['line'])]])) |
|
597 | 580 | |
|
598 | 581 | while before_lines or after_lines: |
|
599 | 582 | before, after = None, None |
|
600 | 583 | before_tokens, after_tokens = None, None |
|
601 | 584 | |
|
602 | 585 | if before_lines: |
|
603 | 586 | before = before_lines.pop(0) |
|
604 | 587 | if after_lines: |
|
605 | 588 | after = after_lines.pop(0) |
|
606 | 589 | |
|
607 | 590 | original = AttributeDict() |
|
608 | 591 | modified = AttributeDict() |
|
609 | 592 | |
|
610 | 593 | if before: |
|
611 | 594 | if before['action'] == 'old-no-nl': |
|
612 | 595 | before_tokens = [('nonl', before['line'])] |
|
613 | 596 | else: |
|
614 | 597 | before_tokens = self.get_line_tokens( |
|
615 | 598 | line_text=before['line'], |
|
616 | 599 | line_number=before['old_lineno'], |
|
617 | 600 | file=source_file) |
|
618 | 601 | original.lineno = before['old_lineno'] |
|
619 | 602 | original.content = before['line'] |
|
620 | 603 | original.action = self.action_to_op(before['action']) |
|
621 | 604 | |
|
622 | 605 | original.get_comment_args = ( |
|
623 | 606 | source_file, 'o', before['old_lineno']) |
|
624 | 607 | |
|
625 | 608 | if after: |
|
626 | 609 | if after['action'] == 'new-no-nl': |
|
627 | 610 | after_tokens = [('nonl', after['line'])] |
|
628 | 611 | else: |
|
629 | 612 | after_tokens = self.get_line_tokens( |
|
630 | 613 | line_text=after['line'], line_number=after['new_lineno'], |
|
631 | 614 | file=target_file) |
|
632 | 615 | modified.lineno = after['new_lineno'] |
|
633 | 616 | modified.content = after['line'] |
|
634 | 617 | modified.action = self.action_to_op(after['action']) |
|
635 | 618 | |
|
636 | 619 | modified.get_comment_args = ( |
|
637 | 620 | target_file, 'n', after['new_lineno']) |
|
638 | 621 | |
|
639 | 622 | # diff the lines |
|
640 | 623 | if before_tokens and after_tokens: |
|
641 | 624 | o_tokens, m_tokens, similarity = tokens_diff( |
|
642 | 625 | before_tokens, after_tokens) |
|
643 | 626 | original.content = render_tokenstream(o_tokens) |
|
644 | 627 | modified.content = render_tokenstream(m_tokens) |
|
645 | 628 | elif before_tokens: |
|
646 | 629 | original.content = render_tokenstream( |
|
647 | 630 | [(x[0], '', x[1]) for x in before_tokens]) |
|
648 | 631 | elif after_tokens: |
|
649 | 632 | modified.content = render_tokenstream( |
|
650 | 633 | [(x[0], '', x[1]) for x in after_tokens]) |
|
651 | 634 | |
|
652 | 635 | if not before_lines and before_newline: |
|
653 | 636 | original.content += before_newline.content |
|
654 | 637 | before_newline = None |
|
655 | 638 | if not after_lines and after_newline: |
|
656 | 639 | modified.content += after_newline.content |
|
657 | 640 | after_newline = None |
|
658 | 641 | |
|
659 | 642 | lines.append(AttributeDict({ |
|
660 | 643 | 'original': original, |
|
661 | 644 | 'modified': modified, |
|
662 | 645 | })) |
|
663 | 646 | |
|
664 | 647 | return lines |
|
665 | 648 | |
|
666 | 649 | def get_line_tokens(self, line_text, line_number, file=None): |
|
667 | 650 | filenode = None |
|
668 | 651 | filename = None |
|
669 | 652 | |
|
670 | 653 | if isinstance(file, basestring): |
|
671 | 654 | filename = file |
|
672 | 655 | elif isinstance(file, FileNode): |
|
673 | 656 | filenode = file |
|
674 | 657 | filename = file.unicode_path |
|
675 | 658 | |
|
676 | 659 | if self.highlight_mode == self.HL_REAL and filenode: |
|
677 | 660 | lexer = self._get_lexer_for_filename(filename) |
|
678 | 661 | file_size_allowed = file.size < self.max_file_size_limit |
|
679 | 662 | if line_number and file_size_allowed: |
|
680 | 663 | return self.get_tokenized_filenode_line( |
|
681 | 664 | file, line_number, lexer) |
|
682 | 665 | |
|
683 | 666 | if self.highlight_mode in (self.HL_REAL, self.HL_FAST) and filename: |
|
684 | 667 | lexer = self._get_lexer_for_filename(filename) |
|
685 | 668 | return list(tokenize_string(line_text, lexer)) |
|
686 | 669 | |
|
687 | 670 | return list(tokenize_string(line_text, plain_text_lexer)) |
|
688 | 671 | |
|
689 | 672 | def get_tokenized_filenode_line(self, filenode, line_number, lexer=None): |
|
690 | 673 | |
|
691 | 674 | if filenode not in self.highlighted_filenodes: |
|
692 | 675 | tokenized_lines = filenode_as_lines_tokens(filenode, lexer) |
|
693 | 676 | self.highlighted_filenodes[filenode] = tokenized_lines |
|
694 | 677 | return self.highlighted_filenodes[filenode][line_number - 1] |
|
695 | 678 | |
|
696 | 679 | def action_to_op(self, action): |
|
697 | 680 | return { |
|
698 | 681 | 'add': '+', |
|
699 | 682 | 'del': '-', |
|
700 | 683 | 'unmod': ' ', |
|
701 | 684 | 'old-no-nl': ' ', |
|
702 | 685 | 'new-no-nl': ' ', |
|
703 | 686 | }.get(action, action) |
|
704 | 687 | |
|
705 | 688 | def as_unified(self, lines): |
|
706 | 689 | """ |
|
707 | 690 | Return a generator that yields the lines of a diff in unified order |
|
708 | 691 | """ |
|
709 | 692 | def generator(): |
|
710 | 693 | buf = [] |
|
711 | 694 | for line in lines: |
|
712 | 695 | |
|
713 | 696 | if buf and not line.original or line.original.action == ' ': |
|
714 | 697 | for b in buf: |
|
715 | 698 | yield b |
|
716 | 699 | buf = [] |
|
717 | 700 | |
|
718 | 701 | if line.original: |
|
719 | 702 | if line.original.action == ' ': |
|
720 | 703 | yield (line.original.lineno, line.modified.lineno, |
|
721 | 704 | line.original.action, line.original.content, |
|
722 | 705 | line.original.get_comment_args) |
|
723 | 706 | continue |
|
724 | 707 | |
|
725 | 708 | if line.original.action == '-': |
|
726 | 709 | yield (line.original.lineno, None, |
|
727 | 710 | line.original.action, line.original.content, |
|
728 | 711 | line.original.get_comment_args) |
|
729 | 712 | |
|
730 | 713 | if line.modified.action == '+': |
|
731 | 714 | buf.append(( |
|
732 | 715 | None, line.modified.lineno, |
|
733 | 716 | line.modified.action, line.modified.content, |
|
734 | 717 | line.modified.get_comment_args)) |
|
735 | 718 | continue |
|
736 | 719 | |
|
737 | 720 | if line.modified: |
|
738 | 721 | yield (None, line.modified.lineno, |
|
739 | 722 | line.modified.action, line.modified.content, |
|
740 | 723 | line.modified.get_comment_args) |
|
741 | 724 | |
|
742 | 725 | for b in buf: |
|
743 | 726 | yield b |
|
744 | 727 | |
|
745 | 728 | return generator() |
@@ -1,407 +1,407 b'' | |||
|
1 | 1 | ## -*- coding: utf-8 -*- |
|
2 | 2 | ## usage: |
|
3 | 3 | ## <%namespace name="comment" file="/changeset/changeset_file_comment.mako"/> |
|
4 | 4 | ## ${comment.comment_block(comment)} |
|
5 | 5 | ## |
|
6 | 6 | <%namespace name="base" file="/base/base.mako"/> |
|
7 | 7 | |
|
8 | 8 | <%def name="comment_block(comment, inline=False)"> |
|
9 | 9 | <% pr_index_ver = comment.get_index_version(getattr(c, 'versions', [])) %> |
|
10 | 10 | <% latest_ver = len(getattr(c, 'versions', [])) %> |
|
11 | 11 | % if inline: |
|
12 | 12 | <% outdated_at_ver = comment.outdated_at_version(getattr(c, 'at_version_num', None)) %> |
|
13 | 13 | % else: |
|
14 | 14 | <% outdated_at_ver = comment.older_than_version(getattr(c, 'at_version_num', None)) %> |
|
15 | 15 | % endif |
|
16 | 16 | |
|
17 | 17 | |
|
18 | 18 | <div class="comment |
|
19 | 19 | ${'comment-inline' if inline else 'comment-general'} |
|
20 | 20 | ${'comment-outdated' if outdated_at_ver else 'comment-current'}" |
|
21 | 21 | id="comment-${comment.comment_id}" |
|
22 | 22 | line="${comment.line_no}" |
|
23 | 23 | data-comment-id="${comment.comment_id}" |
|
24 | 24 | data-comment-type="${comment.comment_type}" |
|
25 | 25 | data-comment-line-no="${comment.line_no}" |
|
26 | 26 | data-comment-inline=${h.json.dumps(inline)} |
|
27 | 27 | style="${'display: none;' if outdated_at_ver else ''}"> |
|
28 | 28 | |
|
29 | 29 | <div class="meta"> |
|
30 | 30 | <div class="comment-type-label"> |
|
31 | <div class="comment-label ${comment.comment_type or 'note'}" id="comment-label-${comment.comment_id}"> | |
|
31 | <div class="comment-label ${comment.comment_type or 'note'}" id="comment-label-${comment.comment_id}" title="line: ${comment.line_no}"> | |
|
32 | 32 | % if comment.comment_type == 'todo': |
|
33 | 33 | % if comment.resolved: |
|
34 | 34 | <div class="resolved tooltip" title="${_('Resolved by comment #{}').format(comment.resolved.comment_id)}"> |
|
35 | 35 | <a href="#comment-${comment.resolved.comment_id}">${comment.comment_type}</a> |
|
36 | 36 | </div> |
|
37 | 37 | % else: |
|
38 | 38 | <div class="resolved tooltip" style="display: none"> |
|
39 | 39 | <span>${comment.comment_type}</span> |
|
40 | 40 | </div> |
|
41 | 41 | <div class="resolve tooltip" onclick="return Rhodecode.comments.createResolutionComment(${comment.comment_id});" title="${_('Click to resolve this comment')}"> |
|
42 | 42 | ${comment.comment_type} |
|
43 | 43 | </div> |
|
44 | 44 | % endif |
|
45 | 45 | % else: |
|
46 | 46 | % if comment.resolved_comment: |
|
47 | 47 | fix |
|
48 | 48 | % else: |
|
49 | 49 | ${comment.comment_type or 'note'} |
|
50 | 50 | % endif |
|
51 | 51 | % endif |
|
52 | 52 | </div> |
|
53 | 53 | </div> |
|
54 | 54 | |
|
55 | 55 | <div class="author ${'author-inline' if inline else 'author-general'}"> |
|
56 | 56 | ${base.gravatar_with_user(comment.author.email, 16)} |
|
57 | 57 | </div> |
|
58 | 58 | <div class="date"> |
|
59 | 59 | ${h.age_component(comment.modified_at, time_is_local=True)} |
|
60 | 60 | </div> |
|
61 | 61 | % if inline: |
|
62 | 62 | <span></span> |
|
63 | 63 | % else: |
|
64 | 64 | <div class="status-change"> |
|
65 | 65 | % if comment.pull_request: |
|
66 | 66 | <a href="${h.route_path('pullrequest_show',repo_name=comment.pull_request.target_repo.repo_name,pull_request_id=comment.pull_request.pull_request_id)}"> |
|
67 | 67 | % if comment.status_change: |
|
68 | 68 | ${_('pull request #%s') % comment.pull_request.pull_request_id}: |
|
69 | 69 | % else: |
|
70 | 70 | ${_('pull request #%s') % comment.pull_request.pull_request_id} |
|
71 | 71 | % endif |
|
72 | 72 | </a> |
|
73 | 73 | % else: |
|
74 | 74 | % if comment.status_change: |
|
75 | 75 | ${_('Status change on commit')}: |
|
76 | 76 | % endif |
|
77 | 77 | % endif |
|
78 | 78 | </div> |
|
79 | 79 | % endif |
|
80 | 80 | |
|
81 | 81 | % if comment.status_change: |
|
82 | 82 | <div class="${'flag_status %s' % comment.status_change[0].status}"></div> |
|
83 | 83 | <div title="${_('Commit status')}" class="changeset-status-lbl"> |
|
84 | 84 | ${comment.status_change[0].status_lbl} |
|
85 | 85 | </div> |
|
86 | 86 | % endif |
|
87 | 87 | |
|
88 | 88 | % if comment.resolved_comment: |
|
89 | 89 | <a class="has-spacer-before" href="#comment-${comment.resolved_comment.comment_id}" onclick="Rhodecode.comments.scrollToComment($('#comment-${comment.resolved_comment.comment_id}'), 0, ${h.json.dumps(comment.resolved_comment.outdated)})"> |
|
90 | 90 | ${_('resolves comment #{}').format(comment.resolved_comment.comment_id)} |
|
91 | 91 | </a> |
|
92 | 92 | % endif |
|
93 | 93 | |
|
94 | 94 | <a class="permalink" href="#comment-${comment.comment_id}"> ¶</a> |
|
95 | 95 | |
|
96 | 96 | <div class="comment-links-block"> |
|
97 | 97 | % if comment.pull_request and comment.pull_request.author.user_id == comment.author.user_id: |
|
98 | 98 | <span class="tag authortag tooltip" title="${_('Pull request author')}"> |
|
99 | 99 | ${_('author')} |
|
100 | 100 | </span> |
|
101 | 101 | | |
|
102 | 102 | % endif |
|
103 | 103 | % if inline: |
|
104 | 104 | <div class="pr-version-inline"> |
|
105 | 105 | <a href="${request.current_route_path(_query=dict(version=comment.pull_request_version_id), _anchor='comment-{}'.format(comment.comment_id))}"> |
|
106 | 106 | % if outdated_at_ver: |
|
107 | 107 | <code class="pr-version-num" title="${_('Outdated comment from pull request version v{0}, latest v{1}').format(pr_index_ver, latest_ver)}"> |
|
108 | 108 | outdated ${'v{}'.format(pr_index_ver)} | |
|
109 | 109 | </code> |
|
110 | 110 | % elif pr_index_ver: |
|
111 | 111 | <code class="pr-version-num" title="${_('Comment from pull request version v{0}, latest v{1}').format(pr_index_ver, latest_ver)}"> |
|
112 | 112 | ${'v{}'.format(pr_index_ver)} | |
|
113 | 113 | </code> |
|
114 | 114 | % endif |
|
115 | 115 | </a> |
|
116 | 116 | </div> |
|
117 | 117 | % else: |
|
118 | 118 | % if comment.pull_request_version_id and pr_index_ver: |
|
119 | 119 | | |
|
120 | 120 | <div class="pr-version"> |
|
121 | 121 | % if comment.outdated: |
|
122 | 122 | <a href="?version=${comment.pull_request_version_id}#comment-${comment.comment_id}"> |
|
123 | 123 | ${_('Outdated comment from pull request version v{0}, latest v{1}').format(pr_index_ver, latest_ver)} |
|
124 | 124 | </a> |
|
125 | 125 | % else: |
|
126 | 126 | <div title="${_('Comment from pull request version v{0}, latest v{1}').format(pr_index_ver, latest_ver)}"> |
|
127 | 127 | <a href="${h.route_path('pullrequest_show',repo_name=comment.pull_request.target_repo.repo_name,pull_request_id=comment.pull_request.pull_request_id, version=comment.pull_request_version_id)}"> |
|
128 | 128 | <code class="pr-version-num"> |
|
129 | 129 | ${'v{}'.format(pr_index_ver)} |
|
130 | 130 | </code> |
|
131 | 131 | </a> |
|
132 | 132 | </div> |
|
133 | 133 | % endif |
|
134 | 134 | </div> |
|
135 | 135 | % endif |
|
136 | 136 | % endif |
|
137 | 137 | |
|
138 | 138 | ## show delete comment if it's not a PR (regular comments) or it's PR that is not closed |
|
139 | 139 | ## only super-admin, repo admin OR comment owner can delete, also hide delete if currently viewed comment is outdated |
|
140 | 140 | %if not outdated_at_ver and (not comment.pull_request or (comment.pull_request and not comment.pull_request.is_closed())): |
|
141 | 141 | ## permissions to delete |
|
142 | 142 | %if h.HasPermissionAny('hg.admin')() or h.HasRepoPermissionAny('repository.admin')(c.repo_name) or comment.author.user_id == c.rhodecode_user.user_id: |
|
143 | 143 | ## TODO: dan: add edit comment here |
|
144 | 144 | <a onclick="return Rhodecode.comments.deleteComment(this);" class="delete-comment"> ${_('Delete')}</a> |
|
145 | 145 | %else: |
|
146 | 146 | <button class="btn-link" disabled="disabled"> ${_('Delete')}</button> |
|
147 | 147 | %endif |
|
148 | 148 | %else: |
|
149 | 149 | <button class="btn-link" disabled="disabled"> ${_('Delete')}</button> |
|
150 | 150 | %endif |
|
151 | 151 | |
|
152 | 152 | % if outdated_at_ver: |
|
153 | 153 | | <a onclick="return Rhodecode.comments.prevOutdatedComment(this);" class="prev-comment"> ${_('Prev')}</a> |
|
154 | 154 | | <a onclick="return Rhodecode.comments.nextOutdatedComment(this);" class="next-comment"> ${_('Next')}</a> |
|
155 | 155 | % else: |
|
156 | 156 | | <a onclick="return Rhodecode.comments.prevComment(this);" class="prev-comment"> ${_('Prev')}</a> |
|
157 | 157 | | <a onclick="return Rhodecode.comments.nextComment(this);" class="next-comment"> ${_('Next')}</a> |
|
158 | 158 | % endif |
|
159 | 159 | |
|
160 | 160 | </div> |
|
161 | 161 | </div> |
|
162 | 162 | <div class="text"> |
|
163 | 163 | ${h.render(comment.text, renderer=comment.renderer, mentions=True)} |
|
164 | 164 | </div> |
|
165 | 165 | |
|
166 | 166 | </div> |
|
167 | 167 | </%def> |
|
168 | 168 | |
|
169 | 169 | ## generate main comments |
|
170 | 170 | <%def name="generate_comments(comments, include_pull_request=False, is_pull_request=False)"> |
|
171 | 171 | <div class="general-comments" id="comments"> |
|
172 | 172 | %for comment in comments: |
|
173 | 173 | <div id="comment-tr-${comment.comment_id}"> |
|
174 | 174 | ## only render comments that are not from pull request, or from |
|
175 | 175 | ## pull request and a status change |
|
176 | 176 | %if not comment.pull_request or (comment.pull_request and comment.status_change) or include_pull_request: |
|
177 | 177 | ${comment_block(comment)} |
|
178 | 178 | %endif |
|
179 | 179 | </div> |
|
180 | 180 | %endfor |
|
181 | 181 | ## to anchor ajax comments |
|
182 | 182 | <div id="injected_page_comments"></div> |
|
183 | 183 | </div> |
|
184 | 184 | </%def> |
|
185 | 185 | |
|
186 | 186 | |
|
187 | 187 | <%def name="comments(post_url, cur_status, is_pull_request=False, is_compare=False, change_status=True, form_extras=None)"> |
|
188 | 188 | |
|
189 | 189 | <div class="comments"> |
|
190 | 190 | <% |
|
191 | 191 | if is_pull_request: |
|
192 | 192 | placeholder = _('Leave a comment on this Pull Request.') |
|
193 | 193 | elif is_compare: |
|
194 | 194 | placeholder = _('Leave a comment on {} commits in this range.').format(len(form_extras)) |
|
195 | 195 | else: |
|
196 | 196 | placeholder = _('Leave a comment on this Commit.') |
|
197 | 197 | %> |
|
198 | 198 | |
|
199 | 199 | % if c.rhodecode_user.username != h.DEFAULT_USER: |
|
200 | 200 | <div class="js-template" id="cb-comment-general-form-template"> |
|
201 | 201 | ## template generated for injection |
|
202 | 202 | ${comment_form(form_type='general', review_statuses=c.commit_statuses, form_extras=form_extras)} |
|
203 | 203 | </div> |
|
204 | 204 | |
|
205 | 205 | <div id="cb-comment-general-form-placeholder" class="comment-form ac"> |
|
206 | 206 | ## inject form here |
|
207 | 207 | </div> |
|
208 | 208 | <script type="text/javascript"> |
|
209 | 209 | var lineNo = 'general'; |
|
210 | 210 | var resolvesCommentId = null; |
|
211 | 211 | var generalCommentForm = Rhodecode.comments.createGeneralComment( |
|
212 | 212 | lineNo, "${placeholder}", resolvesCommentId); |
|
213 | 213 | |
|
214 | 214 | // set custom success callback on rangeCommit |
|
215 | 215 | % if is_compare: |
|
216 | 216 | generalCommentForm.setHandleFormSubmit(function(o) { |
|
217 | 217 | var self = generalCommentForm; |
|
218 | 218 | |
|
219 | 219 | var text = self.cm.getValue(); |
|
220 | 220 | var status = self.getCommentStatus(); |
|
221 | 221 | var commentType = self.getCommentType(); |
|
222 | 222 | |
|
223 | 223 | if (text === "" && !status) { |
|
224 | 224 | return; |
|
225 | 225 | } |
|
226 | 226 | |
|
227 | 227 | // we can pick which commits we want to make the comment by |
|
228 | 228 | // selecting them via click on preview pane, this will alter the hidden inputs |
|
229 | 229 | var cherryPicked = $('#changeset_compare_view_content .compare_select.hl').length > 0; |
|
230 | 230 | |
|
231 | 231 | var commitIds = []; |
|
232 | 232 | $('#changeset_compare_view_content .compare_select').each(function(el) { |
|
233 | 233 | var commitId = this.id.replace('row-', ''); |
|
234 | 234 | if ($(this).hasClass('hl') || !cherryPicked) { |
|
235 | 235 | $("input[data-commit-id='{0}']".format(commitId)).val(commitId); |
|
236 | 236 | commitIds.push(commitId); |
|
237 | 237 | } else { |
|
238 | 238 | $("input[data-commit-id='{0}']".format(commitId)).val('') |
|
239 | 239 | } |
|
240 | 240 | }); |
|
241 | 241 | |
|
242 | 242 | self.setActionButtonsDisabled(true); |
|
243 | 243 | self.cm.setOption("readOnly", true); |
|
244 | 244 | var postData = { |
|
245 | 245 | 'text': text, |
|
246 | 246 | 'changeset_status': status, |
|
247 | 247 | 'comment_type': commentType, |
|
248 | 248 | 'commit_ids': commitIds, |
|
249 | 249 | 'csrf_token': CSRF_TOKEN |
|
250 | 250 | }; |
|
251 | 251 | |
|
252 | 252 | var submitSuccessCallback = function(o) { |
|
253 | 253 | location.reload(true); |
|
254 | 254 | }; |
|
255 | 255 | var submitFailCallback = function(){ |
|
256 | 256 | self.resetCommentFormState(text) |
|
257 | 257 | }; |
|
258 | 258 | self.submitAjaxPOST( |
|
259 | 259 | self.submitUrl, postData, submitSuccessCallback, submitFailCallback); |
|
260 | 260 | }); |
|
261 | 261 | % endif |
|
262 | 262 | |
|
263 | 263 | |
|
264 | 264 | </script> |
|
265 | 265 | % else: |
|
266 | 266 | ## form state when not logged in |
|
267 | 267 | <div class="comment-form ac"> |
|
268 | 268 | |
|
269 | 269 | <div class="comment-area"> |
|
270 | 270 | <div class="comment-area-header"> |
|
271 | 271 | <ul class="nav-links clearfix"> |
|
272 | 272 | <li class="active"> |
|
273 | 273 | <a class="disabled" href="#edit-btn" disabled="disabled" onclick="return false">${_('Write')}</a> |
|
274 | 274 | </li> |
|
275 | 275 | <li class=""> |
|
276 | 276 | <a class="disabled" href="#preview-btn" disabled="disabled" onclick="return false">${_('Preview')}</a> |
|
277 | 277 | </li> |
|
278 | 278 | </ul> |
|
279 | 279 | </div> |
|
280 | 280 | |
|
281 | 281 | <div class="comment-area-write" style="display: block;"> |
|
282 | 282 | <div id="edit-container"> |
|
283 | 283 | <div style="padding: 40px 0"> |
|
284 | 284 | ${_('You need to be logged in to leave comments.')} |
|
285 | 285 | <a href="${h.route_path('login', _query={'came_from': h.current_route_path(request)})}">${_('Login now')}</a> |
|
286 | 286 | </div> |
|
287 | 287 | </div> |
|
288 | 288 | <div id="preview-container" class="clearfix" style="display: none;"> |
|
289 | 289 | <div id="preview-box" class="preview-box"></div> |
|
290 | 290 | </div> |
|
291 | 291 | </div> |
|
292 | 292 | |
|
293 | 293 | <div class="comment-area-footer"> |
|
294 | 294 | <div class="toolbar"> |
|
295 | 295 | <div class="toolbar-text"> |
|
296 | 296 | </div> |
|
297 | 297 | </div> |
|
298 | 298 | </div> |
|
299 | 299 | </div> |
|
300 | 300 | |
|
301 | 301 | <div class="comment-footer"> |
|
302 | 302 | </div> |
|
303 | 303 | |
|
304 | 304 | </div> |
|
305 | 305 | % endif |
|
306 | 306 | |
|
307 | 307 | <script type="text/javascript"> |
|
308 | 308 | bindToggleButtons(); |
|
309 | 309 | </script> |
|
310 | 310 | </div> |
|
311 | 311 | </%def> |
|
312 | 312 | |
|
313 | 313 | |
|
314 | 314 | <%def name="comment_form(form_type, form_id='', lineno_id='{1}', review_statuses=None, form_extras=None)"> |
|
315 | 315 | ## comment injected based on assumption that user is logged in |
|
316 | 316 | |
|
317 | 317 | <form ${'id="{}"'.format(form_id) if form_id else '' |n} action="#" method="GET"> |
|
318 | 318 | |
|
319 | 319 | <div class="comment-area"> |
|
320 | 320 | <div class="comment-area-header"> |
|
321 | 321 | <ul class="nav-links clearfix"> |
|
322 | 322 | <li class="active"> |
|
323 | 323 | <a href="#edit-btn" tabindex="-1" id="edit-btn_${lineno_id}">${_('Write')}</a> |
|
324 | 324 | </li> |
|
325 | 325 | <li class=""> |
|
326 | 326 | <a href="#preview-btn" tabindex="-1" id="preview-btn_${lineno_id}">${_('Preview')}</a> |
|
327 | 327 | </li> |
|
328 | 328 | <li class="pull-right"> |
|
329 | 329 | <select class="comment-type" id="comment_type_${lineno_id}" name="comment_type"> |
|
330 | 330 | % for val in c.visual.comment_types: |
|
331 | 331 | <option value="${val}">${val.upper()}</option> |
|
332 | 332 | % endfor |
|
333 | 333 | </select> |
|
334 | 334 | </li> |
|
335 | 335 | </ul> |
|
336 | 336 | </div> |
|
337 | 337 | |
|
338 | 338 | <div class="comment-area-write" style="display: block;"> |
|
339 | 339 | <div id="edit-container_${lineno_id}"> |
|
340 | 340 | <textarea id="text_${lineno_id}" name="text" class="comment-block-ta ac-input"></textarea> |
|
341 | 341 | </div> |
|
342 | 342 | <div id="preview-container_${lineno_id}" class="clearfix" style="display: none;"> |
|
343 | 343 | <div id="preview-box_${lineno_id}" class="preview-box"></div> |
|
344 | 344 | </div> |
|
345 | 345 | </div> |
|
346 | 346 | |
|
347 | 347 | <div class="comment-area-footer"> |
|
348 | 348 | <div class="toolbar"> |
|
349 | 349 | <div class="toolbar-text"> |
|
350 | 350 | ${(_('Comments parsed using %s syntax with %s, and %s actions support.') % ( |
|
351 | 351 | ('<a href="%s">%s</a>' % (h.route_url('%s_help' % c.visual.default_renderer), c.visual.default_renderer.upper())), |
|
352 | 352 | ('<span class="tooltip" title="%s">@mention</span>' % _('Use @username inside this text to send notification to this RhodeCode user')), |
|
353 | 353 | ('<span class="tooltip" title="%s">`/`</span>' % _('Start typing with / for certain actions to be triggered via text box.')) |
|
354 | 354 | ) |
|
355 | 355 | )|n} |
|
356 | 356 | </div> |
|
357 | 357 | </div> |
|
358 | 358 | </div> |
|
359 | 359 | </div> |
|
360 | 360 | |
|
361 | 361 | <div class="comment-footer"> |
|
362 | 362 | |
|
363 | 363 | % if review_statuses: |
|
364 | 364 | <div class="status_box"> |
|
365 | 365 | <select id="change_status_${lineno_id}" name="changeset_status"> |
|
366 | 366 | <option></option> ## Placeholder |
|
367 | 367 | % for status, lbl in review_statuses: |
|
368 | 368 | <option value="${status}" data-status="${status}">${lbl}</option> |
|
369 | 369 | %if is_pull_request and change_status and status in ('approved', 'rejected'): |
|
370 | 370 | <option value="${status}_closed" data-status="${status}">${lbl} & ${_('Closed')}</option> |
|
371 | 371 | %endif |
|
372 | 372 | % endfor |
|
373 | 373 | </select> |
|
374 | 374 | </div> |
|
375 | 375 | % endif |
|
376 | 376 | |
|
377 | 377 | ## inject extra inputs into the form |
|
378 | 378 | % if form_extras and isinstance(form_extras, (list, tuple)): |
|
379 | 379 | <div id="comment_form_extras"> |
|
380 | 380 | % for form_ex_el in form_extras: |
|
381 | 381 | ${form_ex_el|n} |
|
382 | 382 | % endfor |
|
383 | 383 | </div> |
|
384 | 384 | % endif |
|
385 | 385 | |
|
386 | 386 | <div class="action-buttons"> |
|
387 | 387 | ## inline for has a file, and line-number together with cancel hide button. |
|
388 | 388 | % if form_type == 'inline': |
|
389 | 389 | <input type="hidden" name="f_path" value="{0}"> |
|
390 | 390 | <input type="hidden" name="line" value="${lineno_id}"> |
|
391 | 391 | <button type="button" class="cb-comment-cancel" onclick="return Rhodecode.comments.cancelComment(this);"> |
|
392 | 392 | ${_('Cancel')} |
|
393 | 393 | </button> |
|
394 | 394 | % endif |
|
395 | 395 | |
|
396 | 396 | % if form_type != 'inline': |
|
397 | 397 | <div class="action-buttons-extra"></div> |
|
398 | 398 | % endif |
|
399 | 399 | |
|
400 | 400 | ${h.submit('save', _('Comment'), class_='btn btn-success comment-button-input')} |
|
401 | 401 | |
|
402 | 402 | </div> |
|
403 | 403 | </div> |
|
404 | 404 | |
|
405 | 405 | </form> |
|
406 | 406 | |
|
407 | 407 | </%def> No newline at end of file |
@@ -1,735 +1,760 b'' | |||
|
1 | 1 | <%namespace name="commentblock" file="/changeset/changeset_file_comment.mako"/> |
|
2 | 2 | |
|
3 | 3 | <%def name="diff_line_anchor(filename, line, type)"><% |
|
4 | 4 | return '%s_%s_%i' % (h.safeid(filename), type, line) |
|
5 | 5 | %></%def> |
|
6 | 6 | |
|
7 | 7 | <%def name="action_class(action)"> |
|
8 | 8 | <% |
|
9 | 9 | return { |
|
10 | 10 | '-': 'cb-deletion', |
|
11 | 11 | '+': 'cb-addition', |
|
12 | 12 | ' ': 'cb-context', |
|
13 | 13 | }.get(action, 'cb-empty') |
|
14 | 14 | %> |
|
15 | 15 | </%def> |
|
16 | 16 | |
|
17 | 17 | <%def name="op_class(op_id)"> |
|
18 | 18 | <% |
|
19 | 19 | return { |
|
20 | 20 | DEL_FILENODE: 'deletion', # file deleted |
|
21 | 21 | BIN_FILENODE: 'warning' # binary diff hidden |
|
22 | 22 | }.get(op_id, 'addition') |
|
23 | 23 | %> |
|
24 | 24 | </%def> |
|
25 | 25 | |
|
26 | 26 | |
|
27 | 27 | |
|
28 | 28 | <%def name="render_diffset(diffset, commit=None, |
|
29 | 29 | |
|
30 | 30 | # collapse all file diff entries when there are more than this amount of files in the diff |
|
31 | 31 | collapse_when_files_over=20, |
|
32 | 32 | |
|
33 | 33 | # collapse lines in the diff when more than this amount of lines changed in the file diff |
|
34 | 34 | lines_changed_limit=500, |
|
35 | 35 | |
|
36 | 36 | # add a ruler at to the output |
|
37 | 37 | ruler_at_chars=0, |
|
38 | 38 | |
|
39 | 39 | # show inline comments |
|
40 | 40 | use_comments=False, |
|
41 | 41 | |
|
42 | 42 | # disable new comments |
|
43 | 43 | disable_new_comments=False, |
|
44 | 44 | |
|
45 | 45 | # special file-comments that were deleted in previous versions |
|
46 | 46 | # it's used for showing outdated comments for deleted files in a PR |
|
47 | 47 | deleted_files_comments=None, |
|
48 | 48 | |
|
49 | 49 | # for cache purpose |
|
50 | 50 | inline_comments=None |
|
51 | 51 | |
|
52 | 52 | )"> |
|
53 | 53 | %if use_comments: |
|
54 | 54 | <div id="cb-comments-inline-container-template" class="js-template"> |
|
55 | 55 | ${inline_comments_container([], inline_comments)} |
|
56 | 56 | </div> |
|
57 | 57 | <div class="js-template" id="cb-comment-inline-form-template"> |
|
58 | 58 | <div class="comment-inline-form ac"> |
|
59 | 59 | |
|
60 | 60 | %if c.rhodecode_user.username != h.DEFAULT_USER: |
|
61 | 61 | ## render template for inline comments |
|
62 | 62 | ${commentblock.comment_form(form_type='inline')} |
|
63 | 63 | %else: |
|
64 | 64 | ${h.form('', class_='inline-form comment-form-login', method='get')} |
|
65 | 65 | <div class="pull-left"> |
|
66 | 66 | <div class="comment-help pull-right"> |
|
67 | 67 | ${_('You need to be logged in to leave comments.')} <a href="${h.route_path('login', _query={'came_from': h.current_route_path(request)})}">${_('Login now')}</a> |
|
68 | 68 | </div> |
|
69 | 69 | </div> |
|
70 | 70 | <div class="comment-button pull-right"> |
|
71 | 71 | <button type="button" class="cb-comment-cancel" onclick="return Rhodecode.comments.cancelComment(this);"> |
|
72 | 72 | ${_('Cancel')} |
|
73 | 73 | </button> |
|
74 | 74 | </div> |
|
75 | 75 | <div class="clearfix"></div> |
|
76 | 76 | ${h.end_form()} |
|
77 | 77 | %endif |
|
78 | 78 | </div> |
|
79 | 79 | </div> |
|
80 | 80 | |
|
81 | 81 | %endif |
|
82 | 82 | <% |
|
83 | 83 | collapse_all = len(diffset.files) > collapse_when_files_over |
|
84 | 84 | %> |
|
85 | 85 | |
|
86 | 86 | %if c.diffmode == 'sideside': |
|
87 | 87 | <style> |
|
88 | 88 | .wrapper { |
|
89 | 89 | max-width: 1600px !important; |
|
90 | 90 | } |
|
91 | 91 | </style> |
|
92 | 92 | %endif |
|
93 | 93 | |
|
94 | 94 | %if ruler_at_chars: |
|
95 | 95 | <style> |
|
96 | 96 | .diff table.cb .cb-content:after { |
|
97 | 97 | content: ""; |
|
98 | 98 | border-left: 1px solid blue; |
|
99 | 99 | position: absolute; |
|
100 | 100 | top: 0; |
|
101 | 101 | height: 18px; |
|
102 | 102 | opacity: .2; |
|
103 | 103 | z-index: 10; |
|
104 | 104 | //## +5 to account for diff action (+/-) |
|
105 | 105 | left: ${ruler_at_chars + 5}ch; |
|
106 | 106 | </style> |
|
107 | 107 | %endif |
|
108 | 108 | |
|
109 | 109 | <div class="diffset ${disable_new_comments and 'diffset-comments-disabled'}"> |
|
110 | 110 | <div class="diffset-heading ${diffset.limited_diff and 'diffset-heading-warning' or ''}"> |
|
111 | 111 | %if commit: |
|
112 | 112 | <div class="pull-right"> |
|
113 | 113 | <a class="btn tooltip" title="${h.tooltip(_('Browse Files at revision {}').format(commit.raw_id))}" href="${h.route_path('repo_files',repo_name=diffset.repo_name, commit_id=commit.raw_id, f_path='')}"> |
|
114 | 114 | ${_('Browse Files')} |
|
115 | 115 | </a> |
|
116 | 116 | </div> |
|
117 | 117 | %endif |
|
118 | 118 | <h2 class="clearinner"> |
|
119 | 119 | %if commit: |
|
120 | 120 | <a class="tooltip revision" title="${h.tooltip(commit.message)}" href="${h.route_path('repo_commit',repo_name=c.repo_name,commit_id=commit.raw_id)}">${'r%s:%s' % (commit.revision,h.short_id(commit.raw_id))}</a> - |
|
121 | 121 | ${h.age_component(commit.date)} - |
|
122 | 122 | %endif |
|
123 | 123 | |
|
124 | 124 | %if diffset.limited_diff: |
|
125 | 125 | ${_('The requested commit is too big and content was truncated.')} |
|
126 | 126 | |
|
127 | 127 | ${_ungettext('%(num)s file changed.', '%(num)s files changed.', diffset.changed_files) % {'num': diffset.changed_files}} |
|
128 | 128 | <a href="${h.current_route_path(request, fulldiff=1)}" onclick="return confirm('${_("Showing a big diff might take some time and resources, continue?")}')">${_('Show full diff')}</a> |
|
129 | 129 | %else: |
|
130 | 130 | ${_ungettext('%(num)s file changed: %(linesadd)s inserted, ''%(linesdel)s deleted', |
|
131 | 131 | '%(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}} |
|
132 | 132 | %endif |
|
133 | 133 | |
|
134 | 134 | </h2> |
|
135 | 135 | </div> |
|
136 | 136 | |
|
137 | 137 | %if diffset.has_hidden_changes: |
|
138 | 138 | <p class="empty_data">${_('Some changes may be hidden')}</p> |
|
139 | 139 | %elif not diffset.files: |
|
140 | 140 | <p class="empty_data">${_('No files')}</p> |
|
141 | 141 | %endif |
|
142 | 142 | |
|
143 | 143 | <div class="filediffs"> |
|
144 | 144 | ## initial value could be marked as False later on |
|
145 | 145 | <% over_lines_changed_limit = False %> |
|
146 | 146 | %for i, filediff in enumerate(diffset.files): |
|
147 | 147 | |
|
148 | 148 | <% |
|
149 | 149 | lines_changed = filediff.patch['stats']['added'] + filediff.patch['stats']['deleted'] |
|
150 | 150 | over_lines_changed_limit = lines_changed > lines_changed_limit |
|
151 | 151 | %> |
|
152 | 152 | <input ${collapse_all and 'checked' or ''} class="filediff-collapse-state" id="filediff-collapse-${id(filediff)}" type="checkbox"> |
|
153 | 153 | <div |
|
154 | 154 | class="filediff" |
|
155 | 155 | data-f-path="${filediff.patch['filename']}" |
|
156 | 156 | id="a_${h.FID('', filediff.patch['filename'])}"> |
|
157 | 157 | <label for="filediff-collapse-${id(filediff)}" class="filediff-heading"> |
|
158 | 158 | <div class="filediff-collapse-indicator"></div> |
|
159 | 159 | ${diff_ops(filediff)} |
|
160 | 160 | </label> |
|
161 | 161 | ${diff_menu(filediff, use_comments=use_comments)} |
|
162 | 162 | <table class="cb cb-diff-${c.diffmode} code-highlight ${over_lines_changed_limit and 'cb-collapsed' or ''}"> |
|
163 | 163 | %if not filediff.hunks: |
|
164 | 164 | %for op_id, op_text in filediff.patch['stats']['ops'].items(): |
|
165 | 165 | <tr> |
|
166 | 166 | <td class="cb-text cb-${op_class(op_id)}" ${c.diffmode == 'unified' and 'colspan=4' or 'colspan=6'}> |
|
167 | 167 | %if op_id == DEL_FILENODE: |
|
168 | 168 | ${_('File was deleted')} |
|
169 | 169 | %elif op_id == BIN_FILENODE: |
|
170 | 170 | ${_('Binary file hidden')} |
|
171 | 171 | %else: |
|
172 | 172 | ${op_text} |
|
173 | 173 | %endif |
|
174 | 174 | </td> |
|
175 | 175 | </tr> |
|
176 | 176 | %endfor |
|
177 | 177 | %endif |
|
178 | 178 | %if filediff.limited_diff: |
|
179 | 179 | <tr class="cb-warning cb-collapser"> |
|
180 | 180 | <td class="cb-text" ${c.diffmode == 'unified' and 'colspan=4' or 'colspan=6'}> |
|
181 | 181 | ${_('The requested commit is too big and content was truncated.')} <a href="${h.current_route_path(request, fulldiff=1)}" onclick="return confirm('${_("Showing a big diff might take some time and resources, continue?")}')">${_('Show full diff')}</a> |
|
182 | 182 | </td> |
|
183 | 183 | </tr> |
|
184 | 184 | %else: |
|
185 | 185 | %if over_lines_changed_limit: |
|
186 | 186 | <tr class="cb-warning cb-collapser"> |
|
187 | 187 | <td class="cb-text" ${c.diffmode == 'unified' and 'colspan=4' or 'colspan=6'}> |
|
188 | 188 | ${_('This diff has been collapsed as it changes many lines, (%i lines changed)' % lines_changed)} |
|
189 | 189 | <a href="#" class="cb-expand" |
|
190 | 190 | onclick="$(this).closest('table').removeClass('cb-collapsed'); return false;">${_('Show them')} |
|
191 | 191 | </a> |
|
192 | 192 | <a href="#" class="cb-collapse" |
|
193 | 193 | onclick="$(this).closest('table').addClass('cb-collapsed'); return false;">${_('Hide them')} |
|
194 | 194 | </a> |
|
195 | 195 | </td> |
|
196 | 196 | </tr> |
|
197 | 197 | %endif |
|
198 | 198 | %endif |
|
199 | 199 | |
|
200 | 200 | %for hunk in filediff.hunks: |
|
201 | 201 | <tr class="cb-hunk"> |
|
202 | 202 | <td ${c.diffmode == 'unified' and 'colspan=3' or ''}> |
|
203 | 203 | ## TODO: dan: add ajax loading of more context here |
|
204 | 204 | ## <a href="#"> |
|
205 | 205 | <i class="icon-more"></i> |
|
206 | 206 | ## </a> |
|
207 | 207 | </td> |
|
208 | 208 | <td ${c.diffmode == 'sideside' and 'colspan=5' or ''}> |
|
209 | 209 | @@ |
|
210 | 210 | -${hunk.source_start},${hunk.source_length} |
|
211 | 211 | +${hunk.target_start},${hunk.target_length} |
|
212 | 212 | ${hunk.section_header} |
|
213 | 213 | </td> |
|
214 | 214 | </tr> |
|
215 | 215 | %if c.diffmode == 'unified': |
|
216 | 216 | ${render_hunk_lines_unified(hunk, use_comments=use_comments, inline_comments=inline_comments)} |
|
217 | 217 | %elif c.diffmode == 'sideside': |
|
218 | 218 | ${render_hunk_lines_sideside(hunk, use_comments=use_comments, inline_comments=inline_comments)} |
|
219 | 219 | %else: |
|
220 | 220 | <tr class="cb-line"> |
|
221 | 221 | <td>unknown diff mode</td> |
|
222 | 222 | </tr> |
|
223 | 223 | %endif |
|
224 | 224 | %endfor |
|
225 | 225 |
|
|
226 | <% unmatched_comments = (inline_comments or {}).get(filediff.patch['filename'], {}) %> | |
|
227 | ||
|
226 | 228 | ## outdated comments that do not fit into currently displayed lines |
|
227 |
% for lineno, comments in |
|
|
229 | % for lineno, comments in unmatched_comments.items(): | |
|
228 | 230 | |
|
229 | %if c.diffmode == 'unified': | |
|
230 | <tr class="cb-line"> | |
|
231 |
<t |
|
|
232 |
<td cl |
|
|
233 | <td class="cb-lineno cb-context"></td> | |
|
234 | <td class="cb-content cb-context"> | |
|
235 | ${inline_comments_container(comments, inline_comments)} | |
|
236 |
</ |
|
|
237 |
</t |
|
|
238 | %elif c.diffmode == 'sideside': | |
|
239 | <tr class="cb-line"> | |
|
240 |
<t |
|
|
241 |
<td class="cb- |
|
|
242 |
<td class="cb- |
|
|
243 | % if lineno.startswith('o'): | |
|
231 | %if c.diffmode == 'unified': | |
|
232 | % if loop.index == 0: | |
|
233 | <tr class="cb-hunk"> | |
|
234 | <td colspan="3"></td> | |
|
235 | <td> | |
|
236 | <div> | |
|
237 | ${_('Unmatched inline comments below')} | |
|
238 | </div> | |
|
239 | </td> | |
|
240 | </tr> | |
|
241 | % endif | |
|
242 | <tr class="cb-line"> | |
|
243 | <td class="cb-data cb-context"></td> | |
|
244 | <td class="cb-lineno cb-context"></td> | |
|
245 | <td class="cb-lineno cb-context"></td> | |
|
246 | <td class="cb-content cb-context"> | |
|
244 | 247 | ${inline_comments_container(comments, inline_comments)} |
|
245 |
|
|
|
246 |
</t |
|
|
248 | </td> | |
|
249 | </tr> | |
|
250 | %elif c.diffmode == 'sideside': | |
|
251 | % if loop.index == 0: | |
|
252 | <tr class="cb-hunk"> | |
|
253 | <td colspan="2"></td> | |
|
254 | <td class="cb-line" colspan="6"> | |
|
255 | <div> | |
|
256 | ${_('Unmatched comments below')} | |
|
257 | </div> | |
|
258 | </td> | |
|
259 | </tr> | |
|
260 | % endif | |
|
261 | <tr class="cb-line"> | |
|
262 | <td class="cb-data cb-context"></td> | |
|
263 | <td class="cb-lineno cb-context"></td> | |
|
264 | <td class="cb-content cb-context"> | |
|
265 | % if lineno.startswith('o'): | |
|
266 | ${inline_comments_container(comments, inline_comments)} | |
|
267 | % endif | |
|
268 | </td> | |
|
247 | 269 | |
|
248 | <td class="cb-data cb-context"></td> | |
|
249 | <td class="cb-lineno cb-context"></td> | |
|
250 | <td class="cb-content cb-context"> | |
|
251 | % if lineno.startswith('n'): | |
|
252 | ${inline_comments_container(comments, inline_comments)} | |
|
253 | % endif | |
|
254 | </td> | |
|
255 | </tr> | |
|
256 | %endif | |
|
270 | <td class="cb-data cb-context"></td> | |
|
271 | <td class="cb-lineno cb-context"></td> | |
|
272 | <td class="cb-content cb-context"> | |
|
273 | % if lineno.startswith('n'): | |
|
274 | ${inline_comments_container(comments, inline_comments)} | |
|
275 | % endif | |
|
276 | </td> | |
|
277 | </tr> | |
|
278 | %endif | |
|
257 | 279 | |
|
258 | 280 | % endfor |
|
259 | 281 | |
|
260 | 282 | </table> |
|
261 | 283 | </div> |
|
262 | 284 | %endfor |
|
263 | 285 | |
|
264 | 286 | ## outdated comments that are made for a file that has been deleted |
|
265 | 287 | % for filename, comments_dict in (deleted_files_comments or {}).items(): |
|
266 | 288 | <% |
|
267 | 289 | display_state = 'display: none' |
|
268 | 290 | open_comments_in_file = [x for x in comments_dict['comments'] if x.outdated is False] |
|
269 | 291 | if open_comments_in_file: |
|
270 | 292 | display_state = '' |
|
271 | 293 | %> |
|
272 | 294 | <div class="filediffs filediff-outdated" style="${display_state}"> |
|
273 | 295 | <input ${collapse_all and 'checked' or ''} class="filediff-collapse-state" id="filediff-collapse-${id(filename)}" type="checkbox"> |
|
274 | 296 | <div class="filediff" data-f-path="${filename}" id="a_${h.FID('', filename)}"> |
|
275 | 297 | <label for="filediff-collapse-${id(filename)}" class="filediff-heading"> |
|
276 | 298 | <div class="filediff-collapse-indicator"></div> |
|
277 | 299 | <span class="pill"> |
|
278 | 300 | ## file was deleted |
|
279 | 301 | <strong>${filename}</strong> |
|
280 | 302 | </span> |
|
281 | 303 | <span class="pill-group" style="float: left"> |
|
282 | 304 | ## file op, doesn't need translation |
|
283 | 305 | <span class="pill" op="removed">removed in this version</span> |
|
284 | 306 | </span> |
|
285 | 307 | <a class="pill filediff-anchor" href="#a_${h.FID('', filename)}">ΒΆ</a> |
|
286 | 308 | <span class="pill-group" style="float: right"> |
|
287 | 309 | <span class="pill" op="deleted">-${comments_dict['stats']}</span> |
|
288 | 310 | </span> |
|
289 | 311 | </label> |
|
290 | 312 | |
|
291 | 313 | <table class="cb cb-diff-${c.diffmode} code-highlight ${over_lines_changed_limit and 'cb-collapsed' or ''}"> |
|
292 | 314 | <tr> |
|
293 | 315 | % if c.diffmode == 'unified': |
|
294 | 316 | <td></td> |
|
295 | 317 | %endif |
|
296 | 318 | |
|
297 | 319 | <td></td> |
|
298 | 320 | <td class="cb-text cb-${op_class(BIN_FILENODE)}" ${c.diffmode == 'unified' and 'colspan=4' or 'colspan=5'}> |
|
299 | 321 | ${_('File was deleted in this version. There are still outdated/unresolved comments attached to it.')} |
|
300 | 322 | </td> |
|
301 | 323 | </tr> |
|
302 | 324 | %if c.diffmode == 'unified': |
|
303 | 325 | <tr class="cb-line"> |
|
304 | 326 | <td class="cb-data cb-context"></td> |
|
305 | 327 | <td class="cb-lineno cb-context"></td> |
|
306 | 328 | <td class="cb-lineno cb-context"></td> |
|
307 | 329 | <td class="cb-content cb-context"> |
|
308 | 330 | ${inline_comments_container(comments_dict['comments'], inline_comments)} |
|
309 | 331 | </td> |
|
310 | 332 | </tr> |
|
311 | 333 | %elif c.diffmode == 'sideside': |
|
312 | 334 | <tr class="cb-line"> |
|
313 | 335 | <td class="cb-data cb-context"></td> |
|
314 | 336 | <td class="cb-lineno cb-context"></td> |
|
315 | 337 | <td class="cb-content cb-context"></td> |
|
316 | 338 | |
|
317 | 339 | <td class="cb-data cb-context"></td> |
|
318 | 340 | <td class="cb-lineno cb-context"></td> |
|
319 | 341 | <td class="cb-content cb-context"> |
|
320 | 342 | ${inline_comments_container(comments_dict['comments'], inline_comments)} |
|
321 | 343 | </td> |
|
322 | 344 | </tr> |
|
323 | 345 | %endif |
|
324 | 346 | </table> |
|
325 | 347 | </div> |
|
326 | 348 | </div> |
|
327 | 349 | % endfor |
|
328 | 350 | |
|
329 | 351 | </div> |
|
330 | 352 | </div> |
|
331 | 353 | </%def> |
|
332 | 354 | |
|
333 | 355 | <%def name="diff_ops(filediff)"> |
|
334 | 356 | <% |
|
335 | 357 | from rhodecode.lib.diffs import NEW_FILENODE, DEL_FILENODE, \ |
|
336 | 358 | MOD_FILENODE, RENAMED_FILENODE, CHMOD_FILENODE, BIN_FILENODE, COPIED_FILENODE |
|
337 | 359 | %> |
|
338 | 360 | <span class="pill"> |
|
339 | 361 | %if filediff.source_file_path and filediff.target_file_path: |
|
340 | 362 | %if filediff.source_file_path != filediff.target_file_path: |
|
341 | 363 | ## file was renamed, or copied |
|
342 | 364 | %if RENAMED_FILENODE in filediff.patch['stats']['ops']: |
|
343 | 365 | <strong>${filediff.target_file_path}</strong> β¬ <del>${filediff.source_file_path}</del> |
|
344 | 366 | <% final_path = filediff.target_file_path %> |
|
345 | 367 | %elif COPIED_FILENODE in filediff.patch['stats']['ops']: |
|
346 | 368 | <strong>${filediff.target_file_path}</strong> β¬ ${filediff.source_file_path} |
|
347 | 369 | <% final_path = filediff.target_file_path %> |
|
348 | 370 | %endif |
|
349 | 371 | %else: |
|
350 | 372 | ## file was modified |
|
351 | 373 | <strong>${filediff.source_file_path}</strong> |
|
352 | 374 | <% final_path = filediff.source_file_path %> |
|
353 | 375 | %endif |
|
354 | 376 | %else: |
|
355 | 377 | %if filediff.source_file_path: |
|
356 | 378 | ## file was deleted |
|
357 | 379 | <strong>${filediff.source_file_path}</strong> |
|
358 | 380 | <% final_path = filediff.source_file_path %> |
|
359 | 381 | %else: |
|
360 | 382 | ## file was added |
|
361 | 383 | <strong>${filediff.target_file_path}</strong> |
|
362 | 384 | <% final_path = filediff.target_file_path %> |
|
363 | 385 | %endif |
|
364 | 386 | %endif |
|
365 | 387 | <i style="color: #aaa" class="tooltip icon-clipboard clipboard-action" data-clipboard-text="${final_path}" title="${_('Copy the full path')}" onclick="return false;"></i> |
|
366 | 388 | </span> |
|
367 | 389 | <span class="pill-group" style="float: left"> |
|
368 | 390 | %if filediff.limited_diff: |
|
369 | 391 | <span class="pill tooltip" op="limited" title="The stats for this diff are not complete">limited diff</span> |
|
370 | 392 | %endif |
|
371 | 393 | |
|
372 | 394 | %if RENAMED_FILENODE in filediff.patch['stats']['ops']: |
|
373 | 395 | <span class="pill" op="renamed">renamed</span> |
|
374 | 396 | %endif |
|
375 | 397 | |
|
376 | 398 | %if COPIED_FILENODE in filediff.patch['stats']['ops']: |
|
377 | 399 | <span class="pill" op="copied">copied</span> |
|
378 | 400 | %endif |
|
379 | 401 | |
|
380 | 402 | %if NEW_FILENODE in filediff.patch['stats']['ops']: |
|
381 | 403 | <span class="pill" op="created">created</span> |
|
382 | 404 | %if filediff['target_mode'].startswith('120'): |
|
383 | 405 | <span class="pill" op="symlink">symlink</span> |
|
384 | 406 | %else: |
|
385 | 407 | <span class="pill" op="mode">${nice_mode(filediff['target_mode'])}</span> |
|
386 | 408 | %endif |
|
387 | 409 | %endif |
|
388 | 410 | |
|
389 | 411 | %if DEL_FILENODE in filediff.patch['stats']['ops']: |
|
390 | 412 | <span class="pill" op="removed">removed</span> |
|
391 | 413 | %endif |
|
392 | 414 | |
|
393 | 415 | %if CHMOD_FILENODE in filediff.patch['stats']['ops']: |
|
394 | 416 | <span class="pill" op="mode"> |
|
395 | 417 | ${nice_mode(filediff['source_mode'])} β‘ ${nice_mode(filediff['target_mode'])} |
|
396 | 418 | </span> |
|
397 | 419 | %endif |
|
398 | 420 | </span> |
|
399 | 421 | |
|
400 | 422 | <a class="pill filediff-anchor" href="#a_${h.FID('', filediff.patch['filename'])}">ΒΆ</a> |
|
401 | 423 | |
|
402 | 424 | <span class="pill-group" style="float: right"> |
|
403 | 425 | %if BIN_FILENODE in filediff.patch['stats']['ops']: |
|
404 | 426 | <span class="pill" op="binary">binary</span> |
|
405 | 427 | %if MOD_FILENODE in filediff.patch['stats']['ops']: |
|
406 | 428 | <span class="pill" op="modified">modified</span> |
|
407 | 429 | %endif |
|
408 | 430 | %endif |
|
409 | 431 | %if filediff.patch['stats']['added']: |
|
410 | 432 | <span class="pill" op="added">+${filediff.patch['stats']['added']}</span> |
|
411 | 433 | %endif |
|
412 | 434 | %if filediff.patch['stats']['deleted']: |
|
413 | 435 | <span class="pill" op="deleted">-${filediff.patch['stats']['deleted']}</span> |
|
414 | 436 | %endif |
|
415 | 437 | </span> |
|
416 | 438 | |
|
417 | 439 | </%def> |
|
418 | 440 | |
|
419 | 441 | <%def name="nice_mode(filemode)"> |
|
420 | 442 | ${filemode.startswith('100') and filemode[3:] or filemode} |
|
421 | 443 | </%def> |
|
422 | 444 | |
|
423 | 445 | <%def name="diff_menu(filediff, use_comments=False)"> |
|
424 | 446 | <div class="filediff-menu"> |
|
425 | 447 | %if filediff.diffset.source_ref: |
|
426 | 448 | %if filediff.operation in ['D', 'M']: |
|
427 | 449 | <a |
|
428 | 450 | class="tooltip" |
|
429 | 451 | href="${h.route_path('repo_files',repo_name=filediff.diffset.repo_name,commit_id=filediff.diffset.source_ref,f_path=filediff.source_file_path)}" |
|
430 | 452 | title="${h.tooltip(_('Show file at commit: %(commit_id)s') % {'commit_id': filediff.diffset.source_ref[:12]})}" |
|
431 | 453 | > |
|
432 | 454 | ${_('Show file before')} |
|
433 | 455 | </a> | |
|
434 | 456 | %else: |
|
435 | 457 | <span |
|
436 | 458 | class="tooltip" |
|
437 | 459 | title="${h.tooltip(_('File no longer present at commit: %(commit_id)s') % {'commit_id': filediff.diffset.source_ref[:12]})}" |
|
438 | 460 | > |
|
439 | 461 | ${_('Show file before')} |
|
440 | 462 | </span> | |
|
441 | 463 | %endif |
|
442 | 464 | %if filediff.operation in ['A', 'M']: |
|
443 | 465 | <a |
|
444 | 466 | class="tooltip" |
|
445 | 467 | href="${h.route_path('repo_files',repo_name=filediff.diffset.source_repo_name,commit_id=filediff.diffset.target_ref,f_path=filediff.target_file_path)}" |
|
446 | 468 | title="${h.tooltip(_('Show file at commit: %(commit_id)s') % {'commit_id': filediff.diffset.target_ref[:12]})}" |
|
447 | 469 | > |
|
448 | 470 | ${_('Show file after')} |
|
449 | 471 | </a> | |
|
450 | 472 | %else: |
|
451 | 473 | <span |
|
452 | 474 | class="tooltip" |
|
453 | 475 | title="${h.tooltip(_('File no longer present at commit: %(commit_id)s') % {'commit_id': filediff.diffset.target_ref[:12]})}" |
|
454 | 476 | > |
|
455 | 477 | ${_('Show file after')} |
|
456 | 478 | </span> | |
|
457 | 479 | %endif |
|
458 | 480 | <a |
|
459 | 481 | class="tooltip" |
|
460 | 482 | title="${h.tooltip(_('Raw diff'))}" |
|
461 | 483 | href="${h.route_path('repo_files_diff',repo_name=filediff.diffset.repo_name,f_path=filediff.target_file_path, _query=dict(diff2=filediff.diffset.target_ref,diff1=filediff.diffset.source_ref,diff='raw'))}" |
|
462 | 484 | > |
|
463 | 485 | ${_('Raw diff')} |
|
464 | 486 | </a> | |
|
465 | 487 | <a |
|
466 | 488 | class="tooltip" |
|
467 | 489 | title="${h.tooltip(_('Download diff'))}" |
|
468 | 490 | href="${h.route_path('repo_files_diff',repo_name=filediff.diffset.repo_name,f_path=filediff.target_file_path, _query=dict(diff2=filediff.diffset.target_ref,diff1=filediff.diffset.source_ref,diff='download'))}" |
|
469 | 491 | > |
|
470 | 492 | ${_('Download diff')} |
|
471 | 493 | </a> |
|
472 | 494 | % if use_comments: |
|
473 | 495 | | |
|
474 | 496 | % endif |
|
475 | 497 | |
|
476 | 498 | ## 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) |
|
477 | 499 | %if hasattr(c, 'ignorews_url'): |
|
478 | 500 | ${c.ignorews_url(request, h.FID('', filediff.patch['filename']))} |
|
479 | 501 | %endif |
|
480 | 502 | %if hasattr(c, 'context_url'): |
|
481 | 503 | ${c.context_url(request, h.FID('', filediff.patch['filename']))} |
|
482 | 504 | %endif |
|
483 | 505 | |
|
484 | 506 | %if use_comments: |
|
485 | 507 | <a href="#" onclick="return Rhodecode.comments.toggleComments(this);"> |
|
486 | 508 | <span class="show-comment-button">${_('Show comments')}</span><span class="hide-comment-button">${_('Hide comments')}</span> |
|
487 | 509 | </a> |
|
488 | 510 | %endif |
|
489 | 511 | %endif |
|
490 | 512 | </div> |
|
491 | 513 | </%def> |
|
492 | 514 | |
|
493 | 515 | |
|
494 | 516 | <%def name="inline_comments_container(comments, inline_comments)"> |
|
495 | 517 | <div class="inline-comments"> |
|
496 | 518 | %for comment in comments: |
|
497 | 519 | ${commentblock.comment_block(comment, inline=True)} |
|
498 | 520 | %endfor |
|
499 | 521 | % if comments and comments[-1].outdated: |
|
500 | 522 | <span class="btn btn-secondary cb-comment-add-button comment-outdated}" |
|
501 | 523 | style="display: none;}"> |
|
502 | 524 | ${_('Add another comment')} |
|
503 | 525 | </span> |
|
504 | 526 | % else: |
|
505 | 527 | <span onclick="return Rhodecode.comments.createComment(this)" |
|
506 | 528 | class="btn btn-secondary cb-comment-add-button"> |
|
507 | 529 | ${_('Add another comment')} |
|
508 | 530 | </span> |
|
509 | 531 | % endif |
|
510 | 532 | |
|
511 | 533 | </div> |
|
512 | 534 | </%def> |
|
513 | 535 | |
|
514 | 536 | <%! |
|
515 | def get_comments_for(comments, filename, line_version, line_number): | |
|
537 | def get_comments_for(diff_type, comments, filename, line_version, line_number): | |
|
516 | 538 | if hasattr(filename, 'unicode_path'): |
|
517 | 539 | filename = filename.unicode_path |
|
518 | 540 | |
|
519 | 541 | if not isinstance(filename, basestring): |
|
520 | 542 | return None |
|
521 | 543 | |
|
522 | line_key = '{}{}'.format(line_version, line_number) | |
|
544 | line_key = '{}{}'.format(line_version, line_number) ## e.g o37, n12 | |
|
545 | ||
|
523 | 546 | if comments and filename in comments: |
|
524 | 547 | file_comments = comments[filename] |
|
525 | 548 | if line_key in file_comments: |
|
526 |
|
|
|
549 | data = file_comments.pop(line_key) | |
|
550 | return data | |
|
527 | 551 | %> |
|
528 | 552 | |
|
529 | 553 | <%def name="render_hunk_lines_sideside(hunk, use_comments=False, inline_comments=None)"> |
|
530 | 554 | |
|
531 | 555 | %for i, line in enumerate(hunk.sideside): |
|
532 | 556 | <% |
|
533 | 557 | old_line_anchor, new_line_anchor = None, None |
|
534 | 558 | if line.original.lineno: |
|
535 | 559 | old_line_anchor = diff_line_anchor(hunk.source_file_path, line.original.lineno, 'o') |
|
536 | 560 | if line.modified.lineno: |
|
537 | 561 | new_line_anchor = diff_line_anchor(hunk.target_file_path, line.modified.lineno, 'n') |
|
538 | 562 | %> |
|
539 | 563 | |
|
540 | 564 | <tr class="cb-line"> |
|
541 | 565 | <td class="cb-data ${action_class(line.original.action)}" |
|
542 | 566 | data-line-no="${line.original.lineno}" |
|
543 | 567 | > |
|
544 | 568 | <div> |
|
545 | <% loc = None %> | |
|
569 | ||
|
570 | <% line_old_comments = None %> | |
|
546 | 571 | %if line.original.get_comment_args: |
|
547 | <% loc = get_comments_for(inline_comments, *line.original.get_comment_args) %> | |
|
572 | <% line_old_comments = get_comments_for('side-by-side', inline_comments, *line.original.get_comment_args) %> | |
|
548 | 573 | %endif |
|
549 | %if loc: | |
|
550 | <% has_outdated = any([x.outdated for x in loc]) %> | |
|
574 | %if line_old_comments: | |
|
575 | <% has_outdated = any([x.outdated for x in line_old_comments]) %> | |
|
551 | 576 | % if has_outdated: |
|
552 | <i title="${_('comments including outdated')}:${len(loc)}" class="icon-comment_toggle" onclick="return Rhodecode.comments.toggleLineComments(this)"></i> | |
|
577 | <i title="${_('comments including outdated')}:${len(line_old_comments)}" class="icon-comment_toggle" onclick="return Rhodecode.comments.toggleLineComments(this)"></i> | |
|
553 | 578 | % else: |
|
554 | <i title="${_('comments')}: ${len(loc)}" class="icon-comment" onclick="return Rhodecode.comments.toggleLineComments(this)"></i> | |
|
579 | <i title="${_('comments')}: ${len(line_old_comments)}" class="icon-comment" onclick="return Rhodecode.comments.toggleLineComments(this)"></i> | |
|
555 | 580 | % endif |
|
556 | 581 | %endif |
|
557 | 582 | </div> |
|
558 | 583 | </td> |
|
559 | 584 | <td class="cb-lineno ${action_class(line.original.action)}" |
|
560 | 585 | data-line-no="${line.original.lineno}" |
|
561 | 586 | %if old_line_anchor: |
|
562 | 587 | id="${old_line_anchor}" |
|
563 | 588 | %endif |
|
564 | 589 | > |
|
565 | 590 | %if line.original.lineno: |
|
566 | 591 | <a name="${old_line_anchor}" href="#${old_line_anchor}">${line.original.lineno}</a> |
|
567 | 592 | %endif |
|
568 | 593 | </td> |
|
569 | 594 | <td class="cb-content ${action_class(line.original.action)}" |
|
570 | 595 | data-line-no="o${line.original.lineno}" |
|
571 | 596 | > |
|
572 | 597 | %if use_comments and line.original.lineno: |
|
573 | 598 | ${render_add_comment_button()} |
|
574 | 599 | %endif |
|
575 | 600 | <span class="cb-code">${line.original.action} ${line.original.content or '' | n}</span> |
|
576 | 601 | |
|
577 | %if use_comments and line.original.lineno and loc: | |
|
578 | ${inline_comments_container(loc, inline_comments)} | |
|
602 | %if use_comments and line.original.lineno and line_old_comments: | |
|
603 | ${inline_comments_container(line_old_comments, inline_comments)} | |
|
579 | 604 | %endif |
|
580 | 605 | |
|
581 | 606 | </td> |
|
582 | 607 | <td class="cb-data ${action_class(line.modified.action)}" |
|
583 | 608 | data-line-no="${line.modified.lineno}" |
|
584 | 609 | > |
|
585 | 610 | <div> |
|
586 | 611 | |
|
587 | 612 | %if line.modified.get_comment_args: |
|
588 |
<% l |
|
|
613 | <% line_new_comments = get_comments_for('side-by-side', inline_comments, *line.modified.get_comment_args) %> | |
|
589 | 614 | %else: |
|
590 |
<% l |
|
|
615 | <% line_new_comments = None%> | |
|
591 | 616 | %endif |
|
592 |
%if l |
|
|
593 |
<% has_outdated = any([x.outdated for x in l |
|
|
617 | %if line_new_comments: | |
|
618 | <% has_outdated = any([x.outdated for x in line_new_comments]) %> | |
|
594 | 619 | % if has_outdated: |
|
595 |
<i title="${_('comments including outdated')}:${len(l |
|
|
620 | <i title="${_('comments including outdated')}:${len(line_new_comments)}" class="icon-comment_toggle" onclick="return Rhodecode.comments.toggleLineComments(this)"></i> | |
|
596 | 621 | % else: |
|
597 |
<i title="${_('comments')}: ${len(l |
|
|
622 | <i title="${_('comments')}: ${len(line_new_comments)}" class="icon-comment" onclick="return Rhodecode.comments.toggleLineComments(this)"></i> | |
|
598 | 623 | % endif |
|
599 | 624 | %endif |
|
600 | 625 | </div> |
|
601 | 626 | </td> |
|
602 | 627 | <td class="cb-lineno ${action_class(line.modified.action)}" |
|
603 | 628 | data-line-no="${line.modified.lineno}" |
|
604 | 629 | %if new_line_anchor: |
|
605 | 630 | id="${new_line_anchor}" |
|
606 | 631 | %endif |
|
607 | 632 | > |
|
608 | 633 | %if line.modified.lineno: |
|
609 | 634 | <a name="${new_line_anchor}" href="#${new_line_anchor}">${line.modified.lineno}</a> |
|
610 | 635 | %endif |
|
611 | 636 | </td> |
|
612 | 637 | <td class="cb-content ${action_class(line.modified.action)}" |
|
613 | 638 | data-line-no="n${line.modified.lineno}" |
|
614 | 639 | > |
|
615 | 640 | %if use_comments and line.modified.lineno: |
|
616 | 641 | ${render_add_comment_button()} |
|
617 | 642 | %endif |
|
618 | 643 | <span class="cb-code">${line.modified.action} ${line.modified.content or '' | n}</span> |
|
619 |
%if use_comments and line.modified.lineno and l |
|
|
620 |
${inline_comments_container(l |
|
|
644 | %if use_comments and line.modified.lineno and line_new_comments: | |
|
645 | ${inline_comments_container(line_new_comments, inline_comments)} | |
|
621 | 646 | %endif |
|
622 | 647 | </td> |
|
623 | 648 | </tr> |
|
624 | 649 | %endfor |
|
625 | 650 | </%def> |
|
626 | 651 | |
|
627 | 652 | |
|
628 | 653 | <%def name="render_hunk_lines_unified(hunk, use_comments=False, inline_comments=None)"> |
|
629 | 654 | %for old_line_no, new_line_no, action, content, comments_args in hunk.unified: |
|
630 | 655 | <% |
|
631 | 656 | old_line_anchor, new_line_anchor = None, None |
|
632 | 657 | if old_line_no: |
|
633 | 658 | old_line_anchor = diff_line_anchor(hunk.source_file_path, old_line_no, 'o') |
|
634 | 659 | if new_line_no: |
|
635 | 660 | new_line_anchor = diff_line_anchor(hunk.target_file_path, new_line_no, 'n') |
|
636 | 661 | %> |
|
637 | 662 | <tr class="cb-line"> |
|
638 | 663 | <td class="cb-data ${action_class(action)}"> |
|
639 | 664 | <div> |
|
640 | 665 | |
|
641 | 666 | %if comments_args: |
|
642 | <% comments = get_comments_for(inline_comments, *comments_args) %> | |
|
667 | <% comments = get_comments_for('unified', inline_comments, *comments_args) %> | |
|
643 | 668 | %else: |
|
644 | 669 | <% comments = None%> |
|
645 | 670 | %endif |
|
646 | 671 | |
|
647 | 672 | % if comments: |
|
648 | 673 | <% has_outdated = any([x.outdated for x in comments]) %> |
|
649 | 674 | % if has_outdated: |
|
650 | 675 | <i title="${_('comments including outdated')}:${len(comments)}" class="icon-comment_toggle" onclick="return Rhodecode.comments.toggleLineComments(this)"></i> |
|
651 | 676 | % else: |
|
652 | 677 | <i title="${_('comments')}: ${len(comments)}" class="icon-comment" onclick="return Rhodecode.comments.toggleLineComments(this)"></i> |
|
653 | 678 | % endif |
|
654 | 679 | % endif |
|
655 | 680 | </div> |
|
656 | 681 | </td> |
|
657 | 682 | <td class="cb-lineno ${action_class(action)}" |
|
658 | 683 | data-line-no="${old_line_no}" |
|
659 | 684 | %if old_line_anchor: |
|
660 | 685 | id="${old_line_anchor}" |
|
661 | 686 | %endif |
|
662 | 687 | > |
|
663 | 688 | %if old_line_anchor: |
|
664 | 689 | <a name="${old_line_anchor}" href="#${old_line_anchor}">${old_line_no}</a> |
|
665 | 690 | %endif |
|
666 | 691 | </td> |
|
667 | 692 | <td class="cb-lineno ${action_class(action)}" |
|
668 | 693 | data-line-no="${new_line_no}" |
|
669 | 694 | %if new_line_anchor: |
|
670 | 695 | id="${new_line_anchor}" |
|
671 | 696 | %endif |
|
672 | 697 | > |
|
673 | 698 | %if new_line_anchor: |
|
674 | 699 | <a name="${new_line_anchor}" href="#${new_line_anchor}">${new_line_no}</a> |
|
675 | 700 | %endif |
|
676 | 701 | </td> |
|
677 | 702 | <td class="cb-content ${action_class(action)}" |
|
678 | 703 | data-line-no="${new_line_no and 'n' or 'o'}${new_line_no or old_line_no}" |
|
679 | 704 | > |
|
680 | 705 | %if use_comments: |
|
681 | 706 | ${render_add_comment_button()} |
|
682 | 707 | %endif |
|
683 | 708 | <span class="cb-code">${action} ${content or '' | n}</span> |
|
684 | 709 | %if use_comments and comments: |
|
685 | 710 | ${inline_comments_container(comments, inline_comments)} |
|
686 | 711 | %endif |
|
687 | 712 | </td> |
|
688 | 713 | </tr> |
|
689 | 714 | %endfor |
|
690 | 715 | </%def> |
|
691 | 716 | |
|
692 | 717 | <%def name="render_add_comment_button()"> |
|
693 | 718 | <button class="btn btn-small btn-primary cb-comment-box-opener" onclick="return Rhodecode.comments.createComment(this)"> |
|
694 | 719 | <span><i class="icon-comment"></i></span> |
|
695 | 720 | </button> |
|
696 | 721 | </%def> |
|
697 | 722 | |
|
698 | 723 | <%def name="render_diffset_menu()"> |
|
699 | 724 | |
|
700 | 725 | <div class="diffset-menu clearinner"> |
|
701 | 726 | <div class="pull-right"> |
|
702 | 727 | <div class="btn-group"> |
|
703 | 728 | |
|
704 | 729 | <a |
|
705 | 730 | class="btn ${c.diffmode == 'sideside' and 'btn-primary'} tooltip" |
|
706 | 731 | title="${h.tooltip(_('View side by side'))}" |
|
707 | 732 | href="${h.current_route_path(request, diffmode='sideside')}"> |
|
708 | 733 | <span>${_('Side by Side')}</span> |
|
709 | 734 | </a> |
|
710 | 735 | <a |
|
711 | 736 | class="btn ${c.diffmode == 'unified' and 'btn-primary'} tooltip" |
|
712 | 737 | title="${h.tooltip(_('View unified'))}" href="${h.current_route_path(request, diffmode='unified')}"> |
|
713 | 738 | <span>${_('Unified')}</span> |
|
714 | 739 | </a> |
|
715 | 740 | </div> |
|
716 | 741 | </div> |
|
717 | 742 | |
|
718 | 743 | <div class="pull-left"> |
|
719 | 744 | <div class="btn-group"> |
|
720 | 745 | <a |
|
721 | 746 | class="btn" |
|
722 | 747 | href="#" |
|
723 | 748 | onclick="$('input[class=filediff-collapse-state]').prop('checked', false); return false">${_('Expand All Files')}</a> |
|
724 | 749 | <a |
|
725 | 750 | class="btn" |
|
726 | 751 | href="#" |
|
727 | 752 | onclick="$('input[class=filediff-collapse-state]').prop('checked', true); return false">${_('Collapse All Files')}</a> |
|
728 | 753 | <a |
|
729 | 754 | class="btn" |
|
730 | 755 | href="#" |
|
731 | 756 | onclick="return Rhodecode.comments.toggleWideMode(this)">${_('Wide Mode Diff')}</a> |
|
732 | 757 | </div> |
|
733 | 758 | </div> |
|
734 | 759 | </div> |
|
735 | 760 | </%def> |
General Comments 0
You need to be logged in to leave comments.
Login now