o ]Lb(@s*dZddlmZddlZddlZddlZddlZddlmZddl m Z m Z m Z ddl mZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z$ddl%m&Z&m'Z'd Z(d Z)gd Z*d Z+Gd dde,Z-Gddde,Z.Gddde,Z/ddZ0ddZ1ddZ2ddZ3ddZ4ddZ5d^d d!Z6d"d#Z7d$d%Z8d&d'Z9d(d)Z:d*d+Z;d,d-Zd2d3Z?d4d5Z@d6d7ZAd8d9ZBd:d;ZCdd?ZEd@dAZFdBdCZGdDdEZHdFdGZIdHdIZJdJdKZKdLdMZLdNdOZMdPdQZNdRdSZOdTdUZPdVdWZQdXdYZRdZd[ZSd\d]ZTdS)_a@save and restore changes to the working directory The "hg shelve" command saves changes made to the working directory and reverts those changes, resetting the working directory to a clean state. Later on, the "hg unshelve" command restores the changes saved by "hg shelve". Changes can be restored even after updating to a different parent, in which case Mercurial's merge machinery will resolve any conflicts if necessary. You can have more than one shelved change outstanding at a time; each shelved change has a distinct name. For details, see the help for "hg shelve". )absolute_importN)_)binhexnullrev) bookmarksbundle2 changegroupcmdutil discoveryerrorexchangehglockmdiffmerge mergestatepatchphasespycompatrepairscmutiltemplatefiltersutilvfs)dateutil stringutils shelve-backupsshelved)shgpatchshelvesshelve@localhostc@s&eZdZd ddZddZddZdS) ShelfDirFcCs4|rt|jt|_dSt|jt|_dSN)vfsmodrjoin backupdir shelvedir)selfrepo for_backupsr)2/usr/lib/python3/dist-packages/mercurial/shelve.py__init__IszShelfDir.__init__cCs t|j|Sr!)Shelfr)r&namer)r)r*getOs z ShelfDir.getc Csz|j}Wnty"}z|jtjkrgWYd}~Sd}~wwg}t}|D])}|ddd}||vr9q*||||}| sHq*| }| ||fq*t |ddS)z2return all shelves in repo as list of (time, name)N.rrT)reverse) rlistdirOSErrorerrnoENOENTsetrsplitaddr.existsmtimeappendsorted) r&nameserrinfoseenfilenamer-shelfr9r)r)r* listshelvesRs*    zShelfDir.listshelvesNF)__name__ __module__ __qualname__r+r.rBr)r)r)r*r Hs  r c@sreZdZdZddZddZddZdd Zd d Zd d Z ddZ ddZ dddZ ddZ ddZddZdS)r,aRepresents a shelf, including possibly multiple files storing it. Old shelves will have a .patch and a .hg file. Newer shelves will also have a .shelve file. This class abstracts away some of the differences and lets you work with the shelf as a whole. cCs||_||_dSr!rr-)r&rr-r)r)r*r+qs zShelf.__init__cCs$|j|jdo|j|jdS)N.patch.hgrr8r-r&r)r)r*r8usz Shelf.existscCs|j|jdtjSNrH)rstatr-ST_MTIMErKr)r)r*r9zz Shelf.mtimecCst|j|jd|dSNs.shelve)rsimplekeyvaluefilerr-write)r&r>r)r)r* writeinfo}szShelf.writeinfocCs|j|jdSrPrJrKr)r)r*hasinfoz Shelf.hasinfocCst|j|jdSrP)rrQrr-readrKr)r)r*readinfos  zShelf.readinfoc Cs~t|}|dkrd}d}nd}d}|}tj|||gd}t|||d}|j|jd} t j |j || ||j|ddS) Ns01sHG10BZsHG20sBZ) missingroots ancestorsofrrI) compression) r safeversion unfilteredr outgoingmakechangegrouprr#r-r writebundleui) r&r'basesnode cgversionbtyperZr]cgbundle_filenamer)r)r*r_s(  zShelf.writebundlec Cs|jd}||}zDtj}t|stj}t|j|||j}|d}t j |||dd|j ||d|d}||krH|j dd} || }|W| S| w)NrIstipunshelvesbundle:)sourceurl targetphases revduplicates)r-rrinternalsupportinternalsecretr readbundler`r applybundler#changesclose) r&r'trr@fprjgenpretip shelvectx shelverevr)r)r*rps,   zShelf.applybundlerbcCs||jd|SrLrG)r&moder)r)r* open_patchrUzShelf.open_patchcCs2dd}||D]}||s||SqdS)Ncss<|V|dd\}}tdD] }d|||fVqdS)Nr/rs%s-%d.%s)r6 itertoolscount)baseextir)r)r*gennamess z'Shelf._backupfilename..gennames)r8r#)r& backupvfsr@rnr)r)r*_backupfilenames   zShelf._backupfilenamecCsT|s|tD]}|jd|}|j|r't|j|| ||q dSNr/) isdirmakedirshelvefileextensionsr-rr8rrenamer#r)r&rsuffixr@r)r)r* movetobackups   zShelf.movetobackupcCs$tD] }|j|jd|qdSr)rr tryunlinkr-)r&rr)r)r*deletesz Shelf.deleteN)ry)rDrErF__doc__r+r8r9rSrTrWr_rpr{rrrr)r)r)r*r,is  r,c@sxeZdZdZdZdZdZdZdZdZ e dd Z e d d Z e d d Z e ddZe   dddZe ddZdS) shelvedstatezHandle persistence during unshelving operations. Handles saving and restoring a shelved state. Ensures that different versions of a shelved state are possible and handles them appropriately. s shelvedstatekeepsnokeeps:no-active-bookmark interactivec Csz/t|d|d<t|d|d<dd|ddD|d<dd|ddD|d<Wd StttfyF}ztt|d }~ww) z@Some basic shelvestate syntactic verification and transformation originalwctx pendingctxcSg|]}t|qSr)r.0hr)r)r* z4shelvedstate._verifyandtransform..parents cSrr)rrr)r)r*rs nodestoremoveN) rsplit ValueError TypeErrorKeyErrorr CorruptedStater forcebytestr)clsdr=r)r)r*_verifyandtransforms z shelvedstate._verifyandtransformc Csd||j}z&z t|}Wnty%}ztt |d}~wwW| |S| w)z.Read version information from shelvestate fileN) r _filenameintreadlinestriprr rrrrr)rr'rtversionr=r)r)r* _getversions  zshelvedstate._getversioncCsLgd}||j}i}z|D] }|||<qW||S|w)z9Read the old position-based version of a shelvestate file) sversionnamerrrrbranchtorestorer activebook)rrrrrr)rr'keysrtrkeyr)r)r*_readolds  zshelvedstate._readoldc Cs*||}||jkr||}n||jkr"t|j|jjdd}nt t d| |zO|}|d|_ ||d|_ ||d|_|d|_|d|_|d d |_|d |jk|_d |_|d d |jkrr|d d |_|d |jk|_W|Stjtfy}ztt|d}~ww)NT)firstlinenonkeyvalsIthis version of shelve is incompatible with the version used in this reporrrrrrrrr)r_versionrrrQrrrVr Abortrrr-wctx pendingctxparents nodestoremover.branchtorestore_keepkeepactivebookmark _noactivebook _interactive interactiveRepoLookupErrorrrrbytestr)rr'rrobjr=r)r)r*loads>        zshelvedstate.loadFrc Cs|t|t|ddd|jDddd|D||r&|jn|j|p,|jd} | r6|j| d<t |j |j j | d|jddS) NrcSrr)r)rpr)r)r*rRrz%shelvedstate.save..cSrr)r)rrr)r)r*rSr)rrrrrrrrrs%d) firstline)rrbr#dirstaterr_nokeeprrrrQrrrRr) rr'r- originalwctxrrrr activebookrr>r)r)r*saveAs     zshelvedstate.savecCs|jj|jdddS)NT) ignoremissing)r unlinkpathr)rr'r)r)r*clear^szshelvedstate.clearN)FrF)rDrErFrrrrrrr classmethodrrrrrrr)r)r)r*rs.    #  rcCs~|jdd}t|dd}|}|dkr$|t|kr$||dd}nd}||dD]\}}||kr5q,||q,dS)Nrs maxbackupsT)r(rr)r` configintr rBlenr.r)r' maxbackups backup_dirhgfiles bordermtimer9r-r)r)r*cleanupoldbackupscs rcCs|j}|r t||Sr!)_activebookmarkr deactivate)r'rr)r)r*_backupactivebookmarkrs rcCs|r t||dSdSr!)ractivate)r'markr)r)r*_restoreactivebookmarkysrcCs,d}|j||||jd|dS)z@Abort current transaction for shelve/unshelve, but keep dirstatesdirstate.shelveN)r savebackupabort restorebackup)r'rsdirstatebackupnamer)r)r*_aborttransaction~srcsfdd}|d}|jp|pddddddr,ddd |r_t||rBtd |}t |d|vsJd|vrQt td |dr]t td |St|}|D]}||st|}|Sqf|S) z/Decide on the name this shelve is going to havec3s*VtdD] }d|fVq dS)Nrs%s-%02d)r|r})rlabelr)r*rs zgetshelvename..gennamesrsdefault/_\r/rs*a shelved change named '%s' already existss,shelved change names can not contain slashess+shelved change names can not start with '.') r.rbranchreplace startswithr r8rr r)r'parentoptsrr-e shelf_dirrr)rr* getshelvenames4          rccsvth}t}|||r9|}|V|D]}|}||vr4||| r4||q|sdSdS)zireturn all mutable ancestors for ctx (included) Much faster than the revset ancestors(ctx) & draft()N) r collectionsdequer:popleftrbrrevr7mutable)ctxr?visitrrr)r)r*mutableancestorss      rFcs&fddfdd}|r|SS)Nc st|d}|r|jjd}|j_tj}t|stj}d|i}zHd} r2tj dddit |} |j ||j|t|d|| dWdW|rU||j_SS1sYwYW|rg||j_dSdS|ro||j_w) NsmqFsphasess new-commiteditforms shelve.shelvedateeditorextrar))r safehasattrmq checkappliedrrlrmrnr getcommiteditorr strkwargsr`configoverridecommit shelveuserr.) r`r'messagematchrhasmqsavedrj overrideseditor_rr)r* commitfuncsB     z!getcommitfunc..commitfunccs4t|}t|d|i}|d}|||||S)Nr/message)r byteskwargsrr )r`r'patsrr r)rr)r*interactivecommitfuncs z,getcommitfunc..interactivecommitfuncr))rrrrr))rrrr* getcommitfuncs  rcCsN|jt|d||d}|jr|tdt|jdS|tddS)N)r s4nothing changed (%d missing files, see 'hg status') snothing changed )statusrr deletedrr)r`r'rrrMr)r)r*_nothingtoshelvemessagingsrcCsdt|i}t||}||tt||}|||||d}tj ||g|t j dd|dWddS1sAwYdS)NnodeswbT)git)rr ) rr r.rSlistrr_r{r exportfilerdiffopts)r'rbr-r r>rArartr)r)r*_shelvecreatedcommits   "rcCsJ|jt|d||dd}|jr#d|j|d<|d|jdSdS)NT)r unknownshelve_unknown)rrr rr#r7)r'rrrsr)r)r*_includeunknownfiless r!cCs$t|r |dSt||dSr!)rrmrrr)r'rsr)r)r* _finishshelves  r"cCsD|t|t||||WdS1swYdS)z$subcommand that creates a new shelveN)wlockr checkunfinished _docreatecmd)r`r'rrr)r)r* createcmd s   $r&c Cs|d}|}|d}|}|tkr#d|ddd}nd}|ds.||d<d} } } z|} |jddd d } |d d } |d d oU|dd  } t |||}t |} ddi}| rmt ||||t |rt ||s|j|dt|| dd}| st|||||}ntj|||dd tjg|Rit|}|st||||Wt|| t| | dSt|||}t|||||t d||dr|j!t"|||Wdn1swYnt#$||%t&j'(|}|)s|*||dkr&t ||s&|j|t+|| Wt|| t| | dSt|| t| | w)Nrschanges to: %s rs(changes in empty repository)rrcSdSr!r)xr)r)r*&z_docreatecmd..reportrFsunknowns addremoveinternalr/T)rsshelved as %s r),rrrr descriptionrr.r transactionrrr!_iswctxonnewbranch _isbareshelver setbranchrr rdorecord recordfilterrrrrlockmodreleaser matchfilesfilesrrr parentchange movedirstaterupdaterb mergestatemodrrVunresolvedcountresetr")r`r'rrrrr origbranchdescrrsrrincludeunknownr-rrrbr msr)r)r*r%s~              r%cCs0| o|dd o|dd o|dd S)NrFsincludesexclude)r.)rrr)r)r*r3cs   r3cCs|d|dkSr)rr'r)r)r*r2lrOr2cCsr|+t|}t|jt}|D]\}}|||t |qWddS1s2wYdS)z#subcommand that deletes all shelvesN) r#r r"rr#r$rBr.rr)r`r'rr_mtimer-r)r)r* cleanupcmdps  "rGcCs|s ttd|4t|jt}|D]}t| |}| s/ttd|| |t |qWddS1sDwYdS)z)subcommand that deletes a specific shelvesno shelved changes specified!shelved change '%s' not foundN) r InputErrorrr#r"rr#r$r r.r8rr)r`r'rrr-rAr)r)r* deletecmd{s    "rJc Cst|}d}|s|}d}|dt|}|D]\}}|r(||vr(q|j||dd}|jr:|dq|ddt|d} t |} d t j | d d } |j| d d|dd t| | d 7} | |r} | } | s{n| ds| }|rt||| }||nqt|d|ds|ds Wdq| }|drtt|D] \}}|j||dq|drtj||dD] \}}|j||dqWdn1swYqdS)z,subcommand that displays the list of shelvesPs shelve.newestrrs shelve.namer'rs(%s)T)abbrevs shelve.age #rsstatN)width)r5plain termwidthpagerr rBrRquietrrmakedaterager.r{rrrstrip formattedrellipsis readlinesr difflabeliter diffstatui)r`r'rrrP namelabelrr9r-useddaterVrtlinerB difflineschunkrr)r)r*listcmdsb       rdc Cs|t|}t|dkr |}|sttd|d\}}|g}|D]}||s4ttd|q"t||||dS)z subcommand that displays shelvesrsthere are no shelves to showscannot find shelf %sN) r rrBr rrr.r8rd) r`r'rrrshelvesr9r- shelfnamer)r)r* patchcmdss  rgcCs"|j|jkrttddS)z'check parent while resuming an unshelves5working directory parents do not match unshelve stateN)rrr rr)r'stater)r)r* checkparentss ric Cszt|}|ddur|j|d<W|SW|Sty9}z|jtjkr&t|t dWYd}~|Sd}~wt j y{}z6| t |d|dr_t d}t d}t j||d|drpt|t t d WYd}~|Sd}~ww) Nrrgr'continuescorrupted shelved state files:please run hg unshelve --abort to abort unshelve operationhintabortspcould not read shelved state file, your working copy may be in an unexpected state please update to some commit )rrr.rIOErrorr3r4r wrongtooltocontinuerr rdebugrrrr)r`r'rrhr=msgrlr)r)r*_loadshelvedstates@        rrc Cs|_zEt||t|j|jr!|j|jvr!t||jt |||j |jt |s:t j|||jdddWt||td|jnt||td|jwWddS1sfwYdS)z-subcommand that abort an in-progress unshelveFrbackuptopicsunshelve of '%s' aborted N)rrir clean_updaterr _bookmarksrr mergefilesrrrmrrrrrwarnrr-r`r'rhr)r)r* unshelveaborts"       "r{cCsH|t||ddi}t|||WdS1swYdS)z(logic to abort unshelve using 'hg abortrmTN)r#rrr{rzr)r)r*hgabortunshelves  $r|cCsR|ddit||t|||WddS1s"wYdS)zLupdates to wctx and merges the changes from shelvectx into the dirstate.uisquietTN)rrr=rbr revert)r`r'rrwr)r)r*rx s"rxcCs<|r||jkr|j||td|dSdSdS)Ns&marked working directory as branch %s )rrr4rr)r`r'rr)r)r* restorebranchs   rcCs@|dst|jt}t|||t|dSdS)z&remove related files after an unshelverN)r.r"rr#r$r rr)r`r'r-rrr)r)r*unshelvecleanups  rc Cs0|j}|j}|t||tj|}|r&tj t dt dd||j d}|j }|j ||j |j|j |Wdn1sRwYtj} t|sbtj} d| i} |j| d2|j ||j d|jt||||||\} } Wdn1swYWdn1swY| dur|j }t d } || n |j| || }t|t |||j!|t"|||j#t|st$j%|||jd d d t&'|| st(|||j|t)||j*|t d |jWddS1swYdS)z.subcommand to continue an in-progress unshelves$unresolved conflicts, can't continues/see 'hg resolve', then 'hg unshelve --continue'rkrNrrgr<note: unshelved changes already existed in the working copy Frrssunshelve of '%s' complete )+rr-rrir>rrVr?r rrrrrr; setparentsrbnullidrRcurrenttransactionrrlrmrnr`r_createunshelvectxrrr:rr=rxrrrrrrrrrr)r`r'rhrrbasenamerDrwrrjr newnodeispartialunshelverqr)r)r*unshelvecontinue#sd               $rcCsP|t||ddi}t|||d|jiWdS1s!wYdS)z,logic to resume unshelve using 'hg continue'rjTrN)r#rrrrrzr)r)r*hgcontinueunshelve_s $rc Cs|}t|j}|js|js|js||fS|tdddi}t|ddd}i}d|d<|d|d<|d d it |||g|} Wd n1sPwY|| }||fS) zETemporarily commit working copy changes before moving unshelve commitsLtemporarily committing pending changes (restore with 'hg unshelve --abort') r/rF)rrrs pending changes temporary commitrrr}TN) r frozensetaddedmodifiedremovedrrr.rr r) r`r'rtmpwctxr  addedbeforerrtempoptsrbr)r)r*_commitworkingcopychangesfs& rcCs|}d}t||}|r|d}|dus||vrQ|ddi|||}Wdn1s7wY|durMdt|i}| |||fS||}||fS)z5Recreate commit in the repository during the unshelveNrr}T) r\r r.rTrWrrprrbrS)r`r'rsrrbrArwr>r)r)r*_unshelverestorecommits  rc Cs||d<d|d<g}|s#|j||||d}|dfSt|ddd}tj|||ddtjg|Rit |}|j|||d} | rbt |||  } t|| || |t| fS) ayHandles the creation of unshelve commit and updates the shelve if it was partially unshelved. If interactive is: * False: Commits all the changes in the working directory. * True: Prompts the user to select changes to unshelve and commit them. Update the shelve with remaining changes. Returns the node of the new commit formed and a bool indicating whether the shelve was partially unshelved.Creates a commit ctx to unshelve interactively or non-interactively. The user might want to unshelve certain changes only from the stored shelve in interactive. So, we would create two commits. One with requested changes to unshelve at that time and the latter is shelved for future. Here, we return both the newnode which is created interactively and a bool to know whether the shelve is partly done or completely done. rTsinteractive-unshelve)textruserr`F)rrN)rrr)r0rrrr`rr r5r6rrrr9r:rbool) r`r'rwrrrrrrsnodemr)r)r*rsB   rc  s|d} ||kr| s|dfS|ddtjd} j| d|tdt j |gdd d } | j rd| fd d t |tD}t||||| |d | | tdj|jt|||| |\}}Wdn1swY|dur|}td}||n|}t |Wd||fSWd||fS1swY||fS)zBRebase restored commit from its original location to a destinationrFtoolr)r~s forcemergerrgsrebasing shelved changes )s working-copysshelved changesparent of shelved changeT)labelskeepconflictparentcsg|]}j|qSr)) changelogrb)rrrEr)r*rs z)_rebaserestoredcommit..rNr)r.rbp1rrnr`rrrrgraftr?rrrxrangerrrr ConflictResolutionRequiredrr;rrrr=)r`r'rrs oldtiprevrpctxrrwrrrr statsrrrrqr)rEr*_rebaserestoredcommitsh          1 11rcCsP|d}|s dSt|d}t|j}||@|}|d|dS)Nrr)rr.rrrrforget)r'rwr shelveunknown addedaftertoforgetr)r)r*_forgetunknownfiless rcCs*t|||j||t||dSr!)rr\rrr)r'rrsrr)r)r*_finishunshelve&s rcCsJt|j}t|}||}|r#td}td}tj||ddS)zYCheck potential problems which may result from working copy having untracked changes.s$shelved change touches missing filess,run hg status to see which files are missingrkN)r5rrr: intersectionrr r)r`r'rw wcdeleted shelvetouchedrrrlr)r)r*_checkunshelveuntrackedproblems0s  rc Ost|}|d}|d}|d}|s|st|t|}|dr-||d|r;|dr;tt d|s?|r|rJ|rJtt d|rStt d|rb|d d rb| t d t |||}|rpt |||S|r{|r{tt d |rt ||||Sn2t|d krtt d|st|}|stt d|dd }|t d|n|d}t||stt d|t||||S)Nrmrjrrrs,--keep on --interactive is not yet supporteds"cannot use both abort and continues:cannot combine abort/continue with naming a shelved changerFstool option will be ignored s(cannot use both continue and interactivers&can only unshelve one change at a timesno shelved changes to apply!rsunshelving change '%s' rH)rrr.r r$rr:r rIrryrrr{rrr rB StateErrorrr8 _dounshelve) r`r'shelvedrabortf continuefrrhrr)r)r* unshelvecmd<s\           rc Csx|}d}}z|}|jdddd}t|}|d}|}t|} t||||\}} t||||\}} t||| d} | | krL| } t ||||||||| | | \} } d| ddi}| |dt |||| Wdn1s|wYt||| t|t|||| t|| | | st||||W|r|t|dS|r|t|w) NrgcSr(r!r)r)r)r)r*r+wr,z_dounshelve..r-r/rrr)r\rr1rrrrrrrrr.rrxrrrrrrr8r7)r`r'rrrrsrrrrrrwrrr r)r)r*rrs^      rrC)Ur __future__rrr3r|rMi18nrrbrrrrr r r r r rrrr7rrrr>rrrrrrrrr"utilsrrr$r%rrobjectr r,rrrrrrrrrrr!r"r&r%r3r2rGrJrdrgrirrr{r|rxrrrrrrrrrrrrrr)r)r)r*sn  X!p ( &  Q  /<8N   6