[PATCH 4 of 7 🚿🍦] patchbomb: extract 'getdescription' closure in its own function
Pierre-Yves David
pierre-yves.david at ens-lyon.org
Thu Nov 6 15:46:23 UTC 2014
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at fb.com>
# Date 1415137295 0
# Tue Nov 04 21:41:35 2014 +0000
# Node ID 7a4add054e1090a3aa88464cf1ca54751b9d3e36
# Parent 13f98632a2921017b3e5983a0bec73aeeb79d328
patchbomb: extract 'getdescription' closure in its own function
Keep marching toward the promised land of simplification!
diff --git a/hgext/patchbomb.py b/hgext/patchbomb.py
--- a/hgext/patchbomb.py
+++ b/hgext/patchbomb.py
@@ -209,10 +209,30 @@ def _getbundle(repo, dest, **opts):
os.unlink(tmpfn)
except OSError:
pass
os.rmdir(tmpdir)
+def _getdescription(repo, defaultbody, sender, **opts):
+ """obtain the body of the introduction message and return it
+
+ This is also used for the body of email with an attached bundle.
+
+ The body can be obtained either from the command line option or entered by
+ the user through the editor.
+ """
+ ui = repo.ui
+ if opts.get('desc'):
+ body = open(opts.get('desc')).read()
+ else:
+ ui.write(_('\nWrite the introductory message for the '
+ 'patch series.\n\n'))
+ body = ui.edit(defaultbody, sender)
+ # Save series description in case sendmail fails
+ msgfile = repo.opener('last-email.txt', 'wb')
+ msgfile.write(body)
+ msgfile.close()
+ return body
emailopts = [
('', 'body', None, _('send patches as inline message text (default)')),
('a', 'attach', None, _('send patches as attachments')),
('i', 'inline', None, _('send patches as inline attachments')),
@@ -370,23 +390,10 @@ def patchbomb(ui, repo, *revs, **opts):
start_time = util.makedate()
def genmsgid(id):
return '<%s.%s@%s>' % (id[:20], int(start_time[0]), socket.getfqdn())
- def getdescription(body, sender):
- if opts.get('desc'):
- body = open(opts.get('desc')).read()
- else:
- ui.write(_('\nWrite the introductory message for the '
- 'patch series.\n\n'))
- body = ui.edit(body, sender)
- # Save series description in case sendmail fails
- msgfile = repo.opener('last-email.txt', 'wb')
- msgfile.write(body)
- msgfile.close()
- return body
-
def getpatchmsgs(patches, patchnames=None):
msgs = []
ui.write(_('this patch series consists of %d patches.\n\n')
% len(patches))
@@ -432,21 +439,21 @@ def patchbomb(ui, repo, *revs, **opts):
diffstat = patch.diffstat(sum(patches, []))
body = '\n' + diffstat
else:
diffstat = None
- body = getdescription(body, sender)
+ body = _getdescription(repo, body, sender, **opts)
msg = mail.mimeencode(ui, body, _charsets, opts.get('test'))
msg['Subject'] = mail.headencode(ui, subj, _charsets,
opts.get('test'))
return (msg, subj, diffstat)
def getbundlemsgs(bundle):
subj = (opts.get('subject')
or prompt(ui, 'Subject:', 'A bundle for your repository'))
- body = getdescription('', sender)
+ body = _getdescription(repo, '', sender, **opts)
msg = email.MIMEMultipart.MIMEMultipart()
if body:
msg.attach(mail.mimeencode(ui, body, _charsets, opts.get('test')))
datapart = email.MIMEBase.MIMEBase('application', 'x-mercurial-bundle')
datapart.set_payload(bundle)
More information about the Mercurial-devel
mailing list