[PATCH 1 of 5] patchbomb: make `hg email` reusable for other patch sources
Peter Arrenbrecht
peter.arrenbrecht at gmail.com
Thu Nov 6 12:40:22 UTC 2008
# HG changeset patch
# User Peter Arrenbrecht <peter.arrenbrecht at gmail.com>
# Date 1225962394 -3600
patchbomb: make `hg email` reusable for other patch sources
Adds two internal options, patches and patchnames, which allow
other extension to email a given set of patches. The pbranch
extension needs this to send its patches which are diffs between
topic branches.
Makes the option set that controls the actual emailing of the patches
available as patchbomb.emailopts.
diff --git a/hgext/patchbomb.py b/hgext/patchbomb.py
--- a/hgext/patchbomb.py
+++ b/hgext/patchbomb.py
@@ -146,7 +146,7 @@
s = ''
return s
- def makepatch(patch, idx, total):
+ def makepatch(patch, idx, total, patchname=None):
desc = []
node = None
body = ''
@@ -158,7 +158,7 @@
if line.startswith('diff -r') or line.startswith('diff --git'):
break
desc.append(line)
- if not node:
+ if not patchname and not node:
raise ValueError
if opts.get('attach'):
@@ -184,15 +184,16 @@
opts.get('test'))
binnode = bin(node)
# if node is mq patch, it will have patch file name as tag
- patchname = [t for t in repo.nodetags(binnode)
- if t.endswith('.patch') or t.endswith('.diff')]
- if patchname:
- patchname = patchname[0]
- elif total > 1:
- patchname = cmdutil.make_filename(repo, '%b-%n.patch',
- binnode, idx, total)
- else:
- patchname = cmdutil.make_filename(repo, '%b.patch', binnode)
+ if not patchname:
+ patchname = [t for t in repo.nodetags(binnode)
+ if t.endswith('.patch') or t.endswith('.diff')]
+ if patchname:
+ patchname = patchname[0]
+ elif total > 1:
+ patchname = cmdutil.make_filename(repo, '%b-%n.patch',
+ binnode, idx, total)
+ else:
+ patchname = cmdutil.make_filename(repo, '%b.patch', binnode)
disposition = 'inline'
if opts.get('attach'):
disposition = 'attachment'
@@ -243,7 +244,8 @@
mail.validateconfig(ui)
if not (revs or opts.get('rev')
- or opts.get('outgoing') or opts.get('bundle')):
+ or opts.get('outgoing') or opts.get('bundle')
+ or opts.get('patches')):
raise util.Abort(_('specify at least one changeset with -r or -o'))
cmdutil.setremoteconfig(ui, opts)
@@ -285,36 +287,19 @@
body = ui.edit(body, sender)
return body
- def getexportmsgs():
- patches = []
-
- class exportee:
- def __init__(self, container):
- self.lines = []
- self.container = container
- self.name = 'email'
-
- def write(self, data):
- self.lines.append(data)
-
- def close(self):
- self.container.append(''.join(self.lines).split('\n'))
- self.lines = []
-
- commands.export(ui, repo, *revs, **{'output': exportee(patches),
- 'switch_parent': False,
- 'text': None,
- 'git': opts.get('git')})
-
+ def getpatchmsgs(patches, patchnames=None):
jumbo = []
msgs = []
ui.write(_('This patch series consists of %d patches.\n\n')
% len(patches))
+ name = None
for p, i in zip(patches, xrange(len(patches))):
jumbo.extend(p)
- msgs.append(makepatch(p, i + 1, len(patches)))
+ if patchnames:
+ name = patchnames[i]
+ msgs.append(makepatch(p, i + 1, len(patches), name))
if len(patches) > 1:
tlen = len(str(len(patches)))
@@ -339,6 +324,28 @@
msgs.insert(0, (msg, subj))
return msgs
+ def getexportmsgs():
+
+ class exportee:
+ def __init__(self, container):
+ self.lines = []
+ self.container = container
+ self.name = 'email'
+
+ def write(self, data):
+ self.lines.append(data)
+
+ def close(self):
+ self.container.append(''.join(self.lines).split('\n'))
+ self.lines = []
+
+ patches = []
+ commands.export(ui, repo, *revs, **{'output': exportee(patches),
+ 'switch_parent': False,
+ 'text': None,
+ 'git': opts.get('git')})
+ return getpatchmsgs(patches)
+
def getbundlemsgs(bundle):
subj = (opts.get('subject')
or prompt('Subject:', default='A bundle for your repository'))
@@ -360,7 +367,10 @@
ui.config('patchbomb', 'from') or
prompt('From', ui.username()))
- if opts.get('bundle'):
+ patches = opts.get('patches')
+ if patches:
+ msgs = getpatchmsgs(patches, opts.get('patchnames'))
+ elif opts.get('bundle'):
msgs = getbundlemsgs(getbundle(dest))
else:
msgs = getexportmsgs()
@@ -441,34 +451,38 @@
generator.flatten(m, 0)
sendmail(sender, to + bcc + cc, fp.getvalue())
-cmdtable = {
- "email":
- (patchbomb,
- [('a', 'attach', None, _('send patches as attachments')),
+emailopts = [
+ ('a', 'attach', None, _('send patches as attachments')),
('i', 'inline', None, _('send patches as inline attachments')),
('', 'bcc', [], _('email addresses of blind copy recipients')),
('c', 'cc', [], _('email addresses of copy recipients')),
('d', 'diffstat', None, _('add diffstat output to messages')),
('', 'date', '', _('use the given date as the sending date')),
('', 'desc', '', _('use the given file as the series description')),
- ('g', 'git', None, _('use git extended diff format')),
('f', 'from', '', _('email address of sender')),
- ('', 'plain', None, _('omit hg patch header')),
('n', 'test', None, _('print messages that would be sent')),
('m', 'mbox', '',
_('write messages to mbox file instead of sending them')),
+ ('s', 'subject', '',
+ _('subject of first message (intro or single patch)')),
+ ('t', 'to', [], _('email addresses of recipients')),
+ ]
+
+
+cmdtable = {
+ "email":
+ (patchbomb,
+ [('g', 'git', None, _('use git extended diff format')),
+ ('', 'plain', None, _('omit hg patch header')),
('o', 'outgoing', None,
_('send changes not found in the target repository')),
('b', 'bundle', None,
_('send changes not in target as a binary bundle')),
('r', 'rev', [], _('a revision to send')),
- ('s', 'subject', '',
- _('subject of first message (intro or single patch)')),
- ('t', 'to', [], _('email addresses of recipients')),
('', 'force', None,
_('run even when remote repository is unrelated (with -b)')),
('', 'base', [],
_('a base changeset to specify instead of a destination (with -b)')),
- ] + commands.remoteopts,
+ ] + emailopts + commands.remoteopts,
_('hg email [OPTION]... [DEST]...'))
}
More information about the Mercurial-devel
mailing list