HEX
Server: Apache
System: Linux infong-uk86 4.4.400-icpu-106 #2 SMP Mon Sep 15 08:23:40 UTC 2025 x86_64
User: u44115835 (4976590)
PHP: 8.4.17
Disabled: NONE
Upload Files
File: //kunden/lib/python3/dist-packages/breezy/__pycache__/shelf.cpython-39.pyc
a

�*�^�I�@s�ddlmZddlZddlZddlmZddlmZee�d�Gdd�dej�Z	Gd	d
�d
ej�Z
Gdd�dej�ZGd
d�de�Z
Gdd�de�ZGdd�de�ZdS)�)�absolute_importN�)�errors)�lazy_importzt
from breezy import (
    bencode,
    merge,
    merge3,
    transform,
)
from breezy.bzr import (
    pack,
    )
c@seZdZdZdS)�ShelfCorruptzShelf corrupt.N)�__name__�
__module__�__qualname__�_fmt�rr�./usr/lib/python3/dist-packages/breezy/shelf.pyr%src@seZdZdZdd�ZdS)�
NoSuchShelfIdz.No changes are shelved with id "%(shelf_id)d".cCstjj||d�dS)N)�shelf_id�r�BzrError�__init__��selfrrrrr.szNoSuchShelfId.__init__N�rrr	r
rrrrrr
*sr
c@seZdZdZdd�ZdS)�InvalidShelfIdz?"%(invalid_id)s" is not a valid shelf id, try a number instead.cCstjj||d�dS)N)�
invalid_idr)rrrrrr6szInvalidShelfId.__init__Nrrrrrr2src@s�eZdZdZd'dd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
edd��Zdd�Z
dd�Zdd�Zd(dd�Zdd�Zdd�Zdd �Zed)d!d"��Zd*d#d$�Zed+d%d&��ZdS),�ShelfCreatorz5Create a transform to shelve objects and its inverse.NcCs�||_|��|_zZ||_t�|j�|_z(i|_i|_i|_	|j
|j|d�|_
Wn|j���Yn0Wn|j���Yn0dS)a�Constructor.

        :param work_tree: The working tree to apply changes to. This is not
            required to be locked - a tree_write lock will be taken out.
        :param target_tree: The tree to make the working tree more similar to.
            This is not required to be locked - a read_lock will be taken out.
        :param file_list: The files to make more similar to the target.
        )Zspecific_filesN)�	work_treeZ
get_transform�work_transform�target_tree�	transform�TransformPreview�shelf_transform�renames�creation�deletion�iter_changes�finalize)rrrZ	file_listrrrr=s$	
�

zShelfCreator.__init__ccs|jD�]�}|jddur*|jddkr*q|jddurH|jddkrHq|jddusd|jddur�|jd|jd|jd|jf|j|j<d|j|jd|jdfVq|jddus�|jddu�r|jd|jd|jd|jf|j|j<d|j|jd|jdfVq|jd|jdk�s:|jd|jdk�r`|j|jf|j	|j<d|jf|jV|jd|jdk�r�d	|j|jd|jd|jdfVq|jdd
k�r�|j
�|jd�}|j�|jd�}d|j|jd||fVq|j
rd|jfVqdS)
a�Iterable of tuples describing shelvable changes.

        As well as generating the tuples, this updates several members.
        Tuples may be::

           ('add file', file_id, work_kind, work_path)
           ('delete file', file_id, target_kind, target_path)
           ('rename', file_id, target_path, work_path)
           ('change kind', file_id, target_kind, work_kind, target_path)
           ('modify text', file_id)
           ('modify target', file_id, target_target, work_target)
        rNr�F�add file�delete file�rename�change kind�symlink�
modify target�modify text)r!�kind�name�	versionedZ	parent_idr�file_id�pathr rr�get_symlink_targetrZchanged_content)r�changeZt_targetZw_targetrrr�iter_shelvableXs4
��,&�zShelfCreator.iter_shelvablecCs�|ddkr|�|d�n�|ddkr8|�|d�nd|ddkrT|�|d�nH|ddvrp|�|d�n,|ddkr�|�|d�ntd|d��d	S)
z-Shelve a change in the iter_shelvable format.rr&rr%r$)r'r*r)zUnknown change kind: "%s"N)�
shelve_rename�shelve_deletion�shelve_creation�shelve_content_change�shelve_modify_target�
ValueError�rr1rrr�
shelve_change�szShelfCreator.shelve_changecCs$d}|��D]}|�|�q|duS)zeShelve all changes.

        :return: ``True`` if changes were shelved, otherwise ``False``.
        N)r2r:r9rrr�
shelve_all�szShelfCreator.shelve_allcCsr|j|\}}|j�|�}|j�|d�}|j�|d||�|j�|�}|j�|d�}|j�|d||�dS)zjShelve a file rename.

        :param file_id: The file id of the file to shelve the renaming of.
        rrN)rr�trans_id_file_id�adjust_pathr)rr.�names�parents�
w_trans_idZwork_parent�
s_trans_idZshelf_parentrrrr3�szShelfCreator.shelve_renamecCs�|j�|�}|j�|�}|j�|�}|j�|�|j�||�|j�|�}|j�|�}|j�|�}|j�|�|j�||�dS)z�Shelve a change of symlink target.

        :param file_id: The file id of the symlink which changed target.
        :param new_target: The target that the symlink should have due
            to shelving.
        N)	r�id2pathr0rr<�delete_contentsZcreate_symlinkrr)rr.�new_path�
new_targetr@Zold_pathZ
old_targetrArrrr7�sz!ShelfCreator.shelve_modify_targetcCs\|j�|�}|j�|�|j�||�|j�|�}|j�|�|�||�}|j�||�dS)z�Shelve text changes to a file, using provided lines.

        :param file_id: The file id of the file to shelve the text of.
        :param new_lines: The lines that the file should have due to shelving.
        N)rr<rC�create_filer�_inverse_lines)rr.�	new_linesr@rAZ
inverse_linesrrr�shelve_lines�szShelfCreator.shelve_linescCs.|�|�}|�|�t�||||�|��dS�N)r<rCr�create_from_treerB)�tt�treer.Ztrans_idrrr�_content_from_tree�s

zShelfCreator._content_from_treecCs(|�|j|j|�|�|j|j|�dS)z�Shelve a kind change or binary file content change.

        :param file_id: The file id of the file to shelve the content change
            of.
        N)rNrrrr)rr.rrrr6�sz"ShelfCreator.shelve_content_changec
Cs>|j|\}}}}|d}|�|j||j|j||||�dS)z�Shelve creation of a file.

        This handles content and inventory id.
        :param file_id: The file_id of the file to shelve creation of.
        rN)r�_shelve_creationrrr)rr.r+r,�parentr-�versionrrrr5�s

�zShelfCreator.shelve_creationcCs^|j|\}}}}|j�|�}|j�|�s.d}|d}|j|j||j|j|||||d�	dS)z�Shelve deletion of a file.

        This handles content and inventory id.
        :param file_id: The file_id of the file to shelve deletion of.
        Nr)�
existing_path)r rrBrZhas_filenamerOrr)rr.r+r,rPr-rRrQrrrr4�s

�zShelfCreator.shelve_deletionc

Cs�|�|�}
|dur$|dur$|�|
�|�|
�|	durB|�|	�}n
|�|�}|dur�|�|�}|�|||�|	dur�|dur�|�dg|�nt�||||�|��|r�|�	||�dS)N�)
r<rCZunversion_fileZtrans_id_tree_pathr=rFrrKrBZversion_file)
rrMr.Zfrom_transformZto_transformr+r,rPrQrRr@rAZs_parent_idrrrrO�s&




�zShelfCreator._shelve_creationcCsB|j�|�}|j�|�}|j�|�}|j�|�}t�|||���S)zAProduce a version with only those changes removed from new_lines.)rrBZget_file_linesrZmerge3ZMerge3Zmerge_lines)rrHr.Ztarget_pathZtarget_linesZ	work_pathZ
work_linesrrrrGs
zShelfCreator._inverse_linescCs|j��|j��dS)z0Release all resources used by this ShelfCreator.N)rr"r�rrrrr"s
zShelfCreator.finalizecCs|j��dS)z!Shelve changes from working tree.N)rZapplyrTrrrrszShelfCreator.transformcCs0d|i}|dur|�d�|d<|�t�|�d�S)N�revision_id�utf-8�message)�smetadata)�encodeZbytes_record�bencode)�
serializer�revision_id�message�metadatarrr�metadata_record"s
�zShelfCreator.metadata_recordcCs(t�|j�|j��}|�||j||�S)z�Serialize the shelved changes to a file.

        :param shelf_file: A file-like object to write the shelf to.
        :param message: An optional message describing the shelved changes.
        :return: the filename of the written file.
        )rZresolve_conflictsrrZget_revision_id�_write_shelf)r�
shelf_filer]r\rrr�write_shelf*s

�zShelfCreator.write_shelfcCsZt��}|�|���|�|||�}|�|�|�|�D]}|�|�q8|�|���dSrJ)�packZContainerSerialiser�writeZbeginr_Z	serialize�end)�clsrarr\r]r[r^�bytesrrrr`6s
zShelfCreator._write_shelf)N)N)N)N)N)rrr	�__doc__rr2r:r;r3r7rI�staticmethodrNr6r5r4rOrGr"rr_rb�classmethodr`rrrrr:s.
.

	�

rc@sLeZdZdZdd�Zedd��Zedd��Zedd	��Z	d
d�Z
dd
�ZdS)�	UnshelverzUnshelve shelved changes.cCs||_||_||_||_dS)z�Constructor.

        :param tree: The tree to apply the changes to.
        :param base_tree: The basis to apply the tranform to.
        :param message: A message from the shelved transform.
        N)rM�	base_treerr])rrMrlrr]rrrrDszUnshelver.__init__cCs"t��}|�|���t|���SrJ)rcZContainerPushParserZaccept_bytes�read�iterZread_pending_records)ra�parserrrr�iter_recordsPszUnshelver.iter_recordscCsJt|�\}}|ddkrt�t�|�}|�d�}|durF|�d�|d<|S)NrrXrWrV)�nextrrZZbdecode�get�decode)�recordsr>Zmetadata_bytesr^r]rrr�parse_metadataVs

zUnshelver.parse_metadatacCsv|�|�}|�|�}|d}z|�|�}Wn"tjyL|jj�|�}Yn0t�|�}|�	|�|||||�
d��S)z�Create an Unshelver from a tree and a shelf file.

        :param tree: The tree to apply shelved changes to.
        :param shelf_file: A file-like object containing shelved changes.
        :return: The Unshelver.
        rUrW)rpruZ
revision_treerZNoSuchRevisionInTree�branchZ
repositoryrrZdeserializerr)�klassrMrartr^Zbase_revision_idrlrLrrr�from_tree_and_shelfas



zUnshelver.from_tree_and_shelfcCs*|j��}tj�|j||j�}tj|_|S)z.Return a merger that can unshelve the changes.)	rZget_preview_tree�mergeZMergerZfrom_uncommittedrMrlZMerge3MergerZ
merge_type)rrZmergerrrr�make_mergerts
�zUnshelver.make_mergercCs|j��dS)z-Release all resources held by this Unshelver.N)rr"rTrrrr"|szUnshelver.finalizeN)rrr	rhrrirprurjrxrzr"rrrrrkAs



rkc@sjeZdZdZdd�Zdd�Zdd�Zdd	�Zddd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zd
S)�ShelfManagerz#Maintain a list of shelved changes.cCs ||_|�d�|_|j��dS)NZshelf)rMZclone�	transportZensure_base)rrMr|rrrr�szShelfManager.__init__cCsd|S)Nzshelf-%drrrrr�get_shelf_filename�szShelfManager.get_shelf_filenamecCsBt�d�}g}|D]*}|�|�}|dur|�t|�d���q|S)Nzshelf-([1-9][0-9]*)r)�re�compile�match�append�int�group)r�	filenamesZmatcherZ	shelf_ids�filenamer�rrr�
get_shelf_ids�s

zShelfManager.get_shelf_idscCsB|��}|durd}n|d}|�|�}t|j�|�d�}||fS)z=Return a file object and id for a new set of shelved changes.Nr�wb)�
last_shelfr}�openr|�
local_abspath)rr��
next_shelfr�rarrr�	new_shelf�s
zShelfManager.new_shelfNcCs<|��\}}z|�||�W|��n
|��0|��|S)z/Store the changes in a ShelfCreator on a shelf.)r�rb�closer)rZcreatorr]r�rarrr�shelve_changes�szShelfManager.shelve_changesc
Cs^|�|�}zt|j�|�d�WStyX}z"|jtjkr<�t|��WYd}~n
d}~00dS)z�Return the file associated with a shelf_id for reading.

        :param shelf_id: The id of the shelf to retrive the file for.
        �rbN)r}r�r|r��IOError�errnoZENOENTr
)rrr��errr�
read_shelf�s
zShelfManager.read_shelfcCs2|�|�}zt�|j|�W|��S|��0dS)zvReturn an unshelver for a given shelf_id.

        :param shelf_id: The shelf id to return the unshelver for.
        N)r�rkrxrMr�)rrrarrr�
get_unshelver�s
�zShelfManager.get_unshelvercCs6|�|�}zt�|�}W|��n
|��0t�|�S)z5Return the metadata associated with a given shelf_id.)r�rkrpr�ru)rrrartrrr�get_metadata�s

zShelfManager.get_metadatacCs|�|�}|j�|�dS)zrDelete the shelved changes for a given id.

        :param shelf_id: id of the shelved changes to delete.
        N)r}r|�delete)rrr�rrr�delete_shelf�s
zShelfManager.delete_shelfcCst|�|j�d���}|S)z!Return a list of shelved changes.�.)�sortedr�r|Zlist_dir�rZactiverrr�active_shelves�szShelfManager.active_shelvescCs$|��}t|�dkr|dSdSdS)z1Return the id of the last-created shelved change.r���N)r��lenr�rrrr��szShelfManager.last_shelf)N)rrr	rhrr}r�r�r�r�r�r�r�r�r�rrrrr{�s	


	r{)Z
__future__rr�r~r#rr�globalsrrr
r�objectrrkr{rrrr�<module>s
	@