aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJacob Keller <jacob.e.keller@intel.com>2013-05-29 17:31:04 -0700
committerPeter P Waskiewicz Jr <peter.p.waskiewicz.jr@intel.com>2013-05-29 17:31:04 -0700
commite6a6e8ce335846b75ab846e62bfe428a22980f78 (patch)
treed006d664fbfa29689c2168bd87272162ec588292
parent1bcb69c9d04a2c5e03a74431cf311ac0148fff44 (diff)
downloadstgit-e6a6e8ce335846b75ab846e62bfe428a22980f78.tar.gz
mail: don't hardcode space locations in template variables
This patch modifies stgit-mail in order to enable templates to move the ordering of PATCH, the prefix, the version, and the number. The issue is due to stgit hardcoding a ' ' after the previx, before version and before numbers. This means that you can't design a template which re-orders these as it will result in incorrect spacing being generated. To this end, introduce %(vspace), %(nspace) and %(pspace) which allows a template to move the spacing around and enable correct alignment inside a template. This won't change the default behavior (if sticking to the standard templates) but enables more ability to customize and modify the default behaviors. Signed-off-by: Jacob Keller <jacob.e.keller@intel.com> Signed-off-by: Peter P Waskiewicz Jr <peter.p.waskiewicz.jr@intel.com>
-rw-r--r--stgit/commands/mail.py57
-rw-r--r--templates/covermail.tmpl4
-rw-r--r--templates/patchandattch.tmpl4
-rw-r--r--templates/patchmail.tmpl2
4 files changed, 43 insertions, 24 deletions
diff --git a/stgit/commands/mail.py b/stgit/commands/mail.py
index d551353..d6fbca8 100644
--- a/stgit/commands/mail.py
+++ b/stgit/commands/mail.py
@@ -67,12 +67,14 @@ The following variables are accepted by both the preamble and the
patch e-mail templates:
%(diffstat)s - diff statistics
- %(number)s - empty if only one patch is sent or ' patchnr/totalnr'
+ %(number)s - empty if only one patch is sent or 'patchnr/totalnr'
%(snumber)s - stripped version of '%(number)s'
+ %(nspace)s - ' ' if %(number)s is non-empty, otherwise empty string
%(patchnr)s - patch number
%(sender)s - 'sender' or 'authname <authemail>' as per the config file
%(totalnr)s - total number of patches to be sent
- %(version)s - ' version' string passed on the command line (or empty)
+ %(version)s - 'version' string passed on the command line (or empty)
+ %(vspace)s - ' ' if %(version)s is non-empty, otherwise empty string
In addition to the common variables, the preamble e-mail template
accepts the following:
@@ -91,7 +93,8 @@ the following:
%(fromauth)s - 'From: author\n\n' if different from sender
%(longdescr)s - the rest of the patch description, after the first line
%(patch)s - patch name
- %(prefix)s - 'prefix ' string passed on the command line
+ %(prefix)s - 'prefix' string passed on the command line
+ %(pspace)s - ' ' if %(prefix)s is non-empty, otherwise empty string
%(shortdescr)s - the first line of the patch description"""
args = [argparse.patch_range(argparse.applied_patches,
@@ -464,25 +467,30 @@ def __build_cover(tmpl, msg_id, options, patches):
sender = __get_sender()
if options.version:
- version_str = ' %s' % options.version
+ version_str = '%s' % options.version
+ version_space = ' '
else:
version_str = ''
+ version_space = ''
if options.prefix:
- prefix_str = options.prefix + ' '
+ prefix_str = options.prefix
else:
- confprefix = config.get('stgit.mail.prefix')
- if confprefix:
- prefix_str = confprefix + ' '
- else:
- prefix_str = ''
+ prefix_str = config.get('stgit.mail.prefix')
+ if prefix_str:
+ prefix_space = ' '
+ else:
+ prefix_str = ''
+ prefix_space = ''
total_nr_str = str(len(patches))
patch_nr_str = '0'.zfill(len(total_nr_str))
if len(patches) > 1:
- number_str = ' %s/%s' % (patch_nr_str, total_nr_str)
+ number_str = '%s/%s' % (patch_nr_str, total_nr_str)
+ number_space = ' '
else:
number_str = ''
+ number_space = ''
tmpl_dict = {'sender': sender,
# for backward template compatibility
@@ -492,10 +500,13 @@ def __build_cover(tmpl, msg_id, options, patches):
# for backward template compatibility
'date': '',
'version': version_str,
+ 'vspace': version_space,
'prefix': prefix_str,
+ 'pspace': prefix_space,
'patchnr': patch_nr_str,
'totalnr': total_nr_str,
'number': number_str,
+ 'nspace': number_space,
'snumber': number_str.strip(),
'shortlog': stack.shortlog(crt_series.get_patch(p)
for p in reversed(patches)),
@@ -559,25 +570,30 @@ def __build_message(tmpl, msg_id, options, patch, patch_nr, total_nr, ref_id):
fromauth = ''
if options.version:
- version_str = ' %s' % options.version
+ version_str = '%s' % options.version
+ version_space = ' '
else:
version_str = ''
+ version_space = ''
if options.prefix:
- prefix_str = options.prefix + ' '
+ prefix_str = options.prefix
else:
- confprefix = config.get('stgit.mail.prefix')
- if confprefix:
- prefix_str = confprefix + ' '
- else:
- prefix_str = ''
+ prefix_str = config.get('stgit.mail.prefix')
+ if prefix_str:
+ prefix_space = ' '
+ else:
+ prefix_str = ''
+ prefix_space = ''
total_nr_str = str(total_nr)
patch_nr_str = str(patch_nr).zfill(len(total_nr_str))
if not options.unrelated and total_nr > 1:
- number_str = ' %s/%s' % (patch_nr_str, total_nr_str)
+ number_str = '%s/%s' % (patch_nr_str, total_nr_str)
+ number_space = ' '
else:
number_str = ''
+ number_space = ''
diff = git.diff(rev1 = git_id(crt_series, '%s^' % patch),
rev2 = git_id(crt_series, '%s' % patch),
@@ -595,10 +611,13 @@ def __build_message(tmpl, msg_id, options, patch, patch_nr, total_nr, ref_id):
# for backward template compatibility
'date': '',
'version': version_str,
+ 'vspace': version_space,
'prefix': prefix_str,
+ 'pspace': prefix_space,
'patchnr': patch_nr_str,
'totalnr': total_nr_str,
'number': number_str,
+ 'nspace': number_space,
'snumber': number_str.strip(),
'fromauth': fromauth,
'authname': authname,
diff --git a/templates/covermail.tmpl b/templates/covermail.tmpl
index 5cf11b5..f6b9794 100644
--- a/templates/covermail.tmpl
+++ b/templates/covermail.tmpl
@@ -1,5 +1,5 @@
From: %(sender)s
-Subject: [%(prefix)sPATCH%(version)s%(number)s] Series short description
+Subject: [%(prefix)s%(pspace)sPATCH%(vspace)s%(version)s%(nspace)s%(number)s] Series short description
The following series implements...
@@ -7,5 +7,5 @@ The following series implements...
%(shortlog)s
%(diffstat)s
---
+--
Signature
diff --git a/templates/patchandattch.tmpl b/templates/patchandattch.tmpl
index 9c4f865..63910a0 100644
--- a/templates/patchandattch.tmpl
+++ b/templates/patchandattch.tmpl
@@ -1,5 +1,5 @@
From: %(sender)s
-Subject: [%(prefix)sPATCH%(version)s%(number)s] %(shortdescr)s
+Subject: [%(prefix)s%(pspace)sPATCH%(vspace)s%(version)s%(nspace)s%(number)s] %(shortdescr)s
Mime-Version: 1.0
Content-Type: multipart/mixed; boundary=MIMEBOUNDARY
@@ -23,4 +23,4 @@ Content-Disposition: attachment; filename=%(patch)s.patch
---
%(diffstat)s
%(diff)s
---MIMEBOUNDARY--
+--MIMEBOUNDARY--
diff --git a/templates/patchmail.tmpl b/templates/patchmail.tmpl
index 7d4022a..dbcf9dd 100644
--- a/templates/patchmail.tmpl
+++ b/templates/patchmail.tmpl
@@ -1,5 +1,5 @@
From: %(sender)s
-Subject: [%(prefix)sPATCH%(version)s%(number)s] %(shortdescr)s
+Subject: [%(prefix)s%(pspace)sPATCH%(vspace)s%(version)s%(nspace)s%(number)s] %(shortdescr)s
%(fromauth)s%(longdescr)s
---