directaccesss: also look for symbol into list
revrange is now much smarted and optimise multiple simple symbol (like hash)
into an efficient '_list' call. So we need to look into these to find user
provided input too.
# This software may be used and distributed according to the terms of the# GNU General Public License version 2 or any later version.'''This extension add a hacky command to drop changeset during reviewThis extension is intended as a temporary hack to allow Matt Mackall to useevolve in the Mercurial review it self. You should probably not use it if yourname is not Matt Mackall.'''importosimporttimeimportcontextlibfrommercurial.i18nimport_frommercurialimportcmdutilfrommercurialimportrepairfrommercurialimportscmutilfrommercurialimportlockaslockmodfrommercurialimportutilfrommercurialimportcommandscmdtable={}command=cmdutil.command(cmdtable)@contextlib.contextmanagerdeftimed(ui,caption):ostart=os.times()cstart=time.time()yieldcstop=time.time()ostop=os.times()wall=cstop-cstartuser=ostop[0]-ostart[0]sys=ostop[1]-ostart[1]comb=user+sysui.write("%s: wall %f comb %f user %f sys %f\n"%(caption,wall,comb,user,sys))defobsmarkerchainfrom(obsstore,nodes):"""return all marker chain starting from node Starting from mean "use as successors"."""# XXX need something smarter for descendant of bumped changesetseennodes=set(nodes)seenmarkers=set()pendingnodes=set(nodes)precursorsmarkers=obsstore.precursorswhilependingnodes:current=pendingnodes.pop()new=set()forprecmarkinprecursorsmarkers.get(current,()):ifprecmarkinseenmarkers:continueseenmarkers.add(precmark)new.add(precmark[0])yieldprecmarknew-=seennodespendingnodes|=newdefstripmarker(ui,repo,markers):"""remove <markers> from the repo obsstore The old obsstore content is saved in a `obsstore.prestrip` file """repo=repo.unfiltered()repo.destroying()oldmarkers=list(repo.obsstore._all)util.rename(repo.sjoin('obsstore'),repo.join('obsstore.prestrip'))delrepo.obsstore# drop the cachenewstore=repo.obsstoreassertnotnewstore# should be empty after renamenewmarkers=[mforminoldmarkersifmnotinmarkers]tr=repo.transaction('drophack')try:newstore.add(tr,newmarkers)tr.close()finally:tr.release()repo.destroyed()@command('drop',[('r','rev',[],'revision to update')],_('[-r] revs'))defcmddrop(ui,repo,*revs,**opts):"""I'm hacky do not use me! This command strip a changeset, its precursors and all obsolescence marker associated to its chain. There is no way to limit the extend of the purge yet. You may have to repull from other source to get some changeset and obsolescence marker back. This intended for Matt Mackall usage only. do not use me. """revs=list(revs)revs.extend(opts['rev'])ifnotrevs:revs=['.']# get the changesetrevs=scmutil.revrange(repo,revs)ifnotrevs:ui.write_err('no revision to drop\n')return1# lock from the beginning to prevent racewlock=lock=Nonetry:wlock=repo.wlock()lock=repo.lock()# check they have no childrenifrepo.revs('%ld and public()',revs):ui.write_err('cannot drop public revision')return1ifrepo.revs('children(%ld) - %ld',revs,revs):ui.write_err('cannot drop revision with children')return1ifrepo.revs('. and %ld',revs):newrevs=repo.revs('max(::. - %ld)',revs)ifnewrevs:assertlen(newrevs)==1newrev=newrevs.first()else:newrev=-1commands.update(ui,repo,newrev)ui.status(_('working directory now at %s\n')%repo[newrev])# get all markers and successors up to rootnodes=[repo[r].node()forrinrevs]withtimed(ui,'search obsmarker'):markers=set(obsmarkerchainfrom(repo.obsstore,nodes))ui.write('%i obsmarkers found\n'%len(markers))cl=repo.unfiltered().changelogwithtimed(ui,'search nodes'):allnodes=set(nodes)allnodes.update(m[0]forminmarkersifcl.hasnode(m[0]))ui.write('%i nodes found\n'%len(allnodes))cl=repo.changelogvisiblenodes=set(nforninallnodesifcl.hasnode(n))# check constraint againifrepo.revs('%ln and public()',visiblenodes):ui.write_err('cannot drop public revision')return1ifrepo.revs('children(%ln) - %ln',visiblenodes,visiblenodes):ui.write_err('cannot drop revision with children')return1ifmarkers:# strip themwithtimed(ui,'strip obsmarker'):stripmarker(ui,repo,markers)# strip the changesetwithtimed(ui,'strip nodes'):repair.strip(ui,repo,list(allnodes),backup="all",topic='drophack')finally:lockmod.release(lock,wlock)# rewrite the whole file.# print data.# - time to compute the chain# - time to strip the changeset# - time to strip the obs marker.