Mercurial > kallithea
comparison rhodecode/controllers/files.py @ 1768:5610fd9b6803 beta
added line context control to diffs
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Thu, 08 Dec 2011 02:25:23 +0200 |
parents | 1d1ccb873d00 |
children | 17caf4efe15c |
comparison
equal
deleted
inserted
replaced
1767:468afe69f2a8 | 1768:5610fd9b6803 |
---|---|
404 | 404 |
405 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write', | 405 @HasRepoPermissionAnyDecorator('repository.read', 'repository.write', |
406 'repository.admin') | 406 'repository.admin') |
407 def diff(self, repo_name, f_path): | 407 def diff(self, repo_name, f_path): |
408 ignore_whitespace = request.GET.get('ignorews') == '1' | 408 ignore_whitespace = request.GET.get('ignorews') == '1' |
409 line_context = request.GET.get('context', 3) | |
409 diff1 = request.GET.get('diff1') | 410 diff1 = request.GET.get('diff1') |
410 diff2 = request.GET.get('diff2') | 411 diff2 = request.GET.get('diff2') |
411 c.action = request.GET.get('diff') | 412 c.action = request.GET.get('diff') |
412 c.no_changes = diff1 == diff2 | 413 c.no_changes = diff1 == diff2 |
413 c.f_path = f_path | 414 c.f_path = f_path |
431 return redirect(url('files_home', | 432 return redirect(url('files_home', |
432 repo_name=c.repo_name, f_path=f_path)) | 433 repo_name=c.repo_name, f_path=f_path)) |
433 | 434 |
434 if c.action == 'download': | 435 if c.action == 'download': |
435 _diff = diffs.get_gitdiff(node1, node2, | 436 _diff = diffs.get_gitdiff(node1, node2, |
436 ignore_whitespace=ignore_whitespace) | 437 ignore_whitespace=ignore_whitespace, |
438 context=line_context) | |
437 diff = diffs.DiffProcessor(_diff,format='gitdiff') | 439 diff = diffs.DiffProcessor(_diff,format='gitdiff') |
438 | 440 |
439 diff_name = '%s_vs_%s.diff' % (diff1, diff2) | 441 diff_name = '%s_vs_%s.diff' % (diff1, diff2) |
440 response.content_type = 'text/plain' | 442 response.content_type = 'text/plain' |
441 response.content_disposition = 'attachment; filename=%s' \ | 443 response.content_disposition = 'attachment; filename=%s' \ |
442 % diff_name | 444 % diff_name |
443 return diff.raw_diff() | 445 return diff.raw_diff() |
444 | 446 |
445 elif c.action == 'raw': | 447 elif c.action == 'raw': |
446 _diff = diffs.get_gitdiff(node1, node2, | 448 _diff = diffs.get_gitdiff(node1, node2, |
447 ignore_whitespace=ignore_whitespace) | 449 ignore_whitespace=ignore_whitespace, |
450 context=line_context) | |
448 diff = diffs.DiffProcessor(_diff,format='gitdiff') | 451 diff = diffs.DiffProcessor(_diff,format='gitdiff') |
449 response.content_type = 'text/plain' | 452 response.content_type = 'text/plain' |
450 return diff.raw_diff() | 453 return diff.raw_diff() |
451 | 454 |
452 elif c.action == 'diff': | 455 elif c.action == 'diff': |
456 node2.size > self.cut_off_limit: | 459 node2.size > self.cut_off_limit: |
457 c.cur_diff = '' | 460 c.cur_diff = '' |
458 c.big_diff = True | 461 c.big_diff = True |
459 else: | 462 else: |
460 _diff = diffs.get_gitdiff(node1, node2, | 463 _diff = diffs.get_gitdiff(node1, node2, |
461 ignore_whitespace=ignore_whitespace) | 464 ignore_whitespace=ignore_whitespace, |
465 context=line_context) | |
462 diff = diffs.DiffProcessor(_diff,format='gitdiff') | 466 diff = diffs.DiffProcessor(_diff,format='gitdiff') |
463 c.cur_diff = diff.as_html() | 467 c.cur_diff = diff.as_html() |
464 else: | 468 else: |
465 | 469 |
466 #default option | 470 #default option |
471 c.cur_diff = '' | 475 c.cur_diff = '' |
472 c.big_diff = True | 476 c.big_diff = True |
473 | 477 |
474 else: | 478 else: |
475 _diff = diffs.get_gitdiff(node1, node2, | 479 _diff = diffs.get_gitdiff(node1, node2, |
476 ignore_whitespace=ignore_whitespace) | 480 ignore_whitespace=ignore_whitespace, |
481 context=line_context) | |
477 diff = diffs.DiffProcessor(_diff,format='gitdiff') | 482 diff = diffs.DiffProcessor(_diff,format='gitdiff') |
478 c.cur_diff = diff.as_html() | 483 c.cur_diff = diff.as_html() |
479 | 484 |
480 if not c.cur_diff and not c.big_diff: | 485 if not c.cur_diff and not c.big_diff: |
481 c.no_changes = True | 486 c.no_changes = True |