From 4bd62bf230bd83e171559f02dd0e27830246bdf4 Mon Sep 17 00:00:00 2001 From: Denis 'GNUtoo' Carikli Date: Wed, 8 Sep 2021 18:32:17 +0200 Subject: scripts: generate-mirror-command: Guard against updating floating revisions We could accidentally update the branches used in Replicant 6 when trying to mirror the code meant for the next Replicant version. So we whitelist revisions to avoid accidentally doing that. Signed-off-by: Denis 'GNUtoo' Carikli --- scripts/generate-mirror-commands.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/scripts/generate-mirror-commands.py b/scripts/generate-mirror-commands.py index 6349bee..c7987c0 100755 --- a/scripts/generate-mirror-commands.py +++ b/scripts/generate-mirror-commands.py @@ -120,6 +120,24 @@ class Manifest(object): return whitelist.get(given_remote.get('name')).get('dirname') + def is_revision_whitelisted(self, elm): + remote = self.get_project_property(elm, 'remote') + revision = self.get_revision(elm) + if remote == 'aosp' and revision == 'refs/tags/android-11.0.0_r17': + return True + if remote == 'freedesktop' and \ + revision == '32819fe45972e0c706423d71075788a5885f7b86': + return True + + return False + + def is_revision_blacklisted(self, elm): + revision = self.get_revision(elm) + if revision == 'master': + return True + + return False + def get_clone_commands(self, elm): commands = [] @@ -130,6 +148,22 @@ class Manifest(object): 'name').replace('/', '_') revision = self.get_revision(elm) + # Guard against updating the master branch of mirrors that could be used + # by several Replicant versions at the same time by forcing users to + # manually declare revisions here. The revisions have to be either + # whitelisted or blacklisted else we abort. + if not self.is_revision_whitelisted(elm) and \ + not self.is_revision_blacklisted(elm): + print('/!\ The "{}" revision of {}/{} is not known by {}'.format( + revision, base_directory, repo_directory, sys.argv[0])) + print(' Please add it either to the whitelist in {}'.format( + 'is_revision_whitelisted')) + print(' or to the blacklist in {}'.format( + 'is_revision_blacklisted')) + assert(False) + elif self.is_revision_blacklisted(elm): + return [] + commands.append("if [ ! -d {}/{}.git ] ; then".format( base_directory, repo_directory)) -- cgit v1.2.3