summaryrefslogtreecommitdiff
path: root/gbp
diff options
context:
space:
mode:
authorGuido Günther <agx@sigxcpu.org>2015-02-08 15:15:03 +0100
committerGuido Günther <agx@sigxcpu.org>2015-02-08 16:29:13 +0100
commit62a5429093ab190a843d5fa7243227c1d799ca3e (patch)
treee64631355e7bfcd50ef8f2bfd8368a3d959428c1 /gbp
parent64be54db7546e7399b5b758d3f25c507180180e1 (diff)
parse_gbp_commands: support command filtering
When we write out patches to subdirs using a topic we want to filter out this topic from the commit message. Support for this was lost in 7ce15d2434ee42aa5a1afce3d03069c5efb2db1b add it back. Also fix parsing of the deprecated commands.
Diffstat (limited to 'gbp')
-rw-r--r--gbp/scripts/common/pq.py28
-rwxr-xr-xgbp/scripts/pq.py19
-rwxr-xr-xgbp/scripts/pq_rpm.py6
3 files changed, 45 insertions, 8 deletions
diff --git a/gbp/scripts/common/pq.py b/gbp/scripts/common/pq.py
index a82e462..9b2a887 100644
--- a/gbp/scripts/common/pq.py
+++ b/gbp/scripts/common/pq.py
@@ -71,8 +71,23 @@ def pq_branch_base(pq_branch):
return pq_branch[len(PQ_BRANCH_PREFIX):]
-def parse_gbp_commands(info, cmd_tag, noarg_cmds, arg_cmds):
- """Parse gbp commands from commit message"""
+def parse_gbp_commands(info, cmd_tag, noarg_cmds, arg_cmds, filter_cmds=None):
+ """
+ Parses gbp commands from commit message. Args with and wthout
+ arguments are supported as is filtering out of commands from the
+ commit body.
+
+ @param info: the commit into to parse for commands
+ @param cmd_tag: the command tag
+ @param noarg_cmds: commands without an argument
+ @type noarg_cmds: C{list} of C{str}
+ @param arg_cmds: command with an argumnt
+ @type arg_cmds: C{list} of C{str}
+ @param filter_cmds: commands to filter out of the passed in info
+ @type filter_cmds: C{list} of C{str}
+ @returns: the parsed commands and the filtered commit body.
+ """
+ body = []
cmd_re = re.compile(r'^%s:\s*(?P<cmd>[a-z-]+)(\s+(?P<args>\S.*))?' %
cmd_tag, flags=re.I)
commands = {}
@@ -91,7 +106,14 @@ def parse_gbp_commands(info, cmd_tag, noarg_cmds, arg_cmds):
else:
gbp.log.warn("Ignoring unknown gbp-command '%s' in commit %s"
% (line, info['id']))
- return commands
+ if filter_cmds is None or cmd not in filter_cmds:
+ body.append(line)
+ else:
+ body.append(line)
+ msg = '\n'.join(body)
+ # Add trailing newline if the originial body hat one
+ #msg += '\n' if info['body'] and info['body'][-1] == '\n' else ''
+ return (commands, msg)
def patch_path_filter(file_status, exclude_regex=None):
diff --git a/gbp/scripts/pq.py b/gbp/scripts/pq.py
index 543907b..cf76c35 100755
--- a/gbp/scripts/pq.py
+++ b/gbp/scripts/pq.py
@@ -76,9 +76,22 @@ def generate_patches(repo, start, end, outdir, options):
rev_list = reversed(repo.get_commits(start, end))
for commit in rev_list:
info = repo.get_commit_info(commit)
- topic = parse_old_style_topic(info)
- cmds = parse_gbp_commands(info, 'gbp', ('ignore'), ('topic'))
- cmds.update(parse_gbp_commands(info, 'gbp-pq', ('ignore'), ('topic')))
+ # Parse 'gbp-pq-topic:'
+ topic = parse_old_style_topic(info)
+ cmds ={'topic': topic } if topic else {}
+ # Parse 'Gbp: ' style commands
+ (cmds_gbp, info['body']) = parse_gbp_commands(info, 'gbp',
+ ('ignore'),
+ ('topic'),
+ ('topic'))
+ cmds.update(cmds)
+ # Parse 'Gbp-Pq: ' style commands
+ (cmds_gbp_pq, info['body']) = parse_gbp_commands(info,
+ 'gbp-pq',
+ ('ignore'),
+ ('topic'),
+ ('topic'))
+ cmds.update(cmds_gbp_pq)
if not 'ignore' in cmds:
if 'topic' in cmds:
topic = cmds['topic']
diff --git a/gbp/scripts/pq_rpm.py b/gbp/scripts/pq_rpm.py
index 3d1c4bc..ab50cad 100755
--- a/gbp/scripts/pq_rpm.py
+++ b/gbp/scripts/pq_rpm.py
@@ -96,8 +96,10 @@ def generate_patches(repo, start, end, outdir, options):
# Generate patches
for commit in reversed(repo.get_commits(start, end_commit)):
info = repo.get_commit_info(commit)
- cmds = parse_gbp_commands(info, 'gbp-rpm', ('ignore'),
- ('if', 'ifarch'))
+ (cmds, info['body']) = parse_gbp_commands(info,
+ 'gbp-rpm',
+ ('ignore'),
+ ('if', 'ifarch'))
if not 'ignore' in cmds:
patch_fn = format_patch(outdir, repo, info, patches,
options.patch_numbers)