diff options
-rw-r--r-- | docs/manpages/git-buildpackage.sgml | 8 | ||||
-rw-r--r-- | gbp/config.py | 2 | ||||
-rw-r--r-- | gbp/deb.py | 9 | ||||
-rw-r--r-- | gbp/git.py | 8 | ||||
-rwxr-xr-x | git-buildpackage | 28 |
5 files changed, 51 insertions, 4 deletions
diff --git a/docs/manpages/git-buildpackage.sgml b/docs/manpages/git-buildpackage.sgml index afb9662..a1eac1f 100644 --- a/docs/manpages/git-buildpackage.sgml +++ b/docs/manpages/git-buildpackage.sgml @@ -246,7 +246,13 @@ </term> <listitem> <para>Specifies the upstream tarball compression type. This will be - used to locate and build the upstream tarball if necessary.</para> + used to locate and build the upstream tarball if necessary. The + default is <replaceable>auto</replaceable> which derives the + compression type from the pristine-tar branch if available and falls + back to gzip otherwise. Other options are + <replaceable>gzip</replaceable>, <replaceable>bzip2</replaceable>, + <replaceable>lzma</replaceable> and <replaceable>xz</replaceable>. + </para> </listitem> </varlistentry> <varlistentry> diff --git a/gbp/config.py b/gbp/config.py index 0c57f3c..7c93200 100644 --- a/gbp/config.py +++ b/gbp/config.py @@ -56,7 +56,7 @@ class GbpOptionParser(OptionParser): 'id-length' : '0', 'git-author' : 'False', 'ignore-regex' : '', - 'compression' : 'gzip', + 'compression' : 'auto', 'compression-level': '9', } help = { @@ -166,6 +166,15 @@ def is_native(cp): return [ True, False ]['-' in cp['Version']] +def get_compression(orig_file): + "Given an orig file return the compression used" + ext = orig_file.rsplit('.',1)[1] + for (c, o) in compressor_opts.iteritems(): + if o[1] == ext: + return c + return None + + def has_epoch(cp): """does the topmost version number contain an epoch""" try: @@ -166,6 +166,14 @@ class GitRepository(object): for line in commit: yield line + def get_subject(self, commit): + """Gets the subject of a commit""" + self.__check_path() + out, ret = self.__git_getoutput('show', ['--format=%s', commit]) + if ret: + raise GitRepositoryError, "Error getting subject of commit %s" % commit + return out[0].strip() + def find_tag(self, branch): "find the closest tag to a branch's head" tag, ret = self.__git_getoutput('describe', [ "--abbrev=0", branch ]) diff --git a/git-buildpackage b/git-buildpackage index d5c3ce8..dba20a9 100755 --- a/git-buildpackage +++ b/git-buildpackage @@ -1,7 +1,7 @@ #!/usr/bin/python -u # vim: set fileencoding=utf-8 : # -# (C) 2006,2007,2008 Guido Guenther <agx@sigxcpu.org> +# (C) 2006-2010 Guido Guenther <agx@sigxcpu.org> # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or @@ -27,7 +27,7 @@ import time import gbp.deb as du from gbp.git import (GitRepositoryError, GitRepository, build_tag) from gbp.command_wrappers import (GitTag, Command, RunAtCommand, CommandExecFailed, - PristineTar, RemoveTree, GitAdd) + PristineTar, RemoveTree, GitAdd, PristineTar) from gbp.config import (GbpOptionParser, GbpOptionGroup) from gbp.errors import GbpError from glob import glob @@ -174,6 +174,29 @@ def extract_orig(orig_tarball, dest_dir): # Remove that single folder: os.rmdir(tar_topdir) + +def guess_comp_type(repo, comp_type): + """Guess compression type""" + + if comp_type != 'auto': + try: + dummy = du.compressor_opts[comp_type] + except KeyError: + print >>sys.stderr, "Unknown compression type - guessing." + comp_type = 'auto' + else: + if not repo.has_branch(PristineTar.branch): + comp_type = 'gzip' + print >>sys.stderr, "No pristine tar branch found - assuming %s." % comp_type + else: + tarball = repo.get_subject(PristineTar.branch) + comp_type = du.get_compression(tarball) + if not comp_type: + comp_type = 'gzip' + print >>sys.stderr, "Unknown compression type of %s, assuming %s" % (tarball, comp_type) + return comp_type + + def main(argv): changelog = 'debian/changelog' retval = 0 @@ -304,6 +327,7 @@ def main(argv): else: tarball_dir = output_dir + options.comp_type = guess_comp_type (repo, options.comp_type) # Get/build the orig.tar.gz if necessary: if not du.is_native(cp): orig_file = du.orig_file(cp, options.comp_type) |