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

login
register
mail settings
Submitter Henning Schild
Date Nov. 12, 2016, 2:36 p.m.
Message ID <c3337dbf9c73502c4398.1478961413@localhost>
Download mbox | patch
Permalink /patch/17530/
State Accepted
Headers show

Comments

Henning Schild - Nov. 12, 2016, 2:36 p.m.
# HG changeset patch
# User Henning Schild <henning@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.
Yuya Nishihara - Nov. 16, 2016, 1:48 p.m.
On Sat, 12 Nov 2016 15:36:53 +0100, Henning Schild wrote:
> # HG changeset patch
> # User Henning Schild <henning@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.

I think it's okay to extend --git option to copy the behavior of git
format-patch as long as the generated patch can be imported by hg.

Can you add some tests?

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')