from__future__importabsolute_importfrommercurialimport(revset,util,)from.import(constants,destination,stack,)try:mkmatcher=revset._stringmatcherexceptAttributeError:mkmatcher=util.stringmatcherdeftopicset(repo,subset,x):"""`topic([topic])` 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)defngtipset(repo,subset,x):"""`ngtip([branch])` 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))defstackset(repo,subset,x):"""`stack()` 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=repo.currenttopictopic=Nonebranch=Noneifnottopicandrepo.currenttopic:topic=repo.currenttopicifnottopic:branch=repo[None].branch()returnrevset.baseset(stack.getstack(repo,branch=branch,topic=topic)[1:])&subsetdefmodsetup(ui):revset.symbols.update({'topic':topicset})revset.symbols.update({'ngtip':ngtipset})revset.symbols.update({'stack':stackset})