From 2353ab77c134743873a34455e29c610295af2dd7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Guido=20G=C3=BCnther?= Date: Fri, 18 Mar 2011 12:14:40 +0100 Subject: [PATCH] git-buildpackage: submodule support for dump_tree Heavily based on work by Sean Finney and Chow Loong Jin --- git-buildpackage | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/git-buildpackage b/git-buildpackage index d9bdfdf..1a8c222 100755 --- a/git-buildpackage +++ b/git-buildpackage @@ -74,13 +74,46 @@ def git_archive(cp, output_dir, treeish, comp_type, comp_level): return git_archive_pipe(prefix, pipe, output, treeish) -def dump_tree(export_dir, treeish): +def dump_tree(repo, export_dir, treeish): "dump a tree to output_dir" output_dir = os.path.dirname(export_dir) prefix = os.path.basename(export_dir) + pipe = pipes.Template() + pipe.prepend('git archive --format=tar --prefix=%s/ %s' % (prefix, treeish), '.-') pipe.append('tar -C %s -xf -' % output_dir, '-.') - return git_archive_pipe(prefix, pipe, '', treeish) + top = os.path.abspath(os.path.curdir) + try: + ret = pipe.copy('', '') + if ret: + raise GbpError, "Error in dump_tree archive pipe" + + if 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, err: + gbp.log.err("Error dumping tree to %s: %s" % (output_dir, err[0])) + return False + except GbpError, err: + gbp.log.err(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 def move_old_export(target): @@ -398,7 +431,7 @@ def main(argv): extract_orig(os.path.join(output_dir, du.orig_file(cp, options.comp_type)), tmp_dir) gbp.log.info("Exporting '%s' to '%s'" % (options.export, tmp_dir)) - dump_tree(tmp_dir, tree) + dump_tree(repo, tmp_dir, tree) cp = du.parse_changelog(filename=os.path.join(tmp_dir, 'debian', 'changelog')) export_dir = os.path.join(output_dir, "%s-%s" % (cp['Source'], major)) gbp.log.info("Moving '%s' to '%s'" % (tmp_dir, export_dir)) -- 2.7.4