^c/ dZddlZddlmZddlmZmZmZddlm Z ej rddl m Z m Z e e fD]ZesJGdd ZGd d ZgZiZ d dZdZejdZdZdZedddededededdddededdZdS)!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. N)_)errorpycompatutil)cborutil)AnyDictc6eZdZdZdZdZdZdZdZdZ 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. c"||_||_dS)zorepo is the repo object fname is the file name in which data should be stored in .hg directory N)_repofname)selfrepors 1/usr/lib/python3/dist-packages/mercurial/state.py__init__zcmdstate.__init__8s  c*|S)z=read the existing state file and return a dict of data stored)_readrs rreadz cmdstate.read?szz||rcXt|tstjd|j|jdd5}|d|ztj |D]}|| ddddS#1swxYwYdS)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) isinstanceintrProgrammingErrorrvfsrwriter streamencode)rversiondatafpchunks rsavez cmdstate.saveDs '3'' (= Z^^DJ$^ ? ? 2 HHWw& ' ' '!.t44                     s ABB#&B#cX|j|jd5} t|n"#t $rt jdwxYwtj | dcdddS#1swxYwYdS)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) rrrrreadline ValueErrorrCorruptedStater decodeallr)rr#s rrzcmdstate._readSsZ^^DJ . . 4" BKKMM""""   *:  %bggii003 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4s(B!ABA$$.BB#&B#cvtj|jj|jddS)zdrop the state file if existsT) ignoremissingN)r unlinkpathrrjoinrrs rdeletezcmdstate.delete`s1  ++DJ77tLLLLLLrcJ|jj|jS)z*check whether the state file exists or not)rrexistsrrs rr1zcmdstate.existsdsz~$$TZ000rN) __name__ __module__ __qualname____doc__rrr%rr/r1rrr r *s{       4 4 4MMM11111rr c6eZdZdZdZdZdZdZdZdZ dS) _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. c||_||_||_||_||_||_||_||_d|_| |_ | |_ | |_ | |_ | |_ dS)NF)_opname_fname _clearable _allowcommit _reportonly _continueflag _stopflag _childopnames _delegating_cmdmsg_cmdhint _statushint abortfunc continuefunc)ropnamer clearable allowcommit reportonly continueflagstopflag childopnamescmdmsgcmdhint statushintrFrGs rrz_statecheck.__init__rss   #'%)!)   %"(rc|jsAtd|j|jfz}|jr|td|jzz}|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)rErr:r@)rhints r statusmsgz_statecheck.statusmsgso 1t|,-D~ 788DLIKrc|jsI|jstd|j|jfzStd|j|j|jfzS|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')rDr@rr:rs rrSz_statecheck.hints|} > EFFLLJ )LLL}rcL|jstd|jzS|jS)z7returns the status message corresponding to the commands%s in progress)rCrr:rs rmsgz_statecheck.msgs*| 9&''4<8 8|rc0td|jzS)z=returns appropriate continue message corresponding to commandshg %s --continue)rr:rs r continuemsgz_statecheck.continuemsgs$%%66rc|jdkr+t|ddkS|jrdS|j|jS)zPdetermines whether a multi-step operation is in progress or not mergeNrF)r:lenparentsrBrr1r;)rrs r isunfinishedz_statecheck.isunfinishedsZ <8 # #tDz))++,,q0 0   058??4;// /rN) r2r3r4r5rrTrSrWrYr^r6rrr8r8isx)))>   , 777 0 0 0 0 0rr8Frc |pg}t|||||||||| | | | } |dkrt| nO|D]1}|tvr&t jt d||fz2td| |tvr$t jt d|z| 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. r[sop %s depends on unknown op %srsop %s registered twiceN)r8_unfinishedstatesappend_unfinishedstatesbynamerrrinsert)rHrrIrJrKrLrMrNrOrPrQrFrG statecheckobj childopnames r addunfinishedrfs X %2L M   //// (  K"999,788FK;PP:   M222 ((($Q'@%A%AF%JKKK&3F###rct|d}|s$tjt d|z||jvr&tjt d||fzt|}||fS)Ns unknown op %ssop %s does not delegate to %s)rbgetrrrrA)rHrepcs r_getparentandchildrk"s##FD11A C$Q'7%8%86%ABBB!/))$ . / /6;2G G    ,A a4Krc#8Kt||\}}|jr$tjt d|zd|_ dVn8#tj$r&}|j|krtj||d}~wwxYw d|_dS#d|_wxYw)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)rkrBrrrConflictResolutionRequiredrH)rrHrerirjes r delegatingro.s fk 2 2DAq} $ 7 8 86 A   AM   + 8{ " "26:: :    s* A BB!A>>BB Bct||\}}|js||o||S)z;Returns true if both opname and childopname are unfinished.)rkrBr^)rrHrerirjs rischildunfinishedrqMsA fk 2 2DAq M 1Q^^D11 Kq~~d7K7KKrct||\}}t|||s&tjt d||fz|js$tjt d|z|||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)rkrqrrrrG)uirrHrerirjs r continuechildrtTs fk 2 2DAq T6; 7 7 $ ; < <F# $    > $ / 0 0; >    >>"d # ##rsupdates updatestateTslast update was interrupteds,use 'hg update' to get a consistent checkoutsTo continue: hg update .)rrIrOrPrQsbisects bisect.statesuse 'hg bisect --reset'sTo mark the changeset good: hg bisect --good To mark the changeset bad: hg bisect --bad To abort: hg bisect --reset )rrJrKrPrQct|jdd}tD]>}|j|vr ||r|j|fcS?dS)Nscommandssstatus.skipstates)setrs configlistr`r:r^rT)rskipstates r getrepostaterzzs tw!!+/CDD E ED"66 =D    d # # 6M5??#4#45 5 5 5 666r) FFFFFNrrrNN)r5 contextlibi18nrrrrutilsr TYPE_CHECKINGtypingr r tr r8r`rbrfrkcontextmanagerrorqrtrzr6rrrsk     4[<1<1<1<1<1<1<1<1~a0a0a0a0a0a0a0a0J    M4M4M4M4`    <LLL $ $ $    1 + , , A= > >q/00    A( ) )q >    66666r