rebase: refactor of error handling code path for rebaseskipobsolete
authorLaurent Charignon <lcharignon@fb.com>
Tue, 29 Mar 2016 11:49:45 -0700
changeset 28685 6c4d23fe611c
parent 28684 1ace17e1e160
child 28686 b212e01fead0
rebase: refactor of error handling code path for rebaseskipobsolete This patch extracts the error handling code path to go in a separate function. In the next patch we will able to reuse this logic and avoid duplicated code.
hgext/rebase.py
--- a/hgext/rebase.py	Tue Mar 29 23:59:32 2016 +0900
+++ b/hgext/rebase.py	Tue Mar 29 11:49:45 2016 -0700
@@ -305,31 +305,9 @@
                                                                 rebaseobsrevs,
                                                                 dest)
                 rebaseobsskipped = set(obsoletenotrebased)
-
-                # Obsolete node with successors not in dest leads to divergence
-                divergenceok = ui.configbool('experimental',
-                                             'allowdivergence')
-                divergencebasecandidates = rebaseobsrevs - rebaseobsskipped
-
-                if divergencebasecandidates and not divergenceok:
-                    divhashes = (str(repo[r])
-                                 for r in divergencebasecandidates)
-                    msg = _("this rebase will cause "
-                            "divergences from: %s")
-                    h = _("to force the rebase please set "
-                          "experimental.allowdivergence=True")
-                    raise error.Abort(msg % (",".join(divhashes),), hint=h)
-
-                # - plain prune (no successor) changesets are rebased
-                # - split changesets are not rebased if at least one of the
-                # changeset resulting from the split is an ancestor of dest
-                rebaseset = rebasesetrevs - rebaseobsskipped
-                if rebasesetrevs and not rebaseset:
-                    msg = _('all requested changesets have equivalents '
-                            'or were marked as obsolete')
-                    hint = _('to force the rebase, set the config '
-                             'experimental.rebaseskipobsolete to False')
-                    raise error.Abort(msg, hint=hint)
+                _checkobsrebase(repo, ui, rebaseobsrevs,
+                                              rebasesetrevs,
+                                              rebaseobsskipped)
 
             result = buildstate(repo, dest, rebaseset, collapsef,
                                 obsoletenotrebased)
@@ -709,6 +687,43 @@
     else:
         return None
 
+def _checkobsrebase(repo, ui,
+                                  rebaseobsrevs,
+                                  rebasesetrevs,
+                                  rebaseobsskipped):
+    """
+    Abort if rebase will create divergence or rebase is noop because of markers
+
+    `rebaseobsrevs`: set of obsolete revision in source
+    `rebasesetrevs`: set of revisions to be rebased from source
+    `rebaseobsskipped`: set of revisions from source skipped because they have
+    successors in destination
+    """
+    # Obsolete node with successors not in dest leads to divergence
+    divergenceok = ui.configbool('experimental',
+                                 'allowdivergence')
+    divergencebasecandidates = rebaseobsrevs - rebaseobsskipped
+
+    if divergencebasecandidates and not divergenceok:
+        divhashes = (str(repo[r])
+                     for r in divergencebasecandidates)
+        msg = _("this rebase will cause "
+                "divergences from: %s")
+        h = _("to force the rebase please set "
+              "experimental.allowdivergence=True")
+        raise error.Abort(msg % (",".join(divhashes),), hint=h)
+
+    # - plain prune (no successor) changesets are rebased
+    # - split changesets are not rebased if at least one of the
+    # changeset resulting from the split is an ancestor of dest
+    rebaseset = rebasesetrevs - rebaseobsskipped
+    if rebasesetrevs and not rebaseset:
+        msg = _('all requested changesets have equivalents '
+                'or were marked as obsolete')
+        hint = _('to force the rebase, set the config '
+                 'experimental.rebaseskipobsolete to False')
+        raise error.Abort(msg, hint=hint)
+
 def defineparents(repo, rev, target, state, targetancestors):
     'Return the new parent relationship of the revision that will be rebased'
     parents = repo[rev].parents()