diff options
-rw-r--r-- | gbp/scripts/common/pq.py | 28 | ||||
-rwxr-xr-x | gbp/scripts/pq.py | 19 | ||||
-rwxr-xr-x | gbp/scripts/pq_rpm.py | 6 | ||||
-rw-r--r-- | tests/13_test_gbp_pq.py | 27 |
4 files changed, 71 insertions, 9 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) diff --git a/tests/13_test_gbp_pq.py b/tests/13_test_gbp_pq.py index c17b715..46110b1 100644 --- a/tests/13_test_gbp_pq.py +++ b/tests/13_test_gbp_pq.py @@ -1,5 +1,5 @@ # vim: set fileencoding=utf-8 : -# (C) 2012 Guido Günther <agx@sigxcpu.org> +# (C) 2012,2015 Guido Günther <agx@sigxcpu.org> # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or @@ -153,5 +153,30 @@ class TestExport(testutils.DebianGitTestRepo): self.assertFalse(repo.has_branch(pq_branch)) +class TestParseGbpCommand(unittest.TestCase): + def test_empty_body(self): + """Test command filtering with an empty body""" + info = { 'body': '' } + (cmds, body) = pq.parse_gbp_commands(info, ['tag'], ['cmd1'], ['cmd2']) + self.assertEquals(cmds, {}) + self.assertEquals(body, '') + + def test_noarg_cmd(self): + orig_body = '\n'.join(["Foo", + "tag: cmd1"]) + info = { 'body': orig_body } + (cmds, body) = pq.parse_gbp_commands(info, 'tag', ['cmd'], ['argcmd']) + self.assertEquals(cmds, {'cmd': None}) + self.assertEquals(body, orig_body) + + def test_filter_cmd(self): + orig_body = '\n'.join(["Foo", + "tag: cmd1"]) + info = { 'body': orig_body } + (cmds, body) = pq.parse_gbp_commands(info, 'tag', ['cmd'], ['argcmd'], ['cmd']) + self.assertEquals(cmds, {'cmd': None}) + self.assertEquals(body, 'Foo') + + def _patch_path(name): return os.path.join(context.projectdir, 'tests/data', name) |