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