When it comes to C and C++ parts of Greenplum, we try to follow
[PostgreSQL Coding Conventions](https://www.postgresql.org/docs/devel/static/source.html).
In addition to that we require that:
* All Python code passes [Pylint](https://www.pylint.org/)
* All Go code is formatted according to [gofmt](https://golang.org/cmd/gofmt/)
I don’t know if this helps but there is a pg_indent
tool that will reformat the code to Postgres’ coding style. We typically only run it just before major release (as does Postgres).
→ src/tools/pgindent/pgindent src/tools/pgindent/typedefs.list ./src/backend/utils/resgroup/resgroup.c ./src/backend/utils/resgroup/test/resgroup_test.c
./src/backend/utils/resgroup/test/resgroup_test.c
src/tools/pgindent/pgindent: line 152: /usr/bin/indent: Argument list too long
Instead of writing doc, it is better to call pg_indent in makefile so that it can auto format each time we compile gpdb, also we can hardcode the specific directories or files easily in that command.
~/workspace/postgres/src/tools/pgindent/pgindent src/tools/pgindent/typedefs.list ./src/backend/main/main.c
--- a/src/backend/main/main.c
+++ b/src/backend/main/main.c
@@ -22,7 +22,7 @@
#include <pwd.h>
#include <unistd.h>
-#if defined(__alpha) && defined(__osf__) /* no __alpha__ ? */
+#if defined(__alpha) && defined(__osf__) /* no __alpha__ ? */
#include <sys/sysinfo.h>
#include "machine/hal_sysinfo.h"
#define ASSEMBLER
@@ -155,7 +155,7 @@ main(int argc, char *argv[])
puts("postgres (Greenplum Database) " GP_VERSION);
exit(0);
}
- if (strcmp(argv[1], "--catalog-version") == 0 )
+ if (strcmp(argv[1], "--catalog-version") == 0)
{
printf(_("Catalog version number: %u\n"),
CATALOG_VERSION_NO);
@@ -189,7 +189,7 @@ main(int argc, char *argv[])
#endif
if (argc > 1 && strcmp(argv[1], "--boot") == 0)
- AuxiliaryProcessMain(argc, argv); /* does not return */
+ AuxiliaryProcessMain(argc, argv); /* does not return */
..................................... (more lines see attachment)..............................
diff --git a/src/backend/main/main.c b/src/backend/main/main.c
index 61f7cfce4a..939cfe764e 100644
--- a/src/backend/main/main.c
+++ b/src/backend/main/main.c
@@ -72,8 +72,8 @@ main(int argc, char *argv[])
* be overwritten in order to set the process title for ps. In such cases
* save_ps_display_args makes and returns a new copy of the argv[] array.
*
- * save_ps_display_args may also move the environment strings to make
- * extra room. Therefore this should be done as early as possible during
+ * save_ps_display_args may also move the environment strings to make extra
+ * room. Therefore this should be done as early as possible during
* startup, to avoid entanglements with code that might save a getenv()
* result pointer.
*/
@@ -155,7 +155,7 @@ main(int argc, char *argv[])
puts("postgres (Greenplum Database) " GP_VERSION);
exit(0);
}
- if (strcmp(argv[1], "--catalog-version") == 0 )
+ if (strcmp(argv[1], "--catalog-version") == 0)
{
..................................... (more lines see attachment)..............................
Thanks, Heikki. That clears up a lot of the questions I had.Since we're currently modifying existing (GPDB-specific) files whose formatting mostly doesn't match pgindent v10, I think we'll do this:- Change CLion's formatting settings to match the most salient rules enforced by pgindent v10- Format new functions with CLion, but leave existing code unchanged- Once our functional changes are merged, go back and format the whole file with pgindent v10, and submit a separate PR for that.
Hi all,In the course of investigating our options for formatting code, we've discovered that CLion's formatting presets allow us to get very close to Postgres style. We've found that a combination of LLDB style with Allman braces works well. The attached screenshots show how to set the style options.Alignment of variable declarations in columns (i.e. with the type in one column and the the name in another) can be achieved with the "Wrapping and Braces > Variable Groups > Align in columns option". Note however that while Greenplum's style puts the "*" of pointer types just to the left of the name column, CLion pushes the name to the right to accommodate the "*". The second screenshot shows an example of this.
Wow, wonderful! Thanks for verifying it. Now, we have some good XML to flow around. Btw, in this case, where would be a good place for such xml to reside to? This doesn't below to the GPDB repo directly, but it will definitely help people to consolidate the IDE environment.