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__/vf_repository.cpython-39.pyc
a

�*�^"�@s�dZddlmZddlmZee�d�ddlmZddlmZdd	l	m
Z
mZmZdd
l
mZmZmZmZmZmZddl
mZmZddlmZmZmZmZdd
lmZddlmZGdd�de�ZGdd�de�Z Gdd�de�Z!Gdd�dee!�Z"Gdd�dee�Z#Gdd�de$�Z%Gdd�de$�Z&Gdd�de$�Z'Gdd �d e�Z(Gd!d"�d"e(�Z)Gd#d$�d$e(�Z*e�+e(�e�+e)�e�+e*�d,d&d'�Z,d(d)�Z-d*d+�Z.d%S)-z0Repository formats built around versioned files.�)�absolute_import�)�lazy_importa
import itertools

from breezy import (
    config as _mod_config,
    debug,
    fifo_cache,
    gpg,
    graph,
    lru_cache,
    osutils,
    revision as _mod_revision,
    static_tuple,
    tsort,
    ui,
    )
from breezy.bzr import (
    fetch as _mod_fetch,
    check,
    generate_ids,
    inventory_delta,
    inventorytree,
    versionedfile,
    vf_search,
    )
from breezy.bzr.bundle import serializer

from breezy.recordcounter import RecordCounter
from breezy.i18n import gettext
from breezy.bzr.testament import Testament
)�errors)�only_raises�)�	Inventory�ROOT_ID�
entry_factory)�
CommitBuilder�FetchResult�InterRepository�
Repository�RepositoryFormat�
WriteGroup)�MetaDirRepository�RepositoryFormatMetaDir)�BytesIO�range�	viewitems�
viewvalues)�mutter)�
TreeChangec@s(eZdZdZdZdZdZdZdZdZ	dS)�VersionedFileRepositoryFormatzDBase class for all repository formats that are VersionedFiles-based.T�	unorderedFN)
�__name__�
__module__�__qualname__�__doc__�supports_full_versioned_filesZsupports_versioned_directoriesZsupports_unreferenced_revisions�_commit_inv_deltas�_fetch_order�_fetch_uses_deltas�r#r#�:/usr/lib/python3/dist-packages/breezy/bzr/vf_repository.pyr]srcs�eZdZdZd �fdd�	Zdd�Zdd	�Zd
d�Zdd
�Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zefdd�Zdd�Z�ZS)!�VersionedFileCommitBuilderzJCommit builder implementation for versioned files based repositories.
    NFc
svtt|��|||||||||	�	z|jd}
WntyFtj}
Yn0|
|_d|_g|_	t
�|���j
|_d|_dS)NrF)�superr%�__init__�parents�
IndexError�
_mod_revision�
NULL_REVISION�basis_delta_revision�_new_inventory�_basis_delta�graphZ
HeadsCache�	get_graph�heads�"_VersionedFileCommitBuilder__heads�_any_changes)�self�
repositoryr(�config_stack�	timestamp�timezone�	committer�revprops�revision_id�lossy�basis_id��	__class__r#r$r'us�z#VersionedFileCommitBuilder.__init__cCs|jS)z�Return True if any entries were changed.

        This includes merge-only changes. It is the core for the --unchanged
        detection in commit.

        :return: True if any changes have occured.
        )r3�r4r#r#r$�any_changes�sz&VersionedFileCommitBuilder.any_changesc	s�|jjsdS|jjjs t�d��dd�|jD�}|jjj�	|���fdd�|D�}t
t|jj��}dd�|D�}g}|r�|r�|��}|�
|jj�}|j��}|�||�}qt|r�t�d��dS)	aREnsure that appropriate inventories are available.

        This only applies to repositories that are stacked, and is about
        enusring the stacking invariants. Namely, that for any revision that is
        present, we either have all of the file content, or we have the parent
        inventory and the delta file content.
        N�yCannot commit directly to a stacked branch in pre-2a formats. See https://bugs.launchpad.net/bzr/+bug/375013 for details.cSsg|]
}|f�qSr#r#)�.0�pr#r#r$�
<listcomp>��zKVersionedFileCommitBuilder._ensure_fallback_inventories.<locals>.<listcomp>csh|]}|�vr|�qSr#r#�rCZpk��
parent_mapr#r$�	<setcomp>�s�zJVersionedFileCommitBuilder._ensure_fallback_inventories.<locals>.<setcomp>cSsg|]}d|df�qS)�inventoriesrr#rGr#r#r$rE�s�z9Unable to fill in parent inventories for a stacked branch)r5�_fallback_repositories�_format�
supports_chksr�BzrErrorr(rK�_index�get_parent_map�list�reversed�pop�_get_source�	_get_sink�insert_missing_keys)	r4�parent_keysZmissing_parent_keysZfallback_repos�missing_keys�
resume_tokensZ
fallback_repo�sourceZsinkr#rHr$�_ensure_fallback_inventories�s*


��
z7VersionedFileCommitBuilder._ensure_fallback_inventoriesc	Cs�|�|d�tj|j|j|j||j|j|jd�}|j	|_
|j�d�t
jkrzt||���}|��}|j�t�|j�||j�|j�|�|��|j��|jS)z\Make the actual commit.

        :return: The revision id of the recorded revision.
        zcommit message)r7r8r9�message�inventory_sha1r;Z
propertiesZcreate_signatures)Z_validate_unicode_textr*ZRevision�
_timestampZ	_timezone�
_committer�inv_sha1�_new_revision_idZ	_revpropsr(�
parent_idsZ
_config_stack�getZ_mod_configZSIGN_ALWAYS�	Testament�
revision_tree�
as_short_textr5�store_revision_signature�gpgZGPGStrategy�
_add_revisionr\�commit_write_group)r4r]�rev�	testament�	plaintextr#r#r$�commit�s,��
z!VersionedFileCommitBuilder.commitcCs|j��dS)z.Abort the commit that is being built.
        N)r5�abort_write_groupr@r#r#r$�abort�sz VersionedFileCommitBuilder.abortcCs.|jdur|j�|j�|_t�|j|j|j�S)aWReturn the tree that was just committed.

        After calling commit() this can be called to get a
        RevisionTree representing the newly committed tree. This is
        preferred to calling Repository.revision_tree() because that may
        require deserializing the inventory, while we already have a copy in
        memory.
        N)r-r5�
get_inventoryrb�
inventorytree�InventoryRevisionTreer@r#r#r$rf�s	
��z(VersionedFileCommitBuilder.revision_treecCs,|j}|j�||j|j|j�\|_|_|jS)z�Tell the builder that the inventory is finished.

        :return: The inventory id in the repository, which can be used with
            repository.get_inventory.
        )r,r5�add_inventory_by_deltar.rbr(rar-)r4r=r#r#r$�finish_inventory�s
�z+VersionedFileCommitBuilder.finish_inventorycCst�|j|j�S)zReturn new revision-id.)Zgenerate_idsZgen_revision_idr`r_r@r#r#r$�_gen_revision_id�sz+VersionedFileCommitBuilder._gen_revision_idcCs\|j��rdSt|j�dkr$t���td|�d�dd�}|j|_	|j
�dd|j|f�dS)aEnforce an appropriate root object change.

        This is called once when record_iter_changes is called, if and only if
        the root was not in the delta calculated by record_iter_changes.

        :param tree: The tree which is being committed.
        Nr�	directory�)
r5�supports_rich_root�lenr(r�RootMissingr
�path2idrb�revisionr.�append�file_id)r4�tree�entryr#r#r$�_require_root_change�s
�z/VersionedFileCommitBuilder._require_root_changecCsh|�|j�s*d||j|f}|j�|�|S||�|j�kr`|�|j�||j|f}|j�|�|SdSdS)z/Get a delta against the basis inventory for ie.N)Zhas_idr�r.r�	get_entry�id2path)r4�ie�	basis_inv�path�resultr#r#r$�
_get_deltasz%VersionedFileCommitBuilder._get_deltacCs
|�|�S)z�Calculate the graph heads for revision_ids in the graph of file_id.

        This can use either a per-file graph or a global revision graph as we
        have an identity relationship between the two graphs.
        )r2)r4r��revision_idsr#r#r$�_headssz!VersionedFileCommitBuilder._headscCs|jS)z�Return the complete inventory delta versus the basis inventory.

        :return: An inventory delta, suitable for use with apply_delta, or
            Repository.add_inventory_by_delta, etc.
        )r.r@r#r#r$�get_basis_deltasz*VersionedFileCommitBuilder.get_basis_deltac$cs�i}i}d}zt|j�|j��}Wnrtjy�g}|jD]R}	z|�|j�|	��Wq<tjy�|sttj	}d}|�|j�tj	��Yq<0q<Yn0|r�|d}
n|j�tj	�}
|
j
}t|j�dk�r�||jdkr�|s�td��|dd�D]�}|j
�
|�D]�}
|
ddu�rq�|
d|v�r�|
ddu�rv|�|
d�}|j|
djg||
d<|j||
dj|
di||
d<n.|
djg||
d<|
dj|
di||
d<q�||
d�|
dj�|
d||
d|
dj<q�q�ni}i}|D]D}
|
jddu�r|�|
j�jg}ng}|
|�|
j|�f||
j<�q�t|�t|�}|D]�}z|�|�}Wntj�ylYnX0t||�|�|�|�fdd	|j|jf|j|jf|j|jf|j|jf�}
|
||f||<�qDd}|j}|j}t|�D�]L\}
}|
jd�r�|
jd}|
j}||||
jd|
jd�}|�|
jt|��}g}|D]$}||v�r<|�|�|� |��q<d}t|�dk�r�|�|d�}|�r�|�|dd�}nd}|du�r�d}n4|j|jk�s�|j|jk�s�|j|jk�r�d}nd}nd}|d
k�r�|
jd�rd|_nd|_|�r&|j|jk�r&|j!}nd}|�"|
jd�\} }!zzzB|j#|| |||!�rZ|!j$ndd�\|_!|_%|
jd|j!|!ffVWn*tj&�y�d}|j%|_%|j!|_!Yn0W| �'�n
| �'�0�n|dk�r|�(|
jd�|_)|�r�|j)|j)k�r�d}n|j#|
jt*�|ddd�n�|d
k�rd|�r.d}n4|
jddk�sJ|j�+��r�|j#|
jt*�|ddd�nz|dk�r�|jj,j-�s�t�.|j/|j��|�0|
jd�}"|"|_1|�r�|j1|"k�r�d}n|j#|
jt*�|ddd�nt2d|��|�s�||_n|j|_nd}|
jd}#|�|
jd|#|
j|f�|#dk�r�d}�q�t|�dk�rJ|tj	k�sdt|�dk�rj|tj	k�rjd|_3|�sz|�4|�||_5dS)aYRecord a new tree via iter_changes.

        :param tree: The tree to obtain text contents from for changed objects.
        :param basis_revision_id: The revision id of the tree the iter_changes
            has been generated against. Currently assumed to be the same
            as self.parents[0] - if it is not, errors may occur.
        :param iter_changes: An iter_changes iterator with the changes to apply
            to basis_revision_id. The iterator must not include any items with
            a current kind of None - missing items must be either filtered out
            or errored-on before record_iter_changes sees the item.
        :param _entry_factory: Private method to bind entry_factory locally for
            performance.
        :return: A generator of (relpath, fs_hash) tuples for use with
            tree._observed_sha1.
        FTrz5arbitrary basis parents not yet supported with mergesrNr�)TT�file��size�symlinkrxryztree-referencezunknown kind %r)6rRr5�revision_treesr(r�NoSuchRevisionrrfr*r+�root_inventoryr{�	Exception�_make_deltar�r~r�r�rd�set�NoSuchIdrr��	parent_id�name�kind�
executabler.rbrZ	versionedr��removeZ	text_sha1Zget_file_with_stat�_add_file_to_weave�st_sizeZ	text_sizeZExistingContent�closeZget_symlink_targetZsymlink_targetrrzrM�supports_tree_reference�UnsupportedOperationZ
add_referenceZget_reference_revision�reference_revision�AssertionErrorr3r�r,)$r4r��basis_revision_idZiter_changesZ_entry_factoryZ
merged_idsZparent_entriesZghost_basisZrevtreesr;�
basis_treer�ZrevtreeZchangeZbasis_entryZchangesZhead_candidateZunchanged_mergedr�Z	seen_root�	inv_deltaZmodified_revZhead_candidatesr�r�Zhead_setr1Zcarried_overZparent_entry_revs�parent_entryZcarry_over_possible�nostore_shaZfile_objZ
stat_valuer��new_pathr#r#r$�record_iter_changes$sn

�
������
��



�
�



�
�

��
����
�
�����



��
z.VersionedFileCommitBuilder.record_iter_changescsHt�fdd�|D��}|jjjtj�|jf|||d�||jd�dd�S)Ncsg|]}�|f�qSr#r#�rC�parent�r�r#r$rE>rFzAVersionedFileCommitBuilder._add_file_to_weave.<locals>.<listcomp>r�)r�Z	random_idrr)�tupler5�textsZadd_content�
versionedfileZFileContentFactoryrbZrandom_revid)r4r��fileobjr(r�r�rXr#r�r$r�=s���z-VersionedFileCommitBuilder._add_file_to_weave)NNNNNF)rrrrr'rAr\rorqrfrvrwr�r�r�r�r
r�r��
__classcell__r#r#r>r$r%qs*�
"	�
r%cs:eZdZdZeZdd�Zddd�Zee	j
e	j��fdd��Zd	d
�Z
dd�Zd�dd�Zd�dd�Zd�dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd �Z�fd!d"�Zd�d#d$�Zd��fd%d&�	Zd�d'd(�Zd�d)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Z d3d4�Z!d5d6�Z"d7d8�Z#d9d:�Z$d;d<�Z%d=d>�Z&d?d@�Z'd�dAdB�Z(dCdD�Z)d�dEdF�Z*dGdH�Z+d�dIdJ�Z,dKdL�Z-dMdN�Z.dOdP�Z/d�dQdR�Z0dSdT�Z1dUdV�Z2dWdX�Z3dYdZ�Z4d[d\�Z5d]d^�Z6d_d`�Z7d�dadb�Z8dcdd�Z9dedf�Z:dgdh�Z;didj�Z<dkdl�Z=d�dmdn�Z>dodp�Z?dqdr�Z@dsdt�ZAd�dudv�ZBdwdx�ZCdydz�ZDd{d|�ZEd�d}d~�ZF�ZGS)��VersionedFileRepositoryakRepository holding history for one or more branches.

    The repository holds and retrieves historical information including
    revisions and file history.  It's normally accessed only by the Branch,
    which views a particular line of development through that history.

    The Repository builds on top of some byte storage facilies (the revisions,
    signatures, inventories, texts and chk_bytes attributes) and a Transport,
    which respectively provide byte storage and a means to access the (possibly
    remote) disk.

    The byte storage facilities are addressed via tuples, which we refer to
    as 'keys' throughout the code base. Revision_keys, inventory_keys and
    signature_keys are all 1-tuples: (revision_id,). text_keys are two-tuples:
    (file_id, revision_id). chk_bytes uses CHK keys - a 1-tuple with a single
    byte string made up of a hash identifier and a hash value.
    We use this interface because it allows low friction with the underlying
    code that implements disk indices, network encoding and other parts of
    breezy.

    :ivar revisions: A breezy.versionedfile.VersionedFiles instance containing
        the serialised revisions for the repository. This can be used to obtain
        revision graph information or to access raw serialised revisions.
        The result of trying to insert data into the repository via this store
        is undefined: it should be considered read-only except for implementors
        of repositories.
    :ivar signatures: A breezy.versionedfile.VersionedFiles instance containing
        the serialised signatures for the repository. This can be used to
        obtain access to raw serialised signatures.  The result of trying to
        insert data into the repository via this store is undefined: it should
        be considered read-only except for implementors of repositories.
    :ivar inventories: A breezy.versionedfile.VersionedFiles instance containing
        the serialised inventories for the repository. This can be used to
        obtain unserialised inventories.  The result of trying to insert data
        into the repository via this store is undefined: it should be
        considered read-only except for implementors of repositories.
    :ivar texts: A breezy.versionedfile.VersionedFiles instance containing the
        texts of files and directories for the repository. This can be used to
        obtain file texts or file graphs. Note that Repository.iter_file_bytes
        is usually a better interface for accessing file texts.
        The result of trying to insert data into the repository via this store
        is undefined: it should be considered read-only except for implementors
        of repositories.
    :ivar chk_bytes: A breezy.versionedfile.VersionedFiles instance containing
        any data the repository chooses to store or have indexed by its hash.
        The result of trying to insert data into the repository via this store
        is undefined: it should be considered read-only except for implementors
        of repositories.
    :ivar _transport: Transport for file access to repository, typically
        pointing to .bzr/repository.
    cCs�|jjst�|j|j��|�|�|��r2|��|j�	|�|j
�|j
�|j�|j�|j
�|j
�|j�|j�|jdur�|j�|j�dS)zpAdd a repository to use for looking up data not held locally.

        :param repository: A repository.
        N)rM�supports_external_lookupsrZUnstackableRepositoryFormat�baseZ_check_fallback_repository�	is_locked�	lock_readrLrr�Zadd_fallback_versioned_filesrK�	revisions�
signatures�	chk_bytes)r4r5r#r#r$�add_fallback_repositorys

z/VersionedFileRepository.add_fallback_repositoryNcCst�|||||�S�N)�
serializerZwrite_bundle)r4�targetr�r��formatr#r#r$�
create_bundle�sz%VersionedFileRepository.create_bundlecs(tt|���|jjdkr$|j��dS)Nr)r&r��unlock�
control_filesZ_lock_count�_inventory_entry_cache�clearr@r>r#r$r��szVersionedFileRepository.unlockcCsf|��std|f��t�|�|jdusF|j|ksFtd|j|f��|jdurXt���|�|||�S)alAdd the inventory inv to the repository as revision_id.

        :param parents: The revision ids of the parents that revision_id
                        is known to have and are in the repository already.

        :returns: The validator(which is a sha1 digest, though what is sha'd is
            repository format specific) of the serialized inventory.
        �%r not in write groupNzCMismatch between inventory revision id and insertion revid (%r, %r))	�is_in_write_groupr�r*�check_not_reserved_idr;�rootrr|�_add_inventory_checked)r4r;�invr(r#r#r$�
add_inventory�s	
��
z%VersionedFileRepository.add_inventorycCs|j�|�}|j|||dd�S)z�Add inv to the repository after checking the inputs.

        This function can be overridden to allow different inventory styles.

        :seealso: add_inventory, for the contract.
        F��
check_content)�_serializerZwrite_inventory_to_lines�_inventory_add_lines)r4r;r�r(Z	inv_linesr#r#r$r��s�z.VersionedFileRepository._add_inventory_checkedFcCs�|��std|f��t�|�|�|�}|���@|durB|j}|�|�||_|�	|||�|fWd�S1sx0YdS)aAdd a new inventory expressed as a delta against another revision.

        See the inventory developers documentation for the theory behind
        inventory deltas.

        :param basis_revision_id: The inventory id the delta was created
            against. (This does not have to be a direct parent.)
        :param delta: The inventory delta (see Inventory.apply_delta for
            details).
        :param new_revision_id: The revision id that the inventory is being
            added for.
        :param parents: The revision ids of the parents that revision_id is
            known to have and are in the repository already. These are supplied
            for repositories that depend on the inventory graph for revision
            graph access, as well as for those that pun ancestry with delta
            compression.
        :param basis_inv: The basis inventory if it is already known,
            otherwise None.
        :param propagate_caches: If True, the caches for this inventory are
          copied to and updated for the result if possible.

        :returns: (validator, new_inv)
            The validator(which is a sha1 digest, though what is sha'd is
            repository format specific) of the serialized inventory, and the
            resulting inventory.
        r�N)
r�r�r*r�rfr�r�Zapply_deltar;r�)r4r��deltaZnew_revision_idr(r�Zpropagate_cachesr�r#r#r$ru�s



�z.VersionedFileRepository.add_inventory_by_deltaTcCs8dd�|D�}|jj|f|||d�d}|jj��|S)z;Store lines in inv_vf and return the sha1 of the inventory.cSsg|]
}|f�qSr#r#r�r#r#r$rE�rFz@VersionedFileRepository._inventory_add_lines.<locals>.<listcomp>r�r)rK�	add_linesZ_access�flush)r4r;r(�linesr�r�r#r#r$r��s��z,VersionedFileRepository._inventory_add_linescCsnt�|�|j�|fg�sF|dur2t�||j��q`|�|||j�|_n|f}|j�	|g�||_|�
|�dS)aAdd rev to the revision store as revision_id.

        :param revision_id: the revision id to use.
        :param rev: The revision object.
        :param inv: The inventory for the revision. if None, it will be looked
                    up in the inventory storer
        N)r*r�rKrQrZWeaveRevisionNotPresentr�rcr^Z	get_sha1srj)r4r;rlr��keyr#r#r$�add_revision�s

��z$VersionedFileRepository.add_revisioncCs<|j�|�}|jf}tdd�|jD��}|j�|||�dS)Ncss|]}|fVqdSr�r#r�r#r#r$�	<genexpr>rFz8VersionedFileRepository._add_revision.<locals>.<genexpr>)r�Zwrite_revision_to_linesr;r�rcr�r�)r4r~r�r�r(r#r#r$rjsz%VersionedFileRepository._add_revisioncCs:tj���}|�||�Wd�n1s,0YdS)z�Check the inventories found from the revision scan.

        This is responsible for verifying the sha1 of inventories and
        creating a pending_keys set that covers data referenced by inventories.
        N)�ui�
ui_factory�nested_progress_bar�_do_check_inventories)r4�checker�barr#r#r$�_check_inventoriessz*VersionedFileRepository._check_inventoriescCsd}t�t�t�d�}ddg}t|j�}|�td�dd�|j}i|_|D]H}|ddkrx|d|vrx|j�d|f�||d�|dd	��qJ|dr�d	}	|jj	|dd
�D]@}
|
j
dkr�|j�d|
jf�q�|�d|
||	|d
|
j�}	q�|d=nd	S|�td�d�|j�s,|d�s,|d�r|j}i|_|D]@}|d|v�r`|j�d|f�||d�|dd	���q<|D]�}||�r�d	}	t
||�j	||d
�D]H}
|
j
dk�r�|j�d||
jf�n|�||
||	||f|
j�}	�q�t�||<�q�q��qd	S)zHelper for _check_inventories.r)r�rKr�r�r�rKrzunknown key type %rrN)�keys�absentzMissing inventory {%s})rKzMissing %s {%s})r�r{Zpending_keys�update�gettext�
_report_itemsr�addrK�check�storage_kindr��
_check_record�getattr)r4r�r�Zrevnor�Zkinds�countZcurrent_keysr��last_object�recordr�r#r#r$r�sb


����
��
z-VersionedFileRepository._do_check_inventoriesc
Cs�|dkr�|jd}|�||�d��}|durb|�|�}|D]$\}	}
}}|durPq:|�|||�q:n |��D]\}
}|�|||�qj|jjr�|SnL|dkr�|j�	d|jf�n.|dkr�|�
|||�n|j�	d||jf�dS)	z)Check a single text from this repository.rKrr�Nr�z%unsupported key type chk_bytes for %sr�zunknown key type %s for %s)r��_deserialise_inventory�get_bytes_asr�r��iter_entriesrMZfast_deltasr�r�_check_text)
r4r�r�r�r��	item_data�rev_idr�r��old_pathr�r�r�r#r#r$r�Us0

�

��z%VersionedFileRepository._check_recordcCsX|�d�}t�|�}ttt|��}|rT||dkrT|j�d|j||d|df�dS)zCheck a single text.�chunkedrz:sha1 mismatch: %s has sha1 %s expected %s referenced by %srN)	r��osutilsZsha_strings�sum�mapr{r�rr�)r4r�r�r�ZchunksZsha1Zlengthr#r#r$r�ps

��z#VersionedFileRepository._check_textcCsJ|���.g}|��}|�|�}t|�Wd�S1s<0YdS)zwCheck every revision id in revision_ids to see if we have it.

        Returns a set of the present revisions.
        N)r�r0rQrR)r4r�r�r/rIr#r#r$� _eliminate_revisions_not_present|s


z8VersionedFileRepository._eliminate_revisions_not_presentcsNtt|��|||�|j|_|jj|_d|_d|_d|_t�	d�|_
d|_dS)z�Instantiate a VersionedFileRepository.

        :param _format: The format of the repository on disk.
        :param controldir: The ControlDir of the repository.
        :param control_files: Control files to use for locking, etc.
        TFi(N)r&r�r'Z
_transportr�Z_reconcile_does_inventory_gcZ_reconcile_fixes_text_parentsZ_reconcile_backsup_inventoryZ
fifo_cacheZ	FIFOCacher��_safe_to_return_from_cache�r4rMZa_controldirr�r>r#r$r'�s
�
z VersionedFileRepository.__init__cCs�|dur|durtd��|��r*t�d��|�|�rj|durj|�|�rj|durbt�|�sb|�|�t	d�St
�||�}|dur�t|dd�s�t�
d|��|j||||d�S)	aFetch the content required to construct revision_id from source.

        If revision_id is None and fetch_spec is None, then all content is
        copied.

        fetch() may not be used when the repository is in a write group -
        either finish the current write group before using fetch, or use
        fetch before starting the write group.

        :param find_ghosts: Find and copy revisions in the source that are
            ghosts in the target (and not reachable directly by walking out to
            the first-present revision in target from revision_id).
        :param revision_id: If specified, all the content needed for this
            revision ID will be copied to the target.  Fetch will determine for
            itself which content needs to be copied.
        :param fetch_spec: If specified, a SearchResult or
            PendingAncestryResult that describes which revisions to copy.  This
            allows copying multiple heads at once.  Mutually exclusive with
            revision_id.
        Nz2fetch_spec and revision_id are mutually exclusive.z%May not fetch while in a write group.r�supports_fetch_specFzfetch_spec not supported for %r)r;�find_ghosts�
fetch_specr<)r�r�rZInternalBzrErrorZhas_same_locationZ_has_same_fallbacksr*Zis_null�get_revisionrr
rdr�r��fetch)r4r[r;r�r�r<Zinterr#r#r$r��s:��
���

���zVersionedFileRepository.fetchcs^|���Btt|��||�}|j��r8t|j���|d<|Wd�S1sP0YdS)zSee Repository.gather_stats().r�N)	r�r&r��gather_statsZuser_transportZlistabler{r�r�)r4�revidZ
committersr�r>r#r$r�s
��
z$VersionedFileRepository.gather_statsc
Cs>|jr|jjst�d��|�|||||||||	�	}
|��|
S)a�Obtain a CommitBuilder for this repository.

        :param branch: Branch to commit to.
        :param parents: Revision ids of the parents of the new revision.
        :param config_stack: Configuration stack to use.
        :param timestamp: Optional timestamp recorded for commit.
        :param timezone: Optional timezone for timestamp.
        :param committer: Optional committer to set for commit.
        :param revprops: Optional dictionary of revision properties.
        :param revision_id: Optional revision id.
        :param lossy: Whether to discard data that can not be natively
            represented, when pushing to a foreign VCS
        rB)rLrMrNrrO�_commit_builder_class�start_write_group)r4�branchr(r6r7r8r9r:r;r<r�r#r#r$�get_commit_builder�s


�z*VersionedFileRepository.get_commit_buildercs$|jjst�S|��std��t|jj���}|�t	j
�|jj}|�dd�|D��}|�
|�t|�dkrrt�S|s�tdd�|D��S|jjj}|�|�tdd�|��D��}|�|�}t�}t|�D] \�}	|��fdd�|	D��q�|j�|�}
|�
|
�|�st�Stdd�|D��}|S)	a�Return the keys of missing inventory parents for revisions added in
        this write group.

        A revision is not complete if the inventory delta for that revision
        cannot be calculated.  Therefore if the parent inventories of a
        revision are not present, the revision is incomplete, and e.g. cannot
        be streamed by a smart server.  This method finds missing inventory
        parents for revisions added in this write group.
        znot in a write groupcss|]}|dd�VqdS����Nr#�rCr�r#r#r$r�szIVersionedFileRepository.get_missing_parent_inventories.<locals>.<genexpr>rcss|]\}d|fVqdS�rKNr#�rCr�r#r#r$r�rFcss|]}|dVqdS)rNr#�rC�rr#r#r$r� rFc3s|]}�|fVqdSr�r#)rCZ
version_idr�r#r$r�$scss|]\}d|fVqdSr	r#r
r#r#r$r�.rF)rMr�r�r�r�r�rPZget_missing_parents�discardr*r+rKrQ�difference_updater{Z_key_dependenciesZsatisfy_refs_for_keys�	frozensetZ
get_referrers�fileids_altered_by_revision_idsrr�r�)r4�check_for_missing_textsr(Zunstacked_inventoriesZpresent_inventoriesZkey_depsZ	referrers�file_ids�
missing_textsZversion_idsZ
present_textsrYr#r�r$�get_missing_parent_inventories�s<

�



�

z6VersionedFileRepository.get_missing_parent_inventoriescCsv|���Z|j�dd�|D��}t�}tj|vr<|�tj�|�dd�|D��|Wd�S1sh0YdS)z�Probe to find out the presence of multiple revisions.

        :param revision_ids: An iterable of revision_ids.
        :return: A set of the revision_ids that were present.
        cSsg|]
}|f�qSr#r#r
r#r#r$rE9rFz9VersionedFileRepository.has_revisions.<locals>.<listcomp>cSsg|]}|d�qS�rr#rr#r#r$rE=rFN)r�r�rQr�r*r+r�r�)r4r�rIr�r#r#r$�
has_revisions1s
�
z%VersionedFileRepository.has_revisionscCs<|��� |�|g�dWd�S1s.0YdS)aV'reconcile' helper routine that allows access to a revision always.

        This variant of get_revision does not cross check the weave graph
        against the revision one as get_revision does: but it should only
        be used by reconcile, or reconcile-alike commands that are correcting
        or testing the revision graph.
        rN)r�Z
get_revisions�r4r;r#r#r$�get_revision_reconcile@s
z.VersionedFileRepository.get_revision_reconcilec	cs�|����|D] }|r t|t�stj||d��qdd�|D�}|j�|dd�}|D]D}|jd}|jdkrv|dfVqR|�	d	�}|j
�|�}||fVqRWd�n1s�0YdS)
a�Iterate over revision objects.

        :param revision_ids: An iterable of revisions to examine. None may be
            passed to request all revisions known to the repository. Note that
            not all repositories can find unreferenced revisions; for those
            repositories only referenced ones will be returned.
        :return: An iterator of (revid, revision) tuples. Absent revisions (
            those asked for but not available) are returned as (revid, None).
        )r;rcSsg|]
}|f�qSr#r#rr#r#r$rEZrFz:VersionedFileRepository.iter_revisions.<locals>.<listcomp>rTrr�N�fulltext)r��
isinstance�bytesrZInvalidRevisionIdr��get_record_streamr�r�r�r��read_revision_from_string)	r4r�r�r��streamr�r�textrlr#r#r$�iter_revisionsKs

�


z&VersionedFileRepository.iter_revisionscCsD|���(|j�|fdt�|��Wd�n1s60YdS)z�Store a signature text for a revision.

        :param revision_id: Revision id of the revision
        :param signature: Signature text.
        r#N)�
lock_writer�r�r�Zsplit_lines)r4r;�	signaturer#r#r$�add_signature_textes
�z*VersionedFileRepository.add_signature_textcCsN|���2t�||�}|��}|�|||�Wd�n1s@0YdSr�)r!re�
from_revisionrgrh)r4r;�gpg_strategyrmrnr#r#r$�
sign_revisionos
�z%VersionedFileRepository.sign_revisioncCsF|���*|�|tj�}|�||�Wd�n1s80YdSr�)r!ZsignriZ
MODE_CLEARr#)r4r%rnr;r"r#r#r$rhvs
z0VersionedFileRepository.store_revision_signaturecCs�|����|�|�s,tjdfWd�S|�|�}t�||�}|�|�\}}}|��|krvtj	dfWd�S||fWd�S1s�0YdS)z�Verify the signature on a revision.

        :param revision_id: the revision to verify
        :gpg_strategy: the GPGStrategy object to used

        :return: gpg.SIGNATURE_VALID or a failed SIGNATURE_ value
        N)
r��has_signature_for_revision_idriZSIGNATURE_NOT_SIGNED�get_signature_textrer$ZverifyrgZSIGNATURE_NOT_VALID)r4r;r%r"rmZstatusr�Zsigned_plaintextr#r#r$�verify_revision_signature{s


�z1VersionedFileRepository.verify_revision_signaturecCsT|j��}|j}tj���&}|j�|j||d��Wd�S1sF0YdS)a`Find the text key references within the repository.

        :return: A dictionary mapping text keys ((fileid, revision_id) tuples)
            to whether they were referred to by the inventory of the
            revision_id that they contain. The inventory texts from all present
            revision ids are assessed to generate this report.
        ��pbN)	r�r�rKr�r�r�r��_find_text_key_references�#iter_lines_added_or_present_in_keys)r4�
revision_keys�wr+r#r#r$�find_text_key_references�s
�z0VersionedFileRepository.find_text_key_referencesccsL|j�|dd�}|D]2}|jdkr|jd}|�d�D]}||fVq6qdS)a�Get a line iterator of the sort needed for findind references.

        Not relevant for non-xml inventory repositories.

        Ghosts in revision_keys are ignored.

        :param revision_keys: The revision keys for the inventories to inspect.
        :return: An iterator over (inventory line, revid) for the fulltexts of
            all of the xml inventories specified by revision_keys.
        rTr�rr�N)rKrr�r�r�)r4r�rr�r�liner#r#r$�_inventory_xml_lines_for_keys�s

z5VersionedFileRepository._inventory_xml_lines_for_keysc
Csjt|j�|��}|�|�}t|j�|�|���}||}i}|j}|D]}	||	dt���|	d�qF|S)a�Helper routine for fileids_altered_by_revision_ids.

        This performs the translation of xml lines to revision ids.

        :param line_iterator: An iterator of lines, origin_version_id
        :param revision_keys: The revision ids to filter for. This should be a
            set or other type which supports efficient __contains__ lookups, as
            the revision key from each parsed line will be looked up in the
            revision_keys filter.
        :return: a dictionary mapping altered file-ids to an iterable of
            revision_ids. Each altered file-ids has the exact revision_ids that
            altered it listed explicitly.
        rr)r�r�r,�_find_parent_keys_of_revisionsr2�
setdefaultr�)
r4Z
line_iteratorr.�seenrXZparent_seenZnew_keysr�r4r�r#r#r$�'_find_file_ids_from_xml_inventory_lines�s
�z?VersionedFileRepository._find_file_ids_from_xml_inventory_linescCs:|j�|�}ttj�t|���}|�|�|�t	j
�|S)z�Similar to _find_parent_ids_of_revisions, but used with keys.

        :param revision_keys: An iterable of revision_keys.
        :return: The parents of all revision_keys that are not already in
            revision_keys
        )r�rQr��	itertools�chain�
from_iterablerrr
r*r+)r4r.rIrXr#r#r$r3�s�
z6VersionedFileRepository._find_parent_keys_of_revisionscCs2tdd�|D��}|p|j}|�|j|dd�|�S)a�Find the file ids and versions affected by revisions.

        :param revisions: an iterable containing revision ids.
        :param _inv_weave: The inventory weave from this repository or None.
            If None, the inventory weave will be opened automatically.
        :return: a dictionary mapping altered file-ids to an iterable of
            revision_ids. Each altered file-ids has the exact revision_ids that
            altered it listed explicitly.
        css|]}|fVqdSr�r#)rCrr#r#r$r��rFzJVersionedFileRepository.fileids_altered_by_revision_ids.<locals>.<genexpr>Nr*)r�rKr6r-)r4r�Z
_inv_weaveZ
selected_keysr/r#r#r$r�s

��z7VersionedFileRepository.fileids_altered_by_revision_idsccsri}|D]\}}}||||f<q|j�|dd�D]<}|jdkrVt�|jd|jd��||j|�d�fVq0dS)a,Iterate through file versions.

        Files will not necessarily be returned in the order they occur in
        desired_files.  No specific order is guaranteed.

        Yields pairs of identifier, bytes_iterator.  identifier is an opaque
        value supplied by the caller as part of desired_files.  It should
        uniquely identify the file version in the caller's context.  (Examples:
        an index number or a TreeTransform trans_id.)

        bytes_iterator is an iterable of bytestrings for the file.  The
        kind of iterable and length of the bytestrings are unspecified, but for
        this implementation, it is a list of bytes produced by
        VersionedFile.get_record_stream().

        :param desired_files: a list of (file_id, revision_id, identifier)
            triples
        rTr�rrr�N)r�rr�r�RevisionNotPresentr�r�)r4Z
desired_files�	text_keysr�r;Z
callable_datar�r#r#r$�iter_files_bytes�s
z(VersionedFileRepository.iter_files_bytescCsj|dur|��}|�|���}|dur.|��}tj���}|�|||�Wd�S1s\0YdS)a^Generate a new text key index for the repository.

        This is an expensive function that will take considerable time to run.

        :return: A dict mapping text keys ((file_id, revision_id) tuples) to a
            list of parents, also text keys. When a given key has no parents,
            the parents list will be [NULL_REVISION].
        N)r0rQ�all_revision_idsr0r�r�r��_do_generate_text_key_index)r4�text_key_references�	ancestorsr/r+r#r#r$�_generate_text_key_indexs�z0VersionedFileRepository._generate_text_key_indexc
svt�|�}t�}i}|D]}t�||<qt|�}i}	t|�D]2\}
}|sT|�|
�n||
d�|
�|
|	|
<q<~i}t�t�|��}
t	j
}t�d�}d}t|�|d}d}|�
td�||�t|�D�]�}||||d|�}|s��q\|D�]b}||}||D�]J}
|�
td�|�|d7}g�|D]�}|
d|f}z|||v}Wnt�yld}d}Yn0|�r�z||}Wn(t�y�|�|�j}|||<Yn0z|�|
d�}Wnttjf�y�d}Yn0|du�r�|
d|jf}nd}|du�r0��|	|��q0|
���}t|�}|j�fdd�d	�|gk�rL|g}|||
<�q
q�q�|D]}
|g||
<�q`|S)
z:Helper for _generate_text_key_index to avoid deep nesting.r�
rzCalculating text parentsFNcs
��|�Sr�)�index)�x�Zcandidate_parentsr#r$�<lambda>frFzEVersionedFileRepository._do_generate_text_key_index.<locals>.<lambda>)r�)�tsort�	topo_sortr�r{rr�r/�GraphZDictParentsProviderr*r+�	lru_cache�LRUCacher�r�r�KeyErrorrfr�r�rr�r~rr1rR�sort)r4r@r?r+Zrevision_orderZinvalid_keysr.r;Z
text_countZtext_key_cache�text_keyZvalid�
text_indexZ
text_graphr+�inventory_cache�
batch_sizeZbatch_countZprocessed_texts�offsetZto_queryrcr�Zparent_text_keyZcheck_parentr�r�Zparent_headsZnew_parentsr#rEr$r>s�



��

��
�


�
�

z3VersionedFileRepository._do_generate_text_key_indexccs4|�||�D]
}|Vq~|�|�D]
}|Vq$dS)a�Get an iterable listing the keys of all the data introduced by a set
        of revision IDs.

        The keys will be ordered so that the corresponding items can be safely
        fetched and inserted in that order.

        :returns: An iterable producing tuples of (knit-kind, file-id,
            versions).  knit-kind is one of 'file', 'inventory', 'signatures',
            'revisions'.  file-id is None unless knit-kind is 'file'.
        N)�_find_file_keys_to_fetch�_find_non_file_keys_to_fetch)r4r�Z	_files_pbr�r#r#r$�item_keys_introduced_byos
z/VersionedFileRepository.item_keys_introduced_byc	csb|j}|�||�}d}t|�}t|�D]6\}}|durH|�td�||�|d7}d||fVq&dS)NrzFetch textsrr�)rKrr{rr�r�)	r4r�r+Zinv_wrr�Znum_file_idsr�Zaltered_versionsr#r#r$rS�sz0VersionedFileRepository._find_file_keys_to_fetchccsZdd|fVt|j�dd�|D���}dd�|D�}|�|�dd|fVdd|fVdS)N�	inventorycSsg|]
}|f�qSr#r#rr#r#r$rE�rFzHVersionedFileRepository._find_non_file_keys_to_fetch.<locals>.<listcomp>cSsh|]
\}|�qSr#r#rr#r#r$rJ�rFzGVersionedFileRepository._find_non_file_keys_to_fetch.<locals>.<setcomp>r�r�)r�r�rQ�intersection_update)r4r�Zrevisions_with_signaturesr#r#r$rT�s�
z4VersionedFileRepository._find_non_file_keys_to_fetchcCs<|��� t|�|g��Wd�S1s.0YdS)z$Get Inventory object by revision id.N)r��next�iter_inventoriesrr#r#r$rr�s
z%VersionedFileRepository.get_inventoryccsNd|vstj|vrtd��|�||�D]"\}}|durBt�||��|Vq&dS)aGet many inventories by revision_ids.

        This will buffer some or all of the texts used in constructing the
        inventories in memory, but will only parse a single inventory at a
        time.

        :param revision_ids: The expected revision ids of the inventories.
        :param ordering: optional ordering, e.g. 'topological'.  If not
            specified, the order of revision_ids will be preserved (by
            buffering if necessary).
        :return: An iterator of inventories.
        Nz"cannot get null revision inventory)r*r+�
ValueError�_iter_inventoriesrr�)r4r��orderingr�rr#r#r$rY�s
�z(VersionedFileRepository.iter_inventoriesccsD|�||�}|D].\}}|dur,d|fVq|�||�|fVqdS)z*single-document based inventory iteration.N)�_iter_inventory_xmlsr�)r4r�r\Zinv_xmlsr�r;r#r#r$r[�s
z)VersionedFileRepository._iter_inventoriesc	cs�|durd}d}nd}dd�|D�}|s,dS|r@t|�}t|�}|j�||d�}i}|D]�}	|	jdkr�|	�d�}
|r�|
||	j<q�|
|	jdfVnd|	jdfV|rX||vrX|�|�}
|
|dfVzt|�}Wq�ty�d}YqXYq�0q�qXdS)	NTrFcSsg|]
}|f�qSr#r#)rCr;r#r#r$rE�rFz@VersionedFileRepository._iter_inventory_xmls.<locals>.<listcomp>r�r�r)	�iterrXrKrr�r�r�rT�
StopIteration)r4r�r\Zorder_as_requestedr�Zkey_iterZnext_keyrZ
text_linesr�r�r#r#r$r]�s8


z,VersionedFileRepository._iter_inventory_xmlscCs8|jj|||j|jd�}|j|kr4td|j|f��|S)z�Transform the xml into an inventory object.

        :param revision_id: The expected revision id of the inventory.
        :param xml: A serialised inventory.
        )Zentry_cacheZreturn_from_cachezrevision id mismatch %s != %s)r��read_inventory_from_linesr�r�r;r�)r4r;Zxmlr�r#r#r$r��s�
�z.VersionedFileRepository._deserialise_inventorycCs|jjSr�)r�Z
format_numr@r#r#r$�get_serializer_format�sz-VersionedFileRepository.get_serializer_formatcCs^|���B|�|gd�}t|�\}}|dur8t�||��|Wd�S1sP0YdS)z%Get serialized inventory as a string.rN)r�r]rXrr�)r4r;r�r�r#r#r$�_get_inventory_xml�s
z*VersionedFileRepository._get_inventory_xmlcCsnt�|�}|tjkr*t�|tdd�tj�S|���(|�|�}t�|||�Wd�S1s`0YdS)z|Return Tree for a revision on this branch.

        `revision_id` may be NULL_REVISION for the empty tree revision.
        N)Zroot_id)r*Zensure_nullr+rsrtrr�rr)r4r;r�r#r#r$rfs

�

z%VersionedFileRepository.revision_treeccs*|�|�}|D]}t�|||j�VqdS)z�Return Trees for revisions in this repository.

        :param revision_ids: a sequence of revision-ids;
          a revision-id may not be None or b'null:'
        N)rYrsrtr;)r4r�rKr�r#r#r$r�s
z&VersionedFileRepository.revision_treesccs�t�}|D]$}|�|j�|�|jdd��q
|durRtdd�|�|�D��}ntdd�|�||�D��}|D]8}|js�|�t	j
�}n||jd}||j�|�VqpdS)a�Produce a generator of revision deltas.

        Note that the input is a sequence of REVISIONS, not revision_ids.
        Trees will be held in memory until the generator exits.
        Each delta is relative to the revision's lefthand predecessor.

        :param specific_fileids: if not None, the result is filtered
          so that only those file-ids, their parents and their
          children are included.
        Nrcss|]}|��|fVqdSr���get_revision_id�rC�tr#r#r$r�6s�zCVersionedFileRepository.get_deltas_for_revisions.<locals>.<genexpr>css|]}|��|fVqdSr�rcrer#r#r$r�9s�r)r�r�r;r�rc�dictr��_filtered_revision_treesrfr*r+Zchanges_from)r4r�Zspecific_fileidsZrequired_treesr~ZtreesZold_treer#r#r$�get_deltas_for_revisionss$�
��z0VersionedFileRepository.get_deltas_for_revisionsccs4|�|�}|D] }|�|�}t�|||j�VqdS)aSReturn Tree for a revision on this branch with only some files.

        :param revision_ids: a sequence of revision-ids;
          a revision-id may not be None or b'null:'
        :param file_ids: if not None, the result is filtered
          so that only those file-ids, their parents and their
          children are included.
        N)rY�filterrsrtr;)r4r�rrKr�Zfiltered_invr#r#r$rhEs	

z0VersionedFileRepository._filtered_revision_treescCs�g}i}|D]6}|tjkr$d||<q|dur6td��q|�|f�qt|j�|��D]2\\}}|rztdd�|D��||<qTtjf||<qT|S)z/See graph.StackedParentsProvider.get_parent_mapr#Nz!get_parent_map(None) is not validcSsg|]
\}|�qSr#r#)rCZparent_revidr#r#r$rEes�z:VersionedFileRepository.get_parent_map.<locals>.<listcomp>)r*r+rZrrr�rQr�)r4r�Z
query_keysr�r;rXr#r#r$rQUs"



��z&VersionedFileRepository.get_parent_mapcsZtj��fdd�|D�}|���&|j�|�}t�|�Wd�S1sL0YdS)zNReturn the known graph for a set of revision ids and their ancestors.
        csg|]}�|����qSr#)�intern)rCZr_id��str#r$rEorFzDVersionedFileRepository.get_known_graph_ancestry.<locals>.<listcomp>N)Zstatic_tupleZStaticTupler�r��get_known_graph_ancestryr/ZGraphThunkIdsToKeys)r4r�r.Zknown_graphr#rlr$rnks
�z0VersionedFileRepository.get_known_graph_ancestrycCs8|���t�|j�Wd�S1s*0YdS)z+Return the graph walker for text revisions.N)r�r/rIr�r@r#r#r$�get_file_graphus
z&VersionedFileRepository.get_file_graphcCsTttj�t|���|����}|�|�}|�|�}|�|�}t	�
||t|�|�}|S)z6Convert a set of revision ids to a graph SearchResult.)r�r7r8r9rr0rQ�intersection�
difference�	vf_search�SearchResultr{)r4�
result_setZresult_parents�
included_keysZ
start_keysZexclude_keysr�r#r#r$�revision_ids_to_search_resultzs
�


�z5VersionedFileRepository.revision_ids_to_search_resultcCst|||d�S)a�Return an object suitable for checking versioned files.

        :param text_key_references: if non-None, an already built
            dictionary mapping text keys ((fileid, revision_id) tuples)
            to whether they were referred to by the inventory of the
            revision_id that they contain. If None, this will be
            calculated.
        :param ancestors: Optional result from
            self.get_graph().get_parent_map(self.all_revision_ids()) if already
            available.
        �r?r@)�_VersionedFileChecker)r4r?r@r#r#r$�_get_versioned_file_checker�s
�z3VersionedFileRepository._get_versioned_file_checkercCs^|���B|�|�s t�||��dt|j�|fg��k}|Wd�S1sP0YdS)zAQuery for a revision signature for revision_id in the repository.rN)r��has_revisionrr�r{r�rQ)r4r;Zsig_presentr#r#r$r'�s

�z5VersionedFileRepository.has_signature_for_revision_idcCsh|���L|j�|fgdd�}t|�}|jdkr<t�||��|�d�Wd�S1sZ0YdS)z Return the text for a signature.rTr�rN)r�r�rrXr�rr�r�)r4r;rr�r#r#r$r(�s
�
z*VersionedFileRepository.get_signature_textcCsH|���,tj||d�}|�|�|Wd�S1s:0YdS)N)�
check_repo)r�r�ZVersionedFileCheck)r4r�Z
callback_refsr{r�r#r#r$�_check�s

zVersionedFileRepository._checkccs�|��st��|j}|dur*|�|���}|D]T\}}|dur>|�|fg�}tdd�||fD��}t|j�}||kr.|||fVq.dS)amFind revisions with different parent lists in the revision object
        and in the index graph.

        :param revisions_iterator: None, or an iterator of (revid,
            Revision-or-None). This iterator controls the revisions checked.
        :returns: an iterator yielding tuples of (revison-id, parents-in-index,
            parents-in-revision).
        Ncss|]}|dVqdSrr#r�r#r#r$r��rFzNVersionedFileRepository._find_inconsistent_revision_parents.<locals>.<genexpr>)r�r�r�r r=rQr�rc)r4Zrevisions_iterator�vfrr~rIZparents_according_to_indexZparents_according_to_revisionr#r#r$�#_find_inconsistent_revision_parents�s 	�
�z;VersionedFileRepository._find_inconsistent_revision_parentscCst|���}|rt�d��dS)Nz'Revision knit has inconsistent parents.)rRr~rZ
BzrCheckError)r4Zinconsistenciesr#r#r$�(_check_for_inconsistent_revision_parents�s
�z@VersionedFileRepository._check_for_inconsistent_revision_parentscCst|�S)z1Return a sink for streaming into this repository.)�
StreamSinkr@r#r#r$rV�sz!VersionedFileRepository._get_sinkcCs
t||�S)z3Return a source for streaming from this repository.)�StreamSource)r4�	to_formatr#r#r$rU�sz#VersionedFileRepository._get_sourcecCsLddlm}|���$|||d�}|��Wd�S1s>0YdS)zReconcile this repository.r)�VersionedFileRepoReconciler)�thoroughN)�	reconciler�r!)r4�otherr�r�Z
reconcilerr#r#r$r��s
z!VersionedFileRepository.reconcile)N)NF)T)N)NFNF)NN)NNNNNF)T)N)NN)N)N)N)NN)N)NF)Hrrrrr%rr�r�rrZLockNotHeldZ
LockBrokenr�r�r�rur�r�rjr�r�r�r�r�r'r�rrrrrr r#r&rhr)r0r2r6r3rr<rAr>rUrSrTrrrYr[r]r�rarbrfr�rirhrQrnrorvryr'r(r|r~rrVrUr�r�r#r#r>r$r�Es�7
�
-�
	
	:�
1�

7

�
W

	$	

'
�
	

r�cs eZdZdZ�fdd�Z�ZS)�MetaDirVersionedFileRepositoryzARepositories in a meta-dir, that work via versioned file objects.cstt|��|||�dSr�)r&r�r'r�r>r#r$r'�s�z'MetaDirVersionedFileRepository.__init__)rrrrr'r�r#r#r>r$r��sr�c@seZdZdZdS)�$MetaDirVersionedFileRepositoryFormatzDBase class for repository formats using versioned files in metadirs.N)rrrrr#r#r#r$r��sr�c@sTeZdZdZdd�Zdd�Zdd�Zdd	d
�Zdd�Zddd�Z	dd�Z
dd�Zd
S)r�a,An object that can insert a stream into a repository.

    This interface handles the complexity of reserialising inventories and
    revisions from different formats, and allows unidirectional insertion into
    stacked repositories without looking for the missing basis parents
    beforehand.
    cCs
||_dSr�)�target_repo)r4r�r#r#r$r'�szStreamSink.__init__cCs|�|�}|�||jj�S)z�Insert missing keys from another source.

        :param source: StreamSource to stream from
        :param missing_keys: Keys to insert
        :return: keys still missing
        )�get_stream_for_missing_keys�insert_stream_without_lockingr�rM)r4r[rYrr#r#r$rW�s
�zStreamSink.insert_missing_keysc
Cs�|j����|r"|j�|�d}n|j��d}z�|�|||�}|rf|j��}||fWWd�S|j��}|jjj}|j}	||	kr�|jjj	r�|jj
|d�gt�fWWd�S|jjdd��Yn0Wd�n1s�0YdS)aInsert a stream's content into the target repository.

        :param src_format: a bzr repository format.

        :return: a list of resume tokens and an  iterable of keys additional
            items required before the insertion can be completed.
        TFN��hint)Zsuppress_errors)
r�r!Zresume_write_grouprr�Zsuspend_write_grouprkrMr��pack_compresses�packr�rp)
r4r�
src_formatrZ�	is_resumerYZwrite_group_tokensr��
to_serializer�src_serializerr#r#r$�
insert_streams0
�


�zStreamSink.insert_streamFcs|j��st�|��|j��s(t�d��|jjj}|j}d}||krpz|jjj	}Wnt
ydYn0|�d�|D]�\}}dtj
vr�td|�|dkr�|jj�|�qt|dkr�||kr�|jj�|�n|�||�qt|dkr�|�||�qt|d	k�r|jj�|�qt|d
k�r8||k�r*|jj�|�n|�||�qt|dk�rR|jj�|�qttd|f��qt|du�rz|jd
dd�|jj|d�}	zpd|jjfd|jjfd
|jjfd|jjfd	|jjffD]4\�}
|
du�r֐q�|	��fdd�|
��D���q�Wnt�yt�}	Yn0|	S)a�Insert a stream's content into the target repository.

        This assumes that you already have a locked repository and an active
        write group.

        :param src_format: a bzr repository format.
        :param is_resume: Passed down to get_missing_parent_inventories to
            indicate if we should be checking for missing texts at the same
            time.

        :return: A set of keys that are missing.
        z$you must already be in a write groupNirzinserting substream: %sr�rK�inventory-deltasr�r�r�z
kaboom! %srFT)r�)rc3s|]}�f|VqdSr�r#r��prefixr#r$r��rFz;StreamSink.insert_stream_without_locking.<locals>.<genexpr>)r�Zis_write_lockedrZObjectNotLockedr�rOrMr�Z_pack_collectionZ	_new_pack�AttributeErrorZset_write_cache_size�debug�debug_flagsrr��insert_record_streamrK�_extract_and_insert_inventories�$_extract_and_insert_inventory_deltasr�r��_extract_and_insert_revisionsr�r�Z_write_datarr�Z#get_missing_compression_parent_keys�NotImplementedErrorr�)r4rr�r�r�r�Znew_packZsubstream_type�	substreamrYZversioned_filer#r�r$r�'sz







���


�

�




�
�z(StreamSink.insert_stream_without_lockingcCs�|jjj}|jjj}|D]�}|�d�}t��}z|�|�}Wn@tjy|}	z&t	d|	j
�t�|jj��WYd}	~	n
d}	~	00|\}
}}}
}|}dd�|j
D�}|j�|
|||�qdS)Nr�zIncompatible delta: %scSsg|]}|d�qSrr#rr#r#r$rE�rFzCStreamSink._extract_and_insert_inventory_deltas.<locals>.<listcomp>)r�rM�rich_root_datar�r��inventory_deltaZInventoryDeltaDeserializerZparse_text_bytesZIncompatibleInventoryDeltar�msgr�IncompatibleRevisionr(ru)r4r�r��target_rich_root�target_tree_refsr�Zinventory_delta_bytesZdeserialiserZparse_result�errr=Znew_idZ	rich_rootZ	tree_refsr�r;r(r#r#r$r��s$


�$�z/StreamSink._extract_and_insert_inventory_deltasNcCsd|jjj}|jjj}|D]F}|�d�}|jd}|�||�}	dd�|jD�}
|j�||	|
�~	qdS)z�Generate a new inventory versionedfile in target, converting data.

        The inventory is retrieved from the source, (deserializing it), and
        stored in the target (reserializing it in a different format).
        r�rcSsg|]}|d�qSrr#rr#r#r$rE�rFz>StreamSink._extract_and_insert_inventories.<locals>.<listcomp>N)	r�rMr�r�r�r�r`r(r�)r4r�r�Zparse_deltar�r�r�r�r;r�r(r#r#r$r��s



z*StreamSink._extract_and_insert_inventoriescCsT|D]J}|�d�}|jd}|�|�}|j|kr@td||f��|j�||�qdS)Nrrz
wtf: %s != %s)r�r�rr;r�r�r�)r4r�r�r�rr;rlr#r#r$r��s



z(StreamSink._extract_and_insert_revisionscCs|jjjr|j��dSr�)r�rMZ_fetch_reconciler�r@r#r#r$�finished�s
zStreamSink.finished)F)N)rrrrr'rWr�r�r�r�r�r�r#r#r#r$r��s&�
h�
	r�c@sxeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zddd�Zddd�Z
ddd�Zddd�ZdS) r�z7A source of a stream for fetching between repositories.cCs||_||_t�|_dS)z5Create a StreamSource streaming from from_repository.N)�from_repositoryr�Z
RecordCounterZ_record_counter)r4r�r�r#r#r$r'�szStreamSource.__init__cCs"|jjj}|jj}|jjo ||kS)zpReturn True if delta's are permitted on metadata streams.

        That is on revisions and signatures.
        )r�rMr�r�r")r4r�Ztarget_serializerr#r#r$�delta_on_metadata�s

�zStreamSource.delta_on_metadatacCsd|jj}dd�|D�}t�|�||jj|jj��}|jj}|�||jj|�	��}d|fd|fgS)NcSsg|]
}|f�qSr#r#r
r#r#r$rE�rFz6StreamSource._fetch_revision_texts.<locals>.<listcomp>r�r�)
r�r�r��
filter_absentrr�r!r"r�r�)r4�revsZfrom_sfr�r�Zfrom_rfr�r#r#r$�_fetch_revision_texts�s��z"StreamSource._fetch_revision_textscCs"|��rt�|j��|�SgSdS)zqThis will be called by get_stream between fetching weave texts and
        fetching the inventory weave.
        N)�_rich_root_upgrade�
_mod_fetchZInter1and2Helperr�Zgenerate_root_texts)r4r�r#r#r$�_generate_root_texts�s��z!StreamSource._generate_root_textsc
#sd}|��}|j��}t�|�|��}|j�|�}g}|D]�\}�}||krP|}|dkrr|��fdd�|D��q:|dkr�|jj}	d|	�	||j
j|j
j�fVd}|�
|�D]
}
|
Vq�|�|�D]
}|Vq�q:|dkr�q:|dkr�|�|�D]
}|Vq�q:td|��q:dS)	Nr�csg|]}�|f�qSr#r#)rCr~r�r#r$rErFz+StreamSource.get_stream.<locals>.<listcomp>rVr�r�r�zUnknown knit kind %r)�get_keysr�r0rGrHrQrU�extendr�rr�r!r"r��_get_inventory_streamr�r�)
r4�searchZphaser�r/Z
data_to_fetchr;Z	knit_kindr��
from_texts�_�infor�r#r�r$�
get_stream�s<
�
�

zStreamSource.get_streamc
csi}t�|d<t�|d<t�|d<t�|d<t�|d<|D]}||d�|dd��q:t|d�rxtd|df��t|�D]�\}}t|j|�}|dur�|r�td	||f��|s�q�|dkr�|jj�|�}d
d�|D�}|j	|dd
�D]
}|Vq�q�t
�|�||j
jd��}	||	fVq�dS)Nr�r�rKr�r�rrz2cannot copy revisions to fill in missing deltas %szCcannot fill in keys for a versioned file we don't have: %s needs %scSsg|]}|d�qSrr#rr#r#r$rEBrFz<StreamSource.get_stream_for_missing_keys.<locals>.<listcomp>T��missing)r�r�r{r�rr�r�rKrQr�r�r�rr�r!)
r4rYr�r�Zsubstream_kindr}Zpresentr�r�rr#r#r$r�#sD




����
�z(StreamSource.get_stream_for_missing_keyscCs|��rdS|jjSdS)N�topological)r�r�r!r@r#r#r$�inventory_fetch_orderUsz"StreamSource.inventory_fetch_ordercCs|jjjo|jjSr�)r�rMr�r�r@r#r#r$r�[s�zStreamSource._rich_root_upgradeFcCs�|jj}|jr2|jjr2|��|j��kr2td��npdtjvrJ|j||d�S|��|j��krj|j	||d�S|js�|jjs�|j
|jj
kr�|j	||d�S|j||d�SdS)Nz3this case should be handled by GroupCHKStreamSourceZforceinvdeltas��delta_versus_nullr�)r�rMrNr��network_namer�r�r��!_get_convertable_inventory_stream�_get_simple_inventory_streamr�)r4r�r��from_formatr#r#r$r�_s0��
�����z"StreamSource._get_inventory_streamccsB|jj}|rd}n
|��}d|�dd�|D�|��|�fVdS)NTrKcSsg|]
}|f�qSr#r#r
r#r#r$rE�rFz=StreamSource._get_simple_inventory_stream.<locals>.<listcomp>)r�rKr�rr�)r4r�r�Z
from_weaveZ
delta_closurer#r#r$r�ws
�z)StreamSource._get_simple_inventory_streamccsd|j||d�fVdS)Nr�r�)�_stream_invs_as_deltas)r4r�r�r#r#r$r��s
	��z.StreamSource._get_convertable_inventory_streamccsl|j}dd�|D�}|j�|�}|j�|d�}|j}tjh}t�d�}	|�	tj�j
}
tj|j
|jd�}|D]�}|jf}
|�|
d�}d}|�s|�rdd�|D�}|D]h}||vr�q�|tjkr�|
}n|	�|d�}|dur�|�|�}|�|�}|du�st|�t|�kr�|}|}q�|du�r(tj}|�|
�}|�|j�||	|j<|�||
d	|�}tj|
|d|d
d�VqjdS)a�Return a stream of inventory-deltas for the given rev ids.

        :param revision_ids: The list of inventories to transmit
        :param delta_versus_null: Don't try to find a minimal delta for this
            entry, instead compute the delta versus the NULL_REVISION. This
            effectively streams a complete inventory. Used for stuff like
            filling in missing parents, etc.
        cSsg|]
}|f�qSr#r#r
r#r#r$rE�rFz7StreamSource._stream_invs_as_deltas.<locals>.<listcomp>r��2)Zversioned_rootZtree_referencesr#NcSsg|]}|d�qSrr#)rCZ
parent_keyr#r#r$rE�rFrT)Zchunks_are_lines)r�rKrQrYrMr*r+rJrKrfr�r�ZInventoryDeltaSerializerr�r�r;rdrrr�r{r�Zdelta_to_linesr�ZChunkedContentFactory)r4r�r�Z	from_repor.rIrKr�Zinvs_sent_so_farrPZnull_inventoryr�r�r�rXr�rcr�Z
parent_invZcandidate_deltar=Zdelta_serializedr#r#r$r��sZ	�
��



�



�z#StreamSource._stream_invs_as_deltasN)F)F)F)F)rrrrr'r�r�r�r�r�r�r�r�r�r�r�r#r#r#r$r��s

-2


�

r�c@s0eZdZd
dd�Zdd�Zddd�Zdd	�ZdS)rxNcCs||_|jj||d�|_dS)Nrw)r5rArO)r4r5r?r@r#r#r$r'�s�z_VersionedFileChecker.__init__cCs"|j|}|tjgkrdSt|�S)z_Calculate the correct parents for a file version according to
        the inventories.
        r#)rOr*r+r�)r4rNrXr#r#r$�calculate_file_version_parents�s
z4_VersionedFileChecker.calculate_file_version_parentscCsJd}|durtj��}|}z|�||�W|r4|��Sn|rD|��0dS)anCheck the parents stored in a versioned file are correct.

        It also detects file versions that are not referenced by their
        corresponding revision's inventory.

        :returns: A tuple of (wrong_parents, dangling_file_versions).
            wrong_parents is a dict mapping {revision_id: (stored_parents,
            correct_parents)} for each revision_id where the stored parents
            are not correct.  dangling_file_versions is a set of (file_id,
            revision_id) tuples for versions that are present in this versioned
            file, but not used by the corresponding inventory.
        N)r�r�r��_check_file_version_parentsr�)r4r��progress_barZlocal_progressr#r#r$�check_file_version_parents�s

��z0_VersionedFileChecker.check_file_version_parentsc	Cs�i}dd�|jD�|_t|j�}|�td�d|�|jj�|j�}|jj��}t	|�t
|j�}t|j�D]^\}}	|�td�||�|�|	�}
z||	}Wnt
jy�d}Yn0|
|krj||
f||	<qj||fS)zSee check_file_version_parents.cSsh|]\}}|�qSr#r#)rCr�r�r#r#r$rJ�rFzD_VersionedFileChecker._check_file_version_parents.<locals>.<setcomp>zloading text storerzchecking text graphN)rOrr{r�r�r5r�rQr�rr��	enumerater�rr:)r4r�r�Z
wrong_parentsZ
n_versionsrIr;Zunused_keysZnumr�Zcorrect_parentsZknit_parentsr#r#r$r��s&

�

z1_VersionedFileChecker._check_file_version_parents)NN)N)rrrr'r�r�r�r#r#r#r$rx�s
	
rxc@sTeZdZdZdZddd�Zddd�Zdd	d
�Zddd�Ze	d
d��Z
e	dd��ZdS)�InterVersionedFileRepositoryr�TNFcCs�|rt�|j|j��|jjjr8tjjd|jj|jjd�ddl	m
}|jj��|jj��krvtjjd|jj|jjd�|���,||j|j|||d�}t
�Wd�S1s�0YdS)aFetch the content required to construct revision_id.

        The content is copied from self.source to self.target.

        :param revision_id: if None all content is copied, if NULL_REVISION no
                            content is copied.
        :return: None.
        �experimental_format_fetch�r�r�r)�RepoFetcher�cross_format_fetch)Z
to_repositoryr�Z
last_revisionr�r�N)r�LossyPushToSameVCSr[r�rM�experimentalr�r��show_user_warningZbreezy.bzr.fetchr�r�r!r)r4r;r�r�r<r��fr#r#r$r�	s,

��
�z"InterVersionedFileRepository.fetchcCsV|j��}t|�}|r"|�|�}n|}t�}|j��}|�|�}ttjg�}d}	t�}
t�}t	|
�|j
kr�z$|��\}}
|
�|�|�|
�Wq\t
y�d}	Yq�Yq\0q\t|�|��}t|
��|�}|�r*t|�|��}|�|�}|�|�|�rt�|j|����|�|
|�|�|�}|�|�|	rP�q4qP|��\}}}t�||t	|�|�S)z�Walk out from revision_ids in source to revisions target has.

        :param revision_ids: The start point for the search.
        :return: A set of revision ids.
        FT)r�r0r�unionr�r[Z_make_breadth_first_searcherr*r+r{�$_walk_to_common_revisions_batch_sizeZnext_with_ghostsr�r_rprQrrr�rTZfind_seen_ancestorsZstop_searching_anyZ	get_staterrrs)r4r��if_present_idsZtarget_graphZall_wanted_revsZmissing_revsZsource_graphZsearcherZnull_setZsearcher_exhaustedZ	next_revsZghostsZnext_revs_partZghosts_partZghosts_to_checkZrevs_to_getZ	have_revsZ	stop_revsZstarted_keysZexcludesrur#r#r$�_walk_to_common_revisions5	sN






�

�z6InterVersionedFileRepository._walk_to_common_revisionsc
Cs�|����|sP|dus|durP|j||d�}|durF|Wd�S|��}n(t|j���}|�||�}t|��|�}|dur�|j�	��
|�}	tt�|	|��}|j�
|�Wd�S1s�0YdS)a�Return the revision ids that source has that target does not.

        :param revision_ids: return revision ids included by these
            revision_ids.  NoSuchRevision will be raised if any of these
            revisions are not present.
        :param if_present_ids: like revision_ids, but will not cause
            NoSuchRevision if any of these are absent, instead they will simply
            not be in the result.  This is useful for e.g. finding revisions
            to fetch for tags, which may reference absent revisions.
        :param find_ghosts: If True find missing revisions in deep history
            rather than just finding the surface difference.
        :return: A breezy.graph.SearchResult.
        N)r�)r�r�r�r�r�r=�_present_source_revisions_forrqr[r0Ziter_topo_orderr7�islicerv)
r4r�r�r��limitr�rtZ
target_ids�
source_idsZtopo_orderedr#r#r$�search_missing_revision_idso	s&
��
�z8InterVersionedFileRepository.search_missing_revision_idsc	Cs�|dus|dur�|durt�}|dur,t�}t|�}t|�}|�|�}|j��}t|�|��}|�|�}|r~t�|j|����|�	|�}dd�|�
|�D�}n
|j��}t|�S)a'Returns set of all revisions in ancestry of revision_ids present in
        the source repo.

        :param revision_ids: if None, all revisions in source are returned.
        :param if_present_ids: like revision_ids, but if any/all of these are
            absent no error is raised.
        NcSs&g|]\}}|tjkr|dur|�qSr�)r*r+)rCr�r(r#r#r$rE�	s
�zNInterVersionedFileRepository._present_source_revisions_for.<locals>.<listcomp>)r�r�r[r0rQrqrr�rTrpZ
iter_ancestryr=)	r4r�r�Zall_wanted_idsr/Zpresent_revsr�Z	found_idsr�r#r#r$r��	s&



�
z:InterVersionedFileRepository._present_source_revisions_forcCsdSr�r#r@r#r#r$�_get_repo_format_to_test�	sz5InterVersionedFileRepository._get_repo_format_to_testcCs|jjo|jjSr�)rMr)�clsr[r�r#r#r$�
is_compatible�	s�z*InterVersionedFileRepository.is_compatible)NFNF)N)TNNN)N)rrrr�r�r�r�r�r��classmethodr�r�r#r#r#r$r�	s�

;�
$
 
r�c@s^eZdZedd��Zedd��Zdd�Zdd�Zd	d
�Z	dd�Z
d
d�Zddd�Zdd�Z
dS)�InterDifferingSerializercCsdSr�r#r@r#r#r$r��	sz1InterDifferingSerializer._get_repo_format_to_testcCs�|jjsdS|jjsdSdtjvr&dS|��r:|��s:dS|jjrN|jjsNdS|jr`|jjr`dSdtjvrndS|jj	j
�d�s�dS|jj	j
�d�s�dSdS)NFZ	IDS_neverZ
IDS_alwaysTzfile:///)rMrr�r�rzr�rLrNZ
controldirZ	transportr��
startswith�r[r�r#r#r$r��	s*
�
z&InterDifferingSerializer.is_compatiblec	Csjg}|D]\}||vr(|�|||f�qz|j�|�}WntjyLYq0|||<|�||f�q|Sr�)rr[rfrr�)r4r��cache�possible_treesr�r�r#r#r$�
_get_trees�	sz#InterDifferingSerializer._get_treescCs�g}t�}|D]t\}}|j�|j�}|D]D\}	}
}}|
dur>q(|
sDq(|j}
|
dkr\|
dkr\q(|�||jf�q(|�t|�||f�q|��|ddd�S)z[Get the best delta and base for this revision.

        :return: (basis_id, delta)
        Nrxr�rr)	r�r�r�r�r�r~rr{rM)r4r�rcr�Zdeltas�texts_possibly_new_in_treer=r�r�r�r�r�Z	new_entryr�r#r#r$�_get_delta_for_revision�	s z0InterDifferingSerializer._get_delta_for_revisioncCs�ttj�t|���}|j�|�}|�|�}|jj�dd�|D��}dd�|D�}|j�	|�D]^}|�
�}	||	f}
dd�|
D�}tj}|j�
|�}
|j�|
j�}|j�|||	|�|||	<q\dS)asFind all parent revisions that are absent, but for which the
        inventory is present, and copy those inventories.

        This is necessary to preserve correctness when the source is stacked
        without fallbacks configured.  (Note that in cases like upgrade the
        source may be not have _fallback_repositories even though it is
        stacked.)
        css|]}|fVqdSr�r#r
r#r#r$r�
szKInterDifferingSerializer._fetch_parent_invs_for_stacking.<locals>.<genexpr>cSsg|]}|d�qS�rr#rr#r#r$rE
rFzLInterDifferingSerializer._fetch_parent_invs_for_stacking.<locals>.<listcomp>cSsg|]}|d�qSr�r#rr#r#r$rE$
rFN)r�r7r8r9rr[rQrqrKr�rdr*r+rfr�r�r�ru)r4rIr�Zparent_revs�present_parentsZabsent_parentsZparent_invs_keys_for_stackingZparent_inv_ids�parent_tree�current_revision_idZparents_parents_keys�parents_parentsr=r�r�r#r#r$�_fetch_parent_invs_for_stacking
s0	
�
����z8InterDifferingSerializer._fetch_parent_invs_for_stackingc Cslt�}t�}g}g}|j�|�}|�||�d|j_|j�|�D�]�}	|	��}
|�|
d�}|�||�}t	|�}
t
|
�dkr�|
�|||f�|�|	||
�\}}|j�
|
�}|�|||
|jf�|jr�|	�d�|j|
<t�}|D]Z\}}}}|dur�q�|�s"|j���sq�|j�r"|�||jf�q�|j}|�||jf�q�|
D]j\}}|j}t	|�D]P}|\}}z|�|�}Wntj�y�Y�qTYn0|j|k�rT|�|��qT�q>|�|�|�|�|	||
<|
}q@d|j_|jj}|jj}|�rt�||j||j�}|� |�|� |�!||jj"j#|jj"j$��|D]}|jj%|��q.|jj&�rt�}t�}|D]}|�|j'�|�|j��q\|�(|�|�)t*j+�|j�|�}|j�|�D]f}|��}
||
}|�||�}
t
|
�dk�r�|
�|||f�|�|||
�\}}|j�%|||
|��q�|D]P}z"|j�,|j'�}|j�-|j'|�Wntj.�yRYn0|j�/|j'|��q|S)a�Fetch across a few revisions.

        :param revision_ids: The revisions to copy
        :param basis_id: The revision_id of a tree that must be in cache, used
            as a basis for delta when no other base is available
        :param cache: A cache of RevisionTrees that we can use.
        :return: The revision_id of the last converted tree. The RevisionTree
            for it will be in cache
        Tr#rryNF)0r�r[rQr�r�r�rdrdr�rRr{rr�r�rc�_converting_to_rich_rootr}�_revision_id_to_root_idr�rzr�r~r�r�r�rr�r�r�r�r�Z_new_root_data_streamr�rrMr!r"rurLr;rr
r*r+r(r#r�r�) r4r�r=r�Zroot_keys_to_creater;Zpending_deltasZpending_revisionsrIr�r�rc�parent_treesr�r�r~r�r�r�r�r�r�r�r�Zfile_keyZ
file_revisionr�Zto_textsZroot_streamr�r�r"r#r#r$�_fetch_batch-
s�
���

�


�

���
�z%InterDifferingSerializer._fetch_batchcCs�|�|d�\}}d}t�d�}|||<~g}d}tdt|�|�D]�}	|j��z8|�td�|	t|��||	|	|�}
|�	|
||�}Wn d|j
_|j���YqB0|j�
�}|rB|�|�qB|r�|jjjr�|jj|d�|�td�t|�t|��dS)z�Fetch everything for the list of revisions.

        :param revision_ids: The list of revisions to fetch. Must be in
            topological order.
        :param pb: A ProgressTask
        :return: None
        r�dN�Transferring revisionsFr�)�
_get_basisrJrKrr{r�rr�r�r�r[r�rprkr�rMr�r�)r4r�r+r=r�rQr��hintsZa_graphrRZbatchr�r#r#r$�_fetch_all_revisions�
s6

�

�z-InterDifferingSerializer._fetch_all_revisionsNFc	Cs�|rt�|j|j��|dur&|��}nd}|jjjrNtjj	d|jj|jjd�|j�
�sp|j�
�rpd|_i|_nd|_|jj�
�|jj�
�kr�tjj	d|jj|jjd�|����|dur�|r�|g}nd}|jj|j||d���}|s�td�Wd�St�|j���|��}|�s.td�Wd�Stj���}|�||�Wd�n1�s\0Ytt|��Wd�S1�s�0YdS)	zSee InterRepository.fetch().Nr�r�TFr�)r�r�r)rr�r[r�r�rMr�r�r�r�rzr�r�r�r!r�rrGrHr0rQr�r�r{)r4r;r�r�r<r�Zsearch_revision_idsr+r#r#r$r��
sP

�
��
�
�,zInterDifferingSerializer.fetchc	Csf|j�|�}z&|jd}|j�|�|j�|�}Wn*ttjfy\tj	}|j�|�}Yn0||fS)aGGet a revision and tree which exists in the target.

        This assumes that first_revision_id is selected for transmission
        because all other ancestors are already present. If we can't find an
        ancestor we fall back to NULL_REVISION since we know that is safe.

        :return: (basis_id, basis_tree)
        r)
r[r�rcr�rfr)rr�r*r+)r4Zfirst_revision_idZ	first_revr=r�r#r#r$r�s	
z#InterDifferingSerializer._get_basis)NFNF)rrrr�r��staticmethodr�r�r�r�r�r�r�r�r#r#r#r$r��	s

$�
.r�c@s(eZdZdZedd��Zedd��ZdS)�InterSameDataRepositoryz�Code for converting between repositories that represent the same data.

    Data format and model must match for this to work.
    cCsddlm}|��S)z�Repository format for testing with.

        InterSameData can pull from subtree to subtree and from non-subtree to
        non-subtree, so we test this with the richest repository format.
        r)�knitrepo)Z
breezy.bzrr�ZRepositoryFormatKnit3)r4r�r#r#r$r�sz0InterSameDataRepository._get_repo_format_to_testcCst�||�o|jjo|jjSr�)r
Z_same_modelrMrr�r#r#r$r�'s
��z%InterSameDataRepository.is_compatibleN)rrrrr�r�r�r�r#r#r#r$r�s

	r�Nc	Cs|t|��`t�d�}t|�D]<\}\}}}t|||||�|dur|�td�|d|�qWd�n1sn0YdS)z�Install all revision data into a repository.

    Accepts an iterable of revision, tree, signature tuples.  The signature
    may be None.
    rBNr�r)rrJrKr��_install_revisionr�r�)	r5�iterableZ
num_revisionsr+rP�nr~rfr"r#r#r$�install_revisions4s


�
�r�c
Cs`g}i}|jD]8}|�|�r6|�|�|�|�||<q|�tj�||<q|j}|��}	|��s�t	|	�\}
}|j
|jkr�t�
t|���i}|	D]\}
}
|
||
j|
j
f<q�|j�|�}t|�t|�}|D]�}||}
g}t|�D]Z\}}z|�|
j�}
Wntj�yYq�Yn0|�|
�}||v�r(q�|�|
j|f�q�|�|
j�}|�|��}|��}Wd�n1�sp0Y|j�|||�q�z�|jj�r
t|j��r
|||j<z||jd}Wn$t�y�|�|j||�Yn$0|�|�}|� |jd||j|�n|�|j||�Wntj!�y2Yn0|du�rL|�"|j|�|�#|j||�dS)�,Install all revision data into a repository.Nr)$rcrzrrfr*r+r�r�rzrXr~r;rr��reprr�r�rQr�rr�r�Zget_file_revisionZget_file�	readlinesr�rMr r{rLr�r�ruZRevisionAlreadyPresentr#r�)r5rlrfr"rPr�r�Zp_idr��entriesr�r�r;r�Ztext_parent_maprrNZtext_parentsr~r�r�Zrevision_tree_pathr�r�r�r�r#r#r$r�Dsj


�



(

�
r�cCst|||dfg�dS)r�N)r�)r5rlrfr#r#r$�install_revision�sr)NN)/rZ
__future__rr�globalsryrZ
decoratorsrrVrr	r
r5rrr
rrrrrZsixishrrrrZtracerr�rrr%r�r�r��objectr�r�rxr�r�r�Zregister_optimiserr�r�rr#r#r#r$�<module>sd  W!�	�[
@/[



E

Youez - 2016 - github.com/yon3zu
LinuXploit