diff options
author | Markus Lehtonen <markus.lehtonen@linux.intel.com> | 2013-05-02 12:57:10 +0300 |
---|---|---|
committer | Guido Günther <agx@sigxcpu.org> | 2013-10-31 19:17:20 +0100 |
commit | c661c7153783c79c45fbe63d828b03ea0a788215 (patch) | |
tree | fd2190d631e47c1f8d9b99f4949da237392eaacc /gbp/scripts/pq.py | |
parent | 3092623a8841a6aa9e12902436779c8dea80598c (diff) | |
download | git-buildpackage-c661c7153783c79c45fbe63d828b03ea0a788215.tar.gz git-buildpackage-c661c7153783c79c45fbe63d828b03ea0a788215.tar.bz2 git-buildpackage-c661c7153783c79c45fbe63d828b03ea0a788215.zip |
pq: rewrite patch export functionality
Use our own function for constructing the patch files instead of using
the format-patch command of git. This way, we get the desired output
format directly, without the need for the error-prone "format-patch,
parse patch files, mangle and re-write patch files" cycle.
Also, fix patch naming in patch generation when '--no-patch-numbers' is
used. Previously, multiple commits with the same subject resulted in
multiple patches having the same filename. This lead into broken series
with missing patches as patch files were overwritten by the topmost
commit.
Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
Diffstat (limited to 'gbp/scripts/pq.py')
-rwxr-xr-x | gbp/scripts/pq.py | 40 |
1 files changed, 28 insertions, 12 deletions
diff --git a/gbp/scripts/pq.py b/gbp/scripts/pq.py index 59be3832..c0f09469 100755 --- a/gbp/scripts/pq.py +++ b/gbp/scripts/pq.py @@ -22,6 +22,7 @@ import os import shutil import sys import tempfile +import re from gbp.config import GbpOptionParserDebian from gbp.git import (GitRepositoryError, GitRepository) from gbp.command_wrappers import (GitCommand, CommandExecFailed) @@ -29,7 +30,7 @@ from gbp.errors import GbpError import gbp.log from gbp.patch_series import (PatchSeries, Patch) from gbp.scripts.common.pq import (is_pq_branch, pq_branch_name, pq_branch_base, - write_patch, switch_to_pq_branch, + format_patch, switch_to_pq_branch, apply_single_patch, apply_and_commit_patch, drop_pq, get_maintainer_from_control) @@ -37,6 +38,27 @@ PATCH_DIR = "debian/patches/" SERIES_FILE = os.path.join(PATCH_DIR,"series") +def generate_patches(repo, start, end, outdir, options): + """ + Generate patch files from git + """ + gbp.log.info("Generating patches from git (%s..%s)" % (start, end)) + patches = [] + for treeish in [start, end]: + if not repo.has_treeish(treeish): + raise GbpError('%s not a valid tree-ish' % treeish) + + # Generate patches + rev_list = reversed(repo.get_commits(start, end)) + topic_regex = 'gbp-pq-topic:\s*(?P<topic>\S.*)' + for commit in rev_list: + info = repo.get_commit_info(commit) + format_patch(outdir, repo, info, patches, options.patch_numbers, + topic_regex=topic_regex) + + return patches + + def export_patches(repo, branch, options): """Export patches from the pq branch into a patch series""" if is_pq_branch(branch): @@ -54,18 +76,12 @@ def export_patches(repo, branch, options): else: gbp.log.debug("%s does not exist." % PATCH_DIR) - patches = repo.format_patches(branch, - pq_branch, PATCH_DIR, - signature=False, - symmetric=False) - if patches: - f = open(SERIES_FILE, 'w') - gbp.log.info("Regenerating patch queue in '%s'." % PATCH_DIR) - for patch in patches: - filename = write_patch(patch, PATCH_DIR, options) - f.write(filename[len(PATCH_DIR):] + '\n') + patches = generate_patches(repo, branch, pq_branch, PATCH_DIR, options) - f.close() + if patches: + with open(SERIES_FILE, 'w') as seriesfd: + for patch in patches: + seriesfd.write(os.path.relpath(patch, PATCH_DIR) + '\n') GitCommand('status')(['--', PATCH_DIR]) else: gbp.log.info("No patches on '%s' - nothing to do." % pq_branch) |