o
    Uh                    @   s  d Z ddlZddlZddlZddlZddlZddlmZ ddlm	Z	 ddl
mZmZmZmZmZmZ erBddlmZmZ ddlmZ dd	lmZmZmZmZmZmZmZmZmZ dd
l m!Z! ddl"m#Z#m$Z$m%Z%m&Z&m'Z' ddl(m)Z)m*Z* ddl+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1 ddl2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z: ddl;m<Z< ddl=m>Z>m?Z?m@Z@mAZAmBZBmCZCmDZDmEZEmFZFmGZGmHZHmIZImJZJmKZKmLZLmMZMmNZN dZOdZPdZQdZRdZSdZTdZUdZVdZWdgeQgeQeRgeQeSgdgdggZXdZYG dd deZZ[G d d! d!eZZ\d"e]e^e^f fd#d$Z_dAd%d&d'ee^ d"e`fd(d)ZadBd*d+Zbd,ee` d"ece`ede` f fd-d.Zed,ece`ede` f d"e`fd/d0ZfdBd1d2ZgG d3d4 d4ZhG d5d6 d6Zid7d8 ZjG d9d: d:eZZkG d;d< d<eZZlG d=d> d>eiZmG d?d@ d@eiZndS )CzRepository access.

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

    N)Iterable)BytesIO)TYPE_CHECKINGAnyBinaryIOCallableOptionalUnion   
ConfigFileStackedConfigIndex)	CommitError	HookErrorNoIndexPresentNotBlobErrorNotCommitErrorNotGitRepositoryNotTagErrorNotTreeErrorRefFormatError)GitFile)CommitMsgShellHookHookPostCommitShellHookPostReceiveShellHookPreCommitShellHook)BlobNormalizerTreeBlobNormalizer)DiskObjectStoreMemoryObjectStoreMissingObjectFinderObjectStoreGraphWalkerPackBasedObjectStorepeel_sha)BlobCommitObjectIDShaFileTagTreecheck_hexshavalid_hexsha)generate_unpacked_objects)ANNOTATED_TAG_SUFFIXLOCAL_BRANCH_PREFIXLOCAL_TAG_PREFIXSYMREFDictRefsContainerDiskRefsContainerInfoRefsContainerRefRefsContainer_set_default_branch	_set_head_set_origin_headcheck_ref_formatread_packed_refsread_packed_refs_with_peeledserialize_refswrite_packed_refsz.gitobjectsrefstagsheadsindex	commondirgitdir	worktreesbrancheshooksinfos   masterc                   @      e Zd ZdZdddZdS )InvalidUserIdentityz2User identity is not of the format 'user <email>'.returnNc                 C   
   || _ d S N)identity)selfrQ    rS   `/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/dulwich/repo.py__init__      
zInvalidUserIdentity.__init__rN   N__name__
__module____qualname____doc__rU   rS   rS   rS   rT   rM          rM   c                   @   s   e Zd ZdZdS )DefaultIdentityNotFoundz)Default identity could not be determined.N)rY   rZ   r[   r\   rS   rS   rS   rT   r^      s    r^   rN   c                  C   s   dd l } dD ]}tj|}|r nqd }zdd l}W n ty&   d }Y n.w z	|t }W n ty;   d }Y nw t	|dd rK|j
dd }nd }|d u rT|j}|s`|d u r^td|}tjd}|d u r{|d u rrtd| d|   }||fS )Nr   )LOGNAMEUSERLNAMEUSERNAMEgecos,zno username foundEMAIL@)socketosenvirongetpwdImportErrorgetpwuidgetuidKeyErrorgetattrpw_gecossplitpw_namer^   gethostname)rg   nameusernamerk   fullnameentryemailrS   rS   rT   _get_default_identity   s@   rz   configr   kindc                 C   s  d}d}|r,t jd| d }|dur|d}t jd| d }|dur,|d}|du rDz| dd}W n tyC   d}Y nw |du r\z| dd}W n ty[   d}Y nw t \}}|du rj|d}|du rs|d}|d	r|d
r|dd }|d | d
 S )aa  Determine 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
    NGIT__NAMEutf-8_EMAIL)userru   ry      <   >r
       <)rh   ri   rj   encodero   rz   
startswithendswith)r{   r|   r   ry   user_ucemail_ucdefault_userdefault_emailrS   rS   rT   get_user_identity   s:   




r   c              
   C   sd   z
|  dd\}}W n ty } zt| |d}~ww d|vr$t| d| v s,d| v r0t| dS )zVerify that a user identity is formatted correctly.

    Args:
      identity: User identity bytestring
    Raises:
      InvalidUserIdentity: Raised when identity is invalid
    r   r
   Nr          
)rr   
ValueErrorrM   )rQ   fstsndexcrS   rS   rT   check_user_identity   s   
r   graftpointsc                 C   sf   i }| D ],}| dd}|d }t|dkr|d   }ng }|g|D ]}t|d q$|||< 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)rr   lenr-   )r   graftsline	raw_graftcommitparentssharS   rS   rT   parse_graftpoints   s   
r   c                 C   sH   g }|   D ]\}}|r||d d|  q|| qd|S )a  Convert 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

        r   )itemsappendjoin)r   graft_linesr   r   rS   rS   rT   serialize_graftpoints  s   
r   c                 C   sp   t jdkr4ddl}ddlm}m}m} d}||||d|jj	f}t
| tr,t| } || |s6	 dS dS dS )zMark 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>
    win32r   N)BOOLDWORDLPCWSTRr   SetFileAttributesW)sysplatformctypesctypes.wintypesr   r   r   WINFUNCTYPEwindllkernel32
isinstancebytesrh   fsdecode)pathr   r   r   r   FILE_ATTRIBUTE_HIDDENr   rS   rS   rT   _set_filesystem_hidden4  s   




r   c                   @   s&   e Zd Zi g fdddZdddZdS )	ParentsProviderrN   Nc                 C   s   || _ || _t|| _d S rP   )storer   setshallows)rR   r   r   r   rS   rS   rT   rU   L  s   zParentsProvider.__init__c                 C   sF   z| j | W S  ty   Y nw || jv rg S |d u r | j| }|jS rP   )r   ro   r   r   r   )rR   	commit_idr   rS   rS   rT   get_parentsQ  s   

zParentsProvider.get_parentsrW   rP   )rY   rZ   r[   rU   r   rS   rS   rS   rT   r   K  s    r   c                   @   s6  e Zd ZdZdededdfddZdefdd	Zdefd
dZ	dpdede
e ddfddZdede
e fddZdededdfddZdeddfddZdqddZdrddZ		dsddZ		dsde
e fdd Z		dsd!ee d"ee d#e
eegdf  d$e
e fd%d&Z	dpd'e
ee  defd(d)Zdeeef fd*d+Zdefd,d-Zd.d/ Z d0ede!fd1d2Z"de#fd3d4Z$dpd0ed5e
e% dee fd6d7Z&dtd9d:Z'dtd;d<Z(de
e fd=d>Z)dud?d@Z*dvdBdCZ+de,e fdDdEZ-dudFdGZ.dHe/defdIdJZ0dpdKe
ee  fdLdMZ1dNe2ee/f fdOdPZ3dNedefdQdRZ4dNedSe2e!ef ddfdTdUZ5dNeddfdVdWZ6	dpdXdAdYe
e defdZd[Z7d\eeee f ddfd]d^Z8g fd_ee ddfd`daZ9dbdc Z:										d		e	edwdfe
e dge
e dhe
e die
e dje
e dHe/dke
ee  dledmefdndoZ;dS )xBaseRepoak  Base class for a git repository.

    This base class is meant to be used for Repository implementations that e.g.
    work on top of a different transport than a standard filesystem path.

    Attributes:
      object_store: Dictionary-like object for accessing
        the objects
      refs: Dictionary-like object with the refs in this
        repository
    object_storerB   rN   Nc                 C   s   || _ || _i | _i | _dS )zOpen 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   rB   _graftpointsrJ   )rR   r   rB   rS   rS   rT   rU   j  s   

zBaseRepo.__init__c                 C   
   t | j)Probe the file-system to determine whether permissions can be trusted.

        Returns: True if permissions can be trusted, False otherwise.
        )NotImplementedError_determine_file_moderR   rS   rS   rT   r   z     
zBaseRepo._determine_file_modec                 C   
   t jdkS zProbe the filesystem to determine whether symlinks can be created.

        Returns: True if symlinks can be created, False otherwise.
        r   r   r   r   rS   rS   rT   _determine_symlinks     
zBaseRepo._determine_symlinksbaresymlinksc                 C   s   ddl m} | dd t }| }|ddd |  r%|ddd	 n|ddd
 |du r6|s6|  }|d
u rA|dd| |dd| |ddd	 || | d|  | t	j
ddd dS )z(Initialize a default set of named files.r
   r   descriptions   Unnamed repositorycorerepositoryformatversion0filemodeTFNr   r   logallrefupdatesr{   rK   exclude    )r{   r   _put_named_filer   r   r   r   write_to_filegetvaluerh   r   r   )rR   r   r   r   fcfrS   rS   rT   _init_files  s"   
zBaseRepo._init_filesr   c                 C   r   )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.
        )r   get_named_filerR   r   rS   rS   rT   r     s   
zBaseRepo.get_named_filecontentsc                 C   r   )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.
        )r   r   rR   r   r   rS   rS   rT   r        
zBaseRepo._put_named_filec                 C   r   )z;Delete a file in the control directory with the given name.)r   _del_named_filer   rS   rS   rT   r        
zBaseRepo._del_named_filer   c                 C   r   )Open the index for this repository.

        Raises:
          NoIndexPresent: If no index is present
        Returns: The matching `Index`
        )r   
open_indexr   rS   rS   rT   r     r   zBaseRepo.open_indexc                 C   sB   |du r|j j}| 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   determine_wants_allfetch_pack_dataget_graph_walkeradd_pack_dataget_refs)rR   targetdetermine_wantsr   r   count	pack_datarS   rS   rT   fetch  s   
zBaseRepo.fetchc           	      C   s>   | j |||||d}| }t|}t|t| j|||df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   )r   other_haves)find_missing_objectsget_remote_haslistr   r/   r   )	rR   r   graph_walkerr   
get_taggedr   missing_objects
remote_has
object_idsrS   rS   rT   r     s   

zBaseRepo.fetch_pack_datac              	      s   |dvrt dt| j|  }||}t|tstdt|dt }t|dt }	|g kr?|s3|	r5dS G dd d}
|
 S | j	|}|sI|	rKg }t
| j|d	  fd
d}t| j|||  |||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
        Nr   zdepth not supported yetz'determine_wants() did not return a listshallow	unshallowNc                   @   s,   e Zd Zd	ddZdefddZdd ZdS )
z?BaseRepo.find_missing_objects.<locals>.DummyMissingObjectFinderrN   Nc                 S   s   d S rP   rS   r   rS   rS   rT   r   )     zNBaseRepo.find_missing_objects.<locals>.DummyMissingObjectFinder.get_remote_hasc                 S   s   dS r   rS   r   rS   rS   rT   __len__,  r   zGBaseRepo.find_missing_objects.<locals>.DummyMissingObjectFinder.__len__c                 s   s    g E d H  d S rP   rS   r   rS   rS   rT   __iter__/  s   zHBaseRepo.find_missing_objects.<locals>.DummyMissingObjectFinder.__iter__rW   )rY   rZ   r[   r   intr  r  rS   rS   rS   rT   DummyMissingObjectFinder(  s    
r  )r   c                         | j| S rP   r   idr   parents_providerrS   rT   r   B     z2BaseRepo.find_missing_objects.<locals>.get_parents)haveswantsr   r   r   r   )r   r?   r   r   r   r   	TypeErrorrp   	frozensetfind_common_revisionsr   r#   get_shallow)rR   r   r   r   r   r   rB   r  r   
unshallowsr  r  r   rS   r	  rT   r     s:   

zBaseRepo.find_missing_objectshavewantr   	ofs_deltac                 C   s   | j j|||  ||dS )a9  Generate 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   r  )r   generate_pack_datar  )rR   r  r  r   r  rS   rS   rT   r  O  s   zBaseRepo.generate_pack_datarD   c                    sD   |du r fdd j d D }t j}t||j  dS )a  Retrieve 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
        Nc                    s   g | ]	}| j v r|qS rS   r   .0r   r   rS   rT   
<listcomp>s  s
    
z-BaseRepo.get_graph_walker.<locals>.<listcomp>
   refs/heads)r   )rB   as_dictvaluesr   r   r$   r   r  )rR   rD   r
  rS   r   rT   r   f  s   

zBaseRepo.get_graph_walkerc                 C   s
   | j  S )z^Get dictionary with all refs.

        Returns: A ``dict`` mapping ref names to SHA1s
        )rB   r  r   rS   rS   rT   r   }  r   zBaseRepo.get_refsc                 C   s
   | j d S )z#Return the SHA1 pointed at by HEAD.   HEAD)rB   r   rS   rS   rT   head  r   zBaseRepo.headc                 C   s   t |dv sJ | |}t||s>|tu rt||tu r"t||tu r*t||t	u r2t
|td|jd|j|S )N   (   zType invalid: z != )r   
get_objectr   r(   r   r'   r   r,   r   r+   r   	Exception	type_name)rR   r   clsretrS   rS   rT   _get_object  s   

zBaseRepo._get_objectr   c                 C   s
   | j | S )zRetrieve 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  )rR   r   rS   rS   rT   r#    s   
	zBaseRepo.get_objectc                 C   s   t | j| j|  dS )N)r   r   )r   r   r   r  r   rS   rS   rT   r
    s
   zBaseRepo.parents_providerr   c                 C   s   |   ||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   )rR   r   r   rS   rS   rT   r     s   zBaseRepo.get_parentsr   c                 C   r   )hRetrieve the config object.

        Returns: `ConfigFile` object for the ``.git/config`` file.
        )r   
get_configr   rS   rS   rT   r*    r   zBaseRepo.get_configc                 C   r   )z$Retrieve the worktree config object.)r   get_worktree_configr   rS   rS   rT   r+    r   zBaseRepo.get_worktree_configc                 C   r   )zRetrieve the description for this repository.

        Returns: String with the description of the repository
            as set by the user.
        )r   get_descriptionr   rS   rS   rT   r,    r   zBaseRepo.get_descriptionc                 C   r   )Set the description for this repository.

        Args:
          description: Text to set as description for this repository.
        )r   set_descriptionrR   r   rS   rS   rT   r.    r   zBaseRepo.set_descriptionr   c                 C   sR   ddl m}m} |  }|g}|dddr||   || 7 }|||dS )a  Return 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   s
   extensions   worktreeconfigF)writable)r{   r   r   r*  get_booleanr   r+  default_backends)rR   r   r   local_configbackendsrS   rS   rT   get_config_stack  s   	zBaseRepo.get_config_stackc                 C   sN   |  d}|du rt S | dd |D W  d   S 1 s w   Y  dS )zRGet the set of shallow commits.

        Returns: Set of shallow commits.
        r   Nc                 S   s   h | ]}|  qS rS   stripr  r   rS   rS   rT   	<setcomp>      z'BaseRepo.get_shallow.<locals>.<setcomp>)r   r   )rR   r   rS   rS   rT   r    s   
$zBaseRepo.get_shallowc                 C   sV   |   }|r|| |r|| |r$| dddd |D  dS | d dS )zUpdate the list of shallow objects.

        Args:
          new_shallow: Newly shallow objects
          new_unshallow: Newly no longer shallow objects
        r   r   c                 S   s   g | ]}|d  qS )r   rS   r  rS   rS   rT   r    r<  z+BaseRepo.update_shallow.<locals>.<listcomp>N)r  updatedifference_updater   r   r   )rR   new_shallownew_unshallowr   rS   rS   rT   update_shallow  s   

 zBaseRepo.update_shallowrefc                 C   s0   | j |}|dur|S t| j| j | d jS )a  Get 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.
        Nr
   )rB   
get_peeledr&   r   r  )rR   rB  cachedrS   rS   rT   rC    s   	zBaseRepo.get_peeledincludec                    sH   ddl m} |du r  g} fdd|d< | j|g|R i |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
   )WalkerNc                    r  rP   r  r  r   rS   rT   <lambda>.  s    z%BaseRepo.get_walker.<locals>.<lambda>r   )walkrF  r  r   )rR   rE  argskwargsrF  rS   r   rT   
get_walker  s
   
zBaseRepo.get_walkerru   c              
   C   s   t |tstdt|jdt|dv r(z| j| W S  ttfy'   Y nw z	| j| j	|  W S  t
yB } zt||d}~ww )zRetrieve 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 z.80r   N)r   r   r  typerY   r   r   ro   r   rB   r   )rR   ru   r   rS   rS   rT   __getitem__2  s   
	
zBaseRepo.__getitem__c                 C   s>   t |dkst |dkrt|r|| jv p|| jv S || jv S )zuCheck if a specific Git object or ref is present.

        Args:
          name: Git object SHA1 or ref name
        r!  r"  )r   r.   r   rB   rR   ru   rS   rS   rT   __contains__G  s    
zBaseRepo.__contains__valuec                 C   sT   | ds	|dkr&t|tr|j| j|< dS t|tr"|| j|< dS t|t|)z~Set a ref.

        Args:
          name: ref name
          value: Ref value - either a ShaFile object, or a hex sha
           refs/r  N)r   r   r*   r  rB   r   r  r   )rR   ru   rP  rS   rS   rT   __setitem__R  s   

zBaseRepo.__setitem__c                 C   s&   | ds	|dkr| j|= dS t|)zORemove a ref.

        Args:
          name: Name of the ref to remove
        rQ  r  N)r   rB   r   rN  rS   rS   rT   __delitem__c  s   zBaseRepo.__delitem__r{   r|   c                 C   s   t dt t|S )z.Determine the identity to use for new commits.z;use get_user_identity() rather than Repo._get_user_identity)warningswarnDeprecationWarningr   )rR   r{   r|   rS   rS   rT   _get_user_identityn  s
   zBaseRepo._get_user_identityupdated_graftpointsc                 C   s<   |  D ]\}}|g|D ]}t|d qq| j| dS )z|Add or modify graftpoints.

        Args:
          updated_graftpoints: Dict of commit shas to list of parent shas
        r   N)r   r-   r   r=  )rR   rX  r   r   r   rS   rS   rT   _add_graftpointsx  s
   zBaseRepo._add_graftpoints	to_removec                 C   s   |D ]}| j |= qdS )zTRemove graftpoints.

        Args:
          to_remove: List of commit shas
        N)r   )rR   rZ  r   rS   rS   rT   _remove_graftpoints  s   
zBaseRepo._remove_graftpointsc                 C   sP   |  |}|d u rg S | dd | D W  d    S 1 s!w   Y  d S )Nc                 S      g | ]
}|  r|  qS rS   r8  r:  rS   rS   rT   r        z(BaseRepo._read_heads.<locals>.<listcomp>)r   	readlines)rR   ru   r   rS   rS   rT   _read_heads  s   
$zBaseRepo._read_headsr  Fmessage	committerauthortreeencodingmerge_heads	no_verifysignc                 C   sh  z|s
| j d   W n ty } zt||d}~w ty$   Y nw t }|du r8|  }|| j|_	nt
|dkrBtd||_	|  }|du rR| d}|du r\t|dd}t| ||_|du rkt }t||_|du rvd}||_|du rt|d	d}||_t| |du r|}t||_|du r|}||_|	du rz|d
d}	W n	 ty   Y nw |	dur|	|_|du rtdz|r||_n| j d ||_|jdu r||_W n ty } zt||d}~w ty   ||_Y nw t|tr|nd}|
du r||_|r|| | j| n`z+| j |
 }|g||_|r.|| | j| | j j!|
||j"d| |||d}W n* tyo   ||_|rX|| | j| | j j#|
|j"d| |||d}Y nw |szt|
d| $d z| j d   W |j"S  ty } zt%&d| t' W Y d}~|j"S d}~w ty   Y |j"S w )a  Create 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_HEAD)
          no_verify: Skip pre-commit and commit-msg hooks
          sign: GPG Sign the commit (bool, defaults to False,
            pass True to use default GPG key,
            pass a str containing Key ID to use a specific GPG key)

        Returns:
          New commit SHA1
        
pre-commitNr"  z%tree must be a 40-byte hex sha string
MERGE_HEAD	COMMITTER)r|   r   AUTHOR)i18ncommitEncodingzNo commit message specified
commit-msgs   commit: )r`  ra  	timestamptimezonez changed during commitpost-commitzpost-commit hook failed: )(rJ   executer   r   ro   r(   r   r   r   rc  r   r   r7  r_  r   r   ra  timer  commit_timecommit_timezonerb  author_timeauthor_timezonerj   rd  r`  r   strr   rg  
add_objectrB   set_if_equalsr  
add_if_newr   rT  rU  UserWarning)rR   r`  ra  rb  commit_timestampru  author_timestamprw  rc  rd  rB  re  rf  rg  r   crE   r{   keyidold_headokerS   rS   rT   	do_commit  s   -











	


zBaseRepo.do_commitrP   rN   r   )NNNNNrN   r   rW   )rN   r   )NNNNNNNNNr  NFF)<rY   rZ   r[   r\   r%   r8   rU   boolr   r   r   r   rx  r   r   r   r   r   r   r   r   r#   r   r   r)   r   r  r$   r   dictr   r  r(  r*   r#  r   r
  r(   r   r*  r+  r,  r.  r7  r   r  rA  r7   rC  rK  r	   rM  rO  rR  rS  rW  rY  r[  r_  r  rS   rS   rS   rT   r   ]  s    	

	
%
X


 




#

			

r   c                 C   s0   |   }|dstd|tdd dS )zRead a ``.git`` file.

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

    Args:
      f: File-like object to read from
    Returns: A path
    zgitdir: z&Expected file to start with 'gitdir: 'N
)readr   r   r   rstrip)r   csrS   rS   rT   read_gitfile:  s   	
r  c                   @   rL   )UnsupportedVersionzUnsupported repository version.rN   Nc                 C   rO   rP   )version)rR   r  rS   rS   rT   rU   L  rV   zUnsupportedVersion.__init__rW   rX   rS   rS   rS   rT   r  I  r]   r  c                   @   rL   )UnsupportedExtensionz!Unsupported repository extension.rN   Nc                 C   rO   rP   )	extension)rR   r  rS   rS   rT   rU   S  rV   zUnsupportedExtension.__init__rW   rX   rS   rS   rS   rT   r  P  r]   r  c                
   @   sz  e Zd ZU dZeed< eed< 		d_dedee dee ddfdd	Z			d`d
dZ
edaddZdd Zdd Zdd Zdd Zd`ddZd`ddZdbddZdd Zdcd d!Zdefd"d#Zd$eeeejeeeeejf  f ddfd%d&Zd$ee ddfd'd(Zd)d*d+dddddd,	 ddd-d.Zdbd/ee fd0d1Z ded3d4Z!ded5d6Z"d7d8 Z#defd9d:Z$d`d;d<Z%e				dfd=ee fd>d?Z&ed*dddd@dedAed=ee dd fdBdCZ'edgdDdEZ(ed*ddddFdGdHZ)e)Z*d`dIdJZ+dKdL Z,dMdN Z-dOdP Z.defdQdRZ/d`dSdTZ0defdUdVZ1dee fdWdXZ2dYee ddfdZd[Z3dbd\eee df ddfd]d^Z4dS )hRepoa  A git repository backed by local disk.

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

    To create a new repository, use the Repo.init class method.

    Note that a repository object may hold on to resources such
    as file handles for performance reasons; call .close() to free
    up those resources.

    Attributes:
      path: Path to the working copy (if it exists) or repository control
        directory (if the repository is bare)
      bare: Whether this is a bare repository
    r   r   Nrootr   rN   c              	   C   s  t j|t}|du rEt j|st jt j|trd}n&t jt j|tr8t jt j|tr8d}ntdj	di t
|d|| _|du rwt j|rst|}t|}W d   n1 sew   Y  t j||| _n|| _n|| _| t}|dur| t j|  t | d| _W d   n1 sw   Y  n| j| _|| _|  }z|dd}	|	du rd	nt|	}
W n ty   d	}
Y nw |
d
vrt|
|dD ]\}}| dvrt|q|du rtt j|   t|}t!|   | j| j"d}t#$| || i | _%| jt jdd|   d}|r?| | j%&t'| W d   n	1 s:w   Y  | jd|   d}|rf| | j%&t'| W d   n	1 saw   Y  t(| j|  | j)d< t*|  | j)d< t+|  | j)d< t,|  | j)d< dS )a  Open a repository on disk.

        Args:
          root: Path to the repository's root.
          object_store: ObjectStore to use; if omitted, we use the
            repository's default object store
          bare: True if this is a bare repository.
        NFT%No git repository was found at {path}r   s   
r   r   r   )r   r
   r0  )r1  loggerrK   r   )basedirr   rh  rn  rq  zpost-receiverS   )-rh   r   r   
CONTROLDIRisfileisdir	OBJECTDIRREFSDIRr   formatr  r   openr  _controldirr   	COMMONDIR
controldirr   r  r  
_commondirr*  rj   r  ro   r  r   lowerr  r!   from_configrF   r5   _write_reflogr   rU   r   r=  r   r   rJ   r   r   r   )rR   r  r   r   hidden_pathr   r   rF   r{   repository_format_versionformat_versionr  _valuerB   
graft_filerS   rS   rT   rU   l  s   


zRepo.__init__c              
   C   s   ddl m} tj|  dt|}	zttj|	 W n	 t	y'   Y nw |d u r4| 
 }
t|
}t| |d u rBtt }|d u rHd}t|	d}||||||||d  W d    d S 1 sgw   Y  d S )Nr
   )format_reflog_linelogsr   abr   )reflogr  rh   r   r   r  r   makedirsdirnameFileExistsErrorr7  r   r   r  rs  r  write)rR   rB  old_shanew_shara  ro  rp  r`  r  r   r{   r   rS   rS   rT   r    s0   "zRepo._write_reflog.c                 C   s`   d}t j|}|r#z| |W S  ty    t j|\}}Y nw |s
tdjdi t|d)zIterate 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 '.')
        Tr  r  NrS   )rh   r   abspathr   rr   r  r  )r&  start	remainingr   rS   rS   rT   discover  s   

zRepo.discoverc                 C      | j S )z)Return the path of the control directory.)r  r   rS   rS   rT   r    s   zRepo.controldirc                 C   r  )zReturn 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   rS   rS   rT   rF     s   zRepo.commondirc                 C   s   t j| jd}t|d}|d W d   n1 sw   Y  t |}zt ||jtj	A  W n
 t
y=   Y dS w t |}t | |j|jk}|jtj	@ dk}|oY|S )r   z.probe-permissionsw NFr   )rh   r   r   r  r  lstatchmodst_modestatS_IXUSRPermissionErrorunlink)rR   fnamer   st1st2mode_differsst2_has_execrS   rS   rT   r     s   


zRepo._determine_file_modec                 C   r   r   r   r   rS   rS   rT   r     r   zRepo._determine_symlinksc                 C   sV   | tjj}ttj|  |d}|| W d   dS 1 s$w   Y  dS )r   wbN)lstriprh   r   sepr   r   r  r  )rR   r   r   r   rS   rS   rT   r   %  s   "zRepo._put_named_filec                 C   s4   zt t j|  | W d S  ty   Y d S w rP   )rh   r  r   r   r  FileNotFoundErrorr   rS   rS   rT   r   0  s
   zRepo._del_named_filec                 C   sJ   |du r|   }|tjj}zttj||dW S  ty$   Y dS w )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.
          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  r  rh   r   r  r  r   r  )rR   r   r  rS   rS   rT   r   6  s   zRepo.get_named_filec                 C   s   t j|  tS )zReturn path to the index file.)rh   r   r   r  INDEX_FILENAMEr   rS   rS   rT   
index_pathM  s   zRepo.index_pathr   c                 C   s$   ddl m} |  st||  S )r   r
   r   )rE   r   	has_indexr   r  )rR   r   rS   rS   rT   r   Q  s   zRepo.open_indexc                 C   s   | j  S )zCheck if an index is present.r   r   rS   rS   rT   r  ^  s   zRepo.has_indexfs_pathsc                 C   s  t | j}t|ttt jfr|g}t|}ddlm	}m
}m}m} |  }|  }|D ]}	t|	ts8t |	}	t j|	rFtd|	d||	}
t j||	}zt |}W n typ   z||
= W n	 tym   Y nw Y q,w t|jr|||}|r|||
< q,z||
= W q, ty   Y q,w t|jst|jsz||
= W q, ty   Y q,w |||}|||	}| j| |||j||
< q,|  dS )zpStage a set of paths.

        Args:
          fs_paths: List of paths, relative to the repository path
        r
   )_fs_to_tree_pathblob_from_path_and_statindex_entry_from_directoryindex_entry_from_statzpath z4 should be relative to repository root, not absoluteN)rh   fsencoder   r   rx  r   PathLiker   rE   r  r  r  r  r   get_blob_normalizerisabsr   r   r  OSErrorro   r  S_ISDIRr  S_ISREGS_ISLNKcheckin_normalizer   ry  r  r  )rR   r  root_path_bytesr  r  r  r  rE   blob_normalizerfs_path	tree_path	full_pathstrx   blobrS   rS   rT   staged  s\   








z
Repo.stagec                 C   s  ddl m}m} |  }z| d j}W n ty-   |D ]	}||}||= q|  Y dS w |D ]}||}z| j| }t|t	sCJ |
| jj|}	W n% tyq   z||= W Y q0 typ }
 ztd|  d|
d}
~
ww w d}zttj| j|}W n	 ty   Y nw || d jdf| d jdf|r|jnd|r|jnd|	d |r|jnd|r|jndt| |	d  j|	d ddd}|||< q0|  dS )	zUnstage specific file in the index
        Args:
          fs_paths: a list of files to unstage,
            relative to the repository path.
        r
   )
IndexEntryr  r  Nzfile 'z' not in indexr   )ctimemtimedevinomodeuidgidsizer   flagsextended_flags)rE   r  r  r   rc  ro   r  r   r   r,   lookup_pathrM  decoderh   r  r   r   r  rt  st_devst_inost_uidst_gidr   data)rR   r  r  r  rE   tree_idr  r  rc  
tree_entryr   r  index_entryrS   rS   rT   unstage  s^   
	
zRepo.unstageTFs   origin)mkdirr   origincheckoutbranchr   r   r   c                C   s  t | j}
|rt | z|stj||	d}|du rd}n|r$tdt|}z| }|	d|fd|
 |	d|fdd| d	  |
  d
|
 }| j||d |jjd| | jd|d |jjd| jd|d | jd\}}|r}|d nd}|r|s||jd< nt|j|| t|j||||}|rt|j||}nd}|r|dur|  W W |S W W |S W W |S  ty   |   w  ty   |rddl}||  w )a  Clone this repository.

        Args:
          target_path: Target path
          mkdir: Create the target directory
          bare: Whether to create a bare repository
          checkout: Whether or not to check-out HEAD after cloning
          origin: Base name for refs in target repository
            cloned from this repository
          branch: Optional branch or tag to be used as HEAD in the new repository
            instead of this repository's HEAD.
          progress: Optional progress function
          depth: Depth at which to fetch
          symlinks: Symlinks setting (default to autodetect)
        Returns: Created repository as `Repo`
        )r   NTz"checkout and bare are incompatibles   remotes   urls   fetchs   +refs/heads/*:refs/remotes/s   /*s   clone: from r   s   refs/remotes/r  )r`  s	   refs/tagsr  r   r   )rh   r  r   r   r  initr   	init_barer*  r   write_to_pathr   rB   import_refsr  followr;   r9   r:   reset_indexBaseExceptioncloseshutilrmtree)rR   target_pathr   r   r  r  r  r   r   r   encoded_pathr   target_configref_message
head_chain
origin_shaorigin_headhead_refr  r  rS   rS   rT   clone  sv   





z
Repo.clonerc  c              	   C   s   ddl m}m}m}m} |du r&| d }t|tr#|j\}}| |}|j	}| 
 }	|	ddtjdk}
|	ddtjdkrA|}n|}|	dd	d
rM|}nddd}|| j|  | j||
||dS )zReset the index back to a specific tree.

        Args:
          tree: Tree SHA to reset to, None for current HEAD tree.
        r
   )build_index_from_treesymlinkvalidate_path_element_defaultvalidate_path_element_ntfsNr     cores   filemodents   core.protectNTFSs   symlinksTrN   c                 S   sL   t |dt| tr
dnd }||  W d    d S 1 sw   Y  d S )Nr  br  )r  r   r   r  )sourcer   r   rS   rS   rT   
symlink_fn[  s   "z$Repo.reset_index.<locals>.symlink_fn)honor_filemodevalidate_path_elementr  rW   )rE   r  r  r  r  r   r+   objectr#  rc  r*  r3  rh   ru   r   r  r   )rR   rc  r  r  r  r  r  _clsobjr{   r   r!  r  rS   rS   rT   r	  >  s0   



zRepo.reset_indexr   c                 C   sN   ddl m} tj|  d}z||W S  ty&   | }||_| Y S w )Nr
   r   zconfig.worktree)r{   r   rh   r   r   rF   	from_pathr  )rR   r   r   r   rS   rS   rT   r+  k  s   zRepo.get_worktree_configc                 C   sL   ddl m} tj| jd}z||W S  ty%   | }||_| Y S w )r)  r
   r   r{   )r{   r   rh   r   r   r  r%  r  )rR   r   r   r'  rS   rS   rT   r*  v  s   zRepo.get_configc                 C   s`   t j| jd}zt|d}| W  d   W S 1 sw   Y  W dS  ty/   Y dS w )zsRetrieve the description of this repository.

        Returns: A string describing the repository or None.
        r   r  N)rh   r   r   r  r   r  r  rR   r   r   rS   rS   rT   r,    s   (zRepo.get_descriptionc                 C   s   d| j dS )Nz	<Repo at >r  r   rS   rS   rT   __repr__  r  zRepo.__repr__c                 C   s   |  d| dS )r-  r   N)r   r/  rS   rS   rT   r.    s   zRepo.set_descriptionr   c                 C   s   t D ]}ttjj|g|R   q|d u r ttj|t}| |||d}	|d u rM|d u r9ddlm	}
 |

 }z|dd}W n tyL   t}Y nw |	jdt|  |	j||d |	S )N)r   r   r
   )r   r  defaultBranchr  )r   r   )BASE_DIRECTORIESrh   r   r   r   r!   r  r  r{   r   defaultrj   ro   DEFAULT_BRANCHrB   set_symbolic_refr1   r   )r&  r   r  r   r   r{   default_branchr   dr'  r   rS   rS   rT   _init_maybe_bare  s"   zRepo._init_maybe_bare)r   r{   r.  r   r   c                C   sD   |rt | t j|t}t | t| | j||d|||dS )zCreate a new repository.

        Args:
          path: Path in which to create the repository
          mkdir: Whether to create the directory
        Returns: `Repo` instance
        F)r{   r.  r   )rh   r   r   r   r  r   r0  )r&  r   r   r{   r.  r   r  rS   rS   rT   r    s   

z	Repo.initc           
      C   s  |rt | |du rt j|}t j| t}t j||}t j|t}t|d}|	dt 
| d  W d   n1 sDw   Y  zt | W n	 tyY   Y nw zt | W n	 tyj   Y nw tt j|td}|	t 
|d  W d   n1 sw   Y  tt j|td}|	d W d   n1 sw   Y  tt j|dd}|	| d  W d   n1 sw   Y  | |}	|	  |	S )a6  Create 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
        Nr  s   gitdir: r   s   ../..
HEAD)rh   r   r   basenamer   r  	WORKTREESr  r  r  r  r  GITDIRr  r  r	  )
r&  r   	main_repo
identifierr   main_worktreesdirworktree_controldir
gitdirfiler   rrS   rS   rT   _init_new_working_directory  s@   
z Repo._init_new_working_directory)r   r   r{   r.  c                C   s$   |rt | | j||d|||dS )zCreate 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)r   r{   r.  )rh   r   r0  )r&  r   r   r   r{   r.  rS   rS   rT   r    s   
zRepo.init_barec                 C   s   | j   dS )z*Close any files opened by this repository.N)r   r  r   rS   rS   rT   r    s   z
Repo.closec                 C   s   | S rP   rS   r   rS   rS   rT   	__enter__  r   zRepo.__enter__c                 C   s   |    d S rP   )r  )rR   exc_typeexc_valexc_tbrS   rS   rT   __exit__  s   zRepo.__exit__c                 C   sN   i }|   }z| j| jd  j}t||| j|W S  ty&   t|| Y S w )zReturn a BlobNormalizer object.r  )r7  r   rB   rc  r    ro   r   )rR   git_attributesconfig_stackrc  rS   rS   rT   r  !  s   zRepo.get_blob_normalizerc                 C   s   t j|  ddS )zGReturn the path of the sparse-checkout file in this repo's control dir.rK   zsparse-checkout)rh   r   r   r  r   rS   rS   rT   _sparse_checkout_file_path1  s   zRepo._sparse_checkout_file_pathc                 C   s0   |   }|ddd |ddd |  dS )zBEnsure the repository is configured for cone-mode sparse-checkout.r  s   sparseCheckout   true   sparseCheckoutConeN)r*  r   r  )rR   r{   rS   rS   rT   configure_for_cone_mode5  s   zRepo.configure_for_cone_modec                 C   s4   |   }z|dd}|dkW S  ty   Y dS w )zPReturn True if 'core.sparseCheckoutCone' is set to 'true' in config, else False.rD  rF  rE  F)r*  rj   ro   )rR   r{   sc_conerS   rS   rT   infer_cone_mode<  s   
zRepo.infer_cone_modec                 C   sb   |   }z!t|dd}dd |D W  d   W S 1 sw   Y  W dS  ty0   g  Y S w )zReturn a list of sparse-checkout patterns from info/sparse-checkout.

        Returns:
            A list of patterns. Returns an empty list if the file is missing.
        r   rd  c                 S   r\  rS   r8  r:  rS   rS   rT   r  O  r]  z5Repo.get_sparse_checkout_patterns.<locals>.<listcomp>N)rC  r  r  r&  rS   rS   rT   get_sparse_checkout_patternsF  s   (z!Repo.get_sparse_checkout_patternspatternsc                 C   st   t j|  d}t j|dd |  }t|ddd}|D ]	}||d  qW d   dS 1 s3w   Y  dS )	zWrite the given sparse-checkout patterns into info/sparse-checkout.

        Creates the info/ directory if it does not exist.

        Args:
            patterns: A list of gitignore-style patterns to store.
        rK   T)exist_okr  r   rJ  r  N)rh   r   r   r  r  rC  r  r  )rR   rL  info_dirr   r   patrS   rS   rT   set_sparse_checkout_patternsS  s   "z!Repo.set_sparse_checkout_patternsdirsc                 C   sP   ddg}|r!|D ]}| d}d| d}|r ||vr || q| | dS )a!  Write the given cone-mode directory patterns into info/sparse-checkout.

        For each directory to include, add an inclusion line that "undoes" the prior
        ``!/*/`` 'exclude' that re-includes that directory and everything under it.
        Never add the same line twice.
        z/*z!/*//N)r9  r   rP  )rR   rQ  rL  r/  r   rS   rS   rT   set_cone_mode_patternsc  s   

zRepo.set_cone_mode_patternsr  rW   )r  rP   r  )rN   r  r  )NNNN)NF)5rY   rZ   r[   r\   rx  __annotations__r  r   r%   rU   r  classmethodr  r  rF   r   r   r   r   r   r  r   r  r	   r   rh   r  r   r  r   r  r  r	  r+  r*  r,  r(  r.  r0  r  r;  r  creater  r<  r@  r  rC  rG  rI  rK  rP  rS  rS   rS   rS   rT   r  W  s   
 
]






B=
_
-

%


$r  c                   @   s   e Zd Z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dZdddZdddZdd Zedd ZdS ) 
MemoryRepozRepo 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.
    rN   Nc                 C   sN   ddl m} g | _ti | jd}t| t | i | _d| _	| | _
d| _dS )z"Create a new repository in memory.r
   r   r  TN)r{   r   _reflogr4   _append_reflogr   rU   r"   _named_filesr   _config_description)rR   r   refs_containerrS   rS   rT   rU   {  s   
zMemoryRepo.__init__c                 G   s   | j | d S rP   )rX  r   )rR   rI  rS   rS   rT   rY    s   zMemoryRepo._append_reflogc                 C   rO   rP   r\  r/  rS   rS   rT   r.    rV   zMemoryRepo.set_descriptionc                 C   r  rP   r^  r   rS   rS   rT   r,    s   zMemoryRepo.get_descriptionc                 C   r   r   r   r   r   rS   rS   rT   r     r   zMemoryRepo._determine_file_modec                 C   r   r_  r   r   rS   rS   rT   r     r   zMemoryRepo._determine_symlinksc                 C   s   || j |< dS )r   N)rZ  r   rS   rS   rT   r     s   zMemoryRepo._put_named_filec                 C   s$   z| j |= W d S  ty   Y d S w rP   )rZ  ro   r   rS   rS   rT   r     s
   zMemoryRepo._del_named_filec                 C   s"   | j |d}|du rdS t|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)rZ  rj   r   )rR   r   r  r   rS   rS   rT   r     s   zMemoryRepo.get_named_filer   c                 C   s   t )zFail to open index for this repo, since it is bare.

        Raises:
          NoIndexPresent: Raised when no index is present
        )r   r   rS   rS   rT   r     s   zMemoryRepo.open_indexc                 C   r  )zKRetrieve the config object.

        Returns: `ConfigFile` object.
        )r[  r   rS   rS   rT   r*    s   zMemoryRepo.get_configc                 C   sL   |  }|D ]}|j | q| D ]\}}|j|| q|jdd |S )zCreate a new bare repository in memory.

        Args:
          objects: Objects for the new repository,
            as iterable
          refs: Refs as dictionary, mapping names
            to object SHA1s
        Tr  )r   ry  r   rB   r{  r   )r&  rA   rB   r'  r$  refnamer   rS   rS   rT   r    s   
zMemoryRepo.init_barerW   rP   r  )rY   rZ   r[   r\   rU   rY  r.  r,  r   r   r   r   r   r   r*  rU  r  rS   rS   rS   rT   rW  t  s    




	

rW  rP   rW   )or\   rh   r  r   rs  rT  collections.abcr   ior   typingr   r   r   r   r   r	   r{   r   r   rE   r   errorsr   r   r   r   r   r   r   r   r   filer   rJ   r   r   r   r   r   line_endingr   r    r   r!   r"   r#   r$   r%   r&   rA   r'   r(   r)   r*   r+   r,   r-   r.   packr/   rB   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   r  r  r  REFSDIR_TAGSREFSDIR_HEADSr  r  r4  r3  r*  r,  r$  rM   r^   tuplerx  rz   r   r   r   r  r   r   r   r   r   r   r  r  r  r  rW  rS   rS   rS   rT   <module>   s    	, (
L	&
2
!
     b      #