##// END OF EJS Templates
patchbomb: make it easy for the user to decline sending an intro message....
Greg Ward -
r15164:7bddec63 default
parent child Browse files
Show More
@@ -57,24 +57,25 b' cmdtable = {}'
57 command = cmdutil.command(cmdtable)
57 command = cmdutil.command(cmdtable)
58
58
59 def prompt(ui, prompt, default=None, rest=':'):
59 def prompt(ui, prompt, default=None, rest=':'):
60 if not ui.interactive() and default is None:
60 if not ui.interactive():
61 raise util.Abort(_("%s Please enter a valid value" % (prompt + rest)))
61 return default
62 if default:
62 if default:
63 prompt += ' [%s]' % default
63 prompt += ' [%s]' % default
64 prompt += rest
64 prompt += rest
65 while True:
65 while True:
66 r = ui.prompt(prompt, default=default)
66 result = ui.prompt(prompt, default=default)
67 if r:
67 if result is not None:
68 return r
68 return result
69 if default is not None:
69 elif default is not None:
70 return default
70 return default
71 else:
71 ui.warn(_('Please enter a valid value.\n'))
72 ui.warn(_('Please enter a valid value.\n'))
72
73
73 def introneeded(opts, number):
74 def introwanted(opts, number):
74 '''is an introductory message required?'''
75 '''is an introductory message apparently wanted?'''
75 return number > 1 or opts.get('intro') or opts.get('desc')
76 return number > 1 or opts.get('intro') or opts.get('desc')
76
77
77 def makepatch(ui, repo, patchlines, opts, _charsets, idx, total,
78 def makepatch(ui, repo, patchlines, opts, _charsets, idx, total, numbered,
78 patchname=None):
79 patchname=None):
79
80
80 desc = []
81 desc = []
@@ -141,7 +142,7 b' def makepatch(ui, repo, patchlines, opts'
141 flag = ' ' + flag
142 flag = ' ' + flag
142
143
143 subj = desc[0].strip().rstrip('. ')
144 subj = desc[0].strip().rstrip('. ')
144 if not introneeded(opts, total):
145 if not numbered:
145 subj = '[PATCH%s] %s' % (flag, opts.get('subject') or subj)
146 subj = '[PATCH%s] %s' % (flag, opts.get('subject') or subj)
146 else:
147 else:
147 tlen = len(str(total))
148 tlen = len(str(total))
@@ -352,51 +353,66 b' def patchbomb(ui, repo, *revs, **opts):'
352 ui.write(_('\nWrite the introductory message for the '
353 ui.write(_('\nWrite the introductory message for the '
353 'patch series.\n\n'))
354 'patch series.\n\n'))
354 body = ui.edit(body, sender)
355 body = ui.edit(body, sender)
355 # Save serie description in case sendmail fails
356 # Save series description in case sendmail fails
356 msgfile = repo.opener('last-email.txt', 'wb')
357 msgfile = repo.opener('last-email.txt', 'wb')
357 msgfile.write(body)
358 msgfile.write(body)
358 msgfile.close()
359 msgfile.close()
359 return body
360 return body
360
361
361 def getpatchmsgs(patches, patchnames=None):
362 def getpatchmsgs(patches, patchnames=None):
362 jumbo = []
363 msgs = []
363 msgs = []
364
364
365 ui.write(_('This patch series consists of %d patches.\n\n')
365 ui.write(_('This patch series consists of %d patches.\n\n')
366 % len(patches))
366 % len(patches))
367
367
368 # build the intro message, or skip it if the user declines
369 if introwanted(opts, len(patches)):
370 msg = makeintro(patches)
371 if msg:
372 msgs.append(msg)
373
374 # are we going to send more than one message?
375 numbered = len(msgs) + len(patches) > 1
376
377 # now generate the actual patch messages
368 name = None
378 name = None
369 for i, p in enumerate(patches):
379 for i, p in enumerate(patches):
370 jumbo.extend(p)
371 if patchnames:
380 if patchnames:
372 name = patchnames[i]
381 name = patchnames[i]
373 msg = makepatch(ui, repo, p, opts, _charsets, i + 1,
382 msg = makepatch(ui, repo, p, opts, _charsets, i + 1,
374 len(patches), name)
383 len(patches), numbered, name)
375 msgs.append(msg)
384 msgs.append(msg)
376
385
377 if introneeded(opts, len(patches)):
386 return msgs
387
388 def makeintro(patches):
378 tlen = len(str(len(patches)))
389 tlen = len(str(len(patches)))
379
390
380 flag = ' '.join(opts.get('flag'))
391 flag = opts.get('flag') or ''
381 if flag:
392 if flag:
382 subj = '[PATCH %0*d of %d %s]' % (tlen, 0, len(patches), flag)
393 flag = ' ' + ' '.join(flag)
383 else:
394 prefix = '[PATCH %0*d of %d%s]' % (tlen, 0, len(patches), flag)
384 subj = '[PATCH %0*d of %d]' % (tlen, 0, len(patches))
395
385 subj += ' ' + (opts.get('subject') or
396 subj = (opts.get('subject') or
386 prompt(ui, 'Subject: ', rest=subj))
397 prompt(ui, 'Subject: ', rest=prefix, default=''))
398 if not subj:
399 return None # skip intro if the user doesn't bother
400
401 subj = prefix + ' ' + subj
387
402
388 body = ''
403 body = ''
389 ds = patch.diffstat(jumbo)
404 if opts.get('diffstat'):
390 if ds and opts.get('diffstat'):
405 # generate a cumulative diffstat of the whole patch series
391 body = '\n' + ds
406 diffstat = patch.diffstat(sum(patches, []))
407 body = '\n' + diffstat
408 else:
409 diffstat = None
392
410
393 body = getdescription(body, sender)
411 body = getdescription(body, sender)
394 msg = mail.mimeencode(ui, body, _charsets, opts.get('test'))
412 msg = mail.mimeencode(ui, body, _charsets, opts.get('test'))
395 msg['Subject'] = mail.headencode(ui, subj, _charsets,
413 msg['Subject'] = mail.headencode(ui, subj, _charsets,
396 opts.get('test'))
414 opts.get('test'))
397
415 return (msg, subj, diffstat)
398 msgs.insert(0, (msg, subj, ds))
399 return msgs
400
416
401 def getbundlemsgs(bundle):
417 def getbundlemsgs(bundle):
402 subj = (opts.get('subject')
418 subj = (opts.get('subject')
@@ -442,14 +458,19 b' def patchbomb(ui, repo, *revs, **opts):'
442 ui.config('patchbomb', configkey) or
458 ui.config('patchbomb', configkey) or
443 '')
459 '')
444 if not addr and ask:
460 if not addr and ask:
445 addr = prompt(ui, header, default)
461 addr = prompt(ui, header, default=default)
446 if addr:
462 if addr:
447 showaddrs.append('%s: %s' % (header, addr))
463 showaddrs.append('%s: %s' % (header, addr))
448 return mail.addrlistencode(ui, [addr], _charsets, opts.get('test'))
464 return mail.addrlistencode(ui, [addr], _charsets, opts.get('test'))
465 else:
466 return default
449
467
450 to = getaddrs('To', ask=True)
468 to = getaddrs('To', ask=True)
451 cc = getaddrs('Cc', ask=True, default='')
469 if not to:
452 bcc = getaddrs('Bcc')
470 # we can get here in non-interactive mode
471 raise util.Abort(_('no recipient addresses provided'))
472 cc = getaddrs('Cc', ask=True, default='') or []
473 bcc = getaddrs('Bcc') or []
453 replyto = getaddrs('Reply-To')
474 replyto = getaddrs('Reply-To')
454
475
455 if opts.get('diffstat') or opts.get('confirm'):
476 if opts.get('diffstat') or opts.get('confirm'):
@@ -1469,13 +1469,70 b' test inreplyto:'
1469 +ff2c9fa2018b15fa74b33363bda9527323e2a99f two
1469 +ff2c9fa2018b15fa74b33363bda9527323e2a99f two
1470 +ff2c9fa2018b15fa74b33363bda9527323e2a99f two.diff
1470 +ff2c9fa2018b15fa74b33363bda9527323e2a99f two.diff
1471
1471
1472
1472 no intro message in non-interactive mode
1473 $ hg email --date '1970-1-1 0:1' -n -f quux -t foo -c bar --in-reply-to baz \
1473 $ hg email --date '1970-1-1 0:1' -n -f quux -t foo -c bar --in-reply-to baz \
1474 > -r 0:1
1474 > -r 0:1 | fixheaders
1475 This patch series consists of 2 patches.
1475 This patch series consists of 2 patches.
1476
1476
1477 abort: Subject: [PATCH 0 of 2] Please enter a valid value
1477
1478 [255]
1478 Displaying [PATCH 1 of 2] a ...
1479 Content-Type: text/plain; charset="us-ascii"
1480 MIME-Version: 1.0
1481 Content-Transfer-Encoding: 7bit
1482 Subject: [PATCH 1 of 2] a
1483 X-Mercurial-Node: 8580ff50825a50c8f716709acdf8de0deddcd6ab
1484 Message-Id: <8580ff50825a50c8f716.60@
1485 In-Reply-To: <baz>
1486 References: <baz>
1487 User-Agent: Mercurial-patchbomb
1488 Date: Thu, 01 Jan 1970 00:01:00 +0000
1489 From: quux
1490 To: foo
1491 Cc: bar
1492
1493 # HG changeset patch
1494 # User test
1495 # Date 1 0
1496 # Node ID 8580ff50825a50c8f716709acdf8de0deddcd6ab
1497 # Parent 0000000000000000000000000000000000000000
1498 a
1499
1500 diff -r 000000000000 -r 8580ff50825a a
1501 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1502 +++ b/a Thu Jan 01 00:00:01 1970 +0000
1503 @@ -0,0 +1,1 @@
1504 +a
1505
1506 Displaying [PATCH 2 of 2] b ...
1507 Content-Type: text/plain; charset="us-ascii"
1508 MIME-Version: 1.0
1509 Content-Transfer-Encoding: 7bit
1510 Subject: [PATCH 2 of 2] b
1511 X-Mercurial-Node: 97d72e5f12c7e84f85064aa72e5a297142c36ed9
1512 Message-Id: <97d72e5f12c7e84f8506.61@
1513 In-Reply-To: <8580ff50825a50c8f716.60@
1514 References: <8580ff50825a50c8f716.60@
1515 User-Agent: Mercurial-patchbomb
1516 Date: Thu, 01 Jan 1970 00:01:01 +0000
1517 From: quux
1518 To: foo
1519 Cc: bar
1520
1521 # HG changeset patch
1522 # User test
1523 # Date 2 0
1524 # Node ID 97d72e5f12c7e84f85064aa72e5a297142c36ed9
1525 # Parent 8580ff50825a50c8f716709acdf8de0deddcd6ab
1526 b
1527
1528 diff -r 8580ff50825a -r 97d72e5f12c7 b
1529 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1530 +++ b/b Thu Jan 01 00:00:02 1970 +0000
1531 @@ -0,0 +1,1 @@
1532 +b
1533
1534
1535
1479
1536
1480 $ hg email --date '1970-1-1 0:1' -n -f quux -t foo -c bar --in-reply-to baz \
1537 $ hg email --date '1970-1-1 0:1' -n -f quux -t foo -c bar --in-reply-to baz \
1481 > -s test -r 0:1 | fixheaders
1538 > -s test -r 0:1 | fixheaders
@@ -1826,7 +1883,6 b' test multi-byte domain parsing:'
1826 $ hg email --date '1980-1-1 0:1' -m tmp.mbox -f quux -t "bar@${UUML}nicode.com" -s test -r 0
1883 $ hg email --date '1980-1-1 0:1' -m tmp.mbox -f quux -t "bar@${UUML}nicode.com" -s test -r 0
1827 This patch series consists of 1 patches.
1884 This patch series consists of 1 patches.
1828
1885
1829 Cc:
1830
1886
1831 Writing [PATCH] test ...
1887 Writing [PATCH] test ...
1832
1888
@@ -1871,13 +1927,11 b' test outgoing:'
1871 $ hg email --date '1980-1-1 0:1' -n -t foo -s test -o ../t
1927 $ hg email --date '1980-1-1 0:1' -n -t foo -s test -o ../t
1872 comparing with ../t
1928 comparing with ../t
1873 searching for changes
1929 searching for changes
1874 From [test]: test
1875 This patch series consists of 8 patches.
1930 This patch series consists of 8 patches.
1876
1931
1877
1932
1878 Write the introductory message for the patch series.
1933 Write the introductory message for the patch series.
1879
1934
1880 Cc:
1881
1935
1882 Displaying [PATCH 0 of 8] test ...
1936 Displaying [PATCH 0 of 8] test ...
1883 Content-Type: text/plain; charset="us-ascii"
1937 Content-Type: text/plain; charset="us-ascii"
@@ -2145,10 +2199,8 b' dest#branch URIs:'
2145 $ hg email --date '1980-1-1 0:1' -n -t foo -s test -o ../t#test
2199 $ hg email --date '1980-1-1 0:1' -n -t foo -s test -o ../t#test
2146 comparing with ../t
2200 comparing with ../t
2147 searching for changes
2201 searching for changes
2148 From [test]: test
2149 This patch series consists of 1 patches.
2202 This patch series consists of 1 patches.
2150
2203
2151 Cc:
2152
2204
2153 Displaying [PATCH] test ...
2205 Displaying [PATCH] test ...
2154 Content-Type: text/plain; charset="us-ascii"
2206 Content-Type: text/plain; charset="us-ascii"
General Comments 0
You need to be logged in to leave comments. Login now