tags + patch Hello,
On Mon, Jul 13, 2009 at 09:26:50AM +0200, Guido Günther wrote: > I'd certainly be happy to apply clean patches doing that though. ---end quoted text--- Here's a patch I made to implement this functionality in a basic manner. -- أحمد المحمودي (Ahmed El-Mahmoudy) Digital design engineer GPG KeyID: 0xEDDDA1B7 (@ subkeys.pgp.net) GPG Fingerprint: 8206 A196 2084 7E6D 0DF8 B176 BC19 6A94 EDDD A1B7
Implemented basic overlay functionality Thanks to Muayyad Alsadi for helping me with the extract_orig function. diff --git a/gbp/config.py b/gbp/config.py index 0ffcc32..9aec395 100644 --- a/gbp/config.py +++ b/gbp/config.py @@ -43,6 +43,7 @@ class GbpOptionParser(OptionParser): 'git-log' : '--no-merges', 'export' : 'HEAD', 'export-dir' : '', + 'overlay' : 'False', 'tarball-dir' : '', 'ignore-new' : 'False', 'meta' : 'False', @@ -79,6 +80,8 @@ class GbpOptionParser(OptionParser): "parse meta tags in commit messages, default is '%(meta)s'", 'ignore-new': "build with uncommited changes in the source tree, default is '%(ignore-new)s'", + 'overlay': + "extract orig tarball when using export-dir option, default is '%(overlay)s'", } config_files = [ '/etc/git-buildpackage/gbp.conf', os.path.expanduser('~/.gbp.conf'), diff --git a/git-buildpackage b/git-buildpackage index 2e9ebdd..1356631 100755 --- a/git-buildpackage +++ b/git-buildpackage @@ -29,6 +29,7 @@ from gbp.command_wrappers import (GitTag, Command, RunAtCommand, CommandExecFail PristineTar, RemoveTree, GitAdd) from gbp.config import (GbpOptionParser, GbpOptionGroup) from gbp.errors import GbpError +from glob import glob # when we want to reference the index in a treeish context we call it: index_name = "INDEX" @@ -136,6 +137,32 @@ def write_wc(repo): return tree +def extract_orig(orig_tarball, dest_dir): + """extract orig tarball to export dir before exporting from git""" + print "Extracting %s to '%s'" % (os.path.basename(orig_tarball), dest_dir) + + # TODO: do not create this dir ? remove the dir if something wrong goes with tar ? + os.mkdir(dest_dir) + r=os.system('tar -zxf "%s" -C "%s"' % (orig_tarball, dest_dir)) + if r!=0: + raise "Could not extract orig tarball" + + # Check if tarball extracts into a single folder or not: + r=glob("%s/*" % dest_dir) + r.extend(glob("%s/.*" % dest_dir)) # include hidden files and folders + fdnum=len(r) # number of files & folders + dnum=len(filter(lambda f: os.path.isdir(f) ,r)) # number of folders + + if fdnum==1 and dnum==1: + # If it extracts a single folder, move all of its contents to dest_dir: + r1=glob("%s/*" % r[0]) + r1.extend(glob("%s/.*" % r[0])) # include hidden files and folders + for f in r1: + os.rename(f, os.path.join(dest_dir, os.path.basename(f))) + + # Remove that single folder: + os.rmdir(r[0]) + def main(argv): changelog = 'debian/changelog' retval = 0 @@ -192,6 +219,7 @@ def main(argv): help="export treeish object TREEISH, default is '%(export)s'", metavar="TREEISH") export_group.add_option("--git-dont-purge", action="store_false", dest="purge", default=True, help="retain exported package build directory") + export_group.add_boolean_config_file_option(option_name="overlay", dest="overlay") (options, args) = parser.parse_args(args) if options.verbose: @@ -242,6 +270,20 @@ def main(argv): else: tarball_dir = output_dir + # Get/build the orig.tar.gz if necessary: + if not du.is_native(cp): + # look in tarball_dir first, if found force a symlink to it + if options.tarball_dir: + print "Looking for orig tarball '%s' at '%s'" % (du.orig_file(cp), tarball_dir) + if not du.symlink_orig(cp, tarball_dir, output_dir, force=True): + print "Orig tarball '%s' not found at '%s'" % (du.orig_file(cp), tarball_dir) + else: + print "Orig tarball '%s' found at '%s'" % (du.orig_file(cp), tarball_dir) + # build an orig unless the user forbidds it + if not options.no_create_orig and not du.has_orig(cp, output_dir): + if not pristine_tar_build_orig(repo, cp, output_dir, options): + git_archive_build_orig(repo, cp, output_dir, options) + # Export to another build dir if requested: if options.export_dir: # write a tree of the index if necessary: @@ -254,6 +296,11 @@ def main(argv): if not repo.has_treeish(tree): raise GbpError # git-ls-tree printed an error message already tmp_dir = os.path.join(output_dir, "%s-tmp" % cp['Source']) + + # Extract orig tarball if git-overlay option is selected: + if options.overlay: + extract_orig(os.path.join(output_dir, du.orig_file(cp)) , tmp_dir) + print "Exporting '%s' to '%s'" % (options.export, tmp_dir) dump_tree(tmp_dir, tree) cp = du.parse_changelog(os.path.join(tmp_dir, 'debian', 'changelog')) @@ -262,20 +309,6 @@ def main(argv): move_old_export(export_dir) os.rename(tmp_dir, export_dir) - # Get/build the orig.tar.gz if necessary: - if not du.is_native(cp): - # look in tarball_dir first, if found force a symlink to it - if options.tarball_dir: - print "Looking for orig tarball '%s' at '%s'" % (du.orig_file(cp), tarball_dir) - if not du.symlink_orig(cp, tarball_dir, output_dir, force=True): - print "Orig tarball '%s' not found at '%s'" % (du.orig_file(cp), tarball_dir) - else: - print "Orig tarball '%s' found at '%s'" % (du.orig_file(cp), tarball_dir) - # build an orig unless the user forbidds it - if not options.no_create_orig and not du.has_orig(cp, output_dir): - if not pristine_tar_build_orig(repo, cp, output_dir, options): - git_archive_build_orig(repo, cp, output_dir, options) - if options.export_dir: build_dir = export_dir else: