Add compression=auto
authorGuido Günther <agx@sigxcpu.org>
Fri, 25 Jun 2010 22:18:55 +0000 (00:18 +0200)
committerGuido Günther <agx@sigxcpu.org>
Fri, 25 Jun 2010 23:09:06 +0000 (01:09 +0200)
to guess compression type of upstream tarball from pristine-tar branch.
This is now the default.

Closes: #566993

docs/manpages/git-buildpackage.sgml
gbp/config.py
gbp/deb.py
gbp/git.py
git-buildpackage

index afb9662..a1eac1f 100644 (file)
         </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>
index 0c57f3c..7c93200 100644 (file)
@@ -56,7 +56,7 @@ class GbpOptionParser(OptionParser):
                  'id-length'       : '0',
                  'git-author'      : 'False',
                  'ignore-regex'    : '',
-                 'compression'     : 'gzip',
+                 'compression'     : 'auto',
                  'compression-level': '9',
              }
     help = {
index b50abbd..0663977 100644 (file)
@@ -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:
index 7743bdd..05e8dbb 100644 (file)
@@ -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 ])
index d5c3ce8..dba20a9 100755 (executable)
@@ -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)