File: //kunden/lib/python3/dist-packages/breezy/__pycache__/msgeditor.cpython-39.pyc
a
�*�^3 � @ s d Z ddlmZ ddlZddlZddlmZ ddlZddlm Z m
Z
mZmZm
Z
mZmZ ddlmZ ddlmZ dd lmZmZ G d
d� de�Zdd
� Zdd� Zdddd� Zedfdd�Zedfdd�Zeddfdd�Zdd� Zd%dd�ZG dd � d e�Z e � Zd&d!d"�Z!d'd#d$�Z"dS )(zCommit message editor support.� )�absolute_importN)�call� )�bedding�cmdline�config�osutils�trace� transport�ui)�BzrError)�Hooks)�BytesIO�StringIOc @ s e Zd ZdZdS )�BadCommitMessageEncodingzUThe specified commit message contains characters unsupported by the current encoding.N)�__name__�
__module__�__qualname__Z_fmt� r r �2/usr/lib/python3/dist-packages/breezy/msgeditor.pyr + s r c c s� zt jd dfV W n ty& Y n0 t�� �d�} | durL| t�� fV dD ]"}|t jv rPt j| d| fV qPtj dkr�dD ]}|dfV q�nd D ]}|dfV q�dS )
zDReturn sequence of possible editor binaries for the current platformZ
BRZ_EDITORz$BRZ_EDITOR�editorN)ZVISUALZEDITOR�$Zwin32)zwordpad.exeznotepad.exe)z/usr/bin/editorZviZpicoZnanoZjoe)
�os�environ�KeyErrorr ZGlobalStack�getr �config_path�sys�platform)�eZvarnamer r r r �_get_editor1 s
r c C s� t � D ]�\}}t�|�}zt|| g �}W nR ty| } z:|durZt�d||t|�f � W Y d}~q� W Y d}~n
d}~0 0 |dkr� dS |dkr�qq q�qtdt �
� ��dS )z4Try to execute an editor to edit the commit message.Nz2Could not start editor "%s" (specified by %s): %s
r T� ztCould not start any editor.
Please specify one with:
- $BRZ_EDITOR
- editor=/some/path in %s
- $VISUAL
- $EDITOR)r r �splitr �OSErrorr �warning�strr r r )�filename� candidateZcandidate_sourceZedargs�xr r r r �_run_editorH s*
���r) z%(bar)s %(msg)s %(bar)sz--------------z+This line and the following will be ignored)Zbar�msgc C s2 |dur|� t�� �}| � t�� d�} t| ||�S )a� Let the user edit a commit message in a temp file.
This is run if they don't give a message or
message-containing file on the command line.
:param infotext: Text to be displayed at bottom of message
for the user's reference;
currently similar to 'bzr status'.
:param ignoreline: The separator to use above the infotext.
:param start_message: The text to place above the separator, if any.
This will not be removed from the message
after the user has edited it.
:return: commit message or None.
N�replace)�encoder �get_user_encoding�edit_commit_message_encoded)�infotext�
ignoreline�
start_messager r r �edit_commit_messageh s r2 c C s
d}�z�t | ||�\}}|slW |durhzt�|� W n2 tyf } zt�d||� W Y d}~n
d}~0 0 dS t�|�}t� t�
|��}|�|�}t|�s�W |dur�zt�|� W n2 ty� } zt�d||� W Y d}~n
d}~0 0 dS |�|�} | |k�rbt
j�ddi ��sbW |du�r^zt�|� W n4 t�y\ } zt�d||� W Y d}~n
d}~0 0 dS d}
g }d\}}
tj|dt�� d ���}zh|D ]^}|�� }|
�s�|dk�r�d
}
n�q�|�r�||k�r� �q�|
d7 }
|dk�r�|
}|�|� �q�W n t�y
t� �Y n0 W d � n1 �s"0 Y t|�dk�r�W |du�r�zt�|� W n4 t�y� } zt�d||� W Y d}~n
d}~0 0 dS ||d�= |d
�d��s
dd�|�df W |du�rzt�|� W S t�y } zt�d||� W Y d}~S d}~0 0 S d�|�W |du�rbzt�|� W S t�y` } zt�d||� W Y d}~S d}~0 0 S W |du�rzt�|� W n4 t�y� } zt�d||� W Y d}~n
d}~0 0 nP|du�rzt�|� W n4 t�y } zt�d||� W Y d}~n
d}~0 0 0 dS )a� Let the user edit a commit message in a temp file.
This is run if they don't give a message or
message-containing file on the command line.
:param infotext: Text to be displayed at bottom of message
for the user's reference;
currently similar to 'bzr status'.
The string is already encoded
:param ignoreline: The separator to use above the infotext.
:param start_message: The text to place above the separator, if any.
This will not be removed from the message
after the user has edited it.
The string is already encoded
:return: commit message or None.
Nz failed to unlink %s: %s; ignoredz)Commit message was not edited, use anywayzbreezy.msgeditor.unchanged� F)r r �rb)�mode�encodingTr r ����
z%s%s)�&_create_temp_file_with_commit_templater �unlink�IOErrorr r$ r �basenamer
Zget_transport_from_path�dirnameZ get_bytesr) r Z
ui_factoryZconfirm_action�codecs�openr- �strip�append�UnicodeDecodeErrorr �len�endswith�join)r/ r0 r1 �msgfilename�hasinfor r<