diff --git a/rhodecode/controllers/compare.py b/rhodecode/controllers/compare.py --- a/rhodecode/controllers/compare.py +++ b/rhodecode/controllers/compare.py @@ -26,12 +26,15 @@ import logging import traceback +from webob.exc import HTTPNotFound from pylons import request, response, session, tmpl_context as c, url from pylons.controllers.util import abort, redirect from rhodecode.lib.base import BaseRepoController, render from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator -from webob.exc import HTTPNotFound +from rhodecode.lib import diffs + +from rhodecode.model.db import Repository log = logging.getLogger(__name__) @@ -47,7 +50,8 @@ class CompareController(BaseRepoControll def _handle_ref(self, ref): """ Parse the org...other string - Possible formats are `(branch|book|tag):...(branch|book|tag):` + Possible formats are + `(branch|book|tag):...(branch|book|tag):` :param ref: ... :type ref: str @@ -64,7 +68,8 @@ class CompareController(BaseRepoControll _repo = org_repo name, val = other.split(':') if _other_repo: - _repo = _other_repo #TODO: do an actual repo loookup within rhodecode + #TODO: do an actual repo loookup within rhodecode + _repo = _other_repo return _repo, (name, val) @@ -79,17 +84,47 @@ class CompareController(BaseRepoControll raise HTTPNotFound + def _get_changesets(self, org_repo, org_ref, other_repo, other_ref): + changesets = [] + #case two independent repos + if org_repo != other_repo: + from mercurial import discovery + import binascii + out = discovery.findcommonoutgoing(org_repo._repo, other_repo._repo) + for cs in map(binascii.hexlify, out.missing): + changesets.append(org_repo.get_changeset(cs)) + else: + for cs in map(binascii.hexlify, out): + changesets.append(org_repo.get_changeset(cs)) + + return changesets + def index(self, ref): - org_repo, org_ref, other_repo, other_ref = self._handle_ref(ref) - return ''' -
-        REPO: %s 
-        REF: %s 
+
+        c.org_repo = org_repo = Repository.get_by_repo_name(org_repo)
+        c.other_repo = other_repo = Repository.get_by_repo_name(other_repo)
+
+        c.cs_ranges = self._get_changesets(org_repo.scm_instance,
+                                           org_ref,
+                                           other_repo.scm_instance,
+                                           other_ref)
+
+        c.org_ref = org_ref[1]
+        c.other_ref = other_ref[1]
+        cs1 = org_repo.scm_instance.get_changeset(org_ref[1])
+        cs2 = other_repo.scm_instance.get_changeset(other_ref[1])
+
+        _diff = diffs.differ(org_repo, org_ref, other_repo, other_ref)
+        diff_processor = diffs.DiffProcessor(_diff, format='gitdiff')
+
+        diff = diff_processor.as_html(enable_comments=False)
+        stats = diff_processor.stat()
+
+        c.changes = [('change?', None, diff, cs1, cs2, stats,)]
+
+        return render('compare/compare_diff.html')
+
+
+
         
-        vs 
-        
-        REPO: %s 
-        REF: %s        
-        
- ''' % (org_repo, org_ref, other_repo, other_ref) diff --git a/rhodecode/lib/diffs.py b/rhodecode/lib/diffs.py --- a/rhodecode/lib/diffs.py +++ b/rhodecode/lib/diffs.py @@ -522,3 +522,32 @@ class DiffProcessor(object): 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): + """ + + :param org_repo: + :type org_repo: + :param org_ref: + :type org_ref: + :param other_repo: + :type other_repo: + :param other_ref: + :type other_ref: + """ + ignore_whitespace = False + context = 3 + from mercurial import patch + from mercurial.mdiff import diffopts + + org_repo = org_repo.scm_instance._repo + other_repo = other_repo.scm_instance._repo + + org_ref = org_ref[1] + other_ref = other_ref[1] + + opts = diffopts(git=True, ignorews=ignore_whitespace, context=context) + + return ''.join(patch.diff(org_repo, node1=org_ref, node2=other_ref, + opts=opts)) diff --git a/rhodecode/templates/compare/compare_diff.html b/rhodecode/templates/compare/compare_diff.html new file mode 100644 --- /dev/null +++ b/rhodecode/templates/compare/compare_diff.html @@ -0,0 +1,82 @@ +## -*- coding: utf-8 -*- +<%inherit file="/base/base.html"/> + +<%def name="title()"> + TODO FIll this in + + +<%def name="breadcrumbs_links()"> + ${h.link_to(u'Home',h.url('/'))} + » + ${h.link_to(c.repo_name,h.url('summary_home',repo_name=c.repo_name))} + » + TODO! + + +<%def name="page_nav()"> + ${self.menu('changelog')} + + +<%def name="main()"> +
+ +
+ ${self.breadcrumbs()} +
+
+
+
+

${_('Compare View')}

+
+ ${'%s@%s' % (c.org_repo.repo_name, c.org_ref)} -> ${'%s@%s' % (c.other_repo.repo_name, c.other_ref)} +
+
+
+
+
+ + %for cnt,cs in enumerate(c.cs_ranges): + + + + + + + + + %endfor +
gravatar
${h.link_to('r%s:%s' % (cs.revision,h.short_id(cs.raw_id)),h.url('changeset_home',repo_name=c.repo_name,revision=cs.raw_id))}
${h.person(cs.author)}
${cs.date} + %if hasattr(c,'statuses') and c.statuses: +
+ %endif +
${h.urlify_commit(h.wrap_paragraphs(cs.message),c.repo_name)}
+
+
${_('Files affected')}
+
+ %for change,filenode,diff,cs1,cs2,st in c.changes[cs.raw_id]: +
${h.link_to(h.safe_unicode(filenode.path),h.url.current(anchor=h.FID(cs.raw_id,filenode.path)))}
+ %endfor +
+
+ +
+ + +
+