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/dulwich/__pycache__/porcelain.cpython-39.pyc
a

3k�_��@s�dZddlmZddlmZmZddlmZmZddl	Z	ddl
Z
ddlmZddl
Z
ddlZddlZddlZddlZddlmZmZmZmZddlmZdd	lmZdd
lmZddlmZmZm Z m!Z!m"Z"m#Z#ddl$m%Z%dd
l&m'Z'ddl(m)Z)ddl*m+Z+m,Z,ddl-m.Z.ddl/m0Z0m1Z1m2Z2m3Z3m4Z4ddl5m6Z6m7Z7m8Z8m9Z9m:Z:ddl;m<Z<m=Z=ddl>m?Z?ddl@mAZAmBZBddlCmDZDmEZEmFZFmGZGddlHmIZImJZJddlKmLZLmMZMmNZNmOZOmPZQedd�ZRGdd�de�ZSeTejUdd��p�eS�ZVeTejWdd��p�eS�ZXdZYGdd �d eZ�Z[Gd!d"�d"e[�Z\d#d$�Z]ed%d&��Z^d'd(�Z_eYfd)d*�Z`Gd+d,�d,e[�Zad-d.�ZbdeVeXfd/d0�Zcd�d2d3�ZPd�d5d6�Zdd�d7d8�Zed�d9d:�Zfd�d;d<�Zgdd4deXdd=dfd>d?�Zhd�d@dA�ZidBdC�Zjd�dDdE�Zkd�dFdG�ZlelZmeYfdHdI�ZneYfdJdK�ZoejUfdLdM�ZpejUfdNdO�ZqejUfdPdQ�ZrejUfdRdS�ZsejUfdTdU�ZtejUfdVdW�ZudXdY�ZvdZd[�Zwd1dejUdd4d4fd\d]�Zxd1dejUeYfd^d_�ZyejUfd`da�ZzejUfdbdc�Z{ddde�Z|d�dgdh�Z}didj�Z~ejUfdkdl�Zdmdn�Z�d�dodp�Z�d�eJeee�e�feee�e�fdq�drds�Z�ddeVeXd4fdtdu�Z�ddeVeXdvd4fdwdx�Z�d�dydz�Z�d{d|�Z�d}d~�Z�dd��Z�d�d�d��Z�d�d�d��Z�d�d�d��Z�d�d�d��Z�d�d��Z�d�d��Z�d�d��Z�d�d�d��Z�d�d��Z�d�d��Z�d�d��Z�d�eGe�ee�e�fee�e�e�d��d�d��Z�dejUeXddd4d4d4fd�d��Z�d�d�d��Z�d�d��Z�d�d�d��Z�d�ejUd4d4fd�d��Z�d�d��Z�d�d�d��Z�d�d�d��Z�d�d��Z�d�d��Z�d�d��Z�d�d��Z�d�d��Z�d�d��Z�d�d��Z�d�d�d��Z�d�d��Z�dS)�a�Simple wrapper that provides porcelain-like functions on top of Dulwich.

Currently implemented:
 * archive
 * add
 * branch{_create,_delete,_list}
 * check-ignore
 * checkout
 * clone
 * commit
 * commit-tree
 * daemon
 * describe
 * diff-tree
 * fetch
 * init
 * ls-files
 * ls-remote
 * ls-tree
 * pull
 * push
 * rm
 * remote{_add}
 * receive-pack
 * reset
 * rev-list
 * tag{_create,_delete,_list}
 * upload-pack
 * update-server-info
 * status
 * symbolic-ref

These functions are meant to behave similarly to the git subcommands.
Differences in behaviour are considered bugs.

Functions should generally accept both unicode strings and bytestrings
�)�
namedtuple)�closing�contextmanager)�BytesIO�	RawIOBaseN)�Path)�Dict�Optional�Tuple�Union)�
tar_stream)�get_transport_and_path)�
StackedConfig)�
CHANGE_ADD�
CHANGE_DELETE�
CHANGE_MODIFY�
CHANGE_RENAME�CHANGE_COPY�RENAME_CHANGE_TYPES)�
SendPackError)�can_fast_forward)�IgnoreFilterManager)�blob_from_path_and_stat�get_unstaged_changes)�tree_lookup_path)�Commit�Tag�format_timezone�parse_timezone�pretty_format_tree_entry)�parse_commit�parse_object�	parse_ref�parse_reftuples�
parse_tree)�write_pack_index�write_pack_objects)�write_tree_diff)�Protocol�ZERO_SHA)�ANNOTATED_TAG_SUFFIX�LOCAL_BRANCH_PREFIX�strip_peeled_refs�
RefsContainer)�BaseRepo�Repo)�FileSystemBackend�TCPGitServer�ReceivePackHandler�UploadPackHandler�update_server_info�	GitStatuszstaged unstaged untrackedc@s2eZdZdZddd�Zdd�Zdd�Zd	d
�ZdS)
�
NoneStreamz;Fallback if stdout or stderr are unavailable, does nothing.���cCsdS�N�)�self�sizer9r9�3/usr/lib/python3/dist-packages/dulwich/porcelain.py�read�szNoneStream.readcCsdSr8r9)r:r9r9r<�readall�szNoneStream.readallcCsdSr8r9�r:�br9r9r<�readinto�szNoneStream.readintocCsdSr8r9r?r9r9r<�write�szNoneStream.writeN)r7)�__name__�
__module__�__qualname__�__doc__r=r>rArBr9r9r9r<r6�s

r6�buffer�utf-8cs"eZdZdZd�fdd�	Z�ZS)�ErrorzPorcelain-based error. Ncstt|��|�||_dSr8)�superrI�__init__�inner)r:�msgrL��	__class__r9r<rK�szError.__init__)N)rCrDrErFrK�
__classcell__r9r9rNr<rI�srIc@seZdZdZdS)�RemoteExistsz&Raised when the remote already exists.N�rCrDrErFr9r9r9r<rQ�srQcCst|t�r|St|�S)zEOpen an argument that can be a repository or a path for a repository.)�
isinstancer.r/�Zpath_or_repor9r9r<�	open_repo�s
rUccs
|VdS)zBContext manager that has the same api as closing but does nothing.Nr9)�objr9r9r<�_noop_context_manager�srWcCst|t�rt|�Stt|��S)z�Open an argument that can be a repository or a path for a repository.
    returns a context manager that will close the repo on exit if the argument
    is a path, else does nothing if the argument is a repo.
    )rSr.rWrr/rTr9r9r<�open_repo_closing�s
rXcCstjdkr�t|t�st�|�}t|t�s2t�|�}tj�||�}|�d�r^d||f}t	|��tjj
dkr�|�tjj
�d�d�}|Stj
dkr�tj�|�}t|���}tj
dkr�tj�|�}t|���}|�|�}tj
dkr�t|��tjj
d��|�St|�SdS)	aConvert a path to a path usable in an index, e.g. bytes and relative to
    the repository root.

    Args:
      repopath: Repository path, absolute or relative to the cwd
      path: A path, absolute or relative to the cwd
    Returns: A path formatted for use in e.g. an index
    )��s..zPath %r not in repo path (%r)�/�ascii�/Zwin32N)�sys�version_inforS�bytes�os�fsencode�path�relpath�
startswith�
ValueError�sep�replace�encode�platform�abspathr�resolve�relative_to�str)ZrepopathrcZ
tree_encodingZtreepath�err_msgrdr9r9r<�path_to_tree_path�s,









rpc@seZdZdZdS)�DivergedBranchesz8Branches have diverged and fast-forward is not possible.NrRr9r9r9r<rqsrqcCs:zt|||�}Wnty&d}Yn0|s6t||��dS)z�Check if updating to a sha can be done with fast forwarding.

    Args:
      repo: Repository object
      current_sha: Current head sha
      new_sha: New head sha
    FN)r�KeyErrorrq)�repoZcurrent_shaZnew_shaZcanr9r9r<�check_divergeds
rtcCsj|durd}t|��B}t||�}t|j|j|j|j�D]}|�|�q8Wd�n1s\0YdS)z�Create an archive.

    Args:
      repo: Path of repository for which to generate an archive.
      committish: Commit SHA1 or ref to use
      outstream: Output stream (defaults to stdout)
      errstream: Error stream (defaults to stderr)
    N�HEAD)rXr r�object_store�tree�commit_timerB)rs�
committish�	outstream�	errstream�repo_obj�c�chunkr9r9r<�archives

�r�.cCs4t|��}t|�Wd�n1s&0YdS)z]Update server info files for a repository.

    Args:
      repo: path to the repository
    N)rX�server_update_server_info�rs�rr9r9r<r4-s
r4FcCs`t|��D}t|�}|s0||j��vr0td|��|j�d|�Wd�n1sR0YdS)z�Set git symbolic ref into HEAD.

    Args:
      repo: path to the repository
      ref_name: short name of the new ref
      force: force settings without checking if it exists in refs/heads
    zfatal: ref `%s` is not a ref�HEADN)rX�_make_branch_ref�refs�keysrI�set_symbolic_ref)rsZref_name�forcer|Zref_pathr9r9r<�symbolic_ref7s

r�cCs�t|dd�r|�|pt�}t|dd�r4|�|p0t�}t|dd�rN|�|pJt�}t|��$}|j|||||d�Wd�S1s�0YdS)a$Create a new commit.

    Args:
      repo: Path to repository
      message: Optional commit message
      author: Optional author name and email
      committer: Optional committer name and email
      no_verify: Skip pre-commit and commit-msg hooks
    Returns: SHA1 of the new commit
    riN)�message�author�	committer�encoding�	no_verify)�getattrri�DEFAULT_ENCODINGrX�	do_commit)rsr�r�r�r�r�r�r9r9r<�commitFs
�r�cCs>t|��"}|j||||d�Wd�S1s00YdS)z�Create a new commit object.

    Args:
      repo: Path to repository
      tree: An existing tree object
      author: Optional author name and email
      committer: Optional committer name and email
    )r�rwr�r�N)rXr�)rsrwr�r�r�r�r9r9r<�commit_tree`s	
�r�cCs2tj�|�st�|�|r$t�|�St�|�SdS)z�Create a new git repository.

    Args:
      path: Path to repository.
      bare: Whether to create a bare repository.
    Returns: A Repo instance
    N)rarc�exists�mkdirr/�	init_bare�init)rc�barer9r9r<r�ns


r��origincKs�|dur$ddl}	|	jdtdd�|}|dur2|}|rB|rBtd��|durX|�d�d}tj�|�snt�|�|r~t	�
|�}
n
t	�|�}
d	|�d
�}z�|
�
�}t|t�s�|�t�}|�d|fd|�|�d|fd
d|d�|��t|
|f|||d�|��}
z|
|
jd}Wnt�y,d}Yn0|j|
d<|�rn|�sn|du�rn|�d|jd�|
�|j�Wn(t�y�t�|�|
���Yn0|
S)aClone a local or remote git repository.

    Args:
      source: Path or URL for source repository
      target: Path to target repository (optional)
      bare: Whether or not to create a bare repository
      checkout: Whether or not to check-out HEAD after cloning
      errstream: Optional stream to write progress to
      outstream: Optional stream to write progress to (deprecated)
      origin: Name of remote from the repository used to clone
      depth: Depth to fetch at
    Returns: The new repository
    Nrz7outstream= has been deprecated in favour of errstream=.rY)�
stacklevelz"checkout and bare are incompatibler[r7sclone: from rH�remote�urlsfetchs+refs/heads/*:refs/remotes/s/*)r{r��depthr�s
Checking out �
)�warnings�warn�DeprecationWarningrI�splitrarcr�r�r/r�r�ri�
get_configrSr`r��set�
write_to_path�fetchr�rr�idrB�reset_indexrw�
BaseException�shutilZrmtree�close)�source�targetr�Zcheckoutr{rz�originr��kwargsr�r�Zreflog_messageZ
target_config�fetch_result�headr9r9r<�clonesd�




����


r�c	Cs�t�}t|���}t|j���}t�|�}|sTttt	tt
������t	|�|����}g}t
|t�sh|g}|D]:}t	t|����|��}|�|�r�|�|�ql|�|�ql|�|�Wd�n1s�0Y||fS)z�Add files to the staging area.

    Args:
      repo: Repository for the files
      paths: Paths to add.  No value passed stages all modified files.
    Returns: Tuple with set of added files and ignored files
    N)r�rXrrcrlr�	from_repo�list�get_untracked_pathsrnra�getcwd�
open_indexrSrm�
is_ignored�add�appendZstage)	rs�paths�ignoredr�Z	repo_path�ignore_managerZrelpaths�prdr9r9r<r��s,

��


(r�cCs2tj�|�tjj}tj�|�tjj}|�|�S)z�Check whether subdir is parentdir or a subdir of parentdir

        If parentdir or subdir is a relative path, it will be disamgibuated
        relative to the pwd.
    )rarc�realpathrgre)ZsubdirZ	parentdirZ
parentdir_absZ
subdir_absr9r9r<�
_is_subdir�sr�cCs|durt��}t|���}t||j�s.td��|��}|�ddd�}|��}t	�
|�}t||j�}tt
|��D]n\}}	|	r�tt�|��dk}
|
r�t�|�qnt|j|�}||v}tj�||j�}
|�|
�}|sn|snt�|�qnWd�n1s�0YdS)aRemove any untracked files from the target directory recursively

    Equivalent to running `git clean -fd` in target_dir.

    Args:
      repo: Repository where the files may be tracked
      target_dir: Directory to clean - current directory if None
    Nz,target_dir must be in the repo's working dir)scleansrequireForceTr)rar�rXr�rcrI�get_config_stackZget_booleanr�rr��_walk_working_dir_paths�reversedr��len�listdir�rmdirrprdr��remove)rsZ
target_dirr��configZ
require_force�indexr�Zpaths_in_wd�ap�is_dirZis_empty�ipZ
is_trackedZrpr�r9r9r<�clean�s.	
�

r�c
Csbt|���B}|��}|D�]}t�tj�|��}t|j|�}z||j}Wntyht	d|��Yn0|�s.zt�
|�}	Wnty�Yn�0zt||	�}
Wnt
y�Yn|0z t|j||��j|�d}Wnty�d}Yn0|
j|k�r||k�rt	d|��||k�r$t	d|��t�|�||=q|��Wd�n1�sT0YdS)zuRemove files from the staging area.

    Args:
      repo: Repository for the files
      paths: Paths to remove
    z%s did not match any files�NzAfile has staged content differing from both the file and head: %szfile has staged changes: %s)rXr�rarbrcrkrp�sharrrI�lstat�OSErrorr�IOErrorr�__getitem__r�rwr�r�rB)rsr��cachedr�r�r��	full_pathZ	tree_pathZ	index_sha�st�blobZ
committed_shar9r9r<r�!sN
��
��
�
r�cCs$|jr|j�d�}n|}|�|d�S)Nr\rh)r��decode�r��contents�default_encodingr�r9r9r<�
commit_decodeSsr�cCs"|jr|j�d�}n|}|�|�S)Nr\)r�r�rir�r9r9r<�
commit_encode[sr�c	Cs|�d�|�d|j�d�d�t|j�dkr^|�dd�dd	�|jdd
�D��d�|�d||j�d�|j|jkr�|�d||j�d�t�	|j
|j�}t�d
|�}t
|j��d�}|�d|d|d�|�d�|�||j�d�|�d�d
S)z�Write a human-readable commit log entry.

    Args:
      commit: A `Commit` object
      outstream: A stream file to write to
    z3--------------------------------------------------
zcommit: r\�
r�zmerge: z...cSsg|]}|�d��qS)r\�r���.0r}r9r9r<�
<listcomp>o�z print_commit.<locals>.<listcomp>NzAuthor: zCommitter: �%a %b %d %Y %H:%M:%S�Date:   � )rBr�r�r��parents�joinr�r��time�gmtimeZauthor_timeZauthor_timezone�strftimerr�)r�r�rz�
time_tuple�time_str�timezone_strr9r9r<�print_commitcs(
���
r�cCs�|�d||j�d�t�|j|j�}t�d|�}t|j��d�}|�d|d|d�|�d�|�||j	�d�|�d�dS)z�Write a human-readable tag.

    Args:
      tag: A `Tag` object
      decode: Function for decoding bytes to unicode string
      outstream: A stream to write to
    zTagger: r�r�r\r�r�N)
rB�taggerr�r��tag_time�tag_timezoner�rr�r�)�tagr�rzr�r�r�r9r9r<�	print_tag}s
r�cCs|�||j��dS)z�Write a blob to a stream.

    Args:
      repo: A `Repo` object
      blob: A `Blob` object
      decode: Function for decoding bytes to unicode string
      outstream: A stream file to write to
    N)rB�data)rsr�r�rzr9r9r<�	show_blob�s	r�cCsht|||d�|jr*||jd}|j}nd}t�}t||j||j�|�d�|�t||�	���dS)z�Show a commit to a stream.

    Args:
      repo: A `Repo` object
      commit: A `Commit` object
      decode: Function for decoding bytes to unicode string
      outstream: Stream to write to
    )r�rzrN)
r�r�rwrr'rv�seekrBr��getvalue)rsr�r�rzZ
parent_commit�	base_treeZ
diffstreamr9r9r<�show_commit�s	
�
r�cCs |D]}|�||�d�qdS)z�Print a tree to a stream.

    Args:
      repo: A `Repo` object
      tree: A `Tree` object
      decode: Function for decoding bytes to unicode string
      outstream: Stream to write to
    r�N)rB)rsrwr�rz�nr9r9r<�	show_tree�s	r�cCs(t|||�t|||jd||�dS)z�Print a tag to a stream.

    Args:
      repo: A `Repo` object
      tag: A `Tag` object
      decode: Function for decoding bytes to unicode string
      outstream: Stream to write to
    r�N)r��show_object�object)rsr�r�rzr9r9r<�show_tag�s	rcCsttttd�|j||||�S)N)streesblobscommitstag)r�r�r�rZ	type_name)rsrVr�rzr9r9r<r��s���r�ccs�|D]�}|sqt|t�r |d}|jtkr<|jj}d}d}np|jtkrX|jj}d}d}nT|jtkrt|jj}d}d}n8|jt	vr�|jj}|jj}|jt
kr�d}n|jtkr�d}d|||fVqd	S)
z:Print a simple status summary, listing changed files.
    r��A�D�M�R�Cz%-8s%-20s%-20sN)rSr��typer�newrcr�oldrrrr)�changes�changeZpath1Zpath2�kindr9r9r<�print_name_status�s2






r
c	s�t|��d}|j|||d�}|D]>��fdd�}t�j||�|r|�dd�t����D��qWd�n1sr0YdS)aQWrite commit logs.

    Args:
      repo: Path to repository
      paths: Optional set of specific paths to print entries for
      outstream: Stream to write log output to
      reverse: Reverse order in which entries are printed
      name_status: Print name status
      max_entries: Optional maximum number of entries to display
    )�max_entriesr��reversecst�j|�Sr8)r�r���x��entryr9r<r�szlog.<locals>.decodecSsg|]}|d�qS)r�r9)r��liner9r9r<r�r�zlog.<locals>.<listcomp>N)rX�
get_walkerr�r��
writelinesr
r
)	rsr�rzrrZname_statusr��walkerr�r9rr<�log�s
��rcs�|durdg}t|t�s|g}t|��X}|D]B}t||��t�t�rT��fdd�}n�fdd�}t|�||�q,Wd�n1s�0YdS)z�Print the changes in a commit.

    Args:
      repo: Path to repository
      objects: Objects to show (defaults to [HEAD])
      outstream: Stream to write to
      default_encoding: Default encoding to use if none is set in the
        commit
    Nrucst�|��Sr8)r�r�r��or9r<r�szshow.<locals>.decodecs
|���Sr8r�r)r�r9r<r�"s)rSr�rXr!rr�)rsZobjectsrzr�r��	objectishr�r9rr<�shows



rcCs<t|�� }t||j||�Wd�n1s.0YdS)z�Compares the content and mode of blobs found via two tree objects.

    Args:
      repo: Path to repository
      old_tree: Id of old tree
      new_tree: Id of new tree
      outstream: Stream to write to
    N)rXr'rv)rsZold_treeZnew_treerzr�r9r9r<�	diff_tree's	
rcs^t|��B��j�fdd�|D�d�D]}|�|jjd�q$Wd�n1sP0YdS)z�Lists commit objects in reverse chronological order.

    Args:
      repo: Path to repository
      commits: Commits over which to iterate
      outstream: Stream to write to
    csg|]}�|j�qSr9)r�r��r�r9r<r�=r�zrev_list.<locals>.<listcomp>)Zincluder�N)rXrrBr�r�)rsZcommitsrzrr9rr<�rev_list4s
rcOs"ddl}|�dt�t|i|��S)Nrz0tag has been deprecated in favour of tag_create.)r�r�r��
tag_create��argsr�r�r9r9r<r�As
�r�ruc		Cs0t|���}	t|	|�}
|r�t�}|dur6|	�|	���}||_||_||_t|
�|
j	f|_
|durltt���}||_
|dur�d}nt|t�r�t|�}||_|r�ddl}|jdd��$}
|
�|���\|_}Wd�n1s�0Y|	j�|�|j	}n|
j	}||	jt|�<Wd�n1�s"0YdS)a�Creates a tag in git via dulwich calls:

    Args:
      repo: Path to repository
      tag: tag string
      author: tag author (optional, if annotated is set)
      message: tag message (optional)
      annotated: whether to create an annotated tag
      objectish: object the tag should point at, defaults to HEAD
      tag_time: Optional time for annotated tag
      tag_timezone: Optional timezone for annotated tag
      sign: GPG Sign the tag
    NrT)Zarmor)rXr!rZ_get_user_identityr�r�r��namerr�r��intr�r�rSrnrr��gpgZContext�signZ
as_raw_stringZ	signaturervZ
add_objectr��
_make_tag_ref)rsr�r�r�Z	annotatedrr�r�r&r�r�Ztag_objr%r}Z
unused_resultZtag_idr9r9r<r Hs8

�(r cOs"ddl}|�dt�t|i|��S)Nrz4list_tags has been deprecated in favour of tag_list.)r�r�r��tag_listr!r9r9r<�	list_tags}s
�r)cCs@t|��$}t|j�d��}|Wd�S1s20YdS)zfList all tags.

    Args:
      repo: Path to repository
      outstream: Stream to write tags to
    �	refs/tagsN)rX�sortedr�Zas_dict)rsrzr��tagsr9r9r<r(�s
r(cCspt|��T}t|t�r|g}nt|t�r,|}ntd|��|D]}|jt|�=q<Wd�n1sb0YdS)z^Remove a tag.

    Args:
      repo: Path to repository
      name: Name of tag to remove
    zUnexpected tag name type %rN)rXrSr`r�rIr�r'�rsr#r��namesr9r9r<�
tag_delete�s


r/cCsR|dkrtd��t|��&}t||�}|�|j�Wd�n1sD0YdS)z�Reset current HEAD to the specified state.

    Args:
      repo: Path to repository
      mode: Mode ("hard", "soft", "mixed")
      treeish: Treeish to reset to
    Zhardz)hard is the only mode currently supportedN)rIrXr$r�r�)rs�mode�treeishr�rwr9r9r<�reset�s
	

r2)rs�remote_location�returncCsp|��}|durt|�}t|t�r,|��}n|}d|f}d}|�|�r`|��}|�|d�}|}nd}||��fS)Nr��url)r��get_branch_remoterSrnri�has_sectionr��get)rsr3r�Zencoded_location�section�remote_namer5r9r9r<�get_remote_repo�s


r;cslt|���L�t�|�\}}t|fd���i|��\}}	g�i������fdd�}
t|dd�p`t}|�|	�}z|j|	|
�j|j	d�}WnFt
y�}
z.td|d|
jd	�
�|
d
��WYd}
~
n"d}
~
00|�	d|�|�d�|jp�i��D]:\}}|du�r |�	d
||�|�f�q�|�	d|�q�|du�rHt�j|��Wd�n1�s^0YdS)a1Remote push with dulwich via dulwich.client

    Args:
      repo: Path to repository
      remote_location: Location of the remote
      refspecs: Refs to push to remote
      outstream: A stream file to write output
      errstream: A stream file to write errors
      force: Force overwriting refs
    r�c	s���t�j|��d��i}�D]~\}}}|durDt||<d�|<q z�j|}Wntyptd|��Yn0|s�||vr�t�|||�|||<|�|<q |S)N�r�z#No valid ref %s in local repository)�extendr#r�r)rrrIrt)r�Znew_refs�lh�rh�	force_refZlocalsha�r�r��refspecsZremote_changed_refs�
selected_refsr9r<�update_refs�s&
�
�

zpush.<locals>.update_refsr�N)�generate_pack_data�progresszPush to z failed -> r)rLsPush to s
 successful.
sPush of ref %s failed: %s
sRef %s updated
)rXr;r
r�r�r�Zget_urlZ	send_packrErBrrIr"r�riZ
ref_status�items�_import_remote_refsr�)rsr3rBrzr{r�r�r:�clientrcrDZerr_encoding�result�e�ref�errorr9rAr<�push�s\���

�
������
��
rNTc
s<t|����t�|�\}}�dur(dg�g�����fdd�}	t|fd���i|��\}
}|
j|�|j|	d�}�D]Z\}
}}zt��j||j|
�Wn"ty�|r��nt	d��Yn0|j|
�j|<qr�r�|j�dd	�d<�dj
}�j|d
�|du�rt�j||j�Wd�n1�s.0YdS)aPull from remote via dulwich.client

    Args:
      repo: Path to repository
      remote_location: Location of the remote
      refspec: refspecs to fetch
      outstream: A stream file to write to output
      errstream: A stream file to write to errors
    Nr�cs,��t��j��d����fdd��D�S)Nr<cs(g|] \}}}�|�jvr�|�qSr9)rv)r�r>r?r@)r��remote_refsr9r<r�0s�z1pull.<locals>.determine_wants.<locals>.<listcomp>)r=r#r��rO�r�r�rBrCrPr<�determine_wants-s��zpull.<locals>.determine_wantsr�)rFrRzmerge is not yet supportedrr�)rw)
rXr;r
r�r�rBrtr�rq�NotImplementedErrorrwr�rH)rsr3rBrzr{Zfast_forwardr�r�r:rRrIrcr�r>r?r@rwr9rQr<�pulls@���

��

rTc
s�t|���}t|�}|��}|��}|j}tt||j|��}t�	|��t
|j|j|�}|rbt|�}	n�fdd�|D�}	t|||	�Wd�S1s�0YdS)a�Returns staged, unstaged, and untracked changes relative to the HEAD.

    Args:
      repo: Path to repository or repository object
      ignored: Whether to include ignored files in `untracked`
    Returns: GitStatus tuple,
        staged -  dict with lists of staged paths (diff index/HEAD)
        unstaged -  list of unstaged paths (diff index/working-tree)
        untracked - list of untracked, un-ignored & non-.git paths
    csg|]}��|�s|�qSr9)r�)r�r��r�r9r<r�es
�zstatus.<locals>.<listcomp>N)rX�get_tree_changesr�Zget_blob_normalizerZcheckin_normalizer�rrcrr�r�r5)
rsr�r��tracked_changesr�Z
normalizerZfilter_callbackZunstaged_changesZuntracked_pathsZuntracked_changesr9rUr<�statusKs 
�


�rXccs�t�|�D]v\}}}d|vr0|�d�||kr0q
d|vrL|�d�||krLq
||kr^|dfV|D]}tj�||�}|dfVqbq
dS)z�Get path, is_dir for files in working dir from frompath

    Args:
      frompath: Path to begin walk
      basepath: Path to compare to
    z.gitTFN)ra�walkr�rcr�)�frompath�basepath�dirpathZdirnames�	filenames�filename�filepathr9r9r<r�ks


r�ccs>t||�D].\}}|s
t||�}||vr
tj�||�Vq
dS)z�Get untracked paths.

    Args:
    ;param frompath: Path to walk
      basepath: Path to compare to
      index: Index to check against
    N)r�rprarcrd)rZr[r�r�r�r�r9r9r<r��s

r�c	Cs�t|���}|��}gggd�}z|dj}WntyBd}Yn0|�|j|�D]�}|ddsz|d�|dd�qR|dds�|d�|dd�qR|dd|ddkr�|d�|dd�qRtd	��qR|Wd�S1s�0YdS)
z�Return add/delete/modify changes to tree by comparing index to HEAD.

    Args:
      repo: repo path or object
    Returns: dict with lists for each type of change
    )r��delete�modifyr�Nrr�r�r`razgit mv ops not yet supported)rXr�rwrrZchanges_from_treervr�rS)rsr�r�rWZtree_idrr9r9r<rV�s&
�

rVcCs t|�}t|||�}|��dS)z�Run a daemon serving Git requests over TCP/IP.

    Args:
      path: Path to the directory to serve.
      address: Optional address to listen on (defaults to ::)
      port: Optional port to listen on (defaults to TCP_GIT_PORT)
    N)r0r1�
serve_forever)rc�address�port�backend�serverr9r9r<�daemon�s	rgc
CsFddlm}m}m}m}t|�}||�}||||||d�}	|	��dS)z�Run a daemon serving Git requests over HTTP.

    Args:
      path: Path to the directory to serve
      address: Optional address to listen on (defaults to ::)
      port: Optional port to listen on (defaults to 80)
    r)�make_wsgi_chain�make_server�WSGIRequestHandlerLogger�WSGIServerLogger)Z
handler_classZserver_classN)Zdulwich.webrhrirjrkr0rb)
rcrcrdrhrirjrkreZapprfr9r9r<�
web_daemon�s�rlcsv�durttjdtj��|dur0ttjdtj�}tj�|�}t|�}�fdd�}t|j	|�}t
||g|�}|��dS)z�Upload a pack file after negotiating its contents using smart protocol.

    Args:
      path: Path to the repository
      inf: Input stream to communicate with client
      outf: Output stream to communicate with client
    NrGcs��|����dSr8�rB�flush�r���outfr9r<�send_fn�s
zupload_pack.<locals>.send_fnr)r�r^�stdout�stdinrarc�
expanduserr0r(r=r3�handle�rc�infrqrerr�protoZhandlerr9rpr<�upload_pack�srzcsv�durttjdtj��|dur0ttjdtj�}tj�|�}t|�}�fdd�}t|j	|�}t
||g|�}|��dS)z�Receive a pack file after negotiating its contents using smart protocol.

    Args:
      path: Path to the repository
      inf: Input stream to communicate with client
      outf: Output stream to communicate with client
    NrGcs��|����dSr8rmrorpr9r<rrs
zreceive_pack.<locals>.send_fnr)r�r^rsrtrarcrur0r(r=r2rvrwr9rpr<�receive_pack�sr{cCst|dd�r|�t�}t|S)Nri)r�rir�r+�r#r9r9r<r�
s
r�cCst|dd�r|�t�}d|S)Nri�
refs/tags/)r�rir�r|r9r9r<r's
r'cCsXt|��<}t|t�r|}n|g}|D]}|jt|�=q$Wd�n1sJ0YdS)zbDelete a branch.

    Args:
      repo: Path to the repository
      name: Name of the branch
    N)rXrSr�r�r�r-r9r9r<�
branch_deletes

r~cCs�t|��x}|durd}t||�}t|�}d|�d�}|rR|jj|d|j|d�n |jj||j|d�srtd|��Wd�n1s�0YdS)z�Create a branch.

    Args:
      repo: Path to the repository
      name: Name of the new branch
      objectish: Target object to point new branch at (defaults to HEAD)
      force: Force creation of branch, even if it already exists
    Nrusbranch: Created from rH)r�z#Branch with name %s already exists.)	rXr!r�rir�Z
set_if_equalsr�Z
add_if_newrI)rsr#rr�r�r�ZrefnameZref_messager9r9r<�
branch_create)s	

�rcCs:t|��}|jjtd�Wd�S1s,0YdS)zEList all branches.

    Args:
      repo: Path to the repository
    )�baseN)rXr�r�r+r�r9r9r<�branch_list@s
r�cCsbt|��F}|j�d�dd}|�t�s0t|��|tt�d�Wd�S1sT0YdS)z�Return the active branch in the repository, if any.

    Args:
      repo: Repository to open
    Returns:
      branch name
    Raises:
      KeyError: if the repository does not have a working tree
      IndexError: if HEAD is floating
    r�rr�N)rXr�Zfollowrer+rfr�)rsr�Z
active_refr9r9r<�
active_branchJs


r�c	Csjt|��N}t|j�}|��}z|�d|fd�}WntyFd}Yn0Wd�n1s\0Y|S)z�Return the active branch's remote name, if any.

    Args:
      repo: Repository to open
    Returns:
      remote name
    Raises:
      KeyError: if the repository does not have a working tree
    sbranchr�r�N)rXr�rcr�r8rr)rsr�Zbranch_namer�r:r9r9r<r6\s


(r6)�refs_containerr:r�r��prune�
prune_tagsc	Cs\t|�}dd�|��D�}|jd|��|||d�dd�|��D�}|jd|||d�dS)NcSs,i|]$\}}|�t�r|tt�d�|�qSr8)rer+r��r�r��vr9r9r<�
<dictcomp>us
�z'_import_remote_refs.<locals>.<dictcomp>s
refs/remotes/)r�r�cSs6i|].\}}|�d�r|�t�s|td�d�|�qS)r}N)re�endswithr*r�r�r9r9r<r�{s

�r*)r,rGZimport_refsri)	r�r:r�r�r�r�Z
stripped_refsZbranchesr,r9r9r<rHps����rHc		Ks�t|���}
t|
|�\}}|dur.d|�d�}t|fd|
��i|	��\}}
|j|
|
|j|d�}|dur~t|
j||j|||d�Wd�n1s�0Y|S)a�Fetch objects from a remote server.

    Args:
      repo: Path to the repository
      remote_location: String identifying a remote server
      outstream: Output stream (defaults to stdout)
      errstream: Error stream (defaults to stderr)
      message: Reflog message (defaults to b"fetch: from <remote_name>")
      depth: Depth to fetch at
      prune: Prune remote removed refs
      prune_tags: Prune reomte removed tags
    Returns:
      Dictionary with refs on the remote
    Nsfetch: from rHr�)rFr�)r�r�)	rXr;rir
r�r�rBrHr�)rsr3rzr{r�r�r�r�r�r�r�r:rIrcr�r9r9r<r��s(
���
��$r�cKs2|durt��}t|fd|i|��\}}|�|�S)z�List the refs in a remote.

    Args:
      remote: Remote repository location
      config: Configuration to use
    Returns:
      Dictionary with remote refs
    Nr�)r�defaultr
�get_refs)Zremoter�r�rIZ	host_pathr9r9r<�	ls_remote�s	r�cCs6t|��}|j��Wd�n1s(0YdS)z�Repack loose files in a repository.

    Currently this only packs loose objects.

    Args:
      repo: Path to the repository
    N)rXrvZpack_loose_objectsr�r9r9r<�repack�s
r�cCszt|��4}t||j�dd�|D��|d�\}}Wd�n1sB0Y|durvtdd�|��D��}t|||�dS)z�Pack objects into a file.

    Args:
      repo: Path to the repository
      object_ids: List of object ids to write
      packf: File-like object to write to
      idxf: File-like object to write to (can be None)
    css|]}|dfVqdSr8r9)r�Zoidr9r9r<�	<genexpr>�r�zpack_objects.<locals>.<genexpr>)�delta_window_sizeNcSs"g|]\}}||d|df�qS)rr�r9)r��kr�r9r9r<r��r�z pack_objects.<locals>.<listcomp>)rXr&rvZ	iter_shasr+rGr%)rsZ
object_idsZpackfZidxfr�r��entriesZdata_sumr9r9r<�pack_objects�s	
�(r�r�csX����fdd��t|��*}t||�}�|j|jd�Wd�n1sJ0YdS)z�List contents of a tree.

    Args:
      repo: Path to the repository
      tree_ish: Tree id to list
      outstream: Output stream (defaults to stdout)
      recursive: Whether to recursively list files
      name_only: Only print item name
    csl||��D]Z\}}}|r&t�||�}�r:��|d�n��t|||��t�|�r�r�|||�qdS)Nr�)Z	iteritems�	posixpathr�rBr�stat�S_ISDIR)ZstoreZtreeidr�r#r0r���	list_tree�	name_onlyrz�	recursiver9r<r��szls_tree.<locals>.list_treerN)rXr$rvr�)rsr1rzr�r�r�rwr9r�r<�ls_tree�s


r�cCs�t|t�s|�t�}t|t�s(|�t�}t|��H}|��}d|f}|�|�rTt|��|�|d|�|�	�Wd�n1s~0YdS)znAdd a remote.

    Args:
      repo: Path to the repository
      name: Remote name
      url: Remote URL
    r�r�N)
rSr`rir�rXr�r7rQr�r�)rsr#r5r�r}r9r9r9r<�
remote_add�s





r�ccs�t|��n}|��}t�|�}|D]F}|s:t|j|�|vr:q tj�|�rVtj�||j�}|�	|�r |Vq Wd�n1s|0YdS)z�Debug gitignore files.

    Args:
      repo: Path to the repository
      paths: List of paths to check for
      no_index: Don't check index
    Returns: List of ignored files
    N)
rXr�rr�rprcra�isabsrdr�)rsr�Zno_indexr�r�r�rcr9r9r<�check_ignores	


r�cCs�t|��p}|durt|�}nd}|r@|j|=t||�j|j|<n|j�|t||��|durj|j�d|�Wd�n1s~0YdS)aUpdate HEAD to point at a new branch/commit.

    Note that this does not actually update the working tree.

    Args:
      repo: Path to the repository
      detach: Create a detached head
      target: Branch or committish to switch to
      new_branch: New branch to create
    Nr�)rXr�r�r r�r�r")rsr�ZdetachedZ
new_branchr�Zto_setr9r9r<�update_heads

r�c	Csvt|��Z}ddlm}z|�tj�|jd��}WntyH|�}Yn0|�|�Wd�S1sh0YdS)z�Check canonical name and email of contact.

    Args:
      repo: Path to the repository
      contact: Contact name and/or email
    Returns: Canonical contact data
    r)�Mailmapz.mailmapN)	rXZdulwich.mailmapr�Z	from_pathrarcr��FileNotFoundError�lookup)rsZcontactr�r�Zmailmapr9r9r<�
check_mailmap3s
r�ccs~t|��b}|jD]J}|j|}z|��WqtyX}z||fVWYd}~qd}~00qWd�n1sp0YdS)zsCheck a repository.

    Args:
      repo: A path to the repository
    Returns: Iterator over errors/warnings
    N)rXrvZcheck�	Exception)rsr�r�rrKr9r9r<�fsckDs


r�cCsRt|��6}ddlm}|�|�}tt|����Wd�S1sD0YdS)z!List all stashes in a repository.r��StashN)rX�
dulwich.stashr�r��	enumerater�Zstashes�rsr�r�Zstashr9r9r<�
stash_listWs

r�cCsJt|��.}ddlm}|�|�}|��Wd�n1s<0YdS)z Push a new stash onto the stack.rr�N)rXr�r�r�rNr�r9r9r<�
stash_push_s

r�cCsJt|��.}ddlm}|�|�}|��Wd�n1s<0YdS)zPop a new stash from the stack.rr�N)rXr�r�r��popr�r9r9r<�	stash_popgs

r�cCs8t|��}t|���Wd�S1s*0YdS)zList all files in an index.N)rXr+r�r�r9r9r<�ls_filesos
r�c
Cs�t|����}|��}i}|��D]�\}}|��}|�|�}d|vrDq |�dd�\}}z
|j}	WntytYq Yn0|�|	d�}	tjt	�
|	j�dd��|	j�d�g||<q t
|��dd�d	d
�}
t|
�dk�rd�||��j�d�dd
��Wd�Sd}||��}|��}
|
D]�}|jj�d�}|
D]|}|d}|dd}||k�r6|dk�r||Wd�Sd�|||j�d�dd
��Wd�S�q6|d7}�q d�|j�d�dd
��Wd�S1�s�0YdS)z�Describe the repository version.

    Args:
      projdir: git repository root
    Returns: a string description of the current git revision

    Examples: "gabcdefh", "v0.1" or "v0.1-5-gabcdefh".
    r,r[r�NrZr\cSs|ddS)Nr�rr9)r�r9r9r<�<lambda>�r�zdescribe.<locals>.<lambda>T)�keyrrzg{}�z	{}-{}-g{})rXr�rGr�Z
get_object�rsplitr��AttributeError�datetimer�r�rxr�r+r��formatr�rr�)rsr�r�r,r��valuerV�_r�r�Zsorted_tagsZcommit_countZ
latest_commitrrZ	commit_idZtag_nameZ
tag_commitr9r9r<�describeusR




�
�0

�r�cCsx|durd}t|��P}t||�}|j}t|t�s:t||�}t|jj||�\}}||Wd�S1sj0YdS)z�Get an object by path.

    Args:
      repo: A path to the repository
      path: Path to look up
      committish: Commit to look up path in
    Returns: A `ShaFile` object
    Nru)	rXr rwrSr`r�rrvr�)rsrcryr�r�r�r0r�r9r9r<�get_object_by_path�s	



�r�cCs<t|�� }|���|j�Wd�S1s.0YdS)z�Write a tree object from the index.

    Args:
      repo: Repository for which to write tree
    Returns: tree id for the tree that was written
    N)rXr�r�rvr�r9r9r<�
write_tree�s
r�)r�)F)r�NNNNF)NNN)r�F)r�N)r�N)r�NF)NNFruNNF)ru)N)r�F)r�NN)r�NN)r�NN)r�NN)NF)NFF)N)N)F)FN)N)�rF�collectionsr�
contextlibrr�iorrr�ra�pathlibrr�r�r�r^r��typingrr	r
rZdulwich.archiverZdulwich.clientr
Zdulwich.configrZdulwich.diff_treerrrrrrZdulwich.errorsrZ
dulwich.graphrZdulwich.ignorerZ
dulwich.indexrrZdulwich.object_storerZdulwich.objectsrrrrrZdulwich.objectspecr r!r"r#r$Zdulwich.packr%r&Z
dulwich.patchr'Zdulwich.protocolr(r)Zdulwich.refsr*r+r,r-Zdulwich.repor.r/Zdulwich.serverr0r1r2r3r4r�r5r6r�rsZdefault_bytes_out_stream�stderrZdefault_bytes_err_streamr�r�rIrQrUrWrXrprqrtrr�r�r�r�r�r�r�r�r�Zrmr�r�r�r�r�r�r�rr�r
rrrrr�r r)r(r/r2rnr`r;rNrTrXr�r�rVrgrlrzr{r�r'r~rr�r�r6�boolrHr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r9r9r9r<�<module>s.& 

��

/�



�


�
H

/
/

	
�
�


�
5
���
K�
3
 #





��
�
!

�


F