[PATCH 2 of 2] patchbomb: put diffstat between commit message and patch for --git

Henning Schild henning at hennsch.de
Sat Nov 12 09:36:53 EST 2016


# HG changeset patch
# User Henning Schild <henning at hennsch.de>
# Date 1478958881 -3600
#      Sat Nov 12 14:54:41 2016 +0100
# Node ID c3337dbf9c73502c439819c62b5d49d377024857
# Parent  a2012c6555da7b6d3a4e70df26a04040adb58471
patchbomb: put diffstat between commit message and patch for --git

When sending patch mails to a git-based project the diffstat should be placed
right under the commit message. This patch makes hg email behave like git
format-patch.

diff --git a/hgext/patchbomb.py b/hgext/patchbomb.py
--- a/hgext/patchbomb.py
+++ b/hgext/patchbomb.py
@@ -140,8 +140,10 @@
     desc = []
     node = None
     body = ''
+    linenr = 0
 
     for line in patchlines:
+        linenr = linenr + 1
         if line.startswith('#'):
             if line.startswith('# Node ID'):
                 node = line.split()[-1]
@@ -150,6 +152,16 @@
             break
         desc.append(line)
 
+    ds = patch.diffstat(patchlines)
+    if opts.get('diffstat') and opts.get('git'):
+        linenr = linenr - 1
+        if (patchlines[linenr - 1] == ''):
+            linenr = linenr - 1
+            patchlines.pop(linenr)
+        patchlines.insert(linenr, '---')
+        linenr = linenr + 1
+        patchlines.insert(linenr, ds)
+
     if not patchname and not node:
         raise ValueError
 
@@ -166,8 +178,7 @@
         while patchlines and not patchlines[0].strip():
             patchlines.pop(0)
 
-    ds = patch.diffstat(patchlines)
-    if opts.get('diffstat'):
+    if opts.get('diffstat') and not opts.get('git'):
         body += ds + '\n\n'
 
     addattachment = opts.get('attach') or opts.get('inline')


More information about the Mercurial-devel mailing list