Guido Günther wrote:
> Looks good at a first glance. Thanks! Feel free to make more intrusive
> changes if you see fit.

The only changes I'd like to add/fix are:
- do not pass exclude option to tar when repacking since it was already
applied when unpacking.
- substitute .tar only in the basename! Otherwise, some funny errors may
arise:
        "/tmp/foo.tar/bar.tar".replace(".tar", ".gbp.tar") =
"/tmp/foo.gbp.tar/bar.gbp.tar" :)

Please find attached the updated patch.

Cheers,

-- 
Mehdi Dogguy مهدي الدڤي
http://www.pps.jussieu.fr/~dogguy
Tel.: (+33).1.44.27.28.38
>From 4613768d776f7334b9199e4fa52ec0e819b0e0c4 Mon Sep 17 00:00:00 2001
From: Mehdi Dogguy <dog...@pps.jussieu.fr>
Date: Wed, 3 Jun 2009 19:36:27 +0200
Subject: [PATCH] Filter pristine-tar when passing filter option

---
 debian/changelog                   |    6 ++++++
 docs/manpages/git-import-orig.sgml |    8 ++++++++
 gbp/command_wrappers.py            |   13 +++++++++++++
 gbp/config.py                      |    3 +++
 gbp/deb_utils.py                   |   11 +++++++++++
 git-import-orig                    |   12 +++++++++++-
 6 files changed, 52 insertions(+), 1 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index e45bc19..b69bcbd 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,9 @@
+git-buildpackage (0.4.54) unstable; urgency=low
+
+  * Filter pristine-tar when option filter is used (Closes: #520722)
+
+ -- Mehdi Dogguy <dog...@pps.jussieu.fr>  Wed, 03 Jun 2009 19:37:29 +0200
+
 git-buildpackage (0.4.53) unstable; urgency=low
 
   * [b772300] pass --pretty=medium to git show (Closes: #525969)
diff --git a/docs/manpages/git-import-orig.sgml b/docs/manpages/git-import-orig.sgml
index 2c0d44d..e3d618e 100644
--- a/docs/manpages/git-import-orig.sgml
+++ b/docs/manpages/git-import-orig.sgml
@@ -32,6 +32,7 @@
       <arg><option>--upstream-tag=</option><replaceable>tag-format</replaceable></arg>
       <arg><option>--filter=</option><replaceable>pattern</replaceable></arg>
       <arg><option>--[no-]pristine-tar</option></arg>
+      <arg><option>--[no-]filter-pristine-tar</option></arg>
       <arg choice="plain"><replaceable>upstream-source</replaceable></arg>
     </cmdsynopsis>
   </refsynopsisdiv>
@@ -136,6 +137,13 @@
           <para>generate pristine-tar delta file</para>
         </listitem>
       </varlistentry>
+      <varlistentry>
+        <term><option>--filter-pristine-tar</option>
+        </term>
+        <listitem>
+          <para>filter pristine-tar when filter option is used</para>
+        </listitem>
+      </varlistentry>
     </variablelist>
   </refsect1>
   <refsect1>
diff --git a/gbp/command_wrappers.py b/gbp/command_wrappers.py
index 1439cc5..8cfa7cb 100644
--- a/gbp/command_wrappers.py
+++ b/gbp/command_wrappers.py
@@ -132,6 +132,19 @@ class UnpackTarArchive(Command):
         Command.__init__(self, 'tar', exclude + ['-C', dir, decompress, '-xf', archive ])
         self.run_error = 'Couldn\'t unpack "%s"' % self.archive
 
+class RepackTarArchive(Command):
+    """Wrap tar to Repack a gzipped tar archive"""
+    def __init__(self, archive, dir, dest):
+        self.archive = archive
+        self.dir = dir
+
+        if archive.lower().endswith(".bz2"):
+            compress = "--bzip2"
+        else:
+            compress = "--gzip"
+
+        Command.__init__(self, 'tar', ['-C', dir, compress, '-cf', archive, dest])
+        self.run_error = 'Couldn\'t repack "%s"' % self.archive
 
 class RemoveTree(Command):
     "Wrap rm to remove a whole directory tree"
diff --git a/gbp/config.py b/gbp/config.py
index 6fa223a..0ffcc32 100644
--- a/gbp/config.py
+++ b/gbp/config.py
@@ -30,6 +30,7 @@ class GbpOptionParser(OptionParser):
                  'debian-branch'   : 'master',
                  'upstream-branch' : 'upstream',
                  'pristine-tar'    : 'False',
+                 'filter-pristine-tar' : 'False',
                  'sign-tags'       : 'False',
                  'no-create-orig'  : 'False',
                  'keyid'           : '',
@@ -66,6 +67,8 @@ class GbpOptionParser(OptionParser):
                   "GPG keyid to sign tags with, default is '%(keyid)s'",
              'pristine-tar':
                   "use pristine-tar to create .orig.tar.gz, default is '%(pristine-tar)s'",
+             'filter-pristine-tar':
+                  "Filter pristine-tar when filter option is used",
              'filter':
                   "files to filter out during import (can be given multiple times)",
              'git-author':
diff --git a/gbp/deb_utils.py b/gbp/deb_utils.py
index 2879459..03db7b9 100644
--- a/gbp/deb_utils.py
+++ b/gbp/deb_utils.py
@@ -200,6 +200,17 @@ def unpack_orig(archive, tmpdir, filters):
         raise GbpError
     return unpackArchive.dir
 
+def repack_orig(archive, tmpdir, dest):
+    """
+    recreate a new .orig.tar.gz from tmpdir (useful when using filter option)
+    """
+    try:
+        repackArchive = gbpc.RepackTarArchive(archive, tmpdir, dest)
+        repackArchive()
+    except gbpc.CommandExecFailed:
+        print >>sys.stderr, "Failed to create %s" % archive
+        raise GbpError
+    return repackArchive.dir
 
 def tar_toplevel(dir):
     """tar archives can contain a leading directory not"""
diff --git a/git-import-orig b/git-import-orig
index e2529f6..63b5615 100755
--- a/git-import-orig
+++ b/git-import-orig
@@ -27,7 +27,7 @@ import subprocess
 import tarfile
 import time
 import gbp.command_wrappers as gbpc
-from gbp.deb_utils import parse_changelog, unpack_orig, NoChangelogError, has_epoch, tar_toplevel
+from gbp.deb_utils import parse_changelog, unpack_orig, repack_orig, NoChangelogError, has_epoch, tar_toplevel
 from gbp.git_utils import (GitRepositoryError, GitRepository, build_tag)
 from gbp.config import GbpOptionParser
 from gbp.errors import (GbpError, GbpNothingImported)
@@ -246,6 +246,7 @@ def main(argv):
     parser.add_config_file_option(option_name="upstream-tag", dest="upstream_tag")
     parser.add_config_file_option(option_name="filter", dest="filters", action="append")
     parser.add_boolean_config_file_option(option_name="pristine-tar", dest="pristine_tar")
+    parser.add_boolean_config_file_option(option_name="filter-pristine-tar", dest="filter_pristine_tar")
     (options, args) = parser.parse_args(argv[1:])
 
     if options.verbose:
@@ -310,6 +311,15 @@ on howto create it otherwise use --upstream-branch to specify it.
                 if options.verbose:
                     print "Unpacked %s to '%s'" % (archive , tmpdir)
                 orig_dir = tar_toplevel(tmpdir)
+                if options.filter_pristine_tar and len(options.filters) > 0:
+                    archivetmp = os.path.basename(archive)
+                    archive = os.path.join(
+                        os.path.dirname(archive),
+                        archivetmp.replace(".tar", ".gbp.tar")
+                        )
+                    repack_orig(archive, tmpdir, os.path.basename(orig_dir))
+                    if options.verbose:
+                        print "Filter pristine-tar: repacking %s from '%s'" % (archive, tmpdir)
             try:
                 cp = parse_changelog('debian/changelog')
                 pristine_orig = symlink_orig(archive, cp['Source'], version)
-- 
1.6.3.1

Reply via email to