mò

¾Dc           @   s­   d  k  Z  d  k Z d  k Z d  k Z d  k Z d  k Z d  k Z d  k Z d  k Z d e	 f d „  ƒ  YZ
 d e	 f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d  S(	   Nt   FormatVersionErrorc           B   s   t  Z RS(   N(   t   __name__t
   __module__(    (    (    t+   /home/charis/jelmer/bzr/svn2bzr/dumpfile.pyR       s    t   IncrementalDumpErrorc           B   s   t  Z RS(   N(   R   R   (    (    (    R   R       s    t	   DumpEntryc           B   s5   t  Z d  Z d d d d d g Z d „  Z d „  Z RS(   s"   
    An entry in a dump file.
    t   propt   content_post   content_lent	   copy_fromt   change_fromc         C   s1   h  |  _ d |  _ d |  _ d  |  _ d  |  _ d  S(   Ni    (   t   selfR   R   R   t   NoneR	   R
   (   R   (    (    R   t   __init__*   s
    				c         C   s   d t  i |  ƒ S(   Ns   <DumpEntry %r>(   t   dictt   __repr__R   (   R   (    (    R   R   1   s    (   R   R   t   __doc__t	   __slots__R   R   (    (    (    R   R   "   s    	t   Dumpc           B   s¤   t  Z d  Z d Z e e e d „ Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z e e d	 „ Z d
 „  Z d „  Z d „  Z d „  Z e d „ Z d „  Z RS(   s…  
    That class will read a dump file and store information about it.

    Besides iterating through the entries, this class is also capable
    of providing the complete tree (a dictionary like {path: entry, ...})
    for any given revision. This is important in cases where a given
    path is not being considered, but some entry is copied from it into
    a path which is being considered.

    The mechanism used to build and store information about the whole dump
    tries to perform reasonably, without consuming an unacceptable amount
    of memory. Basically, there's an on-disk tree cache which saves a
    complete tree state (trees are path -> dump entry mappings) each 
    DEFAULT_CACHE_INTERVAL revisions, or whenever the tree contains copies of 
    previous trees. Then, whenever a tree has to be rebuilt for a given 
    revision, the largest cached tree revision before the asked revision is 
    taken, and the tree is incremented up to the asked revision. This ensures
    that the tree will never be incremented for more than 99 revisions, and
    will never "walk back" (since all trees that need copies are already
    cached).
    id   c         C   s×   t  ƒ  } d | d <d | d <d | d <| g |  _ h  |  _ h  |  _ g  |  _ | |  _ t	 i
 d ƒ |  _ t i |  i d ƒ |  _ h  |  _ g  |  _ h  d d	 <|  _ h  d	 d <|  _ | |  _ | |  _ |  i ƒ  d  S(
   Nt   adds   node-actiont   dirs	   node-kindt    s	   node-paths   -saved-treest   ci    (   R   t   rootR   t   _dumpt   _revision_indext   _revision_slicet   _revision_ordert   cache_intervalt   _tree_cache_intervalt   tempfilet   mktempt   _tree_cache_filenamet   anydbmt   opent   _tree_cachet   _tree_cache_memt   _tree_cache_mem_ordert   _path_idt   _id_patht   logt   _logt   filet   _filet   _read(   R   R*   R(   R   R   (    (    R   R   N   s$    	


								c         C   s   t  i |  i ƒ d  S(   N(   t   ost   unlinkR   R    (   R   (    (    R   t   __del__g   s    c         C   s@   |  i i d | ƒ t i t i | d ƒ ƒ |  i	 t
 | ƒ <d  S(   Ns    Saving revision %d in disk cachei   (   R   R)   t   debugt   revnot   bz2t   compresst   marshalt   dumpst   treeR#   t   str(   R   R1   R6   (    (    R   t
   _save_treej   s    c         C   s7   |  i i d | ƒ t i t i |  i t	 | ƒ ƒ ƒ S(   Ns#   Loading revision %d from disk cache(
   R   R)   R0   R1   R4   t   loadsR2   t
   decompressR#   R7   (   R   R1   (    (    R   t
   _load_treen   s    c   	      C   sS  | |  i j o# |  i i d | ƒ |  i | Sn t | ƒ |  i j o |  i | ƒ Sn d } xE |  i D]: } t
 | ƒ } | | j  o
 | j  n o
 | } qj qj Wx9 |  i D]. } | | j o
 | j  n o
 | } q² q² W| d j oN |  i i d | | f ƒ | |  i j o |  i | } qY|  i | ƒ } n |  i i d | ƒ h  } x |  i D]‚ } | | j o Pqc| | j  o] |  i | } x7 t | i | i ƒ D]  } |  i | |  i | | ƒ q«W| | j o PqåqcqcW|  i i d | ƒ t |  i ƒ d j o |  i |  i d =|  i d =n | |  i | <|  i i | ƒ | S(   Ns!   Found revision %d in memory cacheiÿÿÿÿs    Building revision %d based on %ds!   Building revision %d from scratchs   Revision %d is readyi   i    (   R1   R   R$   R)   R0   R7   R#   R;   t
   tree_revnot   cached_revno_st   intt   cached_revnoR6   R   t   current_revnoR   t   slicet   ranget   startt   stopt   entry_indext   _change_treeR   t   lenR%   t   append(	   R   R1   R@   RE   R6   R<   RA   R?   R=   (    (    R   t   _build_treer   sR    
 
 
  c         C   s   t  |  i ƒ S(   N(   t   iterR   R   (   R   (    (    R   t   __iter__œ   s    c         C   s   |  i |  i | S(   N(   R   R   R   R1   (   R   R1   (    (    R   t   get_revisionŸ   s    c         C   s/   | o | o |  i |  i | Sn t ‚ d  S(   N(   t   incrementalt   pathR   R   R   R1   t   NotImplementedError(   R   R1   RN   RM   (    (    R   t   get_revision_entries¢   s    c         C   s%   |  i | ƒ } |  i | |  i | S(   N(   R   RI   R1   R6   R   R&   RN   (   R   R1   RN   R6   (    (    R   t	   get_entry¨   s    c         C   s>   | i d j o d Sn |  i i | i ƒ |  i i | i ƒ S(   Ni    R   (   t   entryR   R   R+   t   seekR   t   read(   R   RR   (    (    R   t   get_entry_content¬   s    c         C   sR   |  i | ƒ } h  } |  i } x- | i ƒ  D] } |  i	 | | | | | <q+ W| S(   N(
   R   RI   R1   R6   t	   path_treeR'   t   id_patht   keyst   tree_path_idR   (   R   R1   R6   RW   RV   RY   (    (    R   t   get_tree²   s    	 c   	      C   sƒ   |  i | ƒ } h  } |  i } | d } xT | i	 ƒ  D]F } | | } | | j p | i | ƒ o |  i | | | | <q5 q5 W| S(   Nt   /(   R   RI   R1   R6   RV   R'   RW   RN   t   prefixRX   RY   t	   tree_patht
   startswithR   (	   R   R1   RN   R6   R\   RV   RW   R]   RY   (    (    R   t   get_dir_treeº   s    	
 
c            sU  | d } | d ‰ |  i } |  i } ˆ | j o$ t | ƒ } | | ˆ <ˆ | | <n | ˆ }	 t }
 | d j oŽˆ | j p t ‚ | | |	 <| d } d | j oUt }
 | d } t | d ƒ } |  i | ƒ } |  i | | | | _ | oS d | j o | i i | _ qJd | j o" | i i | _ | i i | _ qJn | d	 j o£ | d
 ‰  ‡  ‡ d †  } x‡ | i ƒ  D]u \ } } | | } | i# ˆ  ƒ oO | | ƒ } | | j o$ t | ƒ } | | | <| | | <n | | | | <q}q}WqþqQnP| d j o  |	 | j o t% d ˆ |	 f ‚ n | og |  i | |	 | _& d | j o | i& i | _ q¡d | j o" | i& i | _ | i& i | _ q¡n | | |	 <n£ | d j o• |	 | j o t% d ˆ |	 f ‚ n |  i | |	 } | d d	 j oD ˆ d
 ‰  x7 | i( ƒ  D]% } | | i# ˆ  ƒ o | | =qqWn | |	 =n |
 S(   Ns   node-actions	   node-pathR   s	   node-kinds   node-copyfrom-paths   node-copyfrom-revs   prop-content-lengths   text-content-lengthR   R[   c            s   t  i i ˆ |  t ˆ  ƒ ƒ S(   N(   R-   RN   t   joint	   node_pathRG   R\   (   RN   (   R\   Ra   (    R   t   relocateñ   s    t   changes*   Dump references missing node %s with id %dt   delete()   RR   t   node_actionRa   R   R&   t   path_idR'   RW   RG   t   new_idt   node_path_idt   Falset   copied_somethingR6   t   AssertionErrorRE   t	   node_kindt   Truet	   copy_pathR>   t
   copy_revnoRI   t	   copy_treeR   R	   t   buildingR   R   R   R\   Rb   t   itemsRY   t   tree_entry_indexR]   R^   t   relocated_pathR   R
   t
   tree_entryRX   (   R   R6   RR   RE   Rq   Rg   R\   Rn   R]   Rh   Rj   Rl   Rp   Rb   Rs   Re   Ro   RW   Ru   RY   Rt   Ra   Rf   (    (   R\   Ra   R   RF   Å   s|    

		





 

"
 c         C   s‘  |  i } h  } x- d d d d d g D] } t | t | ƒ <q% Wh  } d } d } t
 } h  d d <} d }	 xt o| i ƒ  } | p Pn | i ƒ  } | p qo n t ƒ  } xŽ | o† | i d d	 ƒ \ } } | d
 j o | d	 } n t | i ƒ  ƒ } | | j o t | ƒ | | <n | | | <| i ƒ  i ƒ  } q´ Wt | i d d ƒ ƒ } | o| i ƒ  i ƒ  } x
| d j oø | i d ƒ \ } } | d j p t ‚ t | i t | ƒ ƒ ƒ } | i ƒ  | i ƒ  i ƒ  } | i d ƒ \ }
 } |
 d j p t ‚ t | ƒ } | | j o  t | i | ƒ ƒ | i! | <n | i | ƒ | i! | <| i ƒ  | i ƒ  i ƒ  } qvWn | i d d ƒ | _" | i" o& | i# ƒ  | _$ | i% | i" d	 ƒ n t& |  i' ƒ } d | j o# | |  i) | | | d t ƒO} nud | j o.|  i* i+ d | d ƒ |  i* i, d t& | ƒ ƒ | |  i- |	 <t. | d	 | ƒ |  i/ |	 <|  i0 i1 |	 ƒ | p | |  i2 t& |  i- ƒ j o# t& |  i- ƒ } |  i3 |	 | ƒ n_ t& |  i4 ƒ d j o% |  i5 d } |  i4 | =|  i5 d =n | i7 ƒ  |  i4 |	 <|  i5 i1 |	 ƒ | d }	 | } | } t
 } n: d | j o, | d } | d j o t9 d | ‚ qxn |  i' i1 | ƒ qo Wd  S(   Ns   revision-numbers   content-lengths   prop-content-lengths   text-content-lengths   node-copyfrom-revi    iÿÿÿÿt   :i   R   s	   PROPS-ENDt    t   Kt   Vs	   node-pathRq   s   Revision %d reads   Tree has %d entriesi   s   svn-fs-dump-format-versiont   2s   Invalid dump format version: %s(:   R   R+   R*   t   convert_to_intt   nameRm   t   internt   revisiont   revision_indext   last_saved_lenRi   Rj   R6   R1   t   readlinet   linet   rstripR   RR   t   splitt   fieldt   valuet   lowerR>   t   gett   prop_content_lengtht   kt   lRk   RT   t   keyt   vt   v_lenR   R   t   tellR   RS   RG   R   t   current_indexRF   R)   t   infoR0   R   RA   R   R   RH   R   R8   R$   R%   t   topt   copyt   format_versionR    (   R   R”   R*   Rj   R‰   R€   R…   RŽ   R~   R1   R   RŒ   R‚   R|   RŠ   R6   R‹   R†   R{   R   RR   R   R’   (    (    R   R,   #  s¤    	  	 
 
 


$



(   R   R   R   t   DEFAULT_CACHE_INTERVALR   R   R/   R8   R;   RI   RK   RL   Rm   RP   RQ   RU   RZ   R_   Ri   RF   R,   (    (    (    R   R   5   s     				*						^(   t   optparseR   t   loggingR4   t   sysR-   R!   t   timeR2   t   StandardErrorR    R   R   R   t   objectR   (   R!   R—   R2   R    R–   R   R   R˜   R   R   R™   R-   R4   (    (    R   t   ?   s   							