Jacob Keller
2013-11-13 00:23:51 UTC
This patch enables the patchdescr.tmpl to work when making a new patch. In
addition, it modifies the semantics, so that the patchdescr.tmpl can take
variables like the other templates. At the moment it only takes the sign_str,
author and committer variables. However future patches could easily add more
options. An example of this use would be a patch description template capable
of including the Signed-off-by tag, or other data.
Signed-off-by: Jacob Keller <***@intel.com>
---
stgit/commands/new.py | 38 +++++++++++++++++++++++++++++++++++---
1 file changed, 35 insertions(+), 3 deletions(-)
diff --git a/stgit/commands/new.py b/stgit/commands/new.py
index d5c5382..71500fb 100644
--- a/stgit/commands/new.py
+++ b/stgit/commands/new.py
@@ -16,7 +16,7 @@ along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
"""
-from stgit import argparse, utils
+from stgit import argparse, utils, templates
from stgit.commands import common
from stgit.lib import git as gitlib, transaction
from stgit.config import config
@@ -37,7 +37,20 @@ one is generated from the first line of the patch's commit message.
An editor will be launched to edit the commit message to be used for
the patch, unless the '--message' flag already specified one. The
'patchdescr.tmpl' template file (if available) is used to pre-fill the
-editor."""
+editor.
+
+The following variables are accepted by the patch description template:
+
+ %(author_name)s - the patch author's name
+ %(author_email)s - the patch author's email
+ %(committer_name)s - the patch committer's name
+ %(committer_email)s - the patch committer's email
+ %(sign_str) - the patch signing string
+
+These variables make it possible for the patch description to include the
+Signed-off-by line along with other text, and enable the user to specify
+exactly where it should be placed. Note, that lines beginning with '#' will be
+stripped from the final commit."""
args = []
options = (argparse.author_options()
@@ -64,8 +77,27 @@ def func(parser, options, args):
else:
parser.error('incorrect number of arguments')
+ tmpl = templates.get_template('patchdescr.tmpl')
+ tmpl_dict = {'author_name': gitlib.Person.author().name,
+ 'author_email': gitlib.Person.author().email,
+ 'committer_name': gitlib.Person.committer().name,
+ 'committer_email': gitlib.Person.committer().email,
+ 'sign_str': options.sign_str or "Signed-off-by"}
+
+ if tmpl:
+ try:
+ default_msg = tmpl % tmpl_dict
+ except KeyError, err:
+ raise common.CmdException, 'Unknown patch description template variable: %s' \
+ % err
+ except TypeError:
+ raise common.CmdException, 'Only "%(name)s" variables are ' \
+ 'supported in the patch description template'
+ else:
+ default_msg = ''
+
cd = gitlib.CommitData(
- tree = stack.head.data.tree, parents = [stack.head], message = '',
+ tree = stack.head.data.tree, parents = [stack.head], message = default_msg,
author = gitlib.Person.author(), committer = gitlib.Person.committer())
cd = common.update_commit_data(cd, options)
addition, it modifies the semantics, so that the patchdescr.tmpl can take
variables like the other templates. At the moment it only takes the sign_str,
author and committer variables. However future patches could easily add more
options. An example of this use would be a patch description template capable
of including the Signed-off-by tag, or other data.
Signed-off-by: Jacob Keller <***@intel.com>
---
stgit/commands/new.py | 38 +++++++++++++++++++++++++++++++++++---
1 file changed, 35 insertions(+), 3 deletions(-)
diff --git a/stgit/commands/new.py b/stgit/commands/new.py
index d5c5382..71500fb 100644
--- a/stgit/commands/new.py
+++ b/stgit/commands/new.py
@@ -16,7 +16,7 @@ along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
"""
-from stgit import argparse, utils
+from stgit import argparse, utils, templates
from stgit.commands import common
from stgit.lib import git as gitlib, transaction
from stgit.config import config
@@ -37,7 +37,20 @@ one is generated from the first line of the patch's commit message.
An editor will be launched to edit the commit message to be used for
the patch, unless the '--message' flag already specified one. The
'patchdescr.tmpl' template file (if available) is used to pre-fill the
-editor."""
+editor.
+
+The following variables are accepted by the patch description template:
+
+ %(author_name)s - the patch author's name
+ %(author_email)s - the patch author's email
+ %(committer_name)s - the patch committer's name
+ %(committer_email)s - the patch committer's email
+ %(sign_str) - the patch signing string
+
+These variables make it possible for the patch description to include the
+Signed-off-by line along with other text, and enable the user to specify
+exactly where it should be placed. Note, that lines beginning with '#' will be
+stripped from the final commit."""
args = []
options = (argparse.author_options()
@@ -64,8 +77,27 @@ def func(parser, options, args):
else:
parser.error('incorrect number of arguments')
+ tmpl = templates.get_template('patchdescr.tmpl')
+ tmpl_dict = {'author_name': gitlib.Person.author().name,
+ 'author_email': gitlib.Person.author().email,
+ 'committer_name': gitlib.Person.committer().name,
+ 'committer_email': gitlib.Person.committer().email,
+ 'sign_str': options.sign_str or "Signed-off-by"}
+
+ if tmpl:
+ try:
+ default_msg = tmpl % tmpl_dict
+ except KeyError, err:
+ raise common.CmdException, 'Unknown patch description template variable: %s' \
+ % err
+ except TypeError:
+ raise common.CmdException, 'Only "%(name)s" variables are ' \
+ 'supported in the patch description template'
+ else:
+ default_msg = ''
+
cd = gitlib.CommitData(
- tree = stack.head.data.tree, parents = [stack.head], message = '',
+ tree = stack.head.data.tree, parents = [stack.head], message = default_msg,
author = gitlib.Person.author(), committer = gitlib.Person.committer())
cd = common.update_commit_data(cd, options)