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__/repo.cpython-39.pyc
a

3k�_!��@s�dZddlmZddlZddlZddlZddlZddlmZm	Z	m
Z
mZmZm
Z
mZe
rtddlmZmZddlmZddlmZmZmZmZmZmZmZmZmZddlmZdd	l m!Z!m"Z"m#Z#m$Z$dd
l%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,ddl-m.Z.ddl/m0Z0m1Z1m2Z2m3Z3m4Z4dd
l5m6Z6ddl7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z?m@Z@mAZAddlBZBdZCdZDdZEdZFdZGdZHdZIdZJdZKdgeEgeEeFgeEeGgdgdggZLdZMGdd�deN�ZOe	ePePfd�dd �ZQd:d!eePeRd"�d#d$�ZSd%d&�ZTeeReeReeRfd'�d(d)�ZUeeReeRfeRd'�d*d+�ZVd,d-�ZWGd.d/�d/eX�ZYGd0d1�d1eX�ZZd2d3�Z[Gd4d5�d5eN�Z\Gd6d7�d7eZ�Z]Gd8d9�d9eZ�Z^dS);z�Repository access.

This module contains the base class for git repositories
(BaseRepo) and an implementation which uses a repository on
local disk (Repo).

�)�BytesION)�Optional�Tuple�
TYPE_CHECKING�List�Dict�Union�Iterable)�
StackedConfig�
ConfigFile��Index)	�NoIndexPresent�NotBlobError�NotCommitError�NotGitRepository�NotTreeError�NotTagError�CommitError�RefFormatError�	HookError)�GitFile)�DiskObjectStore�MemoryObjectStore�BaseObjectStore�ObjectStoreGraphWalker)�check_hexsha�valid_hexsha�Blob�Commit�ShaFile�Tag�Tree)�pack_objects_to_data)�Hook�PreCommitShellHook�PostCommitShellHook�CommitMsgShellHook�PostReceiveShellHook)�BlobNormalizer)
�ANNOTATED_TAG_SUFFIX�check_ref_format�
RefsContainer�DictRefsContainer�InfoRefsContainer�DiskRefsContainer�read_packed_refs�read_packed_refs_with_peeled�write_packed_refs�SYMREFz.git�objects�refsZtags�heads�index�	commondirZgitdirZ	worktreesZbranches�hooks�infosrefs/heads/masterc@seZdZdZdd�ZdS)�InvalidUserIdentityz1User identity is not of the format 'user <email>'cCs
||_dS�N)�identity)�selfr=�r?�./usr/lib/python3/dist-packages/dulwich/repo.py�__init__�szInvalidUserIdentity.__init__N��__name__�
__module__�__qualname__�__doc__rAr?r?r?r@r;sr;��returncCs�ddl}ddl}|��}zddl}Wnty:d}Yn80z|�|�j}Wntybd}Yn0|�d�d}|sz|}t	j
�d�}|dur�d�||�
��}||fS)Nr�,ZEMAILz{}@{})�getpass�socketZgetuser�pwd�ImportError�getpwnamZpw_gecos�KeyError�split�os�environ�get�formatZgethostname)rJrKZusernamerL�fullnameZgecos�emailr?r?r@�_get_default_identity�s$

rWr
��config�kindrHcCsd}d}|rXtj�d|d�}|dur2|�d�}tj�d|d�}|durX|�d�}|dur�z|�dd�}Wnty�d}Yn0|dur�z|�dd�}Wnty�d}Yn0t�\}}|dur�|�d�}|dur�|�d�}|�d	��r
|�d
��r
|dd�}|d
|d
S)aaDetermine the identity to use for new commits.

    If kind is set, this first checks
    GIT_${KIND}_NAME and GIT_${KIND}_EMAIL.

    If those variables are not set, then it will fall back
    to reading the user.name and user.email settings from
    the specified configuration.

    If that also fails, then it will fall back to using
    the current users' identity as obtained from the host
    system (e.g. the gecos field, $EMAIL, $USER@$(hostname -f).

    Args:
      kind: Optional kind to return identity for,
        usually either "AUTHOR" or "COMMITTER".

    Returns:
      A user identity
    NZGIT_Z_NAME�utf-8Z_EMAIL)�user�namerV�<�>����� <)rQrRrS�encoderOrW�
startswith�endswith)rYrZr\rVZuser_ucZemail_ucZdefault_userZ
default_emailr?r?r@�get_user_identity�s6






rfcCsDz|�dd�\}}Wnty.t|��Yn0d|vr@t|��dS)z�Verify that a user identity is formatted correctly.

    Args:
      identity: User identity bytestring
    Raises:
      InvalidUserIdentity: Raised when identity is invalid
    rbr`r_N)rP�
ValueErrorr;)r=ZfstZsndr?r?r@�check_user_identity�srh)�graftpointsrHcCsfi}|D]X}|�dd�}|d}t|�dkr:|d��}ng}|g|D]}t|d�qH|||<q|S)a:Convert a list of graftpoints into a dict

    Args:
      graftpoints: Iterator of graftpoint lines

    Each line is formatted as:
        <commit sha1> <parent sha1> [<parent sha1>]*

    Resulting dictionary is:
        <commit sha1>: [<parent sha1>*]

    https://git.wiki.kernel.org/index.php/GraftPoint
    Nr`r��Invalid graftpoint)rP�lenr)ri�grafts�lineZ	raw_graft�commit�parents�shar?r?r@�parse_graftpoints�s
rrcCsHg}|��D]0\}}|r2|�|dd�|��q|�|�qd�|�S)aConvert a dictionary of grafts into string

    The graft dictionary is:
        <commit sha1>: [<parent sha1>*]

    Each line is formatted as:
        <commit sha1> <parent sha1> [<parent sha1>]*

    https://git.wiki.kernel.org/index.php/GraftPoint

    � �
)�items�append�join)riZgraft_linesrorpr?r?r@�serialize_graftpointssrxcCsftjdkrbddl}ddlm}m}m}d}|�|||�d|jj	f�}t
|t�rXt�
|�}|||�sbdS)z�Mark path as to be hidden if supported by platform and filesystem.

    On win32 uses SetFileAttributesW api:
    <https://docs.microsoft.com/windows/desktop/api/fileapi/nf-fileapi-setfileattributesw>
    �win32rN)�BOOL�DWORD�LPCWSTRrj�SetFileAttributesW)�sys�platform�ctypesZctypes.wintypesrzr{r|ZWINFUNCTYPEZwindllZkernel32�
isinstance�bytesrQ�fsdecode)�pathr�rzr{r|�FILE_ATTRIBUTE_HIDDENr}r?r?r@�_set_filesystem_hiddens

�


r�c@s$eZdZigfdd�Zddd�ZdS)�ParentsProvidercCs||_||_t|�|_dSr<)�storerm�set�shallows)r>r�rmr�r?r?r@rA.szParentsProvider.__init__NcCsFz|j|WStyYn0||jvr.gS|dur@|j|}|jSr<)rmrOr�r�rp)r>Z	commit_idror?r?r@�get_parents3s

zParentsProvider.get_parents)N)rCrDrErAr�r?r?r?r@r�,sr�c@s�eZdZdZeed�dd�Zed�dd�Zedd	�d
d�Z	dd
�Z
dd�Zdd�Zdd�Z
dWdd�ZdXdd�ZdYdd�ZdZdd�Zd[dd�Zeeefd�dd�Zed�d d!�Zd"d#�Zeed$�d%d&�Zd'd(�Zd\eeeed)�d*d+�Zd,d-�Zd.d/�Zd0d1�Z d2d�d3d4�Z!d5d6�Z"d7d8�Z#d9d:�Z$d]d;d<�Z%d=d>�Z&eed?�d@dA�Z'ee(eefdB�dCdD�Z)edE�dFdG�Z*d^d2e+edH�dIdJ�Z,eeeefdK�dLdM�Z-gfeeddN�dOdP�Z.dQdR�Z/d_dUdV�Z0dS)`�BaseRepoz�Base class for a git repository.

    :ivar object_store: Dictionary-like object for accessing
        the objects
    :ivar refs: Dictionary-like object with the refs in this
        repository
    )�object_storer5cCs||_||_i|_i|_dS)z�Open a repository.

        This shouldn't be called directly, but rather through one of the
        base classes, such as MemoryRepo or Repo.

        Args:
          object_store: Object store to use
          refs: Refs container to use
        N)r�r5�_graftpointsr9)r>r�r5r?r?r@rAHs
zBaseRepo.__init__rGcCst|j��dS)��Probe the file-system to determine whether permissions can be trusted.

        Returns: True if permissions can be trusted, False otherwise.
        N)�NotImplementedError�_determine_file_mode�r>r?r?r@r�XszBaseRepo._determine_file_modeN)�barerHcCs�ddlm}|�dd�t�}|�}|�ddd�|��rJ|�ddd	�n|�ddd
�|�dd|�|�ddd	�|�|�|�d
|���|�tj	�
dd�d�dS)z(Initialize a default set of named files.r�r�descriptionsUnnamed repository�core�repositoryformatversion�0�filemodeTFr�ZlogallrefupdatesrYr:Zexclude�N)�dulwich.configr�_put_named_filerr�r�Z
write_to_file�getvaluerQr�rw)r>r�r�fZcfr?r?r@�_init_files_s
zBaseRepo._init_filescCst|j��dS)a�Get a file from the control dir with a specific name.

        Although the filename should be interpreted as a filename relative to
        the control dir in a disk-based Repo, the object returned need not be
        pointing to a file in that location.

        Args:
          path: The path to the file, relative to the control dir.
        Returns: An open file object, or None if the file does not exist.
        N)r��get_named_file�r>r�r?r?r@r�qszBaseRepo.get_named_filecCst|j��dS���Write a file to the control dir with the given name and contents.

        Args:
          path: The path to the file, relative to the control dir.
          contents: A string to write to the file.
        N)r�r��r>r��contentsr?r?r@r�~szBaseRepo._put_named_filecCst|j��dS)z:Delete a file in the contrl directory with the given name.N)r��_del_named_filer�r?r?r@r��szBaseRepo._del_named_filecCst|j��dS)��Open the index for this repository.

        Raises:
          NoIndexPresent: If no index is present
        Returns: The matching `Index`
        N)r��
open_indexr�r?r?r@r��szBaseRepo.open_indexcCsB|dur|jj}|j||��||d�\}}|j�|||�|��S)a=Fetch objects into another repository.

        Args:
          target: The target repository
          determine_wants: Optional function to determine what refs to
            fetch.
          progress: Optional progress function
          depth: Optional shallow fetch depth
        Returns: The local refs
        N)�progress�depth)r�Zdetermine_wants_all�fetch_pack_data�get_graph_walkerZ
add_pack_data�get_refs)r>�target�determine_wantsr�r��countZ	pack_datar?r?r@�fetch�s
�
zBaseRepo.fetchcCs|j|||||d�}t|�S)a�Fetch the pack data required for a set of revisions.

        Args:
          determine_wants: Function that takes a dictionary with heads
            and returns the list of heads to fetch.
          graph_walker: Object that can iterate over the list of revisions
            to fetch and has an "ack" method that will be called to acknowledge
            that a revision is present.
          progress: Simple progress function that will be called with
            updated progress strings.
          get_tagged: Function that returns a dict of pointed-to sha ->
            tag sha for including tags.
          depth: Shallow fetch depth
        Returns: count and iterator over pack data
        )r�)�
fetch_objectsr#)r>r��graph_walkerr��
get_taggedr�r4r?r?r@r��s
�zBaseRepo.fetch_pack_datacs:|dvrtd��i}|����D]t\}}z|j|}	Wn8tynt�d|�dd�|�d�ft�Yq Yq 0t	|	t
�r�|	jd||t<|||<q ||�}
t	|
t
�s�td��t|d	t��}t|d
t��}|
gkr�|s�|r�dSgS|j�|�}
|s�|r�g}
t|j|d���fd
d�}|j�|jj|
|
|��|||d��S)a�Fetch the missing objects required for a set of revisions.

        Args:
          determine_wants: Function that takes a dictionary with heads
            and returns the list of heads to fetch.
          graph_walker: Object that can iterate over the list of revisions
            to fetch and has an "ack" method that will be called to acknowledge
            that a revision is present.
          progress: Simple progress function that will be called with
            updated progress strings.
          get_tagged: Function that returns a dict of pointed-to sha ->
            tag sha for including tags.
          depth: Shallow fetch depth
        Returns: iterator over objects, with __len__ implemented
        )Nrzdepth not supported yetz#ref %s points at non-present sha %sr[�replace�asciir`z'determine_wants() did not return a list�shallowZ	unshallowN)r�cs��|j|�Sr<�r��id�ro��parents_providerr?r@r�sz+BaseRepo.fetch_objects.<locals>.get_parents)r�)r�r�rur�rO�warnings�warn�decode�UserWarningr�r!�objectr*�list�	TypeError�getattr�	frozensetZfind_common_revisionsr�Z	iter_shasZfind_missing_objects�get_shallow)r>r�r�r�r�r�r5�refrq�objZwantsr�Z
unshallowsZhavesr�r?r�r@r��sP��



�
��zBaseRepo.fetch_objectscCs|jj|||��||d�S)a9Generate pack data objects for a set of wants/haves.

        Args:
          have: List of SHA1s of objects that should not be sent
          want: List of SHA1s of objects that should be sent
          ofs_delta: Whether OFS deltas can be included
          progress: Optional progress reporting method
        )r�r��	ofs_delta)r��generate_pack_datar�)r>ZhaveZwantr�r�r?r?r@r�	s	
�zBaseRepo.generate_pack_datacsD|dur&�fdd��j�d���D�}t�j�}t||j���d�S)aRetrieve a graph walker.

        A graph walker is used by a remote repository (or proxy)
        to find out which objects are present in this repository.

        Args:
          heads: Repository heads to use (optional)
        Returns: A graph walker object
        Ncsg|]}|�jvr|�qSr?�r���.0rqr�r?r@�
<listcomp>!s
�z-BaseRepo.get_graph_walker.<locals>.<listcomp>�
refs/heads)r�)r5�as_dict�valuesr�r�rr�r�)r>r6r�r?r�r@r�s

�
�zBaseRepo.get_graph_walkercCs
|j��S)z^Get dictionary with all refs.

        Returns: A ``dict`` mapping ref names to SHA1s
        )r5r�r�r?r?r@r�(szBaseRepo.get_refscCs
|jdS)z#Return the SHA1 pointed at by HEAD.�HEAD)r5r�r?r?r@�head/sz
BaseRepo.headcCs�t|�dvsJ�|�|�}t||�s�|tur6t|��nJ|turHt|��n8|turZt|��n&|t	urlt
|��ntd|j|jf��|S)N���(zType invalid: %r != %r)
rl�
get_objectr�rrrrr"rr!r�	ExceptionZ	type_name)r>rq�cls�retr?r?r@�_get_object3s





�zBaseRepo._get_object)rqrHcCs
|j|S)z�Retrieve the object with the specified SHA.

        Args:
          sha: SHA to retrieve
        Returns: A ShaFile object
        Raises:
          KeyError: when the object can not be found
        r�)r>rqr?r?r@r�Ds	zBaseRepo.get_objectcCst|j|j|��d�S)N)rmr�)r�r�r�r�r�r?r?r@r�Os�zBaseRepo.parents_provider)rqrorHcCs|���||�S)a>Retrieve the parents of a specific commit.

        If the specific commit is a graftpoint, the graft parents
        will be returned instead.

        Args:
          sha: SHA of the commit for which to retrieve the parents
          commit: Optional commit matching the sha
        Returns: List of parents
        )r�r�)r>rqror?r?r@r�TszBaseRepo.get_parentscCst|j��dS)�hRetrieve the config object.

        Returns: `ConfigFile` object for the ``.git/config`` file.
        N)r��
get_configr�r?r?r@r�aszBaseRepo.get_configcCst|j��dS)z�Retrieve the description for this repository.

        Returns: String with the description of the repository
            as set by the user.
        N)r��get_descriptionr�r?r?r@r�hszBaseRepo.get_descriptioncCst|j��dS)��Set the description for this repository.

        Args:
          description: Text to set as description for this repository.
        N)r��set_description�r>r�r?r?r@r�pszBaseRepo.set_descriptionr
cCs.ddlm}|��g|��}|||dd�S)aReturn a config stack for this repository.

        This stack accesses the configuration for both this repository
        itself (.git/config) and the global configuration, which usually
        lives in ~/.gitconfig.

        Returns: `Config` instance for this repository
        r)r
)�writable)r�r
r�Zdefault_backends)r>r
Zbackendsr?r?r@�get_config_stackxs	zBaseRepo.get_config_stackcCsR|�d�}|durt�S|�"tdd�|D��Wd�S1sD0YdS)zRGet the set of shallow commits.

        Returns: Set of shallow commits.
        r�Ncss|]}|��VqdSr<��strip�r�rnr?r?r@�	<genexpr>�r�z'BaseRepo.get_shallow.<locals>.<genexpr>)r�r�)r>r�r?r?r@r��s

zBaseRepo.get_shallowcCsD|��}|r|�|�|r$|�|�|�dd�dd�|D���dS)z�Update the list of shallow objects.

        Args:
          new_shallow: Newly shallow objects
          new_unshallow: Newly no longer shallow objects
        r�r�cSsg|]}|d�qS)rtr?r�r?r?r@r��r�z+BaseRepo.update_shallow.<locals>.<listcomp>N)r��update�difference_updater�rw)r>Znew_shallowZ
new_unshallowr�r?r?r@�update_shallow�s

�zBaseRepo.update_shallowcCs,|j�|�}|dur|S|j�|j|�jS)aGet the peeled value of a ref.

        Args:
          ref: The refname to peel.
        Returns: The fully-peeled SHA1 of a tag object, after peeling all
            intermediate tags; if the original ref does not point to a tag,
            this will equal the original SHA1.
        N)r5�
get_peeledr�Zpeel_shar�)r>r��cachedr?r?r@r��s	zBaseRepo.get_peeledcsXddlm}|dur���g}t|t�r.|g}�fdd�|d<|�j|g|�Ri|��S)a�Obtain a walker for this repository.

        Args:
          include: Iterable of SHAs of commits to include along with their
            ancestors. Defaults to [HEAD]
          exclude: Iterable of SHAs of commits to exclude along with their
            ancestors, overriding includes.
          order: ORDER_* constant specifying the order of results.
            Anything other than ORDER_DATE may result in O(n) memory usage.
          reverse: If True, reverse the order of output, requiring O(n)
            memory.
          max_entries: The maximum number of entries to yield, or None for
            no limit.
          paths: Iterable of file or subtree paths to show entries for.
          rename_detector: diff.RenameDetector object for detecting
            renames.
          follow: If True, follow path across renames/copies. Forces a
            default rename_detector.
          since: Timestamp to list commits after.
          until: Timestamp to list commits before.
          queue_cls: A class to use for a queue of commits, supporting the
            iterator protocol. The constructor takes a single argument, the
            Walker.
        Returns: A `Walker` object
        r)�WalkerNcs��|j|�Sr<r�r�r�r?r@�<lambda>�s�z%BaseRepo.get_walker.<locals>.<lambda>r�)Zdulwich.walkr�r�r��strr�)r>Zinclude�args�kwargsr�r?r�r@�
get_walker�s

zBaseRepo.get_walkerc	Cs~t|t�stdt|�j��t|�dvrLz|j|WSttfyJYn0z|j|j	|WSt
yxt|��Yn0dS)z�Retrieve a Git object by SHA1 or ref.

        Args:
          name: A Git object SHA1 or a ref name
        Returns: A `ShaFile` object, such as a Commit or Blob
        Raises:
          KeyError: when the specified ref or object does not exist
        z$'name' must be bytestring, not %.80sr�N)r�r�r��typerCrlr�rOrgr5r�r>r]r?r?r@�__getitem__�s	
�zBaseRepo.__getitem__)r]rHcCsBt|�dks t|�dkr4t|�r4||jvp2||jvS||jvSdS)zuCheck if a specific Git object or ref is present.

        Args:
          name: Git object SHA1 or ref name
        r�r�N)rlrr�r5r�r?r?r@�__contains__�s zBaseRepo.__contains__)r]�valuecCsV|�d�s|dkrJt|t�r*|j|j|<qRt|t�r@||j|<qRt|��nt|��dS)z~Set a ref.

        Args:
          name: ref name
          value: Ref value - either a ShaFile object, or a hex sha
        �refs/r�N)rdr�r r�r5r�r�rg)r>r]r�r?r?r@�__setitem__�s


zBaseRepo.__setitem__)r]cCs(|�d�s|dkr|j|=nt|��dS)zORemove a ref.

        Args:
          name: Name of the ref to remove
        r�r�N)rdr5rgr�r?r?r@�__delitem__s
zBaseRepo.__delitem__rXcCst|�S)z7Determine the identity to use for new commits.
        )rf)r>rYrZr?r?r@�_get_user_identityszBaseRepo._get_user_identity)�updated_graftpointscCs<|��D]"\}}|g|D]}t|d�qq|j�|�dS)z{Add or modify graftpoints

        Args:
          updated_graftpoints: Dict of commit shas to list of parent shas
        rkN)rurr�r�)r>r�rorprqr?r?r@�_add_graftpointsszBaseRepo._add_graftpoints)�	to_removerHcCs|D]}|j|=qdS)zSRemove graftpoints

        Args:
          to_remove: List of commit shas
        N)r�)r>r�rqr?r?r@�_remove_graftpoints%szBaseRepo._remove_graftpointscCsP|�|�}|durgS|�"dd�|��D�Wd�S1sB0YdS)NcSsg|]}|��r|���qSr?r�r�r?r?r@r�3r�z(BaseRepo._read_heads.<locals>.<listcomp>)r��	readlines)r>r]r�r?r?r@�_read_heads.s

zBaseRepo._read_headsr�Fc
CsNddl}
t�}|dur.|��}|�|j�|_nt|�dkrBtd��||_z|s\|jd�	�Wn<t
y�}zt|��WYd}~nd}~0ty�Yn0|�
�}|dur�|�d�}|dur�t|dd�}t|�||_|dur�|
��}t|�|_|dur�d}||_|du�rt|d	d�}||_t|�|du�r6|}t|�|_|du�rN|}||_|	du�r�z|�d
d�}	Wnt�y�Yn0|	du�r�|	|_|du�r�td��z6|�r�||_n$|jd
�	|�|_|jdu�r�||_WnFt
�y
}zt|��WYd}~n"d}~0t�y"||_Yn0|
du�rB||_|j�|�n�zF|j|
}|g||_|j�|�|jj|
||jd||||d�}WnDt�y�||_|j�|�|jj |
|jd||||d�}Yn0|�s�td|
f��|�!d�z|jd�	�WnHt
�y4}zt"�#d|t$�WYd}~nd}~0t�yFYn0|jS)aCreate a new commit.

        If not specified, `committer` and `author` default to
        get_user_identity(..., 'COMMITTER')
        and get_user_identity(..., 'AUTHOR') respectively.

        Args:
          message: Commit message
          committer: Committer fullname
          author: Author fullname
          commit_timestamp: Commit timestamp (defaults to now)
          commit_timezone: Commit timestamp timezone (defaults to GMT)
          author_timestamp: Author timestamp (defaults to commit
            timestamp)
          author_timezone: Author timestamp timezone
            (defaults to commit timestamp timezone)
          tree: SHA1 of the tree root to use (if not specified the
            current index will be committed).
          encoding: Encoding
          ref: Optional ref to commit to (defaults to current branch)
          merge_heads: Merge heads (defaults to .git/MERGE_HEADS)
          no_verify: Skip pre-commit and commit-msg hooks

        Returns:
          New commit SHA1
        rNr�z%tree must be a 40-byte hex sha string�
pre-commitZMERGE_HEADSZ	COMMITTER)rZZAUTHOR)Zi18nZcommitEncodingzNo commit message specified�
commit-msgscommit: )�message�	committer�	timestamp�timezonez%s changed during commit�post-commitzpost-commit hook failed: %s)%�timerr�ror��treerlrgr9ZexecuterrrOr�rrfrhr�intZcommit_time�commit_timezone�authorZauthor_time�author_timezonerS�encodingrrp�
add_objectr5Z
set_if_equalsr��
add_if_newr�r�r�r�)r>rrr
Zcommit_timestamprZauthor_timestamprr
rr�Zmerge_headsZ	no_verifyr	�cr7�erYZold_head�okr?r?r@�	do_commit5s�











�
�
$zBaseRepo.do_commit)NNN)NN)NN)NN)N)N)N)N)NNNNNNNNNr�NF)1rCrDrErFrr,rA�boolr�r�r�r�r�r�r�r�r�r�r�rr�r�r�r�r r�r�rrr�r�r�r�r�r�r�r�r�r�r�rr�r�r�r�r�r�rrr?r?r?r@r�?s\
		
�
�
L




%��	�r�cCs0|��}|�d�std��|td�d��d�S)z�Read a ``.git`` file.

    The first line of the file should start with "gitdir: "

    Args:
      f: File-like object to read from
    Returns: A path
    zgitdir: z&Expected file to start with 'gitdir: 'N�
)�readrdrgrl�rstrip)r�Zcsr?r?r@�read_gitfile�s	
rc@seZdZdZdd�ZdS)�UnsupportedVersionzUnsupported repository version.cCs
||_dSr<)�version)r>rr?r?r@rA�szUnsupportedVersion.__init__NrBr?r?r?r@r�src@seZdZdZdd�Zdd�Zed@dd��Zd	d
�Zdd�Z	d
d�Z
dd�Zdd�ZdAdd�Z
dd�Zdd�dd�Zdd�Zdd�ZdBd#d$�ZdCd%d&�Zd'd�d(d)�Zd*d+�Zd,d-�Zd.d/�Zed0d1��ZedDd2d3��ZedEd4d5��ZedFd6d7��ZeZd8d9�Zd:d;�Zd<d=�Zd>d?�Z dS)G�Repoz�A git repository backed by local disk.

    To open an existing repository, call the contructor with
    the path of the repository.

    To create a new repository, use the Repo.init class method.
    c	Cs�tj�|t�}tj�tj�|t��r2d|_||_n�tj�tj�|t��rltj�tj�|t��rld|_||_nntj�	|�r�d|_t
|d��}t|�}Wd�n1s�0Yd|_tj�||�|_ntdt
|d���|�t�}|du�r:|�4tj�|��t�|���d���|_Wd�n1�s.0Yn|j|_||_|��}zt|�dd��}Wnt�y|d	}Yn0|d	k�r�t|��t�tj�|��t�|�}t|��|j|jd
�}	t� |||	�i|_!|jtj�dd�|��d
�}
|
�r,|
� |j!�"t#|
��Wd�n1�s"0Y|jd|��d
�}
|
�rz|
� |j!�"t#|
��Wd�n1�sp0Yt$|���|j%d<t&|���|j%d<t'|���|j%d<t(|���|j%d<dS)NFT�r�'No git repository was found at %(path)s�r�s
r�r�r�Zloggerr:rm)�basedirr�rrrzpost-receive))rQr�rw�
CONTROLDIR�isdir�	OBJECTDIRr��_controldir�REFSDIR�isfile�openrr�dictr��	COMMONDIR�
controldirr�rr�
_commondirr�rrSrOrrZfrom_configr8r/�
_write_reflogr�rAr�r�rrr%r9r'r&r()r>�rootZhidden_pathr�r�r8rYZformat_versionr�r5Z
graft_filer?r?r@rA�sv�&�

�(

���0�0z
Repo.__init__c
Cs�ddlm}tj�|��dt�|��}	zt�tj�|	��Wnt	yNYn0|durj|�
�}
|�|
�}t|�|dur�t
t���}|dur�d}t|	d��,}|�|||||||�d�Wd�n1s�0YdS)Nr`)�format_reflog_lineZlogsrZabrt)Zreflogr0rQr�rwr,r��makedirs�dirname�FileExistsErrorr�r�rhrr	r)�write)r>r�Zold_shaZnew_sharrrrr0r�rYr�r?r?r@r.s(
��zRepo._write_reflog�.cCsZd}tj�|�}|rDz
||�WSty@tj�|�\}}Yq0qtdt|d���dS)z�Iterate parent directories to discover a repository

        Return a Repo object for the first parent directory that looks like a
        Git repository.

        Args:
          start: The directory to start discovery from (defaults to '.')
        Trr N)rQr��abspathrrPr*)r��startZ	remainingr�r?r?r@�discover*s

�z
Repo.discovercCs|jS)z)Return the path of the control directory.)r&r�r?r?r@r,?szRepo.controldircCs|jS)z�Return the path of the common directory.

        For a main working tree, it is identical to controldir().

        For a linked working tree, it is the control directory of the
        main working tree.)r-r�r?r?r@r8CszRepo.commondircCs�tj�|jd�}t|d��}|�d�Wd�n1s:0Yt�|�}zt�||jtj	A�Wnt
yzYdS0t�|�}t�|�|j|jk}|jtj	@dk}|o�|S)r�z.probe-permissions�w�NFr)rQr�rwr)r4�lstat�chmod�st_mode�stat�S_IXUSR�PermissionError�unlink)r>�fnamer�Zst1Zst2Zmode_differsZst2_has_execr?r?r@r�Ms(


zRepo._determine_file_modecCsT|�tjj�}ttj�|��|�d��}|�|�Wd�n1sF0YdS)r��wbN)�lstriprQr��seprrwr,r4)r>r�r�r�r?r?r@r�dszRepo._put_named_filecCs6zt�tj�|��|��Wnty0YdS0dSr<)rQrAr�rwr,�FileNotFoundErrorr�r?r?r@r�oszRepo._del_named_fileNcCsN|dur|��}|�tjj�}zttj�||�d�WStyHYdS0dS)aGet a file from the control dir with a specific name.

        Although the filename should be interpreted as a filename relative to
        the control dir in a disk-based Repo, the object returned need not be
        pointing to a file in that location.

        Args:
          path: The path to the file, relative to the control dir.
          basedir: Optional argument that specifies an alternative to the
            control dir.
        Returns: An open file object, or None if the file does not exist.
        N�rb)r,rDrQr�rEr)rwrF)r>r�r"r?r?r@r�uszRepo.get_named_filecCstj�|��t�S)zReturn path to the index file.)rQr�rwr,�INDEX_FILENAMEr�r?r?r@�
index_path�szRepo.index_pathr
rGcCs&ddlm}|��st��||���S)r�rr)�
dulwich.indexr
�	has_indexrrI)r>r
r?r?r@r��szRepo.open_indexcCs|jS)zCheck if an index is present.�r�r�r?r?r@rK�szRepo.has_indexc
CsJt�|j�}t|t�s|g}ddlm}m}m}|�	�}|�
�}|D]�}t|t�s\t�|�}tj�|�rtt
d|��||�}	tj�||�}
zt�|
�}Wn0ty�z
||	=Wnty�Yn0YqD0t�|j��st�|j��sz
||	=Wnt�yYn0qD||
|�}|�||�}|j�|�|||jd�||	<qD|��dS)zpStage a set of paths.

        Args:
          fs_paths: List of paths, relative to the repository path
        r)�blob_from_path_and_stat�index_entry_from_stat�_fs_to_tree_pathz;path %r should be relative to repository root, not absoluteN)rQ�fsencoder�r�r�rJrMrNrOr��get_blob_normalizerr��isabsrgrwr;�OSErrorrOr>�S_ISREGr=�S_ISLNKZcheckin_normalizer�rr�r4)
r>Zfs_pathsZroot_path_bytesrMrNrOr7Zblob_normalizerZfs_pathZ	tree_path�	full_path�stZblobr?r?r@�stage�sH


��

�

z
Repo.stageTF�origincCsN|s|j||d�}n|r td��|j||d�}|�|�|j}t|t�sRt�|�}d|}|j	j
d||j	�d�|d�|j	j
d|j	�d�|d�z|j	jt
|j	t
|d�Wnty�Yn0|��}	|	�dd	|�|	�dd
d�|	��|j	�d�\}
}|
�rJ|d
u�rJ|j	jd|
d|d�||d<|d
u�r<|}|�rJ|��|S)aBClone this repository.

        Args:
          target_path: Target path
          mkdir: Create the target directory
          bare: Whether to create a bare repository
          origin: Base name for refs in target repository
            cloned from this repository
        Returns: Created repository as `Repo`
        )�mkdirz"checkout and bare are incompatiblesclone: from s
refs/remotes/r�)rs	refs/tags)Zremote�originZurlr�z#+refs/heads/*:refs/remotes/origin/*r�Nra)�initrg�	init_barer�r�r�r�rQrPr5Zimport_refsr�r�DEFAULT_REFrOr�r�Z
write_to_pathZfollow�set_symbolic_ref�reset_index)r>Ztarget_pathrZr�r[Zcheckoutr�Zencoded_pathZref_messageZ
target_configZ
head_chainZhead_shar?r?r@�clone�sT


��
�
��
z
Repo.clonecCs|ddlm}m}m}|dur&|dj}|��}|�ddtjdk�}|�ddtjdk�r\|}n|}||j	|�
�|j|||d	�S)
z�Reset the index back to a specific tree.

        Args:
          tree: Tree SHA to reset to, None for current HEAD tree.
        r)�build_index_from_tree�validate_path_element_default�validate_path_element_ntfsNr�scoresfilemode�ntscore.protectNTFS)�honor_filemode�validate_path_element)rJrbrcrdr
r�Zget_booleanrQr]r�rIr�)r>r
rbrcrdrYrfrgr?r?r@r`s
��zRepo.reset_indexrcCsPddlm}tj�|jd�}z|�|�WStyJ|�}||_|YS0dS)r�rr�rYN)r�rrQr�rwr&Z	from_pathrF)r>rr�r�r?r?r@r�$szRepo.get_configcCsbtj�|jd�}z8t|d��}|��Wd�WS1s<0YWnty\YdS0dS)zsRetrieve the description of this repository.

        Returns: A string describing the repository or None.
        r�rGN)rQr�rwr&rrrF)r>r�r�r?r?r@r�2s,zRepo.get_descriptioncCs
d|jS)Nz<Repo at %r>r r�r?r?r@�__repr__>sz
Repo.__repr__cCs|�d|�dS)r�r�N)r�r�r?r?r@r�AszRepo.set_descriptioncCs\tD]}t�tjj|g|�R��qt�tj�|t��||�}|j�	dt
�|�|�|S)Nr�)�BASE_DIRECTORIESrQrZr�rwrr\r%r5r_r^r�)r�r�r��dr�r?r?r@�_init_maybe_bareJs
zRepo._init_maybe_barecCsB|rt�|�tj�|t�}t�|�t|�|�|d�||�S)z�Create a new repository.

        Args:
          path: Path in which to create the repository
          mkdir: Whether to create the directory
        Returns: `Repo` instance
        F)rQrZr�rwr#r�rk)r�r�rZr,r?r?r@r\Ts	

z	Repo.initc
Cs�|rt�|�|dur"tj�|�}tj�|��t�}tj�||�}tj�|t�}t|d��(}|�	dt�
|�d�Wd�n1s�0Yzt�|�Wnty�Yn0zt�|�Wnty�Yn0ttj�|t�d��$}|�	t�
|�d�Wd�n1�s0Yttj�|t
�d��}|�	d�Wd�n1�sV0Yttj�|d�d��"}|�	|��d�Wd�n1�s�0Y||�}	|	��|	S)a6Create a new working directory linked to a repository.

        Args:
          path: Path in which to create the working tree.
          main_repo: Main repository to reference
          identifier: Worktree identifier
          mkdir: Whether to create the directory
        Returns: `Repo` instance
        NrCsgitdir: rts../..
ZHEAD)rQrZr��basenamerwr,�	WORKTREESr#r)r4rPr3�GITDIRr+r�r`)
r�r�Z	main_repoZ
identifierrZZmain_worktreesdirZworktree_controldirZ
gitdirfiler�rr?r?r@�_init_new_working_directoryes4
64*2z Repo._init_new_working_directorycCs|rt�|�|�|d�S)z�Create a new bare repository.

        ``path`` should already exist and be an empty directory.

        Args:
          path: Path to create bare repository in
        Returns: a `Repo` instance
        T)rQrZrk)r�r�rZr?r?r@r]�s

zRepo.init_barecCs|j��dS)z*Close any files opened by this repository.N)r��closer�r?r?r@rp�sz
Repo.closecCs|Sr<r?r�r?r?r@�	__enter__�szRepo.__enter__cCs|��dSr<)rp)r>�exc_typeZexc_valZexc_tbr?r?r@�__exit__�sz
Repo.__exit__cCsi}t|��|�S)z( Return a BlobNormalizer object
        )r)r�)r>Zgit_attributesr?r?r@rQ�s�zRepo.get_blob_normalizer)r5)N)TFrYN)N)F)NF)F)!rCrDrErFrAr.�classmethodr8r,r8r�r�r�r�rIr�rKrXrar`r�r�rhr�rkr\ror]ZcreaterprqrsrQr?r?r?r@r�sL;

1�
8
	
	�&
rc@sneZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
ddd�Zdd�Zdd�Z
edd��ZdS)�
MemoryRepoz�Repo that stores refs, objects, and named files in memory.

    MemoryRepos are always bare: they have no working tree and no index, since
    those have a stronger dependency on the filesystem.
    cCsNddlm}g|_ti|jd�}t�|t�|�i|_d|_	|�|_
d|_dS)Nrr�r!T)r�r�_reflogr-�_append_reflogr�rAr�_named_filesr��_config�_description)r>rZrefs_containerr?r?r@rA�szMemoryRepo.__init__cGs|j�|�dSr<)rvrv)r>r�r?r?r@rw�szMemoryRepo._append_reflogcCs
||_dSr<�rzr�r?r?r@r��szMemoryRepo.set_descriptioncCs|jSr<r{r�r?r?r@r��szMemoryRepo.get_descriptioncCs
tjdkS)r�ry)r~rr�r?r?r@r��szMemoryRepo._determine_file_modecCs||j|<dSr�)rxr�r?r?r@r��szMemoryRepo._put_named_filecCs$z|j|=WntyYn0dSr<)rxrOr�r?r?r@r��szMemoryRepo._del_named_fileNcCs"|j�|d�}|durdSt|�S)a�Get a file from the control dir with a specific name.

        Although the filename should be interpreted as a filename relative to
        the control dir in a disk-baked Repo, the object returned need not be
        pointing to a file in that location.

        Args:
          path: The path to the file, relative to the control dir.
        Returns: An open file object, or None if the file does not exist.
        N)rxrSr)r>r�r"r�r?r?r@r��szMemoryRepo.get_named_filecCs
t��dS)z�Fail to open index for this repo, since it is bare.

        Raises:
          NoIndexPresent: Raised when no index is present
        N)rr�r?r?r@r��szMemoryRepo.open_indexcCs|jS)zKRetrieve the config object.

        Returns: `ConfigFile` object.
        )ryr�r?r?r@r��szMemoryRepo.get_configcCsL|�}|D]}|j�|�q
|��D]\}}|j�||�q$|jdd�|S)z�Create a new bare repository in memory.

        Args:
          objects: Objects for the new repository,
            as iterable
          refs: Refs as dictionary, mapping names
            to object SHA1s
        TrL)r�rrur5rr�)r�r4r5r�r�Zrefnamerqr?r?r@r]�s
zMemoryRepo.init_bare)N)rCrDrErFrArwr�r�r�r�r�r�r�r�rtr]r?r?r?r@ru�s
	
ru)N)_rF�iorrQr~r>r	�typingrrrrrrr	r�r
rrJr
Zdulwich.errorsrrrrrrrrrZdulwich.filerZdulwich.object_storerrrrZdulwich.objectsrrrrr r!r"Zdulwich.packr#Z
dulwich.hooksr$r%r&r'r(Zdulwich.line_endingr)Zdulwich.refsr*r+r,r-r.r/r0r1r2r3r�r#r%r'ZREFSDIR_TAGSZ
REFSDIR_HEADSrHr+rnrmrir^r�r;r�rWr�rfrhrrrxr�r�r�r�rrrrur?r?r?r@�<module>sz$,$	0�	��4� a