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_ui.cpython-39.pyc
a

�*�^iO�@s�ddlmZddlZddlZddlZddlZddlmZddlm	Z	m
Z
mZmZm
Z
mZmZmZmZmZmZmZddlmZGdd�de�ZGd	d
�d
e�ZGdd�de�ZGd
d�de�ZGdd�de�ZdS)�)�absolute_importN)�BytesIO�)�builtins�cleanup�delta�diff�errors�osutils�patches�shelf�textfile�trace�ui�workingtree)�gettextc@seZdZdZdS)�	UseEditorz)Use an editor instead of selecting hunks.N)�__name__�
__module__�__qualname__�__doc__�rr�1/usr/lib/python3/dist-packages/breezy/shelf_ui.pyr+src	@sveZdZed�ed�ed�ed�ed�ed�ed�ed�d	�Zd
Zdd�Zd
d�Zdd�Zdd�Z	dd�Z
dd�ZdS)�
ShelfReporterzShelve adding file "%(path)s"?zShelve binary changes?z0Shelve changing "%s" from %(other)s to %(this)s?z Shelve removing file "%(path)s"?zShelve %d change(s)?zShelve?zDShelve changing target of "%(path)s" from "%(other)s" to "%(this)s"?z*Shelve renaming "%(other)s" => "%(this)s"?�zadd file�binary�change kindzdelete file�final�hunk�
modify target�renameFcCst��|_dS�N)r�_ChangeReporter�delta_reporter��selfrrr�__init__@szShelfReporter.__init__cCst�d�dS)z.Report that no changes were selected to apply.zNo changes to shelve.N)rZwarningr$rrr�
no_changesCszShelfReporter.no_changescCst�td�|�dS)z&Report the id changes were shelved to.zChanges shelved with id "%d".N�r�noter)r%�shelf_idrrr�
shelved_idGszShelfReporter.shelved_idcCst�td��dS)z/Report that changes were made without shelving.zSelected changes destroyed.Nr(r$rrr�changes_destroyedKszShelfReporter.changes_destroyedcCs(t�td��|��}t�||j�dS)z&Report the changes that were selected.zSelected changes:N)rr)rZiter_changesrZreport_changesr#)r%�	transformZchangesrrr�selected_changesOszShelfReporter.selected_changescCs�|ddkr |d|dd�}nX|ddkrF|d|d|dd�}n2|dd	krl|d|d|dd�}nd
|di}|j|d|}|S)z+Determine the prompt for a change to apply.rr ��)�this�otherr�)�pathr2r1rr4)�vocab)r%�changeZvals�promptrrr�
prompt_changeUszShelfReporter.prompt_changeN)rrrrr5�invert_diffr&r'r+r,r.r8rrrrr/s �
rc	@sNeZdZed�ed�ed�ed�ed�ed�ed�ed�d	�Zd
Zdd�Zd
S)�
ApplyReporterzDelete file "%(path)s"?zApply binary changes?z-Change "%(path)s" from %(this)s to %(other)s?zAdd file "%(path)s"?zApply %d change(s)?z
Apply change?z;Change target of "%(path)s" from "%(this)s" to "%(other)s"?z!Rename "%(this)s" => "%(other)s"?rTcCsdSr!rr$rrrr,sszApplyReporter.changes_destroyedN)rrrrr5r9r,rrrrr:cs�r:c@sxeZdZdZddd�Zeddd��Zdd	�Zd
d�Zddd
�Z	dd�Z
ddd�Zdd�Zdd�Z
dd�Zedd��ZdS)�Shelverz3Interactively shelve the changes in a working tree.NFcCs�||_||_||_|jdur$tj|_|	dur4|��}	|	|_||_||_||_	||_
||_|
durft�}
|
|_
|jj��}|�||�|_|j��dS)a�Constructor.

        :param work_tree: The working tree to shelve changes from.
        :param target_tree: The "unchanged" / old tree to compare the
            work_tree to.
        :param auto: If True, shelve each possible change.
        :param auto_apply: If True, shelve changes with no final prompt.
        :param file_list: If supplied, only files in this list may be shelved.
        :param message: The message to associate with the shelved changes.
        :param destroy: Change the working tree without storing the shelved
            changes.
        :param manager: The shelf manager to use.
        :param reporter: Object for reporting changes to user.
        N)�	work_tree�target_tree�diff_writer�sys�stdout�get_shelf_manager�manager�auto�
auto_apply�	file_list�message�destroyr�reporter�branchZ
get_configZget_change_editor�
change_editor�lock_tree_write)r%r<r=r>rCrDrErFrGrBrHZconfigrrrr&zs&
zShelver.__init__c
s��durd�n|r$�fdd�|D�}tj���\}}	|���Bt�d||j|�}
|�|�}|||
||||||�Wd�S1s�0YdS)aaCreate a shelver from commandline arguments.

        The returned shelver wil have a work_tree that is locked and should
        be unlocked.

        :param revision: RevisionSpec of the revision to compare to.
        :param all: If True, shelve all changes without prompting.
        :param file_list: If supplied, only files in this list may be  shelved.
        :param message: The message to associate with the shelved changes.
        :param directory: The directory containing the working tree.
        :param destroy: Change the working tree without storing the shelved
            changes.
        N�.csg|]}t��|��qSr)r
Zpathjoin)�.0�f��	directoryrr�
<listcomp>��z%Shelver.from_args.<locals>.<listcomp>Zshelf2)r�WorkingTree�open_containingrKrZ_get_one_revision_treerIZsafe_relpath_files)�klassr>Zrevision�allrErFrPrG�treer4r=�filesrrOr�	from_args�s
�
�zShelver.from_argsc	Csht�|j|j|j�}t��|_d}�z(|��D]�}|ddkr�z||�	||d�7}Wq�t
jy�|�|j
jd�r�|d7}|�|d�Yq�0q.|�|j
�|��r.|�|�|d7}q.|dk�r,|j
�|j�|js�|�|j
jd|��r6|j�r|��|j
��n|j�||j�}|j
�|�n
|j
��Wt�|j�|��nt�|j�|��0dS)z!Interactively shelve the changes.rzmodify textrrrN) rZShelfCreatorr<r=rE�tempfileZmkdtempZtempdirZiter_shelvable�handle_modify_textr	Z
BinaryFile�prompt_boolrHr5Zshelve_content_changer8Z
shelve_changer.Zwork_transformrDrGr-r,rBZshelve_changesrFr+r'�shutilZrmtree�finalize)r%�creatorZchanges_shelvedr6r*rrr�run�sH�
�




��
�zShelver.runcCs"|jdur|j��|j��dSr!)rJZfinishr<�unlockr$rrrr^�s

zShelver.finalizecCsvt�}|r|j}|j}n|j}|j}|�|�}|�|�}t��}tj||||d�}	|	�||dd�}
|�d�t	�
|�S)a&Return a parsed version of a file's patch.

        :param file_id: The id of the file to generate a patch for.
        :param invert: If True, provide an inverted patch (insertions displayed
            as removals, removals displayed as insertions).
        :return: A patches.Patch.
        ��
path_encoding�filer)rr<r=�id2pathr
Zget_terminal_encodingrZDiffText�seekrZparse_patch)r%�file_id�invertZ	diff_file�old_tree�new_treeZold_path�new_pathrcZtext_differZpatchrrr�get_parsed_patch�s


�
zShelver.get_parsed_patchcCstjj|||d�S)N)�default)r�
ui_factoryZchoose)r%rF�choicesrmrrrr7�szShelver.promptcCs�|jr
dSd}d}|r&|d7}|d7}|d7}|d7}|�||d�}|d	urRd
}n||}|dkrfdS|dkrx|rxt�n|dkr�d|_dS|d
kr�t���ndSd	S)z�Prompt the user with a yes/no question.

        This may be overridden by self.auto.  It may also *set* self.auto.  It
        may also raise UserAbort.
        :param question: The question to ask the user.
        :return: True or False
        TZynz&yes
&No�ez
&edit manuallyZfqz
&finish
&quitrN�n�yrN�qF)rCr7rr	Z	UserAbort)r%Zquestion�allow_editorZalternatives_charsZalternativesZchoice�charrrrr\s.
zShelver.prompt_boolcCsl|j�|�}|j�||�}z|�|||�\}}Wn"tyR|�||�\}}Yn0|dkrh|�||�|S)z�Handle modified text, by using hunk selection or file editing.

        :param creator: A ShelfCreator.
        :param file_id: The id of the file that was modified.
        :return: The number of changes.
        r)r<re�get_file_lines�
_select_hunksr�
_edit_fileZshelve_lines)r%r_rgr4�work_tree_lines�lines�change_countrrrr[%s�zShelver.handle_modify_textcCs&|jjr|}n|j�|�}|j�|�}t�|�t�|�|�||jj�}g}|js�d}|j	�
|���|jD]l}	|j	�
|	�
��|j|jjd|jdud�}
|jjs�|
}
|
r�|	j|7_|�|	�qn||	j|	j8}qntj��|jjr�t|�}nt|j�t|�}t�||�}t|�}
|
|fS)a�Provide diff hunk selection for modified text.

        If self.reporter.invert_diff is True, the diff is inverted so that
        insertions are displayed as removals and vice versa.

        :param creator: a ShelfCreator
        :param file_id: The id of the file to shelve.
        :param work_tree_lines: Line contents of the file in the working tree.
        :return: number of shelved hunks.
        rrN)rt)rHr9r=rervr
Zcheck_text_linesrlrCr>�writeZ
get_headerZhunksZas_bytesr\r5rJZmod_pos�appendZ	mod_rangeZ
orig_ranger?r@�flush�lenrZiter_patched_from_hunks�list)r%r_rgryZtarget_linesr4ZparsedZfinal_hunks�offsetrZselectedr{Zpatchedrzrrrrw7sB


��

�zShelver._select_hunkscCs8t�|j�|jj�|�|jj�|���}||�||�fS)a:
        :param file_id: id of the file to edit.
        :param work_tree_lines: Line contents of the file in the working tree.
        :return: (lines, change_region_count), where lines is the new line
            content of the file, and change_region_count is the number of
            changed regions.
        )r
Zsplit_linesrJZ	edit_filerirerj�_count_changed_regions)r%rgryrzrrrrxds

�zShelver._edit_filecCs"t�d||�}|��}t|�dS)Nr0)�patiencediffZPatienceSequenceMatcherZget_matching_blocksr)Z	old_linesZ	new_linesZmatcherZblocksrrrr�qs
�zShelver._count_changed_regions)NFFNNFNN)NFNNNF)F)F)rrrrr&�classmethodrYr`r^rlr7r\r[rwrx�staticmethodr�rrrrr;ws&�
%�%

#-
r;c@s@eZdZdZeddd��Zdd	d
�Zdd�Zd
d�Zdd�Z	dS)�	Unshelverz%Unshelve changes into a working tree.N�applyrLc	Cs�tj�|�\}}|��z�|��}|durVzt|�}WqttyRt�|��Yqt0n|�	�}|durtt
�td���d}d}	d}
d}|dkr�d}d}	n8|dkr�d}d}	d}n"|dkr�d}d}
n|dkr�d}d}	Wn|�
��Yn0||||||	|
||�S)	a�Create an unshelver from commandline arguments.

        The returned shelver will have a tree that is locked and should
        be unlocked.

        :param shelf_id: Integer id of the shelf, as a string.
        :param action: action to perform.  May be 'apply', 'dry-run',
            'delete', 'preview'.
        :param directory: The directory to unshelve changes into.
        :param write_diff_to: See Unshelver.__init__().
        NzNo changes are shelved.TFzdry-runZpreviewzdelete-onlyZkeep)rrSrTrKrA�int�
ValueErrorrZInvalidShelfIdZ
last_shelfr	ZBzrCommandErrorrra)rUr*�actionrP�
write_diff_torWr4rB�
apply_changes�delete_shelf�
read_shelf�	show_diffrrrrY|sJ��zUnshelver.from_argsTFc		Cs<||_|��}||_||_||_||_||_||_||_dS)a�Constructor.

        :param tree: The working tree to unshelve into.
        :param manager: The ShelveManager containing the shelved changes.
        :param shelf_id:
        :param apply_changes: If True, apply the shelved changes to the
            working tree.
        :param delete_shelf: If True, delete the changes from the shelf.
        :param read_shelf: If True, read the changes from the shelf.
        :param show_diff: If True, show the diff that would result from
            unshelving the changes.
        :param write_diff_to: A file-like object where the diff will be
            written to. If None, ui.ui_factory.make_output_stream() will
            be used.
        N)	rWrArBr*r�r�r�r�r�)	r%rWrBr*r�r�r�r�r�rrrr&�szUnshelver.__init__cCs�t����}|�|j���|jr�t�td�|j	�|j
�|j	�}|�|j
�|jdurlt�td�|j�t��}|��}||_|jr�|��n|jr�|�|�n
|�|�|jr�|j
�|j	�t�td�|j	�Wd�n1s�0YdS)z!Perform the unshelving operation.zUsing changes with id "%d".NzMessage: %szDeleted changes with id "%d".)r�	ExitStack�
enter_contextrWrKr�rr)rr*rBZ
get_unshelver�callbackr^rFrr"�make_merger�change_reporterr�Zdo_merger��
write_diff�show_changesr�)r%Z
exit_stackZ	unshelverr��mergerrrrr`�s.

�



�z
Unshelver.runcCs\|��}|��}|��}|jdur2tjjdd�|_t��}t	j
|j||j|d�|��dS)z2Write this operation's diff to self.write_diff_to.N�exact)Z
encoding_typerb)
r��make_preview_transformZget_preview_treer�rrnZmake_output_streamr
Zget_diff_header_encodingrZshow_diff_treesZ	this_treer^)r%r��tree_merger�ttrjrcrrrr��s
��zUnshelver.write_diffcCs|��}|��}|��dS)z/Show the changes that this operation specifies.N)r�r�r^)r%r�r�r�rrrr��szUnshelver.show_changes)Nr�rLN)TTTFN)
rrrrr�rYr&r`r�r�rrrrr�ys�2�

r�)Z
__future__rr�r]r?rZ�ior�rrrrr	r
rrr
rrrZi18nr�	Exceptionr�objectrr:r;r�rrrr�<module>s84