
    i%              	      (   S SK Jr  S SKrS SKrS SKrS SKrS SKrS SKJr  S SK	J
r
  S SKJr  S SKJr  S SKJrJr  S SKJrJr  S S	KJrJr  \(       a  S S
KJr  S SKJr  SrS*S jrSS.S+S jjrS,S jrS-S jr S.S jr!\S/S0S jj5       r"S1S-S jjr#\S   r$ \RJ                  " SSRM                  \$RN                  5       S35      r(S2S jr)Sr*S3S jr+S S S S  S! S" S# \+S$.r,              S4S% jr-S1S-S& jjr.S1S5S' jjr/\
 " S( S)5      5       r0g)6    )annotationsN)contextmanager)	dataclass)Path)TemporaryDirectory)TYPE_CHECKINGLiteral)urlsplit
urlunsplit)BuiltinModuleErrorGitError)Iterator)Modulezgriffe-worktree-c                    [         R                  " SU 5      n [        R                  " SSU 5      n [        R                  " SSU 5      R	                  S5      $ )NNFKCz[^\w]+-z[-\s]+)unicodedata	normalizeresubstrip)values    N/home/james-whalen/.local/lib/python3.13/site-packages/griffe/_internal/git.py
_normalizer      sD    !!&%0EFF9c5)E66)S%(..s33    Tcheckc           	        [         R                  " S/UQSS[         R                  [         R                  SS9nU (       a3  UR                  S:w  a#  [        UR                  R                  5       5      eUR                  R                  5       $ )NgitFTutf8)r   textstdoutstderrencodingr   )
subprocessrunPIPESTDOUT
returncoder   r"   r   )r   argsprocesss      r   _gitr,   $   so    nn	  G ##q(w~~++-..>>!!r   c                    [         R                  " S5      (       d  [        S5      e [        S[	        U 5      SS5        g! [
         a  n[        SU  35      UeSnAff = f)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,   strr   OSError)patherrors     r   _assert_git_repor7   2   s_     <<OPPBT3t9k+BC B.tf56EABs   A   
A
AAc                $   [        U [        5      (       a  [        U 5      n U R                  5       (       d  U R                  n  [        SSS5      nUR                  SS	5      S
   $ ! [         a   n[        SU  SU=(       d    S 35      UeSnAff = f)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   )
isinstancer3   r   is_dirparentr,   r   split)repooutputr6   s      r   _get_latest_tagrB   C   s     $Dz;;=={{[eT#89 <<a ##  [1$r%:L99MNOUZZ[s   A% %
B/B

Bc                    [        U [        5      (       a  [        U 5      n U R                  5       (       d  U R                  n [        [        S[        U 5      SS5      5      $ )zDeprecated. Get the root of a Git repository.

Parameters:
    repo: The path to a Git repository.

Returns:
    The root of the repository.
r.   r/   z--show-toplevel)r<   r3   r   r=   r>   r,   )r@   s    r   _get_repo_rootrD   W   sI     $Dz;;=={{T3t9k3DEFFr   c              #    #    [        U 5        [        U 5      R                  5       R                  n[	        U5      n[        [         U SU S3S9 n[        R                  R                  XC5      nSU 3n [        S[        U 5      SSSXeU5         [        U5      v   [        S[        U 5      SS
USS9  [        S[        U 5      SSSS9  [        S[        U 5      SSUSS9   S	S	S	5        g	! [         a  n[        SU 35      UeS	nAff = f! [        S[        U 5      SS
USS9  [        S[        U 5      SSSS9  [        S[        U 5      SSUSS9  f = f! , (       d  f       g	= f7f)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-r.   worktreeaddz-bzCould not create git worktree: NremoveFr   prunebranchz-D)r7   r   resolvenamer   r   _WORKTREE_PREFIXosr5   joinr,   r3   r   r2   )r@   ref	repo_namenormreftmp_dirlocation
tmp_branchr6   s           r   _tmp_worktreerW   g   sY     TT
""$))IoG	&6%7	{!G9A#N	OSZ77<<1wi(
	Us4y*eT:QTU	Kx. s4y*hNs4y*gUCs4y(D*EJ 
P	O
  	U!@HIuT	U s4y*hNs4y*gUCs4y(D*EJ 
P	OsV   AE(%E7C-DAE$	E(-
D7DDEAEE
E%!E(c           	        [         R                  " S5      =n(       a  U$ S[         R                  " SS5      -   S-   n[        S[        U 5      SSS	S
U5      nUR	                  S5      (       a$  UR                  SSS5      R                  SSS5      nUR                  S5      nUR	                  S5      (       a:  [        [        U5      5      nUS   R                  SS5      S   US'   [        U5      nU$ )NGRIFFE_GIT_REMOTE_URLzremote.GRIFFE_GIT_REMOTEoriginz.urlr.   configz	--default z--getzgit@:/r;   https://z.git)zhttp://r`   @)rO   getenvr,   r3   
startswithreplaceremovesuffixlistr
   r?   r   )r@   git_urlremoteurlpartss       r   _get_git_remote_urlrk      s    ))344w4#6AAFJF4THk2wOG&!!//#sA.66vz1M""6*G 122)*qk''Q/3X&Nr   )githubgitlab	sourcehutgiteagogsforgejocodebergradicle(|)c                    [         R                  " S5      =n(       a  U[        R                  ;  a  g U$ [        R                  [        U 5      R                  5      =n(       a  UR                  S5      $ g )NGRIFFE_GIT_SERVICEr;   )	rO   rc   KnownGitService__args___service_researchr
   netlocgroup)git_remote_urlservicematchs      r   _get_git_known_servicer      s_    ))011w1/222""8N#;#B#BCCuC{{1~r   z,https://app.radicle.at/nodes/seed.radicle.atc                    U R                  S5      (       a  [         SU R                  SS5       3OU nU SU SU SU 3$ )Nzrad://r_   z//r]   /tree/#L)rd   _RADICLE_URLre   )
url_or_ridcommit_hashfilepathlineno	endlinenourls         r   _get_radicle_urlr      sQ    >H>S>ST\>]>]\N!J..tR89
:cmCU&Qxj6(;;r   c           	     "    U  SU SU SU SU 3	$ Nz/blob/r_   r   -L r   chfplnelns        r   <lambda>r      s!    cU&AbTB4r#+Or   c           	     "    U  SU SU SU SU 3	$ )Nz/-/blob/r_   r   r   r   r   s        r   r   r      s!    cU(2$at2bTC5+Qr   c                    U  SU SU SU 3$ )Nr   r_   r   r   r   s        r   r   r      s    VB4qBrd.Kr   c           	     "    U  SU SU SU SU 3	$ r   r   r   s        r   r   r      s!    C5rd!B4r"Ru)Mr   c           	     "    U  SU SU SU SU 3	$ Nz/src/commit/r_   r   r   r   r   s        r   r   r      s!    SEbT2$bBse*Tr   c           	     "    U  SU SU SU SU 3	$ r   r   r   s        r   r   r      s#    uLAbTB4rRUQV-Wr   c           	     "    U  SU SU SU SU 3	$ r   r   r   s        r   r   r      s#    se<t1RD2$bQTPU,Vr   )rl   rm   rn   rp   ro   rr   rq   rs   c                n    [        U[        5      (       a  UR                  5       n[        U    " XX4U5      $ )N)r<   r   as_posix_service_to_url)r   
remote_urlr   r   r   r   s         r   _get_source_linkr      s3     (D!!$$&7#JXyYYr   c                n    [         R                  " S5      =n(       a  U$ [        S[        U 5      SS5      $ )NGRIFFE_GIT_COMMIT_HASHr.   r/   HEAD)rO   rc   r,   r3   )r@   r   s     r   _get_git_commit_hashr      s2    ii 899{9c$if55r   c                J    [        S[        U5      S[        U 5      SS9(       + $ )Nr.   zcheck-ignoreFr   )r,   r3   )r   r@   s     r   _is_trackedr      s     D#d)^S]%PPPr   c                  h    \ rS rSr% SrS\S'    S\S'    S\S'    S\S	'    \SS
 j5       rSS jrSr	g)GitInfo   z#Information about a Git repository.r   
repositoryry   r   r3   r   r   c                    [        UR                  [        5      (       a  UR                  S   OUR                  n [	        U5      n[        UR                  U5      U5      (       d  g[        U5      n[        U5      =n(       d  g[        U5      nU " X5XFS9$ ! [         a     gf = f! [        [        [        4 a     gf = f)ziCreate a GitInfo instance from a Griffe package.

Returns:
    The GitInfo instance, or None if unknown.
r   N)r   r   r   r   )r<   r   rg   r   rD   r   relative_tork   r   r   r   
ValueErrorr4   )clspackager5   r@   r   r   r   s          r   from_packageGitInfo.from_package   s    	*4W5E5Et*L*L7##A&RYRbRbD	!$'Dt//5t<<,T2J5jAAGA.t4K
 d
dd " 		 *g. 	 	s.   :B +B) )B) B) 
B&%B&)C Cc                \    [        U R                  U R                  U R                  XU5      $ )zoGet 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_linkGitInfo.get_source_link	  s'      doot?O?OQYclmmr   r   N)r   r   returnzGitInfo | None)r   
str | Pathr   intr   r   r   
str | None)
__name__
__module____qualname____firstlineno____doc____annotations__classmethodr   r   __static_attributes__r   r   r   r   r      sB    -)AO/>e e0nr   r   )r   r3   r   r3   )r*   r3   r   boolr   r3   )r5   r   r   None)r@   r   r   r3   )r@   r   r   r   ).r   )r@   r   rQ   r3   r   zIterator[Path])r   )r   r3   r   zKnownGitService | None)r   r3   r   r3   r   r3   r   r   r   r   r   r3   )r   ry   r   r3   r   r3   r   r   r   r   r   r   r   r   )r   r   r@   r   r   r   )1
__future__r   rO   r   r0   r%   r   
contextlibr   dataclassesr   pathlibr   tempfiler   typingr   r	   urllib.parser
   r   griffe._internal.exceptionsr   r   collections.abcr   griffe._internal.modelsr   rN   r   r,   r7   rB   rD   rW   rk   ry   compilerP   rz   r{   r   r   r   r   r   r   r   r   r   r   r   <module>r      s[  
 # 	 	    % !  ' ) - D(. & 4 $( "B"$(G  K KB( lm !jjAchh'?'?@ACD$ >< PQKMTWV
Z
Z
Z 
Z 	
Z
 
Z 
Z 
Z6Q +n +n +nr   