Changeset - 3c4afb8894bd
[Not reviewed]
codereview
0 4 0
Marcin Kuzminski - 13 years ago 2012-05-30 22:23:23
marcin@python-works.com
Improved cross repos diffs
- added logging
- fixed branch issues and empty bundle case
4 files changed with 41 insertions and 27 deletions:
0 comments (0 inline, 0 general)
rhodecode/controllers/compare.py
Show inline comments
 
@@ -58,7 +58,7 @@ class CompareController(BaseRepoControll
 
        :param ref: <orginal_reference>...<other_reference>
 
        :type ref: str
 
        """
 
        org_repo = c.rhodecode_repo.name
 
        org_repo = c.rhodecode_db_repo.repo_name
 

	
 
        def org_parser(org):
 
            _repo = org_repo
 
@@ -70,7 +70,6 @@ class CompareController(BaseRepoControll
 
            _repo = org_repo
 
            name, val = other.split(':')
 
            if _other_repo:
 
                #TODO: do an actual repo loookup within rhodecode
 
                _repo = _other_repo
 

	
 
            return _repo, (name, val)
 
@@ -86,14 +85,19 @@ class CompareController(BaseRepoControll
 

	
 
        raise HTTPNotFound
 

	
 
    def _get_discovery(self,org_repo, org_ref, other_repo, other_ref):
 
    def _get_discovery(self, org_repo, org_ref, other_repo, other_ref):
 
        from mercurial import discovery
 
        other = org_repo._repo
 
        repo = other_repo._repo
 
        tip = other[org_ref[1]]
 
        log.debug('Doing discovery for %s@%s vs %s@%s' % (
 
                        org_repo, org_ref, other_repo, other_ref)
 
        )
 
        log.debug('Filter heads are %s[%s]' % (tip, org_ref[1]))
 
        tmp = discovery.findcommonincoming(
 
                  repo=repo,  # other_repo we check for incoming
 
                  remote=other,  # org_repo source for incoming
 
                  heads=[other[org_ref[1]].node()],
 
                  heads=[tip.node()],
 
                  force=False
 
        )
 
        return tmp
 
@@ -123,13 +127,19 @@ class CompareController(BaseRepoControll
 

	
 
    def index(self, ref):
 
        org_repo, org_ref, other_repo, other_ref = self._handle_ref(ref)
 

	
 
        c.swap_url = h.url('compare_home', repo_name=other_repo,
 
                           ref='%s...%s' % (':'.join(other_ref),
 
                                            ':'.join(org_ref)),
 
                           repo=org_repo)
 
        c.org_repo = org_repo = Repository.get_by_repo_name(org_repo)
 
        c.other_repo = other_repo = Repository.get_by_repo_name(other_repo)
 
        tmp = self._get_discovery(org_repo.scm_instance,
 

	
 
        if c.org_repo is None or c.other_repo is None:
 
            log.error('Could not found repo %s or %s' % (org_repo, other_repo))
 
            raise HTTPNotFound
 

	
 
        discovery_data = self._get_discovery(org_repo.scm_instance,
 
                                           org_ref,
 
                                           other_repo.scm_instance,
 
                                           other_ref)
 
@@ -137,12 +147,13 @@ class CompareController(BaseRepoControll
 
                                           org_ref,
 
                                           other_repo.scm_instance,
 
                                           other_ref,
 
                                           tmp)
 
                                           discovery_data)
 

	
 
        c.org_ref = org_ref[1]
 
        c.other_ref = other_ref[1]
 
        # diff needs to have swapped org with other to generate proper diff
 
        _diff = diffs.differ(other_repo, other_ref, org_repo, org_ref, tmp)
 
        _diff = diffs.differ(other_repo, other_ref, org_repo, org_ref,
 
                             discovery_data)
 
        diff_processor = diffs.DiffProcessor(_diff, format='gitdiff')
 
        _parsed = diff_processor.prepare()
 

	
rhodecode/lib/diffs.py
Show inline comments
 
@@ -546,6 +546,18 @@ class DiffProcessor(object):
 
        return self.adds, self.removes
 

	
 

	
 
class InMemoryBundleRepo(bundlerepository):
 
    def __init__(self, ui, path, bundlestream):
 
        self._tempparent = None
 
        localrepo.localrepository.__init__(self, ui, path)
 
        self.ui.setconfig('phases', 'publish', False)
 

	
 
        self.bundle = bundlestream
 

	
 
        # dict with the mapping 'filename' -> position in the bundle
 
        self.bundlefilespos = {}
 

	
 

	
 
def differ(org_repo, org_ref, other_repo, other_ref, discovery_data=None):
 
    """
 
    General differ between branches, bookmarks or separate but releated 
 
@@ -561,7 +573,7 @@ def differ(org_repo, org_ref, other_repo
 
    :type other_ref:
 
    """
 

	
 
    ignore_whitespace = False
 
    bundlerepo = ignore_whitespace = False
 
    context = 3
 
    org_repo = org_repo.scm_instance._repo
 
    other_repo = other_repo.scm_instance._repo
 
@@ -572,8 +584,9 @@ def differ(org_repo, org_ref, other_repo
 
    if org_repo != other_repo:
 

	
 
        common, incoming, rheads = discovery_data
 

	
 
        # create a bundle (uncompressed if other repo is not local)
 
        if other_repo.capable('getbundle'):
 
        if other_repo.capable('getbundle') and incoming:
 
            # disable repo hooks here since it's just bundle !
 
            # patch and reset hooks section of UI config to not run any
 
            # hooks on fetching archives with subrepos
 
@@ -593,22 +606,10 @@ def differ(org_repo, org_ref, other_repo
 
            buf.seek(0)
 
            unbundle._stream = buf
 

	
 
        class InMemoryBundleRepo(bundlerepository):
 
            def __init__(self, ui, path, bundlestream):
 
                self._tempparent = None
 
                localrepo.localrepository.__init__(self, ui, path)
 
                self.ui.setconfig('phases', 'publish', False)
 

	
 
                self.bundle = bundlestream
 

	
 
                # dict with the mapping 'filename' -> position in the bundle
 
                self.bundlefilespos = {}
 

	
 
        ui = make_ui('db')
 
        bundlerepo = InMemoryBundleRepo(ui, path=other_repo.root,
 
                                        bundlestream=unbundle)
 
        return ''.join(patch.diff(bundlerepo, node1=org_ref, node2=other_ref,
 
                                  opts=opts))
 
            ui = make_ui('db')
 
            bundlerepo = InMemoryBundleRepo(ui, path=org_repo.root,
 
                                            bundlestream=unbundle)
 
        return ''.join(patch.diff(bundlerepo or org_repo, node2=other_ref, opts=opts))
 
    else:
 
        return ''.join(patch.diff(org_repo, node1=org_ref, node2=other_ref,
 
                                  opts=opts))
rhodecode/templates/branches/branches.html
Show inline comments
 
@@ -25,7 +25,9 @@
 
        ${self.breadcrumbs()}
 
    </div>
 
    <!-- end box / title -->
 
    %if c.repo_branches:
 
    <div class="info_box" id="compare_branches" style="clear: both;padding: 10px 19px;vertical-align: right;text-align: right;"><a href="#" class="ui-btn small">${_('Compare branches')}</a></div>
 
    %endif
 
    <div class="table">
 
        <%include file='branches_data.html'/>
 
    </div>
rhodecode/templates/compare/compare_diff.html
Show inline comments
 
@@ -26,9 +26,9 @@
 
    <div class="table">
 
        <div id="body" class="diffblock">
 
            <div class="code-header cv">
 
                <h3 class="code-header-title">${_('Compare View')} <a href="${c.swap_url}">swap</a></h3>
 
                <h3 class="code-header-title">${_('Compare View')}</h3>
 
                <div>
 
                ${'%s@%s' % (c.org_repo.repo_name, c.org_ref)} -> ${'%s@%s' % (c.other_repo.repo_name, c.other_ref)}
 
                ${'%s@%s' % (c.org_repo.repo_name, c.org_ref)} -> ${'%s@%s' % (c.other_repo.repo_name, c.other_ref)}  <a href="${c.swap_url}">[swap]</a>
 
                </div>
 
            </div>
 
        </div>
0 comments (0 inline, 0 general)