diff options
author | Guido Günther <agx@sigxcpu.org> | 2011-03-21 14:20:21 +0100 |
---|---|---|
committer | Guido Günther <agx@sigxcpu.org> | 2011-03-21 21:05:34 +0100 |
commit | 1021f8439fcdced1699414d686d299b49753eff4 (patch) | |
tree | b72f14784ade8759d5880e0e687839da60d2adab /git-buildpackage | |
parent | 0095808588283b8274aeef1a7670d80ef71438e2 (diff) |
git-buildpackage: special case non-submodule tarfile generation
Tarfile generation with submodules is slower since we need to
concatenate several tarfiles and compress afterwards. So special case
the common non submodule case and add a testcase to check the tarfiles
content.
Diffstat (limited to 'git-buildpackage')
-rwxr-xr-x | git-buildpackage | 77 |
1 files changed, 52 insertions, 25 deletions
diff --git a/git-buildpackage b/git-buildpackage index fa7abe7..26d18fa 100755 --- a/git-buildpackage +++ b/git-buildpackage @@ -45,58 +45,85 @@ wc_name = "WC" wc_index = ".git/gbp_index" -def git_archive(repo, cp, output_dir, treeish, comp_type, comp_level): - "create a compressed orig tarball in output_dir using git_archive" +def git_archive_submodules(repo, treeish, output, prefix, comp_type, comp_level, comp_opts): + """ + Create tar.gz of an archive with submodules - try: - comp_opts = du.compressor_opts[comp_type][0] - except KeyError: - raise GbpError, "Unsupported compression type '%s'" % comp_type + since git-archive always writes an end of tarfile trailer we concatenate + the generated archives using tar and compress the result. - output = os.path.join(output_dir, du.orig_file(cp, comp_type)) - prefix = "%s-%s" % (cp['Source'], cp['Upstream-Version']) + Exception handling is left to the caller. + """ - # make space for main and submodule tarfiles + tarfile = output.rsplit('.', 1)[0] tempdir = tempfile.mkdtemp() - main_tarfile = os.path.join(tempdir, "main.tar") submodule_tarfile = os.path.join(tempdir, "submodule.tar") - try: # generate main tarfile repo.archive(format='tar', prefix='%s/' % (prefix), - output=main_tarfile, treeish=treeish) + output=tarfile, treeish=treeish) - # generate and integrate each submodule's tarfile into main_tarfile - if repo.has_submodules(): - repo.update_submodules() + # generate each submodule's tarfile and append it to the main archive for (subdir, commit) in repo.get_submodules(treeish): tarpath = [subdir, subdir[2:]][subdir.startswith("./")] - gbp.log.info("Processing submodule %s (%s)" % (subdir, commit[0:8])) + gbp.log.debug("Processing submodule %s (%s)" % (subdir, commit[0:8])) repo.archive(format='tar', prefix='%s/%s/' % (prefix, tarpath), output=submodule_tarfile, treeish=commit, cwd=subdir) - CatenateTarArchive(main_tarfile)(submodule_tarfile) + CatenateTarArchive(tarfile)(submodule_tarfile) # compress the output - pipe = pipes.Template() - pipe.append('%s -c -%s %s' % (comp_type, comp_level, comp_opts), '--') - ret = pipe.copy(main_tarfile, output) + ret = os.system("%s -%s %s %s" % (comp_type, comp_level, comp_opts, tarfile)) if ret: raise GbpError("Error creating %s: %d" % (output, ret)) + finally: + shutil.rmtree(tempdir) + + +def git_archive_single(repo, treeish, output, prefix, comp_type, comp_level, comp_opts): + """ + Create tar.gz of an archive without submodules + + Exception handling is left to the caller. + """ + pipe = pipes.Template() + pipe.prepend("git archive --format=tar --prefix=%s/ %s" % (prefix, treeish), '.-') + pipe.append('%s -c -%s %s' % (comp_type, comp_level, comp_opts), '--') + ret = pipe.copy('', output) + if ret: + raise GbpError("Error creating %s: %d" % (output, ret)) + + +def git_archive(repo, cp, output_dir, treeish, comp_type, comp_level): + "create a compressed orig tarball in output_dir using git_archive" + try: + comp_opts = du.compressor_opts[comp_type][0] + except KeyError: + raise GbpError, "Unsupported compression type '%s'" % comp_type + + output = os.path.join(output_dir, du.orig_file(cp, comp_type)) + prefix = "%s-%s" % (cp['Source'], cp['Upstream-Version']) + + try: + if repo.has_submodules(): + repo.update_submodules() + git_archive_submodules(repo, treeish, output, prefix, + comp_type, comp_level, comp_opts) + + else: + git_archive_single(repo, treeish, output, prefix, + comp_type, comp_level, comp_opts) except CommandExecFailed: gbp.log.err("Error generating submodules' archives") return False - except GbpError, err: - gbp.log.err(err) - return False except OSError, err: gbp.log.err("Error creating %s: %s" % (output, err[0])) return False + except GbpError: + raise except Exception as e: gbp.log.err("Error creating %s: %s" % (output, e)) return False - finally: - shutil.rmtree(tempdir) return True |