
    Ji%              	         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d*dZddd+dZd,dZd-dZ d.dZ!ed/d0d       Z"d1d-dZ#ed   Z$	  ejJ                  ddjM                  e$jN                         d      Z(d2dZ)dZ*d3dZ+d d d d  d! d" d# e+d$Z,	 	 	 	 	 	 	 	 	 	 	 	 	 	 d4d%Z-d1d-d&Z.d1d5d'Z/e
 G d( d)             Z0y)6    )annotationsN)contextmanager)	dataclass)Path)TemporaryDirectory)TYPE_CHECKINGLiteral)urlsplit
urlunsplit)BuiltinModuleErrorGitError)Iterator)Modulezgriffe-worktree-c                    t        j                  d|       } t        j                  dd|       } t        j                  dd|       j	                  d      S )NNFKCz[^\w]+-z[-\s]+)unicodedata	normalizeresubstrip)values    f/var/www/html/BankruptcyAI-uat/bankruptcy-ai/venv/lib/python3.12/site-packages/griffe/_internal/git.py
_normalizer      sD    !!&%0EFF9c5)E66)S%(..s33    Tcheckc                   t        j                  dg|ddt         j                  t         j                  d      }| r2|j                  dk7  r#t        |j                  j                               |j                  j                         S )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                    t        j                  d      st        d      	 t        dt	        |       dd       y# 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,   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c                   t        | t              rt        |       } | j                         s| j                  } 	 t        ddd      }|j                  dd	      d
   S # t        $ r}t        d|  d|xs d       |d}~ww xY w)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 	A?$A::A?c                    t        | t              rt        |       } | j                         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.
    r.   r/   z--show-toplevel)r<   r3   r   r=   r>   r,   )r@   s    r   _get_repo_rootrD   W   sD     $Dz;;={{T3t9k3DEFFr   c              #    K   t        |        t        |       j                         j                  }t	        |      }t        t         | d| d      5 }t        j                  j                  ||      }d| }	 t        dt        |       ddd|||       	 t        |       t        dt        |       dd
|d       t        dt        |       ddd       t        dt        |       dd|d       	 d	d	d	       y	# t        $ r}t        d|       |d	}~ww xY w# t        dt        |       dd
|d       t        dt        |       ddd       t        dt        |       dd|d       w xY w# 1 sw Y   y	xY ww)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   sj     TT
""$))IoG	&6%7	{!G9A#N	O KSZ77<<1wi(
	Us4y*eT:xQTU	Kx. s4y*hNs4y*gUCs4y(D*EJK K
  	U!@HIuT	U s4y*hNs4y*gUCs4y(D*EJK KsV   AE9&E-;C;D$AE-2	E9;	DDDE-AE**E--E62E9c           	        t        j                  d      x}r|S dt        j                  dd      z   dz   }t        dt        |       ddd	d
|      }|j	                  d      r$|j                  ddd      j                  ddd      }|j                  d      }|j	                  d      r:t        t        |            }|d   j                  dd      d   |d<   t        |      }|S )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)*qk''Q/3X&Nr   )githubgitlab	sourcehutgiteagogsforgejocodebergradicle(|)c                    t        j                  d      x}r|t        j                  vry |S t        j                  t        |       j                        x}r|j                  d      S y )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                x    | j                  d      rt         d| j                  dd       n| }| d| d| d| S )Nzrad://r_   z//r]   /tree/#L)rd   _RADICLE_URLre   )
url_or_ridcommit_hashfilepathlineno	endlinenourls         r   _get_radicle_urlr      sN    >H>S>ST\>]\N!J..tR89
:cmCU&Qxj6(;;r   c           	     "    |  d| d| d| d| 	S Nz/blob/r_   r   -L r   chfplnelns        r   <lambda>r      s#    cU&AbTB4r#+O r   c           	     "    |  d| d| d| d| 	S )Nz/-/blob/r_   r   r   r   r   s        r   r   r      s#    cU(2$at2bTC5+Q r   c                    |  d| d| d| S )Nr   r_   r   r   r   s        r   r   r      s    VB4qBrd.K r   c           	     "    |  d| d| d| d| 	S r   r   r   s        r   r   r      s#    C5rd!B4r"Ru)M r   c           	     "    |  d| d| d| d| 	S Nz/src/commit/r_   r   r   r   r   s        r   r   r      s#    SEbT2$bBse*T r   c           	     "    |  d| d| d| d| 	S r   r   r   s        r   r   r      s%    uLAbTB4rRUQV-W r   c           	     "    |  d| d| d| d| 	S r   r   r   s        r   r   r      s%    se<t1RD2$bQTPU,V r   )rl   rm   rn   rp   ro   rr   rq   rs   c                f    t        |t              r|j                         }t        |    |||||      S )N)r<   r   as_posix_service_to_url)r   
remote_urlr   r   r   r   s         r   _get_source_linkr      s4     (D!$$&7#JXvyYYr   c                b    t        j                  d      x}r|S t        dt        |       dd      S )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                H    t        dt        |      dt        |       d       S )Nr.   zcheck-ignoreFr   )r,   r3   )r   r@   s     r   _is_trackedr      s     D#d)^S]%PPPr   c                  \    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y)GitInfoz#Information about a Git repository.r   
repositoryry   r   r3   r   r   c                p   	 t        |j                  t              r|j                  d   n|j                  }	 t	        |      }t        |j                  |      |      syt        |      }t        |      x}syt        |      } | ||||      S # t        $ r Y yw xY w# t        t        t        f$ r Y yw xY w)zCreate 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_packagezGitInfo.from_package   s    	*4W5E5Et*L7##A&RYRbRbD	!$'Dt//5t<,T2J5jAAGA.t4K
 dG
Xcdd " 		 *g. 	 	s.   5B &B B 8B 	BBB54B5c                ^    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*      doot?O?OQY[aclmmr   N)r   r   returnzGitInfo | None)r   
str | Pathr   intr   r   r   
str | None)__name__
__module____qualname____doc____annotations__classmethodr   r   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 !bjjAchh'?'?@ACD$ >< PQKMTWV
Z
Z
Z 
Z 	
Z
 
Z 
Z 
Z6Q +n +n +nr   