HEX
Server: LiteSpeed
System: Linux s787.bom1.mysecurecloudhost.com 4.18.0-477.13.1.lve.el8.x86_64 #1 SMP Thu Jun 1 16:40:47 EDT 2023 x86_64
User: mobilech (5348)
PHP: 8.1.34
Disabled: NONE
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/git/__pycache__/util.cpython-310.pyc
o

;j��	@s�UddlZgd�Zejdkre�d�ddlmZddlZddlmZddl	Z	ddl
Z
ddlZddlm
ZddlmZddlZddlZddlZddlZddlZddlZddlmZmZddlZdd	lmZmZmZmZmZm Z m!Z!m"Z"m#Z#dd
l$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6e2r�ddl7m8Z8ddl9m:Z:m;Z;dd
l<m=Z=ddl>m?Z?ddl@mAZAmBZBmCZCmDZDmEZEmFZFmGZGmHZHmIZIe3de4ddd�ZJe
�KeL�ZMdeNdeOdeOfdd�ZPdeNdeOdeOfdd�ZQeQdd�ZReQdd�ZSe3d�ZTde(deTfde(deTffd d!�ZUejVd"eEde*eEddffd#d$��ZWejVdeNd%eNde*d&fd'd(��ZXd)eEddfd*d+�ZYd)eEddfd,d-�ZZd�d/e'd0e'd1e[de[fd2d3�Z\d4eEd5eEdeEfd6d7�Z]ejdk�ryd)eEdeNfd8d�Z^d)eEdeNfd9d:�Z_e^Z`nd)eEdeNfd;d:�Z_e_Z`d4eEd5eEdeEfd<d=�Zad�d)eEd?eOdeOfd@dA�Zbde0eNfdBdC�Zcd�dDeNd)e.eEde-eNfdEdF�ZddGe.eNd)eNdeNfdHdI�Zee�fdJ�dKdL�d>fe�fdM�eed>fe�fdN�eed>fe�fdOejg�dPdL�dfe�fdQ�dRdL�d>ffZhe1e1e/eNe(eOfdfeidS<d)eNdeNfdTdU�Zje�fdV�Zkd)eEdeNfdWdX�ZliZme)eNe.eOfeidY<dZeNdeOfd[d\�Zne6dZddeDd>fd]d^��Zoe6dZeEdeOfd_d^��ZodZe4deEfdeOfd`d^�ZodeNfdadb�Zpdce4ejqddfdee%ddfdfdg�Zre6d�d5ddheOddfdidj��Zse6d�d5eEdheOdeNfdkdj��Zsd�d5e4deEfdheOde.eEfdldj�Zsdme0eNde-eNfdndo�ZtGdpdq�dq�ZuGdrds�dseu�ZvGdtdu�du�ZwGdvdw�dw�ZxGdxdy�dy�ZyGdzd{�d{�ZzGd|d}�d}ez�Z{Gd~d�de-eJ�Z|eIGd�d��d�eF��Z}Gd�d��d�e~�ZGd�d��d�ed��Z�dS)��N)�stream_copy�	join_path�to_native_path_linux�join_path_native�Stats�IndexFileSHA1Writer�IterableObj�IterableList�BlockingLockFile�LockFile�Actor�get_user_id�assure_directory_exists�RemoteProgress�CallableRemoteProgress�rmtree�unbare_repo�HIDE_WINDOWS_KNOWN_ERRORS�win32�to_native_path_windows)�abstractmethod)�wraps)�Path)�urlsplit�
urlunsplit)	�	LazyMixin�LockedFD�
bin_to_hex�file_contents_ro�file_contents_ro_filepath�
hex_to_bin�make_sha�
to_bin_sha�
to_hex_sha)�Any�AnyStr�BinaryIO�Callable�Dict�	Generator�IO�Iterator�List�Optional�Pattern�Sequence�Tuple�
TYPE_CHECKING�TypeVar�Union�cast�overload)�Git)�GitConfigParser�SectionConstraint)�Remote)�Repo)	�Files_TD�Has_id_attribute�HSH_TD�Literal�PathLike�Protocol�
SupportsIndex�Total_TD�runtime_checkable�
T_IterableObj)rr<T)�bound�	covariant�name�default�returncCsjztj|}Wnty|YSwt�d|�|����}|dvr%dS|dvr+dSt�d|||�|S)z�Read a boolean flag from an environment variable.

    :return:
        The flag, or the `default` value if absent or ambiguous.
    zlThe %s environment variable is deprecated. Its effect has never been documented and changes without warning.>��0�false�noF>Zyes�true�1Tz-%s has unrecognized value %r, treating as %r.)�os�environ�KeyError�_logger�warning�strip�lower)rGrH�valueZadjusted_value�rX�</opt/saltstack/salt/lib/python3.10/site-packages/git/util.py�_read_env_flagss ��rZcCstjdko	t||�S)aRead a boolean flag from an environment variable on Windows.

    :return:
        On Windows, the flag, or the `default` value if absent or ambiguous.
        On all other operating systems, ``False``.

    :note:
        This only accesses the environment on Windows.
    r)�sys�platformrZ)rGrHrXrXrY�_read_win_env_flag�s
r]r�HIDE_WINDOWS_FREEZE_ERRORS�T�func.c	s8ddlm�t��dddtdtdtf��fdd	��}|S)
ztMethods with this decorator raise :exc:`~git.exc.InvalidGitRepositoryError` if
    they encounter a bare repository.�)�InvalidGitRepositoryError�selfr9�args�kwargsrIcs,|jjr�d�j���|g|�Ri|��S)Nz/Method '%s' cannot operate on bare repositories)�repoZbare�__name__�rcrdre�rbr`rXrY�wrapper�szunbare_repo.<locals>.wrapper)�excrbrr$r_)r`rjrXrirYr�s"r�new_dirc	cs8�t��}t�|�z|VWt�|�dSt�|�w)z�Context manager to temporarily change directory.

    This is similar to :func:`contextlib.chdir` introduced in Python 3.11, but the
    context manager object returned by a single call to this function is not reentrant.
    N)rP�getcwd�chdir)rl�old_dirrXrXrY�cwd�s�
rprW)NNNc	cs`�t�|�}|tj|<zdVW|durtj|=dS|tj|<dS|dur*tj|=w|tj|<w)z=Context manager to temporarily patch an environment variable.N)rP�getenvrQ)rGrW�	old_valuerXrXrY�	patch_env�s�

�rs�pathcCs`dtdtdtddfdd�}tjdkrt�|�dStjd	kr'tj||d
�dStj||d�dS)z�Remove the given directory tree recursively.

    :note:
        We use :func:`shutil.rmtree` but adjust its behaviour to see whether files that
        couldn't be deleted are read-only. Windows will not remove them in that case.
    �functionrt�_excinforINc
SsXt�|tj�z||�WdSty+}ztr&ddlm}|d|���|��d}~ww)zuCallback for :func:`shutil.rmtree`.

        This works as either a ``onexc`` or ``onerror`` style callback.
        r)�SkipTestz%FIXME: fails with: PermissionError
  N)rP�chmod�stat�S_IWUSR�PermissionErrorrZunittestrw)rurtrv�exrwrXrXrY�handler�s��zrmtree.<locals>.handlerr)��)Zonexc)�onerror)r'r?r$r[r\�shutilr�version_info)rtr}rXrXrYr�s

rcCs2t�|�rtjdkrt�|d�t�|�dSdS)zWEnsure file deleted also on *Windows* where read-only files need special
    treatment.ri�N)�osp�isfiler[r\rPrx�remove�rtrXrXrY�rmfile�s


�r���source�destination�
chunk_sizecCs:d}	|�|�}|�|�|t|�7}t|�|kr	|Sq)z�Copy all data from the `source` stream into the `destination` stream in chunks
    of size `chunk_size`.

    :return:
        Number of bytes written
    r)�read�write�len)r�r�r��br�chunkrXrXrYr�s

�r�a�pcGslt�|�}|D],}t�|�}|sq|�d�r||dd�7}q|dks(|�d�r-||7}q|d|7}q|S)zmJoin path tokens together similar to osp.join, but always use ``/`` instead of
    possibly ``\`` on Windows.�/raNrJ)rP�fspath�
startswith�endswith)r�r�rt�brXrXrYrs



rcC�t�|�}|�dd�S)Nr��\�rPr��replacer�rXrXrYr$�
cCr�)Nr�r�r�r�rXrXrYr(r�rcCs
t�|�S�N)rPr�r�rXrXrYr/�
cGstt|g|�R��S)z�Like :func:`join_path`, but makes sure an OS native path is returned.

    This is only needed to play it safe on Windows and to ensure nice paths that only
    use ``\``.
    )�to_native_pathr)r�r�rXrXrYr5srF�is_filecCs.|rt�|�}t�|�stj|dd�dSdS)a$Make sure that the directory pointed to by path exists.

    :param is_file:
        If ``True``, `path` is assumed to be a file and handled correctly.
        Otherwise it must be a directory.

    :return:
        ``True`` if the directory was created, ``False`` if it already existed.
    T)�exist_okF)r��dirname�isdirrP�makedirs)rtr�rXrXrYr>s


rcCs>tj�dd�}|rtdd�|�tj�D��StjdkrdSdS)N�PATHEXTcss�|]}|��VqdSr�)�upper)�.0r�rXrXrY�	<genexpr>Ts�z&_get_exe_extensions.<locals>.<genexpr>r)z.BATz.COMz.EXErX)rPrQ�get�tuple�split�pathsepr[r\)r�rXrXrY�_get_exe_extensionsQs
r��programcs�t��dtdtf�fdd�}g}|stjd}t�|��tj�D]'}|�d�}|rGt	�
||���g�fdd��D�D]}||�rF|�|�q;q |S)	a6Perform a path search to assist :func:`is_cygwin_git`.

    This is not robust for general use. It is an implementation detail of
    :func:`is_cygwin_git`. When a search following all shell rules is needed,
    :func:`shutil.which` can be used instead.

    :note:
        Neither this function nor :func:`shutil.which` will predict the effect of an
        executable search on a native Windows system due to a :class:`subprocess.Popen`
        call without ``shell=True``, because shell and non-shell executable search on
        Windows differ considerably.
    �fpathrIcs>t���ot��tj�otjdkp�pt�fdd��D��S)Nrc3s�|]
}����|�VqdSr�)r�r�)r��ext�r�rXrYr�ps�z,py_where.<locals>.is_exec.<locals>.<genexpr>)r�r�rP�access�X_OKr[r\�anyr�)�winprog_extsr�rY�is_execks

�$�zpy_where.<locals>.is_exec�PATH�"csg|]}d�|f�qS)z%s%srX)r��e)�exe_pathrXrY�
<listcomp>{szpy_where.<locals>.<listcomp>)r��str�boolrPrQr�r�r�rUr��join�append)r�rtr�ZprogsZfolder�frX)r�r�rY�py_where[s	


�r��drivecCsvt�|�r
|s
|}n&|ot�t�t�|���}t�|�r&|r!|}nt|�}n
|r0d|��|f}t�|�}|�	dd�S)Nz/proc/cygdrive/%s/%sr�r�)
r��isabs�normpath�
expandvars�
expanduser�cygpathrVrPr�r�)r�rtr�Zp_strrXrXrY�
_cygexpath�s


r�z*\\\\\?\\UNC\\([^\\]+)\\([^\\]+)(?:\\(.*))?cCsd|||�dd�fS)Nz
//%s/%s/%sr�r�)r�)Zserver�share�	rest_pathrXrXrY�<lambda>�sr�z\\\\\?\\(\w):[/\\](.*)z(\w):[/\\](.*)z	file:(.*)cC�|Sr�rX)r�rXrXrYr���z(\w{2,}:.*)cCr�r�rX)�urlrXrXrYr��r��_cygpath_parserscCs^t�|�}|�d�s-tD]\}}}|�|�}|r'||���}|r$t|�}|Sqtd|�}|S)zJUse :meth:`git.cmd.Git.polish_url` instead, that works on any environment.)z	/cygdrivez//z/proc/cygdriveN)rPr�r�r��match�groupsr�r�)rtZregex�parserZrecurser�rXrXrYr��s


�
r�z(?:/proc)?/cygdrive/(\w)(/.*)?cCsDt�|�}t�|�}|r|��\}}d|��|pdf}|�dd�S)Nz%s:%srJr�r�)rPr��_decygpath_regexr�r�r�r�)rt�mr�r�rXrXrY�	decygpath�s

r��_is_cygwin_cache�git_executablec	
Cs�t�|�}|durwd}zOt�|�}|s"t|�}|r t�|d�nd}t�|d�}t|���r5t�	|tj
�sEt�d|�d��|t|<|WSt
j|gt
jdd�}|��\}}d	|v}Wntyr}zt�d
|�WYd}~nd}~ww|t|<|S)NFrrJ�unamez&Failed checking if running in CYGWIN: z is not an executableT)�stdout�universal_newlinesZCYGWINz/Failed checking if running in CYGWIN due to: %r)r�r�r�r�r�r�rr�rPr�r�rS�debug�
subprocess�Popen�PIPE�communicate�	Exception)	r�Z	is_cygwinZgit_dir�resZ	uname_cmd�processZ	uname_out�_r|rXrXrY�_is_cygwin_git�s,

��r�cC�dSr�rX�r�rXrXrY�
is_cygwin_git��r�cCr�r�rXr�rXrXrYr��r�cCs>t�dtj�d|���tjdkrdS|durdStt|��S)Nz
sys.platform=z, git_executable=�cygwinF)rSr�r[r\r�r�r�rXrXrYr��s
cCsdt��t��fS)zM:return: String identifying the currently active system user as ``name@node``z%s@%s)�getpassZgetuserr\�noderXrXrXrYr
�sr
�proczGit.AutoInterruptrecKs|jdi|��dS)zXWait for the process (clone, fetch, pull or push) and handle its errors
    accordingly.NrX)�wait)r�rerXrXrY�finalize_process�sr��expand_varscCr�r�rX�r�r�rXrXrY�expand_pathr�r�cCr�r�rXr�rXrXrYr�scCsRt|t�r	|��Szt�|�}|rt�|�}t�t�|��WSty(YdSwr�)	�
isinstancer�resolver�r�r�r��abspathr�r�rXrXrYr�
s


��cmdlinec	Cs�g}t|�D]L\}}|�|�z:t|�}|jdur |jdur Wq|jdur1|j|j�|jd�d�}|jdurB|j|j�|jd�d�}t|�||<Wqt	yRYqw|S)a>Parse any command line argument and if one of the elements is an URL with a
    username and/or password, replace them by stars (in-place).

    If nothing is found, this just returns the command line as-is.

    This should be used for every log line that print a command line, as well as
    exception messages.
    Nz*****)�netloc)
�	enumerater�r�password�username�_replacer�r�r�
ValueError)r�Znew_cmdline�indexZto_parser�rXrXrY�remove_password_if_presents 	


�r�c@s�eZdZUdZdZeed<dd�ee�D�\	ZZ	Z
ZZZ
ZZZee	BZeZdZdZdZe�d	�Ze�d
�Zdd
d�Zdeddfdd�Zdeegdffdd�Zdeddfdd�Z 		ddede!ee"fde!ee"dfdeddf
dd�Z#dS)rz�Handler providing an interface to parse progress information emitted by
    :manpage:`git-push(1)` and :manpage:`git-fetch(1)` and to dispatch callbacks
    allowing subclasses to react to the progress.�	�
_num_op_codescCsg|]}d|>�qS)rarX)r��xrXrXrYr�KszRemoteProgress.<listcomp>zdone.z, )�	_cur_line�	_seen_ops�error_lines�other_linesz%(remote: )?([\w\s]+):\s+()(\d+)()(.*)z2(remote: )?([\w\s]+):\s+(\d+)% \((\d+)/(\d+)\)(.*)rINcCsg|_d|_g|_g|_dSr�)rrrr�rcrXrXrY�__init__[s
zRemoteProgress.__init__�linecCs�t|t�r|�d�}n|}||_|j�d�r|j�|j�dSd\}}|j�|�}|dur3|j	�|�}|sB|�
|�|j�|�dSd}|��\}}}	}}}
|dkrX||j
O}nC|dkrb||jO}n9|dkrl||jO}n/|d	krv||jO}n%|d
kr�||jO}n|dkr�||jO}n|dkr�||jO}n|�
|�dS||jvr�|j�|�||jO}|
dur�d
}
|
��}
|
�|j�r�||jO}|
dt|j��}
|
�|j�}
|�||o�t|�|o�t|�|
�dS)a^Parse progress information from the given line as retrieved by
        :manpage:`git-push(1)` or :manpage:`git-fetch(1)`.

        - Lines that do not contain progress info are stored in :attr:`other_lines`.
        - Lines that seem to contain an error (i.e. start with ``error:`` or ``fatal:``)
          are stored in :attr:`error_lines`.
        zutf-8)zerror:zfatal:N)NNrzCounting objectszCompressing objectszWriting objectszReceiving objectszResolving deltaszFinding sourceszChecking out filesrJ)r��bytes�decoderr�rr��re_op_relativer��re_op_absolute�line_droppedrr��COUNTING�COMPRESSING�WRITING�	RECEIVING�	RESOLVING�FINDING_SOURCES�CHECKING_OUTr�BEGINrUr��
DONE_TOKEN�ENDr��TOKEN_SEPARATOR�update�float)rcrZline_str�	cur_count�	max_countr��op_codeZ_remoteZop_nameZ_percent�messagerXrXrY�_parse_progress_lineasb








�z#RemoteProgress._parse_progress_linecsdtddf�fdd�}|S)z�
        :return:
            A progress handler suitable for :func:`~git.cmd.handle_process_output`,
            passing lines on to this progress handler in a suitable format.
        rrINcs��|���Sr�)r�rstrip)rrrXrYr}�sz3RemoteProgress.new_message_handler.<locals>.handler)r%)rcr}rXrrY�new_message_handler�sz"RemoteProgress.new_message_handlercC�dS)zICalled whenever a line could not be understood and was therefore dropped.NrX)rcrrXrXrYr�szRemoteProgress.line_droppedrJrrrrcCr!)a�Called whenever the progress changes.

        :param op_code:
            Integer allowing to be compared against Operation IDs and stage IDs.

            Stage IDs are :const:`BEGIN` and :const:`END`. :const:`BEGIN` will only be
            set once for each Operation ID as well as :const:`END`. It may be that
            :const:`BEGIN` and :const:`END` are set at once in case only one progress
            message was emitted due to the speed of the operation. Between
            :const:`BEGIN` and :const:`END`, none of these flags will be set.

            Operation IDs are all held within the :const:`OP_MASK`. Only one Operation
            ID will be active per call.

        :param cur_count:
            Current absolute count of items.

        :param max_count:
            The maximum count of items we expect. It may be ``None`` in case there is no
            maximum number of items or if it is (yet) unknown.

        :param message:
            In case of the :const:`WRITING` operation, it contains the amount of bytes
            transferred. It may possibly be used for other purposes as well.

        :note:
            You may read the contents of the current line in
            :attr:`self._cur_line <_cur_line>`.
        NrX)rcrrrrrXrXrYr�s$zRemoteProgress.update�rIN�NrJ)$rg�
__module__�__qualname__�__doc__r��int�__annotations__�rangerrr
rrrrrrZ
STAGE_MASKZOP_MASKrr�	__slots__�re�compilerr
rr%rr'r�r rr3rrrXrXrXrYr;sL
�


Y��
����rcsDeZdZdZdZdeddf�fdd�Zded	eddfd
d�Z�Z	S)ra�A :class:`RemoteProgress` implementation forwarding updates to any callable.

    :note:
        Like direct instances of :class:`RemoteProgress`, instances of this
        :class:`CallableRemoteProgress` class are not themselves directly callable.
        Rather, instances of this class wrap a callable and forward to it. This should
        therefore not be confused with :class:`git.types.CallableProgress`.
    ��	_callable�fnrINcs||_t���dSr�)r.�superr)rcr/��	__class__rXrYr��zCallableRemoteProgress.__init__rdrecOs|j|i|��dSr�r-rhrXrXrYrszCallableRemoteProgress.update)
rgr$r%r&r*r'rr$r�
__classcell__rXrXr1rYr�s
	rc
@s eZdZdZe�d�Ze�d�ZdZdZ	dZ
dZdZd	Z
d
Zdeed	eeddfd
d�Zdedefdd�Zdedefdd�Zdefdd�Zdefdd�Zdefdd�Zededdfdd��Ze	d'dededed ddfd!d"��Zed'ded ddfd#d$��Zed'ded ddfd%d&��ZdS)(rz�Actors hold information about a person acting on the repository. They can be
    committers and authors or anything with a name and an email as mentioned in the git
    log entries.z<(.*)>z(.*) <(.*?)>ZGIT_AUTHOR_NAMEZGIT_AUTHOR_EMAILZGIT_COMMITTER_NAMEZGIT_COMMITTER_EMAILrG�email�rGr5rINcC�||_||_dSr�r6)rcrGr5rXrXrYr�
zActor.__init__�othercCs|j|jko|j|jkSr�r6�rcr9rXrXrY�__eq__!szActor.__eq__cCs
||kSr�rXr:rXrXrY�__ne__$r�zActor.__ne__cCst|j|jf�Sr�)�hashrGr5rrXrXrY�__hash__'�zActor.__hash__cCs|jr|jSdSr#)rGrrXrXrY�__str__*r?z
Actor.__str__cCsd|j|jfS)Nz<git.Actor "%s <%s>">r6rrXrXrY�__repr__-r?zActor.__repr__�stringcCsP|j�|�}|r|��\}}t||�S|j�|�}|r#t|�d�d�St|d�S)z�Create an :class:`Actor` from a string.

        :param string:
            The string, which is expected to be in regular git format::

                John Doe <jdoe@example.com>

        :return:
            :class:`Actor`
        raN)�name_email_regex�searchr�r�name_only_regex�group)�clsrBr�rGr5rXrXrY�_from_string0s

zActor._from_string�env_name�	env_email�
config_reader)Nr7r8cs�tdd�}d�dtf�fdd��dtf�fdd�}d||j|fd||j�ffD]G\}}}}	z
tj|}
t|||
�Wq'tyn|dur`z|�d	|�}
Wnt	yY|	�}
Ynwt|||
�t
||�slt|||	��Yq'w|S)
NrJrIcs�st���Sr�)r
rX)�user_idrXrY�
default_emailSsz(Actor._main_actor.<locals>.default_emailcs���d�dS)N�@r)r�rX)rMrXrY�default_nameYr?z'Actor._main_actor.<locals>.default_namerGr5�user)rr��	conf_name�
conf_emailrPrQ�setattrrRr�r��getattr)rGrIrJrKZactorrO�attrZevarZcvarrH�valrX)rMrLrY�_main_actorIs.
�

�
��zActor._main_actorcC�|�|j|j|�S)a�
        :return:
            :class:`Actor` instance corresponding to the configured committer. It
            behaves similar to the git implementation, such that the environment will
            override configuration values of `config_reader`. If no value is set at all,
            it will be generated.

        :param config_reader:
            ConfigReader to use to retrieve the values from in case they are not set in
            the environment.
        )rW�env_committer_name�env_committer_email�rGrKrXrXrY�	committerqs
zActor.committercCrX)z�Same as :meth:`committer`, but defines the main author. It may be specified
        in the environment, but defaults to the committer.)rW�env_author_name�env_author_emailr[rXrXrY�author�szActor.authorr�) rgr$r%r&r+r,rErCr]r^rYrZrQrRr*r-r�rr$r�r;r<r'r>r@rA�classmethodrHr3rWr\r_rXrXrXrYrsD

�����'rc@sLeZdZdZdZdedeeefddfdd�Z	e
d	d
deddfdd
��ZdS)ra�Represents stat information as presented by git at the end of a merge. It is
    created from the output of a diff operation.

    Example::

     c = Commit( sha1 )
     s = c.stats
     s.total         # full-stat-dict
     s.files         # dict( filepath : stat-dict )

    ``stat-dict``

    A dictionary with the following keys and values::

      deletions = number of deleted lines as int
      insertions = number of inserted lines as int
      lines = total number of lines changed as int, or deletions + insertions
      change_type = type of change as str, A|C|D|M|R|T|U|X|B

    ``full-stat-dict``

    In addition to the items in the stat-dict, it features additional information::

     files = number of changed files as int
    ��total�filesrbrcrINcCr7r�ra)rcrbrcrXrXrYr�r8zStats.__init__rfr:�textcCs�ddddd�id�}|��D]Z}|�d�\}}}}|dkr!t|�p"d}	|dkr+t|�p,d}
|dd|	7<|dd|
7<|dd	|	|
7<|dd
d7<|	|
|	|
|d�}||d
|��<qt|d|d
�S)
z�Create a :class:`Stats` object from output retrieved by
        :manpage:`git-diff(1)`.

        :return:
            :class:`git.Stats`
        r)�
insertions�	deletions�linesrcra�	�-rbrerfrgrcra)rerfrg�change_type)�
splitlinesr�r'rUr)rGrfrdZhshrrjZraw_insertionsZ
raw_deletions�filenamererfZ
files_dictrXrXrY�_list_from_string�s$
��zStats._list_from_string)
rgr$r%r&r*rBr(r?r;rr`r�rmrXrXrXrYr�src@sbeZdZdZdZdeddfdd�Zdedefd	d
�Z	de
fdd�Zde
fd
d�Zdefdd�Z
dS)raWrapper around a file-like object that remembers the SHA1 of the data written to
    it. It will write a sha when the stream is closed or if asked for explicitly using
    :meth:`write_sha`.

    Only useful to the index file.

    :note:
        Based on the dulwich project.
    )r��sha1r�rINcCs||_td�|_dS)N�)r�r!rn)rcr�rXrXrYr�r3zIndexFileSHA1Writer.__init__�datacCs|j�|�|j�|�Sr�)rnrr�r�)rcrprXrXrYr��szIndexFileSHA1Writer.writecCs|j��}|j�|�|Sr�)rn�digestr�r��rcZsharXrXrY�	write_sha�s
zIndexFileSHA1Writer.write_shacCs|��}|j��|Sr�)rsr��closerrrXrXrYrt�s
zIndexFileSHA1Writer.closecCs
|j��Sr�)r��tellrrXrXrYru�r�zIndexFileSHA1Writer.tell)rgr$r%r&r*r*rr%r'r�rrsrtrurXrXrXrYr�s
rc@sjeZdZdZdZdeddfdd�Zddd	�Zdefd
d�Z	de
fdd
�Zddd�Zddd�Z
ddd�ZdS)raProvides methods to obtain, check for, and release a file based lock which
    should be used to handle concurrent access to the same file.

    As we are a utility class to be derived from, we only use protected methods.

    Locks will automatically be released on destruction.
    ��
_file_path�
_owns_lock�	file_pathrINcCs||_d|_dS)NFrv)rcryrXrXrYr�r8zLockFile.__init__cCs|��dSr�)�
_release_lockrrXrXrY�__del__��zLockFile.__del__cCs
d|jS)z:return: Path to lockfilez%s.lock)rwrrXrXrY�_lock_file_path�s
zLockFile._lock_file_pathcCs|jS)z�
        :return:
            True if we have a lock and if the lockfile still exists

        :raise AssertionError:
            If our lock-file does not exist.
        )rxrrXrXrY�	_has_lockszLockFile._has_lockc
Cs�|��rdS|��}t�|�rtd|j|f��zt|dd��Wd�n1s*wYWntyC}ztt|��|�d}~wwd|_	dS)z�Create a lock file as flag for other instances, mark our instance as
        lock-holder.

        :raise IOError:
            If a lock was already present or a lock file could not be written.
        NzILock for file %r did already exist, delete %r in case the lock is illegal�w)�modeT)
r~r}r�r��IOErrorrw�open�OSErrorr�rx)rcZ	lock_filer�rXrXrY�_obtain_lock_or_raise
s&
������
zLockFile._obtain_lock_or_raisecCs|��S)z�The default implementation will raise if a lock cannot be obtained.

        Subclasses may override this method to provide a different implementation.
        )r�rrXrXrY�_obtain_lock"szLockFile._obtain_lockcCs>|��sdS|��}zt|�Wn	tyYnwd|_dS)z Release our lock if we have one.NF)r~r}r�r�rx)rcZlfprXrXrYrz)s�
zLockFile._release_lockr")rgr$r%r&r*r?rr{r�r}r�r~r�r�rzrXrXrXrYr�s



rc	sLeZdZdZdZdejfdedede	ddf�fd	d
�
Z
d
�fdd�Z�ZS)r
aThe lock file will block until a lock could be obtained, or fail after a
    specified timeout.

    :note:
        If the directory containing the lock was removed, an exception will be raised
        during the blocking period, preventing hangs as the lock can never be obtained.
    )�_check_interval�_max_block_timeg333333�?ry�check_interval_s�max_block_time_srINcst��|�||_||_dS)aConfigure the instance.

        :param check_interval_s:
            Period of time to sleep until the lock is checked the next time.
            By default, it waits a nearly unlimited time.

        :param max_block_time_s:
            Maximum amount of seconds we may lock.
        N)r0rr�r�)rcryr�r�r1rXrYrCs
zBlockingLockFile.__init__c
s�t��}|t|j�}	zt���WdSty\}z<t��}t�t�|�	���s9d|�	�||f}t|�|�||krLd|||�	�f}t|�|�t�
|j�WYd}~nd}~wwq)z�This method blocks until it obtained the lock, or raises :exc:`IOError` if it
        ran out of time or if the parent directory was not available anymore.

        If this method returns, you are guaranteed to own the lock.
        TzVDirectory containing the lockfile %r was not readable anymore after waiting %g secondsz Waited %g seconds for lock at %rN)�timerr�r0r�r�r�r�r�r}�sleepr�)rcZ	starttimeZmaxtimer�Zcurtime�msgr1rXrYr�Vs0��
�
���zBlockingLockFile._obtain_lockr")
rgr$r%r&r*r[�maxsizer?rr'rr�r4rXrXr1rYr
8s�����r
cs�eZdZdZdZddededdf�fdd	�
Zddededd
fdd�Zd
ede	fdd�Z
d
edefdd�Zde
eeeefdefdd�Zde
eeeefdd
fdd�Z�ZS)r	a�List of iterable objects allowing to query an object by id or by named index::

     heads = repo.heads
     heads.master
     heads['master']
     heads[0]

    Iterable parent objects:

    * :class:`Commit <git.objects.Commit>`
    * :class:`Submodule <git.objects.submodule.base.Submodule>`
    * :class:`Reference <git.refs.reference.Reference>`
    * :class:`FetchInfo <git.remote.FetchInfo>`
    * :class:`PushInfo <git.remote.PushInfo>`

    Iterable via inheritance:

    * :class:`Head <git.refs.head.Head>`
    * :class:`TagReference <git.refs.tag.TagReference>`
    * :class:`RemoteReference <git.refs.remote.RemoteReference>`

    This requires an ``id_attribute`` name to be set which will be queried from its
    contained items to have a means for comparison.

    A prefix can be specified which is to be used in case the id returned by the items
    always contains a prefix that does not matter to the user, so it can be left out.
    ��_id_attr�_prefixrJ�id_attr�prefixrIzIterableList[T_IterableObj]cst��|�Sr�)r0�__new__)rGr�r�r1rXrYr��r|zIterableList.__new__NcCr7r�r�)rcr�r�rXrXrYr�r8zIterableList.__init__rUc	Csbz
t�||�}|r|WSWnttfyYnwzt|tt|��WdSttfy0YdSw)NTF)�list�__contains__�AttributeError�	TypeErrorrTr4r�)rcrUZrvalrXrXrYr��s���zIterableList.__contains__cCs8|j|}|D]}t||j�|kr|Sqt�||�Sr�)r�rTr�r��__getattribute__)rcrU�itemrXrXrY�__getattr__�s
�zIterableList.__getattr__r�c
Csjt|t�rt�||�St|t�rtd��z	t|tt|��WSt	y4}zt
d|j�|���|�d}~ww)NzIndex should be an int or strzNo item found with id )r�r'r��__getitem__�slicer�rTr4r�r��
IndexErrorr�)rcr�r�rXrXrYr��s

��zIterableList.__getitem__cCsptt|�}t|t�r0d}|j|}t|�D]\}}t||j�|kr%|}nq|dkr0td|��t	�
||�dS)N���zItem with name %s not found)r4r'r�r�r�r�rTr�r�r��__delitem__)rcr�ZdelindexrG�ir�rXrXrYr��s


�zIterableList.__delitem__)rJ)rgr$r%r&r*r�r�r�objectr�r�rDr�r3rAr'r�r�r�r4rXrXr1rYr	zs&r	c@sfeZdZUdZdZeed<eeddde	de	de
efd	d
���Zeddde	de	de
efdd��Zd
S)ra�Defines an interface for iterable items, so there is a uniform way to retrieve
    and iterate items within the git repository.

    Subclasses:

    * :class:`Submodule <git.objects.submodule.base.Submodule>`
    * :class:`Commit <git.objects.Commit>`
    * :class:`Reference <git.refs.reference.Reference>`
    * :class:`PushInfo <git.remote.PushInfo>`
    * :class:`FetchInfo <git.remote.FetchInfo>`
    * :class:`Remote <git.remote.Remote>`
    rX�_id_attribute_rfr:rdrerIcO�td��)aSFind (all) items of this type.

        Subclasses can specify `args` and `kwargs` differently, and may use them for
        filtering. However, when the method is called with no additional positional or
        keyword arguments, subclasses are obliged to to yield all items.

        :return:
            Iterator yielding Items
        �To be implemented by Subclass��NotImplementedError�rGrfrdrerXrXrY�
iter_items�s
zIterableObj.iter_itemscO�,t|j�}|�|j|g|�Ri|���|S)a�Find (all) items of this type and collect them into a list.

        For more information about the arguments, see :meth:`iter_items`.

        :note:
            Favor the :meth:`iter_items` method as it will avoid eagerly collecting all
            items. When there are many items, that can slow performance and increase
            memory usage.

        :return:
            list(Item,...) list of item instances
        �r	r��extendr��rGrfrdreZout_listrXrXrY�
list_items�s
zIterableObj.list_itemsN)rgr$r%r&r*r�r(r`rr$r+rDr�r	r�rXrXrXrYr�s

"
$rc@s*eZdZdZdedededdfdd�ZdS)	�IterableClassWatcherzbMetaclass that issues :exc:`DeprecationWarning` when :class:`git.util.Iterable`
    is subclassed.rG�bases�clsdictrINcCs2|D]}t|�turtjd|�d�tdd�qdS)Nz!GitPython Iterable subclassed by zq. Iterable is deprecated due to naming clash since v3.1.18 and will be removed in 4.0.0. Use IterableObj instead.�)�
stacklevel)�typer��warnings�warn�DeprecationWarning)rGrGr�r��baserXrXrYrs
���zIterableClassWatcher.__init__)rgr$r%r&r�r0r(rrXrXrXrYr�
sr�c	@sTeZdZdZdZdZedddededefd	d
��Zedddededefdd��Z	d
S)�Iterablez�Deprecated, use :class:`IterableObj` instead.

    Defines an interface for iterable items, so there is a uniform way to retrieve
    and iterate items within the git repository.
    rXz5attribute that most suitably identifies your instancerfr:rdrerIcOr�)z�Deprecated, use :class:`IterableObj` instead.

        Find (all) items of this type.

        See :meth:`IterableObj.iter_items` for details on usage.

        :return:
            Iterator yielding Items
        r�r�r�rXrXrYr�)szIterable.iter_itemscOr�)aDeprecated, use :class:`IterableObj` instead.

        Find (all) items of this type and collect them into a list.

        See :meth:`IterableObj.list_items` for details on usage.

        :return:
            list(Item,...) list of item instances
        r�r�rXrXrYr�6s
zIterable.list_itemsN)
rgr$r%r&r*r�r`r$r�r�rXrXrXrYr�s r�)�	metaclass)r�)Fr�).)T)�r[�__all__r\r��abcr�
contextlib�	functoolsrr��loggingrPZos.pathrtr��pathlibrr+r�ryr�r��urllib.parserrr�Z
gitdb.utilrrrrrr r!r"r#�typingr$r%r&r'r(r)r*r+r,r-r.r/r0r1r2r3r4r5Zgit.cmdr6Z
git.configr7r8Z
git.remoter9Z
git.repo.baser:Z	git.typesr;r<r=r>r?r@rArBrCrD�	getLoggerrgrSr�r�rZr]rr^r_r�contextmanagerrprsrr�r'rrrrr�rrr�r�r�r,�Ir�r(r�r�r�r�r�r�r
r�r�r�r�rrrrrrr
r	rr�r�r�rXrXrXrY�<module>s�


,P,


"
!		 
&�"�
 $"9@#NB^4