aboutsummaryrefslogtreecommitdiffhomepage
path: root/gbp/scripts
diff options
context:
space:
mode:
authorGuido Günther <agx@sigxcpu.org>2011-12-18 13:40:25 +0100
committerGuido Günther <agx@sigxcpu.org>2011-12-18 13:44:26 +0100
commit1f85957f1607ddba35da20c0b0fa34ce05f49e4d (patch)
treee6fba15d4cd090b1ade2221b9cc994b2995e9672 /gbp/scripts
parentb2e51bc3faf6d00b47ccb492b833f3bf345cb57b (diff)
scripts/pq: Move patch name handling to separate function
and add tests
Diffstat (limited to 'gbp/scripts')
-rw-r--r--gbp/scripts/pq.py22
1 files changed, 17 insertions, 5 deletions
diff --git a/gbp/scripts/pq.py b/gbp/scripts/pq.py
index 28de5a8a..5b7f32cd 100644
--- a/gbp/scripts/pq.py
+++ b/gbp/scripts/pq.py
@@ -295,6 +295,22 @@ def apply_single_patch(repo, branch, patch, topic=None):
switch_to_pq_branch(repo, branch)
apply_and_commit_patch(repo, patch, topic)
+def get_patch_subject_from_filename(patch):
+ """
+ Determine the patch's subject based on the patch's filename
+ >>> get_patch_subject('debian/patches/foo.patch')
+ 'foo'
+ >>> get_patch_subject('foo.patch')
+ 'foo'
+ >>> get_patch_subject('debian/patches/foo.bar')
+ 'foo.bar'
+ """
+ subject = os.path.basename(patch)
+ # Strip of .diff or .patch from patch name
+ base, ext = subject.rsplit('.', 1)
+ if ext in [ 'diff', 'patch' ]:
+ subject = base
+ return subject
def apply_and_commit_patch(repo, patch, topic=None):
"""apply a single patch 'patch', add topic 'topic' and commit it"""
@@ -302,11 +318,7 @@ def apply_and_commit_patch(repo, patch, topic=None):
# If we don't find a subject use the patch's name
if not header.has_key('subject'):
- header['subject'] = os.path.basename(patch)
- # Strip of .diff or .patch from patch name
- base, ext = header['subject'].rsplit('.', 1)
- if ext in [ 'diff', 'patch' ]:
- header['subject'] = base
+ header['subject'] = get_patch_subject_from_filename(patch)
if header.has_key('author') and header.has_key('email'):
header['name'] = header['author']