
    q&f                         d dl Z d dlZddlmZ ddlmZmZmZmZ ddl	m
Z
 dZdZdZd	Zd
 ZdZg dZd ZddZ	 	 ddZ G d dej*                        Z ed      Zd Z	 	 ddZy)    N   )_)encodingerrorpycompatutil)
stringutil   s   alls   prefinalizes   postfinalizec                       fd}|S )Nc                 d    | j                   dk(  rt        j                  d       | g|i |S )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_activezactive.<locals>._active"   s<    ;;!((N  D(4(4((     )r   r   s   ` r   activer   !   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                 ^    t         j                  j                  | j                  d            S )z4Return True if the repo has an abandoned transactions   journal)ospathexistssjoin)repos    r   has_abandoned_transactionr!   >   s    77>>$**Z011r   c                 8   t         |z  }g }g }|d   }	  ||      5 }t        | |      }ddd       |D ]%  \  }
}}}|
|v s|s|j                  ||
   |f       ' |j                  ||f       t        D ]  \  }
}|j                  ||
   ||z  f         |D ]  \  }}	 |j                  |        y# 1 sw Y   xY w# t        $ rc}|j                  t        j                  k7  r<t        d      }	|	|j                  |      t        j                  |      fz  }	 | |	       Y d}~d}~ww xY w# t        $ rc}|j                  t        j                  k7  r<t        d      }	|	|j                  |      t        j                  |      fz  }	 | |	       Y d}~d}~ww xY w)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_filesr=   C   s    !;.NNJ(D.! 	:Q.vq9N	: (6 ?#![!v+vh/=>? t^,-: G)6(+Y-DEFG' 	NN8$	: 	: 77ell"./CDIIn-z/F/Fq/IJJC3K	   	ww%,,&23X.
0G0G0JKKs		sG   B> B2B> D-2B;7B> >	D*AD%%D*-	F6AFFc                 T   g fd}i }	|D ]?  }
|
\  }}}}||   }|j                  d      |j                  d      k(  }|s5|s8|s;|
|	|<   A t               }t        t        |      j	                               D ]  \  }}|	j                  |      }|-|\  }}}}d}|r||f|v } |||||       |j                  |       |s|s}|xr |df|v }	  ||d|      }|j                         |k  r2t        j                  t        d      |||j                         fz        |j                  |       |j                          	 |j                  |        |D ]Y  }
|
|v r|
\  }}}}||vr|r d	||fz         ||   }	 |xr ||f|v }|r|r |||||       n|xs |}	 |j                  |       [ d
| z  }|j#                  |      r|j                  |       |j                  |        	 D ](  \  }}|j#                  |      s|j                  |       * y# t        $ r  t        d      |z          w xY w# t        $ r Y w xY w# t        $ r Y w xY w# t        t         t        j                  f$ r |s Y (w xY w# t        t         t        j                  f$ r Y yw xY w)zrollback a transaction :
    - truncate files that have been appended to
    - restore file backups
    - delete temporary files
    c                    | j                  |      }| j                  |      }	 t        j                  |||       j                  | |f       y # t        $ r1}t        j                  |      } 	t        d      ||fz          d }~ww xY w)N
checkambigs   failed to recover %s (%s)
)r(   r   copyfiler*   IOErrorr	   r)   r   )
vfsr4   brA   filepath
backuppathexce_msgbackupfilesr-   s
           r   restore_one_backupz%_playback.<locals>.restore_one_backupy   s~    88A;XXa[
	MM*h:FQx( 	++C0E1345zAB	s   +A 	B,BBr   NF   ar@   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   )r(   setsorteddictitemsgetaddtellr   Abortr   truncatecloserC   r,   FileNotFoundErrorr%   r   )journalr-   openerr.   entriesbackupentriesr,   checkambigfilesrK   store_backupentryr7   	file_pathr8   cacherD   is_store	copy_doner4   o	bck_entryrA   fplrE   r9   targetrG   rJ   s    `                          @r   	_playbackrh   h   s    K	 L ,27/)[%X88C=FKK$44	k&+L#, I tG}**,- "1 !$$Q'	 6?3HieJ'2oE
vy+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 % $ )   %++. 	 	 Wekk* sg   A1HH? I#I/J 	J H<?	II	IIII!JJJ'&J'c                      e Zd Z	 	 	 	 	 	 	 d'dZd Zd Zed        Zed        Z	ed        Z
ed        Zd	 Zed(d       Zd Zed)d       Ze	 	 	 d*d       Zed        Zd
efdZed        Zed        Zed        Zed+d       Zd Zd Zd Zed        Zed        Zed        Zed        Zed        Zed        Z ed        Z!ed        Z"ed         Z#ed!        Z$d" Z%d# Z&d$ Z'd% Z(d& Z)y),transactionNc                    d| _         d| _        || _        || _        |j	                         }||d<   || _        || _        i | _        t               | _	        || _
        g | _        || _        g | _        |	d }	|	| _        t               | _        |
r| j                  j!                  |
       |g| _        i | _        i | _        |j)                  | j                  d      | _        g | _        i | _        d| j                  z  | _        |j)                  | j0                  d      | _        | j2                  j5                  dt6        z         t               | _        |>|j;                  | j                  |d	z         |j;                  | j0                  |d	z         i | _        i | _        d
| _         i | _!        i | _"        ||| jD                  d<   i | _#        i | _$        y)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                      y Nr   )trsuccesss     r   <lambda>z&transaction.__init__.<locals>.<lambda>  s    r   s   w+r      w   %d
i  Fs   001-userhooks)%r   _usages_report_openercopy_vfsmap_after
_offsetmaprM   	_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   r-   rY   r.   journalnameundonameafter
createmode	validator	releasefnr\   names               r   __init__ztransaction.__init__   s   6 s# !0I# #!!((9f  [[6
 !/$--?"KK(;(;TB' 12%!LL
U(:;LL,,j5.@A  " " !# "$ 7@D""#34"$ r   c                     dj                  | j                        }dt        j                  |      | j                  | j
                  fz  S )N   /z*<transaction name=%s, count=%d, usages=%d>)r(   r   r   strfromlocalr   rs   r   r   s     r   __repr__ztransaction.__repr__D  sB    yy%;!!$'KKLL?
 
 	
r   c                 >    | j                   r| j                          y y rm   )r{   _abortr   s    r   __del__ztransaction.__del__L  s    ==KKM r   c                     | j                   d u S rm   r   r   s    r   	finalizedztransaction.finalizedP  s    %%--r   c                 :    | j                   j                  g        y)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~   r*   r   s    r   
startgroupztransaction.startgroupT  s     	2r   c                 p    | j                   j                         }|D ]  \  }}| j                  ||        y)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   qr4   rc   s       r   endgroupztransaction.endgroup\  s5     KKOO 	!DAqNN1a 	!r   c                     || j                   v s*|| j                  v s|| j                  v s|| j                  v ry| j                  r!| j                  d   j                  ||f       y| j                  ||       y)z5record the state of an append-only file before updateN)rz   ry   r   r   r~   r*   r   r   fileoffsets      r   rR   ztransaction.addf  si     DNN"t&t&t&;;KKO""D&>2tV$r   c                 D   || j                   v s*|| j                  v s|| j                  v s|| j                  v ry|r|| j                  |<   n| j                   j	                  |       | j
                  j                  d||fz         | j
                  j                          y)z3add a append-only entry to memory and on-disk stateN   %s %d
)rz   ry   r   r   rR   r   r   flushr   s      r   r   ztransaction._addentryv  s     DNN"t&t&t&$*DOOD!NNt$

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

r   r   c                    | j                   rd}t        j                  |      || j                  v s|| j                  v ry|| j
                  v r|sy|r,|| j
                  vrd}|||fz  }t        j                  |      | j                  |   }|j                  |      \  }}d| j                  |fz  }	|j                  ||	      }
|j                  |      r||j                  |      }|j                  |
      }t        j                  j                  |      }t        j                   ||j"                  d       t        j$                  |||       nd}
| j'                  |||
d	f       y)
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   rz   r   ry   rw   splitr{   reljoinr   r(   r   r   dirnamer   makedirsr   rB   _addbackupentry)r   r   r   r7   
for_offsetr6   rD   r   filenamebackupfilename
backupfilerF   rG   final_dir_names                 r   	addbackupztransaction.addbackup  sD    ;;DC((--4>>!TT__%<T__$ZD72  Hd##C((--ll8$IIdO,x/HH[[.9
::dxx~H*-J  WW__Z8NMM.s~~$OMM(JBJhj%@Ar   c                     | j                   j                  |       t        | j                         dz
  | j                  |d   <   | j                  j                  d|z         | j                  j                          y)z0register a new backup entry and write it to diskr      %s %s %s %d
N)r   r*   lenr   r   r   r   )r   r^   s     r   r   ztransaction._addbackupentry  sd    ""5)$'(;(;$<q$@a! 3e ;<!r   c                 d    | j                   j                  |       | j                  |d|df       y)zregister a temporary transaction file

        Such files will be deleted when the transaction exits (on both
        failure and success).
        r   FN)r   rR   r   )r   tmpfiler7   s      r   registertmpztransaction.registertmp  s-     	G$hWe<=r   c                 0    |||||f}|| j                   |<   y)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orderr7   post_finalizer^   s           r   addfilegeneratorztransaction.addfilegenerator  s%    J 	7HmD&+U#r   c                 <    || j                   v r| j                   |= yy)z=reverse of addfilegenerator, remove a file generator functionNr   )r   r   s     r   removefilegeneratorztransaction.removefilegenerator  s%     D((($$U+ )r   c           
      X   d}|t         k(  rdx}}n|t        k(  }|t        k(  }t        | j                  j                               D ]  \  }}d}|\  }}	}
}}|r|r|r|s| j                  |   }g }	 |	D ]]  }||z  }|r| j                  ||       d}n#| j                  ||       ||f| j                  v }|j                   ||dd|             _  |
|  |D ]  }|j                           |d d = |D ]  }|j                            |S # |D ]  }|j                           w xY w)NFT)r7   rq   )
atomictemprA   )GEN_GROUP_ALLGEN_GROUP_POST_FINALIZEGEN_GROUP_PRE_FINALIZErN   r   rP   rw   r   r   r   r*   rV   discard)r   suffixgroupany	skip_postskip_preidr^   r   r   r   r7   r   rD   filesr   rA   r4   s                     r   _generatefilesztransaction._generatefiles  sm   M!#((I 77H!77I 4 4 : : <= 	 IBCAF>E9gx ]-,,x(CE % 
DFND(((A%*
th?&*H%59N9N%N
LLD$4JO
  AGGI !H  AIIK =	 @ 
   AIIK s   2BDD)c                 V    || j                   v ry| j                  j                  |      S Nr   )rz   ry   rQ   )r   r   s     r   
findoffsetztransaction.findoffset!  s&    4>>!""4((r   c                     | j                   j                  d       g }| j                   j                         D ]2  }|j                  d      \  }}|j	                  |t        |      f       4 |S )Nr       )r   seek	readlinesr   r*   int)r   rZ   rf   r   troffsets        r   readjournalztransaction.readjournal'  s`    

%%' 	2AWWU^ND(NND#h-01	2 r   c                    || j                   v r.|sy| j                   j                  |       || j                  |<   nT|| j                  v r;|s)| j                  |= | j                   j                  |       n|| j                  |<   nt	        |      | j
                  j                  d||fz         | j
                  j                          y)zn
        replace can only replace already committed entries
        that are not pending in the queue
        Nr   )rz   removery   rR   KeyErrorr   r   r   r   s      r   replaceztransaction.replace0  s     4>>!NN!!$'$*DOOD!T__$OOD)""4((.%4. 

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

r   c                     | xj                   dz  c_         | xj                  dz  c_        | j                  j                  |       | S Nr   )r   rs   r   r*   r   s     r   nestztransaction.nestF  s5    q4 r   c                     | j                   dkD  r| xj                  dz  c_        | j                  r| j                  j                          | j                   dkD  r!| j                  dk(  r| j	                          y y y )Nr   r   )r   rs   r   r   r   r   s    r   releaseztransaction.releaseM  sV    ;;?LLAL;;KKOO;;?t||q0KKM  1?r   c                      | j                   dkD  S r   )r   r   s    r   runningztransaction.runningV  s    {{Qr   c                 "    || j                   |<   y)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   
addpendingztransaction.addpendingY  s     +3h'r   c                    t        | j                        }|D ]8  } | j                  j                  |      |       }| j                  xs || _        : | xj                  | j	                  d      z  c_        | j                  S )zpwrite pending file to temporary version

        This is used to allow hooks to view a transaction before commits   .pending)r   )rN   r   r   r   r   )r   
categoriescatr   s       r   writependingztransaction.writependingc  s    
 D112
 	7C0$''++C06C#//63D	7 	D//{/CCr   c                     || j                   v S )z0check is a callback already exist for a categoryr   r   r   s     r   hasfinalizeztransaction.hasfinalizep  s     41111r   c                 "    || j                   |<   y)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   addfinalizeztransaction.addfinalizeu  s     ,4x(r   c                 "    || j                   |<   y)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   addpostcloseztransaction.addpostclose  s     -5)r   c                 :    | j                   j                  |d      S )z1return a postclose callback added before, or NoneN)r   rQ   r  s     r   getpostcloseztransaction.getpostclose  s     &&**8T::r   c                 "    || j                   |<   y)a   add 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   addabortztransaction.addabort  s     )1H%r   c                 "    || j                   |<   y)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   addvalidatorztransaction.addvalidator  s     ,4x(r   c                    | j                   dk(  rt        | j                        D ]  } | j                  |   |         d| _        | j                  t               | j
                  r=| j
                  }i | _        t        |      }|D ]  } ||   |         | j
                  r=d| _        | j                  t               | xj                   dz  c_         | j                   dk7  ry| j                  j                          | j                  j                          | j                  D ]g  \  }}}}|| j                  vr|r| j                  d||fz         /| j                  |   }	|rA|sD|	j                  |      sV	 |	j                  |       i i | _        t+               | _        | j/                          | j0                  r| j1                          d| _        | j2                  j5                  | j6                        r%| j2                  j                  | j6                         | j2                  j5                  | j8                        r%| j2                  j                  | j8                         | j                  D ]d  \  }}}}|| j                  vr|r| j                  d||fz         /| j                  |   }	|sA|	j                  |      sS	 |	j                  |       f g | _
        d| _        | j;                  | d       d| _        t        | j<                        }|D ]  } | j<                  |   |         d| _        y# t        t         t"        j$                  f$ r3}
|s | j                  d|	j'                  |      |
fz         Y d}
~
fd}
~
ww xY w# t        t         t"        j$                  f$ r3}
|s | j                  d|	j'                  |      |
fz         Y d}
~
gd}
~
ww xY w)	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   rN   r   r   r   r   r   r   rV   r   r   rw   rt   r   r,   rC   r%   r   rT   r(   ry   rM   rz   
_writeundorx   ru   isfiler   r{   r   r   )r   r   	callbacksr  r  rf   r4   rE   r9   rD   inst_fs               r   rV   ztransaction.close  st    ;;!"4#9#9: 70&&x067%)D"&<=(( 22	)+&#I.
% )C"IcN4()	 (( &*D"&=>q;;!

!-- 	JAq!Q$F!QO ,,q/Cszz!}JJqM	" ;;KKMDK<<t223LL 3 34<<t}}-LL... 	KAr1a$ !f% ,,q/CSZZ]JJqM	$ !d# D334
 	/C(D##C(.	/ #']  %++6 LL3sxx{D6II 	8  %++6 LL3sxx{D6II 	s0   >MNN(NNO&3(O!!O&c                 $    | j                          y)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   abortztransaction.abort  s    
 	r   c                 >    | j                   j                  ||f       y rm   )r|   r*   )r   vfs_idr   s      r   add_journalztransaction.add_journal  s    ""FD>2r   c                 4     j                   yt         j                   j                   j                          dt        dt        f fd}d j                   z  } j
                  j                  |d      }|j                  dt        z          j                  D ]  \  }}}}|s|sd	}nt| j                  vr|r j                  d
||fz         7 j                  |   }	 ||      }t        j                  |	j                  |      |	j                  |      d       |j                  d||||fz          |j                           j                  D ]1  \  }	}
 ||
      }|	j                  |       	 |	j!                  |
|       3 y# t"        $ r Y @w xY w)z4write transaction data for possible future undo callN)r/   fnreturnc                    t         j                  j                  |       \  }}|j                  j                        sJ |j                  j                  j                  d      }t         j                  j                  ||      S r   )r   r   r   
startswithr{   r   r}   r(   )r  baser   new_namer   s       r   r   z(transaction._writeundo.<locals>.undoname  s^    r*JD$??4==111||DMM4>>1EH77<<h//r   r   rq   rr   r   r  Tr   r   )r}   r=   rt   rw   bytesru   r   r   r   r   r   rB   r(   rV   r|   	tryunlinkrenamerW   )r   r   undo_backup_pathundobackupfilerf   r4   rE   r9   urD   srcdests   `           r   r  ztransaction._writeundo  s   >>!LLLL	
	0 	05 	0 -t~~=**+;TBWw./-- 	EJAq!QDLL(QLL #$a&) ll1oQKchhqk388A;F  !41a|!CD	E  	++ 		HCC=D MM$

3%		 % s   6F	FFc                 D   | j                         }d| _        d| _        | j                  j	                          | j
                  j	                          | j                  |      }	 |s| j                  t        d             t        | j                        D ]  } | j                  |   |         d | _
        |r| j                  |       n| j                  |       d | _        | j                  | d       d | _        y # d | _        | j                  | d       d | _        w xY w)Nr   s   transaction abort!
F)r   r   rs   r   rV   r   _can_quick_abortrt   r   rN   r   _do_quick_abort_do_full_abortr{   r   )r   rZ   quickr  s       r   r   ztransaction._abort0  s    ""$

!%%g.	#Q678d112 /(##C(./ #'D$$W-##G, DMOOD%("DO !DMOOD%("DOs   %A7C= ="Dc                 :    |ry| j                   D ]	  }|d   s	 y y)zFalse if any semantic content have been written on disk

        True if nothing, except temporary files has been writen on disk.Fr   T)r   )r   rZ   r5   s      r   r.  ztransaction._can_quick_abortH  s.     $$ 	At	 r   c                    | j                  |      sJ | j                  D cg c]
  }|d   r	| }}|D ](  \  }}}}| j                  |   }	 |j                  |       * | j
                  r%| j                  j                  | j
                         | j                  r&| j                  j                  | j                         yyc c}w # t        $ r Y w xY w)z4(Silently) do a quick cleanup (see _can_quick_abort)r   N)r.  r   rw   r,   rW   r   ru   r{   )	r   rZ   r5   	tmp_filesr  old_pathtmp_pathxxxrD   s	            r   r/  ztransaction._do_quick_abortS  s    $$W--- $ 3 3@11Q4Q@	@/8 	+FHh,,v&C

8$	 LL 3 34==LL.  A
 % s   
CCC			CCc           
         	 t        | j                  | j                  | j                  | j                  || j
                  d| j                         | j                  t        d             y# t        $ rT}| j                  t        d             | j                  t        d      t        j                  |      z         Y d}~yd}~ww xY w)z?(Noisily) rollback all the change introduced by the transactionT)r,   r\   s   rollback completed
s(   rollback failed - please run hg recover
s   (failure reason: %s)
N)rh   r{   rt   ru   rw   r   r   r   BaseExceptionr	   r)   )r   rZ   rH   s      r   r0  ztransaction._do_full_abortb  s    	## $ 5 5	 LL234 	LLGHILL+,z/F/Fs/KK 	s   A)A, ,	C	5A
CC	)NNNNNN	   <unnamed>)Tr   F)r   )r   r   F)r:  )*__name__
__module____qualname__r   r   r   propertyr   r   r   r   rR   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r	  r  r  r  r  rV   r  r  r  r   r.  r/  r0  r   r   r   rj   rj      s4    `!D
 . .   ! ! % %" ,B ,B\" > >  %, %,N , ,
 %(} *X ) )
    *  3 
  
  2 2 4 4 5 5 ; ; 1 1 4 4 O' O'b   3 3-^#0	/r   rj   s8   journal was created by a different version of Mercurial
c           	          |j                         }g }|rh|d   dd }|dt        z  k7  r | t               |S |dd D ]>  }|s|dd }|j                  d      \  }}}}	|j	                  |||t        |	      f       @ |S )aZ  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   r*   bool)
r-   re   linesr[   verlinerf   r4   rE   r9   s
             r   r$   r$   |  s     LLNEMAhsm57?#?#  ab	 =9D!%E!2JAq!Q!((!Q47);<= r   c           	      R   g }g }| j                  |      5 }|j                         }	ddd       	D ]3  }
	 |
j                  d      \  }}|j                  |t	        |      f       5 d|z  }| j                  |      r&| j                  |      5 }t        ||      }ddd       fd}|D cg c]  } ||      s| }}t        ||| ||||       y# 1 sw Y   xY w# t
        $ r*  |t        d      t        j                  |
      z         Y w xY w# 1 sw Y   }xY wc c}w )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                 .    j                  | d          S r   )match)xskip_journal_patterns    r   rp   zrollback.<locals>.<lambda>  s    177!== r   )r\   )r   r   r   r*   r   
ValueErrorr   r   bytestrr   r$   rh   )rY   r.   r   r-   r\   rI  rZ   r[   re   rB  rf   r4   rc   backupjournalkeeprH  s        `          r   rollbackrN    s3   . GM	T	 b 	775>DAqNNAs1v;' &,M}}]#[[' 	:2-fb9M	:'=$1=qT!W==''   	67(:J:J1:MM		: 	: >s4   C0C"D/D$=D$C"0DDD!)s   undo)TN)NN)r&   r   i18nr    r   r   r   r   utilsr	   r   r   r   r   r   r#   r+   r!   r=   rh   transactionalrj   r@  r$   rN  r   r   r   <module>rS     s     	   
' )     2
"X vrS
$$$ S
l @
> 5r   