
    %j%              	         d dl m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 d dlmZ d dlmZmZ d dlmZmZ d d	lmZmZ erd d
lmZ d dlmZ dZdEdZdddFdZdGdZdHdZ dIdZ!edJdKd#            Z"dLdHd$Z#ed%         Z$	  ej%        d&d'&                    e$j'                   d(          Z(dMd+Z)d,Z*dNd3Z+d4 d5 d6 d7 d8 d9 d: e+d;Z,dOd@Z-dLdHdAZ.dLdPdBZ/e
 G dC dD                      Z0dS )Q    )annotationsN)contextmanager)	dataclass)Path)TemporaryDirectory)TYPE_CHECKINGLiteral)urlsplit
urlunsplit)BuiltinModuleErrorGitError)Iterator)Modulezgriffe-worktree-valuestrreturnc                    t          j        d|           } t          j        dd|           } t          j        dd|                               d          S )NNFKCz[^\w]+-z[-\s]+)unicodedata	normalizeresubstrip)r   s    \/home/rurouni/.hermes/hermes-agent/venv/lib/python3.11/site-packages/griffe/_internal/git.py
_normalizer      sI    !&%00EF9c5))E6)S%((..s333    Tcheckargsr   boolc                    t          j        dg|ddt           j        t           j        d          }| r1|j        dk    r&t          |j                                                  |j                                        S )NgitFTutf8)r   textstdoutstderrencodingr   )
subprocessrunPIPESTDOUT
returncoder   r&   r   )r   r    processs      r   _gitr/   $   s|    n	   G  /#q((w~++--...>!!!r   path
str | PathNonec                    t          j        d          st          d          	 t          dt	          |           dd           dS # t
          $ r}t          d|            |d}~ww xY w)zDeprecated. Assert that a directory is a Git repository.

    Parameters:
        path: Path to a directory.

    Raises:
        OSError: When the directory is not a Git repository.
    r#   z2Could not find git executable. Please install git.-C	rev-parsez--is-inside-work-treezNot a git repository: N)shutilwhichRuntimeErrorr/   r   r   OSError)r0   errors     r   _assert_git_repor;   2   s     < QOPPPBT3t99k+BCCCCC B B B5t5566EABs   A 
A(A##A(repoc                2   t          | t                    rt          |           } |                                 s| j        } 	 t          ddd          }n*# t          $ r}t          d|  d|pd           |d}~ww xY w|                    dd	          d
         S )zDeprecated. Get latest tag of a Git repository.

    Parameters:
        repo: The path to Git repository.

    Returns:
        The latest tag.
    tagz-lz--sort=-creatordatezCannot list Git tags in z: zno tagsN
   r   )
isinstancer   r   is_dirparentr/   r   split)r<   outputr:   s      r   _get_latest_tagrF   C   s     $ Dzz;;== {[eT#899 [ [ [N$NN%:L9NNOOUZZ[<<a  ##s   A 
A:A55A:r   c                    t          | t                    rt          |           } |                                 s| j        } t          t          dt          |           dd                    S )zDeprecated. Get the root of a Git repository.

    Parameters:
        repo: The path to a Git repository.

    Returns:
        The root of the repository.
    r4   r5   z--show-toplevel)rA   r   r   rB   rC   r/   )r<   s    r   _get_repo_rootrH   W   s[     $ Dzz;;== {T3t99k3DEEFFFr   .HEADrefIterator[Path]c              #    K   t          |            t          |                                           j        }t	          |          }t          t           | d| d          5 }t          j        	                    ||          }d| }	 t          dt          |           ddd|||           n%# t          $ r}t          d|           |d	}~ww xY w	 t          |          V  t          dt          |           dd
|d           t          dt          |           ddd           t          dt          |           dd|d           nj# t          dt          |           dd
|d           t          dt          |           ddd           t          dt          |           dd|d           w xY w	 d	d	d	           d	S # 1 swxY w Y   d	S )a  Deprecated. Context manager that checks out the given reference in the given repository to a temporary worktree.

    Parameters:
        repo: Path to the repository (i.e. the directory *containing* the `.git` directory)
        ref: A Git reference such as a commit, tag or branch.

    Yields:
        The path to the temporary worktree.

    Raises:
        OSError: If `repo` is not a valid `.git` repository
        RuntimeError: If the `git` executable is unavailable, or if it cannot create a worktree
    r   )prefixzgriffe-r4   worktreeaddz-bzCould not create git worktree: NremoveFr   prunebranchz-D)r;   r   resolvenamer   r   _WORKTREE_PREFIXosr0   joinr/   r   r   r8   )r<   rK   	repo_namenormreftmp_dirlocation
tmp_branchr:   s           r   _tmp_worktreer^   g   sK      TT

""$$)IooG	&6#N	#N#NG#N#N#N	O	O	O KSZ7<<11(w((
	Us4yy*eT:xQTUUUU 	U 	U 	UHHHIIuT	U	Kx..   s4yy*hNNNNs4yy*gUCCCCs4yy(D*EJJJJJ s4yy*hNNNNs4yy*gUCCCCs4yy(D*EJJJJJJK K K K K K K K K K K K K K K K K KsP   $&G#B/.G/
C9CCGE&A&GA'F33GGGc           	     &   t          j        d          x}r|S dt          j        dd          z   dz   }t          dt          |           ddd	d
|          }|                    d          r,|                    ddd                              ddd          }|                    d          }|                    d          rPt          t          |                    }|d         	                    dd          d         |d<   t          |          }|S )NGRIFFE_GIT_REMOTE_URLzremote.GRIFFE_GIT_REMOTEoriginz.urlr4   configz	--default z--getzgit@:/r@   https://z.git)zhttp://rg   @)rW   getenvr/   r   
startswithreplaceremovesuffixlistr
   rD   r   )r<   git_urlremoteurlpartss       r   _get_git_remote_urlrr      s   )3444w #6AAAFJF4THk2wOOG&!! N//#sA..66vz1MM""6**G 122 '))**qk''Q//3X&&Nr   )githubgitlab	sourcehutgiteagogsforgejocodebergradicle(|)git_remote_urlKnownGitService | Nonec                    t          j        d          x}r|t          j        vrd S |S t                              t          |           j                  x}r|                    d          S d S )NGRIFFE_GIT_SERVICEr@   )	rW   rj   KnownGitService__args___service_researchr
   netlocgroup)r~   servicematchs      r   _get_git_known_servicer      sm    )0111w /2224""8N#;#;#BCCCu {{1~~4r   z,https://app.radicle.at/nodes/seed.radicle.at
url_or_ridcommit_hashfilepathlinenoint	endlinenoc                    |                      d          r t           d|                     dd           n| }| d| d| d| S )Nzrad://rf   z//rd   /tree/#L)rk   _RADICLE_URLrl   )r   r   r   r   r   urls         r   _get_radicle_urlr      sc    >H>S>ST\>]>]
m\
:
:J..tR88
:
:
:cmC;;;;x;;6;;;r   c           	     "    |  d| d| d| d| 	S Nz/blob/rf   r   -L r   chfplnelns        r   <lambda>r      s,    c+O+O+O+Ob+O+OB+O+O#+O+O r   c           	     "    |  d| d| d| d| 	S )Nz/-/blob/rf   r   r   r   r   s        r   r   r      s,    c+Q+Q2+Q+Q+Q+Qb+Q+QC+Q+Q r   c                    |  d| d| d| S )Nr   rf   r   r   r   s        r   r   r      s$    .K.KB.K.K.K.Kr.K.K r   c           	     "    |  d| d| d| d| 	S r   r   r   s        r   r   r      s,    C)M)Mr)M)MB)M)M")M)M)M)M r   c           	     "    |  d| d| d| d| 	S Nz/src/commit/rf   r   r   r   r   s        r   r   r      s,    S*T*Tb*T*T2*T*T*T*Ts*T*T r   c           	     "    |  d| d| d| d| 	S r   r   r   s        r   r   r      s-    -W-W-W-Wb-W-WB-W-WRU-W-W r   c           	     "    |  d| d| d| d| 	S r   r   r   s        r   r   r      s-    s,V,V,V,VR,V,V2,V,VQT,V,V r   )rs   rt   ru   rw   rv   ry   rx   rz   r   r   
remote_url
str | Nonec                    t          |t                    r|                                }t          |          |||||          S )N)rA   r   as_posix_service_to_url)r   r   r   r   r   r   s         r   _get_source_linkr      sB     (D!! '$$&&7#JXvyYYYr   c                p    t          j        d          x}r|S t          dt          |           dd          S )NGRIFFE_GIT_COMMIT_HASHr4   r5   rJ   )rW   rj   r/   r   )r<   r   s     r   _get_git_commit_hashr      s:    i 8999{ c$iif555r   c                `    t          dt          |          dt          |           d           S )Nr4   zcheck-ignoreFr   )r/   r   )r   r<   s     r   _is_trackedr      s*    D#d))^S]]%PPPPPr   c                  d    e Zd ZU dZded<   	 ded<   	 ded<   	 ded<   	 edd            ZddZdS )GitInfoz#Information about a Git repository.r   
repositoryr   r   r   r   r   packager   r   GitInfo | Nonec                   	 t          |j        t                    r|j        d         n|j        }n# t          $ r Y dS w xY w	 t	          |          }t          |                    |          |          sdS t          |          }t          |          x}sdS t          |          }n# t          t          t          f$ r Y dS w xY w | ||||          S )zCreate a GitInfo instance from a Griffe package.

        Returns:
            The GitInfo instance, or None if unknown.
        r   N)r   r   r   r   )rA   r   rn   r   rH   r   relative_torr   r   r   r   
ValueErrorr9   )clsr   r0   r<   r   r   r   s          r   from_packagezGitInfo.from_package   s   	*4W5Et*L*Lb7#A&&RYRbDD! 	 	 	44		!$''Dt//55t<< t,T22J5jAAAG t.t44KK*g. 	 	 	 44	 sdG
Xcdddds*   .1 
??2B) 7 B) B) )CCr   r1   r   r   r   r   c                H    t          | j        | j        | j        |||          S )zGet the source link for the file at the given line numbers.

        Returns:
            The source link, or None if unknown.
        )r   r   r   r   )selfr   r   r   s       r   get_source_linkzGitInfo.get_source_link	  s&      dot?OQY[aclmmmr   N)r   r   r   r   )r   r1   r   r   r   r   r   r   )__name__
__module____qualname____doc____annotations__classmethodr   r   r   r   r   r   r      s         --)AOOO/>e e e [e0n n n n n nr   r   )r   r   r   r   )r    r   r   r!   r   r   )r0   r1   r   r2   )r<   r1   r   r   )r<   r1   r   r   )rI   rJ   )r<   r1   rK   r   r   rL   )rI   )r~   r   r   r   )r   r   r   r   r   r   r   r   r   r   r   r   )r   r   r   r   r   r   r   r1   r   r   r   r   r   r   )r   r1   r<   r1   r   r!   )1
__future__r   rW   r   r6   r)   r   
contextlibr   dataclassesr   pathlibr   tempfiler   typingr   r	   urllib.parser
   r   griffe._internal.exceptionsr   r   collections.abcr   griffe._internal.modelsr   rV   r   r/   r;   rF   rH   r^   rr   r   compilerX   r   r   r   r   r   r   r   r   r   r   r   r   r   <module>r      s  
 # " " " " " 				 				          % % % % % % ! ! ! ! ! !       ' ' ' ' ' ' ) ) ) ) ) ) ) ) - - - - - - - - D D D D D D D D /((((((...... & 4 4 4 4 $( " " " " " "B B B B"$ $ $ $(G G G G  K K K K KB    ( lm !bjCchh'?@@CCCDD   $ >< < < < POQQKKMMTTWWVV 
Z 
Z 
Z 
Z6 6 6 6 6Q Q Q Q Q +n +n +n +n +n +n +n +n +n +nr   