o ]Lb/@s dZddlmZddlZddlmZddlmZmZm Z ddl m Z ej r8ddl mZmZeefD]Zes7Jq1Gd d d eZGd d d eZgZiZ      d&ddZddZejddZddZddZedddedededded d!dded"d#d$d%ZdS)'a^ This file contains class to wrap the state for commands and other related logic. All the data related to the command state is stored as dictionary in the object. The class has methods using which the data can be stored to disk in a file under .hg/ directory. We store the data on disk in cbor, for which we use the CBOR format to encode the data. )absolute_importN)_)errorpycompatutil)cborutil)AnyDictc@@eZdZdZddZddZddZdd Zd d Zd d Z dS)cmdstateaa wrapper class to store the state of commands like `rebase`, `graft`, `histedit`, `shelve` etc. Extensions can also use this to write state files. All the data for the state is stored in the form of key-value pairs in a dictionary. The class object can write all the data to a file in .hg/ directory and can populate the object data reading that file. Uses cbor to serialize and deserialize data while writing and reading from disk. cCs||_||_dS)zorepo is the repo object fname is the file name in which data should be stored in .hg directory N)_repofname)selfreporr1/usr/lib/python3/dist-packages/mercurial/state.py__init__9s zcmdstate.__init__cCs|S)z=read the existing state file and return a dict of data stored)_readrrrrread@sz cmdstate.readcCsvt|ts td|jj|jddd}|d|t |D]}||q!WddS1s4wYdS)zwrite all the state data stored to .hg/ file we use third-party library cbor to serialize data to write in the file. s*version of state file should be an integerswbT) atomictemps%d N) isinstanceintrProgrammingErrorr vfsrwriter streamencode)rversiondatafpchunkrrrsaveEs  "z cmdstate.savec Csp|j|jd&}zt|Wn tytdwt | dWdS1s1wYdS)ztreads the state file and returns a dictionary which contain data in the same format as it was before storingsrbs#unknown version of state file foundrN) r rrrreadline ValueErrorrCorruptedStater decodeallr)rr rrrrTs $zcmdstate._readcCstj|jj|jdddS)zdrop the state file if existsT) ignoremissingN)r unlinkpathr rjoinrrrrrdeleteaszcmdstate.deletecCs|jj|jS)z*check whether the state file exists or not)r rexistsrrrrrr+eszcmdstate.existsN) __name__ __module__ __qualname____doc__rrr"rr*r+rrrrr +s  r c@r ) _statecheckaca utility class that deals with multistep operations like graft, histedit, bisect, update etc and check whether such commands are in an unfinished conditition or not and return appropriate message and hint. It also has the ability to register and determine the states of any new multistep operation or multistep command extension. cCsX||_||_||_||_||_||_||_||_d|_| |_ | |_ | |_ | |_ | |_ dS)NF)_opname_fname _clearable _allowcommit _reportonly _continueflag _stopflag _childopnames _delegating_cmdmsg_cmdhint _statushint abortfunc continuefunc)ropnamer clearable allowcommit reportonly continueflagstopflag childopnamescmdmsgcmdhint statushintr=r>rrrrss z_statecheck.__init__cCs<|jstd|j|jf}|jr|td|j}|S|jS)z^returns the hint message corresponding to the command for hg status --verbose s>To continue: hg %s --continue To abort: hg %s --aborts To stop: hg %s --stop)r<rr1r7)rhintrrr statusmsgs  z_statecheck.statusmsgcCs>|js|jstd|j|jfStd|j|j|jfS|jS)zSreturns the hint message corresponding to an interrupted operation s)use 'hg %s --continue' or 'hg %s --abort's:use 'hg %s --continue', 'hg %s --abort', or 'hg %s --stop')r;r7rr1rrrrrIs z_statecheck.hintcCs|js td|jS|jS)z7returns the status message corresponding to the commands%s in progress)r:rr1rrrrmsgsz_statecheck.msgcCstd|jS)z=returns appropriate continue message corresponding to commandshg %s --continue)rr1rrrr continuemsgsz_statecheck.continuemsgcCs6|jdkrt|ddkS|jrdS|j|jS)zPdetermines whether a multi-step operation is in progress or not mergeNrF)r1lenparentsr9rr+r2)rrrrr isunfinisheds z_statecheck.isunfinishedN) r,r-r.r/rrJrIrKrLrPrrrrr0js r0Fc Cs|pg}t|||||||||| | | | } |dkrt| n|D]}|tvr1ttd||fq td| |tvrEttd|| t|<dS)aJthis registers a new command or operation to unfinishedstates opname is the name the command or operation fname is the file name in which data should be stored in .hg directory. It is None for merge command. clearable boolean determines whether or not interrupted states can be cleared by running `hg update -C .` which in turn deletes the state file. allowcommit boolean decides whether commit is allowed during interrupted state or not. reportonly flag is used for operations like bisect where we just need to detect the operation using 'hg status --verbose' continueflag is a boolean determines whether or not a command supports `--continue` option or not. stopflag is a boolean that determines whether or not a command supports --stop flag childopnames is a list of other opnames this op uses as sub-steps of its own execution. They must already be added. cmdmsg is used to pass a different status message in case standard message of the format "abort: cmdname in progress" is not desired. cmdhint is used to pass a different hint message in case standard message of the format "To continue: hg cmdname --continue To abort: hg cmdname --abort" is not desired. statushint is used to pass a different status message in case standard message of the format ('To continue: hg cmdname --continue' 'To abort: hg cmdname --abort') is not desired abortfunc stores the function required to abort an unfinished state. continuefunc stores the function required to finish an interrupted operation. rMsop %s depends on unknown op %srsop %s registered twiceN)r0_unfinishedstatesappend_unfinishedstatesbynamerrrinsert)r?rr@rArBrCrDrErFrGrHr=r> statecheckobj childopnamerrr addunfinisheds8,   rXcCsRt|d}|sttd|||jvr!ttd||ft|}||fS)Ns unknown op %ssop %s does not delegate to %s)rTgetrrrr8)r?rWpcrrr_getparentandchild#s  r\c cst||\}}|jrttd|d|_z%zdVWntjy6}z |j|kr0t||d}~wwWd|_dSd|_w)a.context wrapper for delegations from opname to childopname. requires that childopname was specified when opname was registered. Usage: def my_command_foo_that_uses_rebase(...): ... with state.delegating(repo, 'foo', 'rebase'): _run_rebase(...) ... s&cannot delegate from op %s recursivelyTNF)r\r9rrrConflictResolutionRequiredr?)rr?rWrZr[errr delegating/s"    r_cCs(t||\}}|js||o||S)z;Returns true if both opname and childopname are unfinished.)r\r9rP)rr?rWrZr[rrrischildunfinishedNsr`cCsTt||\}}t|||sttd||f|js$ttd||||S)z9Checks that childopname is in progress, and continues it.s*child op %s of parent %s is not unfinishedsop %s has no continue function)r\r`rrrr>)uirr?rWrZr[rrr continuechildUs   rbsupdates updatestateTslast update was interrupteds,use 'hg update' to get a consistent checkoutsTo continue: hg update .)rr@rFrGrHsbisects bisect.statesTo mark the changeset good: hg bisect --good To mark the changeset bad: hg bisect --bad To abort: hg bisect --reset )rrArBrHcCsHt|jdd}tD]}|j|vrq ||r!|j|fSq dS)Nscommandssstatus.skipstates)setra configlistrRr1rPrJ)rskipstaterrr getrepostatezs  rg) FFFFFNrQrQrQNN)r/ __future__r contextlibi18nrrrrutilsr TYPE_CHECKINGtypingr r tobjectr r0rRrTrXr\contextmanagerr_r`rbrgrrrrsb     ?e P