^c%gddlmZddlmZmZmZddlmZdZdZ dZ dZ dZ dd Z Gd d ejZedZddZd S))_)errorpycompatutil) stringutilsalls prefinalizes postfinalizecfd}|S)NcZ|jdkrtjd|g|Ri|S)Ns;cannot use transaction when it is already committed/aborted)_countrProgrammingError)selfargskwdsfuncs 7/usr/lib/python3/dist-packages/mercurial/transaction.py_activezactive.._activesJ ;!  (N tD(4(((4((()rrs` ractivers#))))) NrTNctt|D]\}} | s|s|o|df|v} ||d| } | | kr9t jt d|| | fz| | | #t$r|t d|zwxYw | |#t$rYwxYwg} |D]#\} }}}| |vr|r|d|| fz|| } |r|r| |}| |}|o|| f|v} tj||| | |ns#t$r;}t!j|}|t d||fzYd}~n3d}~wwxYw|p|} | |n#t$rYnwxYw#tt$tjf$r|sY!wxYwd|z}||r| || | | D],}||r| |-dS#tt$tjf$rYdSwxYw) Nra) checkambigsBattempted to truncate %s to %d bytes, but it was already %d bytes sfailed to truncate %s s.couldn't handle %s: unknown cache location %s sfailed to recover %s (%s) %s.backupfiles)sorteddictitemstellrAbortrtruncatecloseIOErrorunlinkFileNotFoundErrorjoinrcopyfileappendr forcebytestrOSErrorexists)journalreportopenervfsmapentries backupentriesr#checkambigfilesforfp backupfileslbcvfsfilepath backuppathexce_msgtargets r _playbackr?)stG}}**,,--1  F (HaX-HJ VAt ;;;7799q==+2a+ , A    q344q8999   a    $    K# 1a F??q? FEAN O O OQi  Q 88A;; XXa[[ ,J!Q?1J KM*h:NNNN&&q))))KKK&3C88EF1;<<5zIJJJJJJJJKaJJv&&&&(D%+.       #W,J }}Z  " j!!! MM'  ! !A}}Q ! a    ! ! Wek *     sBC  'C15D  DD6H=,F*)H* G/41G*%H*G//H7H  H HHHHII /J::KKcBeZdZ d'dZdZdZedZedZ edZ ed Z d Z ed(d Z dZed)dZe d*dZedZd efdZedZedZedZed+dZdZdZdZedZedZedZedZed Zed!Z ed"Z!ed#Z"ed$Z#d%Z$d&Z%dS), transactionN c d|_d|_||_||_|}||d<||_||_i|_t|_ ||_ ||_ g|_ | d} | |_ t|_| r|j| | g|_i|_i|_||j d|_g|_i|_d|j z|_||jd|_|jdt4z|<||j |d z||j|d zi|_i|_d |_i|_i|_ | ||j d <i|_!i|_"dS) 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. rrNcdSNr)trsuccesss rz&transaction.__init__..sDrsw+rw%d iFs 001-userhooks)#r _usages_report_openercopy_vfsmap_after _offsetmapset _newfiles_journal _undoname_queue _releasefn_checkambigfilesupdate_nameschangeshookargsopen_file_backupentries _backupmap_backupjournal _backupsfilewriteversionchmod_filegenerators_pendingcallback _anypending_finalizecallback_validatecallback_postclosecallback_abortcallback) rr,r-r. journalnameundonameafter createmode validator releasefnr1names r__init__ztransaction.__init__ss6    s   # !  00I# #  :  ! ( ( 9 9 9f   [[66 !/$-?"KK(;TBB ' 1222  ! LL U(: ; ; ; LL,j5.@ A A A " " !#"$  7@D "#3 4"$ rcZd|j}d||j|jfzS)N/z*)r%rZr rKrrss r__repr__ztransaction.__repr__s4xx $$;  K L?   rc@|jr|dSdSrE)rT_abortrs r__del__ztransaction.__del__s' =  KKMMMMM  rc|jduSrErir{s r finalizedztransaction.finalizeds%--rc:|jgdS)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)rVr'r{s r startgroupztransaction.startgroups 2rct|j}|D]\}}|||dS)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)rVpop _addentry)rqr2r3s rendgroupztransaction.endgroupsI KOO   ! !DAq NN1a  ! !rc||jvs||jvs ||jvrdS|jr$|jd||fdS|||dS)z5record the state of an append-only file before updateN)rSrQr`rVr'rrfileoffsets raddztransaction.addsw DN " "t&&t&& F ;  KO " "D&> 2 2 2 F tV$$$$$rc||jvs||jvs ||jvrdS|r ||j|<n|j||jd||fz|jdS)z3add a append-only entry to memory and on-disk stateN%s%d )rSrQr`rr^rcflushrs rrztransaction._addentrys DN " "t&&t&& F  %$*DOD ! ! N  t $ $ $ f~5666 rTrc|jrd}tj|||jvs||jvs ||jvrdS|j|}||\}}d|j|fz}| ||} | |rB| |} | | } tj | | |nd} |||| dfdS)aWAdds 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 s/cannot use transaction.addbackup inside "group"Ns %s.backup.%shardlinkrF)rVrr rSrQr`rOsplitrTreljoinr*r%rr&_addbackupentry) rrrlocationmsgr9dirnamefilenamebackupfilename backupfiler:r;s r addbackupztransaction.addbackups  ; .DC(-- - DN " "t&&t&& Fl8$IIdOO(DM8+DD[[.99 ::d   xx~~H*--J M(J B B B B BJ hj%@AAAAArc|j|t|jdz |j|d<|jd|z|jdS)z0register a new backup entry and write it to diskr %s%s%s%d N)r_r'lenr`rbrcr)rentrys rrztransaction._addbackupentry5sq ""5)))$'(;$<$E9gx ]  - ,x(CE %  DFNDO(((AAA%* th???&*H%59N%N LLD$4JOOOAGGIIII!!!H  AIIKKKK   AIIKKKK  s 8B DD:cL||jvrdS|j|SNr )rSrQget)rrs r findoffsetztransaction.findoffsets* 4> ! !1""4(((rc|jdg}|jD]>}|d\}}||t |f?|S)Nr )r^seek readlinesrr'int)rr/r6rtroffsets r readjournalztransaction.readjournalsp %%'' 2 2AWWU^^ND( NND#h--0 1 1 1 1rcj||jvr)|sdS|j|||j|<nH||jvr0|s#|j|=|j|n||j|<nt ||jd||fz|jdS)zn replace can only replace already committed entries that are not pending in the queue Nr)rSremoverQrKeyErrorr^rcrrs rreplaceztransaction.replaces 4> ! !  N ! !$ ' ' '$*DOD ! ! T_ $ $ /OD)""4(((((.%%4..  f~5666 rcz|xjdz c_|xjdz c_|j||S)Nr)r rKrZr'rws rnestztransaction.nests= q    4    rc|jdkr|xjdzc_|jr|j|jdkr!|jdkr|dSdSdS)Nr r)r rKrZrrzr{s rreleaseztransaction.releasesn ;?? LLA LL ;  KOO    ;??t|q00 KKMMMMM ?00rc|jdkSr)r r{s rrunningztransaction.runnings{Qrc||j|<dS)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)rgrcategorycallbacks r addpendingztransaction.addpendings+3h'''rct|j}|D]3}|j||}|jp||_4|xj|dzc_|jS)zpwrite pending file to temporary version This is used to allow hooks to view a transaction before commits.pending)r)rrgrrhr)r categoriescatrs r writependingztransaction.writependings D122  7 7C0$'++C0066C#/63D   D//{/CCCrc||jvS)z0check is a callback already exist for a categoryr~rrs r hasfinalizeztransaction.hasfinalizes4111rc||j|<dS)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~rs r addfinalizeztransaction.addfinalizes,4x(((rc||j|<dS)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)rkrs r addpostcloseztransaction.addpostcloses-5)))rc8|j|dS)z1return a postclose callback added before, or NoneN)rkrrs r getpostcloseztransaction.getpostclose s&**8T:::rc||j|<dS)aadd 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)rlrs raddabortztransaction.addaborts)1H%%%rc||j|<dS)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)rjrs r addvalidatorztransaction.addvalidators,4x(((rc|jdkrt|jD]}|j||d|_|t|jr:|j}i|_t|}|D]}||||j:d|_|t |xjdzc_|jdkrdS|j|j |j D]\}}}}||j vr|r| d||fz-|j |} |s|r| |rp | |j#tt t"jf$r:} |s| d| || fzYd} ~ d} ~ wwxYwi|_t+|_||jr|d|_|j|jr|j|j|j|jr|j|j|j D]\}} }}||j vr|r| d||fz-|j |} |r| |rp | |h#tt t"jf$r:} |s| d| || fzYd} ~ d} ~ wwxYwg|_ d|_||dd|_t|j}|D]}|j||d|_dS) zcommit the transactionrN)rr s.couldn't remove %s: unknown cache location %s scouldn't remove %s: %s -couldn't remove %s: unknown cache location%s T)r rrjrrrirr^r!rbr_rOrLr*r#r"r)rrr%rQrRrS _writeundorPrMisfilerarTrWrk) rr callbacksrrr6r2r7r8r9inst_fs rr!ztransaction.close"sf ;!  "4#9:: 7 70&x06666%)D "   &<  = = =( ) 2 )+&#I.. %))C"IcN4(((( ( )&*D "   &=  > > > q ;!   F  !!!-  JAq!Q $$$ F!QO,q/C  szz!}} JJqMMMM%+6LL3sxx{{D6II   ;  KKMMMDK <  t2 3 3 5 L   3 4 4 4 <  t} - - / L   . . ..  KAr1a $$$  !f%,q/C SZZ]] JJqMMMM%+6LL3sxx{{D6II !  d###D344  / /C (D #C ( . . . ."&s0(E>>G0GG=LM)/0M$$M)c.|dS)zabort the transaction (generally called on error, or when the transaction is not explicitly committed before going out of scope)N)rzr{s rabortztransaction.abortts rc|jdSd|jz}|j|d}|dtz|jD]\}}}}|s |sd}n||jvr|r|d||fz6|j|}||\} } | |j s J| | |j |jd} | | | }tj||||d |d ||||fz|dS) z4write transaction data for possible future undo callNrrIrJrrrTrr)rUrMr]rcrdr_rOrLr startswithrTrrrr&r%r!) rundo_backup_pathundobackupfiler6r2r7r8ur9basersunames rrztransaction._writeundo{s > ! F,t~=**+;TBBWw.///- E EJAq!Q  GDL((Q(LL #$a&)l1o YYq\\ dt}55;;t;;; T]DNAFFKKe,, chhqkk388A;;FFFF  !41a|!C D D D Drc |}d|_d|_|j|j |sz|jss|jr|j |j|j r|j |j  d|_ | |dd|_ dS| td t|jD]}|j||d|_t!|j |j |j|j||jd|j| tdnp#t&$rc}| td| tdt)j|zYd}~nd}~wwxYwd|_ | |dd|_ dS#d|_ | |dd|_ wxYw)Nr Fstransaction abort! r1srollback completed s(rollback failed - please run hg recover s(failure reason: %s) )rr rKr^r!rbr_rarMr#rTrWrLrrrlr?rOrX BaseExceptionrr()rr/rr<s rrzztransaction._abortsl""$$    !!!" # 4#6 &=L''(;<<<=7L'' 6664!DM OOD% ( ( ("DOOO5 LL233 4 4 4 !$"56633C,D',T2222&*#MLLL'$($9     Q6778888     QKLLMMM /00:3J33O3OO  !DM OOD% ( ( ("DOOO!DM OOD% ( ( ("DO " " " "s?AH"H5B FH G. AG)$H)G..H&H=)NNNNNNrB)Tr)r)r rF)rB)&__name__ __module__ __qualname__rtrxr|propertyrrrrrrrrrrrrrrrrrrrrrrrrrrrr!rrrzrrrrArArsG ]!]!]!]!~   ..X.  V !! V!  % % V %  BBB VBB""" >>> V> %,%,%, V%,N ,, V, %(}****X )) V)   V  V*  V 333     V   22 V2 44 V4 55 V5 ;; V; 11 V1 44 V4 O'O' VO'b  V :)#)#)#)#)#rrAs8journal was created by a different version of Mercurial c Tg}g}||5}|}dddn #1swxYwY|D]|} | d\} } || t | f@#t $r0|t dtj| zYywxYwd|z} | | r|| }|}|r|ddd} | dtzkr|tnY|ddD]N}|rJ|dd}|d\} } }}|| | |t|fOt||||||| dS) aRolls 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 fileoffset pairs, delimited by newlines. The corresponding '*.backupfiles' file should contain a list of filebackupfile 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. Nrs couldn't read journal entry %r! rr rs%drr)r]rrr'r ValueErrorrrbytestrr*rdBAD_VERSION_MSGboolr?)r-r.rr,r1r/r0r4linesr6r2r3 backupjournalverliner7r8s rrollbackrs7 GM T  b   775>>DAq NNAs1vv; ' ' ' '    F677(:J1:M:MM       &,M }}]## A [[ ' '   A(3B3-Cuw''''''!!""IAADA#CRCy%)ZZ%6%6 1a%,,aAtAww-?@@@  's;?? r s   ')$ F F F F RO #O #O #O #O #$$O #O #O #d!@ 666666r