[PATCH 5 of 6] patchbomb: pass around ui and revs that are needed for flag template
Yuya Nishihara
yuya at tcha.org
Tue Mar 7 09:35:37 EST 2017
# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1488015334 -32400
# Sat Feb 25 18:35:34 2017 +0900
# Node ID 471a972c189c7afa01da72df70463717e57032fe
# Parent 619df871ab3248552a7ac982c3916a7632639acd
patchbomb: pass around ui and revs that are needed for flag template
See the next patch for why.
diff --git a/hgext/patchbomb.py b/hgext/patchbomb.py
--- a/hgext/patchbomb.py
+++ b/hgext/patchbomb.py
@@ -135,7 +135,7 @@ def introwanted(ui, opts, number):
intro = 1 < number
return intro
-def _formatprefix(flags, idx, total, numbered):
+def _formatprefix(ui, repo, rev, flags, idx, total, numbered):
"""build prefix to patch subject"""
flag = ' '.join(flags)
if flag:
@@ -147,7 +147,7 @@ def _formatprefix(flags, idx, total, num
tlen = len(str(total))
return '[PATCH %0*d of %d%s]' % (tlen, idx, total, flag)
-def makepatch(ui, repo, patchlines, opts, _charsets, idx, total, numbered,
+def makepatch(ui, repo, rev, patchlines, opts, _charsets, idx, total, numbered,
patchname=None):
desc = []
@@ -214,7 +214,8 @@ def makepatch(ui, repo, patchlines, opts
else:
msg = mail.mimetextpatch(body, display=opts.get('test'))
- prefix = _formatprefix(opts.get('flag'), idx, total, numbered)
+ prefix = _formatprefix(ui, repo, rev, opts.get('flag'), idx, total,
+ numbered)
subj = desc[0].strip().rstrip('. ')
if not numbered:
subj = ' '.join([prefix, opts.get('subject') or subj])
@@ -311,14 +312,16 @@ def _getbundlemsgs(repo, sender, bundle,
msg['Subject'] = mail.headencode(ui, subj, _charsets, opts.get('test'))
return [(msg, subj, None)]
-def _makeintro(repo, sender, patches, **opts):
+def _makeintro(repo, sender, revs, patches, **opts):
"""make an introduction email, asking the user for content if needed
email is returned as (subject, body, cumulative-diffstat)"""
ui = repo.ui
_charsets = mail._charsets(ui)
- prefix = _formatprefix(opts.get('flag'), 0, len(patches), numbered=True)
+ # use the last revision which is likely to be a bookmarked head
+ prefix = _formatprefix(ui, repo, revs.last(), opts.get('flag'),
+ 0, len(patches), numbered=True)
subj = (opts.get('subject') or
prompt(ui, '(optional) Subject: ', rest=prefix, default=''))
if not subj:
@@ -357,7 +360,7 @@ def _getpatchmsgs(repo, sender, revs, pa
# build the intro message, or skip it if the user declines
if introwanted(ui, opts, len(patches)):
- msg = _makeintro(repo, sender, patches, **opts)
+ msg = _makeintro(repo, sender, revs, patches, **opts)
if msg:
msgs.append(msg)
@@ -366,10 +369,11 @@ def _getpatchmsgs(repo, sender, revs, pa
# now generate the actual patch messages
name = None
- for i, p in enumerate(patches):
+ assert len(revs) == len(patches)
+ for i, (r, p) in enumerate(zip(revs, patches)):
if patchnames:
name = patchnames[i]
- msg = makepatch(ui, repo, p, opts, _charsets, i + 1,
+ msg = makepatch(ui, repo, r, p, opts, _charsets, i + 1,
len(patches), numbered, name)
msgs.append(msg)
More information about the Mercurial-devel
mailing list