[PATCH V2] rebase: do not raise an UnboundLocalError when called with wrong rev (issue4106)

Simon Heimberg simohe at besonet.ch
Wed Feb 19 04:55:41 CST 2014

# HG changeset patch
# User Simon Heimberg <simohe at besonet.ch>
# Date 1392334460 -3600
#      Fri Feb 14 00:34:20 2014 +0100
# Node ID 2554f90793b6645be68348729bedda8f695b979f
# Parent  0e2877f8605dcaf4fdf2ab7e0046f1f6f80161dd
rebase: do not raise an UnboundLocalError when called with wrong rev (issue4106)

When the base is not found, we should not raise a traceback about a not defined
variable. This hides the real problem. The function rebasenode was probaly
called with wrong revisions.

An AssertionError is raised to highlight that the caller of the function did
something wrong.
An alternative approach is to assign None to the variable "base" and let the
merge mechanism raise an abort message. This was the behavior for this case
before ad9db007656f. But the only known case for this problem is when an
extension calls this function wrong. An AssertionError makes this clearer than
an abort message. When a different case is detected, the behaviour can be
improved then.

diff -r 0e2877f8605d -r 2554f90793b6 hgext/rebase.py
--- a/hgext/rebase.py	Sat Feb 15 22:09:32 2014 -0600
+++ b/hgext/rebase.py	Fri Feb 14 00:34:20 2014 +0100
@@ -513,6 +513,11 @@
             if state.get(p.rev()) == repo[p1].rev():
                 base = p.node()
+        else:
+            # fallback when base not found (unnormal, see issue 4106)
+            #
+            # Raise because this function is (probaby) called wrong
+            raise AssertionError('function is called wrong')
     if base is not None:
         repo.ui.debug("   detach base %d:%s\n" % (repo[base].rev(), repo[base]))
     # When collapsing in-place, the parent is the common ancestor, we

More information about the Mercurial-devel mailing list