
    d=$              
          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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mZ ddlmZ ddlmZ dZd	Zej                            ej                            ej                            e          ej        ej        ej        d
d                    ZefdZefdZedddfdZedfdZ d Z!dddefdZ" G d de          Z#ej$        dk    rd Z% ej&        ej'        e%          Z(dS ej'        Z(dS )z$Utilities for interacting with cgit.    N)Tuple)SkipTestTestCase   )TCP_GIT_PORT)Repogit   testdatareposc                 
   	 t          dg|           }n# t          $ r Y dS w xY wd}|                    |          sdS |t          |          d                             d          }g }|D ]6}	 |                    t          |                     &# t          $ r Y  nw xY wt          |          t          k     r-|                    d           t          |          t          k     -t          |dt                             S )a)  Attempt to determine the version of git currently installed.

    Args:
      git_path: Path to the git executable; defaults to the version in
        the system path.
    Returns: A tuple of ints of the form (major, minor, point, sub-point), or
        None if no git installation was found.
    z	--versiongit_pathNs   git version    .r   )
run_git_or_failOSError
startswithlensplitappendint
ValueError_VERSION_LENtuple)r   outputversion_prefixpartsnumsparts         ^/home/feoh/.local/pipx/venvs/poetry/lib/python3.11/site-packages/dulwich/tests/compat/utils.pygit_versionr!   1   s'    +BBB   tt$N^,, t3~&&(()//55ED  	KKD		"""" 	 	 	EE	 d))l
"
"A d))l
"
"m|m$%%%s    
##0"B
B! B!c                    t          |          }|"t          d                    |                     t          |           t          k    rt          d| t          fz            t          |           } t          |          t          |           k     r5|                     d           t          |          t          |           k     5t          |           } || k     rsd	                    t          t          |                     } d	                    t          t          |                    }t          d                    | |                    dS )a  Require git version >= version, or skip the calling test.

    Args:
      required_version: A tuple of ints of the form (major, minor, point,
        sub-point); omitted components default to 0.
      git_path: Path to the git executable; defaults to the version in
        the system path.
    Raises:
      ValueError: if the required version tuple has too many parts.
      SkipTest: if no suitable git version was found at the given path.
    r   Nz,Test requires git >= {}, but c git not foundz+Invalid version tuple %s, expected %i partsr   .z!Test requires git >= {}, found {})r!   r   formatr   r   r   listr   r   joinmapstr)required_versionr   found_versions      r    require_git_versionr+   O   sV     222M:AABRSS
 
 	
 |++9./
 
 	

 ,--
m

s#344
4
4""" m

s#344
4
4-..'''88C-=$>$>??S-!8!899/667GWW
 
 	
 ('    Fc                    |                     di           }dx|d<   |d<   t          j        d          |d<   |g| z   } t          j        |d<   |rt          j        |d<   n|                     dd           |rt          j        |d	<   n|                     d	d           t          j        | fd|i|}|                    |
          \  }}	|j        ||	fS )a  Run a git command.

    Input is piped from the input parameter and output is sent to the standard
    streams, unless capture_stdout is set.

    Args:
      args: A list of args to the git command.
      git_path: Path to to the git executable.
      input: Input data to be sent to stdin.
      capture_stdout: Whether to capture and return stdout.
      popen_kwargs: Additional kwargs for subprocess.Popen;
        stdin/stdout args are ignored.
    Returns: A tuple of (returncode, stdout contents, stderr contents).
        If capture_stdout is False, None will be returned as stdout contents.
        If capture_stderr is False, None will be returned as stderr contents.
    Raises:
      OSError: if the git executable was not found.
    envCLC_ALLLANGPATHstdinstdoutNstderr)input)poposgetenv
subprocessPIPEPopencommunicate
returncode)
argsr   r6   capture_stdoutcapture_stderrpopen_kwargsr.   pr4   r5   s
             r    run_gitrD   t   s    . 

5"
%
%C"%%CMCK)F##CK:D&OL )!+X4((( )!+X4(((7737,77A]]]//NFFL&&))r,   c                     d|vrt           j        |d<   t          | f||ddd|\  }}}|dk    rt          d| |||fz            |S )z@Run a git command, capture stdout/stderr, and fail if git fails.r5   T)r   r6   r@   rA   r   z4git with args %r failed with %d: stdout=%r stderr=%r)r:   STDOUTrD   AssertionError)r?   r   r6   rB   r>   r4   r5   s          r    r   r      s    |##!+!2X!("uT" "+" "J QBdJX^`fEgg
 
 	
 Mr,   c                 n   t          j                    }t          j                            t
          |           }t          j                            ||           }t          |d          }t          ddd|g           t          dg|                                |           |	                                 |S )au  Import a repo from a fast-export file in a temporary directory.

    These are used rather than binary repos for compat tests because they are
    more compact and human-editable, and we already depend on git.

    Args:
      name: The name of the repository export file, relative to
        dulwich/tests/data/repos.
    Returns: The path to the imported repository.
    rbinitz--quietz--barezfast-import)r6   cwd)
tempfilemkdtempr8   pathr&   _REPOS_DATA_DIRopenr   readclose)nametemp_direxport_pathtemp_repo_direxport_files        r    import_repo_to_dirrX      s     !!H',,55KGLL400M{D))KVY-@AAA]O;+;+;+=+==QQQQr,   
   g?c                 `   t          |           D ]}t          j        |           t          j        t          j        t          j                  }|                    |           	 |                    d|f           	 |                                  dS # t          j	        $ r Y nYt          $ rM}t          |dd          r|j        t          j        k    r |j        d         t          j        k    r Y d}~nd}~ww xY w|                                 # |                                 w xY wdS )a  Check for a running TCP daemon.

    Defaults to checking 10 times with a delay of 0.1 sec between tries.

    Args:
      limit: Number of attempts before deciding no daemon is running.
      delay: Delay between connection attempts.
      timeout: Socket timeout for connection attempts.
      port: Port on which we expect the daemon to appear.
    Returns: A boolean, true if a daemon is running on the specified port,
        false if not.
    	localhostTerrnoFr   N)rangetimesleepsocketAF_INETSOCK_STREAM
settimeoutconnectrR   timeoutr   getattrr\   ECONNREFUSEDr?   )limitdelayre   port_ses          r    check_for_daemonrn      s5    5\\  
5M&.&*<==	U	II{D)*** GGIIIIII ~ 	 	 	D 	 	 	q'5)) ag9K.K.Ke000 10000	 GGIIIIAGGIIII5s7   &BC<$D&	C</AC72D7C<<DD+c                   Z     e Zd ZU dZdZeedf         ed<    fdZd Z	d Z
d Zd	 Z xZS )
CompatTestCasezTest case that requires git for compatibility checks.

    Subclasses can change the git version required by overriding
    min_git_version.
    )      r   .min_git_versionc                 p    t                                                       t          | j                   d S N)supersetUpr+   rs   )self	__class__s    r    rw   zCompatTestCase.setUp   s+    D011111r,   c                     |                      t          t          |                    t          t          |                               d S ru   )assertEqualsortedset)rx   store1store2s      r    assertObjectStoreEqualz%CompatTestCase.assertObjectStoreEqual   s:    F,,fS[[.A.ABBBBBr,   c                     |                      |                                |                                           |                     |j        |j                   d S ru   )r{   get_refsr   object_store)rx   repo1repo2s      r    assertReposEqualzCompatTestCase.assertReposEqual   sN    ))5>>+;+;<<<##E$68JKKKKKr,   c                     |                                 }t          |j                  }|                                 }t          |j                  }|                     ||k    o||k               d S ru   )r   r}   r   assertFalse)rx   r   r   refs1objs1refs2objs2s          r    assertReposNotEqualz"CompatTestCase.assertReposNotEqual   sg      E&''  E&''%:EUN;;;;;r,   c                 |    t          |          t                    fd}|                     |           S )a  Import a repo from a fast-export file in a temporary directory.

        Args:
          name: The name of the repository export file, relative to
            dulwich/tests/data/repos.
        Returns: An initialized Repo object that lives in a temporary
            directory.
        c                                                        t          t          j                                                 t          j                                       d S ru   )rR   	rmtree_ror8   rN   dirnamerstripsep)rN   repos   r    cleanupz+CompatTestCase.import_repo.<locals>.cleanup	  s@    JJLLLbgoodkk"&&9&9::;;;;;r,   )rX   r   
addCleanup)rx   rS   r   rN   r   s      @@r    import_repozCompatTestCase.import_repo   sU     "$''Dzz	< 	< 	< 	< 	< 	< 	   r,   )__name__
__module____qualname____doc__rs   r   r   __annotations__rw   r   r   r   r   __classcell__)ry   s   @r    rp   rp      s           (1OU38_0002 2 2 2 2C C CL L L< < <      r,   rp   win32c                 l    t          j        |t          j                   t          j        |           d S ru   )r8   chmodstatS_IWRITEremove)actionrS   excs      r    	remove_ror     s'    
t}%%%
	$r,   )onerror))r   r\   	functoolsr8   shutilr`   r   r:   sysrL   r^   typingr   dulwich.testsr   r   protocolr   r   r   _DEFAULT_GITr   rN   abspathr&   r   __file__pardirrO   r!   r+   rD   r   rX   rn   rp   platformr   partialrmtreer    r,   r    <module>r      s!  * + *      				        



         , , , , , , , , $ $ $ $ $ $      '//GLL
!!29biG   & & & & &< 4@ "
 "
 "
 "
L  tE'* '* '* '*T $0t      * S#L    @, , , , ,X , , ,^ <7   "	!&-CCCIIIIIIr,   