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

login
register
mail settings
Submitter Henning Schild
Date Nov. 16, 2016, 8:32 p.m.
Message ID <6fb9da0f0542d1006277.1479328368@localhost>
Download mbox | patch
Permalink /patch/17608/
State Accepted
Headers show

Comments

Henning Schild - Nov. 16, 2016, 8:32 p.m.
# HG changeset patch
# User Henning Schild <henning@hennsch.de>
# Date 1478958881 -3600
#      Sat Nov 12 14:54:41 2016 +0100
# Node ID 6fb9da0f0542d10062770e3dce722b6a89f8c7bb
# Parent  9713d11a26da1462629eac6f2d7d76b8b31e6a5f
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.
Henning Schild - Nov. 16, 2016, 8:36 p.m.
I got confused, no issue with --plain. Still sent v3 with these two
changes to v2
- change line wrap in testcase
- switch to += -= operators

Henning

Am Wed, 16 Nov 2016 21:32:48 +0100
schrieb Henning Schild <henning@hennsch.de>:

> # HG changeset patch
> # User Henning Schild <henning@hennsch.de>
> # Date 1478958881 -3600
> #      Sat Nov 12 14:54:41 2016 +0100
> # Node ID 6fb9da0f0542d10062770e3dce722b6a89f8c7bb
> # Parent  9713d11a26da1462629eac6f2d7d76b8b31e6a5f
> 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 += 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 -= 1
> +        if (patchlines[linenr - 1] == ''):
> +            linenr -= 1
> +            patchlines.pop(linenr)
> +        patchlines.insert(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')
> diff --git a/tests/test-patchbomb.t b/tests/test-patchbomb.t
> --- a/tests/test-patchbomb.t
> +++ b/tests/test-patchbomb.t
> @@ -722,6 +722,58 @@
>    +c
>    
>  
> +test diffstat for single patch for git:
> +  $ hg email --git --date '1970-1-1 0:1' -n -f quux -t foo -c bar -s
> test -d \
> +  >  -y -r 2
> +  this patch series consists of 1 patches.
> +  
> +  
> +  Final summary:
> +  
> +  From: quux
> +  To: foo
> +  Cc: bar
> +  Subject: [PATCH] test
> +   c |  1 +
> +   1 files changed, 1 insertions(+), 0 deletions(-)
> +  
> +  are you sure you want to send (yn)? y
> +  
> +  displaying [PATCH] test ...
> +  Content-Type: text/plain; charset="us-ascii"
> +  MIME-Version: 1.0
> +  Content-Transfer-Encoding: 7bit
> +  Subject: [PATCH] test
> +  X-Mercurial-Node: ff2c9fa2018b15fa74b33363bda9527323e2a99f
> +  X-Mercurial-Series-Index: 1
> +  X-Mercurial-Series-Total: 1
> +  Message-Id: <ff2c9fa2018b15fa74b3.60@*> (glob)
> +  X-Mercurial-Series-Id: <ff2c9fa2018b15fa74b3.60@*> (glob)
> +  User-Agent: Mercurial-patchbomb/* (glob)
> +  Date: Thu, 01 Jan 1970 00:01:00 +0000
> +  From: quux
> +  To: foo
> +  Cc: bar
> +  
> +  # HG changeset patch
> +  # User test
> +  # Date 3 0
> +  #      Thu Jan 01 00:00:03 1970 +0000
> +  # Node ID ff2c9fa2018b15fa74b33363bda9527323e2a99f
> +  # Parent  97d72e5f12c7e84f85064aa72e5a297142c36ed9
> +  c
> +  ---
> +   c |  1 +
> +   1 files changed, 1 insertions(+), 0 deletions(-)
> +  
> +  diff --git a/c b/c
> +  new file mode 100644
> +  --- /dev/null
> +  +++ b/c
> +  @@ -0,0 +1,1 @@
> +  +c
> +  
> +
>  test diffstat for multiple patches:
>    $ hg email --date '1970-1-1 0:1' -n -f quux -t foo -c bar -s test
> -d -y \
>    >  -r 0:1  
> @@ -839,6 +891,123 @@
>    +b
>    
>  
> +test diffstat for multiple patches for git:
> +  $ hg email --git --date '1970-1-1 0:1' -n -f quux -t foo -c bar -s
> test -d \
> +  >  -y -r 0:1
> +  this patch series consists of 2 patches.
> +  
> +  
> +  Write the introductory message for the patch series.
> +  
> +  
> +  Final summary:
> +  
> +  From: quux
> +  To: foo
> +  Cc: bar
> +  Subject: [PATCH 0 of 2] test
> +   a |  1 +
> +   b |  1 +
> +   2 files changed, 2 insertions(+), 0 deletions(-)
> +  Subject: [PATCH 1 of 2] a
> +   a |  1 +
> +   1 files changed, 1 insertions(+), 0 deletions(-)
> +  Subject: [PATCH 2 of 2] b
> +   b |  1 +
> +   1 files changed, 1 insertions(+), 0 deletions(-)
> +  
> +  are you sure you want to send (yn)? y
> +  
> +  displaying [PATCH 0 of 2] test ...
> +  Content-Type: text/plain; charset="us-ascii"
> +  MIME-Version: 1.0
> +  Content-Transfer-Encoding: 7bit
> +  Subject: [PATCH 0 of 2] test
> +  Message-Id: <patchbomb.60@*> (glob)
> +  User-Agent: Mercurial-patchbomb/* (glob)
> +  Date: Thu, 01 Jan 1970 00:01:00 +0000
> +  From: quux
> +  To: foo
> +  Cc: bar
> +  
> +  
> +   a |  1 +
> +   b |  1 +
> +   2 files changed, 2 insertions(+), 0 deletions(-)
> +  
> +  displaying [PATCH 1 of 2] a ...
> +  Content-Type: text/plain; charset="us-ascii"
> +  MIME-Version: 1.0
> +  Content-Transfer-Encoding: 7bit
> +  Subject: [PATCH 1 of 2] a
> +  X-Mercurial-Node: 8580ff50825a50c8f716709acdf8de0deddcd6ab
> +  X-Mercurial-Series-Index: 1
> +  X-Mercurial-Series-Total: 2
> +  Message-Id: <8580ff50825a50c8f716.61@*> (glob)
> +  X-Mercurial-Series-Id: <8580ff50825a50c8f716.61@*> (glob)
> +  In-Reply-To: <patchbomb.60@*> (glob)
> +  References: <patchbomb.60@*> (glob)
> +  User-Agent: Mercurial-patchbomb/* (glob)
> +  Date: Thu, 01 Jan 1970 00:01:01 +0000
> +  From: quux
> +  To: foo
> +  Cc: bar
> +  
> +  # HG changeset patch
> +  # User test
> +  # Date 1 0
> +  #      Thu Jan 01 00:00:01 1970 +0000
> +  # Node ID 8580ff50825a50c8f716709acdf8de0deddcd6ab
> +  # Parent  0000000000000000000000000000000000000000
> +  a
> +  ---
> +   a |  1 +
> +   1 files changed, 1 insertions(+), 0 deletions(-)
> +  
> +  diff --git a/a b/a
> +  new file mode 100644
> +  --- /dev/null
> +  +++ b/a
> +  @@ -0,0 +1,1 @@
> +  +a
> +  
> +  displaying [PATCH 2 of 2] b ...
> +  Content-Type: text/plain; charset="us-ascii"
> +  MIME-Version: 1.0
> +  Content-Transfer-Encoding: 7bit
> +  Subject: [PATCH 2 of 2] b
> +  X-Mercurial-Node: 97d72e5f12c7e84f85064aa72e5a297142c36ed9
> +  X-Mercurial-Series-Index: 2
> +  X-Mercurial-Series-Total: 2
> +  Message-Id: <97d72e5f12c7e84f8506.62@*> (glob)
> +  X-Mercurial-Series-Id: <8580ff50825a50c8f716.61@*> (glob)
> +  In-Reply-To: <patchbomb.60@*> (glob)
> +  References: <patchbomb.60@*> (glob)
> +  User-Agent: Mercurial-patchbomb/* (glob)
> +  Date: Thu, 01 Jan 1970 00:01:02 +0000
> +  From: quux
> +  To: foo
> +  Cc: bar
> +  
> +  # HG changeset patch
> +  # User test
> +  # Date 2 0
> +  #      Thu Jan 01 00:00:02 1970 +0000
> +  # Node ID 97d72e5f12c7e84f85064aa72e5a297142c36ed9
> +  # Parent  8580ff50825a50c8f716709acdf8de0deddcd6ab
> +  b
> +  ---
> +   b |  1 +
> +   1 files changed, 1 insertions(+), 0 deletions(-)
> +  
> +  diff --git a/b b/b
> +  new file mode 100644
> +  --- /dev/null
> +  +++ b/b
> +  @@ -0,0 +1,1 @@
> +  +b
> +  
> +
>  test inline for single patch:
>    $ hg email --date '1970-1-1 0:1' -n -f quux -t foo -c bar -s test
> -i -r 2 | $FILTERBOUNDARY this patch series consists of 1 patches.
>

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 += 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 -= 1
+        if (patchlines[linenr - 1] == ''):
+            linenr -= 1
+            patchlines.pop(linenr)
+        patchlines.insert(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')
diff --git a/tests/test-patchbomb.t b/tests/test-patchbomb.t
--- a/tests/test-patchbomb.t
+++ b/tests/test-patchbomb.t
@@ -722,6 +722,58 @@ 
   +c
   
 
+test diffstat for single patch for git:
+  $ hg email --git --date '1970-1-1 0:1' -n -f quux -t foo -c bar -s test -d \
+  >  -y -r 2
+  this patch series consists of 1 patches.
+  
+  
+  Final summary:
+  
+  From: quux
+  To: foo
+  Cc: bar
+  Subject: [PATCH] test
+   c |  1 +
+   1 files changed, 1 insertions(+), 0 deletions(-)
+  
+  are you sure you want to send (yn)? y
+  
+  displaying [PATCH] test ...
+  Content-Type: text/plain; charset="us-ascii"
+  MIME-Version: 1.0
+  Content-Transfer-Encoding: 7bit
+  Subject: [PATCH] test
+  X-Mercurial-Node: ff2c9fa2018b15fa74b33363bda9527323e2a99f
+  X-Mercurial-Series-Index: 1
+  X-Mercurial-Series-Total: 1
+  Message-Id: <ff2c9fa2018b15fa74b3.60@*> (glob)
+  X-Mercurial-Series-Id: <ff2c9fa2018b15fa74b3.60@*> (glob)
+  User-Agent: Mercurial-patchbomb/* (glob)
+  Date: Thu, 01 Jan 1970 00:01:00 +0000
+  From: quux
+  To: foo
+  Cc: bar
+  
+  # HG changeset patch
+  # User test
+  # Date 3 0
+  #      Thu Jan 01 00:00:03 1970 +0000
+  # Node ID ff2c9fa2018b15fa74b33363bda9527323e2a99f
+  # Parent  97d72e5f12c7e84f85064aa72e5a297142c36ed9
+  c
+  ---
+   c |  1 +
+   1 files changed, 1 insertions(+), 0 deletions(-)
+  
+  diff --git a/c b/c
+  new file mode 100644
+  --- /dev/null
+  +++ b/c
+  @@ -0,0 +1,1 @@
+  +c
+  
+
 test diffstat for multiple patches:
   $ hg email --date '1970-1-1 0:1' -n -f quux -t foo -c bar -s test -d -y \
   >  -r 0:1
@@ -839,6 +891,123 @@ 
   +b
   
 
+test diffstat for multiple patches for git:
+  $ hg email --git --date '1970-1-1 0:1' -n -f quux -t foo -c bar -s test -d \
+  >  -y -r 0:1
+  this patch series consists of 2 patches.
+  
+  
+  Write the introductory message for the patch series.
+  
+  
+  Final summary:
+  
+  From: quux
+  To: foo
+  Cc: bar
+  Subject: [PATCH 0 of 2] test
+   a |  1 +
+   b |  1 +
+   2 files changed, 2 insertions(+), 0 deletions(-)
+  Subject: [PATCH 1 of 2] a
+   a |  1 +
+   1 files changed, 1 insertions(+), 0 deletions(-)
+  Subject: [PATCH 2 of 2] b
+   b |  1 +
+   1 files changed, 1 insertions(+), 0 deletions(-)
+  
+  are you sure you want to send (yn)? y
+  
+  displaying [PATCH 0 of 2] test ...
+  Content-Type: text/plain; charset="us-ascii"
+  MIME-Version: 1.0
+  Content-Transfer-Encoding: 7bit
+  Subject: [PATCH 0 of 2] test
+  Message-Id: <patchbomb.60@*> (glob)
+  User-Agent: Mercurial-patchbomb/* (glob)
+  Date: Thu, 01 Jan 1970 00:01:00 +0000
+  From: quux
+  To: foo
+  Cc: bar
+  
+  
+   a |  1 +
+   b |  1 +
+   2 files changed, 2 insertions(+), 0 deletions(-)
+  
+  displaying [PATCH 1 of 2] a ...
+  Content-Type: text/plain; charset="us-ascii"
+  MIME-Version: 1.0
+  Content-Transfer-Encoding: 7bit
+  Subject: [PATCH 1 of 2] a
+  X-Mercurial-Node: 8580ff50825a50c8f716709acdf8de0deddcd6ab
+  X-Mercurial-Series-Index: 1
+  X-Mercurial-Series-Total: 2
+  Message-Id: <8580ff50825a50c8f716.61@*> (glob)
+  X-Mercurial-Series-Id: <8580ff50825a50c8f716.61@*> (glob)
+  In-Reply-To: <patchbomb.60@*> (glob)
+  References: <patchbomb.60@*> (glob)
+  User-Agent: Mercurial-patchbomb/* (glob)
+  Date: Thu, 01 Jan 1970 00:01:01 +0000
+  From: quux
+  To: foo
+  Cc: bar
+  
+  # HG changeset patch
+  # User test
+  # Date 1 0
+  #      Thu Jan 01 00:00:01 1970 +0000
+  # Node ID 8580ff50825a50c8f716709acdf8de0deddcd6ab
+  # Parent  0000000000000000000000000000000000000000
+  a
+  ---
+   a |  1 +
+   1 files changed, 1 insertions(+), 0 deletions(-)
+  
+  diff --git a/a b/a
+  new file mode 100644
+  --- /dev/null
+  +++ b/a
+  @@ -0,0 +1,1 @@
+  +a
+  
+  displaying [PATCH 2 of 2] b ...
+  Content-Type: text/plain; charset="us-ascii"
+  MIME-Version: 1.0
+  Content-Transfer-Encoding: 7bit
+  Subject: [PATCH 2 of 2] b
+  X-Mercurial-Node: 97d72e5f12c7e84f85064aa72e5a297142c36ed9
+  X-Mercurial-Series-Index: 2
+  X-Mercurial-Series-Total: 2
+  Message-Id: <97d72e5f12c7e84f8506.62@*> (glob)
+  X-Mercurial-Series-Id: <8580ff50825a50c8f716.61@*> (glob)
+  In-Reply-To: <patchbomb.60@*> (glob)
+  References: <patchbomb.60@*> (glob)
+  User-Agent: Mercurial-patchbomb/* (glob)
+  Date: Thu, 01 Jan 1970 00:01:02 +0000
+  From: quux
+  To: foo
+  Cc: bar
+  
+  # HG changeset patch
+  # User test
+  # Date 2 0
+  #      Thu Jan 01 00:00:02 1970 +0000
+  # Node ID 97d72e5f12c7e84f85064aa72e5a297142c36ed9
+  # Parent  8580ff50825a50c8f716709acdf8de0deddcd6ab
+  b
+  ---
+   b |  1 +
+   1 files changed, 1 insertions(+), 0 deletions(-)
+  
+  diff --git a/b b/b
+  new file mode 100644
+  --- /dev/null
+  +++ b/b
+  @@ -0,0 +1,1 @@
+  +b
+  
+
 test inline for single patch:
   $ hg email --date '1970-1-1 0:1' -n -f quux -t foo -c bar -s test -i -r 2 | $FILTERBOUNDARY
   this patch series consists of 1 patches.