diff options
author | Markus Lehtonen <markus.lehtonen@linux.intel.com> | 2012-06-27 18:12:01 +0300 |
---|---|---|
committer | Markus Lehtonen <markus.lehtonen@linux.intel.com> | 2013-03-08 13:13:38 +0200 |
commit | 69cd3bdf7453fcfaabd12e74679de057d1e8c8ec (patch) | |
tree | 0049424f2dc696fdf526867ba967e83e17049c01 | |
parent | 297319fc9228716c725edbedad6d76f97237a212 (diff) | |
download | git-buildpackage-69cd3bdf7453fcfaabd12e74679de057d1e8c8ec.tar.gz git-buildpackage-69cd3bdf7453fcfaabd12e74679de057d1e8c8ec.tar.bz2 git-buildpackage-69cd3bdf7453fcfaabd12e74679de057d1e8c8ec.zip |
import-srpm: support for patch import
Adds a new commandline option '--patch-import' for importing patches
into the source tree in packaging branch. When enabled, gbp applies and
commits all patches (not marked for manual maintenance) into the
packaging branch. If this succeeds, it also removes all imported patch
files from the packaging directory and the spec file.
Currently only supported for non-orphan-packaging.
This setting is true by default which should make more sense as the
developer wants to do code development in the packaging branch (if
he/she selects to use non-orphan packaging).
However, patch-import is force-disabled if in bare git repository. We
cannot support this, currently.
Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
-rw-r--r-- | gbp/config.py | 3 | ||||
-rw-r--r-- | gbp/rpm/__init__.py | 8 | ||||
-rwxr-xr-x | gbp/scripts/import_srpm.py | 79 | ||||
-rwxr-xr-x | gbp/scripts/pq_rpm.py | 33 |
4 files changed, 102 insertions, 21 deletions
diff --git a/gbp/config.py b/gbp/config.py index 66ff6b06..a99b3ae1 100644 --- a/gbp/config.py +++ b/gbp/config.py @@ -491,6 +491,7 @@ class GbpOptionParserRpm(GbpOptionParser): 'patch-export-squash-until' : '', 'pristine-tarball-name' : 'auto', 'orig-prefix' : 'auto', + 'patch-import' : 'True', } ) help = dict(GbpOptionParser.help) @@ -519,6 +520,8 @@ class GbpOptionParserRpm(GbpOptionParser): "Filename to record to pristine-tar, set to 'auto' to not mangle the file name, default is '%(pristine-tarball-name)s'", 'orig-prefix': "Prefix (dir) to be used when generating/importing tarballs, default is '%(orig-prefix)s'", + 'patch-import': + "Import patches to the packaging branch, default is '%(patch-import)s'", } ) # vim:et:ts=4:sw=4:et:sts=4:ai:set list listchars=tab\:»·,trail\:·: diff --git a/gbp/rpm/__init__.py b/gbp/rpm/__init__.py index 7e07317a..42685052 100644 --- a/gbp/rpm/__init__.py +++ b/gbp/rpm/__init__.py @@ -475,14 +475,18 @@ class SpecFile(object): linenum = loc['nametag'] + 1 # Add all patch tag lines to content, in reversed order + patch_tags_added = 0 for n in reversed(sorted(self.patches.keys())): patch = self.patches[n] if patch['autoupdate']: # "PatchXYZ:" text 12 chars wide, left aligned text = "%-12s%s" % ("Patch%d:" % n, patch['name']) self.content.insert(linenum, text + "\n") - # Finally, add a comment indicating gbp generated patches - self.content.insert(linenum, "# Patches auto-generated by git-buildpackage:\n") + patch_tags_added += 1 + if patch_tags_added > 0: + # Finally, add a comment indicating gbp generated patches + self.content.insert(linenum, "# Patches auto-generated by " + "git-buildpackage:\n") # Remove all old patch tag lines for l in reversed(rm_tag_lines): gbp.log.debug("Removing line #%s from spec: '%s'" % (l, self.content[l].strip())) diff --git a/gbp/scripts/import_srpm.py b/gbp/scripts/import_srpm.py index 3650132e..327231f3 100755 --- a/gbp/scripts/import_srpm.py +++ b/gbp/scripts/import_srpm.py @@ -37,6 +37,8 @@ from gbp.git.modifier import GitModifier from gbp.config import GbpOptionParserRpm, GbpOptionGroup, no_upstream_branch_msg from gbp.errors import GbpError import gbp.log +from gbp.scripts.pq_rpm import safe_patches, rm_patch_files, get_packager +from gbp.scripts.common.pq import apply_and_commit_patch no_packaging_branch_msg = """ Repository does not have branch '%s' for packaging/distribution sources. If there is none see @@ -44,6 +46,12 @@ file:///usr/share/doc/git-buildpackage/manual-html/gbp.import.html#GBP.IMPORT.CO on howto create it otherwise use --packaging-branch to specify it. """ +PATCH_AUTODELETE_COMMIT_MSG = """ +Autoremove imported patches from packaging + +Removed all imported patches from %s +and patch files from the packaging dir. +""" class SkipImport(Exception): pass @@ -95,9 +103,59 @@ def move_tag_stamp(repo, format, tag_str_fields): def set_bare_repo_options(options): """Modify options for import into a bare repository""" if options.pristine_tar: - gbp.log.info("Bare repository: setting %s option" - % (["", " '--no-pristine-tar'"][options.pristine_tar], )) + gbp.log.info("Bare repository: setting %s option '--no-pristine-tar'") options.pristine_tar = False + if options.patch_import: + gbp.log.info("Bare repository: setting %s option '--no-patch-import')") + options.patch_import = False + + +def import_spec_patches(repo, spec): + """ + Import patches from a spec file to the current branch + """ + queue = spec.patchseries() + if len(queue) == 0: + return + + gbp.log.info("Importing patches to '%s' branch" % repo.get_branch()) + tmpdir = tempfile.mkdtemp() + orig_head = repo.rev_parse("HEAD") + packager = get_packager(spec) + + try: + # Put patches in a safe place + safedir, queue = safe_patches(queue, tmpdir) + for patch in queue: + gbp.log.debug("Applying %s" % patch.path) + try: + apply_and_commit_patch(repo, patch, packager) + except (GbpError, GitRepositoryError): + repo.force_head(orig_head, hard=True) + raise GbpError, "Couldn't import patches, you need to apply and commit manually" + finally: + shutil.rmtree(tmpdir) + + # Remove patches from spec and packaging directory + gbp.log.info("Removing imported patch files from spec and packaging dir") + rm_patch_files(spec) + try: + spec.update_patches([]) + spec.write_spec_file() + except GbpError: + repo.force_head('HEAD', hard=True) + raise GbpError("Unable to update spec file, you need to edit and " + "commit it manually") + repo.commit_all(msg=PATCH_AUTODELETE_COMMIT_MSG % + os.path.basename(spec.specfile)) + + +def force_to_branch_head(repo, branch): + if repo.get_branch() == branch: + # Update HEAD if we modified the checked out branch + repo.force_head(branch, hard=True) + # Checkout packaging branch + repo.set_branch(branch) def parse_args(argv): @@ -157,6 +215,8 @@ def parse_args(argv): dest="author_is_committer") import_group.add_config_file_option(option_name="packaging-dir", dest="packaging_dir") + import_group.add_boolean_config_file_option(option_name="patch-import", + dest="patch_import") (options, args) = parser.parse_args(argv[1:]) gbp.log.setup(options.color, options.verbose) return options, args @@ -359,6 +419,15 @@ def main(argv): author=author, committer=committer, create_missing_branch=options.create_missing_branches) + # Import patches on top of the source tree + # (only for non-native packages with non-orphan packaging) + force_to_branch_head(repo, options.packaging_branch) + if options.patch_import: + spec = parse_spec(os.path.join(repo.path, + options.packaging_dir, + os.path.basename(spec.specfile))) + import_spec_patches(repo, spec) + commit = options.packaging_branch # Create packaging tag repo.create_tag(name=tag, @@ -367,11 +436,7 @@ def main(argv): sign=options.sign_tags, keyid=options.keyid) - if repo.get_branch() == options.packaging_branch: - # Update HEAD if we modified the checked out branch - repo.force_head(options.packaging_branch, hard=True) - # Checkout packaging branch - repo.set_branch(options.packaging_branch) + force_to_branch_head(repo, options.packaging_branch) except KeyboardInterrupt: ret = 1 diff --git a/gbp/scripts/pq_rpm.py b/gbp/scripts/pq_rpm.py index 17e25701..bc8256f9 100755 --- a/gbp/scripts/pq_rpm.py +++ b/gbp/scripts/pq_rpm.py @@ -146,6 +146,25 @@ def generate_git_patches(repo, start, squash_point, end, outdir): return patches +def rm_patch_files(spec): + """ + Delete the patch files listed in the spec files. Doesn't delete patches + marked as not maintained by gbp. + """ + # Remove all old patches from the spec dir + for n, p in spec.patches.iteritems(): + if p['autoupdate']: + f = os.path.join(spec.specdir, p['filename']) + gbp.log.debug("Removing '%s'" % f) + try: + os.unlink(f) + except OSError, (e, msg): + if e != errno.ENOENT: + raise GbpError, "Failed to remove patch: %s" % msg + else: + gbp.log.debug("%s does not exist." % f) + + def update_patch_series(repo, spec, start, end, options): """ Export patches to packaging directory and update spec file accordingly. @@ -159,18 +178,8 @@ def update_patch_series(repo, spec, start, end, options): end, tmpdir) - # Remove all old patches from packaging dir - for n, p in spec.patches.iteritems(): - if p['autoupdate']: - f = os.path.join(spec.specdir, p['filename']) - gbp.log.debug("Removing '%s'" % f) - try: - os.unlink(f) - except OSError, (e, msg): - if e != errno.ENOENT: - raise GbpError, "Failed to remove patch: %s" % msg - else: - gbp.log.debug("%s does not exist." % f) + # Unlink old patch files and generate new patches + rm_patch_files(spec) # Filter "vanilla" patches through write_patch() filenames = [] |