
    6h                    4   S SK Jr  S SKrS SKrS SKJrJrJrJrJ	r	  SSK
Jr  SSKJrJrJrJr  SSKJrJrJrJr  SSKJr  SS	KJr  S
rSrSrSrS rSr / SQr!S r"SS jr#  SS jr$ " S S\RJ                  \RL                  5      r\" S5      r'S r(  SS jr)g)    )annotationsN)Callable
CollectionListOptionalUnion   )_)CallbackCategoryTHgPathTTransactionTVfsKeyT)encodingerrorpycompatutil)
stringutil)transaction   s   alls   prefinalizes   postfinalizec                   ^  U 4S jnU$ )Nc                h   > U R                   S:X  a  [        R                  " S5      eT" U /UQ70 UD6$ )Nr   s;   cannot use transaction when it is already committed/aborted)_countr   ProgrammingError)selfargskwdsfuncs      7/usr/lib/python3/dist-packages/mercurial/transaction.py_activeactive.<locals>._active3   s<    ;;!((N  D(4(4((     )r   r   s   ` r   activer#   2   s    ) Nr!      %s.backupfiles))   stores   %s.narrowspec)   plains   %s.narrowspec.dirstate)r&   s	   %s.branch)r&   s   %s.bookmarks)r%   s   %s.phaseroots)r&   s   %s.dirstate)r&   s   %s.desc)r%   s   %sc                ^    [         R                  R                  U R                  S5      5      $ )z4Return True if the repo has an abandoned transactions   journal)ospathexistssjoin)repos    r   has_abandoned_transactionr-   O   s    77>>$**Z011r!   c                h   [         U-  n/ n/ nUS   n U" U5       n[        X5      nSSS5        U H+  u  ppX;   d  M  U(       d  M  UR                  X   U45        M-     UR                  Xc45        [         H  u  pUR                  X   X-  45        M     U H  u  p UR                  U5        M     g! , (       d  f       N= f! [         ae  nUR                  [        R                  :w  a<  [        S5      n	XR                  U5      [        R                  " U5      4-  n	U " U	5         SnAGNSnAff = f! [         am  nUR                  [        R                  :w  aC  [        S5      n	XR                  U5      [        R                  " U5      4-  n	U " U	5         SnAGM
   SnAGM  SnAff = f)zremove "undo" files used by the rollback logic

This is useful to prevent rollback running in situation were it does not
make sense. For example after a strip.
r%   Ns   could not read %s: %s
s   error removing %s: %s
)UNDO_BACKUPread_backup_filesOSErrorerrnoENOENTr
   joinr   forcebytestrappendUNDO_FILES_MAY_NEED_CLEANUPunlink)reportvfsmapundo_prefixbackup_listingbackup_entries
undo_filessvfsfemsglocationbackup_pathc	undo_pathundovfsundofiles                   r   cleanup_undo_filesrI   T   s    !;.NNJ(D.!Q.v9N " (6#[++v/=> (6 t,-:6+Y-DEF  ;'	NN8$ ( "! 77ell"./CIIn-z/F/Fq/IJJC3K	   	ww%,,&23X.
0G0G0JKKs '	sM   C B7C !D:7
CC C 
D7AD22D7:
F1AF,,F1c                  ^^ / mUU4S jn0 n	U HN  n
U
u  ppX;   nUR                  S5      UR                  S5      :H  nU(       d  M8  U(       d  MA  U(       d  MJ  XU'   MP     [        5       n[        [        U5      R	                  5       5       H  u  nnU	R                  U5      nUb/  Uu  ppSnU(       a  X4U;   nU" X,UU5        UR                  U5        U(       d  U(       d  U=(       a    US4U;   n U" USUS9nUR                  5       U:  a3  [        R                  " [        S5      UUUR                  5       4-  5      eUR                  U5        UR                  5         M   UR                  U5        M     U Hz  n
U
U;   a  M  U
u  nnnnUU;  a  U(       a  T" S	UU4-  5        UU   n U=(       a    UU4U;   nU(       a  U(       a  U" UUUU5        M]  U=(       d    Un UR                  U5        M|     S
U -  nUR!                  U5      (       a  UR                  U5        UR                  U 5         T H/  u  nnUR!                  U5      (       d  M  UR                  U5        M1     g! [         a    T" [        S5      U-  5        e f = f! [         a     GM  f = f! [         a     GM5  f = f! [        [        R                  4 a    U(       d  e  GM_  f = f! [        [        R                  4 a     gf = f)zurollback a transaction :
- truncate files that have been appended to
- restore file backups
- delete temporary files
c                  > U R                  U5      nU R                  U5      n [        R                  " XTUS9  TR                  X45        g ! [         a1  n[
        R                  " U5      nT	" [        S5      X4-  5        e S nAff = f)N
checkambigs   failed to recover %s (%s)
)r4   r   copyfiler6   r1   r   r5   r
   )
vfsr@   brM   filepath
backuppathexce_msgbackupfilesr9   s
           r   restore_one_backup%_playback.<locals>.restore_one_backup   sx    88A;XXa[
	MM*:Fx( 	++C0E134zAB	s   'A 
B,BBr!   NF   arL   sB   attempted to truncate %s to %d bytes, but it was already %d bytes
s   failed to truncate %s
s.   couldn't handle %s: unknown cache location %s
r$   )r4   setsorteddictitemsgetaddtellr   Abortr
   truncatecloser1   r8   FileNotFoundErrorr*   )journalr9   openerr:   entriesbackupentriesr8   checkambigfilesrV   store_backupentryrC   	file_pathrD   cacherO   is_store	copy_doner@   o	bck_entryrM   fplrP   rE   targetrR   rU   s    `                          @r   	_playbackrt   y   s    K	 L27/[88C=FKK$448		kk&+#  I tG}**,-1 !$$Q'	 6?3HJ'2oE
v+zJMM)$F(HaX-HJAt
;779q=++2 a+	,  A
a A .H I
1aF?qEANOQi	(FaV-FJQ"31j9aJJv& @ #W,J}}Z  j!
MM'!FCzz!}}

1 "_  q34q89 % $ )   % 	 	 U[[! sm   6A0I2)J2)J9J9)J'<K# K# 2 J
J$#J$'
J61J95J66J99"K K #L ?L c                     \ rS rSr       S)S jrS rS r\S*S j5       r\	S+S j5       r
\	S+S j5       r\	S,S	 j5       rS
 r\	   S-         S.S jj5       rS r\	S/S0S jj5       r\	   S1             S2S jj5       r\	S3S j5       rS\4S jr\	S4S j5       r\	S5S j5       r\	S,S j5       r\	S6S7S jj5       rS+S jrS*S jr      S8S jr\	S*S j5       r\	S9S j5       r\	      S8S j5       r\	      S8S j5       r\	    S:S j5       r \	      S8S j5       r!\	      S8S j5       r"\	S+S  j5       r#\	S+S! j5       r$\	S;S" j5       r%S# r&S$ r'S% r(S& r)S' r*S(r+g)<r      Nc                   SU l         SU l        Xl        X l        UR	                  5       nX#S'   X0l        X`l        0 U l        [        5       U l	        X@l
        / U l        XPl        / U l        U	c  S n	Xl        [        5       U l        U
(       a  U R                  R!                  U
5        U/U l        0 U l        0 U l        UR)                  U R                  S5      U l        / U l        0 U l        SU R                  -  U l        UR)                  U R0                  S5      U l        U R2                  R5                  S[6        -  5        [        5       U l        Ub>  UR;                  U R                  US	-  5        UR;                  U R0                  US	-  5        0 U l        0 U l        S
U l         0 U l!        0 U l"        Ub  XRD                  S'   0 U l#        0 U l$        g)a  Begin a new transaction

Begins a new transaction that allows rolling back writes in the event of
an exception.

* `after`: called after the transaction has been committed
* `createmode`: the mode of the journal file that will be created
* `releasefn`: called after releasing (with transaction and result)

`checkambigfiles` is a set of (path, vfs-location) tuples,
which determine whether file stat ambiguity should be avoided
for corresponded files.
r	   r!   Nc                    g Nr"   )trsuccesss     r   <lambda>&transaction.__init__.<locals>.<lambda>   s    Dr!   s   w+r$      w   %d
i  Fs   001-userhooks)%r   _usages_report_openercopy_vfsmap_after
_offsetmaprY   	_newfiles_journal_journal_files	_undoname_queue
_releasefn_checkambigfilesupdate_nameschangeshookargsopen_file_backupentries
_backupmap_backupjournal_backupsfilewriteversion
_tmp_fileschmod_filegenerators_pendingcallback_anypending_finalizecallback_validatecallback_postclosecallback_abortcallback)r   r9   re   r:   journalnameundonameafter
createmode	validator	releasefnrh   names               r   __init__transaction.__init__   s   6 s# !0I# #!!((9f  [[6
 !/$--?"KK(;(;TB' 12%!LL
U(:;LL,,j5.@A  " " !# "$ 7@""#34"$ r!   c                    SR                  U R                  5      nS[        R                  " U5      U R                  U R
                  4-  $ )N   /z*<transaction name=%s, count=%d, usages=%d>)r4   r   r   strfromlocalr   r   r   r   s     r   __repr__transaction.__repr__U  sB    yy%;!!$'KKLL?
 
 	
r!   c                H    U R                   (       a  U R                  5         g g ry   )r   _abortr   s    r   __del__transaction.__del__]  s    ==KKM r!   c                    U R                   S L $ ry   r   r   s    r   	finalizedtransaction.finalizeda  s    %%--r!   c                :    U R                   R                  / 5        g)zdelay registration of file entry

This is used by strip to delay vision of strip offset. The transaction
sees either none or all of the strip actions to be done.N)r   r6   r   s    r   
startgrouptransaction.startgroupe  s     	2r!   c                p    U R                   R                  5       nU H  u  p#U R                  X#5        M     g)zapply delayed registration of file entry.

This is used by strip to delay vision of strip offset. The transaction
sees either none or all of the strip actions to be done.N)r   pop	_addentry)r   qr@   ro   s       r   endgrouptransaction.endgroupm  s,     KKOODANN1  r!   c                   XR                   ;   d-  XR                  ;   d  XR                  ;   d  XR                  ;   a  gU R                  (       a   U R                  S   R                  X45        gU R                  X5        g)z5record the state of an append-only file before updateN)r   r   r   r   r   r6   r   r   fileoffsets      r   r^   transaction.addw  s]     NN"&&&;;KKO""D>2t$r!   c                R   XR                   ;   d-  XR                  ;   d  XR                  ;   d  XR                  ;   a  gU(       a  X R                  U'   OU R                   R	                  U5        U R
                  R                  SX4-  5        U R
                  R                  5         g)z3add a append-only entry to memory and on-disk stateN   %s %d
)r   r   r   r   r^   r   r   flushr   s      r   r   transaction._addentry  sy     NN"&&&$*OOD!NNt$

~56

r!   r!   c                   U R                   (       a  Sn[        R                  " U5      eXR                  ;   d  XR                  ;   a  gXR
                  ;   a  U(       d  gU(       a-  XR
                  ;  a  SnXSU4-  n[        R                  " U5      eU R                  U   nUR                  U5      u  pxSU R                  U4-  n	UR                  Xy5      n
UR                  U5      (       av  UR                  U5      nUR                  U
5      n[        R                  R                  U5      n[        R                   " XR"                  SS9  [        R$                  " XUS9  OSn
U R'                  X1U
S	45        g)
a  Adds a backup of the file to the transaction

Calling addbackup() creates a hardlink backup of the specified file
that is used to recover the file in the event of the transaction
aborting.

* `file`: the file path, relative to .hg/store
* `hardlink`: use a hardlink to quickly create the backup

If `for_offset` is set, we expect a offset for this file to have been previously recorded
s/   cannot use transaction.addbackup inside "group"NzKcalling `addbackup` with `for_offmap=True`, but no offset recorded: [%r] %rs   %s.backup.%s.bckT)mode
notindexedhardlinkr!   F)r   r   r   r   r   r   r   splitr   reljoinr*   r4   r(   r)   dirnamer   makedirsr   rN   _addbackupentry)r   r   r   rC   
for_offsetrB   rO   r   filenamebackupfilename
backupfilerQ   rR   final_dir_names                 r   	addbackuptransaction.addbackup  s3   & ;;DC((-->>!T__%<__$ZD72  d##C((--ll8$IIdO,x/HH[[9
::dxx~H*-J  WW__Z8NMM.~~$OMM(BJhj%@Ar!   c                    U R                   R                  U5        [        U R                   5      S-
  U R                  US   '   U R                  R                  SU-  5        U R                  R                  5         g)z0register a new backup entry and write it to diskr	      %s %s %s %d
N)r   r6   lenr   r   r   r   )r   rj   s     r   r   transaction._addbackupentry  sd    ""5)$'(;(;$<q$@a! 3e ;<!r!   c                d    U R                   R                  U5        U R                  USUS45        g)z|register a temporary transaction file

Such files will be deleted when the transaction exits (on both
failure and success).
r!   FN)r   r^   r   )r   tmpfilerC   s      r   registertmptransaction.registertmp  s-     	G$hWe<=r!   c                *    XBX5U4nXpR                   U'   g)a  add a function to generates some files at transaction commit

The `genfunc` argument is a function capable of generating proper
content of each entry in the `filename` tuple.

At transaction close time, `genfunc` will be called with one file
object argument per entries in `filenames`.

The transaction itself is responsible for the backup, creation and
final write of such file.

The `genid` argument is used to ensure the same set of file is only
generated once. Call to `addfilegenerator` for a `genid` already
present will overwrite the old entry.

The `order` argument may be used to control the order in which multiple
generator will be executed.

The `location` arguments may be used to indicate the files are located
outside of the the standard directory for transaction. It should match
one of the key of the `transaction.vfsmap` dictionary.

The `post_finalize` argument can be set to `True` for file generation
that must be run after the transaction has been finalized.
Nr   )r   genid	filenamesgenfuncorderrC   post_finalizerj   s           r   addfilegeneratortransaction.addfilegenerator  s    J 7mD&+U#r!   c                >    XR                   ;   a  U R                   U	 gg)z=reverse of addfilegenerator, remove a file generator functionNr   )r   r   s     r   removefilegeneratortransaction.removefilegenerator  s#     ((($$U+ )r!   c                   SnU[         :X  a  S=pEOU[        :H  nU[        :H  n[        U R                  R                  5       5       H  u  pgSnUu  ppnU(       a	  U(       a  M  U(       a	  U(       d  M-  U R                  U   n/ n U	 HW  nX-  nU(       a  U R                  XS9  SnOU R                  XS9  X4U R                  ;   nUR                  U" USSUS95        MY     U
" U6   U H  nUR                  5         M     US S 2	 U H  nUR                  5         M     M     U$ ! U H  nUR                  5         M     f = f)NFT)rC   r~   )
atomictemprM   )GEN_GROUP_ALLGEN_GROUP_POST_FINALIZEGEN_GROUP_PRE_FINALIZErZ   r   r\   r   r   r   r   r6   rb   discard)r   suffixgroupany	skip_postskip_preidrj   r   r   r   rC   r   rO   filesr   rM   r@   s                     r   _generatefilestransaction._generatefiles  sF   M!#((I 77H!77I 4 4 : : <=IBCAF>Eg ]-,,x(CE %DND(((A%*
t?&*%59N9N%N
LLD$4JO & AGGI  !HAIIK = >@ 
 AIIK s   B D$$D?c                X    XR                   ;   a  gU R                  R                  U5      $ Nr   )r   r   r]   )r   r   s     r   
findoffsettransaction.findoffset8  s$    >>!""4((r!   c                    U R                   R                  S5        / nU R                   R                  5        H2  nUR                  S5      u  p4UR	                  U[        U5      45        M4     U$ )Nr       )r   seek	readlinesr   r6   int)r   rf   rr   r   troffsets        r   readjournaltransaction.readjournal>  sY    

%%'AWWU^NDNND#h-01 ( r!   c                   XR                   ;   a2  U(       d  gU R                   R                  U5        X R                  U'   OYXR                  ;   a?  U(       d)  U R                  U	 U R                   R                  U5        OX R                  U'   O[	        U5      eU R
                  R                  SX4-  5        U R
                  R                  5         g)zV
replace can only replace already committed entries
that are not pending in the queue
Nr   )r   remover   r^   KeyErrorr   r   r   r   s      r   replacetransaction.replaceG  s     >>!NN!!$'$*OOD!__$OOD)""4((.%4. 

~56

r!   c                    U =R                   S-  sl         U =R                  S-  sl        U R                  R                  U5        U $ Nr	   )r   r   r   r6   r   s     r   nesttransaction.nest]  s5    q4 r!   c                   U R                   S:  a  U =R                  S-  sl        U R                  (       a  U R                  R                  5         U R                   S:  a"  U R                  S:X  a  U R	                  5         g g g )Nr   r	   )r   r   r   r   r   r   s    r   releasetransaction.released  sV    ;;?LLAL;;KKOO;;?t||q0KKM  1?r!   c                     U R                   S:  $ r  )r   r   s    r   runningtransaction.runningm  s    {{Qr!   c                     X R                   U'   g)zadd a callback to be called when the transaction is pending

The transaction will be given as callback's first argument.

Category is a unique identifier to allow overwriting an old callback
with a newer callback.
N)r   r   categorycallbacks      r   
addpendingtransaction.addpendingp  s     +3h'r!   c                   [        U R                  5      nU H>  nU R                  R                  U5      " U 5      nU R                  =(       d    UU l        M@     U =R                  U R	                  SS9-  sl        U R                  $ )zhwrite pending file to temporary version

This is used to allow hooks to view a transaction before commits   .pending)r   )rZ   r   r   r   r   )r   
categoriescatr   s       r   writependingtransaction.writepending~  sy    
 D112
C''++C06C#//63D  	D//{/CCr!   c                    XR                   ;   $ )z0check is a callback already exist for a categoryr   r   r  s     r   hasfinalizetransaction.hasfinalize  s     1111r!   c                     X R                   U'   g)zadd a callback to be called when the transaction is closed

The transaction will be given as callback's first argument.

Category is a unique identifier to allow overwriting old callbacks with
newer callbacks.
Nr   r  s      r   addfinalizetransaction.addfinalize  s     ,4x(r!   c                     X R                   U'   g)zadd or replace a callback to be called after the transaction closed

The transaction will be given as callback's first argument.

Category is a unique identifier to allow overwriting an old callback
with a newer callback.
N)r   r  s      r   addpostclosetransaction.addpostclose  s     -5)r!   c                :    U R                   R                  US5      $ )z1return a postclose callback added before, or NoneN)r   r]   r)  s     r   getpostclosetransaction.getpostclose  s     &&**8T::r!   c                     X R                   U'   g)zadd a callback to be called when the transaction is aborted.

The transaction will be given as the first argument to the callback.

Category is a unique identifier to allow overwriting an old callback
with a newer callback.
N)r   r  s      r   addaborttransaction.addabort  s     )1H%r!   c                     X R                   U'   g)zadds a callback to be called when validating the transaction.

The transaction will be given as the first argument to the callback.

callback should raise exception if to abort transactionN)r   r  s      r   addvalidatortransaction.addvalidator  s     ,4x(r!   c                d   U R                   S:X  a  [        U R                  5       H  nU R                  U   " U 5        M     SU l        U R                  [        S9  U R
                  (       aD  U R
                  n0 U l        [        U5      nU H  nX$   " U 5        M     U R
                  (       a  MD  SU l        U R                  [        S9  U =R                   S-  sl         U R                   S:w  a  gU R                  R                  5         U R                  R                  5         U R                   H~  u  pVpxXPR                  ;  a  U(       a  U R                  SXu4-  5        M3  U R                  U   n	U(       a  MK  U(       d  MT  U	R                  U5      (       d  Ml   U	R                  U5        M     0 U l        [)        5       U l        U R-                  5         U R.                  (       a  U R/                  5         SU l        U R0                  R3                  U R4                  5      (       a%  U R0                  R                  U R4                  5        U R0                  R3                  U R6                  5      (       a%  U R0                  R                  U R6                  5        U R                   Hu  u  p[pxXPR                  ;  a  U(       a  U R                  SXu4-  5        M3  U R                  U   n	U(       d  MK  U	R                  U5      (       d  Mc   U	R                  U5        Mw     / U l
        SU l        U R9                  U S5        SU l        [        U R:                  5      nU H  nU R:                  U   " U 5        M     SU l        g! [        [         R"                  4 a9  n
U(       d  e U R                  SU	R%                  U5      U
4-  5         Sn
A
GM  Sn
A
ff = f! [        [         R"                  4 a9  n
U(       d  e U R                  SU	R%                  U5      U
4-  5         Sn
A
GM  Sn
A
ff = f)	zcommit the transactionr	   N)r   r   s.   couldn't remove %s: unknown cache location %s
s   couldn't remove %s: %s
-   couldn't remove %s: unknown cache location%s
T)r   rZ   r   r   r   r   r   r   rb   r   r   r   r   r*   r8   r1   r   r`   r4   r   rY   r   
_writeundor   r   isfiler   r   r   r   )r   r  	callbacksr$  r%  rr   r@   rP   rE   rO   inst_fs               r   rb   transaction.close  sR    ;;!"4#9#9:&&x06 ;%)D"&<=(( 22	)+&#I.
%CN4( &	 ((( &*D"&=>q;;!

!--JA!$F!O ,,q/C1szz!}}JJqM ." ;;KKMDK<<t2233LL 3 34<<t}}--LL...KA1$ f% ,,q/CqSZZ]]JJqM /$ !d# D334
C##C(.  #']  - LL3sxx{D6II 	8  - LL3sxx{D6II 	s0   NOO -OOP/6-P**P/c                $    U R                  5         g)zabort the transaction (generally called on error, or when the
transaction is not explicitly committed before going out of
scope)N)r   r   s    r   aborttransaction.abort$  s    
 	r!   c                <    U R                   R                  X45        g ry   )r   r6   )r   vfs_idr)   s      r   add_journaltransaction.add_journal+  s    ""F>2r!   c                <  ^  T R                   c  g[        T R                  T R                  T R                   S9  SU 4S jjnST R                   -  nT R                  R                  US5      nUR                  S[        -  5        T R                   H  u  pEpgU(       d  M  U(       d  SnOyUT R                  ;  a  U(       a  T R                  SXd4-  5        MG  T R                  U   n	U" U5      n[        R                  " U	R                  U5      U	R                  U5      S	S
9  UR                  SXEX4-  5        M     UR                  5         T R                   H0  u  pU" U
5      nU	R                  U5         U	R                  X5        M2     g! [          a     MB  f = f)z4write transaction data for possible future undo callN)r;   c                  > [         R                  R                  U 5      u  pUR                  TR                  5      (       d   eUR                  TR                  TR                  S5      n[         R                  R                  X5      $ r  )r(   r)   r   
startswithr   r  r   r4   )fnbaser   new_namer   s       r   r   (transaction._writeundo.<locals>.undoname9  s]    r*JD??4==1111||DMM4>>1EH77<<//r!   r$   r~   r   r!   r<  Tr   r   )rM  bytesreturnrQ  )r   rI   r   r   r   r   r   r   r   r   rN   r4   rb   r   	tryunlinkrenamerc   )r   r   undo_backup_pathundobackupfilerr   r@   rP   rE   urO   srcdests   `           r   r=  transaction._writeundo/  sg   >>!LLLL	
	0 -t~~=**+;TBWw./--JA!DLL(QLL #$&) ll1oQKchhqk388A;F  !4a|!CD .  	++HCC=D MM$

3% , % s   7F
FFc                \   U R                  5       nSU l        SU l        U R                  R	                  5         U R
                  R	                  5         U R                  U5      n U(       d  U R                  [        S5      5        [        U R                  5       H  nU R                  U   " U 5        M     S U l
        U(       a  U R                  U5        OU R                  U5        S U l        U R                  U S5        S U l        g ! S U l        U R                  U S5        S U l        f = f)Nr   s   transaction abort!
F)r  r   r   r   rb   r   _can_quick_abortr   r
   rZ   r   _do_quick_abort_do_full_abortr   r   )r   rf   quickr%  s       r   r   transaction._abort^  s    ""$

!%%g.	#Q678d112##C(. 3 #'D$$W-##G, DMOOD%("DO !DMOOD%("DOs   %BD	 	"D+c                R    U(       a  gU R                    H  nUS   (       d  M    g   g)zyFalse if any semantic content have been written on disk

True if nothing, except temporary files has been writen on disk.Fr	   T)r   )r   rf   rA   s      r   r\  transaction._can_quick_abortv  s+     $$Att % r!   c                   U R                  U5      (       d   eU R                   Vs/ s H  o"S   (       a  M  UPM     nnU H'  u  pEpgU R                  U   n UR                  U5        M)     U R
                  (       a%  U R                  R                  U R
                  5        U R                  (       a&  U R                  R                  U R                  5        ggs  snf ! [         a     M  f = f)z4(Silently) do a quick cleanup (see _can_quick_abort)r	   N)r\  r   r   r8   rc   r   r   r   )	r   rf   rA   	tmp_filesrG  old_pathtmp_pathxxxrO   s	            r   r]  transaction._do_quick_abort  s    $$W---- $ 3 3@ 31Q4Q 3	@/8+Fh,,v&C

8$ 09 LL 3 34==LL.  A
 % s   CCC  
C.-C.c                    [        U R                  U R                  U R                  U R                  UU R
                  SU R                  S9  U R                  [        S5      5        g! [         aU  nU R                  [        S5      5        U R                  [        S5      [        R                  " U5      -  5         SnAgSnAff = f)z?(Noisily) rollback all the change introduced by the transactionT)r8   rh   s   rollback completed
s(   rollback failed - please run hg recover
s   (failure reason: %s)
N)rt   r   r   r   r   r   r   r
   BaseExceptionr   r5   )r   rf   rS   s      r   r^  transaction._do_full_abort  s    	## $ 5 5	 LL234 	LLGHILL+,z/F/Fs/KK 	s   A&A) )
C3ACC)r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )NNNNNN	   <unnamed>)rR  bool)rR  None)r   r   r   r
  rR  rn  )Tr!   F)
r   r   r   rm  rC   r   r   zUnion[bool, int]rR  rn  )r!   )r   r   rC   r   rR  rn  )r   r!   F)r   rQ  r   zCollection[HgPathT]r   r   r   r
  rC   r   r   rm  rR  rn  )r   rQ  rR  rn  )r   r   rR  zOptional[int])rR  zList[itxn.JournalEntryT])rl  )r   rQ  rR  r   )r  r   r   zCallable[[TransactionT], None]rR  rn  )r  r   rR  rm  )r  r   rR  z(Optional[Callable[[TransactionT], None]])rG  r   r)   r   rR  rn  ),__name__
__module____qualname____firstlineno__r   r   r   propertyr   r#   r   r   r^   r   r   r   r   r   r   r   r   r  r  r  r  r  r  r!  r&  r*  r-  r0  r3  r6  r9  rb   rD  rH  r=  r   r\  r]  r^  __static_attributes__r"   r!   r   r   r      sV    `!D
 . .   ! ! % %"  ',2B2B 2B 	2B
 %2B 
2B 2Bh" > >  #%,%, '%, 	%,
 %, %, %, 
%, %,N , ,
 %(} *X ) )
    *  3#3 13 
	3 
  
  2 2 4#4 14 
	4 4 5#5 15 
	5 5 ;#; 
2; ; 1#1 11 
	1 1 
4#
4 1
4 
	
4 
4 O' O'b   3 3-^#0	/r!   r   s8   journal was created by a different version of Mercurial
c           	        UR                  5       n/ nU(       an  US   SS nUS[        -  :w  a  U " [        5        U$ USS  HB  nU(       d  M  USS nUR                  S5      u  pgpUR	                  XgU[        U	5      45        MD     U$ )aB  parse an (already open) backup file an return contained backup entries

entries are in the form: (location, file, backupfile, xxx)

:location:   the vfs identifier (vfsmap's key)
:file:       original file path (in the vfs)
:backupfile: path of the backup (in the vfs)
:cache:      a boolean currently always set to False
r   Nr   s   %dr	   r  )r	  r   BAD_VERSION_MSGr   r6   rm  )
r9   rq   linesrg   verlinerr   r@   rP   rE   s
             r   r0   r0     s     LLNEMAhsm57?#?#  ab	49D!%E!2JA!!((!47);< " r!   c           
       ^ / n/ nU R                  U5       nUR                  5       n	SSS5        W	 H3  n
 U
R                  S5      u  pUR                  U[	        U5      45        M5     SU-  nU R                  U5      (       a%  U R                  U5       n[        X85      nSSS5        Tb&  U4S jnU Vs/ s H  o" U5      (       d  M  UPM     nn[        UUU UUUUS9  g! , (       d  f       N= f! [
         a,    U" [        S5      [        R                  " U
5      -  5         M  f = f! , (       d  f       N= fs  snf )a_  Rolls back the transaction contained in the given file

Reads the entries in the specified file, and the corresponding
'*.backupfiles' file, to recover from an incomplete transaction.

* `file`: a file containing a list of entries, specifying where
to truncate each file.  The file should contain a list of
file offset pairs, delimited by newlines. The corresponding
'*.backupfiles' file should contain a list of file backupfile
pairs, delimited by  .

`checkambigfiles` is a set of (path, vfs-location) tuples,
which determine whether file stat ambiguity should be avoided at
restoring corresponded files.
Nr  s    couldn't read journal entry %r!
r$   c                6   > TR                  U S   5      (       + $ r  )match)xskip_journal_patterns    r   r|   rollback.<locals>.<lambda>  s    177!==r!   )rh   )r   r	  r   r6   r
  
ValueErrorr
   r   bytestrr*   r0   rt   )re   r:   r   r9   rh   r~  rf   rg   rq   rw  rr   r@   ro   backupjournalkeepr}  s        `          r   rollbackr    s    . GM	T	b 
	775>DANNAs1v;'  &,M}}]##[['2-f9M ('=$1=MqT!WM='' 
	  	67(:J:J1:MM	 (' >s4   C"/C3D,6D=
D="
C032D)(D),
D:)s   undo)TN)NN)*
__future__r   r2   r(   typingr   r   r   r   r   i18nr
   interfaces.typesr   r   r   r    r   r   r   r   utilsr   
interfacesr   itxnr   r   r   r   r#   r/   r7   r-   rI   rt   transactionalITransactionrv  r0   r  r"   r!   r   <module>r     s    #  	      +
' )     2
"X vrp
$$$d&7&7 p
f @
> 5r!   