diff options
Diffstat (limited to 'scripts/combo-layer')
-rwxr-xr-x | scripts/combo-layer | 72 |
1 files changed, 41 insertions, 31 deletions
diff --git a/scripts/combo-layer b/scripts/combo-layer index 8f57ba58cf..7f2020fca7 100755 --- a/scripts/combo-layer +++ b/scripts/combo-layer @@ -7,18 +7,8 @@ # Paul Eggleton <paul.eggleton@intel.com> # Richard Purdie <richard.purdie@intel.com> # -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License version 2 as -# published by the Free Software Foundation. +# SPDX-License-Identifier: GPL-2.0-only # -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with this program; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. import fnmatch import os, sys @@ -31,7 +21,6 @@ import re import copy import pipes import shutil -from collections import OrderedDict from string import Template from functools import reduce @@ -90,7 +79,7 @@ class Configuration(object): logger.debug("Loading config file %s" % self.conffile) self.parser = configparser.ConfigParser() with open(self.conffile) as f: - self.parser.readfp(f) + self.parser.read_file(f) # initialize default values self.commit_msg_template = "Automatic commit to update last_revision" @@ -202,6 +191,23 @@ def runcmd(cmd,destdir=None,printerr=True,out=None,env=None): logger.debug("output: %s" % output.replace(chr(0), '\\0')) return output +def action_sync_revs(conf, args): + """ + Update the last_revision config option for each repo with the latest + revision in the remote's branch. Useful if multiple people are using + combo-layer. + """ + repos = get_repos(conf, args[1:]) + + for name in repos: + repo = conf.repos[name] + ldir = repo['local_repo_dir'] + branch = repo.get('branch', "master") + runcmd("git fetch", ldir) + lastrev = runcmd('git rev-parse origin/%s' % branch, ldir).strip() + print("Updating %s to %s" % (name, lastrev)) + conf.update(name, "last_revision", lastrev) + def action_init(conf, args): """ Clone component repositories @@ -246,7 +252,7 @@ def action_init(conf, args): # traditional behavior from "git archive" (preserved # here) it to choose the first one. This might not be # intended, so at least warn about it. - logger.warn("%s: initial revision '%s' not unique, picking result of rev-parse = %s" % + logger.warning("%s: initial revision '%s' not unique, picking result of rev-parse = %s" % (name, initialrev, refs[0])) initialrev = rev except: @@ -294,6 +300,8 @@ def action_init(conf, args): # again. Uses the list of files created by tar (easier # than walking the tree). for file in files.split('\n'): + if file.endswith(os.path.sep): + continue for pattern in exclude_patterns: if fnmatch.fnmatch(file, pattern): os.unlink(os.path.join(*([extract_dir] + ['..'] * subdir_components + [file]))) @@ -329,7 +337,7 @@ def action_init(conf, args): # one. The commit should be in both repos with # the same tree, but better check here. tree = runcmd('git show -s --pretty=format:%%T %s' % rev).strip() - with tempfile.NamedTemporaryFile() as editor: + with tempfile.NamedTemporaryFile(mode='wt') as editor: editor.write('''cat >$1 <<EOF tree %s author %s @@ -353,7 +361,7 @@ EOF # Optional: rewrite history to change commit messages or to move files. if 'hook' in repo or dest_dir != ".": filter_branch = ['git', 'filter-branch', '--force'] - with tempfile.NamedTemporaryFile() as hookwrapper: + with tempfile.NamedTemporaryFile(mode='wt') as hookwrapper: if 'hook' in repo: # Create a shell script wrapper around the original hook that # can be used by git filter-branch. Hook may or may not have @@ -426,7 +434,7 @@ file_exclude = %s''' % (name, file_filter or '<empty>', repo.get('file_exclude', merge.append(name) # Root all commits which have no parent in the common # ancestor in the new repository. - for start in runcmd('git log --pretty=format:%%H --max-parents=0 %s' % name).split('\n'): + for start in runcmd('git log --pretty=format:%%H --max-parents=0 %s --' % name).split('\n'): runcmd('git replace --graft %s %s' % (start, startrev)) try: runcmd(merge) @@ -482,32 +490,32 @@ def check_repo_clean(repodir): sys.exit(1) def check_patch(patchfile): - f = open(patchfile) + f = open(patchfile, 'rb') ln = f.readline() of = None in_patch = False beyond_msg = False - pre_buf = '' + pre_buf = b'' while ln: if not beyond_msg: - if ln == '---\n': + if ln == b'---\n': if not of: break in_patch = False beyond_msg = True - elif ln.startswith('--- '): + elif ln.startswith(b'--- '): # We have a diff in the commit message in_patch = True if not of: print('WARNING: %s contains a diff in its commit message, indenting to avoid failure during apply' % patchfile) - of = open(patchfile + '.tmp', 'w') + of = open(patchfile + '.tmp', 'wb') of.write(pre_buf) - pre_buf = '' - elif in_patch and not ln[0] in '+-@ \n\r': + pre_buf = b'' + elif in_patch and not ln[0] in b'+-@ \n\r': in_patch = False if of: if in_patch: - of.write(' ' + ln) + of.write(b' ' + ln) else: of.write(ln) else: @@ -516,7 +524,7 @@ def check_patch(patchfile): f.close() if of: of.close() - os.rename(patchfile + '.tmp', patchfile) + os.rename(of.name, patchfile) def drop_to_shell(workdir=None): if not sys.stdin.isatty(): @@ -1137,7 +1145,7 @@ def update_with_history(conf, components, revisions, repos): if hook: # Need to turn the verbatim commit message into something resembling a patch header # for the hook. - with tempfile.NamedTemporaryFile(delete=False) as patch: + with tempfile.NamedTemporaryFile(mode='wt', delete=False) as patch: patch.write('Subject: [PATCH] ') patch.write(body) patch.write('\n---\n') @@ -1310,6 +1318,7 @@ actions = { "update": action_update, "pull": action_pull, "splitpatch": action_splitpatch, + "sync-revs": action_sync_revs, } def main(): @@ -1320,10 +1329,11 @@ def main(): Create and update a combination layer repository from multiple component repositories. Action: - init initialise the combo layer repo - update [components] get patches from component repos and apply them to the combo repo - pull [components] just pull component repos only - splitpatch [commit] generate commit patch and split per component, default commit is HEAD""") + init initialise the combo layer repo + update [components] get patches from component repos and apply them to the combo repo + pull [components] just pull component repos only + sync-revs [components] update the config file's last_revision for each repository + splitpatch [commit] generate commit patch and split per component, default commit is HEAD""") parser.add_option("-c", "--conf", help = "specify the config file (conf/combo-layer.conf is the default).", action = "store", dest = "conffile", default = "conf/combo-layer.conf") |