pq-rpm: implement '--import-files' command line option
authorMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Tue, 10 Dec 2013 13:25:32 +0000 (15:25 +0200)
committerMarkus Lehtonen <markus.lehtonen@linux.intel.com>
Fri, 14 Nov 2014 12:47:19 +0000 (14:47 +0200)
For defining the packaging file(s) that will be imported into the
development/patch-queue branch.

By default, the local gbp conf files are imported in order to try to
ensure that gbp sees the same settings on the development/pq branch as
on the packaging branch.

NOTE: This option does not affect the patch files that are imported. The
files defined with this option will appear as new files in one
monolithic commit in the development/patch-queue branch.

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

index 2c4917a..07569a8 100644 (file)
@@ -598,6 +598,8 @@ class GbpOptionParserRpm(GbpOptionParser):
             'packaging-tag'             : 'packaging/%(version)s',
             'upstream-tag'              : 'upstream/%(upstreamversion)s',
             'pq-branch'                 : 'development/%(branch)s',
+            'import-files'              : ['.gbp.conf',
+                                           'debian/gbp.conf'],
             'spec-file'                 : 'auto',
             'builder'                   : 'rpmbuild',
             'cleaner'                   : '/bin/true',
@@ -640,6 +642,10 @@ class GbpOptionParserRpm(GbpOptionParser):
             'pq-branch':
                 "format string for the patch-queue branch name, default is "
                 "'%(pq-branch)s'",
+            'import-files':
+                "Comma-separated list of additional file(s) to import from "
+                "packaging branch. These will appear as one monolithic patch "
+                "in the pq/development branch. Default is %(import-files)s",
             'spec-file':
                 "Spec file to use, 'auto' makes gbp to guess, other values "
                 "make the packaging-dir option to be ignored, default is "
index 844062b..64a4c7e 100755 (executable)
@@ -315,6 +315,32 @@ def get_packager(spec):
             return GitModifier(match.group('name'), match.group('email'))
     return GitModifier()
 
+def import_extra_files(repo, commitish, files):
+    """Import branch-specific gbp.conf files to current branch"""
+    found = {}
+    for fname in files:
+        if fname:
+            try:
+                found[fname] = repo.show('%s:%s' % (commitish, fname))
+            except GitRepositoryError:
+                pass
+    if found:
+        gbp.log.info("Importing additional file(s) from branch '%s' into '%s'" %
+                     (commitish, repo.get_branch()))
+        for fname, content in found.iteritems():
+            dirname = os.path.dirname(fname)
+            if dirname and not os.path.exists(dirname):
+                os.makedirs(dirname)
+            with open(fname, 'w') as fobj:
+                fobj.write(content)
+
+        files = found.keys()
+        gbp.log.debug('Adding/commiting %s' % files)
+        repo.add_files(files, force=True)
+        commit_msg = ('Auto-import packaging file(s) from branch %s:\n'
+                      '    %s\n\nGbp: Ignore\nGbp-Rpm: Ignore' % (commitish,
+                      '    '.join(files)))
+        repo.commit_files(files, msg=commit_msg)
 
 def import_spec_patches(repo, options):
     """
@@ -368,6 +394,7 @@ def import_spec_patches(repo, options):
     try:
         gbp.log.info("Switching to branch '%s'" % pq_branch)
         repo.set_branch(pq_branch)
+        import_extra_files(repo, base, options.import_files)
 
         if not queue:
             return
@@ -451,6 +478,11 @@ def apply_single_patch(repo, patchfile, options):
     apply_and_commit_patch(repo, patch, fallback_author=None)
 
 
+def opt_split_cb(option, opt_str, value, parser):
+    """Split option string into a list"""
+    setattr(parser.values, option.dest, value.split(','))
+
+
 def main(argv):
     """Main function for the gbp pq-rpm command"""
     retval = 0
@@ -488,6 +520,9 @@ def main(argv):
                  "this is used as the 'base' branch. Default is "
                  "'%(packaging-branch)s'")
     parser.add_config_file_option(option_name="pq-branch", dest="pq_branch")
+    parser.add_config_file_option(option_name="import-files",
+            dest="import_files", type="string", action="callback",
+            callback=opt_split_cb)
     parser.add_option("--export-rev", action="store", dest="export_rev",
             default="",
             help="Export patches from treeish object TREEISH instead of head "