[PATCH 1 of 2 V3] rebase: refactor of error handling code path for rebaseskipobsolete

Laurent Charignon lcharignon at fb.com
Tue Mar 29 14:53:14 EDT 2016


# HG changeset patch
# User Laurent Charignon <lcharignon at fb.com>
# Date 1459277385 25200
#      Tue Mar 29 11:49:45 2016 -0700
# Node ID 6763719b7f4410240a38f84aace80c3e81e9ff4b
# Parent  30863ca01c6b8f519cf1987565eee88734eb03d6
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.

diff --git a/hgext/rebase.py b/hgext/rebase.py
--- a/hgext/rebase.py
+++ b/hgext/rebase.py
@@ -305,31 +305,9 @@ def rebase(ui, repo, **opts):
                                                                 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 @@ def nearestrebased(repo, rev, state):
     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()


More information about the Mercurial-devel mailing list