[PATCH 3 of 4] patchbomb: make `hg email` reusable for other patch sources
Peter Arrenbrecht
peter.arrenbrecht at gmail.com
Thu Nov 6 08:36:13 CST 2008
# HG changeset patch
# User Peter Arrenbrecht <peter.arrenbrecht at gmail.com>
# Date 1225981650 -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.
diff --git a/hgext/patchbomb.py b/hgext/patchbomb.py
--- a/hgext/patchbomb.py
+++ b/hgext/patchbomb.py
@@ -159,7 +159,7 @@
s = ''
return s
- def makepatch(patch, idx, total):
+ def makepatch(patch, idx, total, patchname=None):
desc = []
node = None
body = ''
@@ -171,7 +171,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'):
@@ -197,15 +197,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'
@@ -256,7 +257,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)
@@ -298,22 +300,19 @@
body = ui.edit(body, sender)
return body
- def getexportmsgs():
- patches = []
- 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)))
@@ -338,6 +337,14 @@
msgs.insert(0, (msg, subj))
return msgs
+ def getexportmsgs():
+ 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'))
@@ -359,7 +366,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()
More information about the Mercurial-devel
mailing list