Changeset - b2575bdb847c
[Not reviewed]
beta
0 3 0
Mads Kiilerich - 13 years ago 2013-04-05 00:40:58
madski@unity3d.com
Grafted from: 51fbd52fbc58
diffs: drop diffs.differ

This function did not really add any value, it was yet another layer that was
hiding the bug that we use ref[1] without ref[0], and it had this strange
undefined behaviour for diffing across repos.

Inlining the call to .get_diff do not make the code more complex but makes it
more obvious what is going on so it can be cleaned up later.
3 files changed with 9 insertions and 35 deletions:
0 comments (0 inline, 0 general)
rhodecode/controllers/compare.py
Show inline comments
 
@@ -152,25 +152,28 @@ class CompareController(BaseRepoControll
 
        if c.ancestor:
 
            assert merge
 
            # case we want a simple diff without incoming changesets,
 
            # previewing what will be merged.
 
            # Make the diff on the other repo (which is known to have other_ref)
 
            log.debug('Using ancestor %s as org_ref instead of %s'
 
                      % (c.ancestor, org_ref))
 
            org_ref = ('rev', c.ancestor)
 
            org_repo = other_repo
 

	
 
        diff_limit = self.cut_off_limit if not c.fulldiff else None
 

	
 
        _diff = diffs.differ(org_repo, org_ref, other_repo, other_ref)
 
        log.debug('running diff between %s@%s and %s@%s'
 
                  % (org_repo.scm_instance.path, org_ref,
 
                     other_repo.scm_instance.path, other_ref))
 
        _diff = org_repo.scm_instance.get_diff(rev1=safe_str(org_ref[1]), rev2=safe_str(other_ref[1]))
 

	
 
        diff_processor = diffs.DiffProcessor(_diff or '', format='gitdiff',
 
                                             diff_limit=diff_limit)
 
        _parsed = diff_processor.prepare()
 

	
 
        c.limited_diff = False
 
        if isinstance(_parsed, LimitedDiffContainer):
 
            c.limited_diff = True
 

	
 
        c.files = []
 
        c.changes = {}
 
        c.lines_added = 0
rhodecode/controllers/pullrequests.py
Show inline comments
 
@@ -33,24 +33,25 @@ from itertools import groupby
 
from pylons import request, response, session, tmpl_context as c, url
 
from pylons.controllers.util import abort, redirect
 
from pylons.i18n.translation import _
 

	
 
from rhodecode.lib.compat import json
 
from rhodecode.lib.base import BaseRepoController, render
 
from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator,\
 
    NotAnonymous
 
from rhodecode.lib.helpers import Page
 
from rhodecode.lib import helpers as h
 
from rhodecode.lib import diffs
 
from rhodecode.lib.utils import action_logger, jsonify
 
from rhodecode.lib.vcs.utils import safe_str
 
from rhodecode.lib.vcs.exceptions import EmptyRepositoryError
 
from rhodecode.lib.vcs.backends.base import EmptyChangeset
 
from rhodecode.lib.diffs import LimitedDiffContainer
 
from rhodecode.model.db import User, PullRequest, ChangesetStatus,\
 
    ChangesetComment
 
from rhodecode.model.pull_request import PullRequestModel
 
from rhodecode.model.meta import Session
 
from rhodecode.model.repo import RepoModel
 
from rhodecode.model.comment import ChangesetCommentsModel
 
from rhodecode.model.changeset_status import ChangesetStatusModel
 
from rhodecode.model.forms import PullRequestForm
 
from mercurial import scmutil
 
@@ -319,25 +320,28 @@ class PullrequestsController(BaseRepoCon
 
        c.cs_ranges = [org_repo.get_changeset(x) for x in pull_request.revisions]
 

	
 
        c.statuses = org_repo.statuses([x.raw_id for x in c.cs_ranges])
 

	
 
        c.org_ref = org_ref[1]
 
        c.org_ref_type = org_ref[0]
 
        c.other_ref = other_ref[1]
 
        c.other_ref_type = other_ref[0]
 

	
 
        diff_limit = self.cut_off_limit if not fulldiff else None
 

	
 
        #we swap org/other ref since we run a simple diff on one repo
 
        _diff = diffs.differ(org_repo, other_ref, other_repo, org_ref)
 
        log.debug('running diff between %s@%s and %s@%s'
 
                  % (org_repo.scm_instance.path, org_ref,
 
                     other_repo.scm_instance.path, other_ref))
 
        _diff = org_repo.scm_instance.get_diff(rev1=safe_str(org_ref[1]), rev2=safe_str(other_ref[1]))
 

	
 
        diff_processor = diffs.DiffProcessor(_diff or '', format='gitdiff',
 
                                             diff_limit=diff_limit)
 
        _parsed = diff_processor.prepare()
 

	
 
        c.limited_diff = False
 
        if isinstance(_parsed, LimitedDiffContainer):
 
            c.limited_diff = True
 

	
 
        c.files = []
 
        c.changes = {}
 
        c.lines_added = 0
rhodecode/lib/diffs.py
Show inline comments
 
@@ -673,45 +673,12 @@ class DiffProcessor(object):
 
                    _html.append('''\t</td>''')
 
                    _html.append('''\n</tr>\n''')
 
        _html.append('''</table>''')
 
        if _html_empty:
 
            return None
 
        return ''.join(_html)
 

	
 
    def stat(self):
 
        """
 
        Returns tuple of added, and removed lines for this instance
 
        """
 
        return self.adds, self.removes
 

	
 

	
 
def differ(org_repo, org_ref, other_repo, other_ref,
 
           context=3, ignore_whitespace=False):
 
    """
 
    General differ between branches, bookmarks, revisions of two remote or
 
    local but related repositories
 

	
 
    :param org_repo:
 
    :param org_ref:
 
    :param other_repo:
 
    :type other_repo:
 
    :type other_ref:
 
    """
 

	
 
    org_repo_scm = org_repo.scm_instance
 
    other_repo_scm = other_repo.scm_instance
 

	
 
    org_repo = org_repo_scm._repo
 
    other_repo = other_repo_scm._repo
 

	
 
    org_ref = safe_str(org_ref[1])
 
    other_ref = safe_str(other_ref[1])
 

	
 
    if org_repo_scm == other_repo_scm:
 
        log.debug('running diff between %s@%s and %s@%s'
 
                  % (org_repo.path, org_ref,
 
                     other_repo.path, other_ref))
 
        _diff = org_repo_scm.get_diff(rev1=org_ref, rev2=other_ref,
 
            ignore_whitespace=ignore_whitespace, context=context)
 
        return _diff
 

	
 
    return '' # FIXME: when is it ever relevant to return nothing?
0 comments (0 inline, 0 general)