##// END OF EJS Templates
comments: place the left over comments (outdated/misplaced) to the left or right pane....
marcink -
r2249:dcdc2cc4 stable
parent child Browse files
Show More
@@ -1,707 +1,711 b''
1 1 # -*- coding: utf-8 -*-
2 2
3 3 # Copyright (C) 2011-2017 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 rhodecode.lib.helpers import (
28 28 get_lexer_for_filenode, html_escape, get_custom_lexer)
29 29 from rhodecode.lib.utils2 import AttributeDict
30 30 from rhodecode.lib.vcs.nodes import FileNode
31 31 from rhodecode.lib.diff_match_patch import diff_match_patch
32 32 from rhodecode.lib.diffs import LimitedDiffContainer
33 33 from pygments.lexers import get_lexer_by_name
34 34
35 35 plain_text_lexer = get_lexer_by_name(
36 36 'text', stripall=False, stripnl=False, ensurenl=False)
37 37
38 38
39 39 log = logging.getLogger()
40 40
41 41
42 42 def filenode_as_lines_tokens(filenode, lexer=None):
43 43 org_lexer = lexer
44 44 lexer = lexer or get_lexer_for_filenode(filenode)
45 45 log.debug('Generating file node pygment tokens for %s, %s, org_lexer:%s',
46 46 lexer, filenode, org_lexer)
47 47 tokens = tokenize_string(filenode.content, lexer)
48 48 lines = split_token_stream(tokens, split_string='\n')
49 49 rv = list(lines)
50 50 return rv
51 51
52 52
53 53 def tokenize_string(content, lexer):
54 54 """
55 55 Use pygments to tokenize some content based on a lexer
56 56 ensuring all original new lines and whitespace is preserved
57 57 """
58 58
59 59 lexer.stripall = False
60 60 lexer.stripnl = False
61 61 lexer.ensurenl = False
62 62 for token_type, token_text in lex(content, lexer):
63 63 yield pygment_token_class(token_type), token_text
64 64
65 65
66 66 def split_token_stream(tokens, split_string=u'\n'):
67 67 """
68 68 Take a list of (TokenType, text) tuples and split them by a string
69 69
70 70 >>> split_token_stream([(TEXT, 'some\ntext'), (TEXT, 'more\n')])
71 71 [(TEXT, 'some'), (TEXT, 'text'),
72 72 (TEXT, 'more'), (TEXT, 'text')]
73 73 """
74 74
75 75 buffer = []
76 76 for token_class, token_text in tokens:
77 77 parts = token_text.split(split_string)
78 78 for part in parts[:-1]:
79 79 buffer.append((token_class, part))
80 80 yield buffer
81 81 buffer = []
82 82
83 83 buffer.append((token_class, parts[-1]))
84 84
85 85 if buffer:
86 86 yield buffer
87 87
88 88
89 89 def filenode_as_annotated_lines_tokens(filenode):
90 90 """
91 91 Take a file node and return a list of annotations => lines, if no annotation
92 92 is found, it will be None.
93 93
94 94 eg:
95 95
96 96 [
97 97 (annotation1, [
98 98 (1, line1_tokens_list),
99 99 (2, line2_tokens_list),
100 100 ]),
101 101 (annotation2, [
102 102 (3, line1_tokens_list),
103 103 ]),
104 104 (None, [
105 105 (4, line1_tokens_list),
106 106 ]),
107 107 (annotation1, [
108 108 (5, line1_tokens_list),
109 109 (6, line2_tokens_list),
110 110 ])
111 111 ]
112 112 """
113 113
114 114 commit_cache = {} # cache commit_getter lookups
115 115
116 116 def _get_annotation(commit_id, commit_getter):
117 117 if commit_id not in commit_cache:
118 118 commit_cache[commit_id] = commit_getter()
119 119 return commit_cache[commit_id]
120 120
121 121 annotation_lookup = {
122 122 line_no: _get_annotation(commit_id, commit_getter)
123 123 for line_no, commit_id, commit_getter, line_content
124 124 in filenode.annotate
125 125 }
126 126
127 127 annotations_lines = ((annotation_lookup.get(line_no), line_no, tokens)
128 128 for line_no, tokens
129 129 in enumerate(filenode_as_lines_tokens(filenode), 1))
130 130
131 131 grouped_annotations_lines = groupby(annotations_lines, lambda x: x[0])
132 132
133 133 for annotation, group in grouped_annotations_lines:
134 134 yield (
135 135 annotation, [(line_no, tokens)
136 136 for (_, line_no, tokens) in group]
137 137 )
138 138
139 139
140 140 def render_tokenstream(tokenstream):
141 141 result = []
142 142 for token_class, token_ops_texts in rollup_tokenstream(tokenstream):
143 143
144 144 if token_class:
145 145 result.append(u'<span class="%s">' % token_class)
146 146 else:
147 147 result.append(u'<span>')
148 148
149 149 for op_tag, token_text in token_ops_texts:
150 150
151 151 if op_tag:
152 152 result.append(u'<%s>' % op_tag)
153 153
154 154 escaped_text = html_escape(token_text)
155 155
156 156 # TODO: dan: investigate showing hidden characters like space/nl/tab
157 157 # escaped_text = escaped_text.replace(' ', '<sp> </sp>')
158 158 # escaped_text = escaped_text.replace('\n', '<nl>\n</nl>')
159 159 # escaped_text = escaped_text.replace('\t', '<tab>\t</tab>')
160 160
161 161 result.append(escaped_text)
162 162
163 163 if op_tag:
164 164 result.append(u'</%s>' % op_tag)
165 165
166 166 result.append(u'</span>')
167 167
168 168 html = ''.join(result)
169 169 return html
170 170
171 171
172 172 def rollup_tokenstream(tokenstream):
173 173 """
174 174 Group a token stream of the format:
175 175
176 176 ('class', 'op', 'text')
177 177 or
178 178 ('class', 'text')
179 179
180 180 into
181 181
182 182 [('class1',
183 183 [('op1', 'text'),
184 184 ('op2', 'text')]),
185 185 ('class2',
186 186 [('op3', 'text')])]
187 187
188 188 This is used to get the minimal tags necessary when
189 189 rendering to html eg for a token stream ie.
190 190
191 191 <span class="A"><ins>he</ins>llo</span>
192 192 vs
193 193 <span class="A"><ins>he</ins></span><span class="A">llo</span>
194 194
195 195 If a 2 tuple is passed in, the output op will be an empty string.
196 196
197 197 eg:
198 198
199 199 >>> rollup_tokenstream([('classA', '', 'h'),
200 200 ('classA', 'del', 'ell'),
201 201 ('classA', '', 'o'),
202 202 ('classB', '', ' '),
203 203 ('classA', '', 'the'),
204 204 ('classA', '', 're'),
205 205 ])
206 206
207 207 [('classA', [('', 'h'), ('del', 'ell'), ('', 'o')],
208 208 ('classB', [('', ' ')],
209 209 ('classA', [('', 'there')]]
210 210
211 211 """
212 212 if tokenstream and len(tokenstream[0]) == 2:
213 213 tokenstream = ((t[0], '', t[1]) for t in tokenstream)
214 214
215 215 result = []
216 216 for token_class, op_list in groupby(tokenstream, lambda t: t[0]):
217 217 ops = []
218 218 for token_op, token_text_list in groupby(op_list, lambda o: o[1]):
219 219 text_buffer = []
220 220 for t_class, t_op, t_text in token_text_list:
221 221 text_buffer.append(t_text)
222 222 ops.append((token_op, ''.join(text_buffer)))
223 223 result.append((token_class, ops))
224 224 return result
225 225
226 226
227 227 def tokens_diff(old_tokens, new_tokens, use_diff_match_patch=True):
228 228 """
229 229 Converts a list of (token_class, token_text) tuples to a list of
230 230 (token_class, token_op, token_text) tuples where token_op is one of
231 231 ('ins', 'del', '')
232 232
233 233 :param old_tokens: list of (token_class, token_text) tuples of old line
234 234 :param new_tokens: list of (token_class, token_text) tuples of new line
235 235 :param use_diff_match_patch: boolean, will use google's diff match patch
236 236 library which has options to 'smooth' out the character by character
237 237 differences making nicer ins/del blocks
238 238 """
239 239
240 240 old_tokens_result = []
241 241 new_tokens_result = []
242 242
243 243 similarity = difflib.SequenceMatcher(None,
244 244 ''.join(token_text for token_class, token_text in old_tokens),
245 245 ''.join(token_text for token_class, token_text in new_tokens)
246 246 ).ratio()
247 247
248 248 if similarity < 0.6: # return, the blocks are too different
249 249 for token_class, token_text in old_tokens:
250 250 old_tokens_result.append((token_class, '', token_text))
251 251 for token_class, token_text in new_tokens:
252 252 new_tokens_result.append((token_class, '', token_text))
253 253 return old_tokens_result, new_tokens_result, similarity
254 254
255 255 token_sequence_matcher = difflib.SequenceMatcher(None,
256 256 [x[1] for x in old_tokens],
257 257 [x[1] for x in new_tokens])
258 258
259 259 for tag, o1, o2, n1, n2 in token_sequence_matcher.get_opcodes():
260 260 # check the differences by token block types first to give a more
261 261 # nicer "block" level replacement vs character diffs
262 262
263 263 if tag == 'equal':
264 264 for token_class, token_text in old_tokens[o1:o2]:
265 265 old_tokens_result.append((token_class, '', token_text))
266 266 for token_class, token_text in new_tokens[n1:n2]:
267 267 new_tokens_result.append((token_class, '', token_text))
268 268 elif tag == 'delete':
269 269 for token_class, token_text in old_tokens[o1:o2]:
270 270 old_tokens_result.append((token_class, 'del', token_text))
271 271 elif tag == 'insert':
272 272 for token_class, token_text in new_tokens[n1:n2]:
273 273 new_tokens_result.append((token_class, 'ins', token_text))
274 274 elif tag == 'replace':
275 275 # if same type token blocks must be replaced, do a diff on the
276 276 # characters in the token blocks to show individual changes
277 277
278 278 old_char_tokens = []
279 279 new_char_tokens = []
280 280 for token_class, token_text in old_tokens[o1:o2]:
281 281 for char in token_text:
282 282 old_char_tokens.append((token_class, char))
283 283
284 284 for token_class, token_text in new_tokens[n1:n2]:
285 285 for char in token_text:
286 286 new_char_tokens.append((token_class, char))
287 287
288 288 old_string = ''.join([token_text for
289 289 token_class, token_text in old_char_tokens])
290 290 new_string = ''.join([token_text for
291 291 token_class, token_text in new_char_tokens])
292 292
293 293 char_sequence = difflib.SequenceMatcher(
294 294 None, old_string, new_string)
295 295 copcodes = char_sequence.get_opcodes()
296 296 obuffer, nbuffer = [], []
297 297
298 298 if use_diff_match_patch:
299 299 dmp = diff_match_patch()
300 300 dmp.Diff_EditCost = 11 # TODO: dan: extract this to a setting
301 301 reps = dmp.diff_main(old_string, new_string)
302 302 dmp.diff_cleanupEfficiency(reps)
303 303
304 304 a, b = 0, 0
305 305 for op, rep in reps:
306 306 l = len(rep)
307 307 if op == 0:
308 308 for i, c in enumerate(rep):
309 309 obuffer.append((old_char_tokens[a+i][0], '', c))
310 310 nbuffer.append((new_char_tokens[b+i][0], '', c))
311 311 a += l
312 312 b += l
313 313 elif op == -1:
314 314 for i, c in enumerate(rep):
315 315 obuffer.append((old_char_tokens[a+i][0], 'del', c))
316 316 a += l
317 317 elif op == 1:
318 318 for i, c in enumerate(rep):
319 319 nbuffer.append((new_char_tokens[b+i][0], 'ins', c))
320 320 b += l
321 321 else:
322 322 for ctag, co1, co2, cn1, cn2 in copcodes:
323 323 if ctag == 'equal':
324 324 for token_class, token_text in old_char_tokens[co1:co2]:
325 325 obuffer.append((token_class, '', token_text))
326 326 for token_class, token_text in new_char_tokens[cn1:cn2]:
327 327 nbuffer.append((token_class, '', token_text))
328 328 elif ctag == 'delete':
329 329 for token_class, token_text in old_char_tokens[co1:co2]:
330 330 obuffer.append((token_class, 'del', token_text))
331 331 elif ctag == 'insert':
332 332 for token_class, token_text in new_char_tokens[cn1:cn2]:
333 333 nbuffer.append((token_class, 'ins', token_text))
334 334 elif ctag == 'replace':
335 335 for token_class, token_text in old_char_tokens[co1:co2]:
336 336 obuffer.append((token_class, 'del', token_text))
337 337 for token_class, token_text in new_char_tokens[cn1:cn2]:
338 338 nbuffer.append((token_class, 'ins', token_text))
339 339
340 340 old_tokens_result.extend(obuffer)
341 341 new_tokens_result.extend(nbuffer)
342 342
343 343 return old_tokens_result, new_tokens_result, similarity
344 344
345 345
346 346 class DiffSet(object):
347 347 """
348 348 An object for parsing the diff result from diffs.DiffProcessor and
349 349 adding highlighting, side by side/unified renderings and line diffs
350 350 """
351 351
352 352 HL_REAL = 'REAL' # highlights using original file, slow
353 353 HL_FAST = 'FAST' # highlights using just the line, fast but not correct
354 354 # in the case of multiline code
355 355 HL_NONE = 'NONE' # no highlighting, fastest
356 356
357 357 def __init__(self, highlight_mode=HL_REAL, repo_name=None,
358 358 source_repo_name=None,
359 359 source_node_getter=lambda filename: None,
360 360 target_node_getter=lambda filename: None,
361 361 source_nodes=None, target_nodes=None,
362 362 max_file_size_limit=150 * 1024, # files over this size will
363 363 # use fast highlighting
364 364 comments=None,
365 365 ):
366 366
367 367 self.highlight_mode = highlight_mode
368 368 self.highlighted_filenodes = {}
369 369 self.source_node_getter = source_node_getter
370 370 self.target_node_getter = target_node_getter
371 371 self.source_nodes = source_nodes or {}
372 372 self.target_nodes = target_nodes or {}
373 373 self.repo_name = repo_name
374 374 self.source_repo_name = source_repo_name or repo_name
375 375 self.comments = comments or {}
376 376 self.comments_store = self.comments.copy()
377 377 self.max_file_size_limit = max_file_size_limit
378 378
379 379 def render_patchset(self, patchset, source_ref=None, target_ref=None):
380 380 diffset = AttributeDict(dict(
381 381 lines_added=0,
382 382 lines_deleted=0,
383 383 changed_files=0,
384 384 files=[],
385 385 file_stats={},
386 386 limited_diff=isinstance(patchset, LimitedDiffContainer),
387 387 repo_name=self.repo_name,
388 388 source_repo_name=self.source_repo_name,
389 389 source_ref=source_ref,
390 390 target_ref=target_ref,
391 391 ))
392 392 for patch in patchset:
393 393 diffset.file_stats[patch['filename']] = patch['stats']
394 394 filediff = self.render_patch(patch)
395 395 filediff.diffset = diffset
396 396 diffset.files.append(filediff)
397 397 diffset.changed_files += 1
398 398 if not patch['stats']['binary']:
399 399 diffset.lines_added += patch['stats']['added']
400 400 diffset.lines_deleted += patch['stats']['deleted']
401 401
402 402 return diffset
403 403
404 404 _lexer_cache = {}
405
405 406 def _get_lexer_for_filename(self, filename, filenode=None):
406 407 # cached because we might need to call it twice for source/target
407 408 if filename not in self._lexer_cache:
408 409 if filenode:
409 410 lexer = filenode.lexer
410 411 extension = filenode.extension
411 412 else:
412 413 lexer = FileNode.get_lexer(filename=filename)
413 414 extension = filename.split('.')[-1]
414 415
415 416 lexer = get_custom_lexer(extension) or lexer
416 417 self._lexer_cache[filename] = lexer
417 418 return self._lexer_cache[filename]
418 419
419 420 def render_patch(self, patch):
420 421 log.debug('rendering diff for %r' % patch['filename'])
421 422
422 423 source_filename = patch['original_filename']
423 424 target_filename = patch['filename']
424 425
425 426 source_lexer = plain_text_lexer
426 427 target_lexer = plain_text_lexer
427 428
428 429 if not patch['stats']['binary']:
429 430 if self.highlight_mode == self.HL_REAL:
430 431 if (source_filename and patch['operation'] in ('D', 'M')
431 432 and source_filename not in self.source_nodes):
432 433 self.source_nodes[source_filename] = (
433 434 self.source_node_getter(source_filename))
434 435
435 436 if (target_filename and patch['operation'] in ('A', 'M')
436 437 and target_filename not in self.target_nodes):
437 438 self.target_nodes[target_filename] = (
438 439 self.target_node_getter(target_filename))
439 440
440 441 elif self.highlight_mode == self.HL_FAST:
441 442 source_lexer = self._get_lexer_for_filename(source_filename)
442 443 target_lexer = self._get_lexer_for_filename(target_filename)
443 444
444 445 source_file = self.source_nodes.get(source_filename, source_filename)
445 446 target_file = self.target_nodes.get(target_filename, target_filename)
446 447
447 448 source_filenode, target_filenode = None, None
448 449
449 450 # TODO: dan: FileNode.lexer works on the content of the file - which
450 451 # can be slow - issue #4289 explains a lexer clean up - which once
451 452 # done can allow caching a lexer for a filenode to avoid the file lookup
452 453 if isinstance(source_file, FileNode):
453 454 source_filenode = source_file
454 455 #source_lexer = source_file.lexer
455 456 source_lexer = self._get_lexer_for_filename(source_filename)
456 457 source_file.lexer = source_lexer
457 458
458 459 if isinstance(target_file, FileNode):
459 460 target_filenode = target_file
460 461 #target_lexer = target_file.lexer
461 462 target_lexer = self._get_lexer_for_filename(target_filename)
462 463 target_file.lexer = target_lexer
463 464
464 465 source_file_path, target_file_path = None, None
465 466
466 467 if source_filename != '/dev/null':
467 468 source_file_path = source_filename
468 469 if target_filename != '/dev/null':
469 470 target_file_path = target_filename
470 471
471 472 source_file_type = source_lexer.name
472 473 target_file_type = target_lexer.name
473 474
474 475 filediff = AttributeDict({
475 476 'source_file_path': source_file_path,
476 477 'target_file_path': target_file_path,
477 478 'source_filenode': source_filenode,
478 479 'target_filenode': target_filenode,
479 480 'source_file_type': target_file_type,
480 481 'target_file_type': source_file_type,
481 482 'patch': {'filename': patch['filename'], 'stats': patch['stats']},
482 483 'operation': patch['operation'],
483 484 'source_mode': patch['stats']['old_mode'],
484 485 'target_mode': patch['stats']['new_mode'],
485 486 'limited_diff': isinstance(patch, LimitedDiffContainer),
486 487 'hunks': [],
487 488 'diffset': self,
488 489 })
489 490
490 491 for hunk in patch['chunks'][1:]:
491 492 hunkbit = self.parse_hunk(hunk, source_file, target_file)
492 493 hunkbit.source_file_path = source_file_path
493 494 hunkbit.target_file_path = target_file_path
494 495 filediff.hunks.append(hunkbit)
495 496
496 497 left_comments = {}
497 498 if source_file_path in self.comments_store:
498 499 for lineno, comments in self.comments_store[source_file_path].items():
499 500 left_comments[lineno] = comments
500 501
501 502 if target_file_path in self.comments_store:
502 503 for lineno, comments in self.comments_store[target_file_path].items():
503 504 left_comments[lineno] = comments
505 # left comments are one that we couldn't place in diff lines.
506 # could be outdated, or the diff changed and this line is no
507 # longer available
504 508 filediff.left_comments = left_comments
505 509
506 510 return filediff
507 511
508 512 def parse_hunk(self, hunk, source_file, target_file):
509 513 result = AttributeDict(dict(
510 514 source_start=hunk['source_start'],
511 515 source_length=hunk['source_length'],
512 516 target_start=hunk['target_start'],
513 517 target_length=hunk['target_length'],
514 518 section_header=hunk['section_header'],
515 519 lines=[],
516 520 ))
517 521 before, after = [], []
518 522
519 523 for line in hunk['lines']:
520 524
521 525 if line['action'] == 'unmod':
522 526 result.lines.extend(
523 527 self.parse_lines(before, after, source_file, target_file))
524 528 after.append(line)
525 529 before.append(line)
526 530 elif line['action'] == 'add':
527 531 after.append(line)
528 532 elif line['action'] == 'del':
529 533 before.append(line)
530 534 elif line['action'] == 'old-no-nl':
531 535 before.append(line)
532 536 elif line['action'] == 'new-no-nl':
533 537 after.append(line)
534 538
535 539 result.lines.extend(
536 540 self.parse_lines(before, after, source_file, target_file))
537 541 result.unified = self.as_unified(result.lines)
538 542 result.sideside = result.lines
539 543
540 544 return result
541 545
542 546 def parse_lines(self, before_lines, after_lines, source_file, target_file):
543 547 # TODO: dan: investigate doing the diff comparison and fast highlighting
544 548 # on the entire before and after buffered block lines rather than by
545 549 # line, this means we can get better 'fast' highlighting if the context
546 550 # allows it - eg.
547 551 # line 4: """
548 552 # line 5: this gets highlighted as a string
549 553 # line 6: """
550 554
551 555 lines = []
552 556 while before_lines or after_lines:
553 557 before, after = None, None
554 558 before_tokens, after_tokens = None, None
555 559
556 560 if before_lines:
557 561 before = before_lines.pop(0)
558 562 if after_lines:
559 563 after = after_lines.pop(0)
560 564
561 565 original = AttributeDict()
562 566 modified = AttributeDict()
563 567
564 568 if before:
565 569 if before['action'] == 'old-no-nl':
566 570 before_tokens = [('nonl', before['line'])]
567 571 else:
568 572 before_tokens = self.get_line_tokens(
569 573 line_text=before['line'],
570 574 line_number=before['old_lineno'],
571 575 file=source_file)
572 576 original.lineno = before['old_lineno']
573 577 original.content = before['line']
574 578 original.action = self.action_to_op(before['action'])
575 579 original.comments = self.get_comments_for('old',
576 580 source_file, before['old_lineno'])
577 581
578 582 if after:
579 583 if after['action'] == 'new-no-nl':
580 584 after_tokens = [('nonl', after['line'])]
581 585 else:
582 586 after_tokens = self.get_line_tokens(
583 587 line_text=after['line'], line_number=after['new_lineno'],
584 588 file=target_file)
585 589 modified.lineno = after['new_lineno']
586 590 modified.content = after['line']
587 591 modified.action = self.action_to_op(after['action'])
588 592 modified.comments = self.get_comments_for('new',
589 593 target_file, after['new_lineno'])
590 594
591 595 # diff the lines
592 596 if before_tokens and after_tokens:
593 597 o_tokens, m_tokens, similarity = tokens_diff(
594 598 before_tokens, after_tokens)
595 599 original.content = render_tokenstream(o_tokens)
596 600 modified.content = render_tokenstream(m_tokens)
597 601 elif before_tokens:
598 602 original.content = render_tokenstream(
599 603 [(x[0], '', x[1]) for x in before_tokens])
600 604 elif after_tokens:
601 605 modified.content = render_tokenstream(
602 606 [(x[0], '', x[1]) for x in after_tokens])
603 607
604 608 lines.append(AttributeDict({
605 609 'original': original,
606 610 'modified': modified,
607 611 }))
608 612
609 613 return lines
610 614
611 def get_comments_for(self, version, file, line_number):
612 if hasattr(file, 'unicode_path'):
613 file = file.unicode_path
615 def get_comments_for(self, version, filename, line_number):
616 if hasattr(filename, 'unicode_path'):
617 filename = filename.unicode_path
614 618
615 if not isinstance(file, basestring):
619 if not isinstance(filename, basestring):
616 620 return None
617 621
618 622 line_key = {
619 623 'old': 'o',
620 624 'new': 'n',
621 625 }[version] + str(line_number)
622 626
623 if file in self.comments_store:
624 file_comments = self.comments_store[file]
627 if filename in self.comments_store:
628 file_comments = self.comments_store[filename]
625 629 if line_key in file_comments:
626 630 return file_comments.pop(line_key)
627 631
628 632 def get_line_tokens(self, line_text, line_number, file=None):
629 633 filenode = None
630 634 filename = None
631 635
632 636 if isinstance(file, basestring):
633 637 filename = file
634 638 elif isinstance(file, FileNode):
635 639 filenode = file
636 640 filename = file.unicode_path
637 641
638 642 if self.highlight_mode == self.HL_REAL and filenode:
639 643 lexer = self._get_lexer_for_filename(filename)
640 644 file_size_allowed = file.size < self.max_file_size_limit
641 645 if line_number and file_size_allowed:
642 646 return self.get_tokenized_filenode_line(
643 647 file, line_number, lexer)
644 648
645 649 if self.highlight_mode in (self.HL_REAL, self.HL_FAST) and filename:
646 650 lexer = self._get_lexer_for_filename(filename)
647 651 return list(tokenize_string(line_text, lexer))
648 652
649 653 return list(tokenize_string(line_text, plain_text_lexer))
650 654
651 655 def get_tokenized_filenode_line(self, filenode, line_number, lexer=None):
652 656
653 657 if filenode not in self.highlighted_filenodes:
654 658 tokenized_lines = filenode_as_lines_tokens(filenode, lexer)
655 659 self.highlighted_filenodes[filenode] = tokenized_lines
656 660 return self.highlighted_filenodes[filenode][line_number - 1]
657 661
658 662 def action_to_op(self, action):
659 663 return {
660 664 'add': '+',
661 665 'del': '-',
662 666 'unmod': ' ',
663 667 'old-no-nl': ' ',
664 668 'new-no-nl': ' ',
665 669 }.get(action, action)
666 670
667 671 def as_unified(self, lines):
668 672 """
669 673 Return a generator that yields the lines of a diff in unified order
670 674 """
671 675 def generator():
672 676 buf = []
673 677 for line in lines:
674 678
675 679 if buf and not line.original or line.original.action == ' ':
676 680 for b in buf:
677 681 yield b
678 682 buf = []
679 683
680 684 if line.original:
681 685 if line.original.action == ' ':
682 686 yield (line.original.lineno, line.modified.lineno,
683 687 line.original.action, line.original.content,
684 688 line.original.comments)
685 689 continue
686 690
687 691 if line.original.action == '-':
688 692 yield (line.original.lineno, None,
689 693 line.original.action, line.original.content,
690 694 line.original.comments)
691 695
692 696 if line.modified.action == '+':
693 697 buf.append((
694 698 None, line.modified.lineno,
695 699 line.modified.action, line.modified.content,
696 700 line.modified.comments))
697 701 continue
698 702
699 703 if line.modified:
700 704 yield (None, line.modified.lineno,
701 705 line.modified.action, line.modified.content,
702 706 line.modified.comments)
703 707
704 708 for b in buf:
705 709 yield b
706 710
707 711 return generator()
@@ -1,672 +1,678 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 )">
50 50
51 51 %if use_comments:
52 52 <div id="cb-comments-inline-container-template" class="js-template">
53 53 ${inline_comments_container([])}
54 54 </div>
55 55 <div class="js-template" id="cb-comment-inline-form-template">
56 56 <div class="comment-inline-form ac">
57 57
58 58 %if c.rhodecode_user.username != h.DEFAULT_USER:
59 59 ## render template for inline comments
60 60 ${commentblock.comment_form(form_type='inline')}
61 61 %else:
62 62 ${h.form('', class_='inline-form comment-form-login', method='get')}
63 63 <div class="pull-left">
64 64 <div class="comment-help pull-right">
65 65 ${_('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>
66 66 </div>
67 67 </div>
68 68 <div class="comment-button pull-right">
69 69 <button type="button" class="cb-comment-cancel" onclick="return Rhodecode.comments.cancelComment(this);">
70 70 ${_('Cancel')}
71 71 </button>
72 72 </div>
73 73 <div class="clearfix"></div>
74 74 ${h.end_form()}
75 75 %endif
76 76 </div>
77 77 </div>
78 78
79 79 %endif
80 80 <%
81 81 collapse_all = len(diffset.files) > collapse_when_files_over
82 82 %>
83 83
84 84 %if c.diffmode == 'sideside':
85 85 <style>
86 86 .wrapper {
87 87 max-width: 1600px !important;
88 88 }
89 89 </style>
90 90 %endif
91 91
92 92 %if ruler_at_chars:
93 93 <style>
94 94 .diff table.cb .cb-content:after {
95 95 content: "";
96 96 border-left: 1px solid blue;
97 97 position: absolute;
98 98 top: 0;
99 99 height: 18px;
100 100 opacity: .2;
101 101 z-index: 10;
102 102 //## +5 to account for diff action (+/-)
103 103 left: ${ruler_at_chars + 5}ch;
104 104 </style>
105 105 %endif
106 106
107 107 <div class="diffset ${disable_new_comments and 'diffset-comments-disabled'}">
108 108 <div class="diffset-heading ${diffset.limited_diff and 'diffset-heading-warning' or ''}">
109 109 %if commit:
110 110 <div class="pull-right">
111 111 <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='')}">
112 112 ${_('Browse Files')}
113 113 </a>
114 114 </div>
115 115 %endif
116 116 <h2 class="clearinner">
117 117 %if commit:
118 118 <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> -
119 119 ${h.age_component(commit.date)} -
120 120 %endif
121 121
122 122 %if diffset.limited_diff:
123 123 ${_('The requested commit is too big and content was truncated.')}
124 124
125 125 ${_ungettext('%(num)s file changed.', '%(num)s files changed.', diffset.changed_files) % {'num': diffset.changed_files}}
126 126 <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>
127 127 %else:
128 128 ${_ungettext('%(num)s file changed: %(linesadd)s inserted, ''%(linesdel)s deleted',
129 129 '%(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}}
130 130 %endif
131 131
132 132 </h2>
133 133 </div>
134 134
135 135 %if not diffset.files:
136 136 <p class="empty_data">${_('No files')}</p>
137 137 %endif
138 138
139 139 <div class="filediffs">
140 140 ## initial value could be marked as False later on
141 141 <% over_lines_changed_limit = False %>
142 142 %for i, filediff in enumerate(diffset.files):
143 143
144 144 <%
145 145 lines_changed = filediff.patch['stats']['added'] + filediff.patch['stats']['deleted']
146 146 over_lines_changed_limit = lines_changed > lines_changed_limit
147 147 %>
148 148 <input ${collapse_all and 'checked' or ''} class="filediff-collapse-state" id="filediff-collapse-${id(filediff)}" type="checkbox">
149 149 <div
150 150 class="filediff"
151 151 data-f-path="${filediff.patch['filename']}"
152 152 id="a_${h.FID('', filediff.patch['filename'])}">
153 153 <label for="filediff-collapse-${id(filediff)}" class="filediff-heading">
154 154 <div class="filediff-collapse-indicator"></div>
155 155 ${diff_ops(filediff)}
156 156 </label>
157 157 ${diff_menu(filediff, use_comments=use_comments)}
158 158 <table class="cb cb-diff-${c.diffmode} code-highlight ${over_lines_changed_limit and 'cb-collapsed' or ''}">
159 159 %if not filediff.hunks:
160 160 %for op_id, op_text in filediff.patch['stats']['ops'].items():
161 161 <tr>
162 162 <td class="cb-text cb-${op_class(op_id)}" ${c.diffmode == 'unified' and 'colspan=4' or 'colspan=6'}>
163 163 %if op_id == DEL_FILENODE:
164 164 ${_('File was deleted')}
165 165 %elif op_id == BIN_FILENODE:
166 166 ${_('Binary file hidden')}
167 167 %else:
168 168 ${op_text}
169 169 %endif
170 170 </td>
171 171 </tr>
172 172 %endfor
173 173 %endif
174 174 %if filediff.limited_diff:
175 175 <tr class="cb-warning cb-collapser">
176 176 <td class="cb-text" ${c.diffmode == 'unified' and 'colspan=4' or 'colspan=6'}>
177 177 ${_('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>
178 178 </td>
179 179 </tr>
180 180 %else:
181 181 %if over_lines_changed_limit:
182 182 <tr class="cb-warning cb-collapser">
183 183 <td class="cb-text" ${c.diffmode == 'unified' and 'colspan=4' or 'colspan=6'}>
184 184 ${_('This diff has been collapsed as it changes many lines, (%i lines changed)' % lines_changed)}
185 185 <a href="#" class="cb-expand"
186 186 onclick="$(this).closest('table').removeClass('cb-collapsed'); return false;">${_('Show them')}
187 187 </a>
188 188 <a href="#" class="cb-collapse"
189 189 onclick="$(this).closest('table').addClass('cb-collapsed'); return false;">${_('Hide them')}
190 190 </a>
191 191 </td>
192 192 </tr>
193 193 %endif
194 194 %endif
195 195
196 196 %for hunk in filediff.hunks:
197 197 <tr class="cb-hunk">
198 198 <td ${c.diffmode == 'unified' and 'colspan=3' or ''}>
199 199 ## TODO: dan: add ajax loading of more context here
200 200 ## <a href="#">
201 201 <i class="icon-more"></i>
202 202 ## </a>
203 203 </td>
204 204 <td ${c.diffmode == 'sideside' and 'colspan=5' or ''}>
205 205 @@
206 206 -${hunk.source_start},${hunk.source_length}
207 207 +${hunk.target_start},${hunk.target_length}
208 208 ${hunk.section_header}
209 209 </td>
210 210 </tr>
211 211 %if c.diffmode == 'unified':
212 212 ${render_hunk_lines_unified(hunk, use_comments=use_comments)}
213 213 %elif c.diffmode == 'sideside':
214 214 ${render_hunk_lines_sideside(hunk, use_comments=use_comments)}
215 215 %else:
216 216 <tr class="cb-line">
217 217 <td>unknown diff mode</td>
218 218 </tr>
219 219 %endif
220 220 %endfor
221 221
222 222 ## outdated comments that do not fit into currently displayed lines
223 223 % for lineno, comments in filediff.left_comments.items():
224 224
225 225 %if c.diffmode == 'unified':
226 226 <tr class="cb-line">
227 227 <td class="cb-data cb-context"></td>
228 228 <td class="cb-lineno cb-context"></td>
229 229 <td class="cb-lineno cb-context"></td>
230 230 <td class="cb-content cb-context">
231 231 ${inline_comments_container(comments)}
232 232 </td>
233 233 </tr>
234 234 %elif c.diffmode == 'sideside':
235 235 <tr class="cb-line">
236 236 <td class="cb-data cb-context"></td>
237 237 <td class="cb-lineno cb-context"></td>
238 <td class="cb-content cb-context"></td>
238 <td class="cb-content cb-context">
239 % if lineno.startswith('o'):
240 ${inline_comments_container(comments)}
241 % endif
242 </td>
239 243
240 244 <td class="cb-data cb-context"></td>
241 245 <td class="cb-lineno cb-context"></td>
242 246 <td class="cb-content cb-context">
243 ${inline_comments_container(comments)}
247 % if lineno.startswith('n'):
248 ${inline_comments_container(comments)}
249 % endif
244 250 </td>
245 251 </tr>
246 252 %endif
247 253
248 254 % endfor
249 255
250 256 </table>
251 257 </div>
252 258 %endfor
253 259
254 260 ## outdated comments that are made for a file that has been deleted
255 261 % for filename, comments_dict in (deleted_files_comments or {}).items():
256 262
257 263 <div class="filediffs filediff-outdated" style="display: none">
258 264 <input ${collapse_all and 'checked' or ''} class="filediff-collapse-state" id="filediff-collapse-${id(filename)}" type="checkbox">
259 265 <div class="filediff" data-f-path="${filename}" id="a_${h.FID('', filename)}">
260 266 <label for="filediff-collapse-${id(filename)}" class="filediff-heading">
261 267 <div class="filediff-collapse-indicator"></div>
262 268 <span class="pill">
263 269 ## file was deleted
264 270 <strong>${filename}</strong>
265 271 </span>
266 272 <span class="pill-group" style="float: left">
267 273 ## file op, doesn't need translation
268 274 <span class="pill" op="removed">removed in this version</span>
269 275 </span>
270 276 <a class="pill filediff-anchor" href="#a_${h.FID('', filename)}">ΒΆ</a>
271 277 <span class="pill-group" style="float: right">
272 278 <span class="pill" op="deleted">-${comments_dict['stats']}</span>
273 279 </span>
274 280 </label>
275 281
276 282 <table class="cb cb-diff-${c.diffmode} code-highlight ${over_lines_changed_limit and 'cb-collapsed' or ''}">
277 283 <tr>
278 284 % if c.diffmode == 'unified':
279 285 <td></td>
280 286 %endif
281 287
282 288 <td></td>
283 289 <td class="cb-text cb-${op_class(BIN_FILENODE)}" ${c.diffmode == 'unified' and 'colspan=4' or 'colspan=5'}>
284 290 ${_('File was deleted in this version, and outdated comments were made on it')}
285 291 </td>
286 292 </tr>
287 293 %if c.diffmode == 'unified':
288 294 <tr class="cb-line">
289 295 <td class="cb-data cb-context"></td>
290 296 <td class="cb-lineno cb-context"></td>
291 297 <td class="cb-lineno cb-context"></td>
292 298 <td class="cb-content cb-context">
293 299 ${inline_comments_container(comments_dict['comments'])}
294 300 </td>
295 301 </tr>
296 302 %elif c.diffmode == 'sideside':
297 303 <tr class="cb-line">
298 304 <td class="cb-data cb-context"></td>
299 305 <td class="cb-lineno cb-context"></td>
300 306 <td class="cb-content cb-context"></td>
301 307
302 308 <td class="cb-data cb-context"></td>
303 309 <td class="cb-lineno cb-context"></td>
304 310 <td class="cb-content cb-context">
305 311 ${inline_comments_container(comments_dict['comments'])}
306 312 </td>
307 313 </tr>
308 314 %endif
309 315 </table>
310 316 </div>
311 317 </div>
312 318 % endfor
313 319
314 320 </div>
315 321 </div>
316 322 </%def>
317 323
318 324 <%def name="diff_ops(filediff)">
319 325 <%
320 326 from rhodecode.lib.diffs import NEW_FILENODE, DEL_FILENODE, \
321 327 MOD_FILENODE, RENAMED_FILENODE, CHMOD_FILENODE, BIN_FILENODE, COPIED_FILENODE
322 328 %>
323 329 <span class="pill">
324 330 %if filediff.source_file_path and filediff.target_file_path:
325 331 %if filediff.source_file_path != filediff.target_file_path:
326 332 ## file was renamed, or copied
327 333 %if RENAMED_FILENODE in filediff.patch['stats']['ops']:
328 334 <strong>${filediff.target_file_path}</strong> β¬… <del>${filediff.source_file_path}</del>
329 335 <% final_path = filediff.target_file_path %>
330 336 %elif COPIED_FILENODE in filediff.patch['stats']['ops']:
331 337 <strong>${filediff.target_file_path}</strong> β¬… ${filediff.source_file_path}
332 338 <% final_path = filediff.target_file_path %>
333 339 %endif
334 340 %else:
335 341 ## file was modified
336 342 <strong>${filediff.source_file_path}</strong>
337 343 <% final_path = filediff.source_file_path %>
338 344 %endif
339 345 %else:
340 346 %if filediff.source_file_path:
341 347 ## file was deleted
342 348 <strong>${filediff.source_file_path}</strong>
343 349 <% final_path = filediff.source_file_path %>
344 350 %else:
345 351 ## file was added
346 352 <strong>${filediff.target_file_path}</strong>
347 353 <% final_path = filediff.target_file_path %>
348 354 %endif
349 355 %endif
350 356 <i style="color: #aaa" class="tooltip icon-clipboard clipboard-action" data-clipboard-text="${final_path}" title="${_('Copy the full path')}" onclick="return false;"></i>
351 357 </span>
352 358 <span class="pill-group" style="float: left">
353 359 %if filediff.limited_diff:
354 360 <span class="pill tooltip" op="limited" title="The stats for this diff are not complete">limited diff</span>
355 361 %endif
356 362
357 363 %if RENAMED_FILENODE in filediff.patch['stats']['ops']:
358 364 <span class="pill" op="renamed">renamed</span>
359 365 %endif
360 366
361 367 %if COPIED_FILENODE in filediff.patch['stats']['ops']:
362 368 <span class="pill" op="copied">copied</span>
363 369 %endif
364 370
365 371 %if NEW_FILENODE in filediff.patch['stats']['ops']:
366 372 <span class="pill" op="created">created</span>
367 373 %if filediff['target_mode'].startswith('120'):
368 374 <span class="pill" op="symlink">symlink</span>
369 375 %else:
370 376 <span class="pill" op="mode">${nice_mode(filediff['target_mode'])}</span>
371 377 %endif
372 378 %endif
373 379
374 380 %if DEL_FILENODE in filediff.patch['stats']['ops']:
375 381 <span class="pill" op="removed">removed</span>
376 382 %endif
377 383
378 384 %if CHMOD_FILENODE in filediff.patch['stats']['ops']:
379 385 <span class="pill" op="mode">
380 386 ${nice_mode(filediff['source_mode'])} ➑ ${nice_mode(filediff['target_mode'])}
381 387 </span>
382 388 %endif
383 389 </span>
384 390
385 391 <a class="pill filediff-anchor" href="#a_${h.FID('', filediff.patch['filename'])}">ΒΆ</a>
386 392
387 393 <span class="pill-group" style="float: right">
388 394 %if BIN_FILENODE in filediff.patch['stats']['ops']:
389 395 <span class="pill" op="binary">binary</span>
390 396 %if MOD_FILENODE in filediff.patch['stats']['ops']:
391 397 <span class="pill" op="modified">modified</span>
392 398 %endif
393 399 %endif
394 400 %if filediff.patch['stats']['added']:
395 401 <span class="pill" op="added">+${filediff.patch['stats']['added']}</span>
396 402 %endif
397 403 %if filediff.patch['stats']['deleted']:
398 404 <span class="pill" op="deleted">-${filediff.patch['stats']['deleted']}</span>
399 405 %endif
400 406 </span>
401 407
402 408 </%def>
403 409
404 410 <%def name="nice_mode(filemode)">
405 411 ${filemode.startswith('100') and filemode[3:] or filemode}
406 412 </%def>
407 413
408 414 <%def name="diff_menu(filediff, use_comments=False)">
409 415 <div class="filediff-menu">
410 416 %if filediff.diffset.source_ref:
411 417 %if filediff.operation in ['D', 'M']:
412 418 <a
413 419 class="tooltip"
414 420 href="${h.route_path('repo_files',repo_name=filediff.diffset.repo_name,commit_id=filediff.diffset.source_ref,f_path=filediff.source_file_path)}"
415 421 title="${h.tooltip(_('Show file at commit: %(commit_id)s') % {'commit_id': filediff.diffset.source_ref[:12]})}"
416 422 >
417 423 ${_('Show file before')}
418 424 </a> |
419 425 %else:
420 426 <span
421 427 class="tooltip"
422 428 title="${h.tooltip(_('File no longer present at commit: %(commit_id)s') % {'commit_id': filediff.diffset.source_ref[:12]})}"
423 429 >
424 430 ${_('Show file before')}
425 431 </span> |
426 432 %endif
427 433 %if filediff.operation in ['A', 'M']:
428 434 <a
429 435 class="tooltip"
430 436 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)}"
431 437 title="${h.tooltip(_('Show file at commit: %(commit_id)s') % {'commit_id': filediff.diffset.target_ref[:12]})}"
432 438 >
433 439 ${_('Show file after')}
434 440 </a> |
435 441 %else:
436 442 <span
437 443 class="tooltip"
438 444 title="${h.tooltip(_('File no longer present at commit: %(commit_id)s') % {'commit_id': filediff.diffset.target_ref[:12]})}"
439 445 >
440 446 ${_('Show file after')}
441 447 </span> |
442 448 %endif
443 449 <a
444 450 class="tooltip"
445 451 title="${h.tooltip(_('Raw diff'))}"
446 452 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'))}"
447 453 >
448 454 ${_('Raw diff')}
449 455 </a> |
450 456 <a
451 457 class="tooltip"
452 458 title="${h.tooltip(_('Download diff'))}"
453 459 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'))}"
454 460 >
455 461 ${_('Download diff')}
456 462 </a>
457 463 % if use_comments:
458 464 |
459 465 % endif
460 466
461 467 ## 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)
462 468 %if hasattr(c, 'ignorews_url'):
463 469 ${c.ignorews_url(request, h.FID('', filediff.patch['filename']))}
464 470 %endif
465 471 %if hasattr(c, 'context_url'):
466 472 ${c.context_url(request, h.FID('', filediff.patch['filename']))}
467 473 %endif
468 474
469 475 %if use_comments:
470 476 <a href="#" onclick="return Rhodecode.comments.toggleComments(this);">
471 477 <span class="show-comment-button">${_('Show comments')}</span><span class="hide-comment-button">${_('Hide comments')}</span>
472 478 </a>
473 479 %endif
474 480 %endif
475 481 </div>
476 482 </%def>
477 483
478 484
479 485 <%def name="inline_comments_container(comments)">
480 486 <div class="inline-comments">
481 487 %for comment in comments:
482 488 ${commentblock.comment_block(comment, inline=True)}
483 489 %endfor
484 490
485 491 % if comments and comments[-1].outdated:
486 492 <span class="btn btn-secondary cb-comment-add-button comment-outdated}"
487 493 style="display: none;}">
488 494 ${_('Add another comment')}
489 495 </span>
490 496 % else:
491 497 <span onclick="return Rhodecode.comments.createComment(this)"
492 498 class="btn btn-secondary cb-comment-add-button">
493 499 ${_('Add another comment')}
494 500 </span>
495 501 % endif
496 502
497 503 </div>
498 504 </%def>
499 505
500 506
501 507 <%def name="render_hunk_lines_sideside(hunk, use_comments=False)">
502 508 %for i, line in enumerate(hunk.sideside):
503 509 <%
504 510 old_line_anchor, new_line_anchor = None, None
505 511 if line.original.lineno:
506 512 old_line_anchor = diff_line_anchor(hunk.source_file_path, line.original.lineno, 'o')
507 513 if line.modified.lineno:
508 514 new_line_anchor = diff_line_anchor(hunk.target_file_path, line.modified.lineno, 'n')
509 515 %>
510 516
511 517 <tr class="cb-line">
512 518 <td class="cb-data ${action_class(line.original.action)}"
513 519 data-line-number="${line.original.lineno}"
514 520 >
515 521 <div>
516 522 %if line.original.comments:
517 523 <i class="icon-comment" onclick="return Rhodecode.comments.toggleLineComments(this)"></i>
518 524 %endif
519 525 </div>
520 526 </td>
521 527 <td class="cb-lineno ${action_class(line.original.action)}"
522 528 data-line-number="${line.original.lineno}"
523 529 %if old_line_anchor:
524 530 id="${old_line_anchor}"
525 531 %endif
526 532 >
527 533 %if line.original.lineno:
528 534 <a name="${old_line_anchor}" href="#${old_line_anchor}">${line.original.lineno}</a>
529 535 %endif
530 536 </td>
531 537 <td class="cb-content ${action_class(line.original.action)}"
532 538 data-line-number="o${line.original.lineno}"
533 539 >
534 540 %if use_comments and line.original.lineno:
535 541 ${render_add_comment_button()}
536 542 %endif
537 543 <span class="cb-code">${line.original.action} ${line.original.content or '' | n}</span>
538 544 %if use_comments and line.original.lineno and line.original.comments:
539 545 ${inline_comments_container(line.original.comments)}
540 546 %endif
541 547 </td>
542 548 <td class="cb-data ${action_class(line.modified.action)}"
543 549 data-line-number="${line.modified.lineno}"
544 550 >
545 551 <div>
546 552 %if line.modified.comments:
547 553 <i class="icon-comment" onclick="return Rhodecode.comments.toggleLineComments(this)"></i>
548 554 %endif
549 555 </div>
550 556 </td>
551 557 <td class="cb-lineno ${action_class(line.modified.action)}"
552 558 data-line-number="${line.modified.lineno}"
553 559 %if new_line_anchor:
554 560 id="${new_line_anchor}"
555 561 %endif
556 562 >
557 563 %if line.modified.lineno:
558 564 <a name="${new_line_anchor}" href="#${new_line_anchor}">${line.modified.lineno}</a>
559 565 %endif
560 566 </td>
561 567 <td class="cb-content ${action_class(line.modified.action)}"
562 568 data-line-number="n${line.modified.lineno}"
563 569 >
564 570 %if use_comments and line.modified.lineno:
565 571 ${render_add_comment_button()}
566 572 %endif
567 573 <span class="cb-code">${line.modified.action} ${line.modified.content or '' | n}</span>
568 574 %if use_comments and line.modified.lineno and line.modified.comments:
569 575 ${inline_comments_container(line.modified.comments)}
570 576 %endif
571 577 </td>
572 578 </tr>
573 579 %endfor
574 580 </%def>
575 581
576 582
577 583 <%def name="render_hunk_lines_unified(hunk, use_comments=False)">
578 584 %for old_line_no, new_line_no, action, content, comments in hunk.unified:
579 585 <%
580 586 old_line_anchor, new_line_anchor = None, None
581 587 if old_line_no:
582 588 old_line_anchor = diff_line_anchor(hunk.source_file_path, old_line_no, 'o')
583 589 if new_line_no:
584 590 new_line_anchor = diff_line_anchor(hunk.target_file_path, new_line_no, 'n')
585 591 %>
586 592 <tr class="cb-line">
587 593 <td class="cb-data ${action_class(action)}">
588 594 <div>
589 595 %if comments:
590 596 <i class="icon-comment" onclick="return Rhodecode.comments.toggleLineComments(this)"></i>
591 597 %endif
592 598 </div>
593 599 </td>
594 600 <td class="cb-lineno ${action_class(action)}"
595 601 data-line-number="${old_line_no}"
596 602 %if old_line_anchor:
597 603 id="${old_line_anchor}"
598 604 %endif
599 605 >
600 606 %if old_line_anchor:
601 607 <a name="${old_line_anchor}" href="#${old_line_anchor}">${old_line_no}</a>
602 608 %endif
603 609 </td>
604 610 <td class="cb-lineno ${action_class(action)}"
605 611 data-line-number="${new_line_no}"
606 612 %if new_line_anchor:
607 613 id="${new_line_anchor}"
608 614 %endif
609 615 >
610 616 %if new_line_anchor:
611 617 <a name="${new_line_anchor}" href="#${new_line_anchor}">${new_line_no}</a>
612 618 %endif
613 619 </td>
614 620 <td class="cb-content ${action_class(action)}"
615 621 data-line-number="${new_line_no and 'n' or 'o'}${new_line_no or old_line_no}"
616 622 >
617 623 %if use_comments:
618 624 ${render_add_comment_button()}
619 625 %endif
620 626 <span class="cb-code">${action} ${content or '' | n}</span>
621 627 %if use_comments and comments:
622 628 ${inline_comments_container(comments)}
623 629 %endif
624 630 </td>
625 631 </tr>
626 632 %endfor
627 633 </%def>
628 634
629 635 <%def name="render_add_comment_button()">
630 636 <button class="btn btn-small btn-primary cb-comment-box-opener" onclick="return Rhodecode.comments.createComment(this)">
631 637 <span><i class="icon-comment"></i></span>
632 638 </button>
633 639 </%def>
634 640
635 641 <%def name="render_diffset_menu()">
636 642
637 643 <div class="diffset-menu clearinner">
638 644 <div class="pull-right">
639 645 <div class="btn-group">
640 646
641 647 <a
642 648 class="btn ${c.diffmode == 'sideside' and 'btn-primary'} tooltip"
643 649 title="${h.tooltip(_('View side by side'))}"
644 650 href="${h.url_replace(diffmode='sideside')}">
645 651 <span>${_('Side by Side')}</span>
646 652 </a>
647 653 <a
648 654 class="btn ${c.diffmode == 'unified' and 'btn-primary'} tooltip"
649 655 title="${h.tooltip(_('View unified'))}" href="${h.url_replace(diffmode='unified')}">
650 656 <span>${_('Unified')}</span>
651 657 </a>
652 658 </div>
653 659 </div>
654 660
655 661 <div class="pull-left">
656 662 <div class="btn-group">
657 663 <a
658 664 class="btn"
659 665 href="#"
660 666 onclick="$('input[class=filediff-collapse-state]').prop('checked', false); return false">${_('Expand All Files')}</a>
661 667 <a
662 668 class="btn"
663 669 href="#"
664 670 onclick="$('input[class=filediff-collapse-state]').prop('checked', true); return false">${_('Collapse All Files')}</a>
665 671 <a
666 672 class="btn"
667 673 href="#"
668 674 onclick="return Rhodecode.comments.toggleWideMode(this)">${_('Wide Mode Diff')}</a>
669 675 </div>
670 676 </div>
671 677 </div>
672 678 </%def>
General Comments 0
You need to be logged in to leave comments. Login now