# HG changeset patch # User Marcin Kuzminski # Date 2012-05-30 20:23:23 # Node ID 3c4afb8894bdefeee7ab02a90499d191ad3aa9d6 # Parent 948c16bb947669656ab2282fec311c6c39eeecbb Improved cross repos diffs - added logging - fixed branch issues and empty bundle case diff --git a/rhodecode/controllers/compare.py b/rhodecode/controllers/compare.py --- a/rhodecode/controllers/compare.py +++ b/rhodecode/controllers/compare.py @@ -58,7 +58,7 @@ class CompareController(BaseRepoControll :param ref: ... :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() diff --git a/rhodecode/lib/diffs.py b/rhodecode/lib/diffs.py --- a/rhodecode/lib/diffs.py +++ b/rhodecode/lib/diffs.py @@ -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)) diff --git a/rhodecode/templates/branches/branches.html b/rhodecode/templates/branches/branches.html --- a/rhodecode/templates/branches/branches.html +++ b/rhodecode/templates/branches/branches.html @@ -25,7 +25,9 @@ ${self.breadcrumbs()} + %if c.repo_branches: + %endif
<%include file='branches_data.html'/>
diff --git a/rhodecode/templates/compare/compare_diff.html b/rhodecode/templates/compare/compare_diff.html --- a/rhodecode/templates/compare/compare_diff.html +++ b/rhodecode/templates/compare/compare_diff.html @@ -26,9 +26,9 @@
-

${_('Compare View')} swap

+

${_('Compare View')}

- ${'%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)} [swap]