##// END OF EJS Templates
merge: move default destination computation in a revset...
Pierre-Yves David -
r26303:c99b4d6e default
parent child Browse files
Show More
@@ -4768,58 +4768,8 b' def merge(ui, repo, node=None, **opts):'
4768 4768 if node:
4769 4769 node = scmutil.revsingle(repo, node).node()
4770 4770
4771 if not node and repo._activebookmark:
4772 bmheads = repo.bookmarkheads(repo._activebookmark)
4773 curhead = repo[repo._activebookmark].node()
4774 if len(bmheads) == 2:
4775 if curhead == bmheads[0]:
4776 node = bmheads[1]
4777 else:
4778 node = bmheads[0]
4779 elif len(bmheads) > 2:
4780 raise util.Abort(_("multiple matching bookmarks to merge - "
4781 "please merge with an explicit rev or bookmark"),
4782 hint=_("run 'hg heads' to see all heads"))
4783 elif len(bmheads) <= 1:
4784 raise util.Abort(_("no matching bookmark to merge - "
4785 "please merge with an explicit rev or bookmark"),
4786 hint=_("run 'hg heads' to see all heads"))
4787
4788 elif not node:
4789 branch = repo[None].branch()
4790 bheads = repo.branchheads(branch)
4791 nbhs = [bh for bh in bheads if not repo[bh].bookmarks()]
4792
4793 if len(nbhs) > 2:
4794 raise util.Abort(_("branch '%s' has %d heads - "
4795 "please merge with an explicit rev")
4796 % (branch, len(bheads)),
4797 hint=_("run 'hg heads .' to see heads"))
4798
4799 parent = repo.dirstate.p1()
4800 if len(nbhs) <= 1:
4801 if len(bheads) > 1:
4802 raise util.Abort(_("heads are bookmarked - "
4803 "please merge with an explicit rev"),
4804 hint=_("run 'hg heads' to see all heads"))
4805 if len(repo.heads()) > 1:
4806 raise util.Abort(_("branch '%s' has one head - "
4807 "please merge with an explicit rev")
4808 % branch,
4809 hint=_("run 'hg heads' to see all heads"))
4810 msg, hint = _('nothing to merge'), None
4811 if parent != repo.lookup(branch):
4812 hint = _("use 'hg update' instead")
4813 raise util.Abort(msg, hint=hint)
4814
4815 if parent not in bheads:
4816 raise util.Abort(_('working directory not at a head revision'),
4817 hint=_("use 'hg update' or merge with an "
4818 "explicit revision"))
4819 if parent == nbhs[0]:
4820 node = nbhs[-1]
4821 else:
4822 node = nbhs[0]
4771 if not node:
4772 node = scmutil.revsingle(repo, '_mergedefaultdest()').node()
4823 4773
4824 4774 if opts.get('preview'):
4825 4775 # find nodes that are ancestors of p2 but not of p1
@@ -463,6 +463,67 b' def func(repo, subset, a, b):'
463 463
464 464 # functions
465 465
466 def _mergedefaultdest(repo, subset, x):
467 # ``_mergedefaultdest()``
468
469 # default destination for merge.
470 # # XXX: Currently private because I expect the signature to change.
471 # # XXX: - taking rev as arguments,
472 # # XXX: - bailing out in case of ambiguity vs returning all data.
473 getargs(x, 0, 0, _("_mergedefaultdest takes no arguments"))
474 if repo._activebookmark:
475 bmheads = repo.bookmarkheads(repo._activebookmark)
476 curhead = repo[repo._activebookmark].node()
477 if len(bmheads) == 2:
478 if curhead == bmheads[0]:
479 node = bmheads[1]
480 else:
481 node = bmheads[0]
482 elif len(bmheads) > 2:
483 raise util.Abort(_("multiple matching bookmarks to merge - "
484 "please merge with an explicit rev or bookmark"),
485 hint=_("run 'hg heads' to see all heads"))
486 elif len(bmheads) <= 1:
487 raise util.Abort(_("no matching bookmark to merge - "
488 "please merge with an explicit rev or bookmark"),
489 hint=_("run 'hg heads' to see all heads"))
490 else:
491 branch = repo[None].branch()
492 bheads = repo.branchheads(branch)
493 nbhs = [bh for bh in bheads if not repo[bh].bookmarks()]
494
495 if len(nbhs) > 2:
496 raise util.Abort(_("branch '%s' has %d heads - "
497 "please merge with an explicit rev")
498 % (branch, len(bheads)),
499 hint=_("run 'hg heads .' to see heads"))
500
501 parent = repo.dirstate.p1()
502 if len(nbhs) <= 1:
503 if len(bheads) > 1:
504 raise util.Abort(_("heads are bookmarked - "
505 "please merge with an explicit rev"),
506 hint=_("run 'hg heads' to see all heads"))
507 if len(repo.heads()) > 1:
508 raise util.Abort(_("branch '%s' has one head - "
509 "please merge with an explicit rev")
510 % branch,
511 hint=_("run 'hg heads' to see all heads"))
512 msg, hint = _('nothing to merge'), None
513 if parent != repo.lookup(branch):
514 hint = _("use 'hg update' instead")
515 raise util.Abort(msg, hint=hint)
516
517 if parent not in bheads:
518 raise util.Abort(_('working directory not at a head revision'),
519 hint=_("use 'hg update' or merge with an "
520 "explicit revision"))
521 if parent == nbhs[0]:
522 node = nbhs[-1]
523 else:
524 node = nbhs[0]
525 return subset & baseset([repo[node].rev()])
526
466 527 def adds(repo, subset, x):
467 528 """``adds(pattern)``
468 529 Changesets that add a file matching pattern.
@@ -2100,6 +2161,7 b' def _hexlist(repo, subset, x):'
2100 2161 return baseset([r for r in ls if r in s])
2101 2162
2102 2163 symbols = {
2164 "_mergedefaultdest": _mergedefaultdest,
2103 2165 "adds": adds,
2104 2166 "all": getall,
2105 2167 "ancestor": ancestor,
General Comments 0
You need to be logged in to leave comments. Login now