403Webshell
Server IP : 104.21.74.243  /  Your IP : 216.73.216.47
Web Server : Apache
System : Linux infong-es77 4.4.400-icpu-108 #2 SMP Wed Feb 11 10:12:42 UTC 2026 x86_64
User : u67207989 ( 1351568)
PHP Version : 8.4.24
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /lib/python3/dist-packages/breezy/bzr/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /lib/python3/dist-packages/breezy/bzr/__pycache__/pack_repo.cpython-39.pyc
a

�*�^�]�@s�ddlmZddlZddlZddlmZee�d�ddlmZmZm	Z	ddl
mZddlm
Z
dd	lmZdd
lmZmZddlmZmZddlmZmZdd
lmZmZmZddlmZmZm Z Gdd�de�Z!Gdd�de"�Z#Gdd�de#�Z$Gdd�de$�Z%Gdd�de#�Z&Gdd�de"�Z'Gdd�de"�Z(Gdd�de"�Z)Gdd �d e�Z*Gd!d"�d"e�Z+Gd#d$�d$ej,�Z-Gd%d&�d&e"�Z.dS)'�)�absolute_importN�)�lazy_importz�
import time

from breezy import (
    cleanup,
    config,
    debug,
    graph,
    osutils,
    transactions,
    ui,
    )
from breezy.bzr import (
    pack,
    )
from breezy.bzr.index import (
    CombinedGraphIndex,
    )
)�errors�lockable_files�lockdir)�btree_index)�only_raises)�LogicalLockResult)�
_LazyListJoin�RepositoryWriteLockResult)�MetaDirRepository�RepositoryFormatMetaDir)�reraise�	viewitems)�MetaDirVersionedFileRepository�$MetaDirVersionedFileRepositoryFormat�VersionedFileCommitBuilder)�mutter�note�warningc@s"eZdZdZddd�Zdd�ZdS)	�PackCommitBuilderz�Subclass of VersionedFileCommitBuilder to add texts with pack semantics.

    Specifically this uses one knit object rather than one knit object per
    added text, reducing memory and object pressure.
    NFc

Cs4tj||||||||||	d�
t�|jjj�|_dS)N)�	timestamp�timezone�	committer�revprops�revision_id�lossy)r�__init__�graphZGraph�_pack_collection�
text_index�combined_index�_file_graph)
�self�
repository�parents�configrrrrrr�r(�6/usr/lib/python3/dist-packages/breezy/bzr/pack_repo.pyrVs��zPackCommitBuilder.__init__cs(�fdd�|D�}dd�|j�|�D�S)Ncsg|]}�|f�qSr(r()�.0r��file_idr(r)�
<listcomp>`�z,PackCommitBuilder._heads.<locals>.<listcomp>cSsh|]}|d�qS��r(�r*�keyr(r(r)�	<setcomp>ar.z+PackCommitBuilder._heads.<locals>.<setcomp>)r#Zheads)r$r,�revision_ids�keysr(r+r)�_heads_szPackCommitBuilder._heads)NNNNNF)�__name__�
__module__�__qualname__�__doc__rr6r(r(r(r)rOs�
	rc@s�eZdZdZdddddd�Zd%d	d
�Zdd�Zd
d�Zdd�Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd �Zd!d"�Zd#d$�ZdS)&�Packz�An in memory proxy for a pack and its indices.

    This is a base class that is not directly used, instead the classes
    ExistingPack and NewPack are used.
    )�.cix�)�.rixr)�.iixr0)�.tixr)�.six�)�chk�revision�	inventory�text�	signatureNcCs"||_||_||_||_||_dS)a=Create a pack instance.

        :param revision_index: A GraphIndex for determining what revisions are
            present in the Pack and accessing the locations of their texts.
        :param inventory_index: A GraphIndex for determining what inventories are
            present in the Pack and accessing the locations of their
            texts/deltas.
        :param text_index: A GraphIndex for determining what file texts
            are present in the pack and accessing the locations of their
            texts/deltas (via (fileid, revisionid) tuples).
        :param signature_index: A GraphIndex for determining what signatures are
            present in the Pack and accessing the locations of their texts.
        :param chk_index: A GraphIndex for accessing content by CHK, if the
            pack has one.
        N)�revision_index�inventory_indexr!�signature_index�	chk_index)r$rHrIr!rJrKr(r(r)rus
z
Pack.__init__cCs|j|��fS)�6Return a tuple (transport, name) for the pack content.)�pack_transport�	file_name�r$r(r(r)�access_tuple�szPack.access_tuplecCs�i}d|�|j�|jjjfd|�|j�|jjjffD]8\}}}|�dd�|�|�D��}|r4tt|��||<q4|r�ddl	m
}t�d|||�f��dS)	aBMake sure our external references are present.

        Packs are allowed to have deltas whose base is not in the pack, but it
        must be present somewhere in this collection.  It is not allowed to
        have deltas based on a fallback repository.
        (See <https://bugs.launchpad.net/bzr/+bug/288751>)
        �texts�inventoriescss|]\}}}}|VqdS�Nr()r*�idx�k�v�rr(r(r)�	<genexpr>�sz)Pack._check_references.<locals>.<genexpr>r)�pformatzRNewly created pack file %r has delta references to items not in its repository:
%sN)
�_get_external_refsr!r r"rI�
differenceZiter_entries�sorted�listZpprintrYr�
BzrCheckError)r$Z
missing_items�
index_nameZ
external_refs�index�missingrYr(r(r)�_check_references�s,
�
��
�
��zPack._check_referencescCs
|jdS)z'Get the file name for the pack on disk.�.pack��namerOr(r(r)rN�szPack.file_namecCs
|j��SrS)rH�	key_countrOr(r(r)�get_revision_count�szPack.get_revision_countcCs|tj|dS)z8Get the disk name of an index type for pack name 'name'.r�r;�index_definitions)r$�
index_typerer(r(r)r_�szPack.index_namecCstj|dS)z>Get the position in a index_size array for a given index type.r0rh)r$rjr(r(r)�index_offset�szPack.index_offsetcCs|�d|�S)z!The inv index is the name + .iix.rE�r_�r$rer(r(r)�inventory_index_name�szPack.inventory_index_namecCs|�d|�S)z&The revision index is the name + .rix.rDrlrmr(r(r)�revision_index_name�szPack.revision_index_namecCs|�d|�S)z'The signature index is the name + .six.rGrlrmr(r(r)�signature_index_name�szPack.signature_index_namecCs|�d|�S)z"The text index is the name + .tix.rFrlrmr(r(r)�text_index_name�szPack.text_index_namecCs^d}|dkrd}|j|j|�||j�|j|�|�|d�}|dkrJtj|_t	||d|�dS)NFrCT��unlimited_cache�_index)
�index_class�index_transportr_re�index_sizesrkr�_gcchk_factory�
_leaf_factory�setattr)r$rjrsr`r(r(r)�_replace_index_with_readonly�s��z!Pack._replace_index_with_readonlycCs"t|t�st|��t|�t|�kSrS)�
isinstancer;�	TypeError�id�r$�otherr(r(r)�__lt__�s
zPack.__lt__cCs"tt|�|j|j|j|j|jf�SrS)�hash�typerHrIr!rJrKrOr(r(r)�__hash__�s�z
Pack.__hash__)N)r7r8r9r:rirrPrbrNrgr_rkrnrorprqr{r�r�r(r(r(r)r;ds,	�	�

r;c@s:eZdZdZd
dd�Zdd�Zdd�Zd	d
�Zdd�ZdS)�ExistingPackz>An in memory proxy for an existing .pack and its disk indices.NcCs>t�||||||�||_||_d||||||fvr:t��dS)z�Create an ExistingPack object.

        :param pack_transport: The transport where the pack file resides.
        :param name: The name of the pack on disk in the pack_transport.
        N)r;rrerM�AssertionError)r$rMrerHrIr!rJrKr(r(r)r�s��zExistingPack.__init__cCs|j|jkSrS)�__dict__rr(r(r)�__eq__�szExistingPack.__eq__cCs|�|�SrS)r�rr(r(r)�__ne__�szExistingPack.__ne__cCs"d|jj|jjt|�|j|jfS)Nz<%s.%s object at 0x%x, %s, %s)�	__class__r8r7r~rMrerOr(r(r)�__repr__�s�zExistingPack.__repr__cCstt|�|jf�SrS)r�r�rerOr(r(r)r�szExistingPack.__hash__)N)	r7r8r9r:rr�r�r�r�r(r(r(r)r��s�
r�c@s6eZdZddd�Zdd�Zdd�Zdd	�Zd
d�ZdS)
�ResumedPackNc
Cs�tj||||||||
d�||_||_gd�|_d|fd|fd|fd|fg}|
durn|�d|
f�|j�d�|D]\}}
|�|�}|
j|j|<qr|	j|_	|	|_
d	|_dS)
zCreate a ResumedPack object.�rK�NNNNrDrErFrGNrC�resumed)r�r�upload_transportrvrw�appendrkZ_size�_index_classrur �_state)r$rerHrIr!rJr�rMrv�pack_collectionrK�indicesrjr`�offsetr(r(r)rs*�
�
zResumedPack.__init__cCs:|jdkrt�|�S|jdkr,|j|��fSt|j��dS)N�finishedr�)r�r;rPr�rNr�rOr(r(r)rP!s



zResumedPack.access_tuplecCsV|j�|���|j|j|j|jg}|jdur:|�|j�|D]}|j	�|j
�q>dSrS)r��deleterNrHrIr!rJrKr�Z
_transport�_name)r$r�r`r(r(r)�abort)s�
zResumedPack.abortcCs�|��gd�}|jdur$|�d�|D]2}|�||j�}d|}|j�||�|�|�q(d|��}|j�|��|�d|_	dS)N)rDrErFrGrCz../indices/�	../packs/r�)
rbrKr�r_rer��mover{rNr�)r$Zindex_typesrjZold_name�new_namer(r(r)�finish2s

zResumedPack.finishcCs
|�d�S)z�Return compression parents for this index that are not present.

        This returns any compression parents that are referenced by this index,
        which are not contained *in* this index. They may be present elsewhere.
        r0)Zexternal_references�r$r`r(r(r)rZ@szResumedPack._get_external_refs)N)r7r8r9rrPr�r�rZr(r(r(r)r�s�
	r�c@sfeZdZdZddd�Zdd�Zdd	�Zd
d�Zdd
�Zddd�Z	dd�Z
dd�Zdd�Zddd�Z
dS)�NewPackz5An in memory proxy for a pack which is being created.�NcsH|j}|jdur|dd�}nd}tj�|dd�|dd�|ddd�|dd�|d�|�_|j�_|j�_|j	�_
|j�_|�_
t���_d�_d�_t�d�|�_t���_�jj�j�j
d	��_d
tjvr�tdt���jj�jt���j�gdg�_d�j�jj�jj f�fd
d�	}|�_!t"�#�j!��_$�j$�%�d�_&d�_'dS)aMCreate a NewPack instance.

        :param pack_collection: A PackCollection into which this is being inserted.
        :param upload_suffix: An optional suffix to be given to any temporary
            files created during the pack creation. e.g '.autopack'
        :param file_mode: Unix permissions for newly created file.
        Nr)�reference_listsr0r)r�Zkey_elementsr����mode�packz0%s: create_pack: pack stream open: %s%s t+%6.3fsFcsf|d�|�|dt|�7<|d�jks4|rbd�|d�}||�||�gdg|dd�<dS)Nrr0r.)r��len�_cache_limit�join)�bytes�flush�_bufferZ_writeZ_updaterOr(r)�_write_data�sz%NewPack.__init__.<locals>._write_data�open)(�_index_builder_classrKr;rr r�ru�_upload_transportr��_index_transportrv�_pack_transportrM�
_file_mode�osutilsZmd5�_hashrwr�Z
rand_chars�random_name�time�
start_time�open_write_stream�write_stream�debug�debug_flagsr�ctime�baser��write�updater�r�ZContainerWriter�_writerZbeginr�re)r$r��
upload_suffix�	file_mode�index_builder_classrKr�r(rOr)rLsN


�

�
�
�
zNewPack.__init__cCs"d|_|j��|j�|j�dS)zCancel creating this pack.ZabortedN)r�r��closer�r�r�rOr(r(r)r��s
z
NewPack.abortcCs8|jdkrt�|�S|jdkr*|j|jfSt|j��dS)rLr�r�N)r�r;rPr�r�r�rOr(r(r)rP�s



zNewPack.access_tuplecCs>t|��p:|j��p:|j��p:|j��p:|jduo:|j���S)z)True if data has been added to this pack.N)�boolrgrIrfr!rJrKrOr(r(r)�
data_inserted�s
����zNewPack.data_insertedcCs@|jdurdS|j��|jdr0|jddd�|j��|_dS)Nr0r.T)r�)rer��endr�r�r�Z	hexdigestrOr(r(r)�finish_content�s


zNewPack.finish_contentFcCs|��|s|��gd�|_|�d|jd|�|�d|jd|�|�d|jd|�|�d|jd|�|jdur�|j�	d�|�d	|jd
|�|j
j|jj
�d�d�|jd
}|s�d|}|j�|j|�d|_dtjv�rtdt��|jj|j|t��|j�dS)a=Finish the new pack.

        This:
         - finalises the content
         - assigns a name (the md5 of the content, currently)
         - writes out the associated indices
         - renames the pack into place.
         - stores the index size tuple for the pack in the index_sizes
           attribute.
        r�rDrErFz
file textsrGzrevision signaturesNrCzcontent hash bytes�repository.fdatasync�Zwant_fdatasyncrcr�r�r�z1%s: create_pack: pack finished: %s%s->%s t+%6.3fs)r�rbrw�_write_indexrHrIr!rJrKr�r�r�r �config_stack�getrer�r�r�r�r�r�rr�r�r�r�)r$�suspendr�r(r(r)r��s@
��
�

��
�zNewPack.finishcCsH|jdrDd�|jd�}|j�|�|j�|�gdg|jdd�<dS)zFlush any current data.r0r.rN)r�r�r�r�r�r�)r$r�r(r(r)r�s

z
NewPack.flushcCs|��SrS)Z_external_referencesr�r(r(r)rZ
szNewPack._get_external_refscCs
||_dSrS)r�)r$�sizer(r(r)�set_write_cache_size
szNewPack.set_write_cache_sizec
Cs�|�||j�}|r|j}n|j}|��}|��}|j||jd�}	|	�|�|	j	|j
j�d�d�t
|�|j|�|�<dtjvr�tdt��||jj|jt��|j�|�|�dS)z�Write out an index.

        :param index_type: The type of index to write - e.g. 'revision'.
        :param index: The index object to serialise.
        :param label: What label to give the index e.g. 'revision'.
        r�r�r�r�z.%s: create_pack: wrote %s index: %s%s t+%6.3fsN)r_rer�rvr��readr�r�r�r�r r�r�r�rwrkr�r�rr�r�r�r�r�r{)
r$rjr`Zlabelr�r_�	transportZindex_tempfileZindex_bytesr�r(r(r)r�s(�
�
�zNewPack._write_index)r�N)F)F)r7r8r9r:rr�rPr�r�r�r�rZr�r�r(r(r(r)r�Is
^	
7r�c@s:eZdZdZd
dd�Zdd�Zdd�Zd	d
�Zdd�ZdS)�AggregateIndexa�An aggregated index for the RepositoryPackCollection.

    AggregateIndex is reponsible for managing the PackAccess object,
    Index-To-Pack mapping, and all indices list for a specific type of index
    such as 'revision index'.

    A CombinedIndex provides an index on a single key space built up
    from several on-disk indices.  The AggregateIndex builds on this
    to provide a knit access layer, and allows having up to one writable
    index within the collection.
    NcCs6||_i|_tg|d�|_t|j||d�|_d|_dS)z�Create an AggregateIndex.

        :param reload_func: A function to call if we find we are missing an
            index. Should have the form reload_func() => True if the list of
            active pack files has changed.
        ��reload_func)r��
flush_funcN)�_reload_func�
index_to_packZCombinedGraphIndexr"�_DirectPackAccess�data_access�add_callback)r$r�r�r(r(r)r?s�zAggregateIndex.__init__cCs$|��|j|<|j�d||j�dS)aAdd index to the aggregate, which is an index for Pack pack.

        Future searches on the aggregate index will seach this new index
        before all previously inserted indices.

        :param index: An Index for the pack.
        :param pack: A Pack instance.
        rN)rPr�r"Zinsert_indexre�r$r`r�r(r(r)�	add_indexNs
zAggregateIndex.add_indexcCsJ|jdurtd||jf��|�||�|j�|j||���|j|_dS)aAdd an index which is able to have data added to it.

        There can be at most one writable index at any time.  Any
        modifications made to the knit are put into this index.

        :param index: An index from the pack parameter.
        :param pack: A Pack instance.
        Nz*%s already has a writable index through %s)r�r�r�r��
set_writerr�rP�	add_nodesr�r(r(r)�add_writable_index\s	
��z!AggregateIndex.add_writable_indexcCs@|j�ddd�|j��|jjdd�=|jjdd�=d|_dS)z(Reset all the aggregate data to nothing.N�NN)r�r�r��clearr"�_indices�_index_namesr�rOr(r(r)r�os

zAggregateIndex.clearcCs`|j|=|jj�|�}|jj|=|jj|=|jdur\t|dd�|jkr\d|_|j�ddd�dS)zwRemove index from the indices used to answer queries.

        :param index: An index from the pack parameter.
        Nr�r�)	r�r"r�r`r�r��getattrr�r�)r$r`�posr(r(r)�remove_indexws


�zAggregateIndex.remove_index)NN)	r7r8r9r:rr�r�r�r�r(r(r(r)r�0s
r�c@s\eZdZdZddd�Zddd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�ZdS)�PackerzCreate a pack from packs.NcCs4||_||_||_d|_||_||_d|_d|_dS)aCreate a Packer.

        :param pack_collection: A RepositoryPackCollection object where the
            new pack is being written to.
        :param packs: The packs to combine.
        :param suffix: The suffix to use on the temporary files for the pack.
        :param revision_ids: Revision ids to limit the pack to.
        :param reload_func: A function to call if a pack file/index goes
            missing. The side effect of calling this function should be to
            update self.packs. See also AggregateIndex
        N)�packs�suffixr4�new_packr r�Z_revision_keysZ_text_filter)r$r�r�r�r4r�r(r(r)r�s
zPacker.__init__cCs�|jjdur t�d|jjf��|jdur^t|j�dkr<dSt|j�|_tdd�|jD��|_	|durtt
j��|_
n||_
z|��W|dur�|j
��Sn|dur�|j
��0dS)a|Create a new pack by reading data from other packs.

        This does little more than a bulk copy of data. One key difference
        is that data with the same item key across multiple packs is elided
        from the output. The new pack is written into the current pack store
        along with its indices, and the name added to the pack names. The
        source packs are not altered and are not required to be in the current
        pack collection.

        :param pb: An optional progress bar to use. A nested bar is created if
            this is None.
        :return: A Pack object, or None if nothing was copied.
        Nz6call to %s.pack() while another pack is being written.rcss|]}|fVqdSrSr()r*Zrevidr(r(r)rX�r.zPacker.pack.<locals>.<genexpr>)r �	_new_packr�BzrErrorr�r7r4r��	frozensetZ
revision_keysZuiZ
ui_factoryZnested_progress_bar�pb�_create_pack_from_packsr�)r$r�r(r(r)r��s.�
�

��zPacker.packcCs\|jj|j|j|jjj��d�}|jjdd�|jjdd�|j	jdd�|j
jdd�|S)z)Open a pack for the pack we are creating.�r�r�F�Zcombine_backing_indices)r �pack_factoryr��repo�
controldir�_get_file_moderH�set_optimizerIr!rJ�r$r�r(r(r)�	open_pack�s
�zPacker.open_packcCst|j��dS)z#Copy revision data to the new pack.N)�NotImplementedError�_copy_revision_textsrOr(r(r)r��szPacker._copy_revision_textscCst|j��dS)z�Copy the inventory texts to the new pack.

        self._revision_keys is used to determine what inventories to copy.

        Sets self._text_filter appropriately.
        N)r��_copy_inventory_textsrOr(r(r)r��szPacker._copy_inventory_textscCst|j��dSrS)r��_copy_text_textsrOr(r(r)r��szPacker._copy_text_textscCst|j��dSrS)r�r�rOr(r(r)r��szPacker._create_pack_from_packscCsBdtjvr>tdt��|jjj|jj	|jj
��t��|jj�dS)Nr�z:%s: create_pack: file texts copied: %s%s %d items t+%6.3fs)
r�r�rr�r�r r�r�r�r�r!rfr�rOr(r(r)�_log_copied_texts�s

�zPacker._log_copied_textscCs|��S)z�Return True if new_pack should be used.

        :param new_pack: The pack that has just been created.
        :return: True if the pack should be used.
        )r�r�r(r(r)�	_use_pack�szPacker._use_pack)NN)N)
r7r8r9r:rr�r�r�r�r�r�r�rr(r(r(r)r��s�

(
	r�c@s�eZdZdZdZdZdZdZdd�Zdd�Z	dd�Z
d	d
�Zdd�Zd
d�Z
dZdd�Zdd�Zdd�Zdd�Zd[dd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd\d*d+�Zd,d-�Zd.d/�Zd0d1�Zd2d3�Zd4d5�Z d6d7�Z!d]d8d9�Z"d:d;�Z#d<d=�Z$d>d?�Z%d@dA�Z&d^dBdC�Z'dDdE�Z(dFdG�Z)dHdI�Z*d_dJdK�Z+dLdM�Z,dNdO�Z-dPdQ�Z.dRdS�Z/dTdU�Z0dVdW�Z1dXdY�Z2dS)`�RepositoryPackCollectionzbManagement of packs within a repository.

    :ivar _names: map of {pack_name: (index_size,)}
    Nc	
Cs||_||_||_||_||_||_||_dddddd�|_g|_d|_	i|_
d|_d|_|j
}	t|j|	�|_t|j|	�|_t|j|	�|_t|j|	�|_|j|j|j|jg}
|r�t|j|	�|_|
�|j�nd|_dd	�|
D�}|D]}|�t|��|g��q�g|_t�|jj�|_dS)
ayCreate a new RepositoryPackCollection.

        :param transport: Addresses the repository base directory
            (typically .bzr/repository/).
        :param index_transport: Addresses the directory containing indices.
        :param upload_transport: Addresses the directory into which packs are written
            while they're being created.
        :param pack_transport: Addresses the directory of existing complete packs.
        :param index_builder_class: The index builder class to use.
        :param index_class: The index class to use.
        :param use_chk_index: Whether to setup and manage a CHK index.
        rr0rrBr=)r>r?r@rAr<NcSsg|]
}|j�qSr()r")r*Zagg_idxr(r(r)r-9r.z5RepositoryPackCollection.__init__.<locals>.<listcomp>)r�r�r�r�r�r�r��_suffix_offsetsr��_names�_packs_by_name�_packs_at_loadr��_flush_new_packr��reload_pack_namesrHrIr!rJrKr�Zset_sibling_indices�setr[�_resumed_packsr'Z
LocationStackr�r�)
r$r�r�rvr�rMr�ruZ
use_chk_indexr�Zall_indicesZall_combinedZcombined_idxr(r(r)rsD���z!RepositoryPackCollection.__init__cCsd|jj|jfS)Nz%s(%r))r�r7r�rOr(r(r)r�Asz!RepositoryPackCollection.__repr__cCs�|j|jvrtd|jf��|j�|�||j|j<|j�|j|�|j�|j|�|j�|j|�|j	�|j	|�|j
dur�|j
�|j
|�dS)zpMake a Pack object available to the repository to satisfy queries.

        :param pack: A Pack object.
        z!pack %s already in _packs_by_nameN)rerr�r�r�rHr�rIr!rJrK�r$r�r(r(r)�add_pack_to_memoryDs
�
z+RepositoryPackCollection.add_pack_to_memorycCs&g}|��D]}|�|�|��q|S)z�Return a list of all the Pack objects this repository has.

        Note that an in-progress pack being created is not returned.

        :return: A list of Pack objects for all the packs in the repository.
        )�namesr��get_pack_by_name)r$�resultrer(r(r)�	all_packsUsz"RepositoryPackCollection.all_packscCs&z
|��WStjyYq0qdS)a�Pack the pack collection incrementally.

        This will not attempt global reorganisation or recompression,
        rather it will just ensure that the total number of packs does
        not grow without bound. It uses the _max_pack_count method to
        determine if autopacking is needed, and the pack_distribution
        method to determine the number of revisions in each pack.

        If autopacking takes place then the packs name collection will have
        been flushed to disk - packing requires updating the name collection
        in synchronisation with certain steps. Otherwise the names collection
        is not flushed.

        :return: Something evaluating true if packing took place.
        N)�_do_autopackr�
RetryAutopackrOr(r(r)�autopackas
z!RepositoryPackCollection.autopackcCs�|jj��}t|j�}|�|�|kr(dS|�|�}g}|��D]$}|��}|dkrTq>|�	||f�q>|�
||�}t|�}tdd�|D��}	tdd�|D��}
tdt
|�|||	||
�|j||j|jd�}tdt
|��|S)NrcSsg|]}t|d��qSr/)r��r*Zpor(r(r)r-�r.z9RepositoryPackCollection._do_autopack.<locals>.<listcomp>cSsg|]}|d�qS�rr(rr(r(r)r-�r.z}Auto-packing repository %s, which has %d pack files, containing %d revisions. Packing %d files into %d affecting %d revisions��packer_classr�z$Auto-packing repository %s completed)rHr"rfr�r�_max_pack_count�pack_distributionrrgr��plan_autopack_combinations�sumr�str�_execute_pack_operations�normal_packer_class�_restart_autopack)r$�total_revisions�total_packsr�existing_packsr��revision_count�pack_operationsZ
num_new_packsZ
num_old_packsZnum_revs_affectedrr(r(r)rys:

���
�z%RepositoryPackCollection._do_autopackc	Cs�|D]�\}}t|�dkrq|||d|d�}z|��}Wn*tjy`|jdurZ|j���Yn0|durpdS|D]}|�|�qtqg}	|D]\}
}|	�|�q�|jd|	d�}|S)z�Execute a series of pack operations.

        :param pack_operations: A list of [revision_count, packs_to_combine].
        :param packer_class: The class of packer to use
        :return: The new pack names.
        rz	.autopackr�NT)�clear_obsolete_packs�obsolete_packs)	r�r�r�RetryWithNewPacksr�r��_remove_pack_from_memory�extend�_save_pack_names)r$r#rr�r"r�Zpackerrr�Zto_be_obsoleted�_r(r(r)r�s.�

�z1RepositoryPackCollection._execute_pack_operationscCs|jdur|j��dSrS)r�r�rOr(r(r)r�s
z(RepositoryPackCollection._flush_new_packcCs|jj��dS)z�Acquire the mutex around the pack-names index.

        This cannot be used in the middle of a read-only transaction on the
        repository.
        N)r��
control_files�
lock_writerOr(r(r)�
lock_names�sz#RepositoryPackCollection.lock_namescCs|jjjpt|j�dkS)z!Is the collection already packed?r0)r��_formatZpack_compressesr�rrOr(r(r)�_already_packed�sz(RepositoryPackCollection._already_packedFcCsx|��t|j�}|��rdS|jj��}tdt|�|||�z|�	|�Wqht
ybYq>Yqh0qhq>|rt|��dS)z!Pack the pack collection totally.NzUPacking repository %s, which has %d pack files, containing %d revisions with hint %r.)�
ensure_loadedr�rr/rHr"rfrr�_try_pack_operations�RetryPackOperations�_clear_obsolete_packs)r$�hint�clean_obsolete_packsr rr(r(r)r��s 
�
zRepositoryPackCollection.packcCsldggg}|��D]@}|dus(|j|vr|dd|��7<|dd�|�q|j||j|jd�dS)z\Calculate the pack operations based on the hint (if any), and
        execute them.
        rN���r0r)rrergr�r�optimising_packer_class�_restart_pack_operations)r$r4r#r�r(r(r)r1�s
�z-RepositoryPackCollection._try_pack_operationsc
Cst|�t|�krgS|jdd�dggg}t|�r�|�d�\}}||dkr~|dkr�||d8}|dkrp|d=qL||d<qLq*|dd|7<|dd�|�|dd|dkr*|d=|�dgg�q*d}g}|D]\}}	||7}|�|	�q�t|�dk�rtd��gS||ggS)z�Plan a pack operation.

        :param existing_packs: The packs to pack. (A list of (revcount, Pack)
            tuples).
        :param pack_distribution: A list with the number of revisions desired
            in each pack.
        T)�reverserr6r0zEWe somehow generated an autopack with a single pack file being moved.)r��sort�popr�r(r�)
r$r!rr#Znext_pack_rev_countZ	next_packZfinal_rev_countZfinal_pack_listZnum_revsZ
pack_filesr(r(r)r�s4
z3RepositoryPackCollection.plan_autopack_combinationscCs�|j��st�|j��|jdurvi|_t�|_|��D]8\}}}|d�d�}|�	|�|j|<|j�
||f�q6d}nd}|��|S)ztEnsure we have read names from disk.

        :return: True if the disk names had not been previously read.
        Nr�asciiTF)r��	is_lockedrZObjectNotLockedrrr�_iter_disk_pack_index�decode�_parse_index_sizes�addr)r$r`r2�valuererr(r(r)r0/s

z&RepositoryPackCollection.ensure_loadedcCstdd�|�d�D��S)zParse a string of index sizes.css|]}t|�VqdSrS)�int)r*�digitsr(r(r)rXHr.z>RepositoryPackCollection._parse_index_sizes.<locals>.<genexpr>� )�tuple�split)r$rBr(r(r)r@Fsz+RepositoryPackCollection._parse_index_sizescCs�z|j|WSty�|�|d�}|�|d�}|�|d�}|�|d�}|jdurf|j|ddd�}nd}t|j||||||�}|�|�|YS0dS)	z~Get a Pack object by name.

        :param name: The name of the pack - e.g. '123456'
        :return: A Pack object.
        r>r?r@rANr<T)�is_chk)r�KeyError�_make_indexrKr�r�r)r$re�	rev_index�	inv_index�	txt_index�	sig_indexrKrr(r(r)r
Js

�
z)RepositoryPackCollection.get_pack_by_namec	Cst�d|�st�|j|gd��z�|j|ddd�}|j|ddd�}|j|ddd�}|j|ddd�}|jd	ur~|j|d
ddd�}nd	}|j||||||j|j	|j
||d�
}Wn<tjy�}z"t�|j|gt|���WYd	}~n
d	}~00|�
|�|j�|�|S)
z�Get a suspended Pack object by name.

        :param name: The name of the pack - e.g. '123456'
        :return: A Pack object.
        z[a-f0-9]{32}zMalformed write group tokenr>T)�resumer?r@rANr<)rOrHr�)�re�matchr�UnresumableWriteGroupr�rJrK�resumed_pack_factoryr�r�r��
NoSuchFilerrr	r�)	r$rerKrLrMrNrKr�er(r(r)�_resume_pack`s0
�

�

�
,
z%RepositoryPackCollection._resume_packcCsH|��|j|jvr(t�d|j|f��t|j�|j|j<|�|�dS)z�Allocate name in the list of packs.

        :param a_new_pack: A NewPack instance to be added to the collection of
            packs for this repository.
        zPack %r already exists in %sN)r0rerrr�rFrwr)r$Z
a_new_packr(r(r)�allocates�z!RepositoryPackCollection.allocatecCs|�|jdd���S)z�Iterate over the contents of the pack-names index.

        This is used when loading the list from disk, and before writing to
        detect updates from others during our write operation.
        :return: An iterator of the index contents.
        �
pack-namesN)r�r�Ziter_all_entriesrOr(r(r)r>�sz.RepositoryPackCollection._iter_disk_pack_indexc
Csl|j|}||}|r*|j}|�|�j}n|j}|j||}|j||||d�}	|rh|jtjurhtj	|	_
|	S)Nrr)rr��stat�st_sizer�rr�rZBTreeGraphIndexrxry)
r$rer�rOrHZsize_offsetr_r�Z
index_sizer`r(r(r)rJ�s

�z$RepositoryPackCollection._make_indexcCs.|sdSt|�}d}|D]}|t|�7}q|S)z�Return the maximum number of packs to use for total revisions.

        :param total_revisions: The total number of revisions in the
            repository.
        r0r)rrC)r$rrDrZdigitr(r(r)r�sz(RepositoryPackCollection._max_pack_countcCst|j���S)z)Provide an order to the underlying names.)r\rr5rOr(r(r)r�szRepositoryPackCollection.namescCsJ|D�]>}zxz|j�|��d|���WnTtjy~z|j�d�Wntjy^Yn0|j�|��d|���Yn0Wn:tjtjfy�}zt	d|f�WYd}~n
d}~00gd�}|j
dur�|�d�|D]d}z"|j�|j
|d|j
|�Wq�tjtjf�y@}zt	d|f�WYd}~q�d}~00q�qdS)a�Move a number of packs which have been obsoleted out of the way.

        Each pack and its associated indices are moved out of the way.

        Note: for correctness this function should only be called after a new
        pack names index has been written without these pack names, and with
        the names of packs that contain the data previously available via these
        packs.

        :param packs: The packs to obsolete.
        :param return: None.
        z../obsolete_packs/z.couldn't rename obsolete pack, skipping it:
%sN)r?rAr@r>r<z/couldn't rename obsolete index, skipping it:
%s)rMr�rNrrT�mkdirZ
FileExists�	PathError�TransportErrorrrKr�r�re)r$r�r�rU�suffixesr�r(r(r)�_obsolete_packs�s<

�
��

��z(RepositoryPackCollection._obsolete_packscCs`|dkrdgStt|��}g}t|�D],\}}d|}tt|��D]}|�|�qBq&tt|��S)z�Generate a list of the number of revisions to put in each pack.

        :param total_revisions: The total number of revisions in the
            repository.
        r�
)�reversedr�	enumerate�rangerCr�r])r$rrDrZexponent�countr�r�r(r(r)r�sz*RepositoryPackCollection.pack_distributioncCs|j|dfS)z@Return a tuple with the transport and file name for a pack name.rc)r�rmr(r(r)�_pack_tuple�sz$RepositoryPackCollection._pack_tuplecCs6|j�|j�|j�|j�|�|�|j�|�dS)z�Remove pack from the packs accessed by this repository.

        Only affects memory state, until self._save_pack_names() is invoked.
        N)rr;rer�_remove_pack_indicesr��remover
r(r(r)r'�s
z1RepositoryPackCollection._remove_pack_from_memoryc	Cs`tjD]T}|d}t||�}|durt||�}z|�|�WqtyX|rRYq�Yq0qdS)z�Remove the indices for pack from the aggregated indices.

        :param ignore_missing: Suppress KeyErrors from calling remove_index.
        rtN)r;rir�r�rI)r$r��ignore_missingrjZ	attr_nameZaggregate_indexZ
pack_indexr(r(r)rfs


z-RepositoryPackCollection._remove_pack_indicescCs^|j��|j��|j��|j��|jdur<|j��d|_d|_g|_i|_	d|_
dS)zClear all cached data.N)rHr�rJr!rIrKr�rr�rrrOr(r(r)�resets





zRepositoryPackCollection.resetcCs|jj��dS)z.Release the mutex around the pack-names index.N)r�r+�unlockrOr(r(r)�
_unlock_names(sz&RepositoryPackCollection._unlock_namescCs�t�}|��D]"\}}}|�|d�d�|f�qt|�}t�}t|j�D]&\}}|�|d�dd�|D��f�qJ|j|}	||j}
|�|	�|�	|
�||	|
|fS)aWRead the pack names from disk, and compare it to the one in memory.

        :return: (disk_nodes, deleted_nodes, new_nodes)
            disk_nodes    The final set of nodes that should be referenced
            deleted_nodes Nodes which have been removed from when we started
            new_nodes     Nodes that are newly introduced
        rr<rEcss|]}d|VqdS)s%dNr()r*r�r(r(r)rX>r.z<RepositoryPackCollection._diff_pack_names.<locals>.<genexpr>)
rr>rAr?rrr�r�difference_updater�)r$�
disk_nodesr`r2rB�orig_disk_nodesZ
current_nodesre�sizes�
deleted_nodes�	new_nodesr(r(r)�_diff_pack_names,s	�



z)RepositoryPackCollection._diff_pack_namesc
Cs�g}g}g}t|�}|��D]$}|j|vr|�|j�|�|�q|D]x\}}|�|�}	||jvr�|	|j|kr�|�|�|��|	|j|<|�|�|�|�qF|	|j|<|�|�|�|�qF|||fS)aGiven the correct set of pack files, update our saved info.

        :return: (removed, added, modified)
            removed     pack names removed from self._names
            added       pack names added to self._names
            modified    pack names that had changed value
        )�dictrrer�r'r@rr
)
r$rm�removed�added�modifiedZ	new_namesr�rerBror(r(r)�&_syncronize_pack_names_from_disk_nodesMs(


	



z?RepositoryPackCollection._syncronize_pack_names_from_disk_nodescs�g�|��z�|��}|��\}}}}|D]\}}	|�|�d�f|	�q*|jjd|��|jj	�
�d�||_|r�d}
|r�dd�|D�}
|�|
��W|�
�n
|�
�0|�|�|rЇfdd�|D�}|�|�d	d�|D�S)
aNSave the list of packs.

        This will take out the mutex around the pack names list for the
        duration of the method call. If concurrent updates have been made, a
        three-way merge between the current list and the current in memory list
        is performed.

        :param clear_obsolete_packs: If True, clear out the contents of the
            obsolete_packs directory.
        :param obsolete_packs: Packs that are obsolete once the new pack-names
            file has been written.
        :return: A list of the names saved that were not previously on disk.
        r<rXr�NcSsh|]
}|j�qSr(rd�r*�or(r(r)r3�r.z<RepositoryPackCollection._save_pack_names.<locals>.<setcomp>csg|]}|j�vr|�qSr(rdrx�Zalready_obsoleter(r)r-�s
�z=RepositoryPackCollection._save_pack_names.<locals>.<listcomp>cSsg|]}|d�qSrr()r*Znew_noder(r(r)r-�r.)r-r�rrZadd_node�encoder�Zput_filer�r�r�r�rr3rkrwr_)r$r$r%�builderrmrprqrnrerBZto_preserver(rzr)r)xs0�
�

z)RepositoryPackCollection._save_pack_namesc	CsJ|��}|rdS|��\}}}}||_|�|�\}}}|sB|sB|rFdSdS)aKSync our pack listing with what is present in the repository.

        This should be called when we find out that something we thought was
        present is now missing. This happens when another process re-packs the
        repository, etc.

        :return: True if the in-memory list of packs has been altered at all.
        TF)r0rrrrw)	r$Z
first_readrmrprqrnrtrurvr(r(r)r�s��z*RepositoryPackCollection.reload_pack_namescCs"|��s
�t�|jdt����dS�z:Reload the pack names list, and restart the autopack code.FN)rrrr��sys�exc_inforOr(r(r)r�sz*RepositoryPackCollection._restart_autopackcCs |��s
�t|jdt����dSr})rr2r�r~rrOr(r(r)r8�sz1RepositoryPackCollection._restart_pack_operationsc	Cs�g}|j�d�}|durt�}z|�d�}WntjyD|YS0|D]x}t�|�\}}|dkrn|�|�||vrxqJz|�	|�WqJtj
tjfy�}ztd|f�WYd}~qJd}~00qJ|S)z�Delete everything from the obsolete-packs directory.

        :return: A list of pack identifiers (the filename without '.pack') that
            were found in obsolete_packs.
        r%N�.rcz.couldn't delete obsolete pack, skipping it:
%s)
r�ZclonerZlist_dirrrTr��splitextr�r�r\r]r)	r$Zpreserve�foundZobsolete_pack_transportZobsolete_pack_files�filenamereZextrUr(r(r)r3�s*

�z.RepositoryPackCollection._clear_obsolete_packscCs|j��st�|��|j|d|jj��d�|_|j�	|jj|j�|j
�	|jj
|j�|j�	|jj|j�|jjjdd�|j
�	|jj
|j�|jdur�|j�	|jj|j�|jj|jjj_|jjjdd�|j
j|jjj_|jj|jjj_|j
j|jjj_|jj|jjj_dS)Nrcr�Fr�)r��is_write_lockedrZNotWriteLockedr�r�r�r�rHr�rIr!r�rJrKr�Z	chk_bytesrtZ
_add_callbackrR�	revisions�
signaturesrQrOr(r(r)�_start_write_group�s<


�����
��z+RepositoryPackCollection._start_write_groupc	Cs�|jdur`t���>}|�t|dd�|j|j|jdd�|j��Wd�n1sV0Y|jD]F}t���*}|j|j|dd�|��Wd�qf1s�0Yqf|jdd�=dS)Nr�T)rh)r�Zcleanup�	ExitStack�callbackrzrfr�r	)r$�stack�resumed_packr(r(r)�_abort_write_group
s

�(


�(z+RepositoryPackCollection._abort_write_groupcCs&|jD]}|�|�q|jdd�=dSrS)r	rf)r$r�r(r(r)�_remove_resumed_pack_indices"s
z5RepositoryPackCollection._remove_resumed_pack_indicescCsgS)z�Detect missing inventories in this write group.

        :returns: list of strs, summarising any problems found.  If the list is
            empty no problems were found.
        r(rOr(r(r)�_check_new_inventories'sz/RepositoryPackCollection._check_new_inventoriesc	sPt�}d|jjfd|jjfd|jjfd|jjffD](\�}|��}|��fdd�|D��q2|rxt�	d|jt
|�f��|��}|r�d�|�}t�	d	|��|�
|j�d
}|j��r�|j��|�|j�d|_d}n|j��d|_|jD]0}d|j|j<|�|�|��|�|�d}q�|jdd�=|�rL|��}|�sH|��S|SgS)Nr�rRrQr�csg|]}�f|�qSr(r(r1��prefixr(r)r-:r.z@RepositoryPackCollection._commit_write_group.<locals>.<listcomp>z3Repository %s has missing compression parent(s) %r �
z&Cannot add revision(s) to repository: FT)rr�r�rRrQr�Z#get_missing_compression_parent_keysr�rr^r\r�r�rfr�r�r�rWr�r	rrer'rr))	r$Zall_missingZversioned_fileraZproblemsZproblems_summaryZany_new_contentr�rr(r�r)�_commit_write_group1sT



���
�





z,RepositoryPackCollection._commit_write_groupcCsfdd�|jD�}|�|j�|j��rJ|jjdd�|�|jj�d|_n|j��d|_|��|S)NcSsg|]
}|j�qSr(rd)r*r�r(r(r)r-br.zARepositoryPackCollection._suspend_write_group.<locals>.<listcomp>T)r�)	r	rfr�r�r�r�rer�r��r$�tokensr(r(r)�_suspend_write_groupas

z-RepositoryPackCollection._suspend_write_groupcCs|D]}|�|�qdSrS)rV)r$r��tokenr(r(r)�_resume_write_grouposz,RepositoryPackCollection._resume_write_group)N)NF)FF)F)FN)N)3r7r8r9r:r�rSrr7rr�rrrrrrr-r/r�r1rr0r@r
rVrWr>rJrrr_rrer'rfrirkrrrwr)rrr8r3r�r�r�r�r�r�r�r(r(r(r)r�sb9(�
%
4


-

!+
0

0rc@s�eZdZdZdZdZdd�Zdd�Zdd�Zd	d
�Z	dd�Z
d
d�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zd,dd�Zdd�Zdd �Zd!d"�Zd-d$d%�Zd.d&d'�Zd(d)�Zeejej�d*d+��ZdS)/�PackRepositoryaRepository with knit objects stored inside pack containers.

    The layering for a KnitPackRepository is:

    Graph        |  HPSS    | Repository public layer |
    ===================================================
    Tuple based apis below, string based, and key based apis above
    ---------------------------------------------------
    VersionedFiles
      Provides .texts, .revisions etc
      This adapts the N-tuple keys to physical knit records which only have a
      single string identifier (for historical reasons), which in older formats
      was always the revision_id, and in the mapped code for packs is always
      the last element of key tuples.
    ---------------------------------------------------
    GraphIndex
      A separate GraphIndex is used for each of the
      texts/inventories/revisions/signatures contained within each individual
      pack file. The GraphIndex layer works in N-tuples and is unaware of any
      semantic value.
    ===================================================

    NcCsVt�||||�||_||_d|_|jjr<t�|�	��|_
nt�|�|_
|j
��dS)NT)r
r�_commit_builder_class�_serializerZ_reconcile_fixes_text_parentsr.�supports_external_lookupsrZCachingParentsProviderZ _make_parents_provider_unstacked�_unstacked_provider�
disable_cache)r$r.�a_controldirr+r�r�r(r(r)r�s�zPackRepository.__init__cCs@|���$dd�|j��D�Wd�S1s20YdS)z"See Repository.all_revision_ids().cSsg|]}|d�qSrr(r1r(r(r)r-�r.z4PackRepository._all_revision_ids.<locals>.<listcomp>N)�	lock_readr�r5rOr(r(r)�_all_revision_ids�s
z PackRepository._all_revision_idscCs|jjj��|j��dSrS)r�rt�_key_dependenciesr�r r�rOr(r(r)r��sz!PackRepository._abort_write_groupcCs$|jjs|jSt�t|jg|j��SrS)r.r�r�rZStackedParentsProviderr�_fallback_repositoriesrOr(r(r)�_make_parents_provider�s

�z%PackRepository._make_parents_providercCs.|��sdS|j��|j��|j��dSrS)r=r rr�r��enable_cacherOr(r(r)�
_refresh_data�s


zPackRepository._refresh_datacCs|j��dSrS)r r�rOr(r(r)r��sz!PackRepository._start_write_groupcCs0|j��}|jjj��|j��|j��|SrS)	r r�r�rtr�r�r�r�r�)r$r4r(r(r)r��s



z"PackRepository._commit_write_groupcCs"|j��}|jjj��d|_|SrS)r r�r�rtr�r��_write_groupr�r(r(r)�suspend_write_group�s
z"PackRepository.suspend_write_groupcCsZ|��z|j�|�Wntjy6|���Yn0|jjD]}|jj�	|j
�q@dSrS)r�r r�rrRr�r	r�rtZscan_unvalidated_indexrH)r$r�r�r(r(r)r��sz"PackRepository._resume_write_groupcCs|jr|jS|j��SdSrS)�_write_lock_count�_transactionr+�get_transactionrOr(r(r)r��szPackRepository.get_transactioncCs|jp|j��SrS)r�r+r=rOr(r(r)r=�szPackRepository.is_lockedcCs|jSrS)r�rOr(r(r)r��szPackRepository.is_write_lockedcCs�|��}|js|rt�|��|jd7_|jdkr>t��|_|s�dtjvr`|j	dkr`t
d|�d|_	|j��|j
D]}|��qv|��t|jd�S)ziLock the repository for writes.

        :return: A breezy.repository.RepositoryWriteLockResult.
        r0�relock�wz%r was write locked againN)r=r�rZ
ReadOnlyErrorZtransactionsZWriteTransactionr�r�r��
_prev_lockrr�r�r�r�r�rrj)r$r��lockedr�r(r(r)r,�s







zPackRepository.lock_writecCs�|��}|jr|jd7_n
|j��|svdtjvrJ|jdkrJtd|�d|_|j�	�|j
D]}|��q`|��t|j
�S)zZLock the repository for reads.

        :return: A breezy.lock.LogicalLockResult.
        r0r�rWz%r was read locked again)r=r�r+r�r�r�r�rr�r�r�r�r
rj)r$r�r�r(r(r)r��s




zPackRepository.lock_readcCst|j��dSrS)r��leave_lock_in_placerOr(r(r)r�
sz"PackRepository.leave_lock_in_placecCst|j��dSrS)r��dont_leave_lock_in_placerOr(r(r)r�sz'PackRepository.dont_leave_lock_in_placeFcCs<|��� |jj||d�Wd�n1s.0YdS)z�Compress the data within the repository.

        This will pack all the data to a single pack. In future it may
        recompress deltas or do other such expensive operations.
        )r4r5N)r,r r�)r$r4r5r(r(r)r�s
�zPackRepository.packcCsLddlm}|���$|||d�}|��Wd�S1s>0YdS)zReconcile this repository.r0)�PackReconciler)�thoroughN)�	reconciler�r,)r$r�r�r�Z
reconcilerr(r(r)r�s
zPackRepository.reconcilecCst|j��dSrS)r��_reconcile_pack)r$Z
collectionr��	extensionZrevsr�r(r(r)r�#szPackRepository._reconcile_packcCs�|jdkr@|jdur@|��|j��d|_d|_t�d|��|jrp|jd8_|jsz|j}d|_|��n
|j	�
�|��s�|j��|jD]}|�
�q�dS)Nr0rz6Must end write group before releasing write lock on %s)
r�r�Zabort_write_groupr�r�r�rr�r�r+rjr=r�)r$Ztransactionr�r(r(r)rj&s*
��



zPackRepository.unlock)N)NF)NF)r7r8r9r:r�r�rr�r�r�r�r�r�r�r�r�r=r�r,r�r�r�r�r�r�r	rZLockNotHeldZ
LockBrokenrjr(r(r(r)r�ts0
	




r�c@sTeZdZdZdZdZdZdZdZdZ	dZ
dZdZdZ
dZdZd	dd�Zd
dd�ZdS)�RepositoryFormatPacka�Format logic for pack structured repositories.

    This repository format has:
     - a list of packs in pack-names
     - packs in packs/NAME.pack
     - indices in indices/NAME.{iix,six,tix,rix}
     - knit deltas in the packs, knit indices mapped to the indices.
     - thunk objects to support the knits programming API.
     - a format marker of its own
     - an optional 'shared-storage' flag
     - an optional 'no-working-trees' flag
     - a LockDir lock
    NTFcCsltd|jj�gd�}|��}d|��fg}d|��fg}|�|||||�|j|dd�}|�|||�|S)aCreate a pack based repository.

        :param a_controldir: bzrdir to contain the new repository; must already
            be initialized.
        :param shared: If true the repository will be initialized as a shared
                       repository.
        zcreating repository in %s.)r�r%r�ZuploadrX�formatT)r��_found)	rr�r�r�r�Zget_format_stringZ_upload_blank_contentr�Z_run_post_repo_init_hooks)r$r�Zshared�dirsr|�filesZ
utf8_filesr%r(r(r)�
initializefs
�zRepositoryFormatPack.initializecCsN|st�|�}|dur|}n
|�d�}t�|dtj�}|j||||j|j	d�S)aSee RepositoryFormat.open().

        :param _override_transport: INTERNAL USE ONLY. Allows opening the
                                    repository at a slightly different url
                                    than normal. I.e. during 'upgrade'.
        N�lock)r.r�r+r�r�)
rZfind_formatZget_repository_transportrZ
LockableFilesrZLockDir�repository_classr�r�)r$r�r�Z_override_transportr�Zrepo_transportr+r(r(r)r�zs

��zRepositoryFormatPack.open)F)FN)r7r8r9r:r�r�r�Zsupports_ghostsr�Z
supports_chksr�ruZ_fetch_uses_deltasZfast_deltasZsupports_funky_charactersZ%revision_graph_can_have_wrong_parentsr�r�r(r(r(r)r�?s
r�c@seZdZdZdZdZdS)r2z�Raised when we are packing and we find a missing file.

    Meant as a signaling exception, to tell the RepositoryPackCollection.pack
    code it should try again.
    TzWPack files have changed, reload and try pack again. context: %(context)s %(orig_error)sN)r7r8r9r:Zinternal_errorZ_fmtr(r(r(r)r2�sr2c@sJeZdZdZddd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dS)r�z:Access to data in one or more packs with less translation.NcCs"d|_d|_||_||_||_dS)aCreate a _DirectPackAccess object.

        :param index_to_packs: A dict mapping index objects to the transport
            and file names for obtaining data.
        :param reload_func: A function to call if we determine that the pack
            files have moved and we need to reload our caches. See
            breezy.repo_fmt.pack_repo.AggregateIndex for more details.
        N)�_container_writerr�r�r��_flush_func)r$Zindex_to_packsr�r�r(r(r)r�s
	z_DirectPackAccess.__init__cCs |j�||g�\}}|j||fS)a�Add raw knit bytes to a storage area.

        The data is spooled to the container writer in one bytes-record per
        raw data item.

        :param key: key of the data segment
        :param size: length of the data segment
        :param raw_data: A bytestring containing the data.
        :return: An opaque index memo For _DirectPackAccess the memo is
            (index, pos, length), where the index field is the write_index
            object supplied to the PackAccess object.
        )r�Zadd_bytes_recordr�)r$r2r��raw_dataZp_offsetZp_lengthr(r(r)�add_raw_record�s
�z _DirectPackAccess.add_raw_recordcCshd�|�}t|t�s$tdt|���g}d}|D]2\}}|�|�||||||�g��||7}q0|S)aMAdd raw knit bytes to a storage area.

        The data is spooled to the container writer in one bytes-record per
        raw data item.

        :param sizes: An iterable of tuples containing the key and size of each
            raw data segment.
        :param raw_data: A bytestring containing the data.
        :return: A list of memos to retrieve the record later. Each memo is an
            opaque index memo. For _DirectPackAccess the memo is (index, pos,
            length), where the index field is the write_index object supplied
            to the PackAccess object.
        r.zdata must be plain bytes was %sr)r�r|r�r�r�r�r�)r$Z	key_sizesr�rr�r2r�r(r(r)�add_raw_records�s


��
z!_DirectPackAccess.add_raw_recordscCs|jdur|��dS)zoFlush pending writes on this access object.

        This will flush any buffered writes to a NewPack.
        N)r�rOr(r(r)r��s
z_DirectPackAccess.flushc	cs0g}d}|D]F\}}}||kr.|�||f�q|durD|�||f�|}||fg}q|durj|�||f�|D]�\}}z|j|\}	}
Wn2ty�|jdur��tj|dt��d��Yn0z.t�	|	|
|�}|�
�D]\}}
|
d�Vq�Wqntj�y(|jdu�r
�tj|	�|
�dt��d��Yqn0qndS)aZGet the raw bytes for a records.

        :param memos_for_retrieval: An iterable containing the (index, pos,
            length) memo for retrieving the bytes. The Pack access method
            looks up the pack to use for a given record in its index_to_pack
            map.
        :return: An iterator over the bytes of the records.
        NT)�reload_occurredrF)
r�r�rIr�rr&r~rr�Zmake_readv_readerZiter_recordsrT�abspath)r$Zmemos_for_retrievalZ
request_listsZ
current_indexr`r�ZlengthZcurrent_listZoffsetsr��path�readerrZ	read_funcr(r(r)�get_raw_records�s@

��z!_DirectPackAccess.get_raw_recordscCs"|dur||j|<||_||_dS)z$Set a writer to use for adding data.N)r�r�r�)r$�writerr`Ztransport_packnamer(r(r)r�s
z_DirectPackAccess.set_writercCs8d}|jdurd}n|��s&|js&d}|r4t|j�dS)a�Try calling the reload function, or re-raise the original exception.

        This should be called after _DirectPackAccess raises a
        RetryWithNewPacks exception. This function will handle the common logic
        of determining when the error is fatal versus being temporary.
        It will also make sure that the original exception is raised, rather
        than the RetryWithNewPacks exception.

        If this function returns, then the calling function should retry
        whatever operation was being performed. Otherwise an exception will
        be raised.

        :param retry_exc: A RetryWithNewPacks exception.
        FNT)r�r�rr)r$Z	retry_excZis_errorr(r(r)�reload_or_raises
z!_DirectPackAccess.reload_or_raise)NN)r7r8r9r:rr�r�r�r�r�r�r(r(r(r)r��s
2r�)/Z
__future__rrPr~r�globalsr�rrrZbzrrZ
decoratorsr	r�r
r%rrZbzr.repositoryr
rZsixishrrZbzr.vf_repositoryrrrZtracerrrr�objectr;r�r�r�r�r�rr�r�r&r2r�r(r(r(r)�<module>sB!EhVw}LQ

Youez - 2016 - github.com/yon3zu
LinuXploit