diff options
author | Markus Lehtonen <markus.lehtonen@linux.intel.com> | 2012-06-19 16:53:51 +0300 |
---|---|---|
committer | Markus Lehtonen <markus.lehtonen@linux.intel.com> | 2013-04-03 09:13:50 +0300 |
commit | f0463bbeb469cbb30b4804ebbc504b40e5725aa8 (patch) | |
tree | 1b8a142d284823ae0f2c4267f8895ab0070a62c8 | |
parent | a1f58a71f3b040de2349e91cefaa08d0ac68982b (diff) | |
download | git-buildpackage-f0463bbeb469cbb30b4804ebbc504b40e5725aa8.tar.gz git-buildpackage-f0463bbeb469cbb30b4804ebbc504b40e5725aa8.tar.bz2 git-buildpackage-f0463bbeb469cbb30b4804ebbc504b40e5725aa8.zip |
GitRepository: rewrite git_archive()
Add support for filtering. That is, allow the caller to pipe the output
of git-archive through a filter command, usually a compression program.
This utilizes the new filtering functionality of the _git_inout()
method.
Also, gets rid of the hackish use of 'cwd' option.
The 'output' is now considered to be relative to the caller's cwd, not
the git repo dir. This should be more intuitive.
Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
-rw-r--r-- | gbp/git/repository.py | 24 | ||||
-rw-r--r-- | gbp/scripts/common/buildpackage.py | 7 | ||||
-rw-r--r-- | tests/test_PristineTar.py | 2 |
3 files changed, 24 insertions, 9 deletions
diff --git a/gbp/git/repository.py b/gbp/git/repository.py index 33ec2201..9d9ebfc3 100644 --- a/gbp/git/repository.py +++ b/gbp/git/repository.py @@ -1514,7 +1514,8 @@ class GitRepository(object): return output #} - def archive(self, format, prefix, output, treeish, **kwargs): + def archive(self, format, prefix, output, treeish, filter_fn=None, + filter_args={}): """ Create an archive from a treeish @@ -1526,13 +1527,24 @@ class GitRepository(object): @type output: C{str} @param treeish: the treeish to create the archive from @type treeish: C{str} - @param kwargs: additional commandline options passed to git-archive + @param filter_fn: function to filter the output of git-archive + @type filter_fn: C{function} + @param filter_args: arguments to pass to the filter fn + @type filter_args: C{dict} """ - args = [ '--format=%s' % format, '--prefix=%s' % prefix, - '--output=%s' % output, treeish ] - out, ret = self._git_getoutput('archive', args, **kwargs) + args = GitArgs('--format=%s' % format, '--prefix=%s' % prefix, treeish) + + try: + with open(output, 'w') as f_out: + dummy, stderr, ret = self._git_inout('archive', args.args, + output_f=f_out, + filter_fn=filter_fn, + filter_kwargs=filter_args) + except IOError, err: + raise GitRepositoryError("Unable to archive: %s" % err) if ret: - raise GitRepositoryError("Unable to archive %s" % treeish) + raise GitRepositoryError("Unable to archive %s, git-archive "\ + "failed" % treeish) def collect_garbage(self, auto=False): """ diff --git a/gbp/scripts/common/buildpackage.py b/gbp/scripts/common/buildpackage.py index db8a7b6d..3f1071ea 100644 --- a/gbp/scripts/common/buildpackage.py +++ b/gbp/scripts/common/buildpackage.py @@ -56,10 +56,13 @@ def git_archive_submodules(repo, treeish, output, prefix, comp_type, comp_level, # generate each submodule's arhive and append it to the main archive for (subdir, commit) in repo.get_submodules(treeish): tarpath = [subdir, subdir[2:]][subdir.startswith("./")] + subrepo = GitRepository(os.path.join(repo.path, subdir)) gbp.log.debug("Processing submodule %s (%s)" % (subdir, commit[0:8])) - repo.archive(format=format, prefix='%s/%s/' % (prefix, tarpath), - output=submodule_archive, treeish=commit, cwd=subdir) + subrepo.archive(format=format, + prefix='%s/%s/' % (prefix, tarpath), + output=submodule_archive, + treeish=commit) if format == 'tar': CatenateTarArchive(main_archive)(submodule_archive) elif format == 'zip': diff --git a/tests/test_PristineTar.py b/tests/test_PristineTar.py index f1c6411e..55ea0897 100644 --- a/tests/test_PristineTar.py +++ b/tests/test_PristineTar.py @@ -71,7 +71,7 @@ def test_create_tarball(): >>> import gbp.deb.git >>> repo = gbp.deb.git.DebianGitRepository(repo_dir) - >>> repo.archive('tar', 'upstream/', '../upstream_1.0.orig.tar', 'upstream') + >>> repo.archive('tar', 'upstream/', '%s/../upstream_1.0.orig.tar' % repo_dir, 'upstream') >>> gbp.command_wrappers.Command('gzip', [ '-n', '%s/../upstream_1.0.orig.tar' % repo_dir])() """ |