
    q&f~                     0   d dl Z d dlZd dlZd dlZddlmZmZ ddlmZ ddl	m
Z
mZmZ ddlmZ ddlmZ e j"                  Zej&                  Zej*                  Zej.                  Zej2                  ZdZd	Zd	Zd
ZdZdZ dZ!dZ"dZ#dZ$dZ%dZ&dZ'dZ(dZ)dZ*dZ+dZ,dZ- ej\                  dd       G d d             Z/d Z0 G d d       Z1 G d! d"e1      Z2 G d# d$e2      Z3 G d% d&e1      Z4ejj                  fd'Z6d( Z7 G d) d*e2      Z8 G d+ d,e8      Z9d- Z:d. Z;d/ Z<y)0    N   )nullrevsha1nodeconstants)attr)errorrevlogutilsutil)nodemap)	constants                @         i   i   i   i   i    i @  i   TF)slotsinitc                   &   e Zd ZdZ ej
                         Z ej
                         Z ej
                         Z ej
                         Z	 ej
                         Z
 ej
                         Z ej
                         Z ej
                         Z ej
                         Z ej
                         Z	 	 	 	 	 	 	 	 d#dZed        Zed        Zd Zd Zd Zd	 Zd
 Zed        Zed        Zed        Zd Zed        Zed        Zed        Z e jB                  d        Z"ed        Z#ed        Z$e$jB                  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  Z0d! Z1d" Z2y)$DirstateItema  represent a dirstate entry

    It hold multiple attributes

    # about file tracking
    - wc_tracked: is the file tracked by the working copy
    - p1_tracked: is the file tracked in working copy first parent
    - p2_info: the file has been involved in some merge operation. Either
               because it was actually merged, or because the p2 version was
               ahead, or because some rename moved it there. In either case
               `hg status` will want it displayed as modified.

    # about the file state expected from p1 manifest:
    - mode: the file mode in p1
    - size: the file size in p1

    These value can be set to None, which mean we don't have a meaningful value
    to compare with. Either because we don't really care about them as there
    `status` is known without having to look at the disk or because we don't
    know these right now and a full comparison will be needed to find out if
    the file is clean.

    # about the file state on disk last time we saw it:
    - mtime: the last known clean mtime for the file.

    This value can be set to None if no cachable state exist. Either because we
    do not care (see previous section) or because we could not cache something
    yet.
    Nc	                    || _         || _        || _        || _        || _        d | _        d | _        d | _        d | _        d| _	        |d}d}n|d   d}|r|d   | _        |d   | _        |r|d   \  | _        | _        | _	        y y )NFr   r   r   )
_wc_tracked_p1_tracked_p2_info_fallback_exec_fallback_symlink_mode_size_mtime_s	_mtime_ns_mtime_second_ambiguous)	self
wc_tracked
p1_trackedp2_infohas_meaningful_datahas_meaningful_mtimeparentfiledatafallback_execfallback_symlinks	            8/usr/lib/python3/dist-packages/mercurial/pure/parsers.py__init__zDirstateItem.__init__l   s     &%+!1

',$!#( "'A&#( '*DJ'*DJ
 q!	,	      c                    t        |t        z        }t        |t        z        }d}|t        z  rd}d}d}|t        z  r	|t
        z  }d}	|t        z  r	|t        z  }	|rSt        j                  dk(  sJ |t        z  rd}nd}|t        z  r|t        j                  z  }n|t        j                  z  }|t        z  }
 | t        |t        z        t        |t         z        t        |t"        z        |||||||
ff||	      S )z,Build a new DirstateItem object from V2 dataNFr   i  i  )r&   r'   r(   r)   r*   r+   r,   r-   )boolDIRSTATE_V2_HAS_MODE_AND_SIZEDIRSTATE_V2_HAS_MTIME&DIRSTATE_V2_EXPECTED_STATE_IS_MODIFIEDDIRSTATE_V2_HAS_FALLBACK_EXECDIRSTATE_V2_FALLBACK_EXEC DIRSTATE_V2_HAS_FALLBACK_SYMLINKDIRSTATE_V2_FALLBACK_SYMLINKstatS_IXUSRDIRSTATE_V2_MODE_EXEC_PERMDIRSTATE_V2_MODE_IS_SYMLINKS_IFLNKS_IFREG"DIRSTATE_V2_MTIME_SECOND_AMBIGUOUSDIRSTATE_V2_WDIR_TRACKEDDIRSTATE_V2_P1_TRACKEDDIRSTATE_V2_P2_INFO)clsflagssizemtime_smtime_nshas_mode_sizer*   moder,   r-   second_ambiguouss              r.   from_v2_datazDirstateItem.from_v2_data   s%    U%BBC#E,A$AB::: "M#( 00!$==M33$'CC<<5(((1122$$ #EEE$<<=E$::;!445 -!5 $(<L(MN'-	
 		
r0   c           	      `   |dk(  r | ddd      S |dk(  r	 | d      S |dk(  r*|t         k(  rd}d}n|t        k(  rd}d}nd}d} | ||      S |d	k(  rO|t        k(  r
 | dd
      S |t         k(  r
 | dd      S |t        k(  r | ddd||df      S  | dd|||ddff      S t        d|z        )zBuild a new DirstateItem object from V1 data

        Since the dirstate-v1 format is frozen, the signature of this function
        is not expected to change, unlike the __init__ one.
           mT)r&   r'   r(      a)r&      rF)r'   r(      n)r&   r(   )r&   r'   )*   r   F)r&   r'   r*   r+   r   )r&   r'   r+   s   unknown state: %s)	NONNORMALFROM_P2AMBIGUOUS_TIMERuntimeError)rD   staterJ   rF   mtimer'   r(   s          r.   from_v1_datazDirstateItem.from_v1_data   s     D=$4FFd]$''d]y !
"
!
*g>>d]wdD99"dt<<.(##).$($#?	  ##$($50A#B  3e;<<r0   c                      d| _         d| _        y)zMark a file as "possibly dirty"

        This means the next status call will have to actually check its content
        to make sure it is correct.
        N)r"   r#   r%   s    r.   set_possibly_dirtyzDirstateItem.set_possibly_dirty   s     r0   c                 f    d| _         d| _        || _        || _        |\  | _        | _        | _        y)aq  mark a file as "clean" cancelling potential "possibly dirty call"

        Note: this function is a descendant of `dirstate.normal` and is
        currently expected to be call on "normal" entry only. There are not
        reason for this to not change in the future as long as the ccode is
        updated to preserve the proper state of the non-normal files.
        TN)r   r   r    r!   r"   r#   r$   )r%   rJ   rF   rX   s       r.   	set_cleanzDirstateItem.set_clean   s5      

FKCt~t'Cr0   c                 .    d| _         d| _        d| _        y)zumark a file as tracked in the working copy

        This will ultimately be called by command like `hg add`.
        TN)r   r"   r#   r[   s    r.   set_trackedzDirstateItem.set_tracked   s    
  
 r0   c                 J    d| _         d| _        d| _        d| _        d| _        y)zzmark a file as untracked in the working copy

        This will ultimately be called by command like `hg remove`.
        FN)r   r    r!   r"   r#   r[   s    r.   set_untrackedzDirstateItem.set_untracked  s(    
 !

r0   c                 d    | j                   r$d| _         d| _        d| _        d| _        d| _        yy)zremove all "merge-only" information from a DirstateItem

        This is to be call by the dirstatemap code when the second parent is dropped
        FN)r   r    r!   r"   r#   r[   s    r.   drop_merge_datazDirstateItem.drop_merge_data  s3    
 ==!DMDJDJ DM!DN r0   c                 "    | j                         S N)_v1_moder[   s    r.   rJ   zDirstateItem.mode$      }}r0   c                 "    | j                         S rf   )_v1_sizer[   s    r.   rF   zDirstateItem.size(  rh   r0   c                 "    | j                         S rf   )	_v1_mtimer[   s    r.   rX   zDirstateItem.mtime,  s    ~~r0   c                     | j                   }|y| j                  }|\  }}}||k7  ry|dk(  s|dk(  r| j                  ryy||k(  S )NFr   T)r"   r#   r$   )r%   other_mtimeself_secself_ns	other_secother_nsrK   s          r.   mtime_likely_equal_toz"DirstateItem.mtime_likely_equal_to0  sb    ==..0;-	8-y ]gl ++  h&&r0   c                 <    | j                   sy| j                         S )a\  
        States are:
          n  normal
          m  needs merging
          r  marked for removal
          a  marked for addition

        XXX This "state" is a bit obscure and mostly a direct expression of the
        dirstatev1 format. It would make sense to ultimately deprecate it in
        favor of the more "semantic" attributes.
           ?)any_tracked	_v1_stater[   s    r.   rW   zDirstateItem.stateF  s     ~~r0   c                     | j                   duS )a  True if "fallback" information are available for the "exec" bit

        Fallback information can be stored in the dirstate to keep track of
        filesystem attribute tracked by Mercurial when the underlying file
        system or operating system does not support that property, (e.g.
        Windows).

        Not all version of the dirstate on-disk storage support preserving this
        information.
        Nr   r[   s    r.   has_fallback_execzDirstateItem.has_fallback_execW  s     ""$..r0   c                     | j                   S )a   "fallback" information for the executable bit

        True if the file should be considered executable when we cannot get
        this information from the files system. False if it should be
        considered non-executable.

        See has_fallback_exec for details.ry   r[   s    r.   r,   zDirstateItem.fallback_exece  s     """r0   c                 8    |d| _         yt        |      | _         y)a  control "fallback" executable bit

        Set to:
        - True if the file should be considered executable,
        - False if the file should be considered non-executable,
        - None if we do not have valid fallback data.

        See has_fallback_exec for details.N)r   r2   r%   values     r.   set_fallback_execzDirstateItem.set_fallback_execp  s     ="&D"&u+Dr0   c                     | j                   duS )a  True if "fallback" information are available for symlink status

        Fallback information can be stored in the dirstate to keep track of
        filesystem attribute tracked by Mercurial when the underlying file
        system or operating system does not support that property, (e.g.
        Windows).

        Not all version of the dirstate on-disk storage support preserving this
        information.Nr   r[   s    r.   has_fallback_symlinkz!DirstateItem.has_fallback_symlink  s     %%T11r0   c                     | j                   S )a   "fallback" information for symlink status

        True if the file should be considered executable when we cannot get
        this information from the files system. False if it should be
        considered non-executable.

        See has_fallback_exec for details.r   r[   s    r.   r-   zDirstateItem.fallback_symlink  s     %%%r0   c                 8    |d| _         yt        |      | _         y)a  control "fallback" symlink status

        Set to:
        - True if the file should be considered a symlink,
        - False if the file should be considered not a symlink,
        - None if we do not have valid fallback data.

        See has_fallback_symlink for details.N)r   r2   r}   s     r.   set_fallback_symlinkz!DirstateItem.set_fallback_symlink  s     =%)D"%)%[D"r0   c                     | j                   S )z/True is the file is tracked in the working copy)r   r[   s    r.   trackedzDirstateItem.tracked       r0   c                 R    | j                   xs | j                  xs | j                  S )z4True is the file is tracked anywhere (wc or parents)r   r   r   r[   s    r.   rv   zDirstateItem.any_tracked  s$     D4#3#3Dt}}Dr0   c                 T    | j                   xr | j                  xs | j                   S )zTrue if the file has been addedr   r[   s    r.   addedzDirstateItem.added  s'     K)9)9)JT]]$KKr0   c                 R    | j                   xr | j                  xr | j                  S )z"True if the file has been modifiedr   r[   s    r.   modifiedzDirstateItem.modified  s$     FD$4$4FFr0   c                 R    | j                   sy| j                  sy| j                  ryy)z8True if the file has a chance to be in the "clean" stateFTr   r[   s    r.   maybe_cleanzDirstateItem.maybe_clean  s)     !!]]r0   c                     | j                   S )z8True if the file is tracked in the first parent manifest)r   r[   s    r.   r'   zDirstateItem.p1_tracked  r   r0   c                 6    | j                   xr | j                  S )zvTrue if the file needed to merge or apply any input from p2

        See the class documentation for details.
        )r   r   r[   s    r.   r(   zDirstateItem.p2_info  s     1DMM1r0   c                 T    | j                    xr | j                  xs | j                  S )z!True if the file has been removedr   r[   s    r.   removedzDirstateItem.removed  s'     ###K)9)9)JT]]Kr0   c                    d}| j                   r	|t        z  }| j                  r	|t        z  }| j                  r	|t
        z  }| j                  c| j                  W|t        z  }| j                  t        j                  z  r	|t        z  }t        j                  | j                        r	|t        z  }| j                  	|t         z  }| j"                  r	|t$        z  }| j&                  |t(        z  }| j&                  r	|t*        z  }| j,                  |t.        z  }| j,                  r	|t0        z  }|| j                  xs d| j                  xs d| j2                  xs dfS )z7Returns (flags, mode, size, mtime) for v2 serializationr   )r   rA   r   rB   r   rC   r    r!   r3   rJ   r:   r;   r<   S_ISLNKr=   r"   r4   r$   r@   r   r6   r7   r   r8   r9   r#   )r%   rE   s     r.   v2_datazDirstateItem.v2_data  s?   --E++E==((E::!djj&<22Eyy4<<'33||DII&44==$**E''77E*22E""22!!-55E%%55
 tzzQ(:DNN<OaPPr0   c                     | j                   st        d      | j                  ry| j                  r| j                  ry| j
                  ryy)z.return a "state" suitable for v1 serializationuntracked itemrP   rN   rO   rQ   )rv   rV   r   r   r   r   r[   s    r.   rw   zDirstateItem._v1_state  sB     /00\\$--ZZr0   c                 6    | j                   | j                   S dS )z-return a "mode" suitable for v1 serializationr   )r    r[   s    r.   rg   zDirstateItem._v1_mode	  s    !ZZ3tzz::r0   c                 "   | j                   st        d      | j                  r| j                  r| j                  rt
        S | j                  rt        S | j                  ry| j                  rt
        S | j                  t
        S | j                  S )z-return a "size" suitable for v1 serializationr   r   )	rv   rV   r   r   r   rS   rT   r   r!   r[   s    r.   rj   zDirstateItem._v1_size  sq     /00\\d..4==]]N\\ZZZZ::r0   c                     | j                   st        d      | j                  ry| j                  t        S | j
                  rt        S | j                  st        S | j                  rt        S | j                  S )z.return a "mtime" suitable for v1 serializationr   r   )rv   rV   r   r"   rU   r   r   r$   r[   s    r.   rl   zDirstateItem._v1_mtime   sh     /00\\]]"!!]]!!!!!!))!!== r0   )FFFTTNNN)3__name__
__module____qualname____doc__r   ibr   r   r   r    r!   r"   r#   r   r   r$   r/   classmethodrL   rY   r\   r^   r`   rb   rd   propertyrJ   rF   rX   rs   rW   rz   r,   setterr   r   r-   r   r   rv   r   r   r   r'   r(   r   r   rw   rg   rj   rl    r0   r.   r   r   A   s   < $'')K$'')KtwwyHDGGIEDGGIEtwwyH	ITWWYN	%dggi  !$"L )
 )
V (= (=TL	
"        ',      / / # # . . 
2 
2 & & 1 1     E E L L G G       2 2 L L!QF;&!r0   r   c                     t        | dz        S )Ni  )int)qs    r.   gettyper   4  s    q6z?r0   c                   t   e Zd ZdZej
                  Z ej                  d      Z	 ej                  d      Z
dddddddej                  ddej                  ej                  ej                  fZej"                  d        Zej"                  d        Zd Zd Zd	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Z y)BaseIndexObjectr   s   >Q   >ir   c                 .    | j                   j                  S rf   )index_formatrF   r[   s    r.   
entry_sizezBaseIndexObject.entry_sizeR  s      %%%r0   c                     t        j                  t        j                  t        i      }t        dt        |             D ]  }| |   d   }|||<    |S )Nr      )nodemaputilNodeMapr   nullidr   rangelen)r%   r
   rns       r.   _nodemapzBaseIndexObject._nodemapV  sU    %%'8'?'?&IJq#d)$ 	AQ
AGAJ	 r0   c                     || j                   v S )z*return True if the node exist in the indexr   r%   nodes     r.   has_nodezBaseIndexObject.has_node^  s    t}}$$r0   c                      | j                   |   S )zQreturn a revision for a node

        If the node is unknown, raise a RevlogErrorr   r   s     r.   revzBaseIndexObject.revb  s     }}T""r0   c                 8    | j                   j                  |      S )zIreturn a revision for a node

        If the node is unknown, return None)r   getr   s     r.   get_revzBaseIndexObject.get_revh  s     }}  &&r0   c                 ~    dt        |       v r0t        |t        |             D ]  }| |   d   }| j                  |=  y y Nr   r   )varsr   r   r   )r%   startr   r   s       r.   _stripnodeszBaseIndexObject._stripnodesn  sF    d#5#d), %GAJMM!$% $r0   c                 <    | j                   j                  dd        y )Nr   )__dict__popr[   s    r.   clearcacheszBaseIndexObject.clearcachest  s    *d+r0   c                 F    | j                   t        | j                        z   S rf   )_lgtr   _extrar[   s    r.   __len__zBaseIndexObject.__len__w  s    yy3t{{+++r0   c                     dt        |       v rt        |       | j                  |d   <   | j                  t        |       |      }| j                  j                  |       y r   )r   r   r   _pack_entryr   append)r%   tupdatas      r.   r   zBaseIndexObject.appendz  sL    d#$'IDMM#a&!D	3/4 r0   c                 b    |d   dk(  sJ |d   dk(  sJ  | j                   j                  |d d  S )Nr   r   	   r   packr%   r   entrys      r.   r   zBaseIndexObject._pack_entry  sA    Qx1}}Qx1}}%t  %%uRay11r0   c                 v    t        |t              st        d      |dk  s|t        |       k\  rt	        |      y )Ns   expecting int indexesr   )
isinstancer   	TypeErrorr   
IndexErrorr%   is     r.   _check_indexzBaseIndexObject._check_index  s8    !S!455q5ATNQ- #r0   c                    |dk(  r| j                   S | j                  |       || j                  k\  r| j                  || j                  z
     }n-| j	                  |      }| j
                  ||| j                  z    }| j                  ||      }| j                  r0|dk(  r+t        j                  dt        |d               }|f|dd  z   }|S )Nr   r   r   )	null_itemr   r   r   _calculate_index_datar   _unpack_entryr   offset_typer   )r%   r   r   indexr   offsets         r.   __getitem__zBaseIndexObject.__getitem__  s    7>>!!		>;;q499}-D))!,E::eedoo&=>Dq$'99a ,,Q!>F	AabE!Ar0   c                     | j                   j                  |      }|ddt        j                  t        j                  t        j                  fz   }|S Nr   )r   unpackrevlog_constantsCOMP_MODE_INLINERANK_UNKNOWN)r%   r   r   r   s       r.   r   zBaseIndexObject._unpack_entry  sO    $$T*----))
 
 r0   c                 D    t         j                  }|j                  |      S )!pack header information as binary)r   INDEX_HEADERr   )r%   headerv_fmts      r.   pack_headerzBaseIndexObject.pack_header  s     --zz&!!r0   c                     | |   }t        j                  j                  |dd  }|dk(  r|t         j                  j                  d }|S )4return the raw binary string representing a revisionNr   r   )r   INDEX_ENTRY_V1r   r   rF   )r%   r   r   ps       r.   entry_binaryzBaseIndexObject.entry_binary  sM    S	++00%)<!8"//4467Ar0   N)!r   r   r   rust_ext_compatr   r   r   structcalcsizebig_int_sizeint_sizer   r   r   r   r   r	   propertycacher   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r0   r.   r   r   8  s    O#22L"6??5)Lvu%H 	
		



  		))))%%I  
& & 
 %#'%,,!2
 	"
r0   r   c                       e Zd Zd Zd Zd Zy)IndexObjectc                     t        |      | j                  z  dk(  s3J t        |      | j                  t        |      | j                  z  f       || _        t        |      | j                  z  | _        g | _        y r   )r   r   r   r   r   )r%   r   s     r.   r/   zIndexObject.__init__  sk    4y4??*a/ 	
IOOI'2
 	
/
 
I0	r0   c                      || j                   z  S rf   )r   r   s     r.   r   zIndexObject._calculate_index  s    4??""r0   c                    t        |t              r|j                  dk(  r|j                  t	        d      |j
                  }| j                  |       | j                  |       || j                  k  r0| j                  d || j                  z   | _	        || _        g | _        y | j                  d || j                  z
   | _        y Nr   s.   deleting slices only supports a:-1 with step 1)r   slicestopstep
ValueErrorr   r   r   r   r   r   r   r   s     r.   __delitem__zIndexObject.__delitem__  s    !U#166R<166;MNOOGG!tyy=$9a$//&9:DJDIDK++oDII6DKr0   N)r   r   r   r/   r   r  r   r0   r.   r  r    s    #7r0   r  c                   "    e Zd ZdZd Zd Zd Zy)PersistentNodeMapIndexObjecta  a Debug oriented class to test persistent nodemap

    We need a simple python object to test API and higher level behavior. See
    the Rust implementation for  more serious usage. This should be used only
    through the dedicated `devel.persistent-nodemap` config.
    c                 ,    t        j                  |       S )zReturn bytes containing a full serialization of a nodemap

        The nodemap should be valid for the full set of revisions in the
        index.)r   persistent_datar[   s    r.   nodemap_data_allz-PersistentNodeMapIndexObject.nodemap_data_all  s    
 **400r0   c                     | j                   y| j                  }t        j                  | | j                   | j                  | j                  j
                        \  }}dx| _         x| _        | _        |||fS )zReturn bytes containing a incremental update to persistent nodemap

        This containst the data for an append-only update of the data provided
        in the last call to `update_nodemap_data`.
        N)_nm_root
_nm_docketr   update_persistent_data_nm_max_idxtip_rev)r%   docketchangedr   s       r.   nodemap_data_incrementalz5PersistentNodeMapIndexObject.nodemap_data_incremental  sq     == #::$--!1!14??3J3J
 >BAA(4?w$$r0   c                     |Lt        j                  |      \  | _        | _        | j                  r|| _        ydx| _        x| _        | _        yy)zprovide full block of persisted binary data for a nodemap

        The data are expected to come from disk. See `nodemap_data_all` for a
        produceur of such data.N)r   
parse_datar  r  r  )r%   r  nm_datas      r.   update_nodemap_dataz0PersistentNodeMapIndexObject.update_nodemap_data  sM    
 .9.D.DW.M+DM4+}}"(EIII 04? r0   N)r   r   r   r   r  r  r  r   r0   r.   r  r    s    1% 
Jr0   r  c                   &    e Zd ZddZd Zd Zd Zy)InlinedIndexObjectc                     || _         | j                  d       | _        | j                  | j                         g | _        y rf   )r   _inline_scanr   r   )r%   r   inlines      r.   r/   zInlinedIndexObject.__init__  s4    
%%d+	$))$r0   c                    d}|dg|z  | _         d}|t        | j                        | j                  z
  k  r|| j                  z   }t        j                  d| j                  ||| j                  z          \  }||| j                   |<   |dz  }|| j                  |z   z  }|t        | j                        | j                  z
  k  r|t        | j                        k7  rt        d      |S )Nr   r   r   s   corrupted data)	_offsetsr   r   r   r   r   r   r  r  )r%   lgtoffcountr   ss         r.   r#  zInlinedIndexObject._inline_scan  s    ?C#IDMS_t66$+++E==

554==#89DQ '*e$QJE4??Q&&C S_t66 #djj/!.//r0   c                 r   t        |t              r|j                  dk(  r|j                  t	        d      |j
                  }| j                  |       | j                  |       || j                  k  r#| j                  d | | _	        || _        g | _
        y | j                  d || j                  z
   | _
        y r  )r   r	  r
  r  r  r   r   r   r   r&  r   r   s     r.   r  zInlinedIndexObject.__delitem__  s    !U#166R<166;MNOOGG!tyy= MM"1-DMDIDK++oDII6DKr0   c                      | j                   |   S rf   )r&  r   s     r.   r   z#InlinedIndexObject._calculate_index"  s    }}Qr0   Nr   )r   r   r   r/   r#  r  r   r   r0   r.   r!  r!    s    &7 r0   r!  c                     |t         j                  k(  rt        |       S |s*|t         j                  k(  rt        }nt
        } ||       d fS t        } || |      d| ffS r   )r   CHANGELOGV2parse_index_cl_v2REVLOGV2IndexObject2r  r!  )r   r$  formatrD   s       r.   parse_index2r4  &  sa    !--- &&%...CC4y$
CtVq$i''r0   c                     t        |       d fS rf   )IndexChangelogV2)r   s    r.   r0  r0  3  s    D!4''r0   c                   B    e Zd Zej                  Zd Zd Zd Zd Z	d Z
y)r2  c                 *   |dk  rt         | j                  |       || j                  k  rd}t        |      t        | |         }||d<   ||d<   ||d<   ||d<   t	        |      }| j                  ||      }|| j                  || j                  z
  <   y)z
        Replace an existing index entry's sidedata offset and length with new
        ones.
        This cannot be used outside of the context of sidedata rewriting,
        inside the transaction that creates the revision `rev`.
        r   s2   cannot rewrite entries outside of this transactionr   r      N)KeyErrorr   r   listtupler   r   )	r%   r   sidedata_offsetsidedata_lengthoffset_flagscompression_modemsgr   news	            r.   replace_sidedata_infoz"IndexObject2.replace_sidedata_info:  s     7N#?GC3-cOE#E!H&E!H&E!H(E"I%LE""3.C+.DKKdii(r0   c                     | j                   j                  |      }|d d }|d   dz  }|d   dz  dz	  }|||t        j                  fz   S )N
         r   )r   r   r   r   )r%   r   r   r   	data_compsidedata_comps         r.   r   zIndexObject2._unpack_entryX  s\      ''-Sb	HqL	bV,2	=2B2O2OPPPr0   c                 v    |d d }|d   dz  }|d   dz  dz  }|||z  fz  } | j                   j                  | S )NrE  rF  r9  r   r   )r%   r   r   r   rH  rI  s         r.   r   zIndexObject2._pack_entry_  sW    Sbz"IM	rQ1,]*,,%t  %%t,,r0   c                 0    | |   }| j                  ||      S )r   )r   r   s      r.   r   zIndexObject2.entry_binaryg  s    S	U++r0   c                 :    d}||z  }t        j                  |      )r   z9version header should go in the docket, not the index: %d)r   ProgrammingError)r%   r   rA  s      r.   r   zIndexObject2.pack_headerl  s!    Iv$$S))r0   N)r   r   r   r   INDEX_ENTRY_V2r   rC  r   r   r   r   r   r0   r.   r2  r2  7  s'    #22L/<Q-,
*r0   r2  c                       e Zd Zej                  Zej                  dej                   dz   ej                  ej                  d z   ZddZ	d Z
y)r6  Nr-  c                    | j                   j                  |      }|t        j                     |t        j                     |t        j
                     |||t        j                     |t        j                     |t        j                     |t        j                     |t        j                     |t        j                     dz  |t        j                     dz	  dz  |t        j                     fS NrF  r   )r   r   r   INDEX_ENTRY_V2_IDX_OFFSET$INDEX_ENTRY_V2_IDX_COMPRESSED_LENGTH&INDEX_ENTRY_V2_IDX_UNCOMPRESSED_LENGTHINDEX_ENTRY_V2_IDX_PARENT_1INDEX_ENTRY_V2_IDX_PARENT_2INDEX_ENTRY_V2_IDX_NODEID"INDEX_ENTRY_V2_IDX_SIDEDATA_OFFSET-INDEX_ENTRY_V2_IDX_SIDEDATA_COMPRESSED_LENGTH#INDEX_ENTRY_V2_IDX_COMPRESSION_MODEINDEX_ENTRY_V2_IDX_RANK)r%   r   r   r   itemss        r.   r   zIndexChangelogV2._unpack_entry|  s    !!((."<<="GGH"IIJ">>?">>?"<<="EEF NN "FFG!K#GGHAM"::;!
 	
r0   c                 ^   |t         j                     }|t         j                     }||k(  s	J ||f       ||k(  s	J ||f       |t         j                     |t         j                     |t         j
                     |t         j                     |t         j                     |t         j                     |t         j                     |t         j                     |t         j                     dz  |t         j                     dz  dz  z  |t         j                     f
} | j                  j                  | S rQ  )r   ENTRY_DELTA_BASEENTRY_LINK_REVENTRY_DATA_OFFSETENTRY_DATA_COMPRESSED_LENGTHENTRY_DATA_UNCOMPRESSED_LENGTHENTRY_PARENT_1ENTRY_PARENT_2ENTRY_NODE_IDENTRY_SIDEDATA_OFFSET ENTRY_SIDEDATA_COMPRESSED_LENGTHENTRY_DATA_COMPRESSION_MODEENTRY_SIDEDATA_COMPRESSION_MODE
ENTRY_RANKr   r   )r%   r   r   baselink_revr   s         r.   r   zIndexChangelogV2._pack_entry  s.   %667)889s{'T3K'{3/3/"445"??@"AAB"112"112"001"889"CCD">>?!C%EEFJ "--.
 &t  %%t,,r0   )T)r   r   r   r   INDEX_ENTRY_CL_V2r   r2  r   rj  r   r   r   r0   r.   r6  r6  s  s\    #55L 	<!1!<!<=
	

 
 !1!<!<!>
?	@ 
*-r0   r6  c                     t        |       dfS )zBlike parse_index2, but alway return a PersistentNodeMapIndexObjectN)r  )r   r$  s     r.   parse_index_devel_nodemapro    s    '-t33r0   c                 $   |d d |dd g}d}t        j                  |      }d}t        |      }||k  r\||z   }t        d|||       }	||	d   z   }||| }
d|
v r|
j	                  d      \  }
}|||
<   t        j                  |	d d  | |
<   ||k  r\|S )N   (      >cllllr       )r   r   r   _unpacksplitr   rY   )dmapcopymapstparentsr3  e_sizepos1lpos2efcs               r.   parse_dirstater    s    #2w2b	"GF__V$FDBA (f}Ir$t}-ad{tDMA:775>DAqGAJ++QrU3Q ( Nr0   c                    t               }|j                  } |dj                  |             | j                         D ]t  \  }}||v r
d|||   fz  }t	        d|j                         |j                         |j                         |j                         t        |            } ||        ||       v |j                         S )Nr0   s   %s %srs  )stringiowritejoinr\  _packrw   rg   rj   rl   r   getvalue)rw  rx  plcsr  r  r  s          r.   pack_dirstater    s    	BHHE	#((2,

 1<Q
O+AKKMJJLJJLKKMF
 	aa ;;=r0   )=ior:   r   zlibr   r   r   
thirdpartyr    r   r   r	   r
   r   r   r   BytesIOr  r   r  r   ru  compress	_compress
decompress_decompressrT   rS   rU   rA   rB   rC   r<   r=   r6   r7   r8   r9   r5   r3   r4   r@   DIRSTATE_V2_DIRECTORY DIRSTATE_V2_ALL_UNKNOWN_RECORDED DIRSTATE_V2_ALL_IGNORED_RECORDEDr*  r   r   r   r  r  r!  REVLOGV1r4  r0  r2  r6  ro  r  r  r   r0   r.   <module>r     sw   
      1 7:: 	
--MM	oo  	  "   # $  & " #)  % )/ & '  %, " #*  #*   do! o!  o!dx xv7/ 78)J; )JX(  ( V '7&?&? 
((9*; 9*x2-| 2-j4
*r0   