o
     {g5                     @  s  d Z ddlmZ g dZddlZddlmZ ddlm	Z	 ddl
Z
ddlmZ ddlmZmZ ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZmZmZ ddlmZmZmZm Z m!Z! ddl"m#Z#m$Z$m%Z% erddl&m'Z' ddlm(Z(m)Z) ddl*m+Z+ ddl,m-Z- ddl.m/Z/ dFddZ0dGddZ1dHd!d"Z2dId$d%Z3dJd*d+Z4e!dKdLd3d4Z5e!dMd7d4Z5dNdOd9d4Z5dPd<d=Z6dQdAdBZ7dRdDdEZ8dS )Sz%General repository-related functions.    )annotations)		rev_parse
is_git_dirtouchfind_submodule_git_dirname_to_objectshort_to_long	deref_tag	to_commitfind_worktree_git_dirN)Path)digits)BadName	BadObject)Git)WorkTreeRepositoryUnsupported)Object)SymbolicReference)cygpath
bin_to_hex
hex_to_bin)OptionalTYPE_CHECKINGUnioncastoverload)AnyGitObjectLiteralPathLike)GitCmdObjectDB)Commit	TagObject)	Reference)Tag   )Repofilenamestrreturnc                 C  s0   t | d	 W d    | S 1 sw   Y  | S )Nab)open)r&    r+   i/var/www/bot.gig.net.ua/public_html/telegram/P1/HellBot/venv/lib/python3.10/site-packages/git/repo/fun.pyr   3   s   
r   dr   boolc                 C  s   t | rSt t | dsdtjv r4t t | dr4t | d}t |p3t |o3t|dS t t | drSt t | drSt t | drSt	| dS )	ax  This is taken from the git setup.c:is_git_directory function.

    :raise git.exc.WorkTreeRepositoryUnsupported:
        If it sees a worktree directory. It's quite hacky to do that here, but at least
        clearly indicates that we don't support it. There is the unlikely danger to
        throw if we see directories which just look like a worktree dir, but are none.
    objectsGIT_OBJECT_DIRECTORYrefsHEADgitdir	commondirgitfileF)
ospisdirjoinosenvironisfileislinkreadlink
startswithr   )r-   headrefr+   r+   r,   r   9   s   
 
$r   dotgitOptional[str]c                 C  s   zt | }W n
 ty   Y dS w t|jsdS z t|   }dd |D D ]\}}|dkr7|  W S q*W dS  tyD   Y dS w )z&Search for a gitdir for this worktree.Nc                 S  s   g | ]	}|  d qS )z: )stripsplit).0liner+   r+   r,   
<listcomp>[   s    z)find_worktree_git_dir.<locals>.<listcomp>r3   )	r9   statOSErrorS_ISREGst_moder   	read_text
splitlines
ValueError)r@   statbuflineskeyvaluer+   r+   r,   r   P   s&   
r   Optional[PathLike]c                 C  s   t | r| S zt| }|  }W d   n1 sw   Y  W n
 ty,   Y dS w |drU|dd }t r@t|}t	
|sQt	t	t	| |}t|S dS )zSearch for a submodule repo.Nzgitdir:    )r   r*   readrstripIOErrorr>   r   	is_cygwinr   r6   isabsnormpathr8   dirnamer   )r-   fpcontentpathr+   r+   r,   r   c   s&   


r   odb'GitCmdObjectDB'hexshaOptional[bytes]c                 C  s&   zt | |W S  ty   Y dS w )z
    :return:
        Long hexadecimal sha1 from the given less than 40 byte hexsha, or ``None`` if no
        candidate could be found.

    :param hexsha:
        hexsha with less than 40 bytes.
    N)r   partial_to_complete_sha_hexr   )r^   r`   r+   r+   r,   r   ~   s
   	r   .repo'Repo'name
return_refLiteral[False]r   c                 C     d S Nr+   rc   re   rf   r+   r+   r,   r         r   Literal[True]&Union[AnyGitObject, SymbolicReference]c                 C  rh   ri   r+   rj   r+   r+   r,   r      rk   Fc              	   C  s   d}| j |rt|dkrt| j|}n|}|du r@dD ]"}zt| || }|r4t| || W   S W  n	 ty?   Y qw |rHtd| |du rPt	|t
| t|S )ah  
    :return:
        Object specified by the given name - hexshas (short and long) as well as
        references are supported.

    :param return_ref:
        If ``True``, and name specifies a reference, we will return the reference
        instead of the object. Otherwise it will raise :exc:`~gitdb.exc.BadObject` or
        :exc:`~gitdb.exc.BadName`.
    N(   )z%szrefs/%szrefs/tags/%szrefs/heads/%szrefs/remotes/%szrefs/remotes/%s/HEADz Couldn't find reference named %r)re_hexsha_shortenedmatchlenr   r^   r   dereference_recursiverM   r   r   r   new_from_shar   )rc   re   rf   r`   baser+   r+   r,   r      s(   tag'Tag'c                 C  s$   	 z| j } W n
 ty   Y | S w q)z>Recursively dereference a tag and return the resulting object.)objectAttributeError)ru   r+   r+   r,   r	      s   
r	   objr   'Commit'c                 C  s,   | j dkr	t| } | j dkrtd|  | S )z?Convert the given object to a commit if possible and return it.ru   commitz'Cannot convert object %r to type commit)typer	   rM   )ry   r+   r+   r,   r
      s
   

r
   revc              
   C  s  | dr	tdd}d}d}d}d}t|}||k r|| dvr'|d7 }q|| }|du rU|dkr8| jj}n'|dkrKtd	t| |d| d
d}nt| |d| }n
|dur_td|j}|d7 }||k r5|| dkr5|d|}	|	dkrt	d| ||d |	 }|dkrn|dkrztt
|}t|j}W n| tt	fy   Y nrw |dv rtd|}|r|jdkrt|}n\	 nZ|dkr|dusJ dd}
z	t|d  }
W n t	y } ztd|d}~ww z||
}W n ty } ztd|
 |d}~ww t| t|j}d}nt	d||f |r.|r.|j|kr.t	d||jf |	d }|}qd}|dkrfd}||k ra|| tv r[|d t||  }|d7 }d
}nn||k sC|sfd}|}zQtt
|}|dkrt|}t|D ]}|jd }q{n3|dkrt|}|r|j|d  }n|dkr|jdkr|j}|||d  }|}nt	d | W n ttfy } ztd!| d"| t| d#|d}~ww ||k s|du rt| |}|}|du rt	d$| ||krt	d%||d| f |S )&a  Parse a revision string. Like :manpage:`git-rev-parse(1)`.

    :return:
        `~git.objects.base.Object` at the given revision.

        This may be any type of git object:

        * :class:`Commit <git.objects.commit.Commit>`
        * :class:`TagObject <git.objects.tag.TagObject>`
        * :class:`Tree <git.objects.tree.Tree>`
        * :class:`Blob <git.objects.blob.Blob>`

    :param rev:
        :manpage:`git-rev-parse(1)`-compatible revision specification as string.
        Please see :manpage:`git-rev-parse(1)` for details.

    :raise gitdb.exc.BadObject:
        If the given revision could not be found.

    :raise ValueError:
        If `rev` couldn't be parsed.

    :raise IndexError:
        If an invalid reflog index is specified.
    z:/z commit by message search (regex)Nr{   r   z^~:@r$   @r"   T)rf   r    {}z*Missing closing brace to define type in %stree) blobr!   ru   z"Require Reference to access reflogz3Support for additional @{...} modes not implementedzInvalid revlog index: %ir   z!Invalid output type: %s ( in %s )z6Could not accommodate requested object type %r, got %s:F
   ~^zInvalid token: %rzInvalid revision spec 'z(' - not enough parent commits to reach ''z*Revision specifier could not be parsed: %sz6Didn't consume complete rev spec %s, consumed part: %s)r>   NotImplementedErrorrq   headrefr   r   r{   findrM   r   r
   r   rx   r|   r	   int	log_entry
IndexErrorr   rs   r   	newhexshar   rangeparentsr   )rc   r}   ry   r   output_typestart	parsed_tolrtokenendrevlog_indexeentrynumfound_digit_r+   r+   r,   r      s   














  



r   )r&   r'   r(   r'   )r-   r   r(   r.   )r@   r   r(   rA   )r-   r   r(   rR   )r^   r_   r`   r'   r(   ra   ).)rc   rd   re   r'   rf   rg   r(   r   )rc   rd   re   r'   rf   rl   r(   rm   )F)rc   rd   re   r'   rf   r.   r(   rm   )ru   rv   r(   r   )ry   r   r(   rz   )rc   rd   r}   r'   r(   r   )9__doc__
__future__r   __all__r9   os.pathr]   r6   pathlibr   rG   stringr   	gitdb.excr   r   git.cmdr   git.excr   git.objectsr   git.refsr   git.utilr   r   r   typingr   r   r   r   r   	git.typesr   r   r   git.dbr   r    r!   git.refs.referencer"   git.refs.tagr#   rt   r%   r   r   r   r   r   r   r	   r
   r   r+   r+   r+   r,   <module>   sF   





:
