changeset 4296:fa4ef7f0f440

compare: calculate changesets and calculate and show ancestor also for non-merge diffs
author Mads Kiilerich <madski@unity3d.com>
date Fri, 28 Jun 2013 11:50:13 +0200
parents 20f051c5d814
children 7a5977429125
files kallithea/controllers/compare.py kallithea/templates/compare/compare_cs.html
diffstat 2 files changed, 16 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/controllers/compare.py	Fri Jul 18 18:44:54 2014 +0200
+++ b/kallithea/controllers/compare.py	Fri Jun 28 11:50:13 2013 +0200
@@ -98,7 +98,7 @@
                 redirect(h.url('summary_home', repo_name=repo.repo_name))
             raise HTTPBadRequest()
 
-    def _get_changesets(self, alias, org_repo, org_rev, other_repo, other_rev, merge):
+    def _get_changesets(self, alias, org_repo, org_rev, other_repo, other_rev):
         """
         Returns a list of changesets that can be merged from org_repo at org_rev
         to other_repo at other_rev ... and the ancestor that would be used for merge.
@@ -108,13 +108,11 @@
         :param other_repo: repo object, mostl likely the fork of org_repo. It hass
             all changesets that we need to obtain
         :param other_rev: revision we want out compare to be made on other_repo
-
         """
         ancestor = None
         if org_rev == other_rev:
             changesets = []
-            if merge:
-                ancestor = org_rev
+            ancestor = org_rev
 
         elif alias == 'hg':
             #case two independent repos
@@ -129,20 +127,14 @@
             else:
                 hgrepo = other_repo._repo
 
-            if merge:
-                revs = hgrepo.revs(
-                    "ancestors(id(%s)) and not ancestors(id(%s)) and not id(%s)",
-                    other_rev, org_rev, org_rev)
+            ancestors = hgrepo.revs("ancestor(id(%s), id(%s))", org_rev, other_rev)
+            if ancestors:
+                # pick arbitrary ancestor - but there is usually only one
+                ancestor = hgrepo[ancestors[0]].hex()
 
-                ancestors = hgrepo.revs("ancestor(id(%s), id(%s))", org_rev,
-                                        other_rev)
-                if ancestors:
-                    # pick arbitrary ancestor - but there is usually only one
-                    ancestor = hgrepo[ancestors[0]].hex()
-            else:
-                # TODO: have both + and - changesets
-                revs = hgrepo.revs("id(%s) :: id(%s) - id(%s)",
-                                   org_rev, other_rev, org_rev)
+            # TODO: have both + and - changesets
+            revs = hgrepo.revs("ancestors(id(%s)) and not ancestors(id(%s)) and not id(%s)",
+                               other_rev, org_rev, org_rev)
 
             changesets = [other_repo.get_changeset(rev) for rev in revs]
 
@@ -261,14 +253,13 @@
 
         c.cs_ranges, c.ancestor = self._get_changesets(
             org_repo.scm_instance.alias, org_repo.scm_instance, c.org_rev,
-            other_repo.scm_instance, c.other_rev, merge)
+            other_repo.scm_instance, c.other_rev)
         c.statuses = c.db_repo.statuses(
             [x.raw_id for x in c.cs_ranges])
 
         if partial:
             return render('compare/compare_cs.html')
-        if c.ancestor:
-            assert merge
+        if merge and c.ancestor:
             # 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_rev)
--- a/kallithea/templates/compare/compare_cs.html	Fri Jul 18 18:44:54 2014 +0200
+++ b/kallithea/templates/compare/compare_cs.html	Fri Jun 28 11:50:13 2013 +0200
@@ -40,6 +40,11 @@
         </tr>
     %endfor
     </table>
+    %if c.ancestor:
+      <div class="ancestor">${_('Ancestor')}:
+        ${h.link_to(h.short_id(c.ancestor),h.url('changeset_home',repo_name=c.repo_name,revision=c.ancestor))}
+      </div>
+    %endif
     %if c.as_form:
       ${h.hidden('ancestor_rev',c.ancestor)}
       ${h.hidden('merge_rev',c.cs_ranges[-1].raw_id)}