# HG changeset patch # User Pierre-Yves David <pierre-yves.david@fb.com> # Date 1444914657 -3600 # Thu Oct 15 14:10:57 2015 +0100 # Node ID 6c22a17faa18ab1236ffb157f7133002aaa09fd0 # Parent 8bed1eae99df802086c81611f77ccd3cfb5eef3f destupdate: extract validation logic One of the main goal of having consolidated destination function is to allow extension to play with this logic. We extract sub logic to make is wrapping more practical. diff --git a/mercurial/destutil.py b/mercurial/destutil.py --- a/mercurial/destutil.py +++ b/mercurial/destutil.py @@ -12,6 +12,34 @@ obsolete, ) +def _destupdatevalidate(repo, rev, clean, check): + """validate that the destination comply to various rules + + This exists as its own function to help wrapping from extensions.""" + wc = repo[None] + p1 = wc.p1() + if not clean: + # Check that the update is linear. + # + # Mercurial do not allow update-merge for non linear pattern + # (that would be technically possible but was considered too confusing + # for user a long time ago) + # + # See mercurial.merge.update for details + if p1.rev() not in repo.changelog.ancestors([rev], inclusive=True): + dirty = wc.dirty(missing=True) + foreground = obsolete.foreground(repo, [p1.node()]) + if not repo[rev].node() in foreground: + if dirty: + msg = _("uncommitted changes") + hint = _("commit and merge, or update --clean to" + " discard changes") + raise error.UpdateAbort(msg, hint=hint) + elif not check: # destination is not a descendant. + msg = _("not a linear update") + hint = _("merge or update --check to force update") + raise error.UpdateAbort(msg, hint=hint) + def destupdate(repo, clean=False, check=False): """destination for bare update operation @@ -68,27 +96,7 @@ node = repo.revs('max(%ln)', successors).first() rev = repo[node].rev() - if not clean: - # Check that the update is linear. - # - # Mercurial do not allow update-merge for non linear pattern - # (that would be technically possible but was considered too confusing - # for user a long time ago) - # - # See mercurial.merge.update for details - if p1.rev() not in repo.changelog.ancestors([rev], inclusive=True): - dirty = wc.dirty(missing=True) - foreground = obsolete.foreground(repo, [p1.node()]) - if not repo[rev].node() in foreground: - if dirty: - msg = _("uncommitted changes") - hint = _("commit and merge, or update --clean to" - " discard changes") - raise error.UpdateAbort(msg, hint=hint) - elif not check: # destination is not a descendant. - msg = _("not a linear update") - hint = _("merge or update --check to force update") - raise error.UpdateAbort(msg, hint=hint) + _destupdatevalidate(repo, rev, clean, check) return rev, movemark, activemark