pq: support patch-export commands
authorMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Fri, 3 May 2013 08:04:28 +0000 (11:04 +0300)
committerGuido Günther <agx@sigxcpu.org>
Thu, 31 Oct 2013 18:17:21 +0000 (19:17 +0100)
Support giving commands to pq as a meta tag in commit message. The
format is "Gbp: <command> [args]".

Currently, only one command is supported. namely 'ignore'. That is, one
can use 'Gbp: Ignore' in the commit message for ignoring the commit in
patch-generation.

Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
gbp/scripts/common/pq.py
gbp/scripts/pq.py

index 050e7df..b6b2118 100644 (file)
@@ -68,6 +68,29 @@ 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"""
+    cmd_re = re.compile(r'^%s:\s*(?P<cmd>[a-z-]+)(\s+(?P<args>\S.*))?' %
+                            cmd_tag, flags=re.I)
+    commands = {}
+    for line in info['body'].splitlines():
+        match = re.match(cmd_re, line)
+        if match:
+            cmd = match.group('cmd').lower()
+            if arg_cmds and cmd in arg_cmds:
+                if match.group('args'):
+                    commands[cmd] = match.group('args')
+                else:
+                    gbp.log.warn("Ignoring gbp-command '%s' in commit %s: "
+                                 "missing cmd arguments" % (line, info['id']))
+            elif noarg_cmds and cmd in noarg_cmds:
+                commands[cmd] = match.group('args')
+            else:
+                gbp.log.warn("Ignoring unknow gbp-command '%s' in commit %s"
+                                % (line, info['id']))
+    return commands
+
+
 def patch_path_filter(file_status, exclude_regex=None):
     """
     Create patch include paths, i.e. a "negation" of the exclude paths.
index c0f0946..f5618ce 100755 (executable)
@@ -30,8 +30,9 @@ from gbp.errors import GbpError
 import gbp.log
 from gbp.patch_series import (PatchSeries, Patch)
 from gbp.scripts.common.pq import (is_pq_branch, pq_branch_name, pq_branch_base,
-                                 format_patch, switch_to_pq_branch,
-                                 apply_single_patch, apply_and_commit_patch,
+                                 parse_gbp_commands, format_patch,
+                                 switch_to_pq_branch, apply_single_patch,
+                                 apply_and_commit_patch,
                                  drop_pq, get_maintainer_from_control)
 
 PATCH_DIR = "debian/patches/"
@@ -53,8 +54,12 @@ def generate_patches(repo, start, end, outdir, options):
     topic_regex = 'gbp-pq-topic:\s*(?P<topic>\S.*)'
     for commit in rev_list:
         info = repo.get_commit_info(commit)
-        format_patch(outdir, repo, info, patches, options.patch_numbers,
-                     topic_regex=topic_regex)
+        cmds = parse_gbp_commands(info, 'gbp', ('ignore'), None)
+        if not 'ignore' in cmds:
+            format_patch(outdir, repo, info, patches, options.patch_numbers,
+                         topic_regex=topic_regex)
+        else:
+            gbp.log.info('Ignoring commit %s' % info['id'])
 
     return patches