ó
’3Rc           @   sH   d  Z  d d l Z d d l Z d d l m Z d e f d „  ƒ  YZ d S(   s   Git fast import classiÿÿÿÿN(   t   GbpErrort
   FastImportc           B   sz   e  Z d  Z d Z d Z d Z d Z d „  Z d „  Z d „  Z	 e d „ Z
 d	 „  Z d
 „  Z d „  Z d „  Z d „  Z RS(   s5   Add data to a git repository using I{git fast-import}i   i„  ió  iÀÔ c         C   s•   | |  _  y@ t j d d d g d t j d | j ƒ|  _ |  j j |  _ WnE t k
 rn } t	 d | ƒ ‚ n# t
 k
 r } t	 d | ƒ ‚ n Xd S(	   sl   
        @param repo: the git repository L{FastImport} acts on
        @type repo: L{GitRepository}
        t   gits   fast-imports   --quiett   stdint   cwds"   Error spawning git fast-import: %ss2   Invalid argument when spawning git fast-import: %sN(   t   _repot
   subprocesst   Popent   PIPEt   patht   _fiR   t   _outt   OSErrorR    t
   ValueError(   t   selft   repot   err(    (    s6   /usr/lib/python2.7/dist-packages/gbp/git/fastimport.pyt   __init__    s    	c         C   sp   |  j  j d | ƒ xE t r[ | j |  j ƒ } |  j  j | ƒ t | ƒ |  j k r Pq q W|  j  j d ƒ d  S(   Ns   data %s
s   
(   R   t   writet   Truet   readt   _bufsizet   len(   R   t   fdt   sizet   data(    (    s6   /usr/lib/python2.7/dist-packages/gbp/git/fastimport.pyt   _do_data0   s    	c         C   sJ   d j  | j d ƒ d ƒ } |  j j d | | f ƒ |  j | | ƒ d  S(   Nt   /i   s   M %d inline %s
(   t   joint   splitR   R   R   (   R   t   filenamet   modeR   R   t   name(    (    s6   /usr/lib/python2.7/dist-packages/gbp/git/fastimport.pyt   _do_file9   s    c         C   s   |  j  | | | | ƒ d S(   sj  
        Add a file

        @param filename: the name of the file to add
        @type filename: C{str}
        @param fd: stream to read data from
        @type fd: C{File} like object
        @param size: size of the file to add
        @type size: C{int}
        @param mode: file mode, default is L{FastImport.m_regular}.
        @type mode: C{int}
        N(   R!   (   R   R   R   R   R   (    (    s6   /usr/lib/python2.7/dist-packages/gbp/git/fastimport.pyt   add_file>   s    c         C   sO   |  j  j d |  j | f ƒ |  j  j d t | ƒ ƒ |  j  j d | ƒ d S(   sÏ   
        Add a symlink

        @param linkname: the symbolic link's name
        @param linkname: C{str}
        @param linktarget: the target the symlink points to
        @type linktarget: C{str}
        s   M %d inline %s
s   data %s
s   %s
N(   R   R   t	   m_symlinkR   (   R   t   linknamet
   linktarget(    (    s6   /usr/lib/python2.7/dist-packages/gbp/git/fastimport.pyt   add_symlinkM   s    	c         C   s­   t  | ƒ } | j s: d t j ƒ  t j d ƒ f | _ n  |  j j | ƒ rU d } n d } |  j j d i | d 6| j d 6| j	 d 6| j d	 6| d
 6| d 6| d 6ƒ d S(   s  
        Start a fast import commit

        @param branch: branch to commit on
        @type branch: C{str}
        @param committer: the committer information
        @type committer: L{GitModifier}
        @param msg: the commit message
        @type msg: C{str}
        s   %d %ss   %zs   from refs/heads/%(branch)s^0
t    sd   commit refs/heads/%(branch)s
committer %(name)s <%(email)s> %(time)s
data %(length)s
%(msg)s%(from)st   branchR    t   emailt   timet   lengtht   msgt   fromN(
   R   t   dateR*   t   strftimeR   t
   has_branchR   R   R    R)   (   R   R(   t	   committerR,   R+   t   from_(    (    s6   /usr/lib/python2.7/dist-packages/gbp/git/fastimport.pyt   start_commitZ   s     			



c         C   s   |  j  j d ƒ d S(   sP   
        Issue I{deleteall} to fastimport so we start from a empty tree
        s
   deleteall
N(   R   R   (   R   (    (    s6   /usr/lib/python2.7/dist-packages/gbp/git/fastimport.pyt	   deleteall|   s    c         C   s6   |  j  r |  j  j ƒ  n  |  j r2 |  j j ƒ  n  d S(   s?   
        Close fast-import issuing all pending actions
        N(   R   t   closeR
   t   wait(   R   (    (    s6   /usr/lib/python2.7/dist-packages/gbp/git/fastimport.pyR5   ‚   s    		c         C   s   |  j  ƒ  d  S(   N(   R5   (   R   (    (    s6   /usr/lib/python2.7/dist-packages/gbp/git/fastimport.pyt   __del__‹   s    (   t   __name__t
   __module__t   __doc__R   t	   m_regulart   m_execR#   R   R   R!   R"   R&   R3   R4   R5   R7   (    (    (    s6   /usr/lib/python2.7/dist-packages/gbp/git/fastimport.pyR      s   						"			(   R:   R   R*   t
   gbp.errorsR    t   objectR   (    (    (    s6   /usr/lib/python2.7/dist-packages/gbp/git/fastimport.pyt   <module>   s   