summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMarkus Lehtonen <markus.lehtonen@linux.intel.com>2012-09-14 17:21:09 +0300
committerGuido Günther <agx@sigxcpu.org>2013-10-31 19:17:20 +0100
commit017fac39f6bd87d44a94d2cf46474e4ded721432 (patch)
tree0940c7963c3ab9e3fc4e36ed87868f1b0bb14520
parentc661c7153783c79c45fbe63d828b03ea0a788215 (diff)
pq.format_patch: support file path filtering
Implements a filter option that allows filtering out changes to certain files/paths in the patch-generation. A commit is totally ignored if all files would be filtered out. The path filter is given as a Python regexp. Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
-rw-r--r--gbp/scripts/common/pq.py32
1 files changed, 27 insertions, 5 deletions
diff --git a/gbp/scripts/common/pq.py b/gbp/scripts/common/pq.py
index 7bd855e6..7cdfd06f 100644
--- a/gbp/scripts/common/pq.py
+++ b/gbp/scripts/common/pq.py
@@ -66,6 +66,22 @@ def pq_branch_base(pq_branch):
return pq_branch[len(PQ_BRANCH_PREFIX):]
+def patch_path_filter(file_status, exclude_regex=None):
+ """
+ Create patch include paths, i.e. a "negation" of the exclude paths.
+ """
+ if exclude_regex:
+ include_paths = []
+ for file_list in file_status.values():
+ for fname in file_list:
+ if not re.match(exclude_regex, fname):
+ include_paths.append(fname)
+ else:
+ include_paths = ['.']
+
+ return include_paths
+
+
def write_patch_file(filename, commit_info, diff):
"""Write patch file"""
if not diff:
@@ -96,7 +112,7 @@ def write_patch_file(filename, commit_info, diff):
def format_patch(outdir, repo, commit_info, series, numbered=True,
- topic_regex=None):
+ topic_regex=None, path_exclude_regex=None):
"""Create patch of a single commit"""
commit = commit_info['id']
@@ -130,11 +146,17 @@ def format_patch(outdir, repo, commit_info, series, numbered=True,
filename = (num_prefix if numbered else '') + base + suffix
filepath = os.path.join(outdir, filename)
+ # Determine files to include
+ paths = patch_path_filter(commit_info['files'], path_exclude_regex)
+
# Finally, create the patch
- diff = repo.diff('%s^!' % commit, stat=80, summary=True, text=True)
- patch = write_patch_file(filepath, commit_info, diff)
- if patch:
- series.append(patch)
+ patch = None
+ if paths:
+ diff = repo.diff('%s^!' % commit, paths=paths, stat=80, summary=True,
+ text=True)
+ patch = write_patch_file(filepath, commit_info, diff)
+ if patch:
+ series.append(patch)
return patch