Mercurial > kallithea
comparison rhodecode/lib/diffs.py @ 2892:5fba3778431c beta
#590 Add GET flag that controls the way the diff are generated, for pull requests we want to use non-bundle based diffs,
That are far better for doing code reviews. The /compare url still uses bundle compare for full comparision including the incoming changesets.
- Fixed tests
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Wed, 03 Oct 2012 18:41:57 +0200 |
parents | ab75def5c15d |
children | e46d0a90556e |
comparison
equal
deleted
inserted
replaced
2891:9812e617c564 | 2892:5fba3778431c |
---|---|
26 # along with this program. If not, see <http://www.gnu.org/licenses/>. | 26 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
27 | 27 |
28 import re | 28 import re |
29 import difflib | 29 import difflib |
30 import markupsafe | 30 import markupsafe |
31 import logging | |
31 | 32 |
32 from itertools import tee, imap | 33 from itertools import tee, imap |
33 | 34 |
34 from mercurial import patch | 35 from mercurial import patch |
35 from mercurial.mdiff import diffopts | 36 from mercurial.mdiff import diffopts |
43 from rhodecode.lib.vcs.nodes import FileNode, SubModuleNode | 44 from rhodecode.lib.vcs.nodes import FileNode, SubModuleNode |
44 from rhodecode.lib.vcs.backends.base import EmptyChangeset | 45 from rhodecode.lib.vcs.backends.base import EmptyChangeset |
45 from rhodecode.lib.helpers import escape | 46 from rhodecode.lib.helpers import escape |
46 from rhodecode.lib.utils import make_ui | 47 from rhodecode.lib.utils import make_ui |
47 from rhodecode.lib.utils2 import safe_unicode | 48 from rhodecode.lib.utils2 import safe_unicode |
49 | |
50 log = logging.getLogger(__name__) | |
48 | 51 |
49 | 52 |
50 def wrap_to_table(str_): | 53 def wrap_to_table(str_): |
51 return '''<table class="code-difftable"> | 54 return '''<table class="code-difftable"> |
52 <tr class="line no-comment"> | 55 <tr class="line no-comment"> |
572 | 575 |
573 # dict with the mapping 'filename' -> position in the bundle | 576 # dict with the mapping 'filename' -> position in the bundle |
574 self.bundlefilespos = {} | 577 self.bundlefilespos = {} |
575 | 578 |
576 | 579 |
577 def differ(org_repo, org_ref, other_repo, other_ref, discovery_data=None): | 580 def differ(org_repo, org_ref, other_repo, other_ref, discovery_data=None, |
581 bundle_compare=False): | |
578 """ | 582 """ |
579 General differ between branches, bookmarks or separate but releated | 583 General differ between branches, bookmarks or separate but releated |
580 repositories | 584 repositories |
581 | 585 |
582 :param org_repo: | 586 :param org_repo: |
596 other_repo = other_repo.scm_instance._repo | 600 other_repo = other_repo.scm_instance._repo |
597 opts = diffopts(git=True, ignorews=ignore_whitespace, context=context) | 601 opts = diffopts(git=True, ignorews=ignore_whitespace, context=context) |
598 org_ref = org_ref[1] | 602 org_ref = org_ref[1] |
599 other_ref = other_ref[1] | 603 other_ref = other_ref[1] |
600 | 604 |
601 if org_repo != other_repo: | 605 if org_repo != other_repo and bundle_compare: |
602 | 606 |
603 common, incoming, rheads = discovery_data | 607 common, incoming, rheads = discovery_data |
604 other_repo_peer = localrepo.locallegacypeer(other_repo.local()) | 608 other_repo_peer = localrepo.locallegacypeer(other_repo.local()) |
605 # create a bundle (uncompressed if other repo is not local) | 609 # create a bundle (uncompressed if other repo is not local) |
606 if other_repo_peer.capable('getbundle') and incoming: | 610 if other_repo_peer.capable('getbundle') and incoming: |
631 return ''.join(patch.diff(bundlerepo or org_repo, | 635 return ''.join(patch.diff(bundlerepo or org_repo, |
632 node1=org_repo[org_ref].node(), | 636 node1=org_repo[org_ref].node(), |
633 node2=other_repo[other_ref].node(), | 637 node2=other_repo[other_ref].node(), |
634 opts=opts)) | 638 opts=opts)) |
635 else: | 639 else: |
640 log.debug('running diff between %s@%s and %s@%s' | |
641 % (org_repo, org_ref, other_repo, other_ref)) | |
636 return ''.join(patch.diff(org_repo, node1=org_ref, node2=other_ref, | 642 return ''.join(patch.diff(org_repo, node1=org_ref, node2=other_ref, |
637 opts=opts)) | 643 opts=opts)) |