changeset 4559:f4c60fafac54

compare: workaround unexpected Mercurial behaviour when finding ancestor of null rev ancestor(id(0000000000000000000000000000000000000000),7) == 7 - that caused weird pull request diffs and lots of grief when (accidentally) creating a pull request from the null revision. Add special handling for the case of null revisions.
author Mads Kiilerich <madski@unity3d.com>
date Fri, 03 Oct 2014 00:20:36 +0200
parents 18f6bdd1e3fc
children b1679034b6c4
files kallithea/controllers/compare.py
diffstat 1 files changed, 8 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/controllers/compare.py	Fri Oct 03 00:20:36 2014 +0200
+++ b/kallithea/controllers/compare.py	Fri Oct 03 00:20:36 2014 +0200
@@ -88,10 +88,14 @@
             else:
                 hgrepo = other_repo._repo
 
-            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()
+            if org_repo.EMPTY_CHANGESET in (org_rev, other_rev):
+                # work around unexpected Mercurial behaviour
+                ancestor = org_repo.EMPTY_CHANGESET
+            else:
+                ancestors = hgrepo.revs("ancestor(id(%s), id(%s))", org_rev, other_rev)
+                if ancestors:
+                    # FIXME: picks arbitrary ancestor - but there is usually only one
+                    ancestor = hgrepo[ancestors[0]].hex()
 
             other_revs = hgrepo.revs("ancestors(id(%s)) and not ancestors(id(%s)) and not id(%s)",
                                      other_rev, org_rev, org_rev)