summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gbp.conf4
-rw-r--r--gbp/config.py2
-rw-r--r--gbp/deb.py23
-rwxr-xr-xgit-buildpackage47
4 files changed, 53 insertions, 23 deletions
diff --git a/gbp.conf b/gbp.conf
index 277348dd..765f6ca3 100644
--- a/gbp.conf
+++ b/gbp.conf
@@ -31,6 +31,10 @@
#tarball-dir = ../tarballs/
#ignore-new = True
#export = HEAD
+# Compress with bzip2
+#compression = bzip2
+# Use best compression
+#compression-level = best
# Options only affecting git-import-orig
[git-import-orig]
diff --git a/gbp/config.py b/gbp/config.py
index fee3665b..b72b1296 100644
--- a/gbp/config.py
+++ b/gbp/config.py
@@ -53,6 +53,8 @@ class GbpOptionParser(OptionParser):
'id-length' : '0',
'git-author' : 'False',
'ignore-regex' : '',
+ 'compression' : 'gzip',
+ 'compression-level': '9',
}
help = {
'debian-branch':
diff --git a/gbp/deb.py b/gbp/deb.py
index ba9dd0be..ac331198 100644
--- a/gbp/deb.py
+++ b/gbp/deb.py
@@ -18,6 +18,12 @@ from errors import GbpError
# the valid characters.
debian_version_chars = 'a-zA-Z\d.~+-'
+# compression types, extra options and extensions
+compressor_opts = { 'gzip' : [ '-n', 'gz' ],
+ 'bzip2' : [ '', 'bz2' ],
+ 'lzma' : [ '', 'lzma' ],
+ 'xz' : [ '', 'xz' ] }
+
class NoChangelogError(Exception):
"""no changelog found"""
pass
@@ -140,11 +146,12 @@ def parse_changelog(changelog):
except TypeError:
raise ParseChangeLogError, output.split('\n')[0]
return cp
-
-def orig_file(cp):
+
+def orig_file(cp, compression):
"The name of the orig.tar.gz belonging to changelog cp"
- return "%s_%s.orig.tar.gz" % (cp['Source'], cp['Upstream-Version'])
+ ext = compressor_opts[compression][1]
+ return "%s_%s.orig.tar.%s" % (cp['Source'], cp['Upstream-Version'], ext)
def is_native(cp):
@@ -160,15 +167,15 @@ def has_epoch(cp):
except KeyError:
return False
-def has_orig(cp, dir):
+def has_orig(cp, compression, dir):
"Check if orig.tar.gz exists in dir"
try:
- os.stat( os.path.join(dir, orig_file(cp)) )
+ os.stat( os.path.join(dir, orig_file(cp, compression)) )
except OSError:
return False
return True
-def symlink_orig(cp, orig_dir, output_dir, force=False):
+def symlink_orig(cp, compression, orig_dir, output_dir, force=False):
"""
symlink orig.tar.gz from orig_dir to output_dir
@return: True if link was created or src == dst
@@ -180,8 +187,8 @@ def symlink_orig(cp, orig_dir, output_dir, force=False):
if orig_dir == output_dir:
return True
- src = os.path.join(orig_dir, orig_file(cp))
- dst = os.path.join(output_dir, orig_file(cp))
+ src = os.path.join(orig_dir, orig_file(cp, compression))
+ dst = os.path.join(output_dir, orig_file(cp, compression))
if not os.access(src, os.F_OK):
return False
try:
diff --git a/git-buildpackage b/git-buildpackage
index 839af90f..7f2b2d40 100755
--- a/git-buildpackage
+++ b/git-buildpackage
@@ -56,14 +56,19 @@ def git_archive_pipe(prefix, pipe, output, treeish):
return True
-def git_archive(cp, output_dir, treeish):
- "create an orig.tar.gz in output_dir using git_archive"
- output = os.path.join(output_dir, du.orig_file(cp))
+def git_archive(cp, output_dir, treeish, comp_type, comp_level):
+ "create a compressed orig tarball in output_dir using git_archive"
+
+ try:
+ comp_opts = du.compressor_opts[comp_type][0]
+ except KeyError:
+ raise GbpError, "Unsupported compression type '%s'" % comp_type
+
+ output = os.path.join(output_dir, du.orig_file(cp, comp_type))
prefix = "%s-%s" % (cp['Source'], cp['Upstream-Version'])
- gzip_opts = "-9 -n"
pipe = pipes.Template()
- pipe.append('gzip -c %s' % gzip_opts, '--')
+ pipe.append('%s -c -%s %s' % (comp_type, comp_level, comp_opts), '--')
return git_archive_pipe(prefix, pipe, output, treeish)
@@ -107,7 +112,7 @@ def pristine_tar_build_orig(repo, cp, output_dir, options):
pt = PristineTar()
if not repo.has_branch(pt.branch):
print >>sys.stderr, 'Pristine-tar branch "%s" not found' % pt.branch
- pt.checkout(os.path.join(output_dir, du.orig_file(cp)))
+ pt.checkout(os.path.join(output_dir, du.orig_file(cp, options.comp_type)))
return True
else:
return False
@@ -123,10 +128,16 @@ def git_archive_build_orig(repo, cp, output_dir, options):
# fall back to the upstream-branch tip if the tag doesn't exist
if not repo.has_treeish(upstream_tree):
upstream_tree = GbpOptionParser.defaults['upstream-branch']
- print "%s does not exist, creating from '%s'" % (du.orig_file(cp), upstream_tree)
+ print "%s does not exist, creating from '%s'" % (du.orig_file(cp,
+ options.comp_type),
+ upstream_tree)
if not repo.has_treeish(upstream_tree):
raise GbpError # git-ls-tree printed an error message already
- if not git_archive(cp, output_dir, upstream_tree):
+ if options.verbose:
+ print "Building upstream tarball with compression '%s -%s'" % (options.comp_type,
+ options.comp_level)
+ if not git_archive(cp, output_dir, upstream_tree,
+ options.comp_type, options.comp_level):
raise GbpError, "Cannot create upstream tarball at '%s'" % output_dir
@@ -171,6 +182,7 @@ def main(argv):
args = [ arg for arg in argv[1:] if arg.find('--%s' % prefix) == 0 ]
dpkg_args = [ arg for arg in argv[1:] if arg.find('--%s' % prefix) == -1 ]
+ # We handle these although they don't have a --git- prefix
for arg in [ "--help", "-h", "--version" ]:
if arg in dpkg_args:
args.append(arg)
@@ -210,6 +222,10 @@ def main(argv):
help="don't create orig.tar.gz", action="store_true")
orig_group.add_config_file_option(option_name="tarball-dir", dest="tarball_dir",
help="location to look for external tarballs")
+ orig_group.add_config_file_option(option_name="compression", dest="comp_type",
+ help="Compression type, default is '%(compression)s'")
+ orig_group.add_config_file_option(option_name="compression-level", dest="comp_level",
+ help="Compression level, default is '%(compression-level)s'")
branch_group.add_config_file_option(option_name="upstream-branch", dest="upstream_branch")
branch_group.add_config_file_option(option_name="debian-branch", dest="debian_branch")
cmd_group.add_config_file_option(option_name="builder", dest="builder",
@@ -278,7 +294,6 @@ def main(argv):
raise GbpError, "Can't parse version from changelog"
if not options.tag_only:
-
output_dir = prepare_output_dir(options.export_dir)
if options.tarball_dir:
tarball_dir = options.tarball_dir
@@ -287,15 +302,17 @@ def main(argv):
# Get/build the orig.tar.gz if necessary:
if not du.is_native(cp):
+ orig_file = du.orig_file(cp, options.comp_type)
+
# look in tarball_dir first, if found force a symlink to it
if options.tarball_dir:
- print "Looking for orig tarball '%s' at '%s'" % (du.orig_file(cp), tarball_dir)
- if not du.symlink_orig(cp, tarball_dir, output_dir, force=True):
- print "Orig tarball '%s' not found at '%s'" % (du.orig_file(cp), tarball_dir)
+ print "Looking for orig tarball '%s' at '%s'" % (orig_file, tarball_dir)
+ if not du.symlink_orig(cp, options.comp_type, tarball_dir, output_dir, force=True):
+ print "Orig tarball '%s' not found at '%s'" % (orig_file, tarball_dir)
else:
- print "Orig tarball '%s' found at '%s'" % (du.orig_file(cp), tarball_dir)
+ print "Orig tarball '%s' found at '%s'" % (orig_file, tarball_dir)
# build an orig unless the user forbidds it
- if not options.no_create_orig and not du.has_orig(cp, output_dir):
+ if not options.no_create_orig and not du.has_orig(cp, options.comp_type, output_dir):
if not pristine_tar_build_orig(repo, cp, output_dir, options):
git_archive_build_orig(repo, cp, output_dir, options)
@@ -316,7 +333,7 @@ def main(argv):
if options.overlay:
if du.is_native(cp):
raise GbpError, "Cannot overlay Debian native package"
- extract_orig(os.path.join(output_dir, du.orig_file(cp)) , tmp_dir)
+ extract_orig(os.path.join(output_dir, du.orig_file(cp, options.comp_type)), tmp_dir)
print "Exporting '%s' to '%s'" % (options.export, tmp_dir)
dump_tree(tmp_dir, tree)