diff options
author | Guido Günther <agx@sigxcpu.org> | 2016-05-28 14:23:44 +0200 |
---|---|---|
committer | Guido Günther <agx@sigxcpu.org> | 2016-05-28 14:23:44 +0200 |
commit | 1f58d212630389ae87757d84cfe68b48e35553fa (patch) | |
tree | 5cffd0079a1d30936409eb4b80c9db75d87c1319 | |
parent | 0cae8d7c767c27d38e48e65b77ee859c957a6999 (diff) |
PatchSeries: Strip comment from patch names
Closes: #825536
-rw-r--r-- | gbp/patch_series.py | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/gbp/patch_series.py b/gbp/patch_series.py index dc8d24c..22025e0 100644 --- a/gbp/patch_series.py +++ b/gbp/patch_series.py @@ -163,6 +163,7 @@ class PatchSeries(list): """ A series of L{Patch}es as read from a quilt series file). """ + comment_re = re.compile('\s?#.*$') @classmethod def read_series_file(klass, seriesfile): @@ -187,7 +188,7 @@ class PatchSeries(list): Read patch series >>> PatchSeries._read_series(['a/b', - ... 'a -p1', + ... 'a -p1 # comment', ... 'a/b -p2'], '.') ... # doctest:+NORMALIZE_WHITESPACE [<gbp.patch_series.Patch path='./a/b' topic='a' >, @@ -227,6 +228,20 @@ class PatchSeries(list): topic = None return topic + @classmethod + def _strip_comment(klass, line): + """ + Strip a comment from a series file line + + >>> PatchSeries._strip_comment("does/not matter") + 'does/not matter' + >>> PatchSeries._strip_comment("remove/the # comment # text") + 'remove/the' + >>> PatchSeries._strip_comment("leave/level/intact -p1 # comment # text") + 'leave/level/intact -p1' + """ + return re.sub(klass.comment_re, '', line) + @staticmethod def _split_strip(line): """ @@ -261,7 +276,7 @@ class PatchSeries(list): >>> PatchSeries._parse_line("a/b", '.') <gbp.patch_series.Patch path='./a/b' topic='a' > """ - line = line.rstrip() + line = klass._strip_comment(line.rstrip()) topic = klass._get_topic(line) (patch, split) = klass._split_strip(line) return Patch(os.path.join(patch_dir, patch), topic, split) |