mercurial/revset.py
changeset 26303 c99b4d6efdd8
parent 26232 43f9976346e9
child 26304 bca60842e22d
equal deleted inserted replaced
26302:5ba3358ebc7f 26303:c99b4d6efdd8
   461     syms = [s for (s, fn) in symbols.items() if keep(fn)]
   461     syms = [s for (s, fn) in symbols.items() if keep(fn)]
   462     raise error.UnknownIdentifier(a[1], syms)
   462     raise error.UnknownIdentifier(a[1], syms)
   463 
   463 
   464 # functions
   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 def adds(repo, subset, x):
   527 def adds(repo, subset, x):
   467     """``adds(pattern)``
   528     """``adds(pattern)``
   468     Changesets that add a file matching pattern.
   529     Changesets that add a file matching pattern.
   469 
   530 
   470     The pattern without explicit kind like ``glob:`` is expected to be
   531     The pattern without explicit kind like ``glob:`` is expected to be
  2098     ls = [cl.rev(node.bin(r)) for r in s.split('\0')]
  2159     ls = [cl.rev(node.bin(r)) for r in s.split('\0')]
  2099     s = subset
  2160     s = subset
  2100     return baseset([r for r in ls if r in s])
  2161     return baseset([r for r in ls if r in s])
  2101 
  2162 
  2102 symbols = {
  2163 symbols = {
       
  2164     "_mergedefaultdest": _mergedefaultdest,
  2103     "adds": adds,
  2165     "adds": adds,
  2104     "all": getall,
  2166     "all": getall,
  2105     "ancestor": ancestor,
  2167     "ancestor": ancestor,
  2106     "ancestors": ancestors,
  2168     "ancestors": ancestors,
  2107     "_firstancestors": _firstancestors,
  2169     "_firstancestors": _firstancestors,