revsfromramge: hard code the single changeset range case
That case is trivial and triggering and full stable sort for it seems a bit
silly.
from__future__importabsolute_importfrommercurial.i18nimport_frommercurialimport(bookmarks,destutil,error,extensions,util,)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)iflen(getattr(orig,'func_defaults',()))==3:# version hg-3.7returnorig(repo,action,sourceset,onheadcheck)if3<len(getattr(orig,'func_defaults',())):# version hg-3.8 and abovereturnorig(repo,action,sourceset,onheadcheck,destspace=destspace)else:returnorig(repo)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 insteadwithtopicmap.usetopicmap(repo):tmap=repo.branchmap()ifbranchnotintmap:return[]elifall:returntmap.branchheads(branch)else:return[tmap.branchtip(branch)]defmodsetup(ui):"""run a uisetup time to install all destinations wrapping"""ifutil.safehasattr(destutil,'_destmergebranch'):extensions.wrapfunction(destutil,'_destmergebranch',_destmergebranch)try:rebase=extensions.find('rebase')exceptKeyError:rebase=Noneif(util.safehasattr(rebase,'_destrebase')# logic not shared with merge yet < hg-3.8andnotutil.safehasattr(rebase,'_definesets')):extensions.wrapfunction(rebase,'_destrebase',_destmergebranch)ifutil.safehasattr(destutil,'destupdatesteps'):bridx=destutil.destupdatesteps.index('branch')destutil.destupdatesteps.insert(bridx,'topic')destutil.destupdatestepmap['topic']=_destupdatetopicifutil.safehasattr(destutil,'desthistedit'):extensions.wrapfunction(destutil,'desthistedit',desthistedit)