# HG changeset patch # User Mads Kiilerich # Date 2014-10-03 00:20:36 # Node ID f4c60fafac5413c44cafab386000ca7456309aca # Parent 18f6bdd1e3fc81972eb52398a295921380a98271 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. diff --git a/kallithea/controllers/compare.py b/kallithea/controllers/compare.py --- a/kallithea/controllers/compare.py +++ b/kallithea/controllers/compare.py @@ -88,10 +88,14 @@ class CompareController(BaseRepoControll 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)