summaryrefslogtreecommitdiff
path: root/gbp/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'gbp/scripts')
-rw-r--r--gbp/scripts/common/buildpackage.py31
1 files changed, 24 insertions, 7 deletions
diff --git a/gbp/scripts/common/buildpackage.py b/gbp/scripts/common/buildpackage.py
index c80a24f..0522cd6 100644
--- a/gbp/scripts/common/buildpackage.py
+++ b/gbp/scripts/common/buildpackage.py
@@ -34,6 +34,22 @@ wc_name = "WC"
wc_index = ".git/gbp_index"
+def sanitize_prefix(prefix):
+ """
+ Sanitize the prefix used for generating source archives
+
+ >>> sanitize_prefix('')
+ '/'
+ >>> sanitize_prefix('foo/')
+ 'foo/'
+ >>> sanitize_prefix('/foo/bar')
+ 'foo/bar/'
+ """
+ if prefix:
+ return prefix.strip('/') + '/'
+ return '/'
+
+
def git_archive_submodules(repo, treeish, output, prefix, comp_type, comp_level, comp_opts):
"""
Create tar.gz of an archive with submodules
@@ -43,13 +59,13 @@ def git_archive_submodules(repo, treeish, output, prefix, comp_type, comp_level,
Exception handling is left to the caller.
"""
-
+ prefix = sanitize_prefix(prefix)
tarfile = output.rsplit('.', 1)[0]
tempdir = tempfile.mkdtemp()
submodule_tarfile = os.path.join(tempdir, "submodule.tar")
try:
# generate main tarfile
- repo.archive(format='tar', prefix='%s/' % (prefix),
+ repo.archive(format='tar', prefix=prefix,
output=tarfile, treeish=treeish)
# generate each submodule's tarfile and append it to the main archive
@@ -57,7 +73,7 @@ def git_archive_submodules(repo, treeish, output, prefix, comp_type, comp_level,
tarpath = [subdir, subdir[2:]][subdir.startswith("./")]
gbp.log.debug("Processing submodule %s (%s)" % (subdir, commit[0:8]))
- repo.archive(format='tar', prefix='%s/%s/' % (prefix, tarpath),
+ repo.archive(format='tar', prefix='%s%s/' % (prefix, tarpath),
output=submodule_tarfile, treeish=commit, cwd=subdir)
CatenateTarArchive(tarfile)(submodule_tarfile)
@@ -75,8 +91,9 @@ def git_archive_single(treeish, output, prefix, comp_type, comp_level, comp_opts
Exception handling is left to the caller.
"""
+ prefix = sanitize_prefix(prefix)
pipe = pipes.Template()
- pipe.prepend("git archive --format=tar --prefix=%s/ %s" % (prefix, treeish), '.-')
+ 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:
@@ -87,10 +104,10 @@ def git_archive_single(treeish, output, prefix, comp_type, comp_level, comp_opts
def dump_tree(repo, export_dir, treeish, with_submodules):
"dump a tree to output_dir"
output_dir = os.path.dirname(export_dir)
- prefix = os.path.basename(export_dir)
+ prefix = sanitize_prefix(os.path.basename(export_dir))
pipe = pipes.Template()
- pipe.prepend('git archive --format=tar --prefix=%s/ %s' % (prefix, treeish), '.-')
+ pipe.prepend('git archive --format=tar --prefix=%s %s' % (prefix, treeish), '.-')
pipe.append('tar -C %s -xf -' % output_dir, '-.')
top = os.path.abspath(os.path.curdir)
try:
@@ -106,7 +123,7 @@ def dump_tree(repo, export_dir, treeish, with_submodules):
tarpath = [subdir, subdir[2:]][subdir.startswith("./")]
os.chdir(subdir)
pipe = pipes.Template()
- pipe.prepend('git archive --format=tar --prefix=%s/%s/ %s' %
+ pipe.prepend('git archive --format=tar --prefix=%s%s/ %s' %
(prefix, tarpath, commit), '.-')
pipe.append('tar -C %s -xf -' % output_dir, '-.')
ret = pipe.copy('', '')