Patchwork [1,of,3] patchbomb: introduce new option --git-format-patch

login
register
mail settings
Submitter Henning Schild
Date Nov. 17, 2016, 8:47 p.m.
Message ID <7885eea6837bbb30c12e.1479415676@localhost>
Download mbox | patch
Permalink /patch/17629/
State Changes Requested
Delegated to: Yuya Nishihara
Headers show

Comments

Henning Schild - Nov. 17, 2016, 8:47 p.m.
# HG changeset patch
# User Henning Schild <henning@hennsch.de>
# Date 1478958881 -3600
#      Sat Nov 12 14:54:41 2016 +0100
# Node ID 7885eea6837bbb30c12e0833b71a6691008b489e
# Parent  bf876ac433c1859ab61d66ddf786049fd6e6bea8
patchbomb: introduce new option --git-format-patch

When sending patch mails to a git-based project the diffstat should be placed
right under the commit message. Setting that option makes hg email behave like
git-format-patch.
Sean Farley - Nov. 17, 2016, 9:44 p.m.
Henning Schild <henning@hennsch.de> writes:

> # HG changeset patch
> # User Henning Schild <henning@hennsch.de>
> # Date 1478958881 -3600
> #      Sat Nov 12 14:54:41 2016 +0100
> # Node ID 7885eea6837bbb30c12e0833b71a6691008b489e
> # Parent  bf876ac433c1859ab61d66ddf786049fd6e6bea8
> patchbomb: introduce new option --git-format-patch

As I mentioned before, I'd rather not have a new option. If we could do
this with templates, then you could just alias that:

[templates]
gitemail = "{foo} {bar}"

[alias]
gitemail = email -T "{gitemail}"
Yuya Nishihara - Nov. 20, 2016, 9:47 a.m.
On Thu, 17 Nov 2016 13:44:46 -0800, Sean Farley wrote:
> Henning Schild <henning@hennsch.de> writes:
> > # HG changeset patch
> > # User Henning Schild <henning@hennsch.de>
> > # Date 1478958881 -3600
> > #      Sat Nov 12 14:54:41 2016 +0100
> > # Node ID 7885eea6837bbb30c12e0833b71a6691008b489e
> > # Parent  bf876ac433c1859ab61d66ddf786049fd6e6bea8
> > patchbomb: introduce new option --git-format-patch
> 
> As I mentioned before, I'd rather not have a new option. If we could do
> this with templates, then you could just alias that:
> 
> [templates]
> gitemail = "{foo} {bar}"
> 
> [alias]
> gitemail = email -T "{gitemail}"

Yeah, I like the templating idea, but that would require a fair amount of work,
for example:

 1. drop internal opts['patches'] support (which would be unused now)
 2. refactor _getpatchmsgs(), _getpatches() and makepatch()
 3. generate patch header by templater or formatter

So if it's important to support git-style diffstat, I think new option or config
knob is okay.

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_format_patch'):
+        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_format_patch'):
         body += ds + '\n\n'
 
     addattachment = opts.get('attach') or opts.get('inline')
@@ -406,6 +417,7 @@ 
 
 @command('email',
     [('g', 'git', None, _('use git extended diff format')),
+    ('', 'git-format-patch', None, _('use git-format-patch email format')),
     ('', 'plain', None, _('omit hg patch header')),
     ('o', 'outgoing', None,
      _('send changes not found in the target repository')),
@@ -504,7 +516,6 @@ 
     '''
 
     _charsets = mail._charsets(ui)
-
     bundle = opts.get('bundle')
     date = opts.get('date')
     mbox = opts.get('mbox')
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-format-patch --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-format-patch --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.