o ]Lbn|@sdZddlmZddlmZddlmmZ ddl mm Z ddl mZddlZddlZddlZddlmZddlmZddlmZddlmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'ddl(m)Z)m*Z*e'j+Z+iZ,e$-e,Z-iZ.e$/e.Z/e/d d dd e/d d dd e/d d dd e/d ddd e/d ddd e/d ddd e/d ddd e/d ddd e/d ddd e/d ddd dZ0ddZ1ddZ2ddZ3ddd Z4d!d"Z5d#d$Z6d%d&Z7 dd'd(Z8d)d*Z9d+d,Z:d-d.Z;d/d0Zd5d6Z?d7d8Z@d9d:ded;fdfd?d@dedAfd9d gedBedCfdDd gedEedCfd9ddedFfdGdHdedIfd9dJd9edKedLfd9dMd9edNedOfdPdd9edQedCfdRdSdedTfdUdVd9edWedOfd9dgedXedCfdYdZd9ed[ed\fd9d]d9ed^ed_fd9d`gedaedbfdcdgeddedCfgZAe-dedfdgdedhfd9didedjfdkdldedmfdndodedpfdqdrd9edsedtfd9dudoedvedwfdxdygedzed{fd9d|ded}fd9d~geded{fd9ddedfg eAejBede-jCdddZDdS)as 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. )absolute_importN)_)open)bin)cmdutilcommandsencodingerror formatterhg logcmdutilmailpatchpycompat registrarscmutil templaterutil)dateutilurlutil patchbomb bundletypedefaultsbccsccconfirmF flagtemplatefromintroauto publicurlsreply-tostosships-with-hg-corecCs,|}|jdd}|rd|||fSdS)zFAdd a header pointing to a public URL where the changeset is availablerrs/Available At %s # hg pull %s -r %sN)repouiconfig)seqctxr publicurlr&1/usr/lib/python3/dist-packages/hgext/patchbomb.py_addpullheadersr(cCstjdttjd<dS)Nspullurl)r extraexportappendr(extraexportmap)r!r&r&r'uisetups r,cCs|sdS|jddS)Nlast-email.txt)local_wlockfreeprefixadd)r!r r&r&r' reposetupsr1:cCs |r|d|7}||||S)Ns [%s])prompt)r!r3rrestr&r&r'r3s r3cCs|dd}|ds|drd}|S|dkrd}|S|dkr$d}|S|dkr.|d k}|S|td ||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 introconfigintror&r&r' introwanteds&     r=c Cs|dd}|s d|St}tt|}t||di|#}| |j ||d| dd|j |dd Wd | S1sHwY| S) z(build flag string optionally by templaterr s patchbombflag)r$sflagss%sflag)nameN)r"joinrstringior literal_templatespecr unquotestringtemplateformatter startitemcontextwrite formatlistgetvalue)r!r revflagstmploutspecfmr&r&r' _formatflagss   rQc CsBt||||}|r d|}|sd|Std|}d||||fS)zbuild prefix to patch subjectr>s [PATCH%s]%ds[PATCH %0*d of %d%s])rQlen) r!r rKrLidxtotalnumberedflagtlenr&r&r' _formatprefixs rYc  Csg} d} d} |D]$} | dr| dr| d} q| ds%| dr'n| | q| s3| s3t|drN|dsNd | d dpId } | d 7} |d r|rj|ddrj|d|rj|dds\|rq|d|r|ds|d|r|dryt |}|dr| |d7} |dp|d}|r|dr| d |7} |rt }| r| t || ||dt d |d|d}t| }| sdd||D}|r|d} n|d krtj|| d||d} nt|| d} d}|dr d}|dt| |d<| |n t j| |dd}t||||d|||}| dd }|sNd!||d"pJ|g}nd!||g}t ||||d|d#<t| |d$<d%||d&<d%||d'<|||fS)(N#s # Node IDsdiff -rs diff --gitattachbody r6s"Patch subject is complete summary.s plainrs# diffstats inlinetestzx-patchcSs$g|]}|ds|dr|qS)s.patchs.diff)endswith).0tr&r&r' <szmakepatch..s %b-%n.patch)seqnorUs%b.patchinline attachmentz ; filename=Content-Disposition)displayr?s. r>subjectSubjectX-Mercurial-Nodez%izX-Mercurial-Series-IndexzX-Mercurial-Series-Total) startswithsplitr* ValueErrorr7rAstrippoprdiffstatemimemultipart MIMEMultipartattachr mimeencode mimetextpatchrnodetagsr makefilenamer strfromlocalrYrstrip headencodersysstr)r!r rK patchlinesr9 _charsetsrTrUrV patchnamedescnodebodylineds addattachmentmsgpbinnode patchtags dispositionprefixsubjr&r&r' makepatchs                   rc ks|j}|d}|D]4}||kr%|ds|dr%|tdt}tj||g|t j ||ddd| dVq dS)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)r9r_) r!rKfilesdeletedwarnrrBr exportfilerdifffeatureoptsrJrq)r revsr9r!prevroutputr&r&r' _getpatchesbs  rcKs|j}tjdd}tj|d}|dd}|r||d<z1g}|r$|g}tj|||g|Ri|t |Wzt |Wn t yGYnwt |Szt |Wn t y^Ynwt |w)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!rmkdtempospathrAr"rbundlerreadfileunlinkOSErrorrmdir)r destr9r!tmpdirtmpfnbtypedestsr&r&r' _getbundless0       rcKsj|j}|drt|d}|S|td|j|||jdd}|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)repopathactionr-swb) r!r7rreadrHreditrvfsclose)r defaultbodysenderr9r!rmsgfiler&r&r'_getdescriptions     rc Ks|j}t|}|dpt|dd}t|d|fi|}t}|r1|t ||||dt dd} | |d|d d } | j d d t| d t| || t||||d|d<||dfgS)zGet the full email for sending a given bundle This function returns a list of "email" tuples (subject, content, None). The list is always one message long in that case. subjectsSubject:sA bundle for your repositoryrZtest applicationzx-mercurial-bundles%s.hg bundlenamerrkrj)filenamernN)r!r rr7r3rrvrwrxry emimebaseMIMEBase set_payload add_headerrr} emailencoders encode_base64r) r rrr9r!rrrrdatapartrr&r&r'_getbundlemsgss*       rc Ks|j}t|}t||||ddt|dd}|dp&t|d|dd}|s+d S|d |}d} |d rEt t |g} d | } nd } t || |fi|} t || ||d } t ||||d | d<| || fS)zmake an introduction email, asking the user for content if needed email is returned as (subject, body, cumulative-diffstat)rWrT)rVrs(optional) Subject: rZ)r4rNr>rur_rrn)r!r rrYlastr7rSr3rrusumrryr) r rrpatchesr9r!rrrrrurr&r&r' _makeintros(      rc Kst|}|j}t|}tt||fi|}g} |tdt |t ||t |r?t ||||fi|} | r?| | t | t |dk} d} t |t |ksUJt t||D]"\} \}}|rh|| } t||||||| dt || | } | | q\| 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. r6N)r byteskwargsr!r rlistrrHrrSr=rr* enumeratezipr)r rr patchnamesr9 bytesoptsr!rrmsgsrrVr@irrr&r&r' _getpatchmsgss<    rcCs|j}t|||r |gnd}dd|D}|tdd|dd|D}|s1|jg}|d|p7d|}|sC|td |S) z4Return the revisions present locally but not in destNcSsg|]}t|jqSr&)r hidepasswordrawloc)rerr&r&r'rgz _getoutgoing..scomparing with %s ,cSsg|]}|dkr|qS)rr&rerr&r&r'rgrsoutgoing(%s) and ::%ldrZsno changes found ) r!rget_push_pathsstatusrrA changelogtiprevr)r rrr!paths safe_pathsr&r&r' _getoutgoings rcCs>z ttjd}Wn tyt}Ynwd|||fS)Ns HGHOSTNAMEz <%s.%d@%s>)rr}environKeyErrorsocketgetfqdn)r timestamphostnamer&r&r'_msgid&s   rrZr^s-send patches as inline message text (default)ar]ssend patches as attachmentsirbs"send patches as inline attachmentss/email addresses of blind carbon copy recipientssEMAILcs"email addresses of copy recipientss#ask for confirmation before sendingdrasadd diffstat output to messagesdates&use the given date as the sending datesDATEr5s,use the given file as the series descriptionsFILEfsemail address of sendernrcs!print messages that would be sentmmboxs3write messages to mbox file instead of sending thems)email addresses replies should be sent tosrms0subject of first message (intro or single patch)sTEXTs in-reply-tosmessage identifier to reply tosMSGIDr?s flags to add in subject prefixessFLAGtsemail addresses of recipientsemailgsgitsuse git extended diff formatr`somit 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]...) helpcategoryc0 sttd}d}d}d}d}d} ds4|s4t|sE|sE|sE|sE| sEttd|rP|rPttd t dd|s[|rst |d krhttd |ro|d } nd } g}|r|r~ttd|}n| r| j vrttd| t | }t|}|rt| |}|rdd|Dd<jdd} | r^jdz ti| } Wntjyjtd| w| dsjdnufdd|D} | dd| D}g}t| D]\}}||s||q|r^t |d kr.td}|| |d t |d f;}n td}|| |d f;}dd|D}dd dd!|D}td"| |f}tj||d#|rgt |nt!fd$d%}d&pd'd&pdd&pt"d(#}|rt$}t%| fi|}|&}|'d)d t(||fi|}n t)||fit$}gdafd+d, }|d-d.d/}|sttd0|d1d.d2d3}|d4}|d5} *dd6}!|!t+d7pd6O}!|!rTj,td8d9d:j,d;|dd:q|D]\}#}$}%j,d?|$d@d:|%r>j,|%dAd:q&,dB-tdCrTttdD,dBdEp`d }&|&d urt./|&}&|&0dFsudF|&}&|&1dGs|&dG7}&t23t./|d }'t4|d}d }(d })j5tdHtdIt |dJ}*t|D]\}+\}#}$}%z||#dK|#dL<|)s|#dL})|)|#dM<Wnt6y|dN|#dL<Ynw|&r|&|#dO<|&|#dP<|&rdK|#vr|#dL}&dQt789|#dR<t2j:d d.dS|#dT<d d d f||#dU<dV||#dW<|r#dV||#dX<|r-dV||#dY<| r7dV| |#dZ<dr};td[|$d\|#d*,dBWqt?y|}-z|-j@t@jAkrqWYd }-~-qd }-~-ww|(stjB|d^}(;td_|$d\|*jC|+|$d`|s|#dY=tD}.tj=|.d*d]},|,>|#d*|||}/|(|'|/|.Eq|*Fd S)baQsend 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. rrrrrrrcs0specify at least one changeset with -B, -r or -osE--outgoing mode always on with --bundle; do not re-specify --outgoingr6stoo many destinationsrNs)use only one form to specify the revisionsbookmark '%s' not foundcSsg|]}d|qS)rRr&rr&r&r'rg4zemail..srevsrrs0checking that revision exist in the public repo s!unable to access public repo: %s sknowns/skipping existence checks: public repo too old csg|]}|qSr&r&r)r r&r'rgDrcss|]}|VqdSN)rrehr&r&r' Eszemail..s'public "%s" is missing %s and %i othersspublic url %s is missing %scSsg|]}|qSr&)rK)rer$r&r&r'rgQrr>css|]}d|VqdS)s-r %sNr&rr&r&r'rRs s heads(%ld)suse 'hg push %s %s')hintcst|ddtdS)Nr)rint)id) start_timer&r'genmsgid^szemail..genmsgidrrsFromrFcs|}|dd}|}|r*d|d|ft|dSd|p5d|}|sOd|pCd|}|sO|rOt ||d}|rfd||ft|gdS|rtt|gdSgS) N-_s%s: %ss, rcrrr) lowerreplacer7r*rAr addrlistencoder" hasconfigr3)headeraskr configkeyoptaddrsaddr specified)rr9 showaddrsr!r&r'getaddrsts. zemail..getaddrssToT)r sno recipient addresses providedsCcrZ)r rsBccsReply-Torras Final summary: spatchbomb.finalsummary)labels From: %s spatchbomb.froms%s s patchbomb.tos Subject: %s spatchbomb.subjectspatchbomb.diffstatsr_s1are you sure you want to send (yn)?$$ &Yes $$ &Nospatchbomb canceleds in_reply_to<>ssendingsemails)unitrUroz Message-IdzX-Mercurial-Series-Id patchbombz In-Reply-To ReferenceszMercurial-patchbomb/%sz User-Agent) localtimeDateFromz, ToCcBcczReply-Tos displaying s ... ) mangle_from_)mboxssending )item)FN)Grrr rr7validateconfigr Abortrrcheck_at_most_one_argrS _bookmarksr bookmarkrevsr revrangerr!r"debugr peer RepoErrorr8capableknownrr*rAsetr parsedatemakedater3username strkwargsrcopyrtrr configboolboolrH promptchoicerr}rprdeutil parseaddr addressencode makeprogress TypeErrorrversiondecode formatdaterpager GeneratorflattenIOErrorerrnoEPIPEconnectupdaterBrJcomplete)0r!r rr9rdater!outgoingrKbookmarkrr% publicpeerrNr-missingrTrr missingrevsrevhintrrrstropts bundledata bundleoptsrrtoccbccreplytoconfirmrmrrparent sender_addrsendmail firstpatchprogressr generatorinstfpalldestsr&)rr9r rrr!r'emailmsl                                            ra)Nr2r)E__doc__ __future__remail.encodersencodersremail.mime.basemimebaseremail.mime.multipart multipartrv email.utilsutilsr7rCrrmercurial.i18nrmercurial.pycompatrmercurial.noder mercurialrrrr r r r r rrrrrrmercurial.utilsrrrBcmdtablecommand configtable configitem testedwithr(r,r1r3r=rQrYrrrrrrrrr emailopts remoteoptsCATEGORY_IMPORT_EXPORTrar&r&r&r's B     @     d !/ ?  89:?