Patchwork [6,of,6] destutil: document various failure cases

login
register
mail settings
Submitter Pierre-Yves David
Date Feb. 12, 2016, 2:29 p.m.
Message ID <317b33553ba406d35fec.1455287349@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/13135/
State Accepted
Headers show

Comments

Pierre-Yves David - Feb. 12, 2016, 2:29 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@fb.com>
# Date 1454949272 -3600
#      Mon Feb 08 17:34:32 2016 +0100
# Node ID 317b33553ba406d35fec8d8b1045a14c6ccad7bf
# Parent  ac9aa93761f3949cb060b94cbbc62925ffc33427
# EXP-Topic destination
# Available At http://hg.netv6.net/marmoute-wip/mercurial/
#              hg pull http://hg.netv6.net/marmoute-wip/mercurial/ -r 317b33553ba4
destutil: document various failure cases

We document what various conditional branch mean and clarify that they are
exclusive (since they all end up in with exception raised).
Martin von Zweigbergk - Feb. 12, 2016, 9:25 p.m.
Pushed to the clowncopter, thanks!

Patch

diff --git a/mercurial/destutil.py b/mercurial/destutil.py
--- a/mercurial/destutil.py
+++ b/mercurial/destutil.py
@@ -197,32 +197,41 @@  def _destmergebranch(repo):
     branch = repo.dirstate.branch()
     bheads = repo.branchheads(branch)
     nbhs = [bh for bh in bheads if not repo[bh].bookmarks()]
 
     if parent not in bheads:
+        # Case A: working copy if not on a head.
+        #
+        # This is probably a user mistake We bailout pointing at 'hg update'
         if len(repo.heads()) <= 1:
             msg, hint = msgdestmerge['nootherheadsbehind']
         else:
             msg, hint = msgdestmerge['notatheads']
         raise error.Abort(msg, hint=hint)
-
-    if len(nbhs) > 2:
+    elif len(nbhs) > 2:
+        # Case B: There is more than 2 anonymous heads
+        #
+        # This means that there will be more than 1 candidant. This is
+        # ambigious we abort asking the user to pick as explicite destination
+        # instead.
         msg, hint = msgdestmerge['toomanyheads']
         msg %= (branch, len(bheads))
         raise error.Abort(msg, hint=hint)
-
-    if len(nbhs) <= 1:
+    elif len(nbhs) <= 1:
+        # Case B: There is no other anonymous head that the one we are one
+        #
+        # This means that there is not natural candidate to merge with.
+        # We abort, with various messages for various cases.
         if len(bheads) > 1:
             msg, hint = msgdestmerge['bookmarkedheads']
         elif len(repo.heads()) > 1:
             msg, hint = msgdestmerge['nootherbranchheads']
             msg %= branch
         else:
             msg, hint = msgdestmerge['nootherheads']
         raise error.Abort(msg, hint=hint)
-
-    if parent == nbhs[0]:
+    elif parent == nbhs[0]:
         node = nbhs[-1]
     else:
         node = nbhs[0]
     assert node is not None
     return node