^c|*dZddlmZddlmcmZddlmcm Z ddl m Z ddlZddlZddlmZddlmZddlmZddlmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$ddl%m&Z&m'Z'e$j(Z(iZ)e!j*e)Z*iZ+e!j,e+Z,e,dd d e,dd d e,dd d e,dd d e,ddd e,ddd e,ddd e,ddd e,ddd e,ddd dZ-dZ.dZ/dZ0dsdZ1dZ2dZ3dZ4 dtdZ5d Z6d!Z7d"Z8d#Z9d$Z:dtd%Z;d&Zfd?dd(ed@ed2fdAdBdedCfdDdEd(edFed>fd(dgedGed2fdHdId(edJedKfd(dLd(edMedNfd(dOgedPedQfdRdgedSed2fgZ>e*dTdUdVdedWfd(dXdedYfdZd[ded\fd]d^ded_fd`dad(edbedcfd(ddd^edeedffdgdhgediedjfd(dkdedlfd(dmgednedjfd(ddedofg e>zej?zedpe*j@qdrZAdS)uas command to send changesets as (a series of) patch emails The series is started off with a "[PATCH 0 of N]" introduction, which describes the series as a whole. Each patch email has a Subject line of "[PATCH M of N] ...", using the first line of the changeset description as the subject text. The message contains two or three body parts: - The changeset description. - [Optional] The result of running diffstat on the patch. - The patch itself, as generated by :hg:`export`. Each message refers to the first in the series using the In-Reply-To and References headers, so they will show up as a sequence in threaded mail and news readers, and in mail archives. To configure other defaults, add a section like this to your configuration file:: [email] from = My Name to = recipient1, recipient2, ... cc = cc1, cc2, ... bcc = bcc1, bcc2, ... reply-to = address1, address2, ... Use ``[patchbomb]`` as configuration section name if you need to override global ``[email]`` address settings. Then you can use the :hg:`email` command to mail a series of changesets as a patchbomb. You can also either configure the method option in the email section to be a sendmail compatible mailer or fill out the [smtp] section so that the patchbomb extension can automatically send patchbombs directly from the commandline. See the [email] and [smtp] sections in hgrc(5) for details. By default, :hg:`email` will prompt for a ``To`` or ``CC`` header if you do not supply one via configuration or the command line. You can override this to never prompt by configuring an empty value:: [email] cc = You can control the default inclusion of an introduction message with the ``patchbomb.intro`` configuration option. The configuration is always overwritten by command line flags like --intro and --desc:: [patchbomb] intro=auto # include introduction message if more than 1 patch (default) intro=never # never include an introduction message intro=always # always include an introduction message You can specify a template for flags to be added in subject prefixes. Flags specified by --flag option are exported as ``{flags}`` keyword:: [patchbomb] flagtemplate = "{separate(' ', ifeq(branch, 'default', '', branch|upper), flags)}" You can set patchbomb to always ask for confirmation by setting ``patchbomb.confirm`` to true. N)_)open)bin)cmdutilcommandsencodingerror formatterhg logcmdutilmailpatchpycompat registrarscmutil templaterutil)dateutilurlutil patchbomb bundletypedefaultsbccsccconfirmF flagtemplatefromintroauto publicurlsreply-tostosships-with-hg-corecx|}|jdd}|rd|||fzSdS)zFAdd a header pointing to a public URL where the changeset is availablerrs/Available At %s # hg pull %s -r %sN)repouiconfig)seqctxr! publicurls 1/usr/lib/python3/dist-packages/hgext/patchbomb.py_addpullheaderr(sQ 88::D|\::I B   F   4cltjdttjd<dS)Nspullurl)r extraexportappendr(extraexportmap)r"s r'uisetupr.s, z***)7G:&&&r)cf|sdS|jddS)Nlast-email.txt)local_wlockfreeprefixadd)r"r!s r' reposetupr4s5 ::<</00000r):cH|r|d|zz }|||z|S)Ns [%s])prompt)r"r7rrests r'r7r7s1%(W$$ 99Vd]G , ,,r)cd|dd}|ds|drd}nl|dkrd}nc|dkrd}nZ|dkr|d k}nM|td |z|td |d k}|S) z-is an introductory message apparently wanted?rrdescTsalwayssneverFrs,warning: invalid patchbomb.intro value "%s" s'(should be one of always, never, auto) )r#get write_errr)r"optsnumber introconfigintros r' introwantedrBs))L(33K xx TXXg..   ! !       > ? ?+ M    QBCCDDD  Lr)c |dd}|sd|Stj}t jt j|}t j||di|5}| | ||| dd| |d d d d n #1swxYwY| S) z(build flag string optionally by templaterr s patchbombflag)r%sflagss%sflag)nameN)r#joinrstringior literal_templatespecr unquotestringtemplateformatter startitemcontextwrite formatlistgetvalue)r"r!revflagstmploutspecfms r' _formatflagsrWs, 99\? 3 3D  yy -//C  ))*A$*G*G H HD  $R.>D I IFR  tCy !!! 5"--G-"D"DEEEFFFFFFFFFFFFFFF <<>>s?AC((C,/C,cxt||||}|rd|z}|sd|zStd|z}d||||fzS)zbuild prefix to patch subjectrDs [PATCH%s]%ds[PATCH %0*d of %d%s])rWlen) r"r!rQrRidxtotalnumberedflagtlens r' _formatprefixr`s_ D#u - -D d{ Bd""55=!!&$UD)AAAr)c  g} d} d} |D]} | dr0| dr| d} G| ds| drn| | | s | st|drK|ds6d | d dpd } | d z } |d r|rM|ddr2|d|r|dd2|r|d|rK|ds1|d|r|d1tj |}|dr| |dzz } |dp|d}|r|dr| d |z } |rUtj }| r=| tj|| ||dtjd |d|d}t!| }| sjd||D}|r |d} n@|d krt%j|| d||} nt%j|| d} d}|drd}|dzt)j| z|d<| |n)tj| |d}t-||||d|||}| dd}|s-d ||d!p|g}nd ||g}tj||||d|d"<t3j| |d#<d$|z|d%<d$|z|d&<|||fS)'Nr)#s # Node IDsdiff -rs diff --gitattachbody r;s"Patch subject is complete summary.s plainrs# diffstats inlinetestzx-patchcfg|].}|ds|d,|/S)s.patchs.diff)endswith).0ts r' zmakepatch..:sP::i((-.JJx,@,@r)s %b-%n.patch)seqnor\s%b.patchinline attachmentz ; filename=Content-Disposition)displayrEs. rDsubjectSubjectX-Mercurial-Nodez%izX-Mercurial-Series-IndexzX-Mercurial-Series-Total) startswithsplitr, ValueErrorr<rGstrippoprdiffstatemimemultipart MIMEMultipartattachr mimeencode mimetextpatchrnodetagsr makefilenamer strfromlocalr`rstrip headencodersysstr)r"r!rQ patchlinesr> _charsetsr[r\r] patchnamedescnodebodylineds addattachmentmsgpbinnode patchtags dispositionprefixsubjs r' makepatchrs D D D ??4  |,, (zz||B'  ??: & & $//-*H*H  E D T xx 488G#4#4 JJtABBx & & ( ( 54   xx Z]55e<<  NN1    Z]55e<<    NN1    A!4!4!6!6  NN1    A!4!4!6!6   # #B xx  W HHY''>488I+>+>M 'DHHW--'  :&&&B*,,  P JJtr4DHHW$?@@yy&$((_Ry$((7:K:KLLC N&od33C&*SjC"#&*UlC"# b=r)c +K|j}|d}|D]}||krV|ds|dr"|t dt }tj||g|tj ||d| dVdS)zlreturn a list of patches for a list of revisions Each patch in the list is itself a list of lines. .Ns3warning: working directory has uncommitted changes T)git)r>rf) r"rQfilesdeletedwarnrrHr exportfilerdifffeatureoptsrPry)r!revsr>r"prevroutputs r' _getpatchesr`s B :>>  D -- 99$t***,,9T 0B0B0D0D9 GGAMNN O O O 1#vE$9"d$M$M$M    oo%%e,,,,,,--r)c |j}tjd}tj|d}|dd}|r||d< g}|r|g}tj|||g|Ri|tj | tj |n#t$rYnwxYwtj |S# tj |n#t$rYnwxYwtj |wxYw)zreturn a bundle containing changesets missing in "dest" The `opts` keyword-arguments are the same as the one accepted by the `bundle` command. The bundle is a returned as a single in-memory binary blob. shg-email-bundle-)rbundlerrtype)r"rmkdtempospathrGr#rbundlerreadfileunlinkOSErrorrmdir)r!destr>r"tmpdirtmpfnbtypedestss r' _getbundlerqs< B  %8 9 9 9F GLL + +E IIlM 2 2E V    FED%8%8884888}U##  Ie        D     Ie        D  sB1C B"" B/.B/D CD C+(D*C++Dc |j}|dr5t|d}n|t d||||jd}|dd}||| |S)zobtain the body of the introduction message and return it This is also used for the body of email with an attached bundle. The body can be obtained either from the command line option or entered by the user through the editor. rs7 Write the introductory message for the patch series. s patchbombbody)repopathactionr0swb) r"r<rreadrNreditrvfsclose)r! defaultbodysenderr>r"rmsgfiles r'_getdescriptionrs B xx DHHV$$%%**,,  K L L   ww $)r"rrrrdatapartrs r'_getbundlemsgsrsn Br""I 88I   & K8##D 4f 5 5 5 5D  & ( (C K 4?2tY8H8HIIJJJ!-1EFFH    DHH\9===J &z22 )))JJx_Ry$((6:J:JKKC N $  r)c |j}tj|}t||||ddt |d}|dpt|d|d}|sd S|d z|z}d} |d r(tj t|g} d | z} nd } t|| |fi|} tj || ||d } tj ||||d | d<| || fS)zmake an introduction email, asking the user for content if needed email is returned as (subject, body, cumulative-diffstat)r^rT)r]rs(optional) Subject: r))r8rNrDr}rfrrv)r"r rr`lastr<rZr7rr}sumrrr) r!rrpatchesr>r"rrrrr}rs r' _makeintrorsX Br""I D$))++txx//CLL4F 88I   & #&####D t D=4 D D xx >#gr"2"233x 4v 6 6 6 6D /"dItxx/?/? @ @C_Ry$((6:J:JKKC N x  r)c tj|}|j}tj|}t t ||fi|}g} |tdt|zt||t|r't||||fi|} | r| | t| t|zdk} d} t|t|ksJtt||D]O\} \}}|r|| } t||||||| dzt|| | } | | P| S)zreturn a list of emails from a list of patches This involves introduction message creation if necessary. This function returns a list of "email" tuples (subject, content, None). s+this patch series consists of %d patches. r;N)r byteskwargsr"r rlistrrNrrZrBrr, enumeratezipr)r!rr patchnamesr> bytesoptsr"rrmsgsrr]rFirrs r' _getpatchmsgsrs$T**I Br""I;tT22T2233G DHHQ? @ @3w<< OPPP2y#g,,//vtW====   KK   4yy3w<<'!+H D t99G $ $ $ $s41122 6Aq  !a=D     E LL      C Kr)c|j}tj|||r|gnd}d|D}|t dd|zd|D}|s|jg}|d|pd|}|s"|t d|S) z4Return the revisions present locally but not in destNc@g|]}tj|jS)r hidepasswordrawloc)rmrs r'roz _getoutgoing..s%@@@Q'&qx00@@@r)scomparing with %s ,cg|] }|dk| S)rrrmrs r'roz _getoutgoing..s & & &!qAvvAvvvr)soutgoing(%s) and ::%ldr)sno changes found ) r"rget_push_pathsstatusrrG changelogtiprevr)r!rrr"paths safe_pathss r' _getoutgoingrs B  "4t-EdVV F FE@@%@@@JIIa&''$))J*?*??@@@ & &t & & &D )%%''( 99. T B BD , !)**+++ Kr)c tjtjd}n##t$rt j}YnwxYwd|||fzS)Ns HGHOSTNAMEz <%s.%d@%s>)rrenvironKeyErrorsocketgetfqdn)r timestamphostnames r'_msgidr$s_$()9-)HII $$$>##$ 4H5 55s$'AAr)res-send patches as inline message text (default)ardssend patches as attachmentsiris"send patches as inline attachmentss/email addresses of blind carbon copy recipientssEMAILcs"email addresses of copy recipientss#ask for confirmation before sendingdrhsadd diffstat output to messagesdates&use the given date as the sending datesDATEr:s,use the given file as the series descriptionsFILEfsemail address of sendernrjs!print messages that would be sentmmboxs3write messages to mbox file instead of sending thems)email addresses replies should be sent tosrus0subject of first message (intro or single patch)sTEXTs in-reply-tosmessage identifier to reply tosMSGIDrEs flags to add in subject prefixessFLAGtsemail addresses of recipientsemailgsgitsuse git extended diff formatrgsomit hg patch headerooutgoings/send changes not found in the target repositorybrs-send changes not in target as a binary bundleBbookmarks-send changes only reachable by given bookmarksBOOKMARKs bundlenames"name of the bundle attachment filesNAMErrevsa revision to sendsREVsforces?run even when remote repository is unrelated (with -b/--bundle)sbasesGa base changeset to specify instead of a destination (with -b/--bundle)s-send an introduction email for a single patchshg email [OPTION]... [DEST]...) helpcategoryc/01tjtj/d}d}d}d}d}d} ds|stj|s)|s'|s%|s#| s!t jtd|r#|r!t jtd tj dd|s|rCt|d kr!t jtd |r |d } nd } g}|r&|r!t jtd|}nD| rB| j vr$t jtd| ztj| }tj|}|rt#| |}|rd|Dd<jdd} | rʉjd t+ji| } n>#t j$r,jtd| zwxYw| dsjdn)fd|D} | d| D}g}t7| D]"\}}||s||#|rt|d kr.td}|| |d t|d z fz}ntd}|| |d fz}d|D}ddd|D}td | |fz}t j||!|rt?j |1nt?j!11fd"}d#pNd$d#p8dd#p"tEd%#}|r\tj$}tK| fi|}|&}|'d&d tQ||fi|}n!tS||fitj$}g0d]/0fd( }|d)d*+}|s!t jtd,|d-d*d./}|d0}|d1} *dd2}!|!tWd3pd2z}!|!r,td4d56,d7|zd860D]}",d9|"zd:6|D]9\}#}$}%,d;|$zd<6|%r,|%d=6:,d>-td?r!t jtd@,d>dApd }&|&Ht]j/|&}&|&0dBsdB|&z}&|&1dCs|&dCz }&tej3t]j/|d }'tj4|/d}d }(d })5tdDtdEt|F}*t7|D]\}+\}#}$}% ||#dG|#dH<|)s|#dH})|)|#dI<n#tl$r|dJ|#dH<YnwxYw|&r |&|#dK<|&|#dL<|&rdG|#vr|#dH}&dMtoj89z|#dN<tej:1d d*O|#dP<1d d z1d f1||#dQ<dR||#dS<|rdR||#dT<|rdR||#dU<| rdR| |#dV<dr;tdW|$dX<d$tj=d'Y}, |,>|#d',d>#t~$rYwxYw|(stj@|Z}(;td[|$dX|*A|+|$\|s|#dU=t}-tj=|-d'Y},|,>|#d'||z|z}.|(|'|.|-C|*Dd S)^aQsend changesets by email By default, diffs are sent in the format generated by :hg:`export`, one per message. The series starts with a "[PATCH 0 of N]" introduction, which describes the series as a whole. Each patch email has a Subject line of "[PATCH M of N] ...", using the first line of the changeset description as the subject text. The message contains two or three parts. First, the changeset description. With the -d/--diffstat option, if the diffstat program is installed, the result of running diffstat on the patch is inserted. Finally, the patch itself, as generated by :hg:`export`. With the -d/--diffstat or --confirm options, you will be presented with a final summary of all messages and asked for confirmation before the messages are sent. By default the patch is included as text in the email body for easy reviewing. Using the -a/--attach option will instead create an attachment for the patch. With -i/--inline an inline attachment will be created. You can include a patch both as text in the email body and as a regular or an inline attachment by combining the -a/--attach or -i/--inline with the --body option. With -B/--bookmark changesets reachable by the given bookmark are selected. With -o/--outgoing, emails will be generated for patches not found in the destination repository (or only those which are ancestors of the specified revisions if any are provided) With -b/--bundle, changesets are selected as for --outgoing, but a single email containing a binary Mercurial bundle as an attachment will be sent. Use the ``patchbomb.bundletype`` config option to control the bundle type as with :hg:`bundle --type`. With -m/--mbox, instead of previewing each patchbomb message in a pager or sending the messages directly, it will create a UNIX mailbox file with the patch emails. This mailbox file can be previewed with any mail user agent which supports UNIX mbox files. With -n/--test, all steps will run, but mail will not be sent. You will be prompted for an email recipient address, a subject and an introductory message describing the patches of your patchbomb. Then when all is done, patchbomb messages are displayed. In case email sending fails, you will find a backup of your series introductory message in ``.hg/last-email.txt``. The default behavior of this command can be customized through configuration. (See :hg:`help patchbomb` for details) Examples:: hg email -r 3000 # send patch 3000 only hg email -r 3000 -r 3001 # send patches 3000 and 3001 hg email -r 3000:3005 # send patches 3000 through 3005 hg email 3000 # send patch 3000 (deprecated) hg email -o # send all patches not in default hg email -o DEST # send all patches not in DEST hg email -o -r 3000 # send all ancestors of 3000 not in default hg email -o -r 3000 DEST # send all ancestors of 3000 not in DEST hg email -B feature # send all ancestors of feature bookmark hg email -b # send bundle of all patches not in default hg email -b DEST # send bundle of all patches not in DEST hg email -b -r 3000 # bundle of all ancestors of 3000 not in default hg email -b -r 3000 DEST # bundle of all ancestors of 3000 not in DEST hg email -o -m mbox && # generate an mbox file... mutt -R -f mbox # ... and view it with mutt hg email -o -m mbox && # generate an mbox file ... formail -s sendmail \ # ... and use formail to send from the mbox -bm -t < mbox # ... using sendmail Before using this command, you will need to enable email in your hgrc. See the [email] section in hgrc(5) for details. rrrrr rrjs0specify at least one changeset with -B, -r or -osE--outgoing mode always on with --bundle; do not re-specify --outgoingr;stoo many destinationsrNs)use only one form to specify the revisionsbookmark '%s' not foundcg|]}d|zS)rYrrs r'rozemail..2s111q111r)srevsrrs0checking that revision exist in the public repo s!unable to access public repo: %s sknowns/skipping existence checks: public repo too old c g|] }| Srr)rmrr!s r'rozemail..Bs)))q47)))r)c3>K|]}|VdSN)rrmhs r' zemail..Cs*$;$;!QVVXX$;$;$;$;$;$;r)s'public "%s" is missing %s and %i othersspublic url %s is missing %sc6g|]}|Sr)rQ)rmr%s r'rozemail..Os <<.Ps7$$%&HqL$$$$$$r)s heads(%ld)suse 'hg push %s %s')hintcZt|ddtdS)Nr)rint)id start_times r'genmsgidzemail..genmsgid\s'b"gs:a=11222r)rrsFromrFc$|}|dd} |}|rW d|d|fzt j | dS d|p d|}|sB d|p d|}|s|rt ||}|rE d||fzt j |g dS|r+t j |g dSgS) N-_s%s: %ss, rjrrr) lowerreplacer<r,rGr addrlistencoder# hasconfigr7) headeraskr configkeyoptaddrsaddr specifiedrr> showaddrsr"s r'getaddrszemail..getaddrsrsLLNN nnT4((..00   P   Y&%**U2C2C)DD E E E&r5)TXXg=N=NOO Oyy9--  )2 2  ; Xy99R\\i>>I ; ;b&':::     Y&$7 8 8 8&rD69dhhw>O>OPP P  &WIy$((7*;*;  r)sToT)r%sno recipient addresses providedsCcr))r%rsBccsReply-Torrhs Final summary: spatchbomb.finalsummary)labels From: %s spatchbomb.froms%s s patchbomb.tos Subject: %s spatchbomb.subjectspatchbomb.diffstatsrfs1are you sure you want to send (yn)?$$ &Yes $$ &Nospatchbomb canceleds in_reply_to<>ssendingsemails)unitr\rwz Message-IdzX-Mercurial-Series-Id patchbombz In-Reply-To ReferenceszMercurial-patchbomb/%sz User-Agent) localtimeDateFromz, ToCcBcczReply-Tos displaying s ... ) mangle_from_)mboxssending )item)FN)Errr rr<validateconfigr Abortrrcheck_at_most_one_argrZ _bookmarksr bookmarkrevsr revrangerr"r#debugr peer RepoErrorr=capableknownrr,rGsetr parsedatemakedater7username strkwargsrcopyr|rr configboolboolrN promptchoicerrrxrleutil parseaddr addressencode makeprogress TypeErrorrversiondecode formatdaterpager GeneratorflattenBrokenPipeErrorconnectupdaterHrPcomplete)2r"r!rr>rdater:outgoingrQbookmarkrr& publicpeerrTrFmissingr[rr missingrevsrevhintrrrstropts bundledata bundleoptsrr,toccbccreplytoconfirmr)mrrparent sender_addrsendmail firstpatchprogressr generatorfpalldestsrr+rs2`` ` @@@r'emailrwks h   % %Dr""I XXi F 88G  D 88G  Dxx $$H ((6  Cxx $$H HHW     B  C 8 v  k A B B    F k 1      !$ <<<6 t99q==+a 899:: :  7DDD 4  O+a LMMNN N 4 4? * *+a :;;hFGG G#D(33  tT * *D.D$-- 211D111W |\::I2  JKKK r955JJ    G  7889D       !!(++ 2 GMMM N N N N))))D)))C$$$;$;s$;$;$;;;EG#C.. & &QSz&NN1%%% 2w<??@@@ %T3 / / /B (6  Ch{##GmmL*55G tDHH[))ATXXj-A-ABBBG 8 *++3LMMM -&(1BCCC < >>I !!!U+++"     7<666 IIa nndI 6 6 6 OOADO ) ) ) eHBr>>>I   a ' ' 'Cx"}H H[(BKKMM : : : : s0#I::;J5/#``.-`.8+f%% f32f3)Nr5r)B__doc__email.encodersencodersremail.mime.basemimebaseremail.mime.multipart multipartr~ email.utilsutilsrPrrmercurial.i18nrmercurial.pycompatrmercurial.noder mercurialrrrr r r r r rrrrrrmercurial.utilsrrrHcmdtablecommand configtable configitem testedwithr(r.r4r7rBrWr`rrrrrrrrr emailopts remoteoptsCATEGORY_IMPORT_EXPORTrwrr)r'rs3AAF'&&&&&#########--------- ######  =  ) H % % !Y !+ . .                             #     888 111 ---- (    B B B.aaaaH---"82<!!!B,,,,^    666 '4KLLM 9dAA<==> 9dAACDDE    <== (  5"aa=>>( L*dAADEEF ;aa BCCD    344 '     9:: '  7C566( D 7D!!@AAB    @AA '     677 (     =>> '     +,, (  '2qq<==qqzzJ 5"aa89911X;;Gw<  ~  vtQQ>??@ haa 7889    A@ A A      A> ? ?      A> ? ? AkNN      A3 4 4 AgJJ   vr11233QQvYY?    A&        A&   AfII     A> ? ?  c7pq8rs9tA'((/{>>>~@@>>~@@@r)