From: Markus Lehtonen Date: Thu, 7 Jun 2012 14:20:21 +0000 (+0300) Subject: rpm: support generating compressed patches X-Git-Tag: tizen/0.6.22-20150206~111 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9e032926e4cea451f00e0410a909c249ccb03fb1;p=tools%2Fgit-buildpackage.git rpm: support generating compressed patches This patch adds the support to generate compressed patches. User can define the patch file size limit after which patches gzipped. Re-writes the write_patch() function(s) and now uses the same-and-only write_patch() for buildpackage-rpm and pq-rpm. Signed-off-by: Markus Lehtonen --- diff --git a/gbp-rpm.conf b/gbp-rpm.conf index 15529f1..2e31a68 100644 --- a/gbp-rpm.conf +++ b/gbp-rpm.conf @@ -24,6 +24,8 @@ #packaging-dir=rpm # Spec file to be used #spec-file = gbp.spec +# Compress auto-generated patches +#patch-export-compress=100k # Export patches with numbering in filenames #patch-numbers = False diff --git a/gbp/config.py b/gbp/config.py index 8c3a256..6ae16e0 100644 --- a/gbp/config.py +++ b/gbp/config.py @@ -610,6 +610,7 @@ class GbpOptionParserRpm(GbpOptionParser): 'rpmbuild-srpmdir' : 'SRPMS', 'rpmbuild-buildrootdir' : 'BUILDROOT', 'patch-export' : 'False', + 'patch-export-compress' : '0', 'merge' : 'False', 'pristine-tarball-name' : 'auto', }) @@ -644,6 +645,10 @@ class GbpOptionParserRpm(GbpOptionParser): 'patch-export': "Create patches between upstream and export-treeish, default " "is '%(patch-export)s'", + 'patch-export-compress': + "Compress (auto-generated) patches larger than given number of " + "bytes, 0 never compresses, default is " + "'%(patch-export-compress)s'", 'pristine-tarball-name': "Filename to record to pristine-tar, set to 'auto' to not " "mangle the file name, default is '%(pristine-tarball-name)s'", diff --git a/gbp/scripts/buildpackage_rpm.py b/gbp/scripts/buildpackage_rpm.py index bef4623..f6c72f2 100755 --- a/gbp/scripts/buildpackage_rpm.py +++ b/gbp/scripts/buildpackage_rpm.py @@ -26,6 +26,7 @@ import tempfile import shutil import re from datetime import datetime +import gzip import gbp.rpm as rpm from gbp.rpm.policy import RpmPkgPolicy @@ -363,9 +364,12 @@ def parse_args(argv, prefix): export_group.add_option("--git-export-only", action="store_true", dest="export_only", default=False, help="only export packaging files, don't build") export_group.add_boolean_config_file_option("patch-export", dest="patch_export") + export_group.add_config_file_option("patch-export-compress", dest="patch_export_compress") export_group.add_boolean_config_file_option(option_name="patch-numbers", dest="patch_numbers") options, args = parser.parse_args(args) + options.patch_export_compress = rpm.string_to_int(options.patch_export_compress) + gbp.log.setup(options.color, options.verbose) if options.retag: if not options.tag and not options.tag_only: diff --git a/gbp/scripts/pq_rpm.py b/gbp/scripts/pq_rpm.py index 480e382..204091e 100755 --- a/gbp/scripts/pq_rpm.py +++ b/gbp/scripts/pq_rpm.py @@ -26,6 +26,7 @@ import sys import tempfile import re import gzip +import subprocess from gbp.config import (GbpOptionParserRpm, GbpOptionGroup) from gbp.rpm.git import (GitRepositoryError, RpmGitRepository) from gbp.git import GitModifier @@ -35,7 +36,7 @@ from gbp.errors import GbpError import gbp.log from gbp.patch_series import (PatchSeries, Patch) from gbp.pkg import parse_archive_filename -from gbp.rpm import (SpecFile, guess_spec) +from gbp.rpm import (SpecFile, guess_spec, string_to_int) from gbp.scripts.common.pq import (is_pq_branch, pq_branch_name, pq_branch_base, parse_gbp_commands, format_patch, format_diff, @@ -43,6 +44,23 @@ from gbp.scripts.common.pq import (is_pq_branch, pq_branch_name, pq_branch_base, apply_and_commit_patch, drop_pq) +def compress_patches(patches, compress_size=0): + """ + Rename and/or compress patches + """ + ret_patches = [] + for patch in patches: + # Compress if patch file is larger than "threshold" value + suffix = '' + if compress_size and os.path.getsize(patch) > compress_size: + gbp.log.debug("Compressing %s" % os.path.basename(patch)) + subprocess.Popen(['gzip', '-n', patch]).communicate() + suffix = '.gz' + + ret_patches.append(os.path.basename(patch) + suffix) + return ret_patches + + def generate_patches(repo, start, end, outdir, options): """ Generate patch files from git @@ -86,6 +104,9 @@ def generate_patches(repo, start, end, outdir, options): if patch_fn: patches.append(patch_fn) + # Compress + patches = compress_patches(patches, options.patch_export_compress) + return patches, commands @@ -371,9 +392,12 @@ def main(argv): parser.add_option("--export-rev", action="store", dest="export_rev", default="", help="Export patches from treeish object TREEISH instead " "of head of patch-queue branch", metavar="TREEISH") + parser.add_config_file_option("patch-export-compress", + dest="patch_export_compress") (options, args) = parser.parse_args(argv) gbp.log.setup(options.color, options.verbose) + options.patch_export_compress = string_to_int(options.patch_export_compress) if len(args) < 2: gbp.log.err("No action given.")