ó
VpzRc           @   sR   d  Z  d d l Z d d l m Z m Z d d l m Z d e f d „  ƒ  YZ d S(   s,   A Git Repository that keeps a Debian PackageiÿÿÿÿN(   t   GitRepositoryt   GitRepositoryError(   t   DebianPristineTart   DebianGitRepositoryc           B   sƒ   e  Z d  Z d „  Z d „  Z d d d „ Z e d „  ƒ Z e d „  ƒ Z	 e d „  ƒ Z
 e d „  ƒ Z e d	 „  ƒ Z d
 „  Z RS(   s:   A git repository that holds the source of a Debian packagec         C   s)   t  t |  ƒ j | ƒ t |  ƒ |  _ d  S(   N(   t   superR   t   __init__R   t   pristine_tar(   t   selft   path(    (    s/   /usr/lib/python2.7/dist-packages/gbp/deb/git.pyR      s    c         C   sÍ   |  j  | | ƒ } |  j | | ƒ } |  j | ƒ rD |  j d | ƒ S|  j | ƒ rÉ |  j d d d | g ƒ\ } } | r~ d SxH | D]= } | j d | ƒ r¯ |  j d | ƒ S| j d ƒ r… d Sq… Wn  d S(   sœ  
        Check if a certain version is stored in this repo and return the SHA1
        of the related commit. That is, an annotated tag is dereferenced to the
        commit object it points to.

        For legacy tags don't only check the tag itself but also the commit
        message, since the former wasn't injective until release 0.5.5. You
        only need to use this function if you also need to check for legacy
        tags.

        @param format: tag pattern
        @type format: C{str}
        @param version: debian version number
        @type version: C{str}
        @return: sha1 of the commit the tag references to
        @rtype: C{str}
        s   %s^0s   cat-filet   argss   -ps    %s
s   ---N(   t   version_to_tagt   _build_legacy_tagt   has_tagt	   rev_parset   _git_getoutputt   Nonet   endswitht
   startswith(   R   t   formatt   versiont   tagt
   legacy_tagt   outt   rett   line(    (    s/   /usr/lib/python2.7/dist-packages/gbp/deb/git.pyt   find_version   s    !t   HEADc         C   sa   | t  d d ƒ } |  j | d | ƒ} |  j | | ƒ } | d 7} | r] d | | f } n  | S(   så  
        Build the Debian version that a package based on upstream commit
        I{commit} would carry taking into account a possible epoch.

        @param upstream_tag_format: the tag format on the upstream branch
        @type upstream_tag_format: C{str}
        @param commit: the commit to search for the latest upstream version
        @param epoch: an epoch to use
        @returns: a new debian version
        @raises GitRepositoryError: if no upstream tag was found
        R   t   *t   patterns   -1s   %s:%s(   t   dictt   find_tagt   tag_to_version(   R   t   upstream_tag_formatt   committ   epochR   R   R   (    (    s/   /usr/lib/python2.7/dist-packages/gbp/deb/git.pyt   debian_version_from_upstreamA   s    
c         C   sH   d | k r% | j  d d ƒ d } n  | j d d ƒ } |  t d | ƒ S(   sÅ   
        Legacy tags (prior to 0.5.5) dropped epochs and didn't honor the '~'

        >>> DebianGitRepository._build_legacy_tag('upstream/%(version)s', '1:2.0~3')
        'upstream/2.0.3'
        t   :i   t   ~t   .R   (   t   splitt   replaceR   (   R   R   (    (    s/   /usr/lib/python2.7/dist-packages/gbp/deb/git.pyR   W   s    c         C   s   |  t  d t j | ƒ ƒ S(   sŸ   Generate a tag from a given format and a version

        >>> DebianGitRepository.version_to_tag("debian/%(version)s", "0:0~0")
        'debian/0%0_0'
        R   (   R   R   t   _sanitize_version(   R   R   (    (    s/   /usr/lib/python2.7/dist-packages/gbp/deb/git.pyR
   d   s    c         C   s   |  j  d d ƒ j  d d ƒ S(   sc  sanitize a version so git accepts it as a tag

        >>> DebianGitRepository._sanitize_version("0.0.0")
        '0.0.0'
        >>> DebianGitRepository._sanitize_version("0.0~0")
        '0.0_0'
        >>> DebianGitRepository._sanitize_version("0:0.0")
        '0%0.0'
        >>> DebianGitRepository._sanitize_version("0%0~0")
        '0%0_0'
        R%   t   _R$   t   %(   R(   (   R   (    (    s/   /usr/lib/python2.7/dist-packages/gbp/deb/git.pyR)   m   s    c         C   sY   | j  d d ƒ } t j | |  ƒ } | rU | j d ƒ j  d d ƒ j  d d ƒ } | Sd S(	   sH  Extract the version from a tag

        >>> DebianGitRepository.tag_to_version("upstream/1%2_3-4", "upstream/%(version)s")
        '1:2~3-4'
        >>> DebianGitRepository.tag_to_version("foo/2.3.4", "foo/%(version)s")
        '2.3.4'
        >>> DebianGitRepository.tag_to_version("foo/2.3.4", "upstream/%(version)s")
        s   %(version)ss   (?P<version>[\w_%+-.]+)R   R*   R%   R+   R$   N(   R(   t   ret   matcht   groupR   (   R   R   t
   version_ret   rR   (    (    s/   /usr/lib/python2.7/dist-packages/gbp/deb/git.pyR   |   s    
		'c         C   s   t  j S(   s`   
        The name of the pristine-tar branch, whether it already exists or
        not.
        (   R   t   branch(   R   (    (    s/   /usr/lib/python2.7/dist-packages/gbp/deb/git.pyt   pristine_tar_branchŽ   s    c         C   s   |  j  |  j ƒ r t St S(   s¾   
        Wheter the repo has a I{pristine-tar} branch.

        @return: C{True} if the repo has pristine-tar commits already, C{False}
            otherwise
        @rtype: C{Bool}
        (   t
   has_branchR2   t   Truet   False(   R   (    (    s/   /usr/lib/python2.7/dist-packages/gbp/deb/git.pyt   has_pristine_tar_branch–   s    N(   t   __name__t
   __module__t   __doc__R   R   R   R#   t   staticmethodR   R
   R)   R   t   propertyR2   R6   (    (    (    s/   /usr/lib/python2.7/dist-packages/gbp/deb/git.pyR      s   		#	(   R9   R,   t   gbp.gitR    R   t   gbp.deb.pristinetarR   R   (    (    (    s/   /usr/lib/python2.7/dist-packages/gbp/deb/git.pyt   <module>   s   