buildpackage/git_archive_single: use GitRepository.archive()
authorMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Tue, 15 May 2012 15:13:43 +0000 (18:13 +0300)
committerMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Fri, 14 Nov 2014 12:22:01 +0000 (14:22 +0200)
Use GitRepository.archive() method like git_archive_submodules() does.
This makes it possible to call git_archive_single() independent of the
callers current working directory.

Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
gbp/scripts/buildpackage.py
gbp/scripts/common/buildpackage.py

index dbf783a..38e5a75 100755 (executable)
@@ -58,7 +58,7 @@ def git_archive(repo, cp, output_dir, treeish, comp_type, comp_level, with_submo
                                    comp_type, comp_level, comp_opts)
 
         else:
-            git_archive_single(treeish, output, prefix,
+            git_archive_single(repo, treeish, output, prefix,
                                comp_type, comp_level, comp_opts)
     except (GitRepositoryError, CommandExecFailed):
         gbp.log.err("Error generating submodules' archives")
index 6e5fa65..a38eaf7 100644 (file)
@@ -21,6 +21,7 @@
 import os, os.path
 import pipes
 import tempfile
+import subprocess
 import shutil
 from gbp.command_wrappers import (CatenateTarArchive, CatenateZipArchive)
 from gbp.errors import GbpError
@@ -94,21 +95,26 @@ def git_archive_submodules(repo, treeish, output, prefix, comp_type, comp_level,
         shutil.rmtree(tempdir)
 
 
-def git_archive_single(treeish, output, prefix, comp_type, comp_level, comp_opts, format='tar'):
+def git_archive_single(repo, treeish, output, prefix, comp_type, comp_level,
+                       comp_opts, format='tar'):
     """
     Create an archive without submodules
 
     Exception handling is left to the caller.
     """
     prefix = sanitize_prefix(prefix)
-    pipe = pipes.Template()
-    pipe.prepend("git archive --format=%s --prefix=%s %s" % (format, prefix, treeish), '.-')
-    if comp_type:
-        pipe.append('%s -c -%s %s' % (comp_type, comp_level,
-                                      " ".join(comp_opts)),  '--')
-    ret = pipe.copy('', output)
-    if ret:
-        raise GbpError("Error creating %s: %d" % (output, ret))
+    with open(output, 'w') as archive_fd:
+        if comp_type:
+            cmd = [comp_type, '--stdout', '-%s' % comp_level] + comp_opts
+        else:
+            cmd = ['cat']
+
+        popen = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=archive_fd)
+        for chunk in repo.archive(format, prefix, None, treeish):
+            popen.stdin.write(chunk)
+        popen.stdin.close()
+        if popen.wait():
+            raise GbpError("Error creating %s: compressor cmd failed" % output)
 
 
 #{ Functions to handle export-dir