From 618453a2bab42325facfec885ca8fc65d2ce3818 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hanefi=20=C3=96nald=C4=B1?= Date: Thu, 18 Jun 2020 16:58:16 +0300 Subject: [PATCH] Disallow C-style comments in migration files --- .circleci/config.yml | 6 +++++ ci/disallow_c_comments_in_migrations.sh | 26 +++++++++++++++++++ ci/fix_style.sh | 1 + .../distributed/sql/citus--9.2-2--9.2-4.sql | 4 +-- .../distributed/sql/citus--9.2-4--9.3-2.sql | 4 +-- .../distributed/sql/citus--9.3-1--9.2-4.sql | 14 +++++----- 6 files changed, 44 insertions(+), 11 deletions(-) create mode 100755 ci/disallow_c_comments_in_migrations.sh diff --git a/.circleci/config.yml b/.circleci/config.yml index 90ca195ce..d487ae5ab 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -41,6 +41,12 @@ jobs: - run: name: 'Check if changed' command: git diff --exit-code + - run: + name: 'Check for C-style comments in migration files' + command: ci/disallow_c_comments_in_migrations.sh + - run: + name: 'Check if changed' + command: git diff --exit-code - run: name: 'Check for banned C API usage' command: ci/banned.h.sh diff --git a/ci/disallow_c_comments_in_migrations.sh b/ci/disallow_c_comments_in_migrations.sh new file mode 100755 index 000000000..72ab74587 --- /dev/null +++ b/ci/disallow_c_comments_in_migrations.sh @@ -0,0 +1,26 @@ +#! /bin/bash + +set -euo pipefail + +# We do not use c-style comments in migration files as the stripped +# zero-length migration files cause warning during packaging +# See #3115 for more info + +# In this file, we aim to keep the indentation intact by capturing whitespaces, +# and reusing them if needed. GNU sed unfortunately does not support lookaround assertions. + +# /* -> -- +find src/backend/distributed/sql/*.sql -print0 | xargs -0 sed -i 's#/\*#--#g' + +# */ -> `` (empty string) +# remove all whitespaces immediately before the match +find src/backend/distributed/sql/*.sql -print0 | xargs -0 sed -i 's#\s*\*/\s*##g' + +# * -> -- +# keep the indentation +# allow only whitespaces before the match +find src/backend/distributed/sql/*.sql -print0 | xargs -0 sed -i 's#^\(\s*\) \*#\1--#g' + +# // -> -- +# do not touch http:// or similar by allowing only whitespaces before // +find src/backend/distributed/sql/*.sql -print0 | xargs -0 sed -i 's#^\(\s*\)//#\1--#g' diff --git a/ci/fix_style.sh b/ci/fix_style.sh index ce0d93a38..39d2d312e 100755 --- a/ci/fix_style.sh +++ b/ci/fix_style.sh @@ -10,5 +10,6 @@ cd ${cidir}/.. ci/editorconfig.sh ci/remove_useless_declarations.sh +ci/disallow_c_comments_in_migrations.sh citus_indent . --quiet diff --git a/src/backend/distributed/sql/citus--9.2-2--9.2-4.sql b/src/backend/distributed/sql/citus--9.2-2--9.2-4.sql index ee91f0823..336456afb 100644 --- a/src/backend/distributed/sql/citus--9.2-2--9.2-4.sql +++ b/src/backend/distributed/sql/citus--9.2-2--9.2-4.sql @@ -1,2 +1,2 @@ -/* we've some issues with versioning, and we're fixing it by bumping version */ -/* from 9.2-2 to 9.2-4 see #3673 for details */ +-- we've some issues with versioning, and we're fixing it by bumping version +-- from 9.2-2 to 9.2-4 see #3673 for details diff --git a/src/backend/distributed/sql/citus--9.2-4--9.3-2.sql b/src/backend/distributed/sql/citus--9.2-4--9.3-2.sql index 9a64ec020..67d10ba33 100644 --- a/src/backend/distributed/sql/citus--9.2-4--9.3-2.sql +++ b/src/backend/distributed/sql/citus--9.2-4--9.3-2.sql @@ -1,6 +1,6 @@ -/* citus--9.2-4--9.3-2 */ +-- citus--9.2-4--9.3-2 -/* bump version to 9.3-2 */ +-- bump version to 9.3-2 #include "udfs/citus_extradata_container/9.3-2.sql" #include "udfs/update_distributed_table_colocation/9.3-2.sql" diff --git a/src/backend/distributed/sql/citus--9.3-1--9.2-4.sql b/src/backend/distributed/sql/citus--9.3-1--9.2-4.sql index 460807c06..6277ec762 100644 --- a/src/backend/distributed/sql/citus--9.3-1--9.2-4.sql +++ b/src/backend/distributed/sql/citus--9.3-1--9.2-4.sql @@ -1,10 +1,10 @@ -/* citus--9.3-1--9.2-4 */ -/* this is an unusual upgrade path, we are doing it because */ -/* we have accidentally tagged master branch with v9.2-3 */ -/* however master branch was already bumped to v9.3-1 */ -/* with this file, we are undoing the catalog changes that */ -/* have happened between 9.2-2 to 9.3-1, and making 9.2-4 */ -/* as the release that we can */ +-- citus--9.3-1--9.2-4 +-- this is an unusual upgrade path, we are doing it because +-- we have accidentally tagged master branch with v9.2-3 +-- however master branch was already bumped to v9.3-1 +-- with this file, we are undoing the catalog changes that +-- have happened between 9.2-2 to 9.3-1, and making 9.2-4 +-- as the release that we can -- undo the changes for citus_extradata_container that happened on citus 9.3 DROP FUNCTION IF EXISTS pg_catalog.citus_extradata_container(INTERNAL);