diff hgext3rd/evolve/evolvecmd.py @ 3805:2410e7063692

evolve: implement resolution of content-divergence when on differet parents This patch implements the basic version of resolution of content-divergence changesets when they are on different parents but one of the parent is gca of both the different parents. The functionality first relocates the divergent changeset which was left behind and then resolves the content-divergence like it resolves in normal cases. This is a very basic implementation because it still does not work on interrupted evolution. Test changes in this patch shows the basic functionality working. The output of dry-run is also required to be tweaked in such cased. Upcoming patches will add more tests and will improve the implementation to work during conflicts too.
author Pulkit Goyal <7895pulkit@gmail.com>
date Fri, 01 Jun 2018 19:52:06 +0530
parents 4bad80f1aad3
children 03ccdc753582
line wrap: on
line diff
--- a/hgext3rd/evolve/evolvecmd.py	Fri Jun 01 19:57:19 2018 +0530
+++ b/hgext3rd/evolve/evolvecmd.py	Fri Jun 01 19:52:06 2018 +0530
@@ -376,8 +376,36 @@
         ui.write_err(hint)
         return (False, '')
 
-    # we don't handle content-divergent changesets with different parents yet
-    if other.p1() not in divergent.parents():
+    otherp1 = other.p1().rev()
+    divp1 = divergent.p1().rev()
+    gca = repo.revs("ancestor(%d, %d)" % (otherp1, divp1))
+
+    # is relocation of one of the changeset required
+    relocatereq = False
+
+    # testing how both the divergent changesets are arranged, there can be 4
+    # possible cases here:
+    #
+    # 1) both have the same parents
+    # 2) both have different parents but greatest common anscestor of them is
+    #    parent of one of them
+    # 3) both have different parents and gca is not parent of any of them
+    # 4) one of them is parent of other
+    #
+    # we are handling 1) very good now.
+    # for 2) we will relocate one which is behind to the parent of ahead one and
+    # then solve the content-divergence the way we solve 1)
+    # for 3) and 4), we still have to decide
+    if otherp1 in gca and divp1 in gca:
+        # both are on the same parents
+        pass
+    elif otherp1 in gca and divp1 not in gca:
+        relocatereq = True
+        pass
+    elif divp1 in gca and otherp1 not in gca:
+        relocatereq = True
+        divergent, other = other, divergent
+    else:
         msg = _("skipping %s: have a different parent than %s "
                 "(not handled yet)\n") % (divergent, other)
         hint = _("| %(d)s, %(o)s are not based on the same changeset.\n"
@@ -412,6 +440,15 @@
         ui.write(('hg commit -m "`hg log -r %s --template={desc}`";\n'
                  % divergent))
         return (False, '')
+
+    # relocate the other divergent if required
+    if relocatereq:
+        ui.status(_('rebasing "other" content-divergent changeset %s on'
+                    ' %s\n' % (other, divergent.p1())))
+        newother = relocate(repo, other, divergent.p1(), evolvestate,
+                            keepbranch=True)
+        other = repo[newother]
+
     if divergent not in repo[None].parents():
         repo.ui.status(_("updating to \"local\" side of the conflict: %s\n") %
                        divergent.hex()[:12])