caches: factorise the cache warming check
The old conditional was duplicated and hard to read. We factorise everything
into the `utility` module.
from__future__importabsolute_importfrommercurial.i18nimport_frommercurialimport(bookmarks,destutil,error,extensions,)from.importtopicmapfrom.evolvebitsimportbuilddependenciesdef_destmergebranch(orig,repo,action='merge',sourceset=None,onheadcheck=True,destspace=None):# XXX: take destspace into accountifsourcesetisNone:p1=repo['.']else:# XXX: using only the max here is flacky. That code should eventually# be updated to take care of the whole sourceset.p1=repo[max(sourceset)]top=p1.topic()iftop:revs=repo.revs('topic(%s) - obsolete()',top)deps,rdeps=builddependencies(repo,revs)heads=[rforrinrevsifnotrdeps[r]]ifonheadcheckandp1.rev()notinheads:raiseerror.Abort(_("not at topic head, update or explicit"))# prune heads above the sourceotherheads=set(heads)pool=set([p1.rev()])whilepool:current=pool.pop()otherheads.discard(current)pool.update(rdeps[current])ifnototherheads:# nothing to do at the topic levelbhead=ngtip(repo,p1.branch(),all=True)ifnotbhead:raiseerror.NoMergeDestAbort(_("nothing to merge"))elif1==len(bhead):returnbhead[0]else:msg=_("branch '%s' has %d heads ""- please merge with an explicit rev")hint=_("run 'hg heads .' to see heads")raiseerror.ManyMergeDestAbort(msg%(p1.branch(),len(bhead)),hint=hint)eliflen(otherheads)==1:returnotherheads.pop()else:msg=_("topic '%s' has %d heads ""- please merge with an explicit rev")%(top,len(heads))raiseerror.ManyMergeDestAbort(msg)returnorig(repo,action,sourceset,onheadcheck,destspace=destspace)def_destupdatetopic(repo,clean,check=None):"""decide on an update destination from current topic"""movemark=node=Nonetopic=repo.currenttopicrevs=repo.revs('.::topic("%s")'%topic)ifnotrevs:returnNone,None,Nonenode=revs.last()ifbookmarks.isactivewdirparent(repo):movemark=repo['.'].node()returnnode,movemark,Nonedefdesthistedit(orig,ui,repo):ifnot(ui.config('histedit','defaultrev',None)isNoneandrepo.currenttopic):returnorig(ui,repo)revs=repo.revs('::. and stack()')ifrevs:returnrevs.min()returnNonedefngtip(repo,branch,all=False):"""tip new generation"""## search for untopiced heads of branch# could be heads((::branch(x) - topic()))# but that is expensive## we should write plain code insteadtmap=topicmap.gettopicrepo(repo).branchmap()ifbranchnotintmap:return[]elifall:returntmap.branchheads(branch)else:return[tmap.branchtip(branch)]defmodsetup(ui):"""run a uisetup time to install all destinations wrapping"""extensions.wrapfunction(destutil,'_destmergebranch',_destmergebranch)bridx=destutil.destupdatesteps.index('branch')destutil.destupdatesteps.insert(bridx,'topic')destutil.destupdatestepmap['topic']=_destupdatetopicextensions.wrapfunction(destutil,'desthistedit',desthistedit)