##// END OF EJS Templates
mail: unsupport smtp.verifycert (BC)...
Gregory Szorc -
r29285:63a37491 default
parent child Browse files
Show More
@@ -1,730 +1,724 b''
1 1 # patchbomb.py - sending Mercurial changesets as patch emails
2 2 #
3 3 # Copyright 2005-2009 Matt Mackall <mpm@selenic.com> and others
4 4 #
5 5 # This software may be used and distributed according to the terms of the
6 6 # GNU General Public License version 2 or any later version.
7 7
8 8 '''command to send changesets as (a series of) patch emails
9 9
10 10 The series is started off with a "[PATCH 0 of N]" introduction, which
11 11 describes the series as a whole.
12 12
13 13 Each patch email has a Subject line of "[PATCH M of N] ...", using the
14 14 first line of the changeset description as the subject text. The
15 15 message contains two or three body parts:
16 16
17 17 - The changeset description.
18 18 - [Optional] The result of running diffstat on the patch.
19 19 - The patch itself, as generated by :hg:`export`.
20 20
21 21 Each message refers to the first in the series using the In-Reply-To
22 22 and References headers, so they will show up as a sequence in threaded
23 23 mail and news readers, and in mail archives.
24 24
25 25 To configure other defaults, add a section like this to your
26 26 configuration file::
27 27
28 28 [email]
29 29 from = My Name <my@email>
30 30 to = recipient1, recipient2, ...
31 31 cc = cc1, cc2, ...
32 32 bcc = bcc1, bcc2, ...
33 33 reply-to = address1, address2, ...
34 34
35 35 Use ``[patchbomb]`` as configuration section name if you need to
36 36 override global ``[email]`` address settings.
37 37
38 38 Then you can use the :hg:`email` command to mail a series of
39 39 changesets as a patchbomb.
40 40
41 41 You can also either configure the method option in the email section
42 42 to be a sendmail compatible mailer or fill out the [smtp] section so
43 43 that the patchbomb extension can automatically send patchbombs
44 44 directly from the commandline. See the [email] and [smtp] sections in
45 45 hgrc(5) for details.
46 46
47 47 By default, :hg:`email` will prompt for a ``To`` or ``CC`` header if
48 48 you do not supply one via configuration or the command line. You can
49 49 override this to never prompt by configuring an empty value::
50 50
51 51 [email]
52 52 cc =
53 53
54 54 You can control the default inclusion of an introduction message with the
55 55 ``patchbomb.intro`` configuration option. The configuration is always
56 56 overwritten by command line flags like --intro and --desc::
57 57
58 58 [patchbomb]
59 59 intro=auto # include introduction message if more than 1 patch (default)
60 60 intro=never # never include an introduction message
61 61 intro=always # always include an introduction message
62 62
63 63 You can set patchbomb to always ask for confirmation by setting
64 64 ``patchbomb.confirm`` to true.
65 65 '''
66 66 from __future__ import absolute_import
67 67
68 68 import email as emailmod
69 69 import errno
70 70 import os
71 71 import socket
72 72 import tempfile
73 73
74 74 from mercurial.i18n import _
75 75 from mercurial import (
76 76 cmdutil,
77 77 commands,
78 78 error,
79 79 hg,
80 80 mail,
81 81 node as nodemod,
82 82 patch,
83 83 scmutil,
84 84 util,
85 85 )
86 86 stringio = util.stringio
87 87
88 88 cmdtable = {}
89 89 command = cmdutil.command(cmdtable)
90 90 # Note for extension authors: ONLY specify testedwith = 'internal' for
91 91 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
92 92 # be specifying the version(s) of Mercurial they are tested with, or
93 93 # leave the attribute unspecified.
94 94 testedwith = 'internal'
95 95
96 96 def _addpullheader(seq, ctx):
97 97 """Add a header pointing to a public URL where the changeset is available
98 98 """
99 99 repo = ctx.repo()
100 100 # experimental config: patchbomb.publicurl
101 101 # waiting for some logic that check that the changeset are available on the
102 102 # destination before patchbombing anything.
103 103 pullurl = repo.ui.config('patchbomb', 'publicurl')
104 104 if pullurl is not None:
105 105 return ('Available At %s\n'
106 106 '# hg pull %s -r %s' % (pullurl, pullurl, ctx))
107 107 return None
108 108
109 109 def uisetup(ui):
110 110 cmdutil.extraexport.append('pullurl')
111 111 cmdutil.extraexportmap['pullurl'] = _addpullheader
112 112
113 113
114 114 def prompt(ui, prompt, default=None, rest=':'):
115 115 if default:
116 116 prompt += ' [%s]' % default
117 117 return ui.prompt(prompt + rest, default)
118 118
119 119 def introwanted(ui, opts, number):
120 120 '''is an introductory message apparently wanted?'''
121 121 introconfig = ui.config('patchbomb', 'intro', 'auto')
122 122 if opts.get('intro') or opts.get('desc'):
123 123 intro = True
124 124 elif introconfig == 'always':
125 125 intro = True
126 126 elif introconfig == 'never':
127 127 intro = False
128 128 elif introconfig == 'auto':
129 129 intro = 1 < number
130 130 else:
131 131 ui.write_err(_('warning: invalid patchbomb.intro value "%s"\n')
132 132 % introconfig)
133 133 ui.write_err(_('(should be one of always, never, auto)\n'))
134 134 intro = 1 < number
135 135 return intro
136 136
137 137 def makepatch(ui, repo, patchlines, opts, _charsets, idx, total, numbered,
138 138 patchname=None):
139 139
140 140 desc = []
141 141 node = None
142 142 body = ''
143 143
144 144 for line in patchlines:
145 145 if line.startswith('#'):
146 146 if line.startswith('# Node ID'):
147 147 node = line.split()[-1]
148 148 continue
149 149 if line.startswith('diff -r') or line.startswith('diff --git'):
150 150 break
151 151 desc.append(line)
152 152
153 153 if not patchname and not node:
154 154 raise ValueError
155 155
156 156 if opts.get('attach') and not opts.get('body'):
157 157 body = ('\n'.join(desc[1:]).strip() or
158 158 'Patch subject is complete summary.')
159 159 body += '\n\n\n'
160 160
161 161 if opts.get('plain'):
162 162 while patchlines and patchlines[0].startswith('# '):
163 163 patchlines.pop(0)
164 164 if patchlines:
165 165 patchlines.pop(0)
166 166 while patchlines and not patchlines[0].strip():
167 167 patchlines.pop(0)
168 168
169 169 ds = patch.diffstat(patchlines, git=opts.get('git'))
170 170 if opts.get('diffstat'):
171 171 body += ds + '\n\n'
172 172
173 173 addattachment = opts.get('attach') or opts.get('inline')
174 174 if not addattachment or opts.get('body'):
175 175 body += '\n'.join(patchlines)
176 176
177 177 if addattachment:
178 178 msg = emailmod.MIMEMultipart.MIMEMultipart()
179 179 if body:
180 180 msg.attach(mail.mimeencode(ui, body, _charsets, opts.get('test')))
181 181 p = mail.mimetextpatch('\n'.join(patchlines), 'x-patch',
182 182 opts.get('test'))
183 183 binnode = nodemod.bin(node)
184 184 # if node is mq patch, it will have the patch file's name as a tag
185 185 if not patchname:
186 186 patchtags = [t for t in repo.nodetags(binnode)
187 187 if t.endswith('.patch') or t.endswith('.diff')]
188 188 if patchtags:
189 189 patchname = patchtags[0]
190 190 elif total > 1:
191 191 patchname = cmdutil.makefilename(repo, '%b-%n.patch',
192 192 binnode, seqno=idx,
193 193 total=total)
194 194 else:
195 195 patchname = cmdutil.makefilename(repo, '%b.patch', binnode)
196 196 disposition = 'inline'
197 197 if opts.get('attach'):
198 198 disposition = 'attachment'
199 199 p['Content-Disposition'] = disposition + '; filename=' + patchname
200 200 msg.attach(p)
201 201 else:
202 202 msg = mail.mimetextpatch(body, display=opts.get('test'))
203 203
204 204 flag = ' '.join(opts.get('flag'))
205 205 if flag:
206 206 flag = ' ' + flag
207 207
208 208 subj = desc[0].strip().rstrip('. ')
209 209 if not numbered:
210 210 subj = '[PATCH%s] %s' % (flag, opts.get('subject') or subj)
211 211 else:
212 212 tlen = len(str(total))
213 213 subj = '[PATCH %0*d of %d%s] %s' % (tlen, idx, total, flag, subj)
214 214 msg['Subject'] = mail.headencode(ui, subj, _charsets, opts.get('test'))
215 215 msg['X-Mercurial-Node'] = node
216 216 msg['X-Mercurial-Series-Index'] = '%i' % idx
217 217 msg['X-Mercurial-Series-Total'] = '%i' % total
218 218 return msg, subj, ds
219 219
220 220 def _getpatches(repo, revs, **opts):
221 221 """return a list of patches for a list of revisions
222 222
223 223 Each patch in the list is itself a list of lines.
224 224 """
225 225 ui = repo.ui
226 226 prev = repo['.'].rev()
227 227 for r in revs:
228 228 if r == prev and (repo[None].files() or repo[None].deleted()):
229 229 ui.warn(_('warning: working directory has '
230 230 'uncommitted changes\n'))
231 231 output = stringio()
232 232 cmdutil.export(repo, [r], fp=output,
233 233 opts=patch.difffeatureopts(ui, opts, git=True))
234 234 yield output.getvalue().split('\n')
235 235 def _getbundle(repo, dest, **opts):
236 236 """return a bundle containing changesets missing in "dest"
237 237
238 238 The `opts` keyword-arguments are the same as the one accepted by the
239 239 `bundle` command.
240 240
241 241 The bundle is a returned as a single in-memory binary blob.
242 242 """
243 243 ui = repo.ui
244 244 tmpdir = tempfile.mkdtemp(prefix='hg-email-bundle-')
245 245 tmpfn = os.path.join(tmpdir, 'bundle')
246 246 btype = ui.config('patchbomb', 'bundletype')
247 247 if btype:
248 248 opts['type'] = btype
249 249 try:
250 250 commands.bundle(ui, repo, tmpfn, dest, **opts)
251 251 return util.readfile(tmpfn)
252 252 finally:
253 253 try:
254 254 os.unlink(tmpfn)
255 255 except OSError:
256 256 pass
257 257 os.rmdir(tmpdir)
258 258
259 259 def _getdescription(repo, defaultbody, sender, **opts):
260 260 """obtain the body of the introduction message and return it
261 261
262 262 This is also used for the body of email with an attached bundle.
263 263
264 264 The body can be obtained either from the command line option or entered by
265 265 the user through the editor.
266 266 """
267 267 ui = repo.ui
268 268 if opts.get('desc'):
269 269 body = open(opts.get('desc')).read()
270 270 else:
271 271 ui.write(_('\nWrite the introductory message for the '
272 272 'patch series.\n\n'))
273 273 body = ui.edit(defaultbody, sender)
274 274 # Save series description in case sendmail fails
275 275 msgfile = repo.vfs('last-email.txt', 'wb')
276 276 msgfile.write(body)
277 277 msgfile.close()
278 278 return body
279 279
280 280 def _getbundlemsgs(repo, sender, bundle, **opts):
281 281 """Get the full email for sending a given bundle
282 282
283 283 This function returns a list of "email" tuples (subject, content, None).
284 284 The list is always one message long in that case.
285 285 """
286 286 ui = repo.ui
287 287 _charsets = mail._charsets(ui)
288 288 subj = (opts.get('subject')
289 289 or prompt(ui, 'Subject:', 'A bundle for your repository'))
290 290
291 291 body = _getdescription(repo, '', sender, **opts)
292 292 msg = emailmod.MIMEMultipart.MIMEMultipart()
293 293 if body:
294 294 msg.attach(mail.mimeencode(ui, body, _charsets, opts.get('test')))
295 295 datapart = emailmod.MIMEBase.MIMEBase('application', 'x-mercurial-bundle')
296 296 datapart.set_payload(bundle)
297 297 bundlename = '%s.hg' % opts.get('bundlename', 'bundle')
298 298 datapart.add_header('Content-Disposition', 'attachment',
299 299 filename=bundlename)
300 300 emailmod.Encoders.encode_base64(datapart)
301 301 msg.attach(datapart)
302 302 msg['Subject'] = mail.headencode(ui, subj, _charsets, opts.get('test'))
303 303 return [(msg, subj, None)]
304 304
305 305 def _makeintro(repo, sender, patches, **opts):
306 306 """make an introduction email, asking the user for content if needed
307 307
308 308 email is returned as (subject, body, cumulative-diffstat)"""
309 309 ui = repo.ui
310 310 _charsets = mail._charsets(ui)
311 311 tlen = len(str(len(patches)))
312 312
313 313 flag = opts.get('flag') or ''
314 314 if flag:
315 315 flag = ' ' + ' '.join(flag)
316 316 prefix = '[PATCH %0*d of %d%s]' % (tlen, 0, len(patches), flag)
317 317
318 318 subj = (opts.get('subject') or
319 319 prompt(ui, '(optional) Subject: ', rest=prefix, default=''))
320 320 if not subj:
321 321 return None # skip intro if the user doesn't bother
322 322
323 323 subj = prefix + ' ' + subj
324 324
325 325 body = ''
326 326 if opts.get('diffstat'):
327 327 # generate a cumulative diffstat of the whole patch series
328 328 diffstat = patch.diffstat(sum(patches, []))
329 329 body = '\n' + diffstat
330 330 else:
331 331 diffstat = None
332 332
333 333 body = _getdescription(repo, body, sender, **opts)
334 334 msg = mail.mimeencode(ui, body, _charsets, opts.get('test'))
335 335 msg['Subject'] = mail.headencode(ui, subj, _charsets,
336 336 opts.get('test'))
337 337 return (msg, subj, diffstat)
338 338
339 339 def _getpatchmsgs(repo, sender, patches, patchnames=None, **opts):
340 340 """return a list of emails from a list of patches
341 341
342 342 This involves introduction message creation if necessary.
343 343
344 344 This function returns a list of "email" tuples (subject, content, None).
345 345 """
346 346 ui = repo.ui
347 347 _charsets = mail._charsets(ui)
348 348 msgs = []
349 349
350 350 ui.write(_('this patch series consists of %d patches.\n\n')
351 351 % len(patches))
352 352
353 353 # build the intro message, or skip it if the user declines
354 354 if introwanted(ui, opts, len(patches)):
355 355 msg = _makeintro(repo, sender, patches, **opts)
356 356 if msg:
357 357 msgs.append(msg)
358 358
359 359 # are we going to send more than one message?
360 360 numbered = len(msgs) + len(patches) > 1
361 361
362 362 # now generate the actual patch messages
363 363 name = None
364 364 for i, p in enumerate(patches):
365 365 if patchnames:
366 366 name = patchnames[i]
367 367 msg = makepatch(ui, repo, p, opts, _charsets, i + 1,
368 368 len(patches), numbered, name)
369 369 msgs.append(msg)
370 370
371 371 return msgs
372 372
373 373 def _getoutgoing(repo, dest, revs):
374 374 '''Return the revisions present locally but not in dest'''
375 375 ui = repo.ui
376 376 url = ui.expandpath(dest or 'default-push', dest or 'default')
377 377 url = hg.parseurl(url)[0]
378 378 ui.status(_('comparing with %s\n') % util.hidepassword(url))
379 379
380 380 revs = [r for r in revs if r >= 0]
381 381 if not revs:
382 382 revs = [len(repo) - 1]
383 383 revs = repo.revs('outgoing(%s) and ::%ld', dest or '', revs)
384 384 if not revs:
385 385 ui.status(_("no changes found\n"))
386 386 return revs
387 387
388 388 emailopts = [
389 389 ('', 'body', None, _('send patches as inline message text (default)')),
390 390 ('a', 'attach', None, _('send patches as attachments')),
391 391 ('i', 'inline', None, _('send patches as inline attachments')),
392 392 ('', 'bcc', [], _('email addresses of blind carbon copy recipients')),
393 393 ('c', 'cc', [], _('email addresses of copy recipients')),
394 394 ('', 'confirm', None, _('ask for confirmation before sending')),
395 395 ('d', 'diffstat', None, _('add diffstat output to messages')),
396 396 ('', 'date', '', _('use the given date as the sending date')),
397 397 ('', 'desc', '', _('use the given file as the series description')),
398 398 ('f', 'from', '', _('email address of sender')),
399 399 ('n', 'test', None, _('print messages that would be sent')),
400 400 ('m', 'mbox', '', _('write messages to mbox file instead of sending them')),
401 401 ('', 'reply-to', [], _('email addresses replies should be sent to')),
402 402 ('s', 'subject', '', _('subject of first message (intro or single patch)')),
403 403 ('', 'in-reply-to', '', _('message identifier to reply to')),
404 404 ('', 'flag', [], _('flags to add in subject prefixes')),
405 405 ('t', 'to', [], _('email addresses of recipients'))]
406 406
407 407 @command('email',
408 408 [('g', 'git', None, _('use git extended diff format')),
409 409 ('', 'plain', None, _('omit hg patch header')),
410 410 ('o', 'outgoing', None,
411 411 _('send changes not found in the target repository')),
412 412 ('b', 'bundle', None, _('send changes not in target as a binary bundle')),
413 413 ('', 'bundlename', 'bundle',
414 414 _('name of the bundle attachment file'), _('NAME')),
415 415 ('r', 'rev', [], _('a revision to send'), _('REV')),
416 416 ('', 'force', None, _('run even when remote repository is unrelated '
417 417 '(with -b/--bundle)')),
418 418 ('', 'base', [], _('a base changeset to specify instead of a destination '
419 419 '(with -b/--bundle)'), _('REV')),
420 420 ('', 'intro', None, _('send an introduction email for a single patch')),
421 421 ] + emailopts + commands.remoteopts,
422 422 _('hg email [OPTION]... [DEST]...'))
423 423 def email(ui, repo, *revs, **opts):
424 424 '''send changesets by email
425 425
426 426 By default, diffs are sent in the format generated by
427 427 :hg:`export`, one per message. The series starts with a "[PATCH 0
428 428 of N]" introduction, which describes the series as a whole.
429 429
430 430 Each patch email has a Subject line of "[PATCH M of N] ...", using
431 431 the first line of the changeset description as the subject text.
432 432 The message contains two or three parts. First, the changeset
433 433 description.
434 434
435 435 With the -d/--diffstat option, if the diffstat program is
436 436 installed, the result of running diffstat on the patch is inserted.
437 437
438 438 Finally, the patch itself, as generated by :hg:`export`.
439 439
440 440 With the -d/--diffstat or --confirm options, you will be presented
441 441 with a final summary of all messages and asked for confirmation before
442 442 the messages are sent.
443 443
444 444 By default the patch is included as text in the email body for
445 445 easy reviewing. Using the -a/--attach option will instead create
446 446 an attachment for the patch. With -i/--inline an inline attachment
447 447 will be created. You can include a patch both as text in the email
448 448 body and as a regular or an inline attachment by combining the
449 449 -a/--attach or -i/--inline with the --body option.
450 450
451 451 With -o/--outgoing, emails will be generated for patches not found
452 452 in the destination repository (or only those which are ancestors
453 453 of the specified revisions if any are provided)
454 454
455 455 With -b/--bundle, changesets are selected as for --outgoing, but a
456 456 single email containing a binary Mercurial bundle as an attachment
457 457 will be sent. Use the ``patchbomb.bundletype`` config option to
458 458 control the bundle type as with :hg:`bundle --type`.
459 459
460 460 With -m/--mbox, instead of previewing each patchbomb message in a
461 461 pager or sending the messages directly, it will create a UNIX
462 462 mailbox file with the patch emails. This mailbox file can be
463 463 previewed with any mail user agent which supports UNIX mbox
464 464 files.
465 465
466 466 With -n/--test, all steps will run, but mail will not be sent.
467 467 You will be prompted for an email recipient address, a subject and
468 468 an introductory message describing the patches of your patchbomb.
469 469 Then when all is done, patchbomb messages are displayed. If the
470 470 PAGER environment variable is set, your pager will be fired up once
471 471 for each patchbomb message, so you can verify everything is alright.
472 472
473 473 In case email sending fails, you will find a backup of your series
474 474 introductory message in ``.hg/last-email.txt``.
475 475
476 476 The default behavior of this command can be customized through
477 477 configuration. (See :hg:`help patchbomb` for details)
478 478
479 479 Examples::
480 480
481 481 hg email -r 3000 # send patch 3000 only
482 482 hg email -r 3000 -r 3001 # send patches 3000 and 3001
483 483 hg email -r 3000:3005 # send patches 3000 through 3005
484 484 hg email 3000 # send patch 3000 (deprecated)
485 485
486 486 hg email -o # send all patches not in default
487 487 hg email -o DEST # send all patches not in DEST
488 488 hg email -o -r 3000 # send all ancestors of 3000 not in default
489 489 hg email -o -r 3000 DEST # send all ancestors of 3000 not in DEST
490 490
491 491 hg email -b # send bundle of all patches not in default
492 492 hg email -b DEST # send bundle of all patches not in DEST
493 493 hg email -b -r 3000 # bundle of all ancestors of 3000 not in default
494 494 hg email -b -r 3000 DEST # bundle of all ancestors of 3000 not in DEST
495 495
496 496 hg email -o -m mbox && # generate an mbox file...
497 497 mutt -R -f mbox # ... and view it with mutt
498 498 hg email -o -m mbox && # generate an mbox file ...
499 499 formail -s sendmail \\ # ... and use formail to send from the mbox
500 500 -bm -t < mbox # ... using sendmail
501 501
502 502 Before using this command, you will need to enable email in your
503 503 hgrc. See the [email] section in hgrc(5) for details.
504 504 '''
505 505
506 506 _charsets = mail._charsets(ui)
507 507
508 508 bundle = opts.get('bundle')
509 509 date = opts.get('date')
510 510 mbox = opts.get('mbox')
511 511 outgoing = opts.get('outgoing')
512 512 rev = opts.get('rev')
513 513 # internal option used by pbranches
514 514 patches = opts.get('patches')
515 515
516 516 if not (opts.get('test') or mbox):
517 517 # really sending
518 518 mail.validateconfig(ui)
519 519
520 520 if not (revs or rev or outgoing or bundle or patches):
521 521 raise error.Abort(_('specify at least one changeset with -r or -o'))
522 522
523 523 if outgoing and bundle:
524 524 raise error.Abort(_("--outgoing mode always on with --bundle;"
525 525 " do not re-specify --outgoing"))
526 526
527 527 if outgoing or bundle:
528 528 if len(revs) > 1:
529 529 raise error.Abort(_("too many destinations"))
530 530 if revs:
531 531 dest = revs[0]
532 532 else:
533 533 dest = None
534 534 revs = []
535 535
536 536 if rev:
537 537 if revs:
538 538 raise error.Abort(_('use only one form to specify the revision'))
539 539 revs = rev
540 540
541 541 revs = scmutil.revrange(repo, revs)
542 542 if outgoing:
543 543 revs = _getoutgoing(repo, dest, revs)
544 544 if bundle:
545 545 opts['revs'] = [str(r) for r in revs]
546 546
547 547 # check if revision exist on the public destination
548 548 publicurl = repo.ui.config('patchbomb', 'publicurl')
549 549 if publicurl is not None:
550 550 repo.ui.debug('checking that revision exist in the public repo')
551 551 try:
552 552 publicpeer = hg.peer(repo, {}, publicurl)
553 553 except error.RepoError:
554 554 repo.ui.write_err(_('unable to access public repo: %s\n')
555 555 % publicurl)
556 556 raise
557 557 if not publicpeer.capable('known'):
558 558 repo.ui.debug('skipping existence checks: public repo too old')
559 559 else:
560 560 out = [repo[r] for r in revs]
561 561 known = publicpeer.known(h.node() for h in out)
562 562 missing = []
563 563 for idx, h in enumerate(out):
564 564 if not known[idx]:
565 565 missing.append(h)
566 566 if missing:
567 567 if 1 < len(missing):
568 568 msg = _('public "%s" is missing %s and %i others')
569 569 msg %= (publicurl, missing[0], len(missing) - 1)
570 570 else:
571 571 msg = _('public url %s is missing %s')
572 572 msg %= (publicurl, missing[0])
573 573 revhint = ' '.join('-r %s' % h
574 574 for h in repo.set('heads(%ld)', missing))
575 575 hint = _("use 'hg push %s %s'") % (publicurl, revhint)
576 576 raise error.Abort(msg, hint=hint)
577 577
578 578 # start
579 579 if date:
580 580 start_time = util.parsedate(date)
581 581 else:
582 582 start_time = util.makedate()
583 583
584 584 def genmsgid(id):
585 585 return '<%s.%s@%s>' % (id[:20], int(start_time[0]), socket.getfqdn())
586 586
587 587 # deprecated config: patchbomb.from
588 588 sender = (opts.get('from') or ui.config('email', 'from') or
589 589 ui.config('patchbomb', 'from') or
590 590 prompt(ui, 'From', ui.username()))
591 591
592 592 if patches:
593 593 msgs = _getpatchmsgs(repo, sender, patches, opts.get('patchnames'),
594 594 **opts)
595 595 elif bundle:
596 596 bundledata = _getbundle(repo, dest, **opts)
597 597 bundleopts = opts.copy()
598 598 bundleopts.pop('bundle', None) # already processed
599 599 msgs = _getbundlemsgs(repo, sender, bundledata, **bundleopts)
600 600 else:
601 601 _patches = list(_getpatches(repo, revs, **opts))
602 602 msgs = _getpatchmsgs(repo, sender, _patches, **opts)
603 603
604 604 showaddrs = []
605 605
606 606 def getaddrs(header, ask=False, default=None):
607 607 configkey = header.lower()
608 608 opt = header.replace('-', '_').lower()
609 609 addrs = opts.get(opt)
610 610 if addrs:
611 611 showaddrs.append('%s: %s' % (header, ', '.join(addrs)))
612 612 return mail.addrlistencode(ui, addrs, _charsets, opts.get('test'))
613 613
614 614 # not on the command line: fallback to config and then maybe ask
615 615 addr = (ui.config('email', configkey) or
616 616 ui.config('patchbomb', configkey))
617 617 if not addr:
618 618 specified = (ui.hasconfig('email', configkey) or
619 619 ui.hasconfig('patchbomb', configkey))
620 620 if not specified and ask:
621 621 addr = prompt(ui, header, default=default)
622 622 if addr:
623 623 showaddrs.append('%s: %s' % (header, addr))
624 624 return mail.addrlistencode(ui, [addr], _charsets, opts.get('test'))
625 625 else:
626 626 return default
627 627
628 628 to = getaddrs('To', ask=True)
629 629 if not to:
630 630 # we can get here in non-interactive mode
631 631 raise error.Abort(_('no recipient addresses provided'))
632 632 cc = getaddrs('Cc', ask=True, default='') or []
633 633 bcc = getaddrs('Bcc') or []
634 634 replyto = getaddrs('Reply-To')
635 635
636 636 confirm = ui.configbool('patchbomb', 'confirm')
637 637 confirm |= bool(opts.get('diffstat') or opts.get('confirm'))
638 638
639 639 if confirm:
640 640 ui.write(_('\nFinal summary:\n\n'), label='patchbomb.finalsummary')
641 641 ui.write(('From: %s\n' % sender), label='patchbomb.from')
642 642 for addr in showaddrs:
643 643 ui.write('%s\n' % addr, label='patchbomb.to')
644 644 for m, subj, ds in msgs:
645 645 ui.write(('Subject: %s\n' % subj), label='patchbomb.subject')
646 646 if ds:
647 647 ui.write(ds, label='patchbomb.diffstats')
648 648 ui.write('\n')
649 649 if ui.promptchoice(_('are you sure you want to send (yn)?'
650 650 '$$ &Yes $$ &No')):
651 651 raise error.Abort(_('patchbomb canceled'))
652 652
653 653 ui.write('\n')
654 654
655 655 parent = opts.get('in_reply_to') or None
656 656 # angle brackets may be omitted, they're not semantically part of the msg-id
657 657 if parent is not None:
658 658 if not parent.startswith('<'):
659 659 parent = '<' + parent
660 660 if not parent.endswith('>'):
661 661 parent += '>'
662 662
663 663 sender_addr = emailmod.Utils.parseaddr(sender)[1]
664 664 sender = mail.addressencode(ui, sender, _charsets, opts.get('test'))
665 665 sendmail = None
666 666 firstpatch = None
667 667 for i, (m, subj, ds) in enumerate(msgs):
668 668 try:
669 669 m['Message-Id'] = genmsgid(m['X-Mercurial-Node'])
670 670 if not firstpatch:
671 671 firstpatch = m['Message-Id']
672 672 m['X-Mercurial-Series-Id'] = firstpatch
673 673 except TypeError:
674 674 m['Message-Id'] = genmsgid('patchbomb')
675 675 if parent:
676 676 m['In-Reply-To'] = parent
677 677 m['References'] = parent
678 678 if not parent or 'X-Mercurial-Node' not in m:
679 679 parent = m['Message-Id']
680 680
681 681 m['User-Agent'] = 'Mercurial-patchbomb/%s' % util.version()
682 682 m['Date'] = emailmod.Utils.formatdate(start_time[0], localtime=True)
683 683
684 684 start_time = (start_time[0] + 1, start_time[1])
685 685 m['From'] = sender
686 686 m['To'] = ', '.join(to)
687 687 if cc:
688 688 m['Cc'] = ', '.join(cc)
689 689 if bcc:
690 690 m['Bcc'] = ', '.join(bcc)
691 691 if replyto:
692 692 m['Reply-To'] = ', '.join(replyto)
693 693 if opts.get('test'):
694 694 ui.status(_('displaying '), subj, ' ...\n')
695 695 ui.flush()
696 696 if 'PAGER' in os.environ and not ui.plain():
697 697 fp = util.popen(os.environ['PAGER'], 'w')
698 698 else:
699 699 fp = ui
700 700 generator = emailmod.Generator.Generator(fp, mangle_from_=False)
701 701 try:
702 702 generator.flatten(m, 0)
703 703 fp.write('\n')
704 704 except IOError as inst:
705 705 if inst.errno != errno.EPIPE:
706 706 raise
707 707 if fp is not ui:
708 708 fp.close()
709 709 else:
710 710 if not sendmail:
711 verifycert = ui.config('smtp', 'verifycert', 'strict')
712 if opts.get('insecure'):
713 ui.setconfig('smtp', 'verifycert', 'loose', 'patchbomb')
714 try:
715 sendmail = mail.connect(ui, mbox=mbox)
716 finally:
717 ui.setconfig('smtp', 'verifycert', verifycert, 'patchbomb')
711 sendmail = mail.connect(ui, mbox=mbox)
718 712 ui.status(_('sending '), subj, ' ...\n')
719 713 ui.progress(_('sending'), i, item=subj, total=len(msgs),
720 714 unit=_('emails'))
721 715 if not mbox:
722 716 # Exim does not remove the Bcc field
723 717 del m['Bcc']
724 718 fp = stringio()
725 719 generator = emailmod.Generator.Generator(fp, mangle_from_=False)
726 720 generator.flatten(m, 0)
727 721 sendmail(sender_addr, to + bcc + cc, fp.getvalue())
728 722
729 723 ui.progress(_('writing'), None)
730 724 ui.progress(_('sending'), None)
@@ -1,2127 +1,2117 b''
1 1 The Mercurial system uses a set of configuration files to control
2 2 aspects of its behavior.
3 3
4 4 Troubleshooting
5 5 ===============
6 6
7 7 If you're having problems with your configuration,
8 8 :hg:`config --debug` can help you understand what is introducing
9 9 a setting into your environment.
10 10
11 11 See :hg:`help config.syntax` and :hg:`help config.files`
12 12 for information about how and where to override things.
13 13
14 14 Structure
15 15 =========
16 16
17 17 The configuration files use a simple ini-file format. A configuration
18 18 file consists of sections, led by a ``[section]`` header and followed
19 19 by ``name = value`` entries::
20 20
21 21 [ui]
22 22 username = Firstname Lastname <firstname.lastname@example.net>
23 23 verbose = True
24 24
25 25 The above entries will be referred to as ``ui.username`` and
26 26 ``ui.verbose``, respectively. See :hg:`help config.syntax`.
27 27
28 28 Files
29 29 =====
30 30
31 31 Mercurial reads configuration data from several files, if they exist.
32 32 These files do not exist by default and you will have to create the
33 33 appropriate configuration files yourself:
34 34
35 35 Local configuration is put into the per-repository ``<repo>/.hg/hgrc`` file.
36 36
37 37 Global configuration like the username setting is typically put into:
38 38
39 39 .. container:: windows
40 40
41 41 - ``%USERPROFILE%\mercurial.ini`` (on Windows)
42 42
43 43 .. container:: unix.plan9
44 44
45 45 - ``$HOME/.hgrc`` (on Unix, Plan9)
46 46
47 47 The names of these files depend on the system on which Mercurial is
48 48 installed. ``*.rc`` files from a single directory are read in
49 49 alphabetical order, later ones overriding earlier ones. Where multiple
50 50 paths are given below, settings from earlier paths override later
51 51 ones.
52 52
53 53 .. container:: verbose.unix
54 54
55 55 On Unix, the following files are consulted:
56 56
57 57 - ``<repo>/.hg/hgrc`` (per-repository)
58 58 - ``$HOME/.hgrc`` (per-user)
59 59 - ``<install-root>/etc/mercurial/hgrc`` (per-installation)
60 60 - ``<install-root>/etc/mercurial/hgrc.d/*.rc`` (per-installation)
61 61 - ``/etc/mercurial/hgrc`` (per-system)
62 62 - ``/etc/mercurial/hgrc.d/*.rc`` (per-system)
63 63 - ``<internal>/default.d/*.rc`` (defaults)
64 64
65 65 .. container:: verbose.windows
66 66
67 67 On Windows, the following files are consulted:
68 68
69 69 - ``<repo>/.hg/hgrc`` (per-repository)
70 70 - ``%USERPROFILE%\.hgrc`` (per-user)
71 71 - ``%USERPROFILE%\Mercurial.ini`` (per-user)
72 72 - ``%HOME%\.hgrc`` (per-user)
73 73 - ``%HOME%\Mercurial.ini`` (per-user)
74 74 - ``HKEY_LOCAL_MACHINE\SOFTWARE\Mercurial`` (per-installation)
75 75 - ``<install-dir>\hgrc.d\*.rc`` (per-installation)
76 76 - ``<install-dir>\Mercurial.ini`` (per-installation)
77 77 - ``<internal>/default.d/*.rc`` (defaults)
78 78
79 79 .. note::
80 80
81 81 The registry key ``HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Mercurial``
82 82 is used when running 32-bit Python on 64-bit Windows.
83 83
84 84 .. container:: windows
85 85
86 86 On Windows 9x, ``%HOME%`` is replaced by ``%APPDATA%``.
87 87
88 88 .. container:: verbose.plan9
89 89
90 90 On Plan9, the following files are consulted:
91 91
92 92 - ``<repo>/.hg/hgrc`` (per-repository)
93 93 - ``$home/lib/hgrc`` (per-user)
94 94 - ``<install-root>/lib/mercurial/hgrc`` (per-installation)
95 95 - ``<install-root>/lib/mercurial/hgrc.d/*.rc`` (per-installation)
96 96 - ``/lib/mercurial/hgrc`` (per-system)
97 97 - ``/lib/mercurial/hgrc.d/*.rc`` (per-system)
98 98 - ``<internal>/default.d/*.rc`` (defaults)
99 99
100 100 Per-repository configuration options only apply in a
101 101 particular repository. This file is not version-controlled, and
102 102 will not get transferred during a "clone" operation. Options in
103 103 this file override options in all other configuration files.
104 104
105 105 .. container:: unix.plan9
106 106
107 107 On Plan 9 and Unix, most of this file will be ignored if it doesn't
108 108 belong to a trusted user or to a trusted group. See
109 109 :hg:`help config.trusted` for more details.
110 110
111 111 Per-user configuration file(s) are for the user running Mercurial. Options
112 112 in these files apply to all Mercurial commands executed by this user in any
113 113 directory. Options in these files override per-system and per-installation
114 114 options.
115 115
116 116 Per-installation configuration files are searched for in the
117 117 directory where Mercurial is installed. ``<install-root>`` is the
118 118 parent directory of the **hg** executable (or symlink) being run.
119 119
120 120 .. container:: unix.plan9
121 121
122 122 For example, if installed in ``/shared/tools/bin/hg``, Mercurial
123 123 will look in ``/shared/tools/etc/mercurial/hgrc``. Options in these
124 124 files apply to all Mercurial commands executed by any user in any
125 125 directory.
126 126
127 127 Per-installation configuration files are for the system on
128 128 which Mercurial is running. Options in these files apply to all
129 129 Mercurial commands executed by any user in any directory. Registry
130 130 keys contain PATH-like strings, every part of which must reference
131 131 a ``Mercurial.ini`` file or be a directory where ``*.rc`` files will
132 132 be read. Mercurial checks each of these locations in the specified
133 133 order until one or more configuration files are detected.
134 134
135 135 Per-system configuration files are for the system on which Mercurial
136 136 is running. Options in these files apply to all Mercurial commands
137 137 executed by any user in any directory. Options in these files
138 138 override per-installation options.
139 139
140 140 Mercurial comes with some default configuration. The default configuration
141 141 files are installed with Mercurial and will be overwritten on upgrades. Default
142 142 configuration files should never be edited by users or administrators but can
143 143 be overridden in other configuration files. So far the directory only contains
144 144 merge tool configuration but packagers can also put other default configuration
145 145 there.
146 146
147 147 Syntax
148 148 ======
149 149
150 150 A configuration file consists of sections, led by a ``[section]`` header
151 151 and followed by ``name = value`` entries (sometimes called
152 152 ``configuration keys``)::
153 153
154 154 [spam]
155 155 eggs=ham
156 156 green=
157 157 eggs
158 158
159 159 Each line contains one entry. If the lines that follow are indented,
160 160 they are treated as continuations of that entry. Leading whitespace is
161 161 removed from values. Empty lines are skipped. Lines beginning with
162 162 ``#`` or ``;`` are ignored and may be used to provide comments.
163 163
164 164 Configuration keys can be set multiple times, in which case Mercurial
165 165 will use the value that was configured last. As an example::
166 166
167 167 [spam]
168 168 eggs=large
169 169 ham=serrano
170 170 eggs=small
171 171
172 172 This would set the configuration key named ``eggs`` to ``small``.
173 173
174 174 It is also possible to define a section multiple times. A section can
175 175 be redefined on the same and/or on different configuration files. For
176 176 example::
177 177
178 178 [foo]
179 179 eggs=large
180 180 ham=serrano
181 181 eggs=small
182 182
183 183 [bar]
184 184 eggs=ham
185 185 green=
186 186 eggs
187 187
188 188 [foo]
189 189 ham=prosciutto
190 190 eggs=medium
191 191 bread=toasted
192 192
193 193 This would set the ``eggs``, ``ham``, and ``bread`` configuration keys
194 194 of the ``foo`` section to ``medium``, ``prosciutto``, and ``toasted``,
195 195 respectively. As you can see there only thing that matters is the last
196 196 value that was set for each of the configuration keys.
197 197
198 198 If a configuration key is set multiple times in different
199 199 configuration files the final value will depend on the order in which
200 200 the different configuration files are read, with settings from earlier
201 201 paths overriding later ones as described on the ``Files`` section
202 202 above.
203 203
204 204 A line of the form ``%include file`` will include ``file`` into the
205 205 current configuration file. The inclusion is recursive, which means
206 206 that included files can include other files. Filenames are relative to
207 207 the configuration file in which the ``%include`` directive is found.
208 208 Environment variables and ``~user`` constructs are expanded in
209 209 ``file``. This lets you do something like::
210 210
211 211 %include ~/.hgrc.d/$HOST.rc
212 212
213 213 to include a different configuration file on each computer you use.
214 214
215 215 A line with ``%unset name`` will remove ``name`` from the current
216 216 section, if it has been set previously.
217 217
218 218 The values are either free-form text strings, lists of text strings,
219 219 or Boolean values. Boolean values can be set to true using any of "1",
220 220 "yes", "true", or "on" and to false using "0", "no", "false", or "off"
221 221 (all case insensitive).
222 222
223 223 List values are separated by whitespace or comma, except when values are
224 224 placed in double quotation marks::
225 225
226 226 allow_read = "John Doe, PhD", brian, betty
227 227
228 228 Quotation marks can be escaped by prefixing them with a backslash. Only
229 229 quotation marks at the beginning of a word is counted as a quotation
230 230 (e.g., ``foo"bar baz`` is the list of ``foo"bar`` and ``baz``).
231 231
232 232 Sections
233 233 ========
234 234
235 235 This section describes the different sections that may appear in a
236 236 Mercurial configuration file, the purpose of each section, its possible
237 237 keys, and their possible values.
238 238
239 239 ``alias``
240 240 ---------
241 241
242 242 Defines command aliases.
243 243
244 244 Aliases allow you to define your own commands in terms of other
245 245 commands (or aliases), optionally including arguments. Positional
246 246 arguments in the form of ``$1``, ``$2``, etc. in the alias definition
247 247 are expanded by Mercurial before execution. Positional arguments not
248 248 already used by ``$N`` in the definition are put at the end of the
249 249 command to be executed.
250 250
251 251 Alias definitions consist of lines of the form::
252 252
253 253 <alias> = <command> [<argument>]...
254 254
255 255 For example, this definition::
256 256
257 257 latest = log --limit 5
258 258
259 259 creates a new command ``latest`` that shows only the five most recent
260 260 changesets. You can define subsequent aliases using earlier ones::
261 261
262 262 stable5 = latest -b stable
263 263
264 264 .. note::
265 265
266 266 It is possible to create aliases with the same names as
267 267 existing commands, which will then override the original
268 268 definitions. This is almost always a bad idea!
269 269
270 270 An alias can start with an exclamation point (``!``) to make it a
271 271 shell alias. A shell alias is executed with the shell and will let you
272 272 run arbitrary commands. As an example, ::
273 273
274 274 echo = !echo $@
275 275
276 276 will let you do ``hg echo foo`` to have ``foo`` printed in your
277 277 terminal. A better example might be::
278 278
279 279 purge = !$HG status --no-status --unknown -0 re: | xargs -0 rm
280 280
281 281 which will make ``hg purge`` delete all unknown files in the
282 282 repository in the same manner as the purge extension.
283 283
284 284 Positional arguments like ``$1``, ``$2``, etc. in the alias definition
285 285 expand to the command arguments. Unmatched arguments are
286 286 removed. ``$0`` expands to the alias name and ``$@`` expands to all
287 287 arguments separated by a space. ``"$@"`` (with quotes) expands to all
288 288 arguments quoted individually and separated by a space. These expansions
289 289 happen before the command is passed to the shell.
290 290
291 291 Shell aliases are executed in an environment where ``$HG`` expands to
292 292 the path of the Mercurial that was used to execute the alias. This is
293 293 useful when you want to call further Mercurial commands in a shell
294 294 alias, as was done above for the purge alias. In addition,
295 295 ``$HG_ARGS`` expands to the arguments given to Mercurial. In the ``hg
296 296 echo foo`` call above, ``$HG_ARGS`` would expand to ``echo foo``.
297 297
298 298 .. note::
299 299
300 300 Some global configuration options such as ``-R`` are
301 301 processed before shell aliases and will thus not be passed to
302 302 aliases.
303 303
304 304
305 305 ``annotate``
306 306 ------------
307 307
308 308 Settings used when displaying file annotations. All values are
309 309 Booleans and default to False. See :hg:`help config.diff` for
310 310 related options for the diff command.
311 311
312 312 ``ignorews``
313 313 Ignore white space when comparing lines.
314 314
315 315 ``ignorewsamount``
316 316 Ignore changes in the amount of white space.
317 317
318 318 ``ignoreblanklines``
319 319 Ignore changes whose lines are all blank.
320 320
321 321
322 322 ``auth``
323 323 --------
324 324
325 325 Authentication credentials for HTTP authentication. This section
326 326 allows you to store usernames and passwords for use when logging
327 327 *into* HTTP servers. See :hg:`help config.web` if
328 328 you want to configure *who* can login to your HTTP server.
329 329
330 330 Each line has the following format::
331 331
332 332 <name>.<argument> = <value>
333 333
334 334 where ``<name>`` is used to group arguments into authentication
335 335 entries. Example::
336 336
337 337 foo.prefix = hg.intevation.de/mercurial
338 338 foo.username = foo
339 339 foo.password = bar
340 340 foo.schemes = http https
341 341
342 342 bar.prefix = secure.example.org
343 343 bar.key = path/to/file.key
344 344 bar.cert = path/to/file.cert
345 345 bar.schemes = https
346 346
347 347 Supported arguments:
348 348
349 349 ``prefix``
350 350 Either ``*`` or a URI prefix with or without the scheme part.
351 351 The authentication entry with the longest matching prefix is used
352 352 (where ``*`` matches everything and counts as a match of length
353 353 1). If the prefix doesn't include a scheme, the match is performed
354 354 against the URI with its scheme stripped as well, and the schemes
355 355 argument, q.v., is then subsequently consulted.
356 356
357 357 ``username``
358 358 Optional. Username to authenticate with. If not given, and the
359 359 remote site requires basic or digest authentication, the user will
360 360 be prompted for it. Environment variables are expanded in the
361 361 username letting you do ``foo.username = $USER``. If the URI
362 362 includes a username, only ``[auth]`` entries with a matching
363 363 username or without a username will be considered.
364 364
365 365 ``password``
366 366 Optional. Password to authenticate with. If not given, and the
367 367 remote site requires basic or digest authentication, the user
368 368 will be prompted for it.
369 369
370 370 ``key``
371 371 Optional. PEM encoded client certificate key file. Environment
372 372 variables are expanded in the filename.
373 373
374 374 ``cert``
375 375 Optional. PEM encoded client certificate chain file. Environment
376 376 variables are expanded in the filename.
377 377
378 378 ``schemes``
379 379 Optional. Space separated list of URI schemes to use this
380 380 authentication entry with. Only used if the prefix doesn't include
381 381 a scheme. Supported schemes are http and https. They will match
382 382 static-http and static-https respectively, as well.
383 383 (default: https)
384 384
385 385 If no suitable authentication entry is found, the user is prompted
386 386 for credentials as usual if required by the remote.
387 387
388 388
389 389 ``committemplate``
390 390 ------------------
391 391
392 392 ``changeset``
393 393 String: configuration in this section is used as the template to
394 394 customize the text shown in the editor when committing.
395 395
396 396 In addition to pre-defined template keywords, commit log specific one
397 397 below can be used for customization:
398 398
399 399 ``extramsg``
400 400 String: Extra message (typically 'Leave message empty to abort
401 401 commit.'). This may be changed by some commands or extensions.
402 402
403 403 For example, the template configuration below shows as same text as
404 404 one shown by default::
405 405
406 406 [committemplate]
407 407 changeset = {desc}\n\n
408 408 HG: Enter commit message. Lines beginning with 'HG:' are removed.
409 409 HG: {extramsg}
410 410 HG: --
411 411 HG: user: {author}\n{ifeq(p2rev, "-1", "",
412 412 "HG: branch merge\n")
413 413 }HG: branch '{branch}'\n{if(activebookmark,
414 414 "HG: bookmark '{activebookmark}'\n") }{subrepos %
415 415 "HG: subrepo {subrepo}\n" }{file_adds %
416 416 "HG: added {file}\n" }{file_mods %
417 417 "HG: changed {file}\n" }{file_dels %
418 418 "HG: removed {file}\n" }{if(files, "",
419 419 "HG: no files changed\n")}
420 420
421 421 .. note::
422 422
423 423 For some problematic encodings (see :hg:`help win32mbcs` for
424 424 detail), this customization should be configured carefully, to
425 425 avoid showing broken characters.
426 426
427 427 For example, if a multibyte character ending with backslash (0x5c) is
428 428 followed by the ASCII character 'n' in the customized template,
429 429 the sequence of backslash and 'n' is treated as line-feed unexpectedly
430 430 (and the multibyte character is broken, too).
431 431
432 432 Customized template is used for commands below (``--edit`` may be
433 433 required):
434 434
435 435 - :hg:`backout`
436 436 - :hg:`commit`
437 437 - :hg:`fetch` (for merge commit only)
438 438 - :hg:`graft`
439 439 - :hg:`histedit`
440 440 - :hg:`import`
441 441 - :hg:`qfold`, :hg:`qnew` and :hg:`qrefresh`
442 442 - :hg:`rebase`
443 443 - :hg:`shelve`
444 444 - :hg:`sign`
445 445 - :hg:`tag`
446 446 - :hg:`transplant`
447 447
448 448 Configuring items below instead of ``changeset`` allows showing
449 449 customized message only for specific actions, or showing different
450 450 messages for each action.
451 451
452 452 - ``changeset.backout`` for :hg:`backout`
453 453 - ``changeset.commit.amend.merge`` for :hg:`commit --amend` on merges
454 454 - ``changeset.commit.amend.normal`` for :hg:`commit --amend` on other
455 455 - ``changeset.commit.normal.merge`` for :hg:`commit` on merges
456 456 - ``changeset.commit.normal.normal`` for :hg:`commit` on other
457 457 - ``changeset.fetch`` for :hg:`fetch` (impling merge commit)
458 458 - ``changeset.gpg.sign`` for :hg:`sign`
459 459 - ``changeset.graft`` for :hg:`graft`
460 460 - ``changeset.histedit.edit`` for ``edit`` of :hg:`histedit`
461 461 - ``changeset.histedit.fold`` for ``fold`` of :hg:`histedit`
462 462 - ``changeset.histedit.mess`` for ``mess`` of :hg:`histedit`
463 463 - ``changeset.histedit.pick`` for ``pick`` of :hg:`histedit`
464 464 - ``changeset.import.bypass`` for :hg:`import --bypass`
465 465 - ``changeset.import.normal.merge`` for :hg:`import` on merges
466 466 - ``changeset.import.normal.normal`` for :hg:`import` on other
467 467 - ``changeset.mq.qnew`` for :hg:`qnew`
468 468 - ``changeset.mq.qfold`` for :hg:`qfold`
469 469 - ``changeset.mq.qrefresh`` for :hg:`qrefresh`
470 470 - ``changeset.rebase.collapse`` for :hg:`rebase --collapse`
471 471 - ``changeset.rebase.merge`` for :hg:`rebase` on merges
472 472 - ``changeset.rebase.normal`` for :hg:`rebase` on other
473 473 - ``changeset.shelve.shelve`` for :hg:`shelve`
474 474 - ``changeset.tag.add`` for :hg:`tag` without ``--remove``
475 475 - ``changeset.tag.remove`` for :hg:`tag --remove`
476 476 - ``changeset.transplant.merge`` for :hg:`transplant` on merges
477 477 - ``changeset.transplant.normal`` for :hg:`transplant` on other
478 478
479 479 These dot-separated lists of names are treated as hierarchical ones.
480 480 For example, ``changeset.tag.remove`` customizes the commit message
481 481 only for :hg:`tag --remove`, but ``changeset.tag`` customizes the
482 482 commit message for :hg:`tag` regardless of ``--remove`` option.
483 483
484 484 When the external editor is invoked for a commit, the corresponding
485 485 dot-separated list of names without the ``changeset.`` prefix
486 486 (e.g. ``commit.normal.normal``) is in the ``HGEDITFORM`` environment
487 487 variable.
488 488
489 489 In this section, items other than ``changeset`` can be referred from
490 490 others. For example, the configuration to list committed files up
491 491 below can be referred as ``{listupfiles}``::
492 492
493 493 [committemplate]
494 494 listupfiles = {file_adds %
495 495 "HG: added {file}\n" }{file_mods %
496 496 "HG: changed {file}\n" }{file_dels %
497 497 "HG: removed {file}\n" }{if(files, "",
498 498 "HG: no files changed\n")}
499 499
500 500 ``decode/encode``
501 501 -----------------
502 502
503 503 Filters for transforming files on checkout/checkin. This would
504 504 typically be used for newline processing or other
505 505 localization/canonicalization of files.
506 506
507 507 Filters consist of a filter pattern followed by a filter command.
508 508 Filter patterns are globs by default, rooted at the repository root.
509 509 For example, to match any file ending in ``.txt`` in the root
510 510 directory only, use the pattern ``*.txt``. To match any file ending
511 511 in ``.c`` anywhere in the repository, use the pattern ``**.c``.
512 512 For each file only the first matching filter applies.
513 513
514 514 The filter command can start with a specifier, either ``pipe:`` or
515 515 ``tempfile:``. If no specifier is given, ``pipe:`` is used by default.
516 516
517 517 A ``pipe:`` command must accept data on stdin and return the transformed
518 518 data on stdout.
519 519
520 520 Pipe example::
521 521
522 522 [encode]
523 523 # uncompress gzip files on checkin to improve delta compression
524 524 # note: not necessarily a good idea, just an example
525 525 *.gz = pipe: gunzip
526 526
527 527 [decode]
528 528 # recompress gzip files when writing them to the working dir (we
529 529 # can safely omit "pipe:", because it's the default)
530 530 *.gz = gzip
531 531
532 532 A ``tempfile:`` command is a template. The string ``INFILE`` is replaced
533 533 with the name of a temporary file that contains the data to be
534 534 filtered by the command. The string ``OUTFILE`` is replaced with the name
535 535 of an empty temporary file, where the filtered data must be written by
536 536 the command.
537 537
538 538 .. container:: windows
539 539
540 540 .. note::
541 541
542 542 The tempfile mechanism is recommended for Windows systems,
543 543 where the standard shell I/O redirection operators often have
544 544 strange effects and may corrupt the contents of your files.
545 545
546 546 This filter mechanism is used internally by the ``eol`` extension to
547 547 translate line ending characters between Windows (CRLF) and Unix (LF)
548 548 format. We suggest you use the ``eol`` extension for convenience.
549 549
550 550
551 551 ``defaults``
552 552 ------------
553 553
554 554 (defaults are deprecated. Don't use them. Use aliases instead.)
555 555
556 556 Use the ``[defaults]`` section to define command defaults, i.e. the
557 557 default options/arguments to pass to the specified commands.
558 558
559 559 The following example makes :hg:`log` run in verbose mode, and
560 560 :hg:`status` show only the modified files, by default::
561 561
562 562 [defaults]
563 563 log = -v
564 564 status = -m
565 565
566 566 The actual commands, instead of their aliases, must be used when
567 567 defining command defaults. The command defaults will also be applied
568 568 to the aliases of the commands defined.
569 569
570 570
571 571 ``diff``
572 572 --------
573 573
574 574 Settings used when displaying diffs. Everything except for ``unified``
575 575 is a Boolean and defaults to False. See :hg:`help config.annotate`
576 576 for related options for the annotate command.
577 577
578 578 ``git``
579 579 Use git extended diff format.
580 580
581 581 ``nobinary``
582 582 Omit git binary patches.
583 583
584 584 ``nodates``
585 585 Don't include dates in diff headers.
586 586
587 587 ``noprefix``
588 588 Omit 'a/' and 'b/' prefixes from filenames. Ignored in plain mode.
589 589
590 590 ``showfunc``
591 591 Show which function each change is in.
592 592
593 593 ``ignorews``
594 594 Ignore white space when comparing lines.
595 595
596 596 ``ignorewsamount``
597 597 Ignore changes in the amount of white space.
598 598
599 599 ``ignoreblanklines``
600 600 Ignore changes whose lines are all blank.
601 601
602 602 ``unified``
603 603 Number of lines of context to show.
604 604
605 605 ``email``
606 606 ---------
607 607
608 608 Settings for extensions that send email messages.
609 609
610 610 ``from``
611 611 Optional. Email address to use in "From" header and SMTP envelope
612 612 of outgoing messages.
613 613
614 614 ``to``
615 615 Optional. Comma-separated list of recipients' email addresses.
616 616
617 617 ``cc``
618 618 Optional. Comma-separated list of carbon copy recipients'
619 619 email addresses.
620 620
621 621 ``bcc``
622 622 Optional. Comma-separated list of blind carbon copy recipients'
623 623 email addresses.
624 624
625 625 ``method``
626 626 Optional. Method to use to send email messages. If value is ``smtp``
627 627 (default), use SMTP (see the ``[smtp]`` section for configuration).
628 628 Otherwise, use as name of program to run that acts like sendmail
629 629 (takes ``-f`` option for sender, list of recipients on command line,
630 630 message on stdin). Normally, setting this to ``sendmail`` or
631 631 ``/usr/sbin/sendmail`` is enough to use sendmail to send messages.
632 632
633 633 ``charsets``
634 634 Optional. Comma-separated list of character sets considered
635 635 convenient for recipients. Addresses, headers, and parts not
636 636 containing patches of outgoing messages will be encoded in the
637 637 first character set to which conversion from local encoding
638 638 (``$HGENCODING``, ``ui.fallbackencoding``) succeeds. If correct
639 639 conversion fails, the text in question is sent as is.
640 640 (default: '')
641 641
642 642 Order of outgoing email character sets:
643 643
644 644 1. ``us-ascii``: always first, regardless of settings
645 645 2. ``email.charsets``: in order given by user
646 646 3. ``ui.fallbackencoding``: if not in email.charsets
647 647 4. ``$HGENCODING``: if not in email.charsets
648 648 5. ``utf-8``: always last, regardless of settings
649 649
650 650 Email example::
651 651
652 652 [email]
653 653 from = Joseph User <joe.user@example.com>
654 654 method = /usr/sbin/sendmail
655 655 # charsets for western Europeans
656 656 # us-ascii, utf-8 omitted, as they are tried first and last
657 657 charsets = iso-8859-1, iso-8859-15, windows-1252
658 658
659 659
660 660 ``extensions``
661 661 --------------
662 662
663 663 Mercurial has an extension mechanism for adding new features. To
664 664 enable an extension, create an entry for it in this section.
665 665
666 666 If you know that the extension is already in Python's search path,
667 667 you can give the name of the module, followed by ``=``, with nothing
668 668 after the ``=``.
669 669
670 670 Otherwise, give a name that you choose, followed by ``=``, followed by
671 671 the path to the ``.py`` file (including the file name extension) that
672 672 defines the extension.
673 673
674 674 To explicitly disable an extension that is enabled in an hgrc of
675 675 broader scope, prepend its path with ``!``, as in ``foo = !/ext/path``
676 676 or ``foo = !`` when path is not supplied.
677 677
678 678 Example for ``~/.hgrc``::
679 679
680 680 [extensions]
681 681 # (the color extension will get loaded from Mercurial's path)
682 682 color =
683 683 # (this extension will get loaded from the file specified)
684 684 myfeature = ~/.hgext/myfeature.py
685 685
686 686
687 687 ``format``
688 688 ----------
689 689
690 690 ``usegeneraldelta``
691 691 Enable or disable the "generaldelta" repository format which improves
692 692 repository compression by allowing "revlog" to store delta against arbitrary
693 693 revision instead of the previous stored one. This provides significant
694 694 improvement for repositories with branches.
695 695
696 696 Repositories with this on-disk format require Mercurial version 1.9.
697 697
698 698 Enabled by default.
699 699
700 700 ``dotencode``
701 701 Enable or disable the "dotencode" repository format which enhances
702 702 the "fncache" repository format (which has to be enabled to use
703 703 dotencode) to avoid issues with filenames starting with ._ on
704 704 Mac OS X and spaces on Windows.
705 705
706 706 Repositories with this on-disk format require Mercurial version 1.7.
707 707
708 708 Enabled by default.
709 709
710 710 ``usefncache``
711 711 Enable or disable the "fncache" repository format which enhances
712 712 the "store" repository format (which has to be enabled to use
713 713 fncache) to allow longer filenames and avoids using Windows
714 714 reserved names, e.g. "nul".
715 715
716 716 Repositories with this on-disk format require Mercurial version 1.1.
717 717
718 718 Enabled by default.
719 719
720 720 ``usestore``
721 721 Enable or disable the "store" repository format which improves
722 722 compatibility with systems that fold case or otherwise mangle
723 723 filenames. Disabling this option will allow you to store longer filenames
724 724 in some situations at the expense of compatibility.
725 725
726 726 Repositories with this on-disk format require Mercurial version 0.9.4.
727 727
728 728 Enabled by default.
729 729
730 730 ``graph``
731 731 ---------
732 732
733 733 Web graph view configuration. This section let you change graph
734 734 elements display properties by branches, for instance to make the
735 735 ``default`` branch stand out.
736 736
737 737 Each line has the following format::
738 738
739 739 <branch>.<argument> = <value>
740 740
741 741 where ``<branch>`` is the name of the branch being
742 742 customized. Example::
743 743
744 744 [graph]
745 745 # 2px width
746 746 default.width = 2
747 747 # red color
748 748 default.color = FF0000
749 749
750 750 Supported arguments:
751 751
752 752 ``width``
753 753 Set branch edges width in pixels.
754 754
755 755 ``color``
756 756 Set branch edges color in hexadecimal RGB notation.
757 757
758 758 ``hooks``
759 759 ---------
760 760
761 761 Commands or Python functions that get automatically executed by
762 762 various actions such as starting or finishing a commit. Multiple
763 763 hooks can be run for the same action by appending a suffix to the
764 764 action. Overriding a site-wide hook can be done by changing its
765 765 value or setting it to an empty string. Hooks can be prioritized
766 766 by adding a prefix of ``priority.`` to the hook name on a new line
767 767 and setting the priority. The default priority is 0.
768 768
769 769 Example ``.hg/hgrc``::
770 770
771 771 [hooks]
772 772 # update working directory after adding changesets
773 773 changegroup.update = hg update
774 774 # do not use the site-wide hook
775 775 incoming =
776 776 incoming.email = /my/email/hook
777 777 incoming.autobuild = /my/build/hook
778 778 # force autobuild hook to run before other incoming hooks
779 779 priority.incoming.autobuild = 1
780 780
781 781 Most hooks are run with environment variables set that give useful
782 782 additional information. For each hook below, the environment
783 783 variables it is passed are listed with names of the form ``$HG_foo``.
784 784
785 785 ``changegroup``
786 786 Run after a changegroup has been added via push, pull or unbundle. ID of the
787 787 first new changeset is in ``$HG_NODE`` and last in ``$HG_NODE_LAST``. URL
788 788 from which changes came is in ``$HG_URL``.
789 789
790 790 ``commit``
791 791 Run after a changeset has been created in the local repository. ID
792 792 of the newly created changeset is in ``$HG_NODE``. Parent changeset
793 793 IDs are in ``$HG_PARENT1`` and ``$HG_PARENT2``.
794 794
795 795 ``incoming``
796 796 Run after a changeset has been pulled, pushed, or unbundled into
797 797 the local repository. The ID of the newly arrived changeset is in
798 798 ``$HG_NODE``. URL that was source of changes came is in ``$HG_URL``.
799 799
800 800 ``outgoing``
801 801 Run after sending changes from local repository to another. ID of
802 802 first changeset sent is in ``$HG_NODE``. Source of operation is in
803 803 ``$HG_SOURCE``; Also see :hg:`help config.hooks.preoutgoing` hook.
804 804
805 805 ``post-<command>``
806 806 Run after successful invocations of the associated command. The
807 807 contents of the command line are passed as ``$HG_ARGS`` and the result
808 808 code in ``$HG_RESULT``. Parsed command line arguments are passed as
809 809 ``$HG_PATS`` and ``$HG_OPTS``. These contain string representations of
810 810 the python data internally passed to <command>. ``$HG_OPTS`` is a
811 811 dictionary of options (with unspecified options set to their defaults).
812 812 ``$HG_PATS`` is a list of arguments. Hook failure is ignored.
813 813
814 814 ``fail-<command>``
815 815 Run after a failed invocation of an associated command. The contents
816 816 of the command line are passed as ``$HG_ARGS``. Parsed command line
817 817 arguments are passed as ``$HG_PATS`` and ``$HG_OPTS``. These contain
818 818 string representations of the python data internally passed to
819 819 <command>. ``$HG_OPTS`` is a dictionary of options (with unspecified
820 820 options set to their defaults). ``$HG_PATS`` is a list of arguments.
821 821 Hook failure is ignored.
822 822
823 823 ``pre-<command>``
824 824 Run before executing the associated command. The contents of the
825 825 command line are passed as ``$HG_ARGS``. Parsed command line arguments
826 826 are passed as ``$HG_PATS`` and ``$HG_OPTS``. These contain string
827 827 representations of the data internally passed to <command>. ``$HG_OPTS``
828 828 is a dictionary of options (with unspecified options set to their
829 829 defaults). ``$HG_PATS`` is a list of arguments. If the hook returns
830 830 failure, the command doesn't execute and Mercurial returns the failure
831 831 code.
832 832
833 833 ``prechangegroup``
834 834 Run before a changegroup is added via push, pull or unbundle. Exit
835 835 status 0 allows the changegroup to proceed. Non-zero status will
836 836 cause the push, pull or unbundle to fail. URL from which changes
837 837 will come is in ``$HG_URL``.
838 838
839 839 ``precommit``
840 840 Run before starting a local commit. Exit status 0 allows the
841 841 commit to proceed. Non-zero status will cause the commit to fail.
842 842 Parent changeset IDs are in ``$HG_PARENT1`` and ``$HG_PARENT2``.
843 843
844 844 ``prelistkeys``
845 845 Run before listing pushkeys (like bookmarks) in the
846 846 repository. Non-zero status will cause failure. The key namespace is
847 847 in ``$HG_NAMESPACE``.
848 848
849 849 ``preoutgoing``
850 850 Run before collecting changes to send from the local repository to
851 851 another. Non-zero status will cause failure. This lets you prevent
852 852 pull over HTTP or SSH. Also prevents against local pull, push
853 853 (outbound) or bundle commands, but not effective, since you can
854 854 just copy files instead then. Source of operation is in
855 855 ``$HG_SOURCE``. If "serve", operation is happening on behalf of remote
856 856 SSH or HTTP repository. If "push", "pull" or "bundle", operation
857 857 is happening on behalf of repository on same system.
858 858
859 859 ``prepushkey``
860 860 Run before a pushkey (like a bookmark) is added to the
861 861 repository. Non-zero status will cause the key to be rejected. The
862 862 key namespace is in ``$HG_NAMESPACE``, the key is in ``$HG_KEY``,
863 863 the old value (if any) is in ``$HG_OLD``, and the new value is in
864 864 ``$HG_NEW``.
865 865
866 866 ``pretag``
867 867 Run before creating a tag. Exit status 0 allows the tag to be
868 868 created. Non-zero status will cause the tag to fail. ID of
869 869 changeset to tag is in ``$HG_NODE``. Name of tag is in ``$HG_TAG``. Tag is
870 870 local if ``$HG_LOCAL=1``, in repository if ``$HG_LOCAL=0``.
871 871
872 872 ``pretxnopen``
873 873 Run before any new repository transaction is open. The reason for the
874 874 transaction will be in ``$HG_TXNNAME`` and a unique identifier for the
875 875 transaction will be in ``HG_TXNID``. A non-zero status will prevent the
876 876 transaction from being opened.
877 877
878 878 ``pretxnclose``
879 879 Run right before the transaction is actually finalized. Any repository change
880 880 will be visible to the hook program. This lets you validate the transaction
881 881 content or change it. Exit status 0 allows the commit to proceed. Non-zero
882 882 status will cause the transaction to be rolled back. The reason for the
883 883 transaction opening will be in ``$HG_TXNNAME`` and a unique identifier for
884 884 the transaction will be in ``HG_TXNID``. The rest of the available data will
885 885 vary according the transaction type. New changesets will add ``$HG_NODE`` (id
886 886 of the first added changeset), ``$HG_NODE_LAST`` (id of the last added
887 887 changeset), ``$HG_URL`` and ``$HG_SOURCE`` variables, bookmarks and phases
888 888 changes will set ``HG_BOOKMARK_MOVED`` and ``HG_PHASES_MOVED`` to ``1``, etc.
889 889
890 890 ``txnclose``
891 891 Run after any repository transaction has been committed. At this
892 892 point, the transaction can no longer be rolled back. The hook will run
893 893 after the lock is released. See :hg:`help config.hooks.pretxnclose` docs for
894 894 details about available variables.
895 895
896 896 ``txnabort``
897 897 Run when a transaction is aborted. See :hg:`help config.hooks.pretxnclose`
898 898 docs for details about available variables.
899 899
900 900 ``pretxnchangegroup``
901 901 Run after a changegroup has been added via push, pull or unbundle, but before
902 902 the transaction has been committed. Changegroup is visible to hook program.
903 903 This lets you validate incoming changes before accepting them. Passed the ID
904 904 of the first new changeset in ``$HG_NODE`` and last in ``$HG_NODE_LAST``.
905 905 Exit status 0 allows the transaction to commit. Non-zero status will cause
906 906 the transaction to be rolled back and the push, pull or unbundle will fail.
907 907 URL that was source of changes is in ``$HG_URL``.
908 908
909 909 ``pretxncommit``
910 910 Run after a changeset has been created but the transaction not yet
911 911 committed. Changeset is visible to hook program. This lets you
912 912 validate commit message and changes. Exit status 0 allows the
913 913 commit to proceed. Non-zero status will cause the transaction to
914 914 be rolled back. ID of changeset is in ``$HG_NODE``. Parent changeset
915 915 IDs are in ``$HG_PARENT1`` and ``$HG_PARENT2``.
916 916
917 917 ``preupdate``
918 918 Run before updating the working directory. Exit status 0 allows
919 919 the update to proceed. Non-zero status will prevent the update.
920 920 Changeset ID of first new parent is in ``$HG_PARENT1``. If merge, ID
921 921 of second new parent is in ``$HG_PARENT2``.
922 922
923 923 ``listkeys``
924 924 Run after listing pushkeys (like bookmarks) in the repository. The
925 925 key namespace is in ``$HG_NAMESPACE``. ``$HG_VALUES`` is a
926 926 dictionary containing the keys and values.
927 927
928 928 ``pushkey``
929 929 Run after a pushkey (like a bookmark) is added to the
930 930 repository. The key namespace is in ``$HG_NAMESPACE``, the key is in
931 931 ``$HG_KEY``, the old value (if any) is in ``$HG_OLD``, and the new
932 932 value is in ``$HG_NEW``.
933 933
934 934 ``tag``
935 935 Run after a tag is created. ID of tagged changeset is in ``$HG_NODE``.
936 936 Name of tag is in ``$HG_TAG``. Tag is local if ``$HG_LOCAL=1``, in
937 937 repository if ``$HG_LOCAL=0``.
938 938
939 939 ``update``
940 940 Run after updating the working directory. Changeset ID of first
941 941 new parent is in ``$HG_PARENT1``. If merge, ID of second new parent is
942 942 in ``$HG_PARENT2``. If the update succeeded, ``$HG_ERROR=0``. If the
943 943 update failed (e.g. because conflicts not resolved), ``$HG_ERROR=1``.
944 944
945 945 .. note::
946 946
947 947 It is generally better to use standard hooks rather than the
948 948 generic pre- and post- command hooks as they are guaranteed to be
949 949 called in the appropriate contexts for influencing transactions.
950 950 Also, hooks like "commit" will be called in all contexts that
951 951 generate a commit (e.g. tag) and not just the commit command.
952 952
953 953 .. note::
954 954
955 955 Environment variables with empty values may not be passed to
956 956 hooks on platforms such as Windows. As an example, ``$HG_PARENT2``
957 957 will have an empty value under Unix-like platforms for non-merge
958 958 changesets, while it will not be available at all under Windows.
959 959
960 960 The syntax for Python hooks is as follows::
961 961
962 962 hookname = python:modulename.submodule.callable
963 963 hookname = python:/path/to/python/module.py:callable
964 964
965 965 Python hooks are run within the Mercurial process. Each hook is
966 966 called with at least three keyword arguments: a ui object (keyword
967 967 ``ui``), a repository object (keyword ``repo``), and a ``hooktype``
968 968 keyword that tells what kind of hook is used. Arguments listed as
969 969 environment variables above are passed as keyword arguments, with no
970 970 ``HG_`` prefix, and names in lower case.
971 971
972 972 If a Python hook returns a "true" value or raises an exception, this
973 973 is treated as a failure.
974 974
975 975
976 976 ``hostfingerprints``
977 977 --------------------
978 978
979 979 (Deprecated. Use ``[hostsecurity]``'s ``fingerprints`` options instead.)
980 980
981 981 Fingerprints of the certificates of known HTTPS servers.
982 982
983 983 A HTTPS connection to a server with a fingerprint configured here will
984 984 only succeed if the servers certificate matches the fingerprint.
985 985 This is very similar to how ssh known hosts works.
986 986
987 987 The fingerprint is the SHA-1 hash value of the DER encoded certificate.
988 988 Multiple values can be specified (separated by spaces or commas). This can
989 989 be used to define both old and new fingerprints while a host transitions
990 990 to a new certificate.
991 991
992 992 The CA chain and web.cacerts is not used for servers with a fingerprint.
993 993
994 994 For example::
995 995
996 996 [hostfingerprints]
997 997 hg.intevation.de = fc:e2:8d:d9:51:cd:cb:c1:4d:18:6b:b7:44:8d:49:72:57:e6:cd:33
998 998 hg.intevation.org = fc:e2:8d:d9:51:cd:cb:c1:4d:18:6b:b7:44:8d:49:72:57:e6:cd:33
999 999
1000 1000 ``hostsecurity``
1001 1001 ----------------
1002 1002
1003 1003 Used to specify per-host security settings.
1004 1004
1005 1005 Options in this section have the form ``hostname``:``setting``. This allows
1006 1006 multiple settings to be defined on a per-host basis.
1007 1007
1008 1008 The following per-host settings can be defined.
1009 1009
1010 1010 ``fingerprints``
1011 1011 A list of hashes of the DER encoded peer/remote certificate. Values have
1012 1012 the form ``algorithm``:``fingerprint``. e.g.
1013 1013 ``sha256:c3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2``.
1014 1014
1015 1015 The following algorithms/prefixes are supported: ``sha1``, ``sha256``,
1016 1016 ``sha512``.
1017 1017
1018 1018 Use of ``sha256`` or ``sha512`` is preferred.
1019 1019
1020 1020 If a fingerprint is specified, the CA chain is not validated for this
1021 1021 host and Mercurial will require the remote certificate to match one
1022 1022 of the fingerprints specified. This means if the server updates its
1023 1023 certificate, Mercurial will abort until a new fingerprint is defined.
1024 1024 This can provide stronger security than traditional CA-based validation
1025 1025 at the expense of convenience.
1026 1026
1027 1027 For example::
1028 1028
1029 1029 [hostsecurity]
1030 1030 hg.example.com:fingerprints = sha256:c3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2
1031 1031 hg2.example.com:fingerprints = sha1:914f1aff87249c09b6859b88b1906d30756491ca, sha1:fc:e2:8d:d9:51:cd:cb:c1:4d:18:6b:b7:44:8d:49:72:57:e6:cd:33
1032 1032
1033 1033 ``http_proxy``
1034 1034 --------------
1035 1035
1036 1036 Used to access web-based Mercurial repositories through a HTTP
1037 1037 proxy.
1038 1038
1039 1039 ``host``
1040 1040 Host name and (optional) port of the proxy server, for example
1041 1041 "myproxy:8000".
1042 1042
1043 1043 ``no``
1044 1044 Optional. Comma-separated list of host names that should bypass
1045 1045 the proxy.
1046 1046
1047 1047 ``passwd``
1048 1048 Optional. Password to authenticate with at the proxy server.
1049 1049
1050 1050 ``user``
1051 1051 Optional. User name to authenticate with at the proxy server.
1052 1052
1053 1053 ``always``
1054 1054 Optional. Always use the proxy, even for localhost and any entries
1055 1055 in ``http_proxy.no``. (default: False)
1056 1056
1057 1057 ``merge``
1058 1058 ---------
1059 1059
1060 1060 This section specifies behavior during merges and updates.
1061 1061
1062 1062 ``checkignored``
1063 1063 Controls behavior when an ignored file on disk has the same name as a tracked
1064 1064 file in the changeset being merged or updated to, and has different
1065 1065 contents. Options are ``abort``, ``warn`` and ``ignore``. With ``abort``,
1066 1066 abort on such files. With ``warn``, warn on such files and back them up as
1067 1067 ``.orig``. With ``ignore``, don't print a warning and back them up as
1068 1068 ``.orig``. (default: ``abort``)
1069 1069
1070 1070 ``checkunknown``
1071 1071 Controls behavior when an unknown file that isn't ignored has the same name
1072 1072 as a tracked file in the changeset being merged or updated to, and has
1073 1073 different contents. Similar to ``merge.checkignored``, except for files that
1074 1074 are not ignored. (default: ``abort``)
1075 1075
1076 1076 ``merge-patterns``
1077 1077 ------------------
1078 1078
1079 1079 This section specifies merge tools to associate with particular file
1080 1080 patterns. Tools matched here will take precedence over the default
1081 1081 merge tool. Patterns are globs by default, rooted at the repository
1082 1082 root.
1083 1083
1084 1084 Example::
1085 1085
1086 1086 [merge-patterns]
1087 1087 **.c = kdiff3
1088 1088 **.jpg = myimgmerge
1089 1089
1090 1090 ``merge-tools``
1091 1091 ---------------
1092 1092
1093 1093 This section configures external merge tools to use for file-level
1094 1094 merges. This section has likely been preconfigured at install time.
1095 1095 Use :hg:`config merge-tools` to check the existing configuration.
1096 1096 Also see :hg:`help merge-tools` for more details.
1097 1097
1098 1098 Example ``~/.hgrc``::
1099 1099
1100 1100 [merge-tools]
1101 1101 # Override stock tool location
1102 1102 kdiff3.executable = ~/bin/kdiff3
1103 1103 # Specify command line
1104 1104 kdiff3.args = $base $local $other -o $output
1105 1105 # Give higher priority
1106 1106 kdiff3.priority = 1
1107 1107
1108 1108 # Changing the priority of preconfigured tool
1109 1109 meld.priority = 0
1110 1110
1111 1111 # Disable a preconfigured tool
1112 1112 vimdiff.disabled = yes
1113 1113
1114 1114 # Define new tool
1115 1115 myHtmlTool.args = -m $local $other $base $output
1116 1116 myHtmlTool.regkey = Software\FooSoftware\HtmlMerge
1117 1117 myHtmlTool.priority = 1
1118 1118
1119 1119 Supported arguments:
1120 1120
1121 1121 ``priority``
1122 1122 The priority in which to evaluate this tool.
1123 1123 (default: 0)
1124 1124
1125 1125 ``executable``
1126 1126 Either just the name of the executable or its pathname.
1127 1127
1128 1128 .. container:: windows
1129 1129
1130 1130 On Windows, the path can use environment variables with ${ProgramFiles}
1131 1131 syntax.
1132 1132
1133 1133 (default: the tool name)
1134 1134
1135 1135 ``args``
1136 1136 The arguments to pass to the tool executable. You can refer to the
1137 1137 files being merged as well as the output file through these
1138 1138 variables: ``$base``, ``$local``, ``$other``, ``$output``. The meaning
1139 1139 of ``$local`` and ``$other`` can vary depending on which action is being
1140 1140 performed. During and update or merge, ``$local`` represents the original
1141 1141 state of the file, while ``$other`` represents the commit you are updating
1142 1142 to or the commit you are merging with. During a rebase ``$local``
1143 1143 represents the destination of the rebase, and ``$other`` represents the
1144 1144 commit being rebased.
1145 1145 (default: ``$local $base $other``)
1146 1146
1147 1147 ``premerge``
1148 1148 Attempt to run internal non-interactive 3-way merge tool before
1149 1149 launching external tool. Options are ``true``, ``false``, ``keep`` or
1150 1150 ``keep-merge3``. The ``keep`` option will leave markers in the file if the
1151 1151 premerge fails. The ``keep-merge3`` will do the same but include information
1152 1152 about the base of the merge in the marker (see internal :merge3 in
1153 1153 :hg:`help merge-tools`).
1154 1154 (default: True)
1155 1155
1156 1156 ``binary``
1157 1157 This tool can merge binary files. (default: False, unless tool
1158 1158 was selected by file pattern match)
1159 1159
1160 1160 ``symlink``
1161 1161 This tool can merge symlinks. (default: False)
1162 1162
1163 1163 ``check``
1164 1164 A list of merge success-checking options:
1165 1165
1166 1166 ``changed``
1167 1167 Ask whether merge was successful when the merged file shows no changes.
1168 1168 ``conflicts``
1169 1169 Check whether there are conflicts even though the tool reported success.
1170 1170 ``prompt``
1171 1171 Always prompt for merge success, regardless of success reported by tool.
1172 1172
1173 1173 ``fixeol``
1174 1174 Attempt to fix up EOL changes caused by the merge tool.
1175 1175 (default: False)
1176 1176
1177 1177 ``gui``
1178 1178 This tool requires a graphical interface to run. (default: False)
1179 1179
1180 1180 .. container:: windows
1181 1181
1182 1182 ``regkey``
1183 1183 Windows registry key which describes install location of this
1184 1184 tool. Mercurial will search for this key first under
1185 1185 ``HKEY_CURRENT_USER`` and then under ``HKEY_LOCAL_MACHINE``.
1186 1186 (default: None)
1187 1187
1188 1188 ``regkeyalt``
1189 1189 An alternate Windows registry key to try if the first key is not
1190 1190 found. The alternate key uses the same ``regname`` and ``regappend``
1191 1191 semantics of the primary key. The most common use for this key
1192 1192 is to search for 32bit applications on 64bit operating systems.
1193 1193 (default: None)
1194 1194
1195 1195 ``regname``
1196 1196 Name of value to read from specified registry key.
1197 1197 (default: the unnamed (default) value)
1198 1198
1199 1199 ``regappend``
1200 1200 String to append to the value read from the registry, typically
1201 1201 the executable name of the tool.
1202 1202 (default: None)
1203 1203
1204 1204
1205 1205 ``patch``
1206 1206 ---------
1207 1207
1208 1208 Settings used when applying patches, for instance through the 'import'
1209 1209 command or with Mercurial Queues extension.
1210 1210
1211 1211 ``eol``
1212 1212 When set to 'strict' patch content and patched files end of lines
1213 1213 are preserved. When set to ``lf`` or ``crlf``, both files end of
1214 1214 lines are ignored when patching and the result line endings are
1215 1215 normalized to either LF (Unix) or CRLF (Windows). When set to
1216 1216 ``auto``, end of lines are again ignored while patching but line
1217 1217 endings in patched files are normalized to their original setting
1218 1218 on a per-file basis. If target file does not exist or has no end
1219 1219 of line, patch line endings are preserved.
1220 1220 (default: strict)
1221 1221
1222 1222 ``fuzz``
1223 1223 The number of lines of 'fuzz' to allow when applying patches. This
1224 1224 controls how much context the patcher is allowed to ignore when
1225 1225 trying to apply a patch.
1226 1226 (default: 2)
1227 1227
1228 1228 ``paths``
1229 1229 ---------
1230 1230
1231 1231 Assigns symbolic names and behavior to repositories.
1232 1232
1233 1233 Options are symbolic names defining the URL or directory that is the
1234 1234 location of the repository. Example::
1235 1235
1236 1236 [paths]
1237 1237 my_server = https://example.com/my_repo
1238 1238 local_path = /home/me/repo
1239 1239
1240 1240 These symbolic names can be used from the command line. To pull
1241 1241 from ``my_server``: :hg:`pull my_server`. To push to ``local_path``:
1242 1242 :hg:`push local_path`.
1243 1243
1244 1244 Options containing colons (``:``) denote sub-options that can influence
1245 1245 behavior for that specific path. Example::
1246 1246
1247 1247 [paths]
1248 1248 my_server = https://example.com/my_path
1249 1249 my_server:pushurl = ssh://example.com/my_path
1250 1250
1251 1251 The following sub-options can be defined:
1252 1252
1253 1253 ``pushurl``
1254 1254 The URL to use for push operations. If not defined, the location
1255 1255 defined by the path's main entry is used.
1256 1256
1257 1257 The following special named paths exist:
1258 1258
1259 1259 ``default``
1260 1260 The URL or directory to use when no source or remote is specified.
1261 1261
1262 1262 :hg:`clone` will automatically define this path to the location the
1263 1263 repository was cloned from.
1264 1264
1265 1265 ``default-push``
1266 1266 (deprecated) The URL or directory for the default :hg:`push` location.
1267 1267 ``default:pushurl`` should be used instead.
1268 1268
1269 1269 ``phases``
1270 1270 ----------
1271 1271
1272 1272 Specifies default handling of phases. See :hg:`help phases` for more
1273 1273 information about working with phases.
1274 1274
1275 1275 ``publish``
1276 1276 Controls draft phase behavior when working as a server. When true,
1277 1277 pushed changesets are set to public in both client and server and
1278 1278 pulled or cloned changesets are set to public in the client.
1279 1279 (default: True)
1280 1280
1281 1281 ``new-commit``
1282 1282 Phase of newly-created commits.
1283 1283 (default: draft)
1284 1284
1285 1285 ``checksubrepos``
1286 1286 Check the phase of the current revision of each subrepository. Allowed
1287 1287 values are "ignore", "follow" and "abort". For settings other than
1288 1288 "ignore", the phase of the current revision of each subrepository is
1289 1289 checked before committing the parent repository. If any of those phases is
1290 1290 greater than the phase of the parent repository (e.g. if a subrepo is in a
1291 1291 "secret" phase while the parent repo is in "draft" phase), the commit is
1292 1292 either aborted (if checksubrepos is set to "abort") or the higher phase is
1293 1293 used for the parent repository commit (if set to "follow").
1294 1294 (default: follow)
1295 1295
1296 1296
1297 1297 ``profiling``
1298 1298 -------------
1299 1299
1300 1300 Specifies profiling type, format, and file output. Two profilers are
1301 1301 supported: an instrumenting profiler (named ``ls``), and a sampling
1302 1302 profiler (named ``stat``).
1303 1303
1304 1304 In this section description, 'profiling data' stands for the raw data
1305 1305 collected during profiling, while 'profiling report' stands for a
1306 1306 statistical text report generated from the profiling data. The
1307 1307 profiling is done using lsprof.
1308 1308
1309 1309 ``type``
1310 1310 The type of profiler to use.
1311 1311 (default: ls)
1312 1312
1313 1313 ``ls``
1314 1314 Use Python's built-in instrumenting profiler. This profiler
1315 1315 works on all platforms, but each line number it reports is the
1316 1316 first line of a function. This restriction makes it difficult to
1317 1317 identify the expensive parts of a non-trivial function.
1318 1318 ``stat``
1319 1319 Use a third-party statistical profiler, statprof. This profiler
1320 1320 currently runs only on Unix systems, and is most useful for
1321 1321 profiling commands that run for longer than about 0.1 seconds.
1322 1322
1323 1323 ``format``
1324 1324 Profiling format. Specific to the ``ls`` instrumenting profiler.
1325 1325 (default: text)
1326 1326
1327 1327 ``text``
1328 1328 Generate a profiling report. When saving to a file, it should be
1329 1329 noted that only the report is saved, and the profiling data is
1330 1330 not kept.
1331 1331 ``kcachegrind``
1332 1332 Format profiling data for kcachegrind use: when saving to a
1333 1333 file, the generated file can directly be loaded into
1334 1334 kcachegrind.
1335 1335
1336 1336 ``frequency``
1337 1337 Sampling frequency. Specific to the ``stat`` sampling profiler.
1338 1338 (default: 1000)
1339 1339
1340 1340 ``output``
1341 1341 File path where profiling data or report should be saved. If the
1342 1342 file exists, it is replaced. (default: None, data is printed on
1343 1343 stderr)
1344 1344
1345 1345 ``sort``
1346 1346 Sort field. Specific to the ``ls`` instrumenting profiler.
1347 1347 One of ``callcount``, ``reccallcount``, ``totaltime`` and
1348 1348 ``inlinetime``.
1349 1349 (default: inlinetime)
1350 1350
1351 1351 ``limit``
1352 1352 Number of lines to show. Specific to the ``ls`` instrumenting profiler.
1353 1353 (default: 30)
1354 1354
1355 1355 ``nested``
1356 1356 Show at most this number of lines of drill-down info after each main entry.
1357 1357 This can help explain the difference between Total and Inline.
1358 1358 Specific to the ``ls`` instrumenting profiler.
1359 1359 (default: 5)
1360 1360
1361 1361 ``progress``
1362 1362 ------------
1363 1363
1364 1364 Mercurial commands can draw progress bars that are as informative as
1365 1365 possible. Some progress bars only offer indeterminate information, while others
1366 1366 have a definite end point.
1367 1367
1368 1368 ``delay``
1369 1369 Number of seconds (float) before showing the progress bar. (default: 3)
1370 1370
1371 1371 ``changedelay``
1372 1372 Minimum delay before showing a new topic. When set to less than 3 * refresh,
1373 1373 that value will be used instead. (default: 1)
1374 1374
1375 1375 ``refresh``
1376 1376 Time in seconds between refreshes of the progress bar. (default: 0.1)
1377 1377
1378 1378 ``format``
1379 1379 Format of the progress bar.
1380 1380
1381 1381 Valid entries for the format field are ``topic``, ``bar``, ``number``,
1382 1382 ``unit``, ``estimate``, ``speed``, and ``item``. ``item`` defaults to the
1383 1383 last 20 characters of the item, but this can be changed by adding either
1384 1384 ``-<num>`` which would take the last num characters, or ``+<num>`` for the
1385 1385 first num characters.
1386 1386
1387 1387 (default: topic bar number estimate)
1388 1388
1389 1389 ``width``
1390 1390 If set, the maximum width of the progress information (that is, min(width,
1391 1391 term width) will be used).
1392 1392
1393 1393 ``clear-complete``
1394 1394 Clear the progress bar after it's done. (default: True)
1395 1395
1396 1396 ``disable``
1397 1397 If true, don't show a progress bar.
1398 1398
1399 1399 ``assume-tty``
1400 1400 If true, ALWAYS show a progress bar, unless disable is given.
1401 1401
1402 1402 ``rebase``
1403 1403 ----------
1404 1404
1405 1405 ``allowdivergence``
1406 1406 Default to False, when True allow creating divergence when performing
1407 1407 rebase of obsolete changesets.
1408 1408
1409 1409 ``revsetalias``
1410 1410 ---------------
1411 1411
1412 1412 Alias definitions for revsets. See :hg:`help revsets` for details.
1413 1413
1414 1414 ``server``
1415 1415 ----------
1416 1416
1417 1417 Controls generic server settings.
1418 1418
1419 1419 ``uncompressed``
1420 1420 Whether to allow clients to clone a repository using the
1421 1421 uncompressed streaming protocol. This transfers about 40% more
1422 1422 data than a regular clone, but uses less memory and CPU on both
1423 1423 server and client. Over a LAN (100 Mbps or better) or a very fast
1424 1424 WAN, an uncompressed streaming clone is a lot faster (~10x) than a
1425 1425 regular clone. Over most WAN connections (anything slower than
1426 1426 about 6 Mbps), uncompressed streaming is slower, because of the
1427 1427 extra data transfer overhead. This mode will also temporarily hold
1428 1428 the write lock while determining what data to transfer.
1429 1429 (default: True)
1430 1430
1431 1431 ``preferuncompressed``
1432 1432 When set, clients will try to use the uncompressed streaming
1433 1433 protocol. (default: False)
1434 1434
1435 1435 ``validate``
1436 1436 Whether to validate the completeness of pushed changesets by
1437 1437 checking that all new file revisions specified in manifests are
1438 1438 present. (default: False)
1439 1439
1440 1440 ``maxhttpheaderlen``
1441 1441 Instruct HTTP clients not to send request headers longer than this
1442 1442 many bytes. (default: 1024)
1443 1443
1444 1444 ``bundle1``
1445 1445 Whether to allow clients to push and pull using the legacy bundle1
1446 1446 exchange format. (default: True)
1447 1447
1448 1448 ``bundle1gd``
1449 1449 Like ``bundle1`` but only used if the repository is using the
1450 1450 *generaldelta* storage format. (default: True)
1451 1451
1452 1452 ``bundle1.push``
1453 1453 Whether to allow clients to push using the legacy bundle1 exchange
1454 1454 format. (default: True)
1455 1455
1456 1456 ``bundle1gd.push``
1457 1457 Like ``bundle1.push`` but only used if the repository is using the
1458 1458 *generaldelta* storage format. (default: True)
1459 1459
1460 1460 ``bundle1.pull``
1461 1461 Whether to allow clients to pull using the legacy bundle1 exchange
1462 1462 format. (default: True)
1463 1463
1464 1464 ``bundle1gd.pull``
1465 1465 Like ``bundle1.pull`` but only used if the repository is using the
1466 1466 *generaldelta* storage format. (default: True)
1467 1467
1468 1468 Large repositories using the *generaldelta* storage format should
1469 1469 consider setting this option because converting *generaldelta*
1470 1470 repositories to the exchange format required by the bundle1 data
1471 1471 format can consume a lot of CPU.
1472 1472
1473 1473 ``smtp``
1474 1474 --------
1475 1475
1476 1476 Configuration for extensions that need to send email messages.
1477 1477
1478 1478 ``host``
1479 1479 Host name of mail server, e.g. "mail.example.com".
1480 1480
1481 1481 ``port``
1482 1482 Optional. Port to connect to on mail server. (default: 465 if
1483 1483 ``tls`` is smtps; 25 otherwise)
1484 1484
1485 1485 ``tls``
1486 1486 Optional. Method to enable TLS when connecting to mail server: starttls,
1487 1487 smtps or none. (default: none)
1488 1488
1489 ``verifycert``
1490 Optional. Verification for the certificate of mail server, when
1491 ``tls`` is starttls or smtps. "strict", "loose" or False. For
1492 "strict" or "loose", the certificate is verified as same as the
1493 verification for HTTPS connections (see ``[hostfingerprints]`` and
1494 ``[web] cacerts`` also). For "strict", sending email is also
1495 aborted, if there is no configuration for mail server in
1496 ``[hostfingerprints]`` and ``[web] cacerts``. --insecure for
1497 :hg:`email` overwrites this as "loose". (default: strict)
1498
1499 1489 ``username``
1500 1490 Optional. User name for authenticating with the SMTP server.
1501 1491 (default: None)
1502 1492
1503 1493 ``password``
1504 1494 Optional. Password for authenticating with the SMTP server. If not
1505 1495 specified, interactive sessions will prompt the user for a
1506 1496 password; non-interactive sessions will fail. (default: None)
1507 1497
1508 1498 ``local_hostname``
1509 1499 Optional. The hostname that the sender can use to identify
1510 1500 itself to the MTA.
1511 1501
1512 1502
1513 1503 ``subpaths``
1514 1504 ------------
1515 1505
1516 1506 Subrepository source URLs can go stale if a remote server changes name
1517 1507 or becomes temporarily unavailable. This section lets you define
1518 1508 rewrite rules of the form::
1519 1509
1520 1510 <pattern> = <replacement>
1521 1511
1522 1512 where ``pattern`` is a regular expression matching a subrepository
1523 1513 source URL and ``replacement`` is the replacement string used to
1524 1514 rewrite it. Groups can be matched in ``pattern`` and referenced in
1525 1515 ``replacements``. For instance::
1526 1516
1527 1517 http://server/(.*)-hg/ = http://hg.server/\1/
1528 1518
1529 1519 rewrites ``http://server/foo-hg/`` into ``http://hg.server/foo/``.
1530 1520
1531 1521 Relative subrepository paths are first made absolute, and the
1532 1522 rewrite rules are then applied on the full (absolute) path. The rules
1533 1523 are applied in definition order.
1534 1524
1535 1525 ``templatealias``
1536 1526 -----------------
1537 1527
1538 1528 Alias definitions for templates. See :hg:`help templates` for details.
1539 1529
1540 1530 ``trusted``
1541 1531 -----------
1542 1532
1543 1533 Mercurial will not use the settings in the
1544 1534 ``.hg/hgrc`` file from a repository if it doesn't belong to a trusted
1545 1535 user or to a trusted group, as various hgrc features allow arbitrary
1546 1536 commands to be run. This issue is often encountered when configuring
1547 1537 hooks or extensions for shared repositories or servers. However,
1548 1538 the web interface will use some safe settings from the ``[web]``
1549 1539 section.
1550 1540
1551 1541 This section specifies what users and groups are trusted. The
1552 1542 current user is always trusted. To trust everybody, list a user or a
1553 1543 group with name ``*``. These settings must be placed in an
1554 1544 *already-trusted file* to take effect, such as ``$HOME/.hgrc`` of the
1555 1545 user or service running Mercurial.
1556 1546
1557 1547 ``users``
1558 1548 Comma-separated list of trusted users.
1559 1549
1560 1550 ``groups``
1561 1551 Comma-separated list of trusted groups.
1562 1552
1563 1553
1564 1554 ``ui``
1565 1555 ------
1566 1556
1567 1557 User interface controls.
1568 1558
1569 1559 ``archivemeta``
1570 1560 Whether to include the .hg_archival.txt file containing meta data
1571 1561 (hashes for the repository base and for tip) in archives created
1572 1562 by the :hg:`archive` command or downloaded via hgweb.
1573 1563 (default: True)
1574 1564
1575 1565 ``askusername``
1576 1566 Whether to prompt for a username when committing. If True, and
1577 1567 neither ``$HGUSER`` nor ``$EMAIL`` has been specified, then the user will
1578 1568 be prompted to enter a username. If no username is entered, the
1579 1569 default ``USER@HOST`` is used instead.
1580 1570 (default: False)
1581 1571
1582 1572 ``clonebundles``
1583 1573 Whether the "clone bundles" feature is enabled.
1584 1574
1585 1575 When enabled, :hg:`clone` may download and apply a server-advertised
1586 1576 bundle file from a URL instead of using the normal exchange mechanism.
1587 1577
1588 1578 This can likely result in faster and more reliable clones.
1589 1579
1590 1580 (default: True)
1591 1581
1592 1582 ``clonebundlefallback``
1593 1583 Whether failure to apply an advertised "clone bundle" from a server
1594 1584 should result in fallback to a regular clone.
1595 1585
1596 1586 This is disabled by default because servers advertising "clone
1597 1587 bundles" often do so to reduce server load. If advertised bundles
1598 1588 start mass failing and clients automatically fall back to a regular
1599 1589 clone, this would add significant and unexpected load to the server
1600 1590 since the server is expecting clone operations to be offloaded to
1601 1591 pre-generated bundles. Failing fast (the default behavior) ensures
1602 1592 clients don't overwhelm the server when "clone bundle" application
1603 1593 fails.
1604 1594
1605 1595 (default: False)
1606 1596
1607 1597 ``clonebundleprefers``
1608 1598 Defines preferences for which "clone bundles" to use.
1609 1599
1610 1600 Servers advertising "clone bundles" may advertise multiple available
1611 1601 bundles. Each bundle may have different attributes, such as the bundle
1612 1602 type and compression format. This option is used to prefer a particular
1613 1603 bundle over another.
1614 1604
1615 1605 The following keys are defined by Mercurial:
1616 1606
1617 1607 BUNDLESPEC
1618 1608 A bundle type specifier. These are strings passed to :hg:`bundle -t`.
1619 1609 e.g. ``gzip-v2`` or ``bzip2-v1``.
1620 1610
1621 1611 COMPRESSION
1622 1612 The compression format of the bundle. e.g. ``gzip`` and ``bzip2``.
1623 1613
1624 1614 Server operators may define custom keys.
1625 1615
1626 1616 Example values: ``COMPRESSION=bzip2``,
1627 1617 ``BUNDLESPEC=gzip-v2, COMPRESSION=gzip``.
1628 1618
1629 1619 By default, the first bundle advertised by the server is used.
1630 1620
1631 1621 ``commitsubrepos``
1632 1622 Whether to commit modified subrepositories when committing the
1633 1623 parent repository. If False and one subrepository has uncommitted
1634 1624 changes, abort the commit.
1635 1625 (default: False)
1636 1626
1637 1627 ``debug``
1638 1628 Print debugging information. (default: False)
1639 1629
1640 1630 ``editor``
1641 1631 The editor to use during a commit. (default: ``$EDITOR`` or ``vi``)
1642 1632
1643 1633 ``fallbackencoding``
1644 1634 Encoding to try if it's not possible to decode the changelog using
1645 1635 UTF-8. (default: ISO-8859-1)
1646 1636
1647 1637 ``graphnodetemplate``
1648 1638 The template used to print changeset nodes in an ASCII revision graph.
1649 1639 (default: ``{graphnode}``)
1650 1640
1651 1641 ``ignore``
1652 1642 A file to read per-user ignore patterns from. This file should be
1653 1643 in the same format as a repository-wide .hgignore file. Filenames
1654 1644 are relative to the repository root. This option supports hook syntax,
1655 1645 so if you want to specify multiple ignore files, you can do so by
1656 1646 setting something like ``ignore.other = ~/.hgignore2``. For details
1657 1647 of the ignore file format, see the ``hgignore(5)`` man page.
1658 1648
1659 1649 ``interactive``
1660 1650 Allow to prompt the user. (default: True)
1661 1651
1662 1652 ``interface``
1663 1653 Select the default interface for interactive features (default: text).
1664 1654 Possible values are 'text' and 'curses'.
1665 1655
1666 1656 ``interface.chunkselector``
1667 1657 Select the interface for change recording (e.g. :hg:`commit` -i).
1668 1658 Possible values are 'text' and 'curses'.
1669 1659 This config overrides the interface specified by ui.interface.
1670 1660
1671 1661 ``logtemplate``
1672 1662 Template string for commands that print changesets.
1673 1663
1674 1664 ``merge``
1675 1665 The conflict resolution program to use during a manual merge.
1676 1666 For more information on merge tools see :hg:`help merge-tools`.
1677 1667 For configuring merge tools see the ``[merge-tools]`` section.
1678 1668
1679 1669 ``mergemarkers``
1680 1670 Sets the merge conflict marker label styling. The ``detailed``
1681 1671 style uses the ``mergemarkertemplate`` setting to style the labels.
1682 1672 The ``basic`` style just uses 'local' and 'other' as the marker label.
1683 1673 One of ``basic`` or ``detailed``.
1684 1674 (default: ``basic``)
1685 1675
1686 1676 ``mergemarkertemplate``
1687 1677 The template used to print the commit description next to each conflict
1688 1678 marker during merge conflicts. See :hg:`help templates` for the template
1689 1679 format.
1690 1680
1691 1681 Defaults to showing the hash, tags, branches, bookmarks, author, and
1692 1682 the first line of the commit description.
1693 1683
1694 1684 If you use non-ASCII characters in names for tags, branches, bookmarks,
1695 1685 authors, and/or commit descriptions, you must pay attention to encodings of
1696 1686 managed files. At template expansion, non-ASCII characters use the encoding
1697 1687 specified by the ``--encoding`` global option, ``HGENCODING`` or other
1698 1688 environment variables that govern your locale. If the encoding of the merge
1699 1689 markers is different from the encoding of the merged files,
1700 1690 serious problems may occur.
1701 1691
1702 1692 ``origbackuppath``
1703 1693 The path to a directory used to store generated .orig files. If the path is
1704 1694 not a directory, one will be created.
1705 1695
1706 1696 ``patch``
1707 1697 An optional external tool that ``hg import`` and some extensions
1708 1698 will use for applying patches. By default Mercurial uses an
1709 1699 internal patch utility. The external tool must work as the common
1710 1700 Unix ``patch`` program. In particular, it must accept a ``-p``
1711 1701 argument to strip patch headers, a ``-d`` argument to specify the
1712 1702 current directory, a file name to patch, and a patch file to take
1713 1703 from stdin.
1714 1704
1715 1705 It is possible to specify a patch tool together with extra
1716 1706 arguments. For example, setting this option to ``patch --merge``
1717 1707 will use the ``patch`` program with its 2-way merge option.
1718 1708
1719 1709 ``portablefilenames``
1720 1710 Check for portable filenames. Can be ``warn``, ``ignore`` or ``abort``.
1721 1711 (default: ``warn``)
1722 1712
1723 1713 ``warn``
1724 1714 Print a warning message on POSIX platforms, if a file with a non-portable
1725 1715 filename is added (e.g. a file with a name that can't be created on
1726 1716 Windows because it contains reserved parts like ``AUX``, reserved
1727 1717 characters like ``:``, or would cause a case collision with an existing
1728 1718 file).
1729 1719
1730 1720 ``ignore``
1731 1721 Don't print a warning.
1732 1722
1733 1723 ``abort``
1734 1724 The command is aborted.
1735 1725
1736 1726 ``true``
1737 1727 Alias for ``warn``.
1738 1728
1739 1729 ``false``
1740 1730 Alias for ``ignore``.
1741 1731
1742 1732 .. container:: windows
1743 1733
1744 1734 On Windows, this configuration option is ignored and the command aborted.
1745 1735
1746 1736 ``quiet``
1747 1737 Reduce the amount of output printed.
1748 1738 (default: False)
1749 1739
1750 1740 ``remotecmd``
1751 1741 Remote command to use for clone/push/pull operations.
1752 1742 (default: ``hg``)
1753 1743
1754 1744 ``report_untrusted``
1755 1745 Warn if a ``.hg/hgrc`` file is ignored due to not being owned by a
1756 1746 trusted user or group.
1757 1747 (default: True)
1758 1748
1759 1749 ``slash``
1760 1750 Display paths using a slash (``/``) as the path separator. This
1761 1751 only makes a difference on systems where the default path
1762 1752 separator is not the slash character (e.g. Windows uses the
1763 1753 backslash character (``\``)).
1764 1754 (default: False)
1765 1755
1766 1756 ``statuscopies``
1767 1757 Display copies in the status command.
1768 1758
1769 1759 ``ssh``
1770 1760 Command to use for SSH connections. (default: ``ssh``)
1771 1761
1772 1762 ``strict``
1773 1763 Require exact command names, instead of allowing unambiguous
1774 1764 abbreviations. (default: False)
1775 1765
1776 1766 ``style``
1777 1767 Name of style to use for command output.
1778 1768
1779 1769 ``supportcontact``
1780 1770 A URL where users should report a Mercurial traceback. Use this if you are a
1781 1771 large organisation with its own Mercurial deployment process and crash
1782 1772 reports should be addressed to your internal support.
1783 1773
1784 1774 ``textwidth``
1785 1775 Maximum width of help text. A longer line generated by ``hg help`` or
1786 1776 ``hg subcommand --help`` will be broken after white space to get this
1787 1777 width or the terminal width, whichever comes first.
1788 1778 A non-positive value will disable this and the terminal width will be
1789 1779 used. (default: 78)
1790 1780
1791 1781 ``timeout``
1792 1782 The timeout used when a lock is held (in seconds), a negative value
1793 1783 means no timeout. (default: 600)
1794 1784
1795 1785 ``traceback``
1796 1786 Mercurial always prints a traceback when an unknown exception
1797 1787 occurs. Setting this to True will make Mercurial print a traceback
1798 1788 on all exceptions, even those recognized by Mercurial (such as
1799 1789 IOError or MemoryError). (default: False)
1800 1790
1801 1791 ``username``
1802 1792 The committer of a changeset created when running "commit".
1803 1793 Typically a person's name and email address, e.g. ``Fred Widget
1804 1794 <fred@example.com>``. Environment variables in the
1805 1795 username are expanded.
1806 1796
1807 1797 (default: ``$EMAIL`` or ``username@hostname``. If the username in
1808 1798 hgrc is empty, e.g. if the system admin set ``username =`` in the
1809 1799 system hgrc, it has to be specified manually or in a different
1810 1800 hgrc file)
1811 1801
1812 1802 ``verbose``
1813 1803 Increase the amount of output printed. (default: False)
1814 1804
1815 1805
1816 1806 ``web``
1817 1807 -------
1818 1808
1819 1809 Web interface configuration. The settings in this section apply to
1820 1810 both the builtin webserver (started by :hg:`serve`) and the script you
1821 1811 run through a webserver (``hgweb.cgi`` and the derivatives for FastCGI
1822 1812 and WSGI).
1823 1813
1824 1814 The Mercurial webserver does no authentication (it does not prompt for
1825 1815 usernames and passwords to validate *who* users are), but it does do
1826 1816 authorization (it grants or denies access for *authenticated users*
1827 1817 based on settings in this section). You must either configure your
1828 1818 webserver to do authentication for you, or disable the authorization
1829 1819 checks.
1830 1820
1831 1821 For a quick setup in a trusted environment, e.g., a private LAN, where
1832 1822 you want it to accept pushes from anybody, you can use the following
1833 1823 command line::
1834 1824
1835 1825 $ hg --config web.allow_push=* --config web.push_ssl=False serve
1836 1826
1837 1827 Note that this will allow anybody to push anything to the server and
1838 1828 that this should not be used for public servers.
1839 1829
1840 1830 The full set of options is:
1841 1831
1842 1832 ``accesslog``
1843 1833 Where to output the access log. (default: stdout)
1844 1834
1845 1835 ``address``
1846 1836 Interface address to bind to. (default: all)
1847 1837
1848 1838 ``allow_archive``
1849 1839 List of archive format (bz2, gz, zip) allowed for downloading.
1850 1840 (default: empty)
1851 1841
1852 1842 ``allowbz2``
1853 1843 (DEPRECATED) Whether to allow .tar.bz2 downloading of repository
1854 1844 revisions.
1855 1845 (default: False)
1856 1846
1857 1847 ``allowgz``
1858 1848 (DEPRECATED) Whether to allow .tar.gz downloading of repository
1859 1849 revisions.
1860 1850 (default: False)
1861 1851
1862 1852 ``allowpull``
1863 1853 Whether to allow pulling from the repository. (default: True)
1864 1854
1865 1855 ``allow_push``
1866 1856 Whether to allow pushing to the repository. If empty or not set,
1867 1857 pushing is not allowed. If the special value ``*``, any remote
1868 1858 user can push, including unauthenticated users. Otherwise, the
1869 1859 remote user must have been authenticated, and the authenticated
1870 1860 user name must be present in this list. The contents of the
1871 1861 allow_push list are examined after the deny_push list.
1872 1862
1873 1863 ``allow_read``
1874 1864 If the user has not already been denied repository access due to
1875 1865 the contents of deny_read, this list determines whether to grant
1876 1866 repository access to the user. If this list is not empty, and the
1877 1867 user is unauthenticated or not present in the list, then access is
1878 1868 denied for the user. If the list is empty or not set, then access
1879 1869 is permitted to all users by default. Setting allow_read to the
1880 1870 special value ``*`` is equivalent to it not being set (i.e. access
1881 1871 is permitted to all users). The contents of the allow_read list are
1882 1872 examined after the deny_read list.
1883 1873
1884 1874 ``allowzip``
1885 1875 (DEPRECATED) Whether to allow .zip downloading of repository
1886 1876 revisions. This feature creates temporary files.
1887 1877 (default: False)
1888 1878
1889 1879 ``archivesubrepos``
1890 1880 Whether to recurse into subrepositories when archiving.
1891 1881 (default: False)
1892 1882
1893 1883 ``baseurl``
1894 1884 Base URL to use when publishing URLs in other locations, so
1895 1885 third-party tools like email notification hooks can construct
1896 1886 URLs. Example: ``http://hgserver/repos/``.
1897 1887
1898 1888 ``cacerts``
1899 1889 Path to file containing a list of PEM encoded certificate
1900 1890 authority certificates. Environment variables and ``~user``
1901 1891 constructs are expanded in the filename. If specified on the
1902 1892 client, then it will verify the identity of remote HTTPS servers
1903 1893 with these certificates.
1904 1894
1905 1895 To disable SSL verification temporarily, specify ``--insecure`` from
1906 1896 command line.
1907 1897
1908 1898 You can use OpenSSL's CA certificate file if your platform has
1909 1899 one. On most Linux systems this will be
1910 1900 ``/etc/ssl/certs/ca-certificates.crt``. Otherwise you will have to
1911 1901 generate this file manually. The form must be as follows::
1912 1902
1913 1903 -----BEGIN CERTIFICATE-----
1914 1904 ... (certificate in base64 PEM encoding) ...
1915 1905 -----END CERTIFICATE-----
1916 1906 -----BEGIN CERTIFICATE-----
1917 1907 ... (certificate in base64 PEM encoding) ...
1918 1908 -----END CERTIFICATE-----
1919 1909
1920 1910 ``cache``
1921 1911 Whether to support caching in hgweb. (default: True)
1922 1912
1923 1913 ``certificate``
1924 1914 Certificate to use when running :hg:`serve`.
1925 1915
1926 1916 ``collapse``
1927 1917 With ``descend`` enabled, repositories in subdirectories are shown at
1928 1918 a single level alongside repositories in the current path. With
1929 1919 ``collapse`` also enabled, repositories residing at a deeper level than
1930 1920 the current path are grouped behind navigable directory entries that
1931 1921 lead to the locations of these repositories. In effect, this setting
1932 1922 collapses each collection of repositories found within a subdirectory
1933 1923 into a single entry for that subdirectory. (default: False)
1934 1924
1935 1925 ``comparisoncontext``
1936 1926 Number of lines of context to show in side-by-side file comparison. If
1937 1927 negative or the value ``full``, whole files are shown. (default: 5)
1938 1928
1939 1929 This setting can be overridden by a ``context`` request parameter to the
1940 1930 ``comparison`` command, taking the same values.
1941 1931
1942 1932 ``contact``
1943 1933 Name or email address of the person in charge of the repository.
1944 1934 (default: ui.username or ``$EMAIL`` or "unknown" if unset or empty)
1945 1935
1946 1936 ``deny_push``
1947 1937 Whether to deny pushing to the repository. If empty or not set,
1948 1938 push is not denied. If the special value ``*``, all remote users are
1949 1939 denied push. Otherwise, unauthenticated users are all denied, and
1950 1940 any authenticated user name present in this list is also denied. The
1951 1941 contents of the deny_push list are examined before the allow_push list.
1952 1942
1953 1943 ``deny_read``
1954 1944 Whether to deny reading/viewing of the repository. If this list is
1955 1945 not empty, unauthenticated users are all denied, and any
1956 1946 authenticated user name present in this list is also denied access to
1957 1947 the repository. If set to the special value ``*``, all remote users
1958 1948 are denied access (rarely needed ;). If deny_read is empty or not set,
1959 1949 the determination of repository access depends on the presence and
1960 1950 content of the allow_read list (see description). If both
1961 1951 deny_read and allow_read are empty or not set, then access is
1962 1952 permitted to all users by default. If the repository is being
1963 1953 served via hgwebdir, denied users will not be able to see it in
1964 1954 the list of repositories. The contents of the deny_read list have
1965 1955 priority over (are examined before) the contents of the allow_read
1966 1956 list.
1967 1957
1968 1958 ``descend``
1969 1959 hgwebdir indexes will not descend into subdirectories. Only repositories
1970 1960 directly in the current path will be shown (other repositories are still
1971 1961 available from the index corresponding to their containing path).
1972 1962
1973 1963 ``description``
1974 1964 Textual description of the repository's purpose or contents.
1975 1965 (default: "unknown")
1976 1966
1977 1967 ``encoding``
1978 1968 Character encoding name. (default: the current locale charset)
1979 1969 Example: "UTF-8".
1980 1970
1981 1971 ``errorlog``
1982 1972 Where to output the error log. (default: stderr)
1983 1973
1984 1974 ``guessmime``
1985 1975 Control MIME types for raw download of file content.
1986 1976 Set to True to let hgweb guess the content type from the file
1987 1977 extension. This will serve HTML files as ``text/html`` and might
1988 1978 allow cross-site scripting attacks when serving untrusted
1989 1979 repositories. (default: False)
1990 1980
1991 1981 ``hidden``
1992 1982 Whether to hide the repository in the hgwebdir index.
1993 1983 (default: False)
1994 1984
1995 1985 ``ipv6``
1996 1986 Whether to use IPv6. (default: False)
1997 1987
1998 1988 ``logoimg``
1999 1989 File name of the logo image that some templates display on each page.
2000 1990 The file name is relative to ``staticurl``. That is, the full path to
2001 1991 the logo image is "staticurl/logoimg".
2002 1992 If unset, ``hglogo.png`` will be used.
2003 1993
2004 1994 ``logourl``
2005 1995 Base URL to use for logos. If unset, ``https://mercurial-scm.org/``
2006 1996 will be used.
2007 1997
2008 1998 ``maxchanges``
2009 1999 Maximum number of changes to list on the changelog. (default: 10)
2010 2000
2011 2001 ``maxfiles``
2012 2002 Maximum number of files to list per changeset. (default: 10)
2013 2003
2014 2004 ``maxshortchanges``
2015 2005 Maximum number of changes to list on the shortlog, graph or filelog
2016 2006 pages. (default: 60)
2017 2007
2018 2008 ``name``
2019 2009 Repository name to use in the web interface.
2020 2010 (default: current working directory)
2021 2011
2022 2012 ``port``
2023 2013 Port to listen on. (default: 8000)
2024 2014
2025 2015 ``prefix``
2026 2016 Prefix path to serve from. (default: '' (server root))
2027 2017
2028 2018 ``push_ssl``
2029 2019 Whether to require that inbound pushes be transported over SSL to
2030 2020 prevent password sniffing. (default: True)
2031 2021
2032 2022 ``refreshinterval``
2033 2023 How frequently directory listings re-scan the filesystem for new
2034 2024 repositories, in seconds. This is relevant when wildcards are used
2035 2025 to define paths. Depending on how much filesystem traversal is
2036 2026 required, refreshing may negatively impact performance.
2037 2027
2038 2028 Values less than or equal to 0 always refresh.
2039 2029 (default: 20)
2040 2030
2041 2031 ``staticurl``
2042 2032 Base URL to use for static files. If unset, static files (e.g. the
2043 2033 hgicon.png favicon) will be served by the CGI script itself. Use
2044 2034 this setting to serve them directly with the HTTP server.
2045 2035 Example: ``http://hgserver/static/``.
2046 2036
2047 2037 ``stripes``
2048 2038 How many lines a "zebra stripe" should span in multi-line output.
2049 2039 Set to 0 to disable. (default: 1)
2050 2040
2051 2041 ``style``
2052 2042 Which template map style to use. The available options are the names of
2053 2043 subdirectories in the HTML templates path. (default: ``paper``)
2054 2044 Example: ``monoblue``.
2055 2045
2056 2046 ``templates``
2057 2047 Where to find the HTML templates. The default path to the HTML templates
2058 2048 can be obtained from ``hg debuginstall``.
2059 2049
2060 2050 ``websub``
2061 2051 ----------
2062 2052
2063 2053 Web substitution filter definition. You can use this section to
2064 2054 define a set of regular expression substitution patterns which
2065 2055 let you automatically modify the hgweb server output.
2066 2056
2067 2057 The default hgweb templates only apply these substitution patterns
2068 2058 on the revision description fields. You can apply them anywhere
2069 2059 you want when you create your own templates by adding calls to the
2070 2060 "websub" filter (usually after calling the "escape" filter).
2071 2061
2072 2062 This can be used, for example, to convert issue references to links
2073 2063 to your issue tracker, or to convert "markdown-like" syntax into
2074 2064 HTML (see the examples below).
2075 2065
2076 2066 Each entry in this section names a substitution filter.
2077 2067 The value of each entry defines the substitution expression itself.
2078 2068 The websub expressions follow the old interhg extension syntax,
2079 2069 which in turn imitates the Unix sed replacement syntax::
2080 2070
2081 2071 patternname = s/SEARCH_REGEX/REPLACE_EXPRESSION/[i]
2082 2072
2083 2073 You can use any separator other than "/". The final "i" is optional
2084 2074 and indicates that the search must be case insensitive.
2085 2075
2086 2076 Examples::
2087 2077
2088 2078 [websub]
2089 2079 issues = s|issue(\d+)|<a href="http://bts.example.org/issue\1">issue\1</a>|i
2090 2080 italic = s/\b_(\S+)_\b/<i>\1<\/i>/
2091 2081 bold = s/\*\b(\S+)\b\*/<b>\1<\/b>/
2092 2082
2093 2083 ``worker``
2094 2084 ----------
2095 2085
2096 2086 Parallel master/worker configuration. We currently perform working
2097 2087 directory updates in parallel on Unix-like systems, which greatly
2098 2088 helps performance.
2099 2089
2100 2090 ``numcpus``
2101 2091 Number of CPUs to use for parallel operations. A zero or
2102 2092 negative value is treated as ``use the default``.
2103 2093 (default: 4 or the number of CPUs on the system, whichever is larger)
2104 2094
2105 2095 ``backgroundclose``
2106 2096 Whether to enable closing file handles on background threads during certain
2107 2097 operations. Some platforms aren't very efficient at closing file
2108 2098 handles that have been written or appended to. By performing file closing
2109 2099 on background threads, file write rate can increase substantially.
2110 2100 (default: true on Windows, false elsewhere)
2111 2101
2112 2102 ``backgroundcloseminfilecount``
2113 2103 Minimum number of files required to trigger background file closing.
2114 2104 Operations not writing this many files won't start background close
2115 2105 threads.
2116 2106 (default: 2048)
2117 2107
2118 2108 ``backgroundclosemaxqueue``
2119 2109 The maximum number of opened file handles waiting to be closed in the
2120 2110 background. This option only has an effect if ``backgroundclose`` is
2121 2111 enabled.
2122 2112 (default: 384)
2123 2113
2124 2114 ``backgroundclosethreadcount``
2125 2115 Number of threads to process background file closes. Only relevant if
2126 2116 ``backgroundclose`` is enabled.
2127 2117 (default: 4)
@@ -1,353 +1,346 b''
1 1 # mail.py - mail sending bits for mercurial
2 2 #
3 3 # Copyright 2006 Matt Mackall <mpm@selenic.com>
4 4 #
5 5 # This software may be used and distributed according to the terms of the
6 6 # GNU General Public License version 2 or any later version.
7 7
8 8 from __future__ import absolute_import, print_function
9 9
10 10 import email
11 11 import os
12 12 import quopri
13 13 import smtplib
14 14 import socket
15 15 import sys
16 16 import time
17 17
18 18 from .i18n import _
19 19 from . import (
20 20 encoding,
21 21 error,
22 22 sslutil,
23 23 util,
24 24 )
25 25
26 26 _oldheaderinit = email.Header.Header.__init__
27 27 def _unifiedheaderinit(self, *args, **kw):
28 28 """
29 29 Python 2.7 introduces a backwards incompatible change
30 30 (Python issue1974, r70772) in email.Generator.Generator code:
31 31 pre-2.7 code passed "continuation_ws='\t'" to the Header
32 32 constructor, and 2.7 removed this parameter.
33 33
34 34 Default argument is continuation_ws=' ', which means that the
35 35 behavior is different in <2.7 and 2.7
36 36
37 37 We consider the 2.7 behavior to be preferable, but need
38 38 to have an unified behavior for versions 2.4 to 2.7
39 39 """
40 40 # override continuation_ws
41 41 kw['continuation_ws'] = ' '
42 42 _oldheaderinit(self, *args, **kw)
43 43
44 44 setattr(email.header.Header, '__init__', _unifiedheaderinit)
45 45
46 46 class STARTTLS(smtplib.SMTP):
47 47 '''Derived class to verify the peer certificate for STARTTLS.
48 48
49 49 This class allows to pass any keyword arguments to SSL socket creation.
50 50 '''
51 51 def __init__(self, ui, host=None, **kwargs):
52 52 smtplib.SMTP.__init__(self, **kwargs)
53 53 self._ui = ui
54 54 self._host = host
55 55
56 56 def starttls(self, keyfile=None, certfile=None):
57 57 if not self.has_extn("starttls"):
58 58 msg = "STARTTLS extension not supported by server"
59 59 raise smtplib.SMTPException(msg)
60 60 (resp, reply) = self.docmd("STARTTLS")
61 61 if resp == 220:
62 62 self.sock = sslutil.wrapsocket(self.sock, keyfile, certfile,
63 63 ui=self._ui,
64 64 serverhostname=self._host)
65 65 self.file = smtplib.SSLFakeFile(self.sock)
66 66 self.helo_resp = None
67 67 self.ehlo_resp = None
68 68 self.esmtp_features = {}
69 69 self.does_esmtp = 0
70 70 return (resp, reply)
71 71
72 72 class SMTPS(smtplib.SMTP):
73 73 '''Derived class to verify the peer certificate for SMTPS.
74 74
75 75 This class allows to pass any keyword arguments to SSL socket creation.
76 76 '''
77 77 def __init__(self, ui, keyfile=None, certfile=None, host=None,
78 78 **kwargs):
79 79 self.keyfile = keyfile
80 80 self.certfile = certfile
81 81 smtplib.SMTP.__init__(self, **kwargs)
82 82 self._host = host
83 83 self.default_port = smtplib.SMTP_SSL_PORT
84 84 self._ui = ui
85 85
86 86 def _get_socket(self, host, port, timeout):
87 87 if self.debuglevel > 0:
88 88 print('connect:', (host, port), file=sys.stderr)
89 89 new_socket = socket.create_connection((host, port), timeout)
90 90 new_socket = sslutil.wrapsocket(new_socket,
91 91 self.keyfile, self.certfile,
92 92 ui=self._ui,
93 93 serverhostname=self._host)
94 94 self.file = smtplib.SSLFakeFile(new_socket)
95 95 return new_socket
96 96
97 97 def _smtp(ui):
98 98 '''build an smtp connection and return a function to send mail'''
99 99 local_hostname = ui.config('smtp', 'local_hostname')
100 100 tls = ui.config('smtp', 'tls', 'none')
101 101 # backward compatible: when tls = true, we use starttls.
102 102 starttls = tls == 'starttls' or util.parsebool(tls)
103 103 smtps = tls == 'smtps'
104 104 if (starttls or smtps) and not util.safehasattr(socket, 'ssl'):
105 105 raise error.Abort(_("can't use TLS: Python SSL support not installed"))
106 106 mailhost = ui.config('smtp', 'host')
107 107 if not mailhost:
108 108 raise error.Abort(_('smtp.host not configured - cannot send mail'))
109 verifycert = ui.config('smtp', 'verifycert', 'strict')
110 if verifycert not in ['strict', 'loose']:
111 if util.parsebool(verifycert) is not False:
112 raise error.Abort(_('invalid smtp.verifycert configuration: %s')
113 % (verifycert))
114 verifycert = False
115
116 109 if smtps:
117 110 ui.note(_('(using smtps)\n'))
118 111 s = SMTPS(ui, local_hostname=local_hostname, host=mailhost)
119 112 elif starttls:
120 113 s = STARTTLS(ui, local_hostname=local_hostname, host=mailhost)
121 114 else:
122 115 s = smtplib.SMTP(local_hostname=local_hostname)
123 116 if smtps:
124 117 defaultport = 465
125 118 else:
126 119 defaultport = 25
127 120 mailport = util.getport(ui.config('smtp', 'port', defaultport))
128 121 ui.note(_('sending mail: smtp host %s, port %d\n') %
129 122 (mailhost, mailport))
130 123 s.connect(host=mailhost, port=mailport)
131 124 if starttls:
132 125 ui.note(_('(using starttls)\n'))
133 126 s.ehlo()
134 127 s.starttls()
135 128 s.ehlo()
136 if (starttls or smtps) and verifycert:
129 if starttls or smtps:
137 130 ui.note(_('(verifying remote certificate)\n'))
138 sslutil.validatesocket(s.sock, verifycert == 'strict')
131 sslutil.validatesocket(s.sock)
139 132 username = ui.config('smtp', 'username')
140 133 password = ui.config('smtp', 'password')
141 134 if username and not password:
142 135 password = ui.getpass()
143 136 if username and password:
144 137 ui.note(_('(authenticating to mail server as %s)\n') %
145 138 (username))
146 139 try:
147 140 s.login(username, password)
148 141 except smtplib.SMTPException as inst:
149 142 raise error.Abort(inst)
150 143
151 144 def send(sender, recipients, msg):
152 145 try:
153 146 return s.sendmail(sender, recipients, msg)
154 147 except smtplib.SMTPRecipientsRefused as inst:
155 148 recipients = [r[1] for r in inst.recipients.values()]
156 149 raise error.Abort('\n' + '\n'.join(recipients))
157 150 except smtplib.SMTPException as inst:
158 151 raise error.Abort(inst)
159 152
160 153 return send
161 154
162 155 def _sendmail(ui, sender, recipients, msg):
163 156 '''send mail using sendmail.'''
164 157 program = ui.config('email', 'method', 'smtp')
165 158 cmdline = '%s -f %s %s' % (program, util.email(sender),
166 159 ' '.join(map(util.email, recipients)))
167 160 ui.note(_('sending mail: %s\n') % cmdline)
168 161 fp = util.popen(cmdline, 'w')
169 162 fp.write(msg)
170 163 ret = fp.close()
171 164 if ret:
172 165 raise error.Abort('%s %s' % (
173 166 os.path.basename(program.split(None, 1)[0]),
174 167 util.explainexit(ret)[0]))
175 168
176 169 def _mbox(mbox, sender, recipients, msg):
177 170 '''write mails to mbox'''
178 171 fp = open(mbox, 'ab+')
179 172 # Should be time.asctime(), but Windows prints 2-characters day
180 173 # of month instead of one. Make them print the same thing.
181 174 date = time.strftime('%a %b %d %H:%M:%S %Y', time.localtime())
182 175 fp.write('From %s %s\n' % (sender, date))
183 176 fp.write(msg)
184 177 fp.write('\n\n')
185 178 fp.close()
186 179
187 180 def connect(ui, mbox=None):
188 181 '''make a mail connection. return a function to send mail.
189 182 call as sendmail(sender, list-of-recipients, msg).'''
190 183 if mbox:
191 184 open(mbox, 'wb').close()
192 185 return lambda s, r, m: _mbox(mbox, s, r, m)
193 186 if ui.config('email', 'method', 'smtp') == 'smtp':
194 187 return _smtp(ui)
195 188 return lambda s, r, m: _sendmail(ui, s, r, m)
196 189
197 190 def sendmail(ui, sender, recipients, msg, mbox=None):
198 191 send = connect(ui, mbox=mbox)
199 192 return send(sender, recipients, msg)
200 193
201 194 def validateconfig(ui):
202 195 '''determine if we have enough config data to try sending email.'''
203 196 method = ui.config('email', 'method', 'smtp')
204 197 if method == 'smtp':
205 198 if not ui.config('smtp', 'host'):
206 199 raise error.Abort(_('smtp specified as email transport, '
207 200 'but no smtp host configured'))
208 201 else:
209 202 if not util.findexe(method):
210 203 raise error.Abort(_('%r specified as email transport, '
211 204 'but not in PATH') % method)
212 205
213 206 def mimetextpatch(s, subtype='plain', display=False):
214 207 '''Return MIME message suitable for a patch.
215 208 Charset will be detected as utf-8 or (possibly fake) us-ascii.
216 209 Transfer encodings will be used if necessary.'''
217 210
218 211 cs = 'us-ascii'
219 212 if not display:
220 213 try:
221 214 s.decode('us-ascii')
222 215 except UnicodeDecodeError:
223 216 try:
224 217 s.decode('utf-8')
225 218 cs = 'utf-8'
226 219 except UnicodeDecodeError:
227 220 # We'll go with us-ascii as a fallback.
228 221 pass
229 222
230 223 return mimetextqp(s, subtype, cs)
231 224
232 225 def mimetextqp(body, subtype, charset):
233 226 '''Return MIME message.
234 227 Quoted-printable transfer encoding will be used if necessary.
235 228 '''
236 229 enc = None
237 230 for line in body.splitlines():
238 231 if len(line) > 950:
239 232 body = quopri.encodestring(body)
240 233 enc = "quoted-printable"
241 234 break
242 235
243 236 msg = email.MIMEText.MIMEText(body, subtype, charset)
244 237 if enc:
245 238 del msg['Content-Transfer-Encoding']
246 239 msg['Content-Transfer-Encoding'] = enc
247 240 return msg
248 241
249 242 def _charsets(ui):
250 243 '''Obtains charsets to send mail parts not containing patches.'''
251 244 charsets = [cs.lower() for cs in ui.configlist('email', 'charsets')]
252 245 fallbacks = [encoding.fallbackencoding.lower(),
253 246 encoding.encoding.lower(), 'utf-8']
254 247 for cs in fallbacks: # find unique charsets while keeping order
255 248 if cs not in charsets:
256 249 charsets.append(cs)
257 250 return [cs for cs in charsets if not cs.endswith('ascii')]
258 251
259 252 def _encode(ui, s, charsets):
260 253 '''Returns (converted) string, charset tuple.
261 254 Finds out best charset by cycling through sendcharsets in descending
262 255 order. Tries both encoding and fallbackencoding for input. Only as
263 256 last resort send as is in fake ascii.
264 257 Caveat: Do not use for mail parts containing patches!'''
265 258 try:
266 259 s.decode('ascii')
267 260 except UnicodeDecodeError:
268 261 sendcharsets = charsets or _charsets(ui)
269 262 for ics in (encoding.encoding, encoding.fallbackencoding):
270 263 try:
271 264 u = s.decode(ics)
272 265 except UnicodeDecodeError:
273 266 continue
274 267 for ocs in sendcharsets:
275 268 try:
276 269 return u.encode(ocs), ocs
277 270 except UnicodeEncodeError:
278 271 pass
279 272 except LookupError:
280 273 ui.warn(_('ignoring invalid sendcharset: %s\n') % ocs)
281 274 # if ascii, or all conversion attempts fail, send (broken) ascii
282 275 return s, 'us-ascii'
283 276
284 277 def headencode(ui, s, charsets=None, display=False):
285 278 '''Returns RFC-2047 compliant header from given string.'''
286 279 if not display:
287 280 # split into words?
288 281 s, cs = _encode(ui, s, charsets)
289 282 return str(email.Header.Header(s, cs))
290 283 return s
291 284
292 285 def _addressencode(ui, name, addr, charsets=None):
293 286 name = headencode(ui, name, charsets)
294 287 try:
295 288 acc, dom = addr.split('@')
296 289 acc = acc.encode('ascii')
297 290 dom = dom.decode(encoding.encoding).encode('idna')
298 291 addr = '%s@%s' % (acc, dom)
299 292 except UnicodeDecodeError:
300 293 raise error.Abort(_('invalid email address: %s') % addr)
301 294 except ValueError:
302 295 try:
303 296 # too strict?
304 297 addr = addr.encode('ascii')
305 298 except UnicodeDecodeError:
306 299 raise error.Abort(_('invalid local address: %s') % addr)
307 300 return email.Utils.formataddr((name, addr))
308 301
309 302 def addressencode(ui, address, charsets=None, display=False):
310 303 '''Turns address into RFC-2047 compliant header.'''
311 304 if display or not address:
312 305 return address or ''
313 306 name, addr = email.Utils.parseaddr(address)
314 307 return _addressencode(ui, name, addr, charsets)
315 308
316 309 def addrlistencode(ui, addrs, charsets=None, display=False):
317 310 '''Turns a list of addresses into a list of RFC-2047 compliant headers.
318 311 A single element of input list may contain multiple addresses, but output
319 312 always has one address per item'''
320 313 if display:
321 314 return [a.strip() for a in addrs if a.strip()]
322 315
323 316 result = []
324 317 for name, addr in email.Utils.getaddresses(addrs):
325 318 if name or addr:
326 319 result.append(_addressencode(ui, name, addr, charsets))
327 320 return result
328 321
329 322 def mimeencode(ui, s, charsets=None, display=False):
330 323 '''creates mime text object, encodes it if needed, and sets
331 324 charset and transfer-encoding accordingly.'''
332 325 cs = 'us-ascii'
333 326 if not display:
334 327 s, cs = _encode(ui, s, charsets)
335 328 return mimetextqp(s, 'plain', cs)
336 329
337 330 def headdecode(s):
338 331 '''Decodes RFC-2047 header'''
339 332 uparts = []
340 333 for part, charset in email.Header.decode_header(s):
341 334 if charset is not None:
342 335 try:
343 336 uparts.append(part.decode(charset))
344 337 continue
345 338 except UnicodeDecodeError:
346 339 pass
347 340 try:
348 341 uparts.append(part.decode('UTF-8'))
349 342 continue
350 343 except UnicodeDecodeError:
351 344 pass
352 345 uparts.append(part.decode('ISO-8859-1'))
353 346 return encoding.tolocal(u' '.join(uparts).encode('UTF-8'))
General Comments 0
You need to be logged in to leave comments. Login now