rpm: add --orig-prefix option
authorMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Thu, 14 Jun 2012 16:34:09 +0000 (19:34 +0300)
committerMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Tue, 3 Mar 2015 08:07:46 +0000 (10:07 +0200)
Adds a new option --orig-prefix that affects the prefix of the
generated/imported orig tarballs.

For git-buildpackage-rpm, it defines the prefix of tarballs generated by
the tool, 'auto' (default) makes gbp to guess the prefix, as before.
NOTE: this doesn't affect the tarballs checked out from pristine-tar
(i.e. if --pristine-tar is defined) or tarballs that are already present
(see --git-tarball-dir option).

For git-import-orig, this new option affects the prefix of tarballs
imported into pristine-tar branch. If set to 'auto' (default) gbp
doesn't mangle the prefix.

Other tools (e.g. git-import-srpm) are not affected.

Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
gbp/config.py
gbp/scripts/buildpackage_rpm.py
gbp/scripts/import_orig_rpm.py

index 7c486c9a19c1e2e2edde3f2d60b5e43de4786fff..24444d500d8bd5f61a1da6284664a0527f3b292a 100644 (file)
@@ -626,6 +626,7 @@ class GbpOptionParserRpm(GbpOptionParser):
                                            'debian/gbp.conf'],
             'merge'                     : 'False',
             'pristine-tarball-name'     : 'auto',
+            'orig-prefix'               : 'auto',
                     })
 
     help = dict(GbpOptionParser.help)
@@ -680,6 +681,9 @@ class GbpOptionParserRpm(GbpOptionParser):
             'pristine-tarball-name':
                 "Filename to record to pristine-tar, set to 'auto' to not "
                 "mangle the file name, default is '%(pristine-tarball-name)s'",
+            'orig-prefix':
+                "Prefix (dir) to be used when generating/importing tarballs, "
+                "default is '%(orig-prefix)s'",
                  })
 
 # vim:et:ts=4:sw=4:et:sts=4:ai:set list listchars=tab\:»·,trail\:·:
index c402d2c1fc05374bd26ea468edcda416ad8c6bec..a259f9a077a829b65498cfdfb8c672a246601d99 100755 (executable)
@@ -53,7 +53,7 @@ def makedir(path):
     return path
 
 
-def git_archive(repo, spec, output_dir, treeish, comp_level,
+def git_archive(repo, spec, output_dir, treeish, prefix, comp_level,
                 with_submodules):
     "Create a compressed orig tarball in output_dir using git_archive"
     comp_opts = ''
@@ -62,17 +62,18 @@ def git_archive(repo, spec, output_dir, treeish, comp_level,
 
     output = os.path.join(output_dir, spec.orig_src['filename'])
 
+    # Remove extra slashes from prefix, will be added by git_archive_x funcs
+    prefix = prefix.strip('/')
     try:
         if repo.has_submodules(treeish) and with_submodules:
             repo.update_submodules()
-            git_archive_submodules(repo, treeish, output,
-                                   spec.orig_src['prefix'],
+            git_archive_submodules(repo, treeish, output, prefix,
                                    spec.orig_src['compression'],
                                    comp_level, comp_opts,
                                    spec.orig_src['archive_fmt'])
 
         else:
-            git_archive_single(repo, treeish, output, spec.orig_src['prefix'],
+            git_archive_single(repo, treeish, output, prefix,
                                spec.orig_src['compression'], comp_level,
                                comp_opts, spec.orig_src['archive_fmt'])
     except (GitRepositoryError, CommandExecFailed):
@@ -222,7 +223,8 @@ def git_archive_build_orig(repo, spec, output_dir, options):
                       "'%s -%s'" % (spec.orig_src['compression'],
                                     options.comp_level))
     if not git_archive(repo, spec, output_dir, upstream_tree,
-                       options.comp_level, options.with_submodules):
+                       options.orig_prefix, options.comp_level,
+                       options.with_submodules):
         raise GbpError("Cannot create upstream tarball at '%s'" % \
                         output_dir)
     return upstream_tree
@@ -417,6 +419,8 @@ def build_parser(name, prefix=None, git_treeish=None):
                     dest="comp_level",
                     help="Compression level, default is "
                          "'%(compression-level)s'")
+    orig_group.add_config_file_option(option_name="orig-prefix",
+                    dest="orig_prefix")
     branch_group.add_config_file_option(option_name="upstream-branch",
                     dest="upstream_branch")
     branch_group.add_config_file_option(option_name="packaging-branch",
@@ -598,6 +602,15 @@ def main(argv):
                     raise GbpError("Error exporting packaging files: %s" % err)
             spec.specdir = os.path.abspath(spec_dir)
 
+            if options.orig_prefix != 'auto':
+                orig_prefix_fields = dict(spec.version,
+                                          version = spec.upstreamversion,
+                                          name=spec.name)
+                options.orig_prefix = format_str(options.orig_prefix,
+                                                 orig_prefix_fields)
+            elif spec.orig_src:
+                options.orig_prefix = spec.orig_src['prefix']
+
             # Get/build the orig tarball
             if is_native(repo, options):
                 if spec.orig_src and not options.no_create_orig:
@@ -610,7 +623,7 @@ def main(argv):
                                       (spec.orig_src['compression'],
                                        options.comp_level))
                     if not git_archive(repo, spec, source_dir, tree,
-                                       options.comp_level,
+                                       options.orig_prefix, options.comp_level,
                                        options.with_submodules):
                         raise GbpError("Cannot create source tarball at '%s'" %
                                         source_dir)
index b24093029503d0bf36febecd8cf5b4cc3013a4df..33771eeaec29c9a6ddb2755c3f6fec633752beb9 100755 (executable)
@@ -174,6 +174,8 @@ def parse_args(argv):
                       dest="filter_pristine_tar")
     import_group.add_config_file_option(option_name="pristine-tarball-name",
                       dest="pristine_tarball_name")
+    import_group.add_config_file_option(option_name="orig-prefix",
+                      dest="orig_prefix")
     import_group.add_config_file_option(option_name="import-msg",
                       dest="import_msg")
     cmd_group.add_config_file_option(option_name="postimport", dest="postimport")
@@ -239,7 +241,7 @@ def main(argv):
                 prepare_sources(source, sourcepackage, version,
                                 prepare_pristine, options.filters,
                                 options.filter_pristine_tar,
-                                None, tmpdir)
+                                options.orig_prefix, tmpdir)
 
         # Don't mess up our repo with git metadata from an upstream tarball
         if os.path.isdir(os.path.join(unpacked_orig, '.git/')):