# HG changeset patch # User Pierre-Yves David # Date 1444867860 -3600 # Node ID 9903261dcc813a78f3304f780577b8624e9275ed # Parent a271925699d66c340ce76f22663f2ece0aaa024a destutil: move default merge destination into a function Function in destutil are much simpler to wrap and more flexible than revset. This also help consistency as 'destupdate' live here and cannot become a pure revset anyway. diff -r a271925699d6 -r 9903261dcc81 mercurial/destutil.py --- a/mercurial/destutil.py Thu Oct 15 01:35:44 2015 +0100 +++ b/mercurial/destutil.py Thu Oct 15 01:11:00 2015 +0100 @@ -91,3 +91,57 @@ raise error.UpdateAbort(msg, hint=hint) return rev, movemark, activemark + +def destmerge(repo): + if repo._activebookmark: + bmheads = repo.bookmarkheads(repo._activebookmark) + curhead = repo[repo._activebookmark].node() + if len(bmheads) == 2: + if curhead == bmheads[0]: + node = bmheads[1] + 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")) + 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")) + else: + branch = repo[None].branch() + bheads = repo.branchheads(branch) + 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")) + + 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") + 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")) + if parent == nbhs[0]: + node = nbhs[-1] + else: + node = nbhs[0] + return repo[node].rev() diff -r a271925699d6 -r 9903261dcc81 mercurial/revset.py --- a/mercurial/revset.py Thu Oct 15 01:35:44 2015 +0100 +++ b/mercurial/revset.py Thu Oct 15 01:11:00 2015 +0100 @@ -477,58 +477,7 @@ # # XXX: - taking rev as arguments, # # XXX: - bailing out in case of ambiguity vs returning all data. getargs(x, 0, 0, _("_mergedefaultdest takes no arguments")) - if repo._activebookmark: - bmheads = repo.bookmarkheads(repo._activebookmark) - curhead = repo[repo._activebookmark].node() - if len(bmheads) == 2: - if curhead == bmheads[0]: - node = bmheads[1] - 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")) - 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")) - else: - branch = repo[None].branch() - bheads = repo.branchheads(branch) - 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")) - - 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") - 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")) - if parent == nbhs[0]: - node = nbhs[-1] - else: - node = nbhs[0] - return subset & baseset([repo[node].rev()]) + return subset & baseset([destutil.destmerge(repo)]) def adds(repo, subset, x): """``adds(pattern)``