from__future__importabsolute_importfrommercurialimport(registrar,revset,util,)from.import(constants,destination,stack,)try:mkmatcher=revset._stringmatcherexceptAttributeError:mkmatcher=util.stringmatcherrevsetpredicate=registrar.revsetpredicate()@revsetpredicate('topic([topic])')deftopicset(repo,subset,x):"""Specified topic or all changes with any topic specified. If `topic` starts with `re:` the remainder of the name is treated as a regular expression. TODO: make `topic(revset)` work the same as `branch(revset)`. """args=revset.getargs(x,0,1,'topic takes one or no arguments')ifargs:# match a specific topictopic=revset.getstring(args[0],'topic() argument must be a string')iftopic=='.':topic=repo['.'].extra().get('topic','')_kind,_pattern,matcher=mkmatcher(topic)else:matcher=lambdat:bool(t)mutable=revset._notpublic(repo,revset.fullreposet(repo),())rawchange=repo.changelog.changelogrevisionkey=constants.extrakeydefmatchtopic(r):topic=rawchange(r).extra.get(key)iftopicisNone:returnFalsereturnmatcher(topic)return(subset&mutable).filter(matchtopic)@revsetpredicate('ngtip([branch])')defngtipset(repo,subset,x):"""The untopiced tip. Name is horrible so that people change it. """args=revset.getargs(x,1,1,'topic takes one')# match a specific topicbranch=revset.getstring(args[0],'ngtip() argument must be a string')ifbranch=='.':branch=repo['.'].branch()returnsubset&revset.baseset(destination.ngtip(repo,branch))@revsetpredicate('stack()')defstackset(repo,subset,x):"""All relevant changes in the current topic, This is roughly equivalent to 'topic(.) - obsolete' with a sorting moving unstable changeset after there future parent (as if evolve where already run)."""err='stack() takes no argument, it works on current topic'revset.getargs(x,0,0,err)topic=Nonebranch=Noneifrepo.currenttopic:topic=repo.currenttopicelse:branch=repo[None].branch()returnrevset.baseset(stack.stack(repo,branch=branch,topic=topic)[1:])&subset