[PATCH 3 of 3] Signed-off-by: Hollis Blanchard <hollisb at us.ibm.com>
Hollis Blanchard
hollisb at us.ibm.com
Thu Nov 1 17:20:48 CDT 2007
Signed-off-by: Hollis Blanchard <hollisb at us.ibm.com>
---
This is the Linux patch format and scripts, and I believe there are import
scripts that expect this format. For other projects, moving the diffstat below
the description and adding an extraneous "---" shouldn't be a big deal...
1 file changed, 23 insertions(+), 11 deletions(-)
hgext/patchbomb.py | 34 +++++++++++++++++++++++-----------
diff --git a/hgext/patchbomb.py b/hgext/patchbomb.py
--- a/hgext/patchbomb.py
+++ b/hgext/patchbomb.py
@@ -145,28 +145,41 @@ def patchbomb(ui, repo, *revs, **opts):
def makepatch(patch, idx, total):
desc = []
+ markerseen = False
node = None
body = ''
- for line in patch:
+ i = 0
+ for i in xrange(len(patch)):
+ line = patch[i]
if line.startswith('#'):
if line.startswith('# Node ID'): node = line.split()[-1]
continue
if (line.startswith('diff -r')
or line.startswith('diff --git')):
break
- desc.append(line)
+ if line == '---':
+ markerseen = True
if not node: raise ValueError
- #body = ('\n'.join(desc[1:]).strip() or
- # 'Patch subject is complete summary.')
- #body += '\n\n\n'
+ desc_lines = patch[:i]
+ body_lines = patch[i:]
if (opts['plain'] or ui.config('email', 'plain')):
- while patch and patch[0].startswith('# '): patch.pop(0)
- if patch: patch.pop(0)
- while patch and not patch[0].strip(): patch.pop(0)
+ while desc_lines and desc_lines[0].startswith('# '):
+ desc_lines.pop(0)
+ if desc_lines:
+ desc_lines.pop(0)
+ while desc_lines and not desc_lines[0].strip():
+ desc_lines.pop(0)
+
if (opts['diffstat'] or ui.config('email', 'diffstat')):
- body += cdiffstat('\n'.join(desc), patch) + '\n\n'
+ diffstat = cdiffstat('\n'.join(desc_lines), patch) + '\n\n'
+ if not markerseen:
+ desc_lines.append('---')
+ desc_lines.append(diffstat)
+
+ body = '\n'.join(desc_lines) + '\n'.join(body_lines)
+
if opts['attach']:
msg = email.MIMEMultipart.MIMEMultipart()
if body: msg.attach(email.MIMEText.MIMEText(body, 'plain'))
@@ -185,10 +198,9 @@ def patchbomb(ui, repo, *revs, **opts):
p['Content-Disposition'] = 'inline; filename=' + patchname
msg.attach(p)
else:
- body += '\n'.join(patch)
msg = email.MIMEText.MIMEText(body)
- subj = desc[0].strip().rstrip('. ')
+ subj = desc_lines[0].strip().rstrip('. ')
if total == 1:
subj = '[PATCH] ' + (opts['subject'] or subj)
else:
More information about the Mercurial-devel
mailing list