parents: add a utility to filter parents
authorPierre-Yves David <pierre-yves.david@octobus.net>
Mon, 18 Dec 2017 06:48:49 +0100
changeset 3309 09db38b34cb9
parent 3308 65af5f9f232b
child 3310 87cb2635352b
parents: add a utility to filter parents There is various strange case of merge out there that needs to be handled. We add an utility function to handle them all.
hgext3rd/evolve/utility.py
--- a/hgext3rd/evolve/utility.py	Mon Dec 18 01:53:20 2017 +0100
+++ b/hgext3rd/evolve/utility.py	Mon Dec 18 06:48:49 2017 +0100
@@ -5,6 +5,8 @@
 # This software may be used and distributed according to the terms of the
 # GNU General Public License version 2 or any later version.
 
+from mercurial.node import nullrev
+
 shorttemplate = "[{label('evolve.rev', rev)}] {desc|firstline}\n"
 
 def obsexcmsg(ui, message, important=False):
@@ -20,3 +22,17 @@
     if ui.configbool('experimental', 'verbose-obsolescence-exchange', False):
         topic = 'OBSEXC'
     ui.progress(topic, *args, **kwargs)
+
+def filterparents(parents):
+    """filter nullrev parents
+
+    (and other crazyness)"""
+    p1, p2 = parents
+    if p1 == nullrev and p2 == nullrev:
+        return ()
+    elif p1 != nullrev and (p2 == nullrev or p1 == p2):
+        return (p1,)
+    elif p1 == nullrev and p2 != nullrev:
+        return (p2,)
+    else:
+        return parents