changeset 2362:3c4afb8894bd codereview

Improved cross repos diffs - added logging - fixed branch issues and empty bundle case
author Marcin Kuzminski <marcin@python-works.com>
date Wed, 30 May 2012 22:23:23 +0200
parents 948c16bb9476
children 745dda7817ed
files rhodecode/controllers/compare.py rhodecode/lib/diffs.py rhodecode/templates/branches/branches.html rhodecode/templates/compare/compare_diff.html
diffstat 4 files changed, 41 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/rhodecode/controllers/compare.py	Wed May 30 21:19:22 2012 +0200
+++ b/rhodecode/controllers/compare.py	Wed May 30 22:23:23 2012 +0200
@@ -58,7 +58,7 @@
         :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 @@
             _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 @@
 
         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 @@
 
     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 @@
                                            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()
 
--- a/rhodecode/lib/diffs.py	Wed May 30 21:19:22 2012 +0200
+++ b/rhodecode/lib/diffs.py	Wed May 30 22:23:23 2012 +0200
@@ -546,6 +546,18 @@
         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 @@
     :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 @@
     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 @@
             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))
--- a/rhodecode/templates/branches/branches.html	Wed May 30 21:19:22 2012 +0200
+++ b/rhodecode/templates/branches/branches.html	Wed May 30 22:23:23 2012 +0200
@@ -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>
--- a/rhodecode/templates/compare/compare_diff.html	Wed May 30 21:19:22 2012 +0200
+++ b/rhodecode/templates/compare/compare_diff.html	Wed May 30 22:23:23 2012 +0200
@@ -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>