pq-rpm: support patch-export up to an arbitrary tree-ish
authorMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Wed, 8 May 2013 17:42:45 +0000 (20:42 +0300)
committerMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Fri, 14 Nov 2014 12:22:11 +0000 (14:22 +0200)
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 <markus.lehtonen@linux.intel.com>
gbp/scripts/pq_rpm.py

index 267357b..1e3c44a 100755 (executable)
@@ -36,6 +36,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)
 
@@ -51,8 +52,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)[0]
         if not 'ignore' in cmds:
@@ -63,6 +77,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