
    6h/              
      p   S r SSKJr  SSKrSSKJrJr  SSKJr  SSK	J
r
Jr  SSKJr  \\4 H  r\(       a  M   e    " S	 S
5      r " S S5      r/ r0 r           SS jrS r\R*                  S 5       rS rS r\" SSS\" S5      \" S5      \" S5      S9  \" SSSS\" S5      \" S5      S9  S rg) 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.
    )annotationsN)AnyDict   )_)errorutil)cborutilc                  @    \ rS rSrSrS rSS jrS rS rS r	S r
S	rg
)cmdstate*   a  a 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                    Xl         X l        g)z_repo is the repo object
fname is the file name in which data should be stored in .hg directory
N_repofname)selfrepor   s      1/usr/lib/python3/dist-packages/mercurial/state.py__init__cmdstate.__init__8   s     

    c                "    U R                  5       $ )z=read the existing state file and return a dict of data stored)_readr   s    r   readcmdstate.read?   s    zz|r   c                \   [        U[        5      (       d  [        R                  " S5      eU R                  R                  U R                  SSS9 nUR                  SU-  5        [        R                  " U5       H  nUR                  U5        M     SSS5        g! , (       d  f       g= f)zwrite all the state data stored to .hg/<filename> file

we use third-party library cbor to serialize data to write in the file.
s*   version of state file should be an integers   wbT)
atomictemps   %d
N)

isinstanceintr   ProgrammingErrorr   vfsr   writer
   streamencode)r   versiondatafpchunks        r   savecmdstate.saveC   s    
 '3''((=  ZZ^^DJJ$^?2HHWw&'!..t4 5 @??s   AB
B+c                N   U R                   R                  U R                  S5       n [        UR	                  5       5        [        R                  " UR                  5       5      S   sSSS5        $ ! [
         a    [        R                  " S5      ef = f! , (       d  f       g= f)zlreads the state file and returns a dictionary which contain
data in the same format as it was before storings   rbs#   unknown version of state file foundr   N)r   r"   r   r    readline
ValueErrorr   CorruptedStater
   	decodeallr   )r   r'   s     r   r   cmdstate._readR   s     ZZ^^DJJ."BKKM" %%bggi03 /.  **:  /.s"   BA2&B2!BB
B$c                    [         R                  " U R                  R                  R	                  U R
                  5      SS9  g)zdrop the state file if existsT)ignoremissingN)r	   
unlinkpathr   r"   joinr   r   s    r   deletecmdstate.delete_   s'    

++DJJ7tLr   c                `    U R                   R                  R                  U R                  5      $ )z*check whether the state file exists or not)r   r"   existsr   r   s    r   r8   cmdstate.existsc   s    zz~~$$TZZ00r   r   N)returnzDict[bytes, Any])__name__
__module____qualname____firstlineno____doc__r   r   r)   r   r5   r8   __static_attributes__ r   r   r   r   *   s&     4M1r   r   c                  <    \ rS rSrSrS rS rS rS rS r	S r
S	rg
)_statecheckh   aK  a 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                    Xl         X l        X0l        X@l        XPl        X`l        Xpl        Xl        SU l        Xl	        Xl
        Xl        Xl        Xl        g )NF)_opname_fname
_clearable_allowcommit_reportonly_continueflag	_stopflag_childopnames_delegating_cmdmsg_cmdhint_statushint	abortfunccontinuefunc)r   opnamer   	clearableallowcommit
reportonlycontinueflagstopflagchildopnamescmdmsgcmdhint
statushintrR   rS   s                 r   r   _statecheck.__init__q   sS      #'%)!) %"(r   c                    U R                   (       dR  [        S5      U R                  U R                  4-  nU R                  (       a  U[        S5      U R                  -  -   nU$ U R                   $ )zNreturns 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)rQ   r   rF   rL   )r   hints     r   	statusmsg_statecheck.statusmsg   sk     1 t||,-D ~~78DLLI Kr   c                   U R                   (       dd  U R                  (       d$  [        S5      U R                  U R                  4-  $ [        S5      U R                  U R                  U R                  4-  $ U R                   $ )zCreturns 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')rP   rL   r   rF   r   s    r   r`   _statecheck.hint   sz     }}>>EFLLLLJ  
 ) LLLLLL  }}r   c                l    U R                   (       d  [        S5      U R                  -  $ U R                   $ )z7returns the status message corresponding to the commands   %s in progress)rO   r   rF   r   s    r   msg_statecheck.msg   s(    ||&'4<<88||r   c                2    [        S5      U R                  -  $ )z=returns appropriate continue message corresponding to commands   hg %s --continue)r   rF   r   s    r   continuemsg_statecheck.continuemsg   s    $%66r   c                    U R                   S:X  a  [        US   R                  5       5      S:  $ U R                  (       a  gUR                  R                  U R                  5      $ )z@determines whether a multi-step operation is in progress
or not
   mergeNr   F)rF   lenparentsrN   r"   r8   rG   )r   r   s     r   isunfinished_statecheck.isunfinished   sP     <<8#tDz))+,q0088??4;;//r   )rI   rM   rH   rP   rO   rK   rN   rG   rF   rJ   rQ   rL   rR   rS   N)r;   r<   r=   r>   r?   r   ra   r`   rf   ri   ro   r@   rA   r   r   rC   rC   h   s%    )>  ,7	0r   rC   c                   U=(       d    / n[        U UUUUUUUUU	U
UU5      nU S:X  a  [        R                  U5        OLU H0  nU[        ;  d  M  [        R
                  " [        S5      X4-  5      e   [        R                  SU5        U [        ;   a"  [        R
                  " [        S5      U -  5      eU[        U '   g)a  this 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.
rl   s   op %s depends on unknown op %sr   s   op %s registered twiceN)rC   _unfinishedstatesappend_unfinishedstatesbynamer   r!   r   insert)rT   r   rU   rV   rW   rX   rY   rZ   r[   r\   r]   rR   rS   statecheckobjchildopnames                  r   addunfinishedrx      s    X  %2LM    /
 (K"99,,78F;PP  ( 	  M2(($$Q'@%AF%JKK&3F#r   c                    [         R                  U S 5      nU(       d"  [        R                  " [	        S5      U -  5      eXR
                  ;  a#  [        R                  " [	        S5      X4-  5      e[         U   nX#4$ )Ns   unknown op %ss   op %s does not delegate to %s)rt   getr   r!   r   rM   )rT   rw   pcs       r   _getparentandchildr}   !  st    ##FD1A$$Q'7%86%ABB//)$$./62GG
 	
 	 ,A4Kr   c              #  T  #    [        X5      u  p4UR                  (       a"  [        R                  " [	        S5      U-  5      eSUl         Sv    SUl        g! [        R
                   a-  nUR                  U:X  a  [        R
                  " U5      eUeSnAff = f! SUl        f = f7f)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}   rN   r   r!   r   ConflictResolutionRequiredrT   )r   rT   rw   r{   r|   es         r   
delegatingr   -  s      f2DA}}$$786A
 	
 AM  ++ 88{"226::	 s6   AB(A B(B,(BBB 	B%%B(c                    [        X5      u  p4UR                  =(       d    UR                  U 5      =(       a    UR                  U 5      $ )z;Returns true if both opname and childopname are unfinished.)r}   rN   ro   )r   rT   rw   r{   r|   s        r   ischildunfinishedr   L  s6     f2DAMM1Q^^D1Kq~~d7KKr   c                   [        X#5      u  pE[        XU5      (       d#  [        R                  " [	        S5      X24-  5      eUR
                  (       d"  [        R                  " [	        S5      U-  5      eUR                  X5      $ )z9Checks that childopname is in progress, and continues it.s*   child op %s of parent %s is not unfinisheds   op %s has no continue function)r}   r   r   r!   r   rS   )uir   rT   rw   r{   r|   s         r   continuechildr   S  s     f2DAT;77$$;<#$
 	
 >>$$/0;>
 	
 >>"##r   s   updates   updatestateTs   last update was interrupteds,   use 'hg update' to get a consistent checkouts   To continue:    hg update .)r   rU   r[   r\   r]   s   bisects   bisect.states   use 'hg bisect --reset's   To mark the changeset good:    hg bisect --good
To mark the changeset bad:     hg bisect --bad
To abort:                      hg bisect --reset
)r   rV   rW   r\   r]   c                    [        U R                  R                  SS5      5      n[         HI  nUR                  U;   a  M  UR                  U 5      (       d  M-  UR                  UR                  5       4s  $    g )Ns   commandss   status.skipstates)setr   
configlistrr   rF   ro   ra   )r   skipstates      r   getrepostater   y  s^    tww!!+/CDED"==D d##MM5??#455	 #r   )FFFFFNr   r   r   NN)r?   
__future__r   
contextlibtypingr   r   i18nr    r   r	   utilsr
   tr   rC   rr   rt   rx   r}   contextmanagerr   r   r   r   rA   r   r   <module>r      s  
 # 
   tA1H1 
;1 ;1|a0 a0J    M4`	  <L$  
+,=>/0 
()	>6r   