diff options
author | Markus Lehtonen <markus.lehtonen@linux.intel.com> | 2012-06-05 15:18:24 +0300 |
---|---|---|
committer | Tzafrir Cohen <tzafrir@debian.org> | 2015-03-26 14:21:52 +0200 |
commit | e4e3cb905c99d2b021c8fb6028e9ef92cd8d57ab (patch) | |
tree | 0adf25f3604b45ac0af7b554e97e5f2cbddac327 /gbp/scripts/common/buildpackage.py | |
parent | 834a98b2edeeadca8a9c0526d5bb92239be8c1fb (diff) |
buildpackage/dump_tree: use GitRepository.archive()
Make dump_tree() utilize the GitRepository.archive() method - similarly
to git_archive_submodules() - instead of ad-hoc Python pipes. This makes
dump_tree() work independent of the callers current working directory.
Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
Diffstat (limited to 'gbp/scripts/common/buildpackage.py')
-rw-r--r-- | gbp/scripts/common/buildpackage.py | 72 |
1 files changed, 32 insertions, 40 deletions
diff --git a/gbp/scripts/common/buildpackage.py b/gbp/scripts/common/buildpackage.py index 2e53b78..7aeebe0 100644 --- a/gbp/scripts/common/buildpackage.py +++ b/gbp/scripts/common/buildpackage.py @@ -22,7 +22,10 @@ import os, os.path import pipes import tempfile import shutil +import subprocess + from gbp.command_wrappers import (CatenateTarArchive) +from gbp.git.repository import GitRepository, GitRepositoryError from gbp.errors import GbpError import gbp.log @@ -100,53 +103,42 @@ def git_archive_single(treeish, output, prefix, comp_type, comp_level, comp_opts raise GbpError("Error creating %s: %d" % (output, ret)) +def untar_data(outdir, data): + """Extract tar provided as an iterable""" + popen = subprocess.Popen(['tar', '-C', outdir, '-x'], + stdin=subprocess.PIPE) + for chunk in data: + popen.stdin.write(chunk) + popen.stdin.close() + if popen.wait(): + raise GbpError("Error extracting tar to %s" % outdir) + + #{ Functions to handle export-dir def dump_tree(repo, export_dir, treeish, with_submodules, recursive=True): - "dump a tree to output_dir" - output_dir = os.path.dirname(export_dir) - prefix = sanitize_prefix(os.path.basename(export_dir)) + """Dump a git tree-ish to output_dir""" + if not os.path.exists(export_dir): + os.makedirs(export_dir) if recursive: - paths = [] + paths = '' else: - paths = ["'%s'" % nam for _mod, typ, _sha, nam in - repo.list_tree(treeish) if typ == 'blob'] - - pipe = pipes.Template() - pipe.prepend('git archive --format=tar --prefix=%s %s -- %s' % - (prefix, treeish, ' '.join(paths)), '.-') - pipe.append('tar -C %s -xf -' % output_dir, '-.') - top = os.path.abspath(os.path.curdir) + paths = [nam for _mod, typ, _sha, nam in repo.list_tree(treeish) if + typ == 'blob'] try: - ret = pipe.copy('', '') - if ret: - raise GbpError("Error in dump_tree archive pipe") - - if recursive and with_submodules: - if repo.has_submodules(): - repo.update_submodules() + data = repo.archive('tar', '', None, treeish, paths) + untar_data(export_dir, data) + if recursive and with_submodules and repo.has_submodules(): + repo.update_submodules() for (subdir, commit) in repo.get_submodules(treeish): - gbp.log.info("Processing submodule %s (%s)" % (subdir, commit[0:8])) - tarpath = [subdir, subdir[2:]][subdir.startswith("./")] - os.chdir(subdir) - pipe = pipes.Template() - pipe.prepend('git archive --format=tar --prefix=%s%s/ %s' % - (prefix, tarpath, commit), '.-') - pipe.append('tar -C %s -xf -' % output_dir, '-.') - ret = pipe.copy('', '') - os.chdir(top) - if ret: - raise GbpError("Error in dump_tree archive pipe in submodule %s" % subdir) - except OSError as err: - gbp.log.err("Error dumping tree to %s: %s" % (output_dir, err[0])) - return False - except GbpError as err: - gbp.log.err(err) + gbp.log.info("Processing submodule %s (%s)" % (subdir, + commit[0:8])) + subrepo = GitRepository(os.path.join(repo.path, subdir)) + prefix = [subdir, subdir[2:]][subdir.startswith("./")] + '/' + data = subrepo.archive('tar', prefix, None, treeish) + untar_data(export_dir, data) + except GitRepositoryError as err: + gbp.log.err("Git error when dumping tree: %s" % err) return False - except Exception as e: - gbp.log.err("Error dumping tree to %s: %s" % (output_dir, e)) - return False - finally: - os.chdir(top) return True |