From: Markus Lehtonen Date: Tue, 10 Dec 2013 13:25:32 +0000 (+0200) Subject: pq-rpm: implement '--import-files' command line option X-Git-Tag: tizen/0.6.15-20140828~67 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=534d37c1344cd1718a1ccce5084e795cf35aa677;p=tools%2Fgit-buildpackage.git pq-rpm: implement '--import-files' command line option 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 --- diff --git a/gbp/config.py b/gbp/config.py index 77c36745..e6b3f612 100644 --- a/gbp/config.py +++ b/gbp/config.py @@ -585,6 +585,8 @@ class GbpOptionParserRpm(GbpOptionParser): 'packaging-tag' : '%(vendor)s/%(version)s', 'upstream-tag' : 'upstream/%(upstreamversion)s', 'pq-branch' : 'development/%(branch)s', + 'import-files' : ['.gbp.conf', + 'debian/gbp.conf'], 'spec-file' : 'auto', 'export-dir' : '../rpmbuild', 'ignore-untracked' : 'False', @@ -614,6 +616,11 @@ class GbpOptionParserRpm(GbpOptionParser): "format string for packaging tags, rpm counterpart of the 'debian-tag' option, default is '%(packaging-tag)s'", '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 '%(spec-file)s'", 'ignore-untracked': diff --git a/gbp/scripts/pq_rpm.py b/gbp/scripts/pq_rpm.py index 844062b7..64a4c7e4 100755 --- a/gbp/scripts/pq_rpm.py +++ b/gbp/scripts/pq_rpm.py @@ -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 "