[PATCH 4 of 5] patchbomb: add config option to generate flag by template

Yuya Nishihara yuya at tcha.org
Wed Apr 1 08:25:53 CDT 2015


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1427726446 -32400
#      Mon Mar 30 23:40:46 2015 +0900
# Node ID 98290eaf4e6bf993f5e351bd8f954b8f6e99479a
# Parent  79696ed77d0e958b4291900a831981211e6d6bfe
patchbomb: add config option to generate flag by template

This allows us to flag stable patches automatically.

  [patchbomb]
  flagtemplate = {ifeq(branch, 'default', '', branch|upper)}

I assume that the following rules are acceptable in most cases, but some of
them won't be applied to the other projects.

 - flag is generated from the last revision because it is likely to be a head
   that has bookmarks.
 - flagtemplate can't be overridden by --flag because we'll want to add extra
   flag such as --flag V2.

diff --git a/hgext/patchbomb.py b/hgext/patchbomb.py
--- a/hgext/patchbomb.py
+++ b/hgext/patchbomb.py
@@ -53,6 +53,12 @@ overwritten by command line flags like -
   intro=never  # never include an introduction message
   intro=always # always include an introduction message
 
+You can specify the template for the flag to add in subject prefixes. The flag
+will be generated from the last revision to be sent.
+
+  [patchbomb]
+  flagtemplate = {ifeq(branch, 'default', '', branch|upper)}
+
 You can set patchbomb to always ask for confirmation by setting
 ``patchbomb.confirm`` to true.
 '''
@@ -65,7 +71,7 @@ import email.Generator
 import email.MIMEMultipart
 
 from mercurial import cmdutil, commands, hg, mail, patch, util
-from mercurial import scmutil
+from mercurial import scmutil, templater
 from mercurial.i18n import _
 from mercurial.node import bin
 
@@ -264,6 +270,25 @@ def _getbundlemsgs(repo, sender, bundle,
     msg['Subject'] = mail.headencode(ui, subj, _charsets, opts.get('test'))
     return [(msg, subj, None)]
 
+def _makeflag(repo, revs):
+    """make a flag from the last revision which is likely to be a branch or
+    bookmark head"""
+    ui = repo.ui
+    tmpl = ui.config('patchbomb', 'flagtemplate')
+    if not revs or not tmpl:
+        return ''
+    tmpl = templater.parsestring(tmpl, quoted=False)
+    try:
+        t = cmdutil.changeset_templater(ui, repo, None, {}, tmpl, None, False)
+    except SyntaxError, inst:
+        raise util.Abort(inst.args[0])
+    ui.pushbuffer()
+    try:
+        t.show(repo[revs.last()])
+        t.close()
+    finally:
+        return ui.popbuffer()
+
 def _makeintro(repo, sender, patches, **opts):
     """make an introduction email, asking the user for content if needed
 
@@ -505,6 +530,10 @@ def patchbomb(ui, repo, *revs, **opts):
     if bundle:
         opts['revs'] = [str(r) for r in revs]
 
+    flag = _makeflag(repo, revs)
+    if flag:
+        opts.setdefault('flag', []).insert(0, flag)
+
     # start
     if date:
         start_time = util.parsedate(date)
diff --git a/tests/test-patchbomb.t b/tests/test-patchbomb.t
--- a/tests/test-patchbomb.t
+++ b/tests/test-patchbomb.t
@@ -2330,6 +2330,113 @@ test multi-address parsing:
   
   
 
+test flag template:
+  $ hg bookmark -r1 foo
+  $ hg email --date '1970-1-1 0:1' -n -f quux -t foo -r 0:1 \
+  > --config patchbomb.flagtemplate='{bookmarks}'
+  this patch series consists of 2 patches.
+  
+  (optional) Subject: [PATCH 0 of 2 foo] 
+  Cc: 
+  
+  displaying [PATCH 1 of 2 foo] a ...
+  Content-Type: text/plain; charset="us-ascii"
+  MIME-Version: 1.0
+  Content-Transfer-Encoding: 7bit
+  Subject: [PATCH 1 of 2 foo] a
+  X-Mercurial-Node: 8580ff50825a50c8f716709acdf8de0deddcd6ab
+  X-Mercurial-Series-Index: 1
+  X-Mercurial-Series-Total: 2
+  Message-Id: <8580ff50825a50c8f716.60@*> (glob)
+  X-Mercurial-Series-Id: <8580ff50825a50c8f716.60@*> (glob)
+  User-Agent: Mercurial-patchbomb/* (glob)
+  Date: Thu, 01 Jan 1970 00:01:00 +0000
+  From: quux
+  To: foo
+  
+  # HG changeset patch
+  # User test
+  # Date 1 0
+  #      Thu Jan 01 00:00:01 1970 +0000
+  # Node ID 8580ff50825a50c8f716709acdf8de0deddcd6ab
+  # Parent  0000000000000000000000000000000000000000
+  a
+  
+  diff -r 000000000000 -r 8580ff50825a a
+  --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+  +++ b/a	Thu Jan 01 00:00:01 1970 +0000
+  @@ -0,0 +1,1 @@
+  +a
+  
+  displaying [PATCH 2 of 2 foo] b ...
+  Content-Type: text/plain; charset="us-ascii"
+  MIME-Version: 1.0
+  Content-Transfer-Encoding: 7bit
+  Subject: [PATCH 2 of 2 foo] b
+  X-Mercurial-Node: 97d72e5f12c7e84f85064aa72e5a297142c36ed9
+  X-Mercurial-Series-Index: 2
+  X-Mercurial-Series-Total: 2
+  Message-Id: <97d72e5f12c7e84f8506.61@*> (glob)
+  X-Mercurial-Series-Id: <8580ff50825a50c8f716.60@*> (glob)
+  In-Reply-To: <8580ff50825a50c8f716.60@*> (glob)
+  References: <8580ff50825a50c8f716.60@*> (glob)
+  User-Agent: Mercurial-patchbomb/* (glob)
+  Date: Thu, 01 Jan 1970 00:01:01 +0000
+  From: quux
+  To: foo
+  
+  # HG changeset patch
+  # User test
+  # Date 2 0
+  #      Thu Jan 01 00:00:02 1970 +0000
+  # Node ID 97d72e5f12c7e84f85064aa72e5a297142c36ed9
+  # Parent  8580ff50825a50c8f716709acdf8de0deddcd6ab
+  b
+  
+  diff -r 8580ff50825a -r 97d72e5f12c7 b
+  --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+  +++ b/b	Thu Jan 01 00:00:02 1970 +0000
+  @@ -0,0 +1,1 @@
+  +b
+  
+
+test flag template plus --flag:
+  $ hg email --date '1970-1-1 0:1' -n -f quux -t foo -r 0 --flag 'V2' \
+  > --config patchbomb.flagtemplate='{branch}'
+  this patch series consists of 1 patches.
+  
+  Cc: 
+  
+  displaying [PATCH default V2] a ...
+  Content-Type: text/plain; charset="us-ascii"
+  MIME-Version: 1.0
+  Content-Transfer-Encoding: 7bit
+  Subject: [PATCH default V2] a
+  X-Mercurial-Node: 8580ff50825a50c8f716709acdf8de0deddcd6ab
+  X-Mercurial-Series-Index: 1
+  X-Mercurial-Series-Total: 1
+  Message-Id: <8580ff50825a50c8f716.60@*> (glob)
+  X-Mercurial-Series-Id: <8580ff50825a50c8f716.60@*> (glob)
+  User-Agent: Mercurial-patchbomb/* (glob)
+  Date: Thu, 01 Jan 1970 00:01:00 +0000
+  From: quux
+  To: foo
+  
+  # HG changeset patch
+  # User test
+  # Date 1 0
+  #      Thu Jan 01 00:00:01 1970 +0000
+  # Node ID 8580ff50825a50c8f716709acdf8de0deddcd6ab
+  # Parent  0000000000000000000000000000000000000000
+  a
+  
+  diff -r 000000000000 -r 8580ff50825a a
+  --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+  +++ b/a	Thu Jan 01 00:00:01 1970 +0000
+  @@ -0,0 +1,1 @@
+  +a
+  
+
 test multi-byte domain parsing:
   $ UUML=`$PYTHON -c 'import sys; sys.stdout.write("\374")'`
   $ HGENCODING=iso-8859-1


More information about the Mercurial-devel mailing list