<div dir="ltr">I've made a set of PRs to have a look at what astyle and clang-format passes will look like.<div><br></div><div> - astyle: <a href="https://github.com/postgis/postgis/pull/218/" target="_blank">https://github.com/postgis/postgis/pull/218/</a> <br></div><div> - clang-format: <a href="https://github.com/postgis/postgis/pull/219" target="_blank">https://github.com/postgis/postgis/pull/219</a> <br> - a pass of clang-format on top of a pass of astyle:</div><div><a href="https://github.com/Komzpa/postgis/pull/3/files" target="_blank">https://github.com/Komzpa/postgis/pull/3/files</a> </div><div> - clang-format with PointerAlignment: Right: <span style="color:rgb(0,0,0)"> </span><a href="https://github.com/postgis/postgis/pull/220/files" target="_blank">https://github.com/postgis/postgis/pull/220/files</a></div><div> - a pass of clang-format with PointerAlignment: Right on top of a pass of astyle:</div><div><a href="https://github.com/Komzpa/postgis/pull/4/files" target="_blank">https://github.com/Komzpa/postgis/pull/4/files</a> <br></div><div><br></div><div>TLDR: clang-format is much eyecandier.</div><div><br></div><div>1. astyle currently doesn't pass CI, clang-format does.</div><div>2. astyle doesn't do anything on line length: <a href="https://github.com/Komzpa/postgis/pull/3/files#diff-cfb8f8761c5379a23860242267edde72L93" target="_blank">https://github.com/Komzpa/postgis/pull/3/files#diff-cfb8f8761c5379a23860242267edde72L93</a></div><div> - clang-format wraps long function calls, long comments and long "text strings"</div><div>3. astyle doesn't attempt at fixing typography, so there are spaces before `;` and `)`</div><div>4. clang-format aligns blocks of comments between different lines: <a href="https://github.com/Komzpa/postgis/pull/3/files#diff-398fded035024e0cd5d922b19ada5c68L884" target="_blank">https://github.com/Komzpa/postgis/pull/3/files#diff-398fded035024e0cd5d922b19ada5c68L884</a> </div><div>5. clang-format can get rid of weird newlines  <a href="https://github.com/Komzpa/postgis/pull/3/files#diff-1fe4151e8b2138fc826e601c61a56eb7L550" target="_blank">https://github.com/Komzpa/postgis/pull/3/files#diff-1fe4151e8b2138fc826e601c61a56eb7L550</a> </div><div><a href="https://github.com/Komzpa/postgis/pull/3/files#diff-1fe4151e8b2138fc826e601c61a56eb7L607" target="_blank">https://github.com/Komzpa/postgis/pull/3/files#diff-1fe4151e8b2138fc826e601c61a56eb7L607</a> </div><div>(it looks like someone did s/;/;\n/g to parts of code at some point)</div><div>6. clang-format deals with #define's internals <a href="https://github.com/Komzpa/postgis/pull/3/files#diff-16bdbc1af78b0ac623fbd5f0d4b0ad79L138" target="_blank">https://github.com/Komzpa/postgis/pull/3/files#diff-16bdbc1af78b0ac623fbd5f0d4b0ad79L138</a> </div><div>7. clang-format deals with function return type <a href="https://github.com/Komzpa/postgis/pull/3/files#diff-1cd5ee9588f4b7c9ec3b06432a82979dL39" target="_blank">https://github.com/Komzpa/postgis/pull/3/files#diff-1cd5ee9588f4b7c9ec3b06432a82979dL39</a></div><div>8. clang-format deals with pointer alignment <a href="https://github.com/Komzpa/postgis/pull/3/files#diff-398fded035024e0cd5d922b19ada5c68L42" target="_blank">https://github.com/Komzpa/postgis/pull/3/files#diff-398fded035024e0cd5d922b19ada5c68L42</a> </div><div>We have all possible kinds in codebase ("char* i", "LWGEOM *geom", "GEOSGeometry * g"). </div><div>I've initially made a pass with DerivePointerAlignment and it decided that most popular one in codebase is Left. For your convenience I built both versions, as it was questioned by mloskot.</div><div><br></div><div>About syncing clang-format versions:</div><div><br></div><div>We can vendor a clang-format binary in a nearby repo, just like <a href="https://github.com/angular/clang-format">https://github.com/angular/clang-format</a></div><div><br></div><div>I've seen that debbie has commit access to postgis repo. How about asking her to regularly (on commit, or on release for starters) run clang-format and commit, possibly duplicating previous commit header so that people who don't know `git diff -w`/`git blame -w` can still find the time, date and commit when change happened? </div><div><br></div><div class="gmail_quote"><div dir="ltr">пт, 23 февр. 2018 г. в 1:26, Tomas Vondra <<a href="mailto:tomas.vondra@2ndquadrant.com" target="_blank">tomas.vondra@2ndquadrant.com</a>>:<br></div></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On 02/22/2018 10:53 PM, Sandro Santilli wrote:<br>
> On Thu, Feb 22, 2018 at 09:20:31PM +0100, Tomas Vondra wrote:<br>
><br>
>> Considering how tightly is PostGIS coupled with PostgreSQL, I think it<br>
>> would make perfect sense to use the same code formatting.<br>
><br>
> You can currently build PostGIS by just installing<br>
> postgresql-server-dev package (for Debian and derivates)<br>
> I'm not sure it does include the formatter ?<br>
<br>
AFAIK that only includes header files, so no - pgindent is not there.<br>
But it's not like it's a massive tool - you can get it here:<br>
<br>
    <a href="https://github.com/postgres/postgres/tree/master/src/tools/pgindent" rel="noreferrer" target="_blank">https://github.com/postgres/postgres/tree/master/src/tools/pgindent</a><br>
<br>
and include it in PostGIS. Or to be more precise, it's a separate tool<br>
available here:<br>
<br>
    <a href="https://git.postgresql.org/git/pg_bsd_indent.git" rel="noreferrer" target="_blank">https://git.postgresql.org/git/pg_bsd_indent.git</a><br>
<br>
and the thing included in the main git repository is a wrapper,<br>
configuration, etc.<br>
<br>
> Also, could it not still change between releases of PostgreSQL ?<br>
><br>
<br>
Not really, it tends to be very stable. One of the primary reasons why<br>
we have pgindent is to make all the branches more alike, to make<br>
back-patching simpler. Changing the formatting rules between releases<br>
would directly contradict that.<br>
<br>
regards<br>
<br>
--<br>
Tomas Vondra                  <a href="http://www.2ndQuadrant.com" rel="noreferrer" target="_blank">http://www.2ndQuadrant.com</a><br>
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services<br>
_______________________________________________<br>
postgis-devel mailing list<br>
<a href="mailto:postgis-devel@lists.osgeo.org" target="_blank">postgis-devel@lists.osgeo.org</a><br>
<a href="https://lists.osgeo.org/mailman/listinfo/postgis-devel" rel="noreferrer" target="_blank">https://lists.osgeo.org/mailman/listinfo/postgis-devel</a></blockquote></div></div>