From: Markus Lehtonen Date: Wed, 8 May 2013 17:42:45 +0000 (+0300) Subject: pq-rpm: support patch-export up to an arbitrary tree-ish X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ae26042a189041f9536f0a8729b2a7e54aef385c;p=tools%2Fgit-buildpackage.git pq-rpm: support patch-export up to an arbitrary tree-ish If the end of the export range is not a commit "normal" patches are generated up to HEAD and finally a raw diff between HEAD and the end-tree-is generated. Signed-off-by: Markus Lehtonen --- diff --git a/gbp/scripts/pq_rpm.py b/gbp/scripts/pq_rpm.py index 24009b3e..aeca2822 100755 --- a/gbp/scripts/pq_rpm.py +++ b/gbp/scripts/pq_rpm.py @@ -35,6 +35,7 @@ from gbp.patch_series import (PatchSeries, Patch) from gbp.rpm import (SpecFile, guess_spec) from gbp.scripts.common.pq import (is_pq_branch, pq_branch_name, pq_branch_base, parse_gbp_commands, format_patch, + format_diff, switch_to_pq_branch, apply_single_patch, apply_and_commit_patch, drop_pq) @@ -50,8 +51,21 @@ def generate_patches(repo, start, end, outdir, options): if not repo.has_treeish(treeish): raise GbpError('%s not a valid tree-ish' % treeish) + try: + end_commit = end + end_commit_sha1 = repo.rev_parse("%s^0" % end_commit) + except GitRepositoryError: + # In case of plain tree-ish objects, assume current branch head is the + # last commit + end_commit = "HEAD" + end_commit_sha1 = repo.rev_parse("%s^0" % end_commit) + + start_sha1 = repo.rev_parse("%s^0" % start) + if repo.get_merge_base(start_sha1, end_commit_sha1) != start_sha1: + raise GbpError("Start commit '%s' not an ancestor of end commit " + "'%s'" % (start, end_commit)) # Generate patches - for commit in reversed(repo.get_commits(start, end)): + for commit in reversed(repo.get_commits(start, end_commit)): info = repo.get_commit_info(commit) cmds = parse_gbp_commands(info, 'gbp-rpm', ('ignore'), None) if not 'ignore' in cmds: @@ -62,6 +76,13 @@ def generate_patches(repo, start, end, outdir, options): else: gbp.log.info('Ignoring commit %s' % info['id']) + # Generate diff to the tree-ish object + if end_commit != end: + gbp.log.info("Generating diff file %s..%s" % (end_commit, end)) + patch_fn = format_diff(outdir, None, repo, end_commit, end) + if patch_fn: + patches.append(patch_fn) + return patches, commands