diff options
-rw-r--r-- | gbp/scripts/common/pq.py | 29 | ||||
-rwxr-xr-x | gbp/scripts/pq.py | 10 | ||||
-rw-r--r-- | tests/13_test_gbp_pq.py | 4 |
3 files changed, 19 insertions, 24 deletions
diff --git a/gbp/scripts/common/pq.py b/gbp/scripts/common/pq.py index 708d392..57edd19 100644 --- a/gbp/scripts/common/pq.py +++ b/gbp/scripts/common/pq.py @@ -22,7 +22,7 @@ import re import os import shutil import subprocess -from gbp.git import GitRepositoryError +from gbp.git import GitRepositoryError, GitModifier from gbp.errors import GbpError import gbp.log @@ -219,9 +219,9 @@ def get_maintainer_from_control(repo): maintainer = cmdout[0].strip() m = re.match('(?P<name>.*[^ ]) *<(?P<email>.*)>', maintainer) if m: - return m.group('name'), m.group('email') + return GitModifier(m.group('name'), m.group('email')) - return None, None + return GitModifier() def switch_to_pq_branch(repo, branch): @@ -244,25 +244,22 @@ def switch_to_pq_branch(repo, branch): repo.set_branch(pq_branch) -def apply_single_patch(repo, branch, patch, get_author_info, topic=None): +def apply_single_patch(repo, branch, patch, fallback_author, topic=None): switch_to_pq_branch(repo, branch) - apply_and_commit_patch(repo, patch, get_author_info, topic) + apply_and_commit_patch(repo, patch, fallback_author, topic) -def apply_and_commit_patch(repo, patch, get_author_info, topic=None): +def apply_and_commit_patch(repo, patch, fallback_author, topic=None): """apply a single patch 'patch', add topic 'topic' and commit it""" - author = {'name': patch.author, - 'email': patch.email, - 'date': patch.date } + author = GitModifier(patch.author, patch.email, patch.date) patch_fn = os.path.basename(patch.path) - if not (patch.author and patch.email): - name, email = get_author_info(repo) - if name: - gbp.log.warn("Patch '%s' has no authorship information, " - "using '%s <%s>'" % (patch_fn, name, email)) - author['name'] = name - author['email'] = email + if not (author.name and author.email): + if fallback_author and fallback_author['name']: + author = fallback_author + gbp.log.warn("Patch '%s' has no authorship information, using " + "'%s <%s>'" % (patch_fn, author['name'], + author['email'])) else: gbp.log.warn("Patch '%s' has no authorship information" % patch_fn) diff --git a/gbp/scripts/pq.py b/gbp/scripts/pq.py index 7755e0d..1ca9ca5 100755 --- a/gbp/scripts/pq.py +++ b/gbp/scripts/pq.py @@ -124,6 +124,7 @@ def import_quilt_patches(repo, branch, series, tries, force): raise GbpError("Patch queue branch '%s'. already exists. Try 'rebase' instead." % pq_branch) + maintainer = get_maintainer_from_control(repo) commits = repo.get_commits(num=tries, first_parent=True) # If we go back in history we have to safe our pq so we always try to apply # the latest one @@ -146,9 +147,7 @@ def import_quilt_patches(repo, branch, series, tries, force): for patch in queue: gbp.log.debug("Applying %s" % patch.path) try: - apply_and_commit_patch(repo, patch, - get_maintainer_from_control, - patch.topic) + apply_and_commit_patch(repo, patch, maintainer, patch.topic) except (GbpError, GitRepositoryError): repo.set_branch(branch) repo.delete_branch(pq_branch) @@ -254,9 +253,8 @@ def main(argv): rebase_pq(repo, current) elif action == "apply": patch = Patch(patchfile) - apply_single_patch(repo, current, patch, - get_maintainer_from_control, - options.topic) + maintainer = get_maintainer_from_control(repo) + apply_single_patch(repo, current, patch, maintainer, options.topic) elif action == "switch": switch_pq(repo, current) except CommandExecFailed: diff --git a/tests/13_test_gbp_pq.py b/tests/13_test_gbp_pq.py index 83b4315..bcfb9bc 100644 --- a/tests/13_test_gbp_pq.py +++ b/tests/13_test_gbp_pq.py @@ -69,8 +69,8 @@ class TestApplyAndCommit(testutils.DebianGitTestRepo): self.add_file("debian/control", "Maintainer: Guido Günther <gg@godiug.net>") - c = pq.get_maintainer_from_control - pq.apply_and_commit_patch(self.repo, patch, c) + maintainer = pq.get_maintainer_from_control(self.repo) + pq.apply_and_commit_patch(self.repo, patch, maintainer) info = self.repo.get_commit_info('HEAD') self.assertEqual(info['author'].email, 'gg@godiug.net') self.assertIn('foo', self.repo.list_files()) |