§
    |{ÈcT$  ã            
       ó  — 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 ddlmZ ddlmZ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)ÚRepo)ÚTCP_GIT_PORT)ÚSkipTestÚTestCaseÚ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         ú</usr/lib/python3/dist-packages/dulwich/tests/compat/utils.pyÚgit_versionr    4   s'  € ðÝ  + ¸ÐBÑBÔBˆˆøÝð ð ð Øˆtˆtðøøøà$€NØ×Ò˜^Ñ,Ô,ð Øˆtà•3�~Ñ&Ô&Ð(Ð(Ô)×/Ò/°Ñ5Ô5€EØ€DØð ð ˆð	Ø�KŠK�˜D™	œ	Ñ"Ô"Ð"Ð"øÝð 	ð 	ð 	ØˆEˆEð	øøøõ ˆ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*   R   sV  € õ  ¨Ð2Ñ2Ô2€MØÐÝØ:×AÒAÐBRÑSÔSñ
ô 
ð 	
õ ÐÑÔ�|Ò+Ð+ÝØ9Ø¥Ð.ñ/ñ
ô 
ð 	
õ
 Ð,Ñ-Ô-ÐÝ
ˆmÑ
Ô
�sÐ#3Ñ4Ô4Ò
4Ð
4Ø×Ò Ñ"Ô"Ð"õ ˆmÑ
Ô
�sÐ#3Ñ4Ô4Ò
4Ð
4åÐ-Ñ.Ô.ÐàÐ'Ò'Ð'ØŸ8š8¥C­Ð-=Ñ$>Ô$>Ñ?Ô?ÐØŸš¥¥S¨-Ñ!8Ô!8Ñ9Ô9ˆÝØ/×6Ò6Ð7GÈÑ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   r5   Úcapture_stdoutÚcapture_stderrÚpopen_kwargsr-   Úpr3   r4   s
             r   Úrun_gitrC   w   só   € ð. ×
Ò
˜5 "Ñ
%Ô
%€CØ"%Ð%€Cˆ�M�C˜‘KÝ”)˜FÑ#Ô#€Cˆ�Kàˆ:˜Ñ€DÝ&œO€L�ÑØð )Ý!+¤ˆ�XÑÐà×Ò˜ 4Ñ(Ô(Ð(Øð )Ý!+¤ˆ�XÑÐà×Ò˜ 4Ñ(Ô(Ð(ÝÔ˜Ð7Ð7 3Ð7¨,Ð7Ð7€AØ—]’]¨�]Ñ/Ô/�N€FˆFØŒ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.r4   T)r   r5   r?   r@   r   z4git with args %r failed with %d: stdout=%r stderr=%r)r9   ÚSTDOUTrC   ÚAssertionError)r>   r   r5   rA   r=   r3   r4   s          r   r   r   ¡   s†   € à�|Ð#Ð#Ý!+Ô!2ˆ�XÑÝ!(Øð"Ø u¸TØð"ð "à+ð"ð "Ñ€J�˜ð �Q‚€ÝØBÀdÈJÐX^Ð`fÐEgÑ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)r5   Úcwd)
ÚtempfileÚmkdtempr7   Úpathr%   Ú_REPOS_DATA_DIRÚopenr   ÚreadÚclose)ÚnameÚtemp_dirÚexport_pathÚtemp_repo_dirÚexport_files        r   Úimport_repo_to_dirrW   °   s�   € õ ÔÑ!Ô!€HÝ”'—,’,�°Ñ5Ô5€KÝ”G—L’L ¨4Ñ0Ô0€MÝ�{ DÑ)Ô)€KÝ�V˜Y¨°-Ð@Ñ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ÚconnectrQ   Útimeoutr   Úgetattrr[   ÚECONNREFUSEDr>   )ÚlimitÚdelayrd   ÚportÚ_ÚsÚes          r   Úcheck_for_daemonrm   Å   s5  € õ �5‰\Œ\ð ñ ˆÝŒ
�5ÑÔÐÝŒM�&œ.­&Ô*<Ñ=Ô=ˆØ	�Š�UÑÔÐð	Ø�IŠI�{ DÐ)Ñ*Ô*Ð*Øð �GŠG‰IŒIˆIˆIˆIˆIøõ Œ~ð 	ð 	ð 	ØˆDÝð 	ð 	ð 	Ý�q˜' 5Ñ)Ô)ð ¨a¬g½Ô9KÒ.KÐ.KØØ”˜”�eÔ0Ò0Ð0Øð 1Ð0Ð0Ð0Ð0øøøøð	øøøð �GŠG‰IŒIˆI‰IøˆA�GŠG‰IŒIˆIˆIøøøØˆ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 )
ÚCompatTestCasez‘Test 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*   rr   )ÚselfÚ	__class__s    €r   rv   zCompatTestCase.setUpî   s+   ø€ Ý‰Œ�Š‰ŒˆÝ˜DÔ0Ñ1Ô1Ð1Ð1Ð1r+   c                 óš   — |                       t          t          |¦  «        ¦  «        t          t          |¦  «        ¦  «        ¦  «         d S rt   )ÚassertEqualÚsortedÚset)rw   Ústore1Ústore2s      r   ÚassertObjectStoreEqualz%CompatTestCase.assertObjectStoreEqualò   s:   € Ø×Ò�¥ F¡¤Ñ,Ô,­fµS¸±[´[Ñ.AÔ.AÑBÔBÐBÐBÐBr+   c                 óº   — |                       |                     ¦   «         |                     ¦   «         ¦  «         |                      |j        |j        ¦  «         d S rt   )rz   Úget_refsr   Úobject_store)rw   Ú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 rt   )r�   r|   r‚   ÚassertFalse)rw   rƒ   r„   Úrefs1Úobjs1Úrefs2Úobjs2s          r   ÚassertReposNotEqualz"CompatTestCase.assertReposNotEqualù   sg   € Ø—’Ñ Ô ˆÝ�EÔ&Ñ'Ô'ˆØ—’Ñ Ô ˆÝ�EÔ&Ñ'Ô'ˆØ×Ò˜ %šÐ:¨E°UªNÑ;Ô;Ð;Ð;Ð;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 rt   )rQ   Ú	rmtree_ror7   rM   ÚdirnameÚrstripÚsep)rM   Úrepos   €€r   Úcleanupz+CompatTestCase.import_repo.<locals>.cleanup  s@   ø€ Ø�JŠJ‰LŒLˆLÝ•b”g—o’o d§k¢kµ"´&Ñ&9Ô&9Ñ:Ô:Ñ;Ô;Ð;Ð;Ð;r+   )rW   r   Ú
addCleanup)rw   rR   r”   rM   r“   s      @@r   Úimport_repozCompatTestCase.import_repo   sU   øø€ õ " $Ñ'Ô'ˆÝ�D‰zŒzˆð	<ð 	<ð 	<ð 	<ð 	<ð 	<ð 	�Š˜Ñ Ô Ð Øˆr+   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__rr   r   r   Ú__annotations__rv   r   r…   rŒ   r–   Ú__classcell__)rx   s   @r   ro   ro   å   s    ø€ € € € € € ðð ð (1€O�U˜3 ˜8”_Ð0Ð0Ñ0ð2ð 2ð 2ð 2ð 2ðCð Cð CðLð Lð Lð<ð <ð <ðð ð ð ð ð ð r+   ro   Úwin32c                 ól   — t          j        |t          j        ¦  «         t          j        |¦  «         d S rt   )r7   ÚchmodÚstatÚS_IWRITEÚremove)ÚactionrR   Úexcs      r   Ú	remove_ror¥     s'   € Ý
Œ�•t”}Ñ%Ô%Ð%Ý
Œ	�$‰Œˆˆˆr+   )Úonerror))rš   r[   Ú	functoolsr7   Úshutilr_   r    r9   ÚsysrK   r]   Útypingr   Údulwich.repor   Údulwich.protocolr   Údulwich.testsr   r   Ú_DEFAULT_GITr   rM   Úabspathr%   r�   Ú__file__ÚpardirrN   r    r*   rC   r   rW   rm   ro   Úplatformr¥   ÚpartialÚrmtreer�   © r+   r   ú<module>r¶      s3  ðð* +Ð *à €€€Ø Ð Ð Ð Ø 	€	€	€	Ø €€€Ø €€€Ø €€€Ø Ð Ð Ð Ø 
€
€
€
Ø €€€Ø €€€Ø Ð Ð Ð Ð Ð à Ð Ð Ð Ð Ð Ø )Ð )Ð )Ð )Ð )Ð )ðð ð ð ð ð ð ð ð
 €Ø€Ø”'—/’/Ø„G‡L‚LØ
Œ�Š˜Ñ!Ô! 2¤9¨b¬i¸¼Ø�Gñô ñô €ð &ð &ð &ð &ð &ð< 4@ð "
ð "
ð "
ð "
ðL   t¸EØð'*ð '*ð '*ð '*ðT $0°tð ð ð ð ðð ð ð*  S°#¸Lð ð ð ð ð@,ð ,ð ,ð ,ð ,�Xñ ,ô ,ð ,ð^ „<�7ÒÐðð ð ð "�	Ô! &¤-¸ÐCÑCÔC€I€I€Ià”€I€I€Ir+   