
    6h                        S r SSKJr  SSKrSSKrSSKJrJr  SSK	J
r
Jr  SSKJr  SrSrS	rS
rSrSrSrSrSrSrSrSr\R4                  " S5      r\R4                  " S5      rS rS rSS jrS r S r!g)aa  core code for "sidedata" support

The "sidedata" are stored alongside the revision without actually being part of
its content and not affecting its hash. It's main use cases is to cache
important information related to a changesets.

The current implementation is experimental and subject to changes. Do not rely
on it in production.

Sidedata are stored in the revlog itself, thanks to a new version of the
revlog. The following format is currently used::

    initial header:
        <number of sidedata; 2 bytes>
    sidedata (repeated N times):
        <sidedata-key; 2 bytes>
        <sidedata-entry-length: 4 bytes>
        <sidedata-content-sha1-digest: 20 bytes>
        <sidedata-content; X bytes>
    normal raw text:
        <all bytes remaining in the rawtext>

This is a simple and effective format. It should be enough to experiment with
the concept.
    )annotationsN   )errorrequirements)	constantsflagutil)hashutil                     	   
         z>Hz>HL20sc           	        [        U R                  5       5      n U R                  5         [        R	                  [        U 5      5      /nU  HX  u  p#[        R                  " U5      R                  5       nUR                  [        R	                  U[        U5      U5      5        MZ     U  H  u  p#UR                  U5        M     SR                  U5      nU$ )N    )listitemssortSIDEDATA_HEADERpacklenr	   sha1digestappendSIDEDATA_ENTRYjoin)sidedatabufkeyvaluer   s        @/usr/lib/python3/dist-packages/mercurial/revlogutils/sidedata.pyserialize_sidedatar'   @   s    HNN$%HMMOH.
/C
u%,,.

>&&sCJ?@  


5 
((3-CJr   c                   0 nSn[         R                  U S [         R                   5      u  nU[         R                  -  n[         R                  [        R                  U-  -   n[	        U5       H  nU[        R                  -   n[        R                  XU 5      u  pxn	UnXH-   n
[        XU
 5      n[        R                  " U5      R                  5       nX:w  a  [        R                  " XyU5      eXU'   U
nM     U$ )Nr   )r   unpacksizer    rangebytesr	   r   r   r   SidedataHashError)blobr"   offsetnbentry
dataoffseti
nextoffsetr$   r*   storeddigestnextdataoffset	entrytext
readdigests                r&   deserialize_sidedatar8   M   s    HF ''-C/C/C(DEJW
o"""F %%)<)<w)FGJ7^n111
"0"7"7J8O"P<#*$.9:	]]9-446
%))#ZHH!#
  Or   c                   [         R                  " [        5      n[         R                  " [        5      nXR                  -
  nU R                  U-
  nU(       a  XepeU R                  R                  5        HP  u  pxUR                  5        H7  u  pX;   a  X7   R                  U
5        X;   d  M$  XG   R                  U
5        M9     MR     XU4nU$ )a  
Returns a dictionary mapping revlog types to tuples of
`(repo, computers, removers)`:
    * `repo` is used as an argument for computers
    * `computers` is a list of `(category, (keys, computer, flags)` that
       compute the missing sidedata categories that were asked:
       * `category` is the sidedata category
       * `keys` are the sidedata keys to be affected
       * `flags` is a bitmask (an integer) of flags to remove when
          removing the category.
       * `computer` is the function `(repo, store, rev, sidedata)` that
         returns a tuple of
         `(new sidedata dict, (flags to add, flags to remove))`.
         For example, it will return `({}, (0, 1 << 15))` to return no
         sidedata, with no flags to add and one flag to remove.
    * `removers` will remove the keys corresponding to the categories
      that are present, but not needed.
    If both `computers` and `removers` are empty, sidedata will simply not
    be transformed.
)collectionsdefaultdictr   _wanted_sidedata_sidedata_computersr   r   )reporemote_sd_categoriespullsd_computerssd_removersto_generate	to_removerevlog_kind	computerscategorycomputersidedata_helperss               r&   get_sidedata_helpersrJ   b   s    , **40L))$/K&)>)>>K%%(<<I!*Y"&":":"@"@"B"+//"3H&)00:$(//9	 #4 #C K8r   c                   Uu  pEnU R                   nSnSn	UR                  U/ 5       H  u  pnU" X@X25      u  p-XS   -  nXS   -  n	M!     UR                  U/ 5       H%  u  pnU H  nUR                  US5        M     X-  n	M'     X(U	44$ )a3  Returns the sidedata for the given revision after running through
the given helpers.
- `store`: the revlog this applies to (changelog, manifest, or filelog
  instance)
- `sidedata_helpers`: see `get_sidedata_helpers`
- `sidedata`: previous sidedata at the given rev, if any
- `rev`: affected rev of `store`
r   r
   N)rE   getpop)storerI   r"   revr>   rA   rB   kindflags_to_addflags_to_remove_keyssd_computer_flagsflagskeys	_computerr$   s                    r&   run_sidedata_helpersrY      s     '7#DDLO&2&6&6tR&@"F%d3Aa 8# 'A #.//$";CLLd#   #< O444r   c                    SSK Jn  [        R                  U R                  ;   a  U R                  [        5        U R                  [        R                  [        [        4UR                  [        R                  5        g )Nr   )metadata) r[   requirementsmodCOPIESSDC_REQUIREMENTr   register_wanted_sidedataSD_FILESregister_sidedata_computerr   KIND_CHANGELOGcopies_sidedata_computerr   REVIDX_HASCOPIESINFO)r>   r[   s     r&   set_sidedata_spec_for_repore      sX    ,,0A0AA%%h/##  	))%%r   )F)"__doc__
__future__r   r:   structr\   r   r   r]   revlogutilsr   r   utilsr	   SD_TEST1SD_TEST2SD_TEST3SD_TEST4SD_TEST5SD_TEST6SD_TEST7SD_P1COPIESSD_P2COPIESSD_FILESADDEDSD_FILESREMOVEDr`   Structr   r    r'   r8   rJ   rY   re    r   r&   <module>rx      s   4 #   5 -    --%x(
*&R50r   