§
    |{ÈcØ0  ã                   óð   — 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m	Z	 ddl
mZmZmZmZ ddlmZmZmZmZmZmZmZmZ ddlmZ ddlmZmZ dZdd	„Zd
„ Zd„ Z d„ Z!d„ Z"d„ Z#d„ Z$dd„Z%dd„Z&d„ Z'dS )z*Utility functions common to Dulwich tests.é    N)Úcommit_tree)ÚFixedShaÚCommitÚTagÚobject_class)Ú	OFS_DELTAÚ	REF_DELTAÚDELTA_TYPESÚobj_shaÚ
SHA1WriterÚwrite_pack_headerÚwrite_pack_objectÚcreate_delta)ÚRepo)ÚskipIfÚSkipTesti¤�  c                 óD  — |€t          j        ¦   «         }t          j                             t          j                             t          ¦  «        dddd| ¦  «        }t          j                             || ¦  «        }t          j        ||d¬¦  «         t          |¦  «        S )a"  Open a copy of a repo in a temporary directory.

    Use this function for accessing repos in dulwich/tests/data/repos to avoid
    accidentally or intentionally modifying those repos in place. Use
    tear_down_repo to delete any temp files created.

    Args:
      name: The name of the repository, relative to
        dulwich/tests/data/repos
      temp_dir: temporary directory to initialize to. If not provided, a
        temporary directory will be created.
    Returns: An initialized Repo object that lives in a temporary directory.
    Nz..ÚtestdataÚreposT)Úsymlinks)
ÚtempfileÚmkdtempÚosÚpathÚjoinÚdirnameÚ__file__ÚshutilÚcopytreer   )ÚnameÚtemp_dirÚrepo_dirÚtemp_repo_dirs       ú5/usr/lib/python3/dist-packages/dulwich/tests/utils.pyÚ	open_repor%   ?   s~   € ð ÐÝÔ#Ñ%Ô%ˆÝŒw�|Š|�BœGŸOšO­HÑ5Ô5°t¸TÀ:ÈwÐX\Ñ]Ô]€HÝ”G—L’L ¨4Ñ0Ô0€MÝ
„O�H˜m°dÐ;Ñ;Ô;Ð;Ý�ÑÔÐó    c                 óØ   — |                       ¦   «          t          j                             | j                             t          j        ¦  «        ¦  «        }t          j        |¦  «         dS )zTear down a test repository.N)Úcloser   r   r   ÚrstripÚsepr   Úrmtree)Úrepor!   s     r$   Útear_down_repor-   U   sJ   € à‡J‚J�L„L€LÝŒw�Š˜tœy×/Ò/µ´Ñ7Ô7Ñ8Ô8€HÝ
„M�(ÑÔÐÐÐr&   c                 óì   ‡—  G d„ d| ¦  «        }d| j         z   |_          |¦   «         }|                     ¦   «         D ]6\  }}|dk    rt          |¦  «        Šˆfd„|_        Œ%t	          |||¦  «         Œ7|S )aL  Make an object for testing and assign some members.

    This method creates a new subclass to allow arbitrary attribute
    reassignment, which is not otherwise possible with objects having
    __slots__.

    Args:
      attrs: dict of attributes to set on the new object.
    Returns: A newly initialized object of type cls.
    c                   ó   — e Zd ZdZdS )úmake_object.<locals>.TestObjecta  Class that inherits from the given class, but without __slots__.

        Note that classes with __slots__ can't have arbitrary attributes
        monkey-patched in, so this is a class that is exactly the same only
        with a __dict__ instead of __slots__.
        N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__© r&   r$   Ú
TestObjectr0   h   s   € € € € € ð	ð 	ð 	ˆr&   r6   ÚTestObject_Úidc                  ó   •— ‰ S ©Nr5   )Úshas   €r$   ú<lambda>zmake_object.<locals>.<lambda>y   s   ø€ ˜c€ r&   )r1   Úitemsr   r;   Úsetattr)ÚclsÚattrsr6   Úobjr    Úvaluer;   s         @r$   Úmake_objectrC   \   s¡   ø€ ðð ð ð ð �Sñ ô ð ð (¨#¬,Ñ6€JÔà
ˆ*‰,Œ,€CØ—{’{‘}”}ð &ð &‰ˆˆeØ�4Š<ˆ<å˜5‘/”/ˆCØ!�k�k�kˆCŒGˆGå�C˜˜uÑ%Ô%Ð%Ð%Ø€Jr&   c            
      ól   — d}d|dd|ddg ddœ	}|                      | ¦  «         t          t          fi |¤ŽS )z¹Make a Commit object with a default set of members.

    Args:
      attrs: dict of attributes to overwrite from the default values.
    Returns: A newly initialized Commit object.
    i ;=Kó   Test Author <test@nodomain.com>r   s"   Test Committer <test@nodomain.com>ó   Test message.s(   0000000000000000000000000000000000000000)	ÚauthorÚauthor_timeÚauthor_timezoneÚ	committerÚcommit_timeÚcommit_timezoneÚmessageÚparentsÚtree)ÚupdaterC   r   )r@   Údefault_timeÚ	all_attrss      r$   Úmake_commitrS      s\   € ð €Là4Ø#ØØ:Ø#ØØ#ØØð
ð 
€Ið ×Ò�UÑÔÐÝ•vÐ+Ð+ Ð+Ð+Ð+r&   c           	      ó*  — | j         }t          | j        ¦  «        }t          t	          j        t          j        ddd¦  «                             ¦   «         ¦  «        ¦  «        }d|dd||fddœ}|                     |¦  «         t          t          fi |¤ŽS )zîMake a Tag object with a default set of values.

    Args:
      target: object to be tagged (Commit, Blob, Tree, etc)
      attrs: dict of attributes to overwrite from the default values.
    Returns: A newly initialized Tag object.
    iÚ  é   rE   r   rF   s   Test Tag)ÚtaggerÚtag_timeÚtag_timezonerM   Úobjectr    )r8   r   Ú	type_nameÚintÚtimeÚmktimeÚdatetimeÚ	timetuplerP   rC   r   )Útargetr@   Ú	target_idÚtarget_typerQ   rR   s         r$   Úmake_tagrc   –   sœ   € ð ”	€IÝ˜vÔ/Ñ0Ô0€KÝ•t”{¥8Ô#4°T¸1¸aÑ#@Ô#@×#JÒ#JÑ#LÔ#LÑMÔMÑNÔN€Là4Ø ØØ#Ø 	Ð*Øðð €Ið ×Ò�UÑÔÐÝ•sÐ(Ð(˜iÐ(Ð(Ð(r&   c                 ó   ‡ ‡— ˆˆ fd„}|S )z5Generate a test method that tests the given function.c                 ó    •—  ‰| ‰¦  «         d S r:   r5   ©ÚselfÚfuncÚmethods    €€r$   Údo_testz!functest_builder.<locals>.do_test°   s   ø€ Øˆˆt�TÑÔÐÐÐr&   r5   ©ri   rh   rj   s   `` r$   Úfunctest_builderrl   ­   s)   øø€ ðð ð ð ð ð ð €Nr&   c                 ó   ‡ ‡— ˆˆ fd„}|S )aã  Generate a test method that tests the given extension function.

    This is intended to generate test methods that test both a pure-Python
    version and an extension version using common test code. The extension test
    will raise SkipTest if the extension is not found.

    Sample usage:

    class MyTest(TestCase);
        def _do_some_test(self, func_impl):
            self.assertEqual('foo', func_impl())

        test_foo = functest_builder(_do_some_test, foo_py)
        test_foo_extension = ext_functest_builder(_do_some_test, _foo_c)

    Args:
      method: The method to run. It must must two parameters, self and the
        function implementation to test.
      func: The function implementation to pass to method.
    c                 óx   •— t          ‰t          j        ¦  «        st          d‰z  ¦  «        ‚ ‰| ‰¦  «         d S )Nz%s extension not found)Ú
isinstanceÚtypesÚBuiltinFunctionTyper   rf   s    €€r$   rj   z%ext_functest_builder.<locals>.do_testÌ   sD   ø€ Ý˜$¥Ô 9Ñ:Ô:ð 	<ÝÐ3°dÑ:Ñ;Ô;Ð;Øˆˆt�TÑÔÐÐÐr&   r5   rk   s   `` r$   Úext_functest_builderrr   ¶   s)   øø€ ð,ð ð ð ð ð ð
 €Nr&   c           	      ó  — t          | ¦  «        }t          |¦  «        }t          |j        |¦  «         i }i }i }t          |¦  «        |k     r§t	          |¦  «        D ]„\  }\  }	}
|	t
          vr|	|
t          |	|
g¦  «        f||<   Œ)|
\  }}
t          |t          ¦  «        r||vrŒH||         \  }}}n| 	                    |¦  «        \  }}||
t          ||
g¦  «        f||<   Œ…t          |¦  «        |k     °§t	          |¦  «        D ]ü\  }\  }	}|  
                    ¦   «         }|	t          k    r<|\  }}
|||         z
  }||         \  }}}|t          t          ||
¦  «        ¦  «        f}ny|	t          k    rn|\  }}
t          |t          ¦  «        r||         \  }}}n(| 	                    |¦  «        \  }}t          ||¦  «        }|t          t          ||
¦  «        ¦  «        f}t          |j        |	|¦  «        }|||<   |||<   Œýg }t!          |¦  «        D ]I}||         \  }	}
}t          |¦  «        dk    sJ ‚|                     ||         |	|
|||         f¦  «         ŒJ|                     ¦   «          |                      d¦  «         |S )aF  Write test pack data from a concise spec.

    Args:
      f: A file-like object to write the pack to.
      objects_spec: A list of (type_num, obj). For non-delta types, obj
        is the string of that object's data.
        For delta types, obj is a tuple of (base, data), where:

        * base can be either an index in objects_spec of the base for that
        * delta; or for a ref delta, a SHA, in which case the resulting pack
        * will be thin and the base will be an external ref.
        * data is a string of the full, non-deltified data for that object.

        Note that offsets/refs and deltas are computed within this function.
      store: An optional ObjectStore for looking up external refs.
    Returns: A list of tuples in the order specified by objects_spec:
        (offset, type num, data, sha, CRC32)
    é   r   )r   Úlenr   ÚwriteÚ	enumerater
   r   ro   r[   Úget_rawÚtellr   Úlistr   r	   r   ÚrangeÚappendÚ	write_shaÚseek)ÚfÚobjects_specÚstoreÚsfÚnum_objectsÚfull_objectsÚoffsetsÚcrc32sÚiÚtype_numÚdataÚbaseÚbase_type_numÚ_rA   ÚoffsetÚ
base_indexÚ	base_dataÚbase_refÚcrc32Úexpectedr;   s                         r$   Ú
build_packr“   Ô   sÐ  € õ& 
�A‰Œ€BÝ�lÑ#Ô#€KÝ�b”h Ñ,Ô,Ð,à€LØ€GØ€Få
ˆlÑ
Ô
˜kÒ
)Ð
)Ý#,¨\Ñ#:Ô#:ð 	ð 	ÑˆAÑ�˜$Ø�{Ð*Ð*Ø#+¨Tµ7¸8ÀdÀVÑ3LÔ3LÐ"M�˜Q‘ØØ‰JˆD�$Ý˜$¥Ñ$Ô$ð 7Ø˜|Ð+Ð+ØØ&2°4Ô&8Ñ#�˜q ! !à#(§=¢=°Ñ#6Ô#6Ñ �˜qàØÝ˜¨ vÑ.Ô.ðˆL˜‰OˆOõ ˆlÑ
Ô
˜kÒ
)Ð
)õ$ (¨Ñ5Ô5ð ð Ñˆ‰?ˆH�cØ—’‘”ˆØ•yÒ Ð Ø"ÑˆJ˜Ø˜G JÔ/Ñ/ˆDØ*¨:Ô6‰OˆAˆy˜!Ø��l¨9°dÑ;Ô;Ñ<Ô<Ð=ˆCˆCØ�Ò"Ð"Ø ‰NˆH�dÝ˜(¥CÑ(Ô(ð 9Ø%1°(Ô%;Ñ"��9˜d˜dà+0¯=ª=¸Ñ+BÔ+BÑ(�˜yÝ˜}¨iÑ8Ô8�Ø��l¨9°dÑ;Ô;Ñ<Ô<Ð=ˆCå! "¤(¨H°cÑ:Ô:ˆØˆ�‰
Øˆˆq‰	ˆ	à€HÝ�;ÑÔð Fð FˆØ*¨1œoÑˆ�$˜Ý�3‰xŒx˜2Š~ˆ~ˆ~ˆ~Ø�Š˜ œ X¨t°S¸&À¼)ÐDÑEÔEÐEÐEà‡L‚L�N„N€NØ‡F‚Fˆ1�I„I€IØ€Or&   c                 óú  ‡— |€i }|€i }d}i Šg }|D �]g}|d         }	 ˆfd„|dd…         D ¦   «         }n.# t           $ r!}	|	j        \  }
t          d|
z  ¦  «        |	‚d}	~	ww xY wg }|                     |g ¦  «        D ]\}t	          |¦  «        dk    r|\  }}||t
          f}|\  }}}|                     ||j        |f¦  «         |                      |¦  «         Œ]t          | |¦  «        }d|z   
                    d¦  «        |||d	œ}|                     |                     |i ¦  «        ¦  «         t          di |¤Ž}|d
         dz   }|j        ‰|<   |                      |¦  «         |                     |¦  «         �Œi|S )a�  Build a commit graph from a concise specification.

    Sample usage:
    >>> c1, c2, c3 = build_commit_graph(store, [[1], [2, 1], [3, 1, 2]])
    >>> store[store[c3].parents[0]] == c1
    True
    >>> store[store[c3].parents[1]] == c2
    True

    If not otherwise specified, commits will refer to the empty tree and have
    commit times increasing in the same order as the commit spec.

    Args:
      object_store: An ObjectStore to commit objects to.
      commit_spec: An iterable of iterables of ints defining the commit
        graph. Each entry defines one commit, and entries must be in
        topological order. The first element of each entry is a commit number,
        and the remaining elements are its parents. The commit numbers are only
        meaningful for the call to make_commits; since real commit objects are
        created, they will get created with real, opaque SHAs.
      trees: An optional dict of commit number -> tree spec for building
        trees for commits. The tree spec is an iterable of (path, blob, mode)
        or (path, blob) entries; if mode is omitted, it defaults to the normal
        file mode (0100644).
      attrs: A dict of commit number -> (dict of attribute -> value) for
        assigning additional values to the commits.
    Returns: The list of commit objects created.
    Raises:
      ValueError: If an undefined commit identifier is listed as a parent.
    Nr   c                 ó    •— g | ]
}‰|         ‘ŒS r5   r5   )Ú.0ÚpnÚnumss     €r$   ú
<listcomp>z&build_commit_graph.<locals>.<listcomp>J  s   ø€ Ð8Ð8Ð8 r˜$˜rœ(Ð8Ð8Ð8r&   rU   zUnknown parent %ié   z	Commit %iÚascii)rM   rN   rO   rK   rK   éd   r5   )ÚKeyErrorÚargsÚ
ValueErrorÚgetru   ÚFr|   r8   Ú
add_objectr   ÚencoderP   rS   )Úobject_storeÚcommit_specÚtreesr@   rK   ÚcommitsÚcommitÚ
commit_numÚ
parent_idsÚexcÚmissing_parentÚblobsÚentryr   ÚblobÚmodeÚtree_idÚcommit_attrsÚ
commit_objr˜   s                      @r$   Úbuild_commit_graphr´      sï  ø€ ð> €}ØˆØ€}ØˆØ€KØ€DØ€Gàð  #ñ  #ˆØ˜A”Yˆ
ð	LØ8Ð8Ð8Ð8¨V°A°B°B¬ZÐ8Ñ8Ô8ˆJˆJøÝð 	Lð 	Lð 	LØ #¤Ñˆ^ÝÐ0°>ÑAÑBÔBÈÐKøøøøð	Løøøð ˆØ—Y’Y˜z¨2Ñ.Ô.ð 	*ð 	*ˆEÝ�5‰zŒz˜QŠˆØ"‘
��dØ˜t¥Q˜�Ø$ÑˆD�$˜Ø�LŠL˜$ ¤¨Ð.Ñ/Ô/Ð/Ø×#Ò# DÑ)Ô)Ð)Ð)Ý˜l¨EÑ2Ô2ˆð $ jÑ0×8Ò8¸ÑAÔAØ!ØØ&ð	
ð 
ˆð 	×Ò˜EŸIšI j°"Ñ5Ô5Ñ6Ô6Ð6Ý Ð0Ð0 <Ð0Ð0ˆ
ð # =Ô1°CÑ7ˆØ%œ=ˆˆZÑØ×Ò 
Ñ+Ô+Ð+Ø�Š�zÑ"Ô"Ð"Ñ"à€Ns   ž5µ
A ¿AÁA c                  óV   ‡‡— g Št           j        Šˆfd„} | t           _        ˆfd„}‰|fS )z:Wrap warnings.showwarning with code that records warnings.c                  ó>   •— ‰                      | d         ¦  «         d S )Nr   )r|   )rž   ÚkwargsÚcaught_warningss     €r$   Úcustom_showwarningz1setup_warning_catcher.<locals>.custom_showwarningr  s!   ø€ Ø×Ò˜t AœwÑ'Ô'Ð'Ð'Ð'r&   c                  ó    •— ‰ t           _        d S r:   ©ÚwarningsÚshowwarning)Úoriginal_showwarnings   €r$   Úrestore_showwarningz2setup_warning_catcher.<locals>.restore_showwarningw  s   ø€ Ø3�ÔÐÐr&   r»   )r¹   r¿   r¸   r¾   s     @@r$   Úsetup_warning_catcherrÀ   l  s^   øø€ ð €OÝ#Ô/Ðð(ð (ð (ð (ð (ð .…HÔð4ð 4ð 4ð 4ð 4ð Ð/Ð/Ð/r&   r:   )NN)(r4   r^   r   r   r   r\   rp   r¼   Údulwich.indexr   Údulwich.objectsr   r   r   r   Údulwich.packr   r	   r
   r   r   r   r   r   Údulwich.repor   Údulwich.testsr   r   r¡   r%   r-   rC   rS   rc   rl   rr   r“   r´   rÀ   r5   r&   r$   ú<module>rÆ      s	  ðð* 1Ð 0ð €€€Ø 	€	€	€	Ø €€€Ø €€€Ø €€€Ø €€€à €€€ðð ð ð ð ð ðð ð ð ð ð ð ð ð ð ð ð ð	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	ð Ð Ð Ð Ð Ð ðð ð ð ð ð ð ð ð €ðð ð ð ð,ð ð ð ð  ð  ðF,ð ,ð ,ð.)ð )ð )ð.ð ð ðð ð ð<Ið Ið Ið IðXIð Ið Ið IðX0ð 0ð 0ð 0ð 0r&   