[PATCH] rebase: split _checkobsrebase into two parts for better wrapping

Kostia Balytskyi ikostia at fb.com
Mon May 30 17:31:20 UTC 2016


# HG changeset patch
# User Kostia Balytskyi <ikostia at fb.com>
# Date 1464629336 -3600
#      Mon May 30 18:28:56 2016 +0100
# Node ID 330fa585c8b9a272f51e6b82a8f65d9b01e0207e
# Parent  318534bb5dfd37b1c95f10ba90b73c5ce562713f
rebase: split _checkobsrebase into two parts for better wrapping

Currently _checkobsrebase does two checks: one aborts if divergence is going
to be caused by the rebase operation (and this can be turned off by a config),
another aborts if all changesets have successors in the destination (and this
cannot be turned off). I have suspicions that some rebase users would like it
not to abort when there's nothing to rebase, but rather to exit with code 0.
Splitting _checkobsrebase is a step in this direction.

This is unrelated to the other refactoring series.

diff --git a/hgext/rebase.py b/hgext/rebase.py
--- a/hgext/rebase.py
+++ b/hgext/rebase.py
@@ -737,6 +737,33 @@
     else:
         return None
 
+def _abortifdivergencecaused(repo, ui, rebaseobsrevs, rebaseobsskipped):
+    """Abort if rebasing will cuase divergence"""
+    # 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)
+
+def _abortifnothingtorebase(repo, ui, rebasesetrevs, rebaseobsskipped):
+    """Abort if every changeset has a successor in the destination"""
+    # - 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 _checkobsrebase(repo, ui,
                                   rebaseobsrevs,
                                   rebasesetrevs,
@@ -749,30 +776,8 @@
     `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)
+    _abortifdivergencecaused(repo, ui, rebaseobsrevs, rebaseobsskipped)
+    _abortifnothingtorebase(repo, ui, rebasesetrevs, rebaseobsskipped)
 
 def defineparents(repo, rev, target, state, targetancestors,
                   obsoletenotrebased):


More information about the Mercurial-devel mailing list