diff rhodecode/model/pull_request.py @ 3486:2053053e0882 beta

compare/pullrequest: introduce merge parameter This is more correct and flexible than the old way of looking on same/different repo.
author Mads Kiilerich <madski@unity3d.com>
date Tue, 05 Mar 2013 11:55:01 +0100
parents 3ac76dfdab8e
children 5dcfa6304f88
line wrap: on
line diff
--- a/rhodecode/model/pull_request.py	Fri Mar 01 17:16:24 2013 +0100
+++ b/rhodecode/model/pull_request.py	Tue Mar 05 11:55:01 2013 +0100
@@ -161,7 +161,7 @@
         pull_request.updated_on = datetime.datetime.now()
         Session().add(pull_request)
 
-    def _get_changesets(self, alias, org_repo, org_ref, other_repo, other_ref):
+    def _get_changesets(self, alias, org_repo, org_ref, other_repo, other_ref, merge):
         """
         Returns a list of changesets that can be merged from org_repo@org_ref
         to other_repo@other_ref ... and the ancestor that would be used for merge
@@ -211,16 +211,21 @@
             else:
                 hgrepo = other_repo._repo
 
-            revs = ["ancestors(id('%s')) and not ancestors(id('%s'))" %
-                    (other_rev, org_rev)]
-            changesets = [other_repo.get_changeset(cs)
-                          for cs in scmutil.revrange(hgrepo, revs)]
+            if merge:
+                revs = ["ancestors(id('%s')) and not ancestors(id('%s')) and not id('%s')" %
+                        (other_rev, org_rev, org_rev)]
 
-            if org_repo != other_repo:
                 ancestors = scmutil.revrange(hgrepo,
                      ["ancestor(id('%s'), id('%s'))" % (org_rev, other_rev)])
                 if len(ancestors) == 1:
                     ancestor = hgrepo[ancestors[0]].hex()
+            else:
+                # TODO: have both + and - changesets
+                revs = ["id('%s') :: id('%s') - id('%s')" %
+                        (org_rev, other_rev, org_rev)]
+
+            changesets = [other_repo.get_changeset(cs)
+                          for cs in scmutil.revrange(hgrepo, revs)]
 
         elif alias == 'git':
             assert org_repo == other_repo, (org_repo, other_repo) # no git support for different repos
@@ -233,7 +238,7 @@
 
         return changesets, ancestor
 
-    def get_compare_data(self, org_repo, org_ref, other_repo, other_ref):
+    def get_compare_data(self, org_repo, org_ref, other_repo, other_ref, merge):
         """
         Returns incoming changesets for mercurial repositories
 
@@ -251,5 +256,6 @@
 
         cs_ranges, ancestor = self._get_changesets(org_repo.scm_instance.alias,
                                                    org_repo.scm_instance, org_ref,
-                                                   other_repo.scm_instance, other_ref)
+                                                   other_repo.scm_instance, other_ref,
+                                                   merge)
         return cs_ranges, ancestor