# HG changeset patch # User Pierre-Yves David # Date 2016-02-09 21:14:37 # Node ID bd74b5e0d2c08a5b775dffa8a4d6160578c2d724 # Parent 79437fb352cec90a5d779e208c0f5ef1df160653 destutil: extract all 'mergedest' abort messages into a dictionary We plan to be able to reuse this function for rebase. The error message explicitly refers to "merge" in multiple places. So we'll need to be able to use different messages. The first step of that is to extract all messages in a dedicated dictionary and use them indirectly. As a side effect it clarifies the actual function and opens the way to various cleanups and fixes in future changesets. diff --git a/mercurial/destutil.py b/mercurial/destutil.py --- a/mercurial/destutil.py +++ b/mercurial/destutil.py @@ -134,6 +134,43 @@ def destupdate(repo, clean=False, check= return rev, movemark, activemark +msgdestmerge = { + # too many matching divergent bookmark + 'toomanybookmarks': + (_("multiple matching bookmarks to merge -" + " please merge with an explicit rev or bookmark"), + _("run 'hg heads' to see all heads")), + # no other matching divergent bookmark + 'nootherbookmarks': + (_("no matching bookmark to merge - " + "please merge with an explicit rev or bookmark"), + _("run 'hg heads' to see all heads")), + # branch have too many unbookmarked heads, no obvious destination + 'toomanyheads': + (_("branch '%s' has %d heads - please merge with an explicit rev"), + _("run 'hg heads .' to see heads")), + # branch have no other unbookmarked heads + 'bookmarkedheads': + (_("heads are bookmarked - please merge with an explicit rev"), + _("run 'hg heads' to see all heads")), + # branch have just a single heads, but there is other branches + 'nootherbranchheads': + (_("branch '%s' has one head - please merge with an explicit rev"), + _("run 'hg heads' to see all heads")), + # repository have a single head + 'nootherheads': + (_('nothing to merge'), + None), + # repository have a single head and we are not on it + 'nootherheadsbehind': + (_('nothing to merge'), + _("use 'hg update' instead")), + # We are not on a head + 'notatheads': + (_('working directory not at a head revision'), + _("use 'hg update' or merge with an explicit revision")) + } + def _destmergebook(repo): """find merge destination in the active bookmark case""" node = None @@ -145,13 +182,11 @@ def _destmergebook(repo): else: node = bmheads[0] elif len(bmheads) > 2: - raise error.Abort(_("multiple matching bookmarks to merge - " - "please merge with an explicit rev or bookmark"), - hint=_("run 'hg heads' to see all heads")) + msg, hint = msgdestmerge['toomanybookmarks'] + raise error.Abort(msg, hint=hint) elif len(bmheads) <= 1: - raise error.Abort(_("no matching bookmark to merge - " - "please merge with an explicit rev or bookmark"), - hint=_("run 'hg heads' to see all heads")) + msg, hint = msgdestmerge['nootherbookmarks'] + raise error.Abort(msg, hint=hint) assert node is not None return node @@ -163,31 +198,26 @@ def _destmergebranch(repo): nbhs = [bh for bh in bheads if not repo[bh].bookmarks()] if len(nbhs) > 2: - raise error.Abort(_("branch '%s' has %d heads - " - "please merge with an explicit rev") - % (branch, len(bheads)), - hint=_("run 'hg heads .' to see heads")) + msg, hint = msgdestmerge['toomanyheads'] + msg %= (branch, len(bheads)) + raise error.Abort(msg, hint=hint) parent = repo.dirstate.p1() if len(nbhs) <= 1: if len(bheads) > 1: - raise error.Abort(_("heads are bookmarked - " - "please merge with an explicit rev"), - hint=_("run 'hg heads' to see all heads")) - if len(repo.heads()) > 1: - raise error.Abort(_("branch '%s' has one head - " - "please merge with an explicit rev") - % branch, - hint=_("run 'hg heads' to see all heads")) - msg, hint = _('nothing to merge'), None - if parent != repo.lookup(branch): - hint = _("use 'hg update' instead") + msg, hint = msgdestmerge['bookmarkedheads'] + elif len(repo.heads()) > 1: + msg, hint = msgdestmerge['nootherbranchheads'] + msg %= branch + elif parent != repo.lookup(branch): + msg, hint = msgdestmerge['nootherheadsbehind'] + else: + msg, hint = msgdestmerge['nootherheads'] raise error.Abort(msg, hint=hint) if parent not in bheads: - raise error.Abort(_('working directory not at a head revision'), - hint=_("use 'hg update' or merge with an " - "explicit revision")) + msg, hint = msgdestmerge['notatheads'] + raise error.Abort(msg, hint=hint) if parent == nbhs[0]: node = nbhs[-1] else: