[PATCH 3 of 3] Patchbomb: Insert a "---" marker between description and diffstat

Hollis Blanchard hollisb at us.ibm.com
Thu Nov 1 23:03:13 UTC 2007


# HG changeset patch
# User Hollis Blanchard <hollisb at us.ibm.com>
# Date 1193958009 18000
# Node ID 4590ec064966938d37d74bed2730b93566e37461
# Parent  59b6acb184bbdb5985922aa5143815e03a13aa42

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...

Changes from v1: fix subject parsing.

1 file changed, 25 insertions(+), 11 deletions(-)
hgext/patchbomb.py |   36 +++++++++++++++++++++++++-----------


diff --git a/hgext/patchbomb.py b/hgext/patchbomb.py
--- a/hgext/patchbomb.py
+++ b/hgext/patchbomb.py
@@ -145,28 +145,44 @@ def patchbomb(ui, repo, *revs, **opts):
 
     def makepatch(patch, idx, total):
         desc = []
+        markerseen = False
         node = None
         body = ''
-        for line in patch:
+        subj = None
+        for i in xrange(len(patch)):
+            line = patch[i]
             if line.startswith('#'):
                 if line.startswith('# Node ID'): node = line.split()[-1]
+                continue
+            elif not subj:
+                subj = line.strip().rstrip('. ')
+                del patch[i]
                 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]
+        print desc_lines
+        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)
+            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 +201,8 @@ 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('. ')
         if total == 1:
             subj = '[PATCH] ' + (opts['subject'] or subj)
         else:



More information about the Mercurial-devel mailing list