
Rc        	   @   s  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 yD d d l	 m
 Z
 d d l	 m Z d d l	 m Z d d l m Z WnQ e k
 r d d l m
 Z
 d d l m Z d d l m Z d d l m Z n Xe Z d d Z d	 Z d
 Z e d d d d d d g  Z d d f \ Z Z d Z d Z d Z d Z d Z d Z  d Z! d Z" d Z# d Z$ d Z% d Z& d Z' d  Z( d! Z) d" Z* d# Z+ d$ Z, d% Z- e  Z. d& e/ f d'     YZ0 d( e/ f d)     YZ1 d* Z2 e3 a4 d+   Z5 e3 e d,  Z6 e3 e d-  Z7 e d.  Z8 e3 d/  Z9 e3 d0  Z: d1 e; f d2     YZ< d3   Z= d4   Z> d5   Z? d6 e; f d7     YZ@ d8 e; f d9     YZA d: e; f d;     YZB d< eB f d=     YZC d> eB f d?     YZD d@ eD f dA     YZE dB eD f dC     YZF dD eD f dE     YZG dF eD f dG     YZH dH e; f dI     YZI dJ eI f dK     YZJ dL eI f dM     YZK dN eI f dO     YZL dP   ZM dQ e; f dR     YZN dS eN f dT     YZO dU eO f dV     YZP dW eN f dX     YZQ dY eO eQ f dZ     YZR d[ eN f d\     YZS d] eO eS f d^     YZT d_ eO f d`     YZU da eN f db     YZV dc eO eV f dd     YZW de eN f df     YZX dg eN f dh     YZY di eX eT eR eW eU eP eY eN f dj     YZZ dk eN f dl     YZ[ dm eX eT eR eW eU eP e[ eN f dn     YZ\ do e; f dp     YZ] dq   Z^ dr   Z_ ds   Z` i eY dt 6e[ du 6Za e3 e3 e3 dv  Zb dw   Zc ed dx k rec e je dy  n  d S(z   s  Generate notification emails for pushes to a git repository.

This hook sends emails describing changes introduced by pushes to a
git repository.  For each reference that was changed, it emits one
ReferenceChange email summarizing how the reference was changed,
followed by one Revision email for each new commit that was introduced
by the reference change.

Each commit is announced in exactly one Revision email.  If the same
commit is merged into another branch in the same or a later push, then
the ReferenceChange email will list the commit's SHA1 and its one-line
summary, but no new Revision email will be generated.

This script is designed to be used as a "post-receive" hook in a git
repository (see githooks(5)).  It can also be used as an "update"
script, but this usage is not completely reliable and is deprecated.

To help with debugging, this script accepts a --stdout option, which
causes the emails to be written to standard output rather than sent
using sendmail.

See the accompanying README file for the complete documentation.

iN(   t
   make_msgid(   t   getaddresses(   t
   formataddr(   t   Headert   0i(   sH   - Log -----------------------------------------------------------------
sH   -----------------------------------------------------------------------
t   fromt   tot   cct   bccs   reply-tot   senders   UTF-8s   utf-8sP   %(emailprefix)s%(refname_type)s %(short_refname)s created (now %(newrev_short)s)s`   %(emailprefix)s%(refname_type)s %(short_refname)s updated (%(oldrev_short)s -> %(newrev_short)s)sP   %(emailprefix)s%(refname_type)s %(short_refname)s deleted (was %(oldrev_short)s)ss  To: %(recipients)s
Subject: %(subject)s
MIME-Version: 1.0
Content-Type: text/plain; charset=%(charset)s
Content-Transfer-Encoding: 8bit
Message-ID: %(msgid)s
From: %(fromaddr)s
Reply-To: %(reply_to)s
X-Git-Repo: %(repo_shortname)s
X-Git-Refname: %(refname)s
X-Git-Reftype: %(refname_type)s
X-Git-Oldrev: %(oldrev)s
X-Git-Newrev: %(newrev)s
Auto-Submitted: auto-generated
s   This is an automated email from the git hooks/post-receive script.

%(pusher)s pushed a change to %(refname_type)s %(short_refname)s
in repository %(repo_shortname)s.

s\   
-- 
To stop receiving notification emails like this one, please contact
%(administrator)s.
sy  This update removed existing revisions from the reference, leaving the
reference pointing at a previous point in the repository history.

 * -- * -- N   %(refname)s (%(newrev_short)s)
            \
             O -- O -- O   (%(oldrev_short)s)

Any revisions marked "omits" are not gone; other references still
refer to them.  Any revisions marked "discards" are gone forever.
s  This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
%(refname_type)s are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (%(oldrev_short)s)
            \
             N -- N -- N   %(refname)s (%(newrev_short)s)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omits" are not gone; other references still
refer to them.  Any revisions marked "discards" are gone forever.
s,   No new revisions were added by this update.
s:   This change permanently discards the following revisions:
s   The revisions that were on this %(refname_type)s are still contained in
other references; therefore, this change does not discard any commits
from the repository.
s   The %(tot)s revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "adds" were already present in the repository and have only
been added to this reference.

s1           at  %(newrev_short)-9s (%(newrev_type)s)
s   *** WARNING: tag %(short_refname)s was modified! ***

      from  %(oldrev_short)-9s (%(oldrev_type)s)
        to  %(newrev_short)-9s (%(newrev_type)s)
s5   *** WARNING: tag %(short_refname)s was deleted! ***

s'   %(action)10s  %(rev_short)-9s %(text)s
s   This is an unusual reference change because the reference did not
refer to a commit either before or after the change.  We do not know
how to provide full information about this reference change.
s  To: %(recipients)s
Subject: %(emailprefix)s%(num)02d/%(tot)02d: %(oneline)s
MIME-Version: 1.0
Content-Type: text/plain; charset=%(charset)s
Content-Transfer-Encoding: 8bit
From: %(fromaddr)s
Reply-To: %(reply_to)s
In-Reply-To: %(reply_to_msgid)s
References: %(reply_to_msgid)s
X-Git-Repo: %(repo_shortname)s
X-Git-Refname: %(refname)s
X-Git-Reftype: %(refname_type)s
X-Git-Rev: %(rev)s
Auto-Submitted: auto-generated
s   This is an automated email from the git hooks/post-receive script.

%(pusher)s pushed a commit to %(refname_type)s %(short_refname)s
in repository %(repo_shortname)s.

t   CommandErrorc           B   s   e  Z d    Z RS(   c         C   s9   | |  _  | |  _ t j |  d d j |  | f  d  S(   Ns#   Command "%s" failed with retcode %st    (   t   cmdt   retcodet	   Exceptiont   __init__t   join(   t   selfR   R   (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyR      s
    		(   t   __name__t
   __module__R   (    (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyR
      s   t   ConfigurationExceptionc           B   s   e  Z RS(    (   R   R   (    (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyR     s   t   gitc          C   sf   t  d k rb y6 t d d d g }  t |   t d d t f g a  Wqb t k
 r^ t g a  qb Xn  d S(   s;   Decide how to invoke git, and record the choice in GIT_CMD.s   -cs   foo.bar=bazs	   --versions   i18n.logoutputencoding=%sN(   t   GIT_CMDt   Nonet   GIT_EXECUTABLEt   read_outputt   ENCODINGR
   (   R   (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyt   choose_git_command  s    
c         K   s3   t  d k r t   n  t t  |  d | d | | S(   s!   Read the output of a Git command.t   inputt   keependsN(   R   R   R   R   (   t   argsR   R   t   kw(    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyt   read_git_output)  s    
c   	   	   K   s   | r t  j } n d  } t  j |  d | d t  j d t  j | } | j |  \ } } | j   } | r{ t |  |   n  | s | j d  } n  | S(   Nt   stdint   stdoutt   stderrs   
(   t
   subprocesst   PIPER   t   Popent   communicatet   waitR
   t   rstrip(	   R   R   R   R   R!   t   pt   outt   errR   (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyR   2  s    $c         K   s   t  |  d t | j |  S(   s`   Return the lines output by Git command.

    Return as single lines, with newlines stripped off.R   (   R    t   Truet
   splitlines(   R   R   R   (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyt   read_git_linesC  s    c         C   su   y> t  |  t  r' |  j t d  }  n  t |  d | j   SWn0 t k
 rp t |  d | d t d d j   SXd S(   s8   Encode and line-wrap the value of an email header field.t   replacet   header_namet   charsett   errorsN(   t
   isinstancet   strt   decodeR   R   t   encodet   UnicodeEncodeErrort   CHARSET(   t   textR1   (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyt   header_encodeK  s    c         C   s2   t  d j d   t |  g  D  d | j   S(   sW   Encode and line-wrap the value of an email header field containing
    email addresses.s   , c         s   s-   |  ]# \ } } t  t |  | f  Vq d  S(   N(   R   R;   (   t   .0t   namet	   emailaddr(    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pys	   <genexpr>]  s   R1   (   R   R   R   R7   (   R:   R1   (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyt   addr_header_encodeW  s
    t   Configc           B   s   e  Z d d   Z e d    Z d d  Z d d  Z d d  Z d d  Z	 d   Z
 d   Z d   Z d	   Z d
   Z RS(   c         C   s>   | |  _  | r1 t j j   |  _ | |  j d <n	 d |  _ d S(   s  Represent a section of the git configuration.

        If git_config is specified, it is passed to "git config" in
        the GIT_CONFIG environment variable, meaning that "git config"
        will read the specified path rather than the Git default
        config paths.t
   GIT_CONFIGN(   t   sectiont   ost   environt   copyt   envR   (   R   RB   t
   git_config(    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyR   e  s
    	c         C   s-   |  j  d  } | d d k s% t  | d  S(   s   Split NUL-terminated values.t    it    (   t   splitt   AssertionError(   t   st   words(    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyt   _splitt  s    c         C   sz   ya |  j  t d d d d |  j | f g d |  j d t  } t |  d k sX t  | d SWn t k
 ru | SXd  S(	   Nt   configs   --gets   --nulls   %s.%sRF   R   i   i    (   RN   R    RB   RF   R-   t   lenRK   R
   (   R   R=   t   defaultt   values(    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyt   get|  s    	c         C   sQ   y2 t  d d d d |  j | f g d |  j } Wn t k
 rF | SX| d k S(   NRO   s   --gets   --bools   %s.%sRF   t   true(   R    RB   RF   R
   (   R   R=   RQ   t   value(    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyt   get_bool  s    c         C   so   y? |  j  t d d d d |  j | f g d |  j d t  SWn) t k
 rj } | j d k rd | S  n Xd S(	   s   Read a (possibly multivalued) setting from the configuration.

        Return the result as a list of values, or default if the name
        is unset.RO   s	   --get-alls   --nulls   %s.%sRF   R   i   N(   RN   R    RB   RF   R-   R
   R   (   R   R=   RQ   t   e(    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyt   get_all  s    	c         C   s<   |  j  | d d } | d k r% | Sd j d   | D  S(   s   Read a recipients list from the configuration.

        Return the result as a comma-separated list of email
        addresses, or default if the option is unset.  If the setting
        has multiple values, concatenate them with comma separators.RQ   s   , c         s   s   |  ] } | j    Vq d  S(   N(   t   strip(   R<   t   line(    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pys	   <genexpr>  s    N(   RX   R   R   (   R   R=   RQ   t   lines(    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyt   get_recipients  s    c         C   s-   t  d d |  j | f | g d |  j d  S(   NRO   s   %s.%sRF   (   R    RB   RF   (   R   R=   RU   (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyt   set  s    c         C   s0   t  d d d |  j | f | g d |  j d  S(   NRO   s   --adds   %s.%sRF   (   R    RB   RF   (   R   R=   RU   (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyt   add  s    c         C   s   |  j  | d d  d  k	 S(   NRQ   (   RX   R   (   R   R=   (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyt   has_key  s    c         C   s\   y- t  d d d |  j | f g d |  j Wn( t k
 rW } | j d k rQ qX   n Xd  S(   NRO   s   --unset-alls   %s.%sRF   i   (   R    RB   RF   R
   R   (   R   R=   RW   (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyt	   unset_all  s    c         C   sA   |  j  |  x- t | g  D] } |  j | t |   q Wd  S(   N(   R`   R   R^   R   (   R   R=   RU   t   pair(    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyt   set_recipients  s    N(   R   R   R   R   t   staticmethodRN   RS   RV   RX   R\   R]   R^   R_   R`   Rb   (    (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyR@   d  s   
				c          g   sR   d d d g t  |   d g } x+ t |  D] } t | j d d   Vq- Wd S(   s2  Generate a brief summary for each revision requested.

    log_args are strings that will be passed directly to "git log" as
    revision selectors.  Iterate over (sha1_short, subject) for each
    commit specified by log_args (subject is the first line of the
    commit message as a string without EOLs).t   logs   --abbrevs   --format=%h %ss   --R   i   N(   t   listR/   t   tupleRJ   (   t   log_argsR   RZ   (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyt   generate_summaries  s    
 c         c   sX   x. t  |   D]  \ } } | | k  r | Vq q W| | k rT d | d | f Vn  d  S(   Ns   ... %d lines suppressed ...
i   (   t	   enumerate(   R[   t	   max_linest   indexRZ   (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyt   limit_lines  s
    c         c   sE   x> |  D]6 } t  |  | d k r8 | | d  d } n  | Vq Wd  S(   Ni   i   s    [...]
(   RP   (   R[   t   max_linelengthRZ   (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyt   limit_linelength  s    t	   CommitSetc           B   s)   e  Z d  Z d   Z d   Z d   Z RS(   s   A (constant) set of object names.

    The set should be initialized with full SHA1 object names.  The
    __contains__() method returns True iff its argument is an
    abbreviation of any the names in the set.c         C   s   t  |  |  _ d  S(   N(   t   sortedt   _names(   R   t   names(    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyR     s    c         C   s   t  |  j  S(   N(   RP   Rq   (   R   (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyt   __len__  s    c         C   s;   t  j |  j |  } | t |   k  o: |  j | j |  S(   sK   Return True iff this set contains sha1_abbrev (which might be abbreviated).(   t   bisectt   bisect_leftRq   RP   t
   startswith(   R   t   sha1_abbrevt   i(    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyt   __contains__  s    (   R   R   t   __doc__R   Rs   Ry   (    (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyRo     s   		t	   GitObjectc           B   sA   e  Z d d   Z d   Z d   Z d   Z d   Z d   Z RS(   c         C   s   | t  k r& d  |  _ |  _ |  _ n | |  _ | pJ t d d |  j g  |  _ |  j d k rn |  j |  _ n^ |  j d k r y& t d d d |  j f g  |  _ Wq t k
 r d  |  _ q Xn	 d  |  _ t d d | g  |  _ d  S(	   Ns   cat-files   -tt   committ   tags	   rev-parses   --verifys   %s^0s   --short(   t   ZEROSR   t   sha1t   typet   commit_sha1R    R
   t   short(   R   R   R   (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyR     s    	!#	c         C   s4   |  j  s t d   n  t t d |  j    j   S(   s-   Return (sha1_short, subject) for this commit.s   Empty commit has no summarys	   --no-walk(   R   t
   ValueErrort   iterRh   t   next(   R   (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyt   get_summary  s    	c         C   s   t  | t  o |  j | j k S(   N(   R4   R{   R   (   R   t   other(    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyt   __eq__%  s    c         C   s   t  |  j  S(   N(   t   hashR   (   R   (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyt   __hash__(  s    c         C   s   t  |  j  S(   N(   t   boolR   (   R   (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyt   __nonzero__+  s    c         C   s   |  j  p t S(   N(   R   R~   (   R   (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyt   __str__.  s    N(	   R   R   R   R   R   R   R   R   R   (    (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyR{     s   				t   Changec           B   st   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d	   Z d
   Z d d  Z RS(   s   A Change that has been made to the Git repository.

    Abstract class from which both Revisions and ReferenceChanges are
    derived.  A Change knows how to generate a notification email
    describing itself.c         C   s   | |  _  d  |  _ d  S(   N(   t   environmentR   t   _values(   R   R   (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyR   9  s    	c         C   s   |  j  j   S(   s  Return a dictionary {keyword : expansion} for this Change.

        Derived classes overload this method to add more entries to
        the return value.  This method is used internally by
        get_values().  The return value should always be a new
        dictionary.(   R   t
   get_values(   R   (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyt   _compute_values=  s    c         K   sJ   |  j  d k r! |  j   |  _  n  |  j  j   } | rF | j |  n  | S(   so  Return a dictionary {keyword : expansion} for this Change.

        Return a dictionary mapping keywords to the values that they
        should be expanded to for this Change (used when interpolating
        template strings).  If any keyword arguments are supplied, add
        those to the return value as well.  The return value is always
        a new dictionary.N(   R   R   R   RE   t   update(   R   t   extra_valuesRR   (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyR   G  s    	c         K   s   | |  j  |   S(   s  Expand template.

        Expand the template (which should be a string) using string
        interpolation of the values for this Change.  If any keyword
        arguments are provided, also include those in the keywords
        available for interpolation.(   R   (   R   t   templateR   (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyt   expandX  s    c         k   s6   |  j  |   } x  | j t  D] } | | Vq Wd S(   s/   Break template into lines and expand each line.N(   R   R.   R-   (   R   R   R   RR   RZ   (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyt   expand_linesb  s    c   	      k   s   |  j  |   } x | j   D] } | j d d  \ } } y | | } Wn= t k
 r } t r t j j d | j d | f  q q X| j	   t
 k r t | |  } n t | |  } x& d | | f j t  D] } | Vq Wq Wd S(   s   Break template into lines and expand each line as an RFC 2822 header.

        Encode values and split up lines that are too long.  Silently
        skip lines that contain references to unknown variables.t   :i   sI   Warning: unknown variable %r in the following line; line skipped:
    %s
i    s   %s: %s
N(   R   R.   RJ   t   KeyErrort   DEBUGt   sysR#   t   writeR   t   lowert   ADDR_HEADERSR?   R;   R-   (	   R   R   R   RR   RZ   R=   RU   RW   t	   splitline(    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyt   expand_header_linesi  s    	 c         C   s   t     d S(   s   Generate the RFC 2822 email headers for this Change, a line at a time.

        The output should not include the trailing blank line.N(   t   NotImplementedError(   R   (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyt   generate_email_header  s    c         C   s   t     d S(   s   Generate the email intro for this Change, a line at a time.

        The output will be used as the standard boilerplate at the top
        of the email body.N(   R   (   R   (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyt   generate_email_intro  s    c         C   s   t     d S(   s   Generate the main part of the email body, a line at a time.

        The text in the body might be truncated after a specified
        number of lines (see multimailhook.emailmaxlines).N(   R   (   R   (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyt   generate_email_body  s    c         C   s   t     d S(   s   Generate the footer of the email, a line at a time.

        The footer is always included, irrespective of
        multimailhook.emailmaxlines.N(   R   (   R   (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyt   generate_email_footer  s    c         c   s   x |  j    D] } | Vq Wd Vx |  j   D] } | Vq. W|  j |  } | d k	 rg | |  } n  x | D] } | Vqn Wx |  j   D] } | Vq Wd S(   s  Generate an email describing this change.

        Iterate over the lines (including the header lines) of an
        email describing this change.  If body_filter is not None,
        then use it to filter the lines that are intended for the
        email body.s   
N(   R   R   R   R   R   (   R   t   pusht   body_filterRZ   t   body(    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyt   generate_email  s    			N(   R   R   Rz   R   R   R   R   R   R   R   R   R   R   R   R   (    (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyR   2  s   		
		
						t   Revisionc           B   sD   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z RS(   s+   A Change consisting of a single git commit.c         C   s   t  j |  | j  | |  _ | |  _ |  j j |  _ |  j j |  _ | |  _ | |  _ t	 d d d |  j j
 g  |  _ |  j j |   |  _ d  S(   NRd   s	   --no-walks   --format=%aN <%aE>(   R   R   R   t   reference_changet   revt   change_typet   refnamet   numt   totR    R   t   authort   get_revision_recipientst
   recipients(   R   R   R   R   R   (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyR     s    				!c         C   s   t  j |   } t d d d |  j j g  } |  j j | d <|  j j | d <|  j | d <|  j | d <|  j j	 | d <|  j j
 | d	 <|  j j | d
 <|  j | d <|  j | d <|  j | d <| | d <|  j | d <|  j j |   } | r | | d <n  | S(   NRd   s   --format=%ss	   --no-walkR   t	   rev_shortR   R   t   short_refnamet   refname_typet   reply_to_msgidR   R   R   t   onelineR   t   reply_to(   R   R   R    R   R   R   R   R   R   R   R   t   msgidR   R   R   R   R   t   get_reply_to_commit(   R   RR   R   R   (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyR     s&    
c         c   s#   x |  j  t  D] } | Vq Wd  S(   N(   R   t   REVISION_HEADER_TEMPLATE(   R   RZ   (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyR     s    c         c   s#   x |  j  t  D] } | Vq Wd  S(   N(   R   t   REVISION_INTRO_TEMPLATE(   R   RZ   (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyR     s    c         C   s-   t  d g |  j j d |  j j g d t S(   s   Show this revision.Rd   s   -1R   (   R/   R   t   commitlogoptsR   R   R-   (   R   R   (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyR     s    #c         C   s   |  j  t  S(   N(   R   t   REVISION_FOOTER_TEMPLATE(   R   (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyR     s    (	   R   R   Rz   R   R   R   R   R   R   (    (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyR     s   					t   ReferenceChangec           B   s   e  Z d  Z e j d  Z e d    Z d   Z d   Z	 d   Z
 d   Z d   Z d   Z d	   Z d
   Z d   Z d   Z d   Z d   Z RS(   s  A Change to a Git reference.

    An abstract class representing a create, update, or delete of a
    Git reference.  Derived classes handle specific types of reference
    (e.g., tags vs. branches).  These classes generate the main
    reference change email summarizing the reference change and
    whether it caused any any commits to be added or removed.

    ReferenceChange objects are usually created using the static
    create() method, which has the logic to decide which derived class
    to instantiate.s+   ^refs\/(?P<area>[^\/]+)\/(?P<shortname>.*)$c         C   sQ  t  |  } t  |  } | p! | } t j j |  } | r] | j d  } | j d  }	 n d } | }	 | j d k r t }
 n | j d k r| d k r t }
 q)| d k r t }
 q)| d k r t	 j
 j d	 | f  t }
 q)t	 j
 j d
 | f  t }
 n# t	 j
 j d | | j f  t }
 |
 |  d | d |	 d | d | d | S(   s   Return a ReferenceChange object representing the change.

        Return an object that represents the type of change that is being
        made. oldrev and newrev should be SHA1s or ZEROS.t   areat	   shortnameRI   R}   R|   t   tagst   headst   remotessI   *** Push-update of tracking branch %r
***  - incomplete email generated.
sK   *** Push-update of strange reference %r
***  - incomplete email generated.
sI   *** Unknown type of update to %r (%s)
***  - incomplete email generated.
R   R   t   oldt   newR   (   R{   R   t   REF_REt   matcht   groupR   t   AnnotatedTagChanget   NonAnnotatedTagChanget   BranchChangeR   R#   R   t   OtherReferenceChange(   R   t   oldrevt   newrevR   R   R   R   t   mR   R   t   klass(    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyt   create  sB    								c         C   s   t  j |  |  i d t t f 6d t t f 6d t t f 6t |  t |  f |  _ | |  _ | |  _ | |  _ | |  _	 | |  _
 t   |  _ | j |  _ | j |  _ | j |  _ | j |  _ d  S(   NR   R   t   delete(   R   R   t   FalseR-   R   R   R   R   R   R   R   R    R   t   diffoptst   logoptsR   t   refchange_showlogt   showlog(   R   R   R   R   R   R   R   (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyR   H  s     					c         C   s  t  j |   } |  j | d <|  j | d <|  j | d <|  j | d <|  j | d <|  j | d <t |  j	  | d <|  j	 j
 | d <t |  j  | d	 <|  j j
 | d
 <|  j	 r |  j	 j | d <n  |  j r |  j j | d <n  |  j j |   } | r | | d <n  | S(   NR   R   R   R   R   R   R   t   oldrev_shortR   t   newrev_shortt   oldrev_typet   newrev_typeR   (   R   R   R   R   R   R   R   R   R5   R   R   R   R   R   t   get_reply_to_refchange(   R   RR   R   (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyR   Z  s&    		c         C   s/   i t  d 6t d 6t d 6|  j } |  j |  S(   NR   R   R   (   t   REF_CREATED_SUBJECT_TEMPLATEt   REF_UPDATED_SUBJECT_TEMPLATEt   REF_DELETED_SUBJECT_TEMPLATER   R   (   R   R   (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyt   get_subjects  s    
c         c   s/   x( |  j  t d |  j   D] } | Vq Wd  S(   Nt   subject(   R   t   REFCHANGE_HEADER_TEMPLATER   (   R   RZ   (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyR   {  s    	c         c   s#   x |  j  t  D] } | Vq Wd  S(   N(   R   t   REFCHANGE_INTRO_TEMPLATE(   R   RZ   (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyR     s    c         c   sj   i |  j  d 6|  j d 6|  j d 6|  j |  } x | D] } | Vq8 Wx |  j |  D] } | VqW Wd S(   s   Call the appropriate body-generation routine.

        Call one of generate_create_summary() /
        generate_update_summary() / generate_delete_summary().R   R   R   N(   t   generate_create_summaryt   generate_delete_summaryt   generate_update_summaryR   t    generate_revision_change_summary(   R   R   t   change_summaryRZ   (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyR     s    


	c         C   s   |  j  t  S(   N(   R   t   FOOTER_TEMPLATE(   R   (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyR     s    c         c   sT   |  j  rP d Vd Vx: t d d g |  j | d g d t D] } | Vq> Wn  d  S(   Ns   
s   Detailed log of new commits:

Rd   s	   --no-walks   --R   (   R   R/   R   R-   (   R   t   new_commits_listRZ   (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyt   generate_revision_change_log  s    	c         c   s*  |  j  j rh|  j j rht | j |    } | j   t |  } g  t |  D]1 \ } } t |  t	 |  d | d d | ^ qQ } | rF|  j
 d  Vd Vx= | D]5 } | j j   \ } } | j
 t d d d | Vq Wd Vx" |  j t d | D] }	 |	 Vq WxW |  j g  | D] } | j j ^ q D] }	 |	 Vq4Wq&x|  j t  D] }	 |	 VqVWn|  j  j r|  j j rt t d	 d
 d |  j j |  j  j f   }
 t t d |  j  j |  j j f   } |
 r| j |   } n g  } t |  } | rt | j |    } n t g   } | r|
 rxO | D]G \ } } | | k r^d } n d } |  j
 t d | d | d | Vq=WxO |
 D]G \ } } | | k rd } n d } |  j
 t d | d | d | VqWd Vx.|  j t  D] }	 |	 VqWn| rxO | D]G \ } } | | k r/d } n d } |  j
 t d | d | d | VqWd Vx |  j t  D] }	 |	 VqnWn |
 r|  j j   \ } } |  j
 t d d d | d | VxR |
 D]G \ } } | | k rd } n d } |  j
 t d | d | d | VqWn  d V| rhx( |  j t d t |  D] }	 |	 Vq7Wx> |  j |  D] }	 |	 VqVWn x |  j t  D] }	 |	 VqxWd Vd Vxt d g |  j d |  j j |  j  j f g d t D] }	 |	 VqWnI|  j j r|  j  j rt | j |    } t |  } g  t |  D]1 \ } } t |  t	 |  d | d d | ^ q$} | rx |  j t  D] }	 |	 VqqWd Vx_ | D]5 } | j j   \ } } | j
 t d d d | VqWq&x[ |  j t  D] }	 |	 VqWn< |  j j r&|  j  j r&x |  j t  D] }	 |	 VqWn  d S(   sA   Generate a summary of the revisions added/removed by this change.R   i   R   s:   This %(refname_type)s includes the following new commits:
s   
t   actionR   R:   s   --topo-orders	   --reverses   %s..%st   discardst   omitsR   t   addsR   s   Summary of changes:
s	   diff-treeR   N(   R   R   R   Re   t   get_new_commitst   reverseRP   Ri   R   R{   R   R   R   t   BRIEF_SUMMARY_TEMPLATER   t   NEW_REVISIONS_TEMPLATER   R   t   NO_NEW_REVISIONS_TEMPLATERh   Ro   t   get_discarded_commitst   NON_FF_TEMPLATEt   REWIND_ONLY_TEMPLATER/   R   R-   t   DISCARDED_REVISIONS_TEMPLATEt   NO_DISCARDED_REVISIONS_TEMPLATEt   NON_COMMIT_UPDATE_TEMPLATE(   R   R   t   sha1sR   Rx   R   t   new_revisionst   rR   RZ   R   R   R   t   new_commitst   discarded_commitsR   t   discarded_revisions(    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyR     s    
A	/	"				"			-A	c         c   s>   |  j  j   \ } } |  j t d d d | d | Vd Vd S(   s'   Called for the creation of a reference.R   t   atR   R:   s   
N(   R   R   R   R   (   R   R   R   R   (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyR   V  s
    c         C   s
   t  g   S(   s/   Called for the change of a pre-existing branch.(   R   (   R   R   (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyR   a  s    c         c   s>   |  j  j   \ } } |  j t d d d | d | Vd Vd S(   s1   Called for the deletion of any type of reference.R   t   wasR   R:   s   
N(   R   R   R   R   (   R   R   R   R   (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyR   f  s
    (   R   R   Rz   t   ret   compileR   Rc   R   R   R   R   R   R   R   R   R   R   R   R   R   (    (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyR     s   B											R   c           B   s   e  Z d  Z d   Z RS(   t   branchc         C   sD   t  j |  | d | d | d | d | d | | j |   |  _ d  S(   NR   R   R   R   R   (   R   R   t   get_refchange_recipientsR   (   R   R   R   R   R   R   R   (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyR   t  s
    	(   R   R   R   R   (    (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyR   q  s   R   c           B   sA   e  Z d  Z d   Z d Z d   Z d   Z d   Z d   Z RS(   s   annotated tagc         C   sP   t  j |  | d | d | d | d | d | | j |   |  _ | j |  _ d  S(   NR   R   R   R   R   (   R   R   t   get_announce_recipientsR   t   announce_show_shortlogt   show_shortlog(   R   R   R   R   R   R   R   (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyR     s    	s9   %(*objectname)
%(*objecttype)
%(taggername)
%(taggerdate)c   
   	   c   s#  t  d d |  j f |  j g  \ } } } } |  j t d d d | d d | f V| d k r y# t d	 d
 d |  j f g  } Wn t k
 r d } n X| r d | f Vq n! d } d t d d | g  f Vd | f Vd | f Vd Vt	 Vt
 t  d d |  j j g d t  } | | j d  d } | ra| d d d k ra| j d  n  x | D] } | VqhW|  j r| d k rd V| rt d d d | |  j f g d t }	 n% t d d d |  j f g d t }	 x+ t  d g d |	 d t D] } | VqWn  t Vd Vd S(   s+   Describe the new value of an annotated tag.s   for-each-refs   --format=%sR   t   taggingR   R:   s   (%s)R|   t   describes
   --abbrev=0s   %s^s     replaces  %s
s       length  %s bytes
s   cat-files   -ss    tagged by  %s
s           on  %s
s   
R}   R   i   is   rev-lists   --pretty=shorts   %s..%ss   %st   shortlogR   N(   R/   t   ANNOTATED_TAG_FORMATR   R   R   R    R   R
   R   t   LOGBEGINRe   R   R-   Rk   t   appendR  t   LOGEND(
   R   R   t	   tagobjectt   tagtypet   taggert   taggedt   prevtagt   contentsRZ   t   revlist(    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyt   describe_tag  sJ    +#
'		"c         c   sB   x |  j  t  D] } | Vq Wx |  j |  D] } | Vq/ Wd S(   s,   Called for the creation of an annotated tag.N(   R   t   TAG_CREATED_TEMPLATER  (   R   R   RZ   (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyR     s    	c         c   sB   x |  j  t  D] } | Vq Wx |  j |  D] } | Vq/ Wd S(   sn   Called for the update of an annotated tag.

        This is probably a rare event and may not even be allowed.N(   R   t   TAG_UPDATED_TEMPLATER  (   R   R   RZ   (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyR     s    	c         c   s6   x |  j  t  D] } | Vq W|  j d  Vd Vd S(   s1   Called when a non-annotated reference is updated.s      tag was  %(oldrev_short)s
s   
N(   R   t   TAG_DELETED_TEMPLATER   (   R   R   RZ   (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyR     s    	(	   R   R   R   R   R  R  R   R   R   (    (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyR   }  s   	
	@			R   c           B   s2   e  Z d  Z d   Z d   Z d   Z d   Z RS(   R}   c         C   sD   t  j |  | d | d | d | d | d | | j |   |  _ d  S(   NR   R   R   R   R   (   R   R   R  R   (   R   R   R   R   R   R   R   (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyR     s
    	c         c   s#   x |  j  t  D] } | Vq Wd S(   s,   Called for the creation of an annotated tag.N(   R   R  (   R   R   RZ   (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyR     s    c         c   s#   x |  j  t  D] } | Vq Wd S(   s1   Called when a non-annotated reference is updated.N(   R   R  (   R   R   RZ   (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyR     s    c         c   sE   x |  j  t  D] } | Vq Wx t j |  |  D] } | Vq2 Wd S(   s1   Called when a non-annotated reference is updated.N(   R   R  R   R   (   R   R   RZ   (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyR     s    	(   R   R   R   R   R   R   R   (    (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyR     s
   			R   c           B   s   e  Z d  Z d   Z RS(   t	   referencec         C   sD   t  j |  | d | d | d | d | d | | j |   |  _ d  S(   NR   R   R   R   R   (   R   R   R  R   (   R   R   R   R   R   R   R   (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyR     s
    	(   R   R   R   R   (    (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyR     s   t   Mailerc           B   s   e  Z d  Z d   Z RS(   s   An object that can send emails.c         C   s   t     d S(   s  Send an email consisting of lines.

        lines must be an iterable over the lines constituting the
        header and body of the email.  to_addrs is a list of recipient
        addresses (can be needed even if lines already contains a
        "To:" field).  It can be either a string (comma-separated list
        of email addresses) or a Python list of individual email
        addresses.

        N(   R   (   R   R[   t   to_addrs(    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyt   send!  s    (   R   R   Rz   R!  (    (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyR    s   t
   SendMailerc           B   sA   e  Z d  Z d d g Z e d    Z d d d  Z d   Z RS(   s$   Send emails using 'sendmail -oi -t'.s   /usr/sbin/sendmails   /usr/lib/sendmailc          C   s=   x6 t  j D] }  t j |  t j  r
 |  Sq
 Wt d   d  S(   NsI   No sendmail executable found.  Try setting multimailhook.sendmailCommand.(   R"  t   SENDMAIL_CANDIDATESRC   t   accesst   X_OKR   (   t   path(    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyt   find_sendmail8  s
    c         C   sN   | r | |  _  n |  j   d d g |  _  | rJ |  j  j d | g  n  d S(   s   Construct a SendMailer instance.

        command should be the command and arguments used to invoke
        sendmail, as a list of strings.  If an envelopesender is
        provided, it will also be passed to the command, via '-f
        envelopesender'.s   -ois   -ts   -fN(   t   commandR'  t   extend(   R   R(  t   envelopesender(    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyR   C  s
    c         C   s   y t  j |  j d t  j } WnR t k
 rs } t j j d d j |  j  d t	 |  d  t j
 d  n Xy | j j |  Wn$ t j j d  | j     n5 X| j j   | j   } | r t |  j |   n  d  S(   NR!   s   *** Cannot execute command: %s
R   s   *** %s
sf   *** Try setting multimailhook.mailer to "smtp"
*** to send emails without using the sendmail command.
i   sE   *** Error while generating commit email
***  - mail sending aborted.
(   R$   R&   R(  R%   t   OSErrorR   R#   R   R   R5   t   exitR!   t
   writelinest	   terminatet   closeR(   R
   (   R   R[   R   R*   RW   R   (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyR!  S  s"    	)	
N(	   R   R   Rz   R#  Rc   R'  R   R   R!  (    (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyR"  0  s   	t
   SMTPMailerc           B   s)   e  Z d  Z d   Z d   Z d   Z RS(   s#   Send emails using Python's smtplib.c         C   s   | s& t  j j d  t  j d  n  | |  _ | |  _ y t j |  j  |  _ WnQ t	 k
 r } t  j j d |  j  t  j j d t
 |   t  j d  n Xd  S(   Ns   fatal: git_multimail: cannot use SMTPMailer without a sender address.
please set either multimailhook.envelopeSender or user.email
i   s0   *** Error establishing SMTP connection to %s***
s   *** %s
(   R   R#   R   R,  R*  t
   smtpservert   smtplibt   SMTPt   smtpR   R5   (   R   R*  R1  RW   (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyR   q  s    			c         C   s   |  j  j   d  S(   N(   R4  t   quit(   R   (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyt   __del__  s    c         C   s   yf d j  |  } t | t  rL g  t | g  D] \ } } | ^ q1 } n  |  j j |  j | |  WnW t k
 r } t j	 j
 d  t j	 j
 d t |   |  j j   t j d  n Xd  S(   NRI   s   *** Error sending email***
s   *** %s
i   (   R   R4   t
   basestringR   R4  t   sendmailR*  R   R   R#   R   R5   R5  R,  (   R   R[   R   t   msgR=   t   emailRW   (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyR!    s    +(   R   R   Rz   R   R6  R!  (    (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyR0  n  s   		t   OutputMailerc           B   s.   e  Z d  Z d d d Z d   Z d   Z RS(   su   Write emails to an output stream, bracketed by lines of '=' characters.

    This is intended for debugging purposes.t   =iK   s   
c         C   s   | |  _  d  S(   N(   t   f(   R   R=  (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyR     s    c         C   s:   |  j  j |  j  |  j  j |  |  j  j |  j  d  S(   N(   R=  R   t	   SEPARATORR-  (   R   R[   R   (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyR!    s    (   R   R   Rz   R>  R   R!  (    (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyR;    s   	c           C   sI   y t  d d g  SWn. t k
 rD t j j d  t j d  n Xd S(   s   Determine GIT_DIR.

    Determine GIT_DIR either from the GIT_DIR environment variable or
    from the working directory, using Git's usual rules.s	   rev-parses	   --git-dirs-   fatal: git_multimail: not in a git directory
i   N(   R    R
   R   R#   R   R,  (    (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyt   get_git_dir  s
    t   Environmentc           B   s   e  Z d  Z e j d  Z d d  Z d   Z d   Z	 d   Z
 d   Z d   Z d   Z d	   Z d
   Z d   Z d   Z d   Z d   Z d   Z d   Z RS(   s  Describes the environment in which the push is occurring.

    An Environment object encapsulates information about the local
    environment.  For example, it knows how to determine:

    * the name of the repository to which the push occurred

    * what user did the push

    * what users want to be informed about various types of changes.

    An Environment object is expected to have the following methods:

        get_repo_shortname()

            Return a short name for the repository, for display
            purposes.

        get_repo_path()

            Return the absolute path to the Git repository.

        get_emailprefix()

            Return a string that will be prefixed to every email's
            subject.

        get_pusher()

            Return the username of the person who pushed the changes.
            This value is used in the email body to indicate who
            pushed the change.

        get_pusher_email() (may return None)

            Return the email address of the person who pushed the
            changes.  The value should be a single RFC 2822 email
            address as a string; e.g., "Joe User <user@example.com>"
            if available, otherwise "user@example.com".  If set, the
            value is used as the Reply-To address for refchange
            emails.  If it is impossible to determine the pusher's
            email, this attribute should be set to None (in which case
            no Reply-To header will be output).

        get_sender()

            Return the address to be used as the 'From' email address
            in the email envelope.

        get_fromaddr()

            Return the 'From' email address used in the email 'From:'
            headers.  (May be a full RFC 2822 email address like 'Joe
            User <user@example.com>'.)

        get_administrator()

            Return the name and/or email of the repository
            administrator.  This value is used in the footer as the
            person to whom requests to be removed from the
            notification list should be sent.  Ideally, it should
            include a valid email address.

        get_reply_to_refchange()
        get_reply_to_commit()

            Return the address to use in the email "Reply-To" header,
            as a string.  These can be an RFC 2822 email address, or
            None to omit the "Reply-To" header.
            get_reply_to_refchange() is used for refchange emails;
            get_reply_to_commit() is used for individual commit
            emails.

    They should also define the following attributes:

        announce_show_shortlog (bool)

            True iff announce emails should include a shortlog.

        refchange_showlog (bool)

            True iff refchanges emails should include a detailed log.

        diffopts (list of strings)

            The options that should be passed to 'git diff' for the
            summary email.  The value should be a list of strings
            representing words to be passed to the command.

        logopts (list of strings)

            Analogous to diffopts, but contains options passed to
            'git log' when generating the detailed log for a set of
            commits (see refchange_showlog)

        commitlogopts (list of strings)

            The options that should be passed to 'git log' for each
            commit mail.  The value should be a list of strings
            representing words to be passed to the command.

    s   ^(?P<name>.+?)(?:\.git)$c      
   C   s   | p t  j |  _ t |  _ d |  _ d d d g |  _ g  |  _ t |  _ d d d d g |  _	 d d	 d
 d d d d d d g	 |  _
 d  |  _ d  S(   Ni  s   --stats	   --summarys   --find-copies-harders   -Cs   -ps   --cct   administratorR2   t   emailprefixt   fromaddrt   pushert   pusher_emailt	   repo_patht   repo_shortnameR	   (   RC   RD   t   osenvR   R
  t   maxcommitemailsR   R   R   R   t   COMPUTED_KEYSR   R   (   R   RH  (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyR     s"    				c         C   sQ   t  j j t  j j |  j     } |  j j |  } | rI | j d  S| Sd S(   sH   Use the last part of the repo path, with ".git" stripped off if present.R=   N(   RC   R&  t   basenamet   abspatht   get_repo_patht   REPO_NAME_RER   R   (   R   RK  R   (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyt   get_repo_shortname0  s
    $c         C   s   t     d  S(   N(   R   (   R   (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyt
   get_pusher:  s    c         C   s   d  S(   N(   R   (   R   (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyt   get_pusher_email=  s    c         C   s   d S(   Ns$   the administrator of this repository(    (   R   (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyt   get_administrator@  s    c         C   s   d S(   NRI   (    (   R   (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyt   get_emailprefixC  s    c         C   sF   t  d d g  d k r$ t   } n t  d d g  } t j j |  S(   Ns	   rev-parses   --is-bare-repositoryRT   s   --show-toplevel(   R    R?  RC   R&  RL  (   R   R&  (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyRM  F  s    c         C   s   t  S(   N(   R9   (   R   (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyt   get_charsetM  s    c         C   st   |  j  d k rg i  } xC |  j D]8 } t |  d | f    } | d k	 r | | | <q q W| |  _  n  |  j  j   S(   s  Return a dictionary {keyword : expansion} for this Environment.

        This method is called by Change._compute_values().  The keys
        in the returned dictionary are available to be used in any of
        the templates.  The dictionary is created by calling
        self.get_NAME() for each of the attributes named in
        COMPUTED_KEYS and recording those that do not return None.
        The return value is always a new dictionary.s   get_%sN(   R   R   RJ  t   getattrRE   (   R   RR   t   keyRU   (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyR   P  s    
c         C   s   t     d S(   s   Return the recipients for notifications about refchange.

        Return the list of email addresses to which notifications
        about the specified ReferenceChange should be sent.N(   R   (   R   t	   refchange(    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyR  f  s    c         C   s   t     d S(   s   Return the recipients for notifications about annotated_tag_change.

        Return the list of email addresses to which notifications
        about the specified AnnotatedTagChange should be sent.N(   R   (   R   t   annotated_tag_change(    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyR	  n  s    c         C   s
   |  j    S(   N(   RQ  (   R   RW  (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyR   v  s    c         C   s   t     d S(   s  Return the recipients for messages about revision.

        Return the list of email addresses to which notifications
        about the specified Revision should be sent.  This method
        could be overridden, for example, to take into account the
        contents of the revision when deciding whom to notify about
        it.  For example, there could be a scheme for users to express
        interest in particular files or subdirectories, and only
        receive notification emails for revisions that affecting those
        files.N(   R   (   R   t   revision(    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyR   y  s    c         C   s   | j  S(   N(   R   (   R   RY  (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyR     s    c         C   s   | S(   sv  Filter the lines intended for an email body.

        lines is an iterable over the lines that would go into the
        email body.  Filter it (e.g., limit the number of lines, the
        line length, character set, etc.), returning another iterable.
        See FilterLinesEnvironmentMixin and MaxlinesEnvironmentMixin
        for classes implementing this functionality.(    (   R   R[   (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyt   filter_body  s    	N(   R   R   Rz   R  R  RN  R   R   RO  RP  RQ  RR  RS  RM  RT  R   R  R	  R   R   R   RZ  (    (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyR@    s"   f	
												t   ConfigEnvironmentMixinc           B   s   e  Z d  Z d   Z RS(   s}  A mixin that sets self.config to its constructor's config argument.

    This class's constructor consumes the "config" argument.

    Mixins that need to inspect the config should inherit from this
    class (1) to make sure that "config" is still in the constructor
    arguments with its own constructor runs and/or (2) to be sure that
    self.config is set after construction.c         K   s#   t  t |   j |   | |  _ d  S(   N(   t   superR[  R   RO   (   R   RO   R   (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyR     s    (   R   R   Rz   R   (    (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyR[    s   t   ConfigOptionsEnvironmentMixinc           B   sV   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 RS(	   sD   An Environment that reads most of its information from "git config".c         K   s  t  t |   j d | |  | j d d |  j |  _ | j d d |  j |  _ | j d  } | d  k	 r y t |  |  _	 Wq t
 k
 r t j j d | d  q Xn  | j d  } | d  k	 r t j |  |  _ n  | j d	  } | d  k	 rt j |  |  _ n  | j d
  } | d  k	 r?t j |  |  _ n  | j d  } | j d d | |  _ |  j d  k	 r|  j j   d k rt d   n  | j d d | |  _ d  S(   NRO   t   announceshortlogRQ   t   refchangeshowlogRI  s:   *** Malformed value for multimailhook.maxCommitEmails: %s
s"   *** Expected a number.  Ignoring.
R   R   R   t   replyTot   replyToRefchangeR   s7   "author" is not an allowed setting for replyToRefchanget   replyToCommit(   R\  R]  R   RV   R
  R   RS   R   t   intRI  R   R   R#   R   t   shlexRJ   R   R   R   t2   _ConfigOptionsEnvironmentMixin__reply_to_refchangeR   R   t/   _ConfigOptionsEnvironmentMixin__reply_to_commit(   R   RO   R   RI  R   R   R   R   (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyR     s<    
	c         C   s1   |  j  j d  p0 |  j   p0 t t |   j   S(   NRA  (   RO   RS   t
   get_senderR\  R]  RR  (   R   (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyRR    s    c         C   s%   |  j  j d  p$ t t |   j   S(   Nt   reponame(   RO   RS   R\  R]  RO  (   R   (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyRO    s    c         C   sG   |  j  j d  } | r2 | j   r2 | j   d Sd |  j   f Sd  S(   NRB  R   s   [%s] (   RO   RS   RY   RO  (   R   RB  (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyRS    s    c         C   s   |  j  j d  S(   NR*  (   RO   RS   (   R   (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyRg    s    c         C   sv   |  j  j d  } | r | St d  } | j d d d } | j d d d } | rh t | | g  S|  j   Sd  S(   NR   t   userR=   RQ   RI   R:  (   RO   RS   R@   R   Rg  (   R   RC  RO   t   fromnamet	   fromemail(    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyt   get_fromaddr  s    c         C   sh   |  j  d  k r% t t |   j |  S|  j  j   d k rD |  j   S|  j  j   d k r] d  S|  j  Sd  S(   NRD  t   none(   Re  R   R\  R]  R   R   RQ  (   R   RW  (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyR     s    
c         C   s   |  j  d  k r% t t |   j |  S|  j  j   d k rD | j   S|  j  j   d k rc |  j   S|  j  j   d k r| d  S|  j  Sd  S(   NR   RD  Rm  (   Rf  R   R\  R]  R   R   t
   get_authorRQ  (   R   RY  (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyR     s    

(   R   R   Rz   R   RR  RO  RS  Rg  Rl  R   R   (    (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyR]    s   	.						
t   FilterLinesEnvironmentMixinc           B   s&   e  Z d  Z e d d  Z d   Z RS(   s  Handle encoding and maximum line length of body lines.

        emailmaxlinelength (int or None)

            The maximum length of any single line in the email body.
            Longer lines are truncated at that length with ' [...]'
            appended.

        strict_utf8 (bool)

            If this field is set to True, then the email body text is
            expected to be UTF-8.  Any invalid characters are
            converted to U+FFFD, the Unicode replacement character
            (encoded as UTF-8, of course).

    i  c         K   s,   t  t |   j |   | |  _ | |  _ d  S(   N(   R\  Ro  R   t)   _FilterLinesEnvironmentMixin__strict_utf8t0   _FilterLinesEnvironmentMixin__emailmaxlinelength(   R   t   strict_utf8t   emailmaxlinelengthR   (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyR   #  s    	c         C   s   t  t |   j |  } |  j rb d   | D } |  j rO t | |  j  } n  d   | D } n |  j r t | |  j  } n  | S(   Nc         s   s!   |  ] } | j  t d   Vq d S(   R0   N(   R6   R   (   R<   RZ   (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pys	   <genexpr>+  s    c         s   s!   |  ] } | j  t d   Vq d S(   R0   N(   R7   R   (   R<   RZ   (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pys	   <genexpr>0  s    (   R\  Ro  RZ  Rp  Rq  Rn   (   R   R[   (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyRZ  (  s    			(   R   R   Rz   R-   R   RZ  (    (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyRo    s   t!   ConfigFilterLinesEnvironmentMixinc           B   s   e  Z d  Z d   Z RS(   s8   Handle encoding and maximum line length based on config.c         K   s|   | j  d d d  } | d  k	 r. | | d <n  | j d  } | d  k	 r\ t |  | d <n  t t |   j d | |  d  S(   Nt   emailstrictutf8RQ   Rr  Rs  RO   (   RV   R   RS   Rc  R\  Rt  R   (   R   RO   R   Rr  Rs  (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyR   =  s    (   R   R   Rz   R   (    (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyRt  7  s   t   MaxlinesEnvironmentMixinc           B   s    e  Z d  Z d   Z d   Z RS(   s4   Limit the email body to a specified number of lines.c         K   s#   t  t |   j |   | |  _ d  S(   N(   R\  Rv  R   t(   _MaxlinesEnvironmentMixin__emailmaxlines(   R   t   emailmaxlinesR   (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyR   N  s    c         C   s:   t  t |   j |  } |  j r6 t | |  j  } n  | S(   N(   R\  Rv  RZ  Rw  Rl   (   R   R[   (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyRZ  R  s    	(   R   R   Rz   R   RZ  (    (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyRv  K  s   	t   ConfigMaxlinesEnvironmentMixinc           B   s   e  Z d  Z d   Z RS(   s@   Limit the email body to the number of lines specified in config.c         K   sA   t  | j d d d  } t t |   j d | d | |  d  S(   NRx  RQ   R   RO   (   Rc  RS   R\  Ry  R   (   R   RO   R   Rx  (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyR   _  s
    (   R   R   Rz   R   (    (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyRy  Y  s   t   PusherDomainEnvironmentMixinc           B   s    e  Z d  Z d   Z d   Z RS(   s<   Deduce pusher_email from pusher by appending an emaildomain.c         K   s/   t  t |   j |   |  j j d  |  _ d  S(   Nt   emaildomain(   R\  Rz  R   RO   RS   t*   _PusherDomainEnvironmentMixin__emaildomain(   R   R   (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyR   k  s    c         C   s7   |  j  r  d |  j   |  j  f St t |   j   Sd  S(   Ns   %s@%s(   R|  RP  R\  Rz  RQ  (   R   (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyRQ  o  s    	(   R   R   Rz   R   RQ  (    (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyRz  h  s   	t    StaticRecipientsEnvironmentMixinc           B   s2   e  Z d  Z d   Z d   Z d   Z d   Z RS(   s:   Set recipients statically based on constructor parameters.c         K   s5   t  t |   j |   | |  _ | |  _ | |  _ d  S(   N(   R\  R}  R   t7   _StaticRecipientsEnvironmentMixin__refchange_recipientst6   _StaticRecipientsEnvironmentMixin__announce_recipientst6   _StaticRecipientsEnvironmentMixin__revision_recipients(   R   t   refchange_recipientst   announce_recipientst   revision_recipientsR   (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyR   z  s    			c         C   s   |  j  S(   N(   R~  (   R   RW  (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyR    s    c         C   s   |  j  S(   N(   R  (   R   RX  (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyR	    s    c         C   s   |  j  S(   N(   R  (   R   RY  (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyR     s    (   R   R   Rz   R   R  R	  R   (    (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyR}  w  s
   			t    ConfigRecipientsEnvironmentMixinc           B   s    e  Z d  Z d   Z d   Z RS(   s0   Determine recipients statically based on config.c         K   sb   t  t |   j d | d |  j | d d  d |  j | d d d  d |  j | d d  |  d  S(	   NRO   R  t   refchangelistt   mailinglistR  t   announcelistR  t
   commitlist(   R\  R  R   t   _get_recipients(   R   RO   R   (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyR     s    c            s   x- | D]% }   j  |  } | d k	 r | Sq Wt |  d k rX d   j | f } n# d d j   f d   | D  } t d | d | f   d S(	   s  Return the recipients for a particular type of message.

        Return the list of email addresses to which a particular type
        of notification email should be sent, by looking at the config
        value for "multimailhook.$name" for each of names.  Use the
        value from the first name that is configured.  The return
        value is a (possibly empty) string containing RFC 2822 email
        addresses separated by commas.  If no configuration could be
        found, raise a ConfigurationException.i   s   Please set "%s.%s"s)   Please set one of the following:
    "%s"s   "
    "c         3   s"   |  ] } d    j  | f Vq d S(   s   %s.%sN(   RB   (   R<   R=   (   RO   (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pys	   <genexpr>  s    s3   The list of recipients for %s is not configured.
%si    N(   R\   R   RP   RB   R   R   (   R   RO   Rr   R=   t   retvalt   hint(    (   RO   s/   /home/cloos/live-x11.git/hooks/git_multimail.pyR    s     (   R   R   Rz   R   R  (    (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyR    s   	t   ProjectdescEnvironmentMixinc           B   s    e  Z d  Z d   Z d   Z RS(   s   Make a "projectdesc" value available for templates.

    By default, it is set to the first line of $GIT_DIR/description
    (if that file is present and appears to be set meaningfully).c         K   s,   t  t |   j |   |  j d g 7_ d  S(   Nt   projectdesc(   R\  R  R   RJ  (   R   R   (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyR     s    c         C   sf   t    } yE t t j j | d   j   j   } | rM | j d  rM | SWn t k
 ra n Xd S(   s.   Return a one-line descripition of the project.t   descriptions   Unnamed repositorys   UNNAMED PROJECT(	   R?  t   openRC   R&  R   t   readlineRY   Rv   t   IOError(   R   t   git_dirR  (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyt   get_projectdesc  s    	'(   R   R   Rz   R   R  (    (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyR    s   	t   GenericEnvironmentMixinc           B   s   e  Z d    Z RS(   c         C   s   |  j  j d d  S(   Nt   USERs   unknown user(   RH  RS   (   R   (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyRP    s    (   R   R   RP  (    (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyR    s   t   GenericEnvironmentc           B   s   e  Z RS(    (   R   R   (    (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyR    s   
t   GitoliteEnvironmentMixinc           B   s   e  Z d    Z d   Z RS(   c         C   s(   |  j  j d d   p' t t |   j   S(   Nt   GL_REPO(   RH  RS   R   R\  R  RO  (   R   (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyRO    s    c         C   s   |  j  j d d  S(   Nt   GL_USERs   unknown user(   RH  RS   (   R   (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyRP    s    (   R   R   RO  RP  (    (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyR    s   		t   GitoliteEnvironmentc           B   s   e  Z RS(    (   R   R   (    (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyR    s   
t   Pushc           B   s   e  Z d  Z e d   e e d f e d f e d f e d f e d f e d f e d f e d f e d f e d f e d f e d f g  D  Z	 d   Z
 e d    Z d   Z d   Z d d	  Z d
   Z d d  Z RS(   s*  Represent an entire push (i.e., a group of ReferenceChanges).

    It is easy to figure out what commits were added to a *branch* by
    a Reference change:

        git rev-list change.old..change.new

    or removed from a *branch*:

        git rev-list change.new..change.old

    But it is not quite so trivial to determine which entirely new
    commits were added to the *repository* by a push and which old
    commits were discarded by a push.  A big part of the job of this
    class is to figure out these things, and to make sure that new
    commits are only detailed once even if they were added to multiple
    references.

    The first step is to determine the "other" references--those
    unaffected by the current push.  They are computed by
    Push._compute_other_ref_sha1s() by listing all references then
    removing any affected by this push.

    The commits contained in the repository before this push were

        git rev-list other1 other2 other3 ... change1.old change2.old ...

    Where "changeN.old" is the old value of one of the references
    affected by this push.

    The commits contained in the repository after this push are

        git rev-list other1 other2 other3 ... change1.new change2.new ...

    The commits added by this push are the difference between these
    two sets, which can be written

        git rev-list             ^other1 ^other2 ...             ^change1.old ^change2.old ...             change1.new change2.new ...

    The commits removed by this push can be computed by

        git rev-list             ^other1 ^other2 ...             ^change1.new ^change2.new ...             change1.old change2.old ...

    The last point is that it is possible that other pushes are
    occurring simultaneously to this one, so reference values can
    change at any time.  It is impossible to eliminate all race
    conditions, but we reduce the window of time during which problems
    can occur by translating reference names to SHA1s as soon as
    possible and working with SHA1s thereafter (because SHA1s are
    immutable).c         c   s!   |  ] \ } } | | f Vq d  S(   N(    (   R<   Rx   RU   (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pys	   <genexpr>N  s    R   R   R   c         C   sx   t  | d |  j |  _ |  j   } |  j | j d   |  j D   |  _ |  j | j d   |  j D   |  _ d  S(   NRV  c         s   s-   |  ]# } | j  j d k r | j  j Vq d S(   R|   R}   N(   s   commits   tag(   R   R   R   (   R<   t   change(    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pys	   <genexpr>g  s   c         s   s-   |  ]# } | j  j d k r | j  j Vq d S(   R|   R}   N(   s   commits   tag(   R   R   R   (   R<   R  (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pys	   <genexpr>n  s   (   Rp   t	   _sort_keyt   changest   _compute_other_ref_sha1st   _compute_rev_exclusion_spect   uniont   _old_rev_exclusion_spect   _new_rev_exclusion_spec(   R   R  t   other_ref_sha1s(    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyR   ^  s    c         C   s    |  j  | j | j f | j f S(   N(   t
   SORT_ORDERt	   __class__R   R   (   R   R  (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyR  t  s    c         C   s   t  d   |  j D  } t    } d } xj t d d | f g  D]O } | j d d  \ } } } | rB | d k rB | | k rB | j |  qB qB W| S(   sH   Return the GitObjects referred to by references unaffected by this push.c         s   s   |  ] } | j  Vq d  S(   N(   R   (   R<   R  (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pys	   <genexpr>}  s   sO   %(objectname) %(objecttype) %(refname)
%(*objectname) %(*objecttype) %(refname)s   for-each-refs   --format=%sR   i   R|   (   R]   R  R/   RJ   R^   (   R   t   updated_refsR   t   fmtRZ   R   R   R=   (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyR  x  s    	 c         C   s-   d j  g  t |  D] } d | f ^ q  S(   s  Return an exclusion specification for 'git rev-list'.

        git_objects is an iterable over GitObject instances.  Return a
        string that can be passed to the standard input of 'git
        rev-list --stdin' to exclude all of the commits referred to by
        git_objects.RI   s   ^%s
(   R   Rp   (   R   R   R   (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyR    s    c         C   sd   | s" t  d   |  j D  } n | j j s2 g  S| j j g } d d g | } t | d |  j S(   s  Return a list of commits added by this push.

        Return a list of the object names of commits that were added
        by the part of this push represented by reference_change.  If
        reference_change is None, then return a list of *all* commits
        added by this push.c         s   s$   |  ] } | j  r | j  j Vq d  S(   N(   R   R   (   R<   R  (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pys	   <genexpr>  s   s   rev-lists   --stdinR   (   Rp   R  R   R   R/   R  (   R   R   t   new_revsR   (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyR     s    c         C   sB   | j  j s g  S| j  j g } d d g | } t | d |  j S(   s   Return a list of commits discarded by this push.

        Return a list of the object names of commits that were
        entirely discarded from the repository by the part of this
        push represented by reference_change.s   rev-lists   --stdinR   (   R   R   R/   R  (   R   R   t   old_revsR   (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyR     s
    c   
      C   s  t  |  j    } x|  j D]} | j sZ t j j d | j | j j	 | j
 j	 f  n9 t j j d | j f  | j | j |  |  | j  g  } xL t t |  j |    D]/ } | | k r | j |  | j |  q q W| j j } | r6t |  | k r6t j j d t |  d d |  d Sxp t |  D]b \ } } t | t |  d | d d	 t |  }	 |	 j rC| j |	 j |  |  |	 j  qCqCWq W| rt j j d
 d j t |   f  n  d S(   s\  Use send all of the notification emails needed for this push.

        Use send all of the notification emails (including reference
        change emails and commit emails) needed for this push.  Send
        the emails using mailer.  If body_filter is not None, then use
        it to filter the lines that are intended for the email
        body.sO   *** no recipients configured so no email will be sent
*** for %r update %s->%s
s#   Sending notification emails to: %s
s:   *** Too many new commits (%d), not sending commit emails.
sA   *** Try setting multimailhook.maxCommitEmails to a greater value
s0   *** Currently, multimailhook.maxCommitEmails=%d
NR   i   R   sA   ERROR: No emails were sent for the following new commits:
    %s
s   
    (   R]   R   R  R   R   R#   R   R   R   R   R   R!  R   t   reversedRe   R  t   removeR   RI  RP   Ri   R   R{   R   Rp   (
   R   t   mailerR   t   unhandled_sha1sR  R   R   t
   max_emailsR   R   (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyt   send_emails  s4    		#"	+	*	N(   R   R   Rz   t   dictRi   R   R   R   R   R  R   t   classmethodR  R  R  R   R   R   R  (    (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyR    s,   8																	c         C   s   g  } xQ t  j D]F } | j   j d d  \ } } } | j t j |  | | |   q Wt |  } | j | d |  j	 d  S(   NR   i   R   (
   R   R!   RY   RJ   R  R   R   R  R  RZ  (   R   R  R  RZ   R   R   R   R   (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyt   run_as_post_receive_hook  s    !c         C   s_   t  j |  t d d | g  t d d | g  |  g } t |  } | j | d |  j d  S(   Ns	   rev-parses   --verifyR   (   R   R   R    R  R  RZ  (   R   R  R   R   R   R  R   (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyt   run_as_update_hook	  s    c         C   s   |  j  d d d } | d k r` |  j  d d d } t d | j   pQ | j   d |  } nv | d k r |  j  d  } | r t j |  } n  t d	 | d | j    } n% t j j	 d
 | d  t j
 d  | S(   NR  RQ   R8  R4  R1  t	   localhostR*  t   sendmailcommandR(  s?   fatal: multimailhook.mailer is set to an incorrect value: "%s"
s(   please use one of "smtp" or "sendmail".
i   (   RS   R0  Rg  Rl  Rd  RJ   R"  R   R#   R   R,  (   RO   R   R  R1  R(  (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyt   choose_mailer	  s     	t   generict   gitolitec         C   s  | s t  j } n  t t t t t g } i | d 6|  d 6} | sS |  j d  } n  | s d | k rz d | k rz d } q d } n  | j t	 |  | r | j
 d t  | | d	 <| | d
 <| | d <n | j
 d t  t d t |  t f i   } | |   S(   NRH  RO   R   R  R  R  R  i    R  R  R  t   EffectiveEnvironment(   RC   RD   R  Ry  Rt  Rz  R]  RS   R  t   KNOWN_ENVIRONMENTSt   insertR}  R  R   Rf   R@  (   RO   RH  RF   R   t   environment_mixinst   environment_kwt   environment_klass(    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyt   choose_environment,	  s8    	
		

	c         C   s  t  j d t d d  } | j d d d d d d	 d
 d d g d d  d d | j d d d d t d d | j d d d d d  d d | j d d d d t d d | j |   \ } }  t d  } y!t | d t	 j
 d | j d | j } | j rct j j d  x@ t | j   j    D]& \ } } t j j d | | f  q&Wt j j d  n  | j r~t t j  } n t | |  } |  rt |   d k r| j d  n  |  \ } }	 }
 t | | | |	 |
  n t | |  Wn& t k
 r} t j t |   n Xd  S(    NR  t   usages<   %prog [OPTIONS]
   or: %prog [OPTIONS] REFNAME OLDREV NEWREVs   --environments   --envR   t   storeR   t   choicet   choicesR  R  RQ   t   helpss   Choose type of environment is in use.  Default is taken from multimailhook.environment if set; otherwise "generic".s   --stdoutt
   store_trues1   Output emails to stdout rather than sending them.s   --recipientss5   Set list of email recipients for all types of emails.s
   --show-envs\   Write to stderr the values determined for the environment (intended for debugging purposes).t   multimailhookRH  RF   R   s   Environment values:
s       %s : %r
s   
i   s'   Need zero or three non-option arguments(   t   optparset   OptionParserRz   t
   add_optionR   R   t
   parse_argsR@   R  RC   RD   R   R   t   show_envR   R#   R   Rp   R   t   itemsR"   R;  R  RP   t   errorR  R  R   R,  R5   (   R   t   parsert   optionsRO   R   t   kt   vR  R   R   R   RW   (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyt   mainW	  sN    				%	t   __main__i   (f   Rz   R   RC   R  Rt   R$   Rd  R  R2  t   email.utilsR    R   R   t   email.headerR   t   ImportErrort   email.Utilst   email.HeaderR   R   R~   R  R  R]   R   R   R9   R   R   R   R   R   R   R   R   R   R   R   R   R  R  R  R   R   R   R   R   R   R
   R   R   R   R   R   R    R   R/   R;   R?   t   objectR@   Rh   Rl   Rn   Ro   R{   R   R   R   R   R   R   R   R  R"  R0  R;  R?  R@  R[  R]  Ro  Rt  Rv  Ry  Rz  R}  R  R  R  R  R  R  R  R  R  R  R  R  R  R   t   argv(    (    (    s/   /home/cloos/live-x11.git/hooks/git_multimail.pyt   <module>.   s   
	
		n				,< {q!>$	l&/			
+	A