§
    	^µcx  ã                   óÖ   — d Z ddlZddlZddlmZmZ ddlmZm	Z	 ddl
m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¦  «        Z ej        d¦  «        Zd„ Zd„ Zdd„Zd„ Zd„ ZdS )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.
é    Né   )ÚerrorÚrequirements)Ú	constantsÚflagutil)Úhashutilé   é   é   é   é   é   é   é	   é
   é   é   z>Hz>HL20sc           	      óø  — t          |                      ¦   «         ¦  «        } |                      ¦   «          t                               t          | ¦  «        ¦  «        g}| D ]g\  }}t          j        |¦  «                             ¦   «         }| 	                    t                               |t          |¦  «        |¦  «        ¦  «         Œh| D ]\  }}| 	                    |¦  «         Œd                     |¦  «        }|S )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Û   € Ý�H—N’NÑ$Ô$Ñ%Ô%€HØ‡M‚M�O„O€OÝ×Ò¥ H¡¤Ñ.Ô.Ð
/€CØð Að A‰
ˆˆUÝ”˜uÑ%Ô%×,Ò,Ñ.Ô.ˆØ�
Š
•>×&Ò& s­C°©J¬J¸Ñ?Ô?Ñ@Ô@Ð@Ð@Øð ð ‰
ˆˆUØ�
Š
�5ÑÔÐÐØ
�(Š(�3‰-Œ-€CØ€Jr   c                 ó  — i }d}t                                | d t           j        …         ¦  «        \  }|t           j        z  }t           j        t          j        |z  z   }t	          |¦  «        D ]ž}|t          j        z   }t                               | ||…         ¦  «        \  }}}	|}||z   }
t          | ||
…         ¦  «        }t          j        |¦  «                             ¦   «         }|	|k    rt          j
        ||	|¦  «        ‚|||<   |
}ŒŸ|S )Nr   )r   ÚunpackÚsizer   ÚrangeÚbytesr   r   r   r   ÚSidedataHashError)Úblobr!   ÚoffsetÚnbentryÚ
dataoffsetÚiÚ
nextoffsetr#   r)   ÚstoreddigestÚnextdataoffsetÚ	entrytextÚ
readdigests                r%   Údeserialize_sidedatar7   L   s  € Ø€HØ€FÝ ×'Ò'¨Ð-C­Ô/CÐ-CÔ(DÑEÔE�J€WØ
�oÔ"Ñ"€FÝ Ô%­Ô)<¸wÑ)FÑG€JÝ�7‰^Œ^ð $ð $ˆØ�nÔ1Ñ1ˆ
Ý"0×"7Ò"7¸¸VÀJÐ=NÔ8OÑ"PÔ"PÑˆˆT�<Øˆà# dÑ*ˆÝ˜$˜z¨.Ð8Ô9Ñ:Ô:ˆ	Ý”] 9Ñ-Ô-×4Ò4Ñ6Ô6ˆ
Ø˜:Ò%Ð%ÝÔ)¨#¨|¸ZÑHÔHÐHØ!ˆ�‰Ø#ˆ
ˆ
Ø€Or   Fc                 ó–  — t          j        t          ¦  «        }t          j        t          ¦  «        }|| j        z
  }| j        |z
  }|r||}}| j                             ¦   «         D ]]\  }}|                     ¦   «         D ]C\  }	}
|	|v r||                              |
¦  «         |	|v r||                              |
¦  «         ŒDŒ^| ||f}|S )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_helpersrI   a   sô   € õ, Ô*­4Ñ0Ô0€LåÔ)­$Ñ/Ô/€KØ&¨Ô)>Ñ>€KØÔ%Ð(<Ñ<€IØð 8Ø!*¨K�Yˆà"&Ô":×"@Ò"@Ñ"BÔ"Bð :ð :Ñˆ�YØ"+§/¢/Ñ"3Ô"3ð 	:ð 	:ÑˆH�hØ˜;Ð&Ð&Ø˜[Ô)×0Ò0°Ñ:Ô:Ð:Ø˜9Ð$Ð$Ø˜KÔ(×/Ò/°Ñ9Ô9Ð9øð		:ð ˜l¨KÐ8ÐØÐr   c                 ó2  — |\  }}}| j         }d}d}	|                     |g ¦  «        D ]-\  }
}} ||| ||¦  «        \  }}||d         z  }|	|d         z  }	Œ.|                     |g ¦  «        D ]&\  }}}|D ]}|                     |d¦  «         Œ|	|z  }	Œ'|||	ffS )aO  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)rD   ÚgetÚpop)ÚstorerH   r!   Úrevr=   r@   rA   ÚkindÚflags_to_addÚflags_to_removeÚ_keysÚsd_computerÚ_flagsÚflagsÚkeysÚ	_computerr#   s                    r%   Úrun_sidedata_helpersrX   Š   så   € ð '7Ñ#€Dˆ,˜ØÔ€DØ€LØ€OØ&2×&6Ò&6°t¸RÑ&@Ô&@ð $ð $Ñ"ˆˆ{˜FØ%˜+ d¨E°3¸ÑAÔA‰ˆ�%Ø˜˜aœÑ ˆØ˜5 œ8Ñ#ˆˆØ"-§/¢/°$¸Ñ";Ô";ð !ð !Ñˆˆi˜Øð 	$ð 	$ˆCØ�LŠL˜˜dÑ#Ô#Ð#Ð#Ø˜5Ñ ˆˆØ�l OÐ4Ð4Ð4r   c                 óæ   — ddl m} t          j        | j        v r|                      t          ¦  «         |                      t          j	        t          t          f|j
        t          j        ¦  «         d S )Nr   )Úmetadata)Ú rZ   ÚrequirementsmodÚCOPIESSDC_REQUIREMENTr   Úregister_wanted_sidedataÚSD_FILESÚregister_sidedata_computerr   ÚKIND_CHANGELOGÚcopies_sidedata_computerr   ÚREVIDX_HASCOPIESINFO)r=   rZ   s     r%   Úset_sidedata_spec_for_repord   ¢   su   € àÐÐÐÐÐåÔ,°Ô0AÐAÐAØ×%Ò%¥hÑ/Ô/Ð/Ø×#Ò#ÝÔ ÝÝ	ˆØÔ)ÝÔ%ñô ð ð ð r   )F) Ú__doc__r9   Ú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&   r7   rI   rX   rd   © r   r%   ú<module>rv      s'  ððð ð6 Ð Ð Ð Ø €€€à 5Ð 5Ð 5Ð 5Ð 5Ð 5Ð 5Ð 5Ø -Ð -Ð -Ð -Ð -Ð -Ð -Ð -Ø Ð Ð Ð Ð Ð ð €Ø€Ø€Ø€Ø€Ø€Ø€ð €Ø€Ø€Ø€Ø€ð  �&”- Ñ%Ô%€Ø�”˜xÑ(Ô(€ð
ð 
ð 
ðð ð ð*&ð &ð &ð &ðR5ð 5ð 5ð0ð ð ð ð r   