##// END OF EJS Templates
diffs: simplified the datastructure of fillediff. Hopefully this...
marcink -
r1844:ecd2b149 default
parent child Browse files
Show More
@@ -267,8 +267,10 b' class ChangesetController(BaseRepoContro'
267 267 repo_name=c.repo_name,
268 268 source_node_getter=_node_getter(commit1),
269 269 target_node_getter=_node_getter(commit2),
270 comments=inline_comments
271 ).render_patchset(_parsed, commit1.raw_id, commit2.raw_id)
270 comments=inline_comments)
271 diffset = diffset.render_patchset(
272 _parsed, commit1.raw_id, commit2.raw_id)
273
272 274 c.changes[commit.raw_id] = diffset
273 275 else:
274 276 # downloads/raw we only need RAW diff nothing else
@@ -271,11 +271,13 b' class CompareController(BaseRepoControll'
271 271 return None
272 272 return get_node
273 273
274 c.diffset = codeblocks.DiffSet(
274 diffset = codeblocks.DiffSet(
275 275 repo_name=source_repo.repo_name,
276 276 source_node_getter=_node_getter(source_commit),
277 277 target_node_getter=_node_getter(target_commit),
278 ).render_patchset(_parsed, source_ref, target_ref)
278 )
279 c.diffset = diffset.render_patchset(
280 _parsed, source_ref, target_ref)
279 281
280 282 c.preview_mode = merge
281 283 c.source_commit = source_commit
@@ -471,31 +471,29 b' class DiffSet(object):'
471 471 source_file_type = source_lexer.name
472 472 target_file_type = target_lexer.name
473 473
474 op_hunks = patch['chunks'][0]
475 hunks = patch['chunks'][1:]
476
477 474 filediff = AttributeDict({
478 475 'source_file_path': source_file_path,
479 476 'target_file_path': target_file_path,
480 477 'source_filenode': source_filenode,
481 478 'target_filenode': target_filenode,
482 'hunks': [],
483 479 'source_file_type': target_file_type,
484 480 'target_file_type': source_file_type,
485 'patch': patch,
481 'patch': {'filename': patch['filename'], 'stats': patch['stats']},
482 'operation': patch['operation'],
486 483 'source_mode': patch['stats']['old_mode'],
487 484 'target_mode': patch['stats']['new_mode'],
488 485 'limited_diff': isinstance(patch, LimitedDiffContainer),
486 'hunks': [],
489 487 'diffset': self,
490 488 })
491 489
492 for hunk in hunks:
490 for hunk in patch['chunks'][1:]:
493 491 hunkbit = self.parse_hunk(hunk, source_file, target_file)
494 hunkbit.filediff = filediff
492 hunkbit.source_file_path = source_file_path
493 hunkbit.target_file_path = target_file_path
495 494 filediff.hunks.append(hunkbit)
496 495
497 496 left_comments = {}
498
499 497 if source_file_path in self.comments_store:
500 498 for lineno, comments in self.comments_store[source_file_path].items():
501 499 left_comments[lineno] = comments
@@ -503,8 +501,8 b' class DiffSet(object):'
503 501 if target_file_path in self.comments_store:
504 502 for lineno, comments in self.comments_store[target_file_path].items():
505 503 left_comments[lineno] = comments
504 filediff.left_comments = left_comments
506 505
507 filediff.left_comments = left_comments
508 506 return filediff
509 507
510 508 def parse_hunk(self, hunk, source_file, target_file):
@@ -519,6 +517,7 b' class DiffSet(object):'
519 517 before, after = [], []
520 518
521 519 for line in hunk['lines']:
520
522 521 if line['action'] == 'unmod':
523 522 result.lines.extend(
524 523 self.parse_lines(before, after, source_file, target_file))
@@ -567,7 +566,8 b' class DiffSet(object):'
567 566 before_tokens = [('nonl', before['line'])]
568 567 else:
569 568 before_tokens = self.get_line_tokens(
570 line_text=before['line'], line_number=before['old_lineno'],
569 line_text=before['line'],
570 line_number=before['old_lineno'],
571 571 file=source_file)
572 572 original.lineno = before['old_lineno']
573 573 original.content = before['line']
@@ -147,14 +147,14 b' collapse_all = len(diffset.files) > coll'
147 147 %for i, filediff in enumerate(diffset.files):
148 148
149 149 <%
150 lines_changed = filediff['patch']['stats']['added'] + filediff['patch']['stats']['deleted']
150 lines_changed = filediff.patch['stats']['added'] + filediff.patch['stats']['deleted']
151 151 over_lines_changed_limit = lines_changed > lines_changed_limit
152 152 %>
153 153 <input ${collapse_all and 'checked' or ''} class="filediff-collapse-state" id="filediff-collapse-${id(filediff)}" type="checkbox">
154 154 <div
155 155 class="filediff"
156 data-f-path="${filediff['patch']['filename']}"
157 id="a_${h.FID('', filediff['patch']['filename'])}">
156 data-f-path="${filediff.patch['filename']}"
157 id="a_${h.FID('', filediff.patch['filename'])}">
158 158 <label for="filediff-collapse-${id(filediff)}" class="filediff-heading">
159 159 <div class="filediff-collapse-indicator"></div>
160 160 ${diff_ops(filediff)}
@@ -162,7 +162,7 b' collapse_all = len(diffset.files) > coll'
162 162 ${diff_menu(filediff, use_comments=use_comments)}
163 163 <table class="cb cb-diff-${c.diffmode} code-highlight ${over_lines_changed_limit and 'cb-collapsed' or ''}">
164 164 %if not filediff.hunks:
165 %for op_id, op_text in filediff['patch']['stats']['ops'].items():
165 %for op_id, op_text in filediff.patch['stats']['ops'].items():
166 166 <tr>
167 167 <td class="cb-text cb-${op_class(op_id)}" ${c.diffmode == 'unified' and 'colspan=4' or 'colspan=6'}>
168 168 %if op_id == DEL_FILENODE:
@@ -176,7 +176,7 b' collapse_all = len(diffset.files) > coll'
176 176 </tr>
177 177 %endfor
178 178 %endif
179 %if filediff.patch['is_limited_diff']:
179 %if filediff.limited_diff:
180 180 <tr class="cb-warning cb-collapser">
181 181 <td class="cb-text" ${c.diffmode == 'unified' and 'colspan=4' or 'colspan=6'}>
182 182 ${_('The requested commit is too big and content was truncated.')} <a href="${link_for(fulldiff=1)}" onclick="return confirm('${_("Showing a big diff might take some time and resources, continue?")}')">${_('Show full diff')}</a>
@@ -322,7 +322,6 b' collapse_all = len(diffset.files) > coll'
322 322
323 323 <%def name="diff_ops(filediff)">
324 324 <%
325 stats = filediff['patch']['stats']
326 325 from rhodecode.lib.diffs import NEW_FILENODE, DEL_FILENODE, \
327 326 MOD_FILENODE, RENAMED_FILENODE, CHMOD_FILENODE, BIN_FILENODE, COPIED_FILENODE
328 327 %>
@@ -330,9 +329,9 b' from rhodecode.lib.diffs import NEW_FILE'
330 329 %if filediff.source_file_path and filediff.target_file_path:
331 330 %if filediff.source_file_path != filediff.target_file_path:
332 331 ## file was renamed, or copied
333 %if RENAMED_FILENODE in stats['ops']:
332 %if RENAMED_FILENODE in filediff.patch['stats']['ops']:
334 333 <strong>${filediff.target_file_path}</strong> β¬… <del>${filediff.source_file_path}</del>
335 %elif COPIED_FILENODE in stats['ops']:
334 %elif COPIED_FILENODE in filediff.patch['stats']['ops']:
336 335 <strong>${filediff.target_file_path}</strong> β¬… ${filediff.source_file_path}
337 336 %endif
338 337 %else:
@@ -350,19 +349,19 b' from rhodecode.lib.diffs import NEW_FILE'
350 349 %endif
351 350 </span>
352 351 <span class="pill-group" style="float: left">
353 %if filediff.patch['is_limited_diff']:
352 %if filediff.limited_diff:
354 353 <span class="pill tooltip" op="limited" title="The stats for this diff are not complete">limited diff</span>
355 354 %endif
356 355
357 %if RENAMED_FILENODE in stats['ops']:
356 %if RENAMED_FILENODE in filediff.patch['stats']['ops']:
358 357 <span class="pill" op="renamed">renamed</span>
359 358 %endif
360 359
361 %if COPIED_FILENODE in stats['ops']:
360 %if COPIED_FILENODE in filediff.patch['stats']['ops']:
362 361 <span class="pill" op="copied">copied</span>
363 362 %endif
364 363
365 %if NEW_FILENODE in stats['ops']:
364 %if NEW_FILENODE in filediff.patch['stats']['ops']:
366 365 <span class="pill" op="created">created</span>
367 366 %if filediff['target_mode'].startswith('120'):
368 367 <span class="pill" op="symlink">symlink</span>
@@ -371,11 +370,11 b' from rhodecode.lib.diffs import NEW_FILE'
371 370 %endif
372 371 %endif
373 372
374 %if DEL_FILENODE in stats['ops']:
373 %if DEL_FILENODE in filediff.patch['stats']['ops']:
375 374 <span class="pill" op="removed">removed</span>
376 375 %endif
377 376
378 %if CHMOD_FILENODE in stats['ops']:
377 %if CHMOD_FILENODE in filediff.patch['stats']['ops']:
379 378 <span class="pill" op="mode">
380 379 ${nice_mode(filediff['source_mode'])} ➑ ${nice_mode(filediff['target_mode'])}
381 380 </span>
@@ -385,17 +384,17 b' from rhodecode.lib.diffs import NEW_FILE'
385 384 <a class="pill filediff-anchor" href="#a_${h.FID('', filediff.patch['filename'])}">ΒΆ</a>
386 385
387 386 <span class="pill-group" style="float: right">
388 %if BIN_FILENODE in stats['ops']:
387 %if BIN_FILENODE in filediff.patch['stats']['ops']:
389 388 <span class="pill" op="binary">binary</span>
390 %if MOD_FILENODE in stats['ops']:
389 %if MOD_FILENODE in filediff.patch['stats']['ops']:
391 390 <span class="pill" op="modified">modified</span>
392 391 %endif
393 392 %endif
394 %if stats['added']:
395 <span class="pill" op="added">+${stats['added']}</span>
393 %if filediff.patch['stats']['added']:
394 <span class="pill" op="added">+${filediff.patch['stats']['added']}</span>
396 395 %endif
397 %if stats['deleted']:
398 <span class="pill" op="deleted">-${stats['deleted']}</span>
396 %if filediff.patch['stats']['deleted']:
397 <span class="pill" op="deleted">-${filediff.patch['stats']['deleted']}</span>
399 398 %endif
400 399 </span>
401 400
@@ -408,7 +407,7 b' from rhodecode.lib.diffs import NEW_FILE'
408 407 <%def name="diff_menu(filediff, use_comments=False)">
409 408 <div class="filediff-menu">
410 409 %if filediff.diffset.source_ref:
411 %if filediff.patch['operation'] in ['D', 'M']:
410 %if filediff.operation in ['D', 'M']:
412 411 <a
413 412 class="tooltip"
414 413 href="${h.url('files_home',repo_name=filediff.diffset.repo_name,f_path=filediff.source_file_path,revision=filediff.diffset.source_ref)}"
@@ -424,7 +423,7 b' from rhodecode.lib.diffs import NEW_FILE'
424 423 ${_('Show file before')}
425 424 </span> |
426 425 %endif
427 %if filediff.patch['operation'] in ['A', 'M']:
426 %if filediff.operation in ['A', 'M']:
428 427 <a
429 428 class="tooltip"
430 429 href="${h.url('files_home',repo_name=filediff.diffset.source_repo_name,f_path=filediff.target_file_path,revision=filediff.diffset.target_ref)}"
@@ -460,10 +459,10 b' from rhodecode.lib.diffs import NEW_FILE'
460 459
461 460 ## 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 461 %if hasattr(c, 'ignorews_url'):
463 ${c.ignorews_url(request.GET, h.FID('', filediff['patch']['filename']))}
462 ${c.ignorews_url(request.GET, h.FID('', filediff.patch['filename']))}
464 463 %endif
465 464 %if hasattr(c, 'context_url'):
466 ${c.context_url(request.GET, h.FID('', filediff['patch']['filename']))}
465 ${c.context_url(request.GET, h.FID('', filediff.patch['filename']))}
467 466 %endif
468 467
469 468 %if use_comments:
@@ -503,9 +502,9 b' from rhodecode.lib.diffs import NEW_FILE'
503 502 <%
504 503 old_line_anchor, new_line_anchor = None, None
505 504 if line.original.lineno:
506 old_line_anchor = diff_line_anchor(hunk.filediff.source_file_path, line.original.lineno, 'o')
505 old_line_anchor = diff_line_anchor(hunk.source_file_path, line.original.lineno, 'o')
507 506 if line.modified.lineno:
508 new_line_anchor = diff_line_anchor(hunk.filediff.target_file_path, line.modified.lineno, 'n')
507 new_line_anchor = diff_line_anchor(hunk.target_file_path, line.modified.lineno, 'n')
509 508 %>
510 509
511 510 <tr class="cb-line">
@@ -579,9 +578,9 b' from rhodecode.lib.diffs import NEW_FILE'
579 578 <%
580 579 old_line_anchor, new_line_anchor = None, None
581 580 if old_line_no:
582 old_line_anchor = diff_line_anchor(hunk.filediff.source_file_path, old_line_no, 'o')
581 old_line_anchor = diff_line_anchor(hunk.source_file_path, old_line_no, 'o')
583 582 if new_line_no:
584 new_line_anchor = diff_line_anchor(hunk.filediff.target_file_path, new_line_no, 'n')
583 new_line_anchor = diff_line_anchor(hunk.target_file_path, new_line_no, 'n')
585 584 %>
586 585 <tr class="cb-line">
587 586 <td class="cb-data ${action_class(action)}">
General Comments 0
You need to be logged in to leave comments. Login now