From 1f85957f1607ddba35da20c0b0fa34ce05f49e4d Mon Sep 17 00:00:00 2001 From: Guido Günther Date: Sun, 18 Dec 2011 13:40:25 +0100 Subject: scripts/pq: Move patch name handling to separate function and add tests --- gbp/scripts/pq.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'gbp/scripts/pq.py') diff --git a/gbp/scripts/pq.py b/gbp/scripts/pq.py index 28de5a8..5b7f32c 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'] -- cgit v1.2.3