[GRASS-dev] Proposal for using ClangFormat, replacing GNU indent, for C/C++ code formatting

Markus Neteler neteler at osgeo.org
Mon Jan 2 11:07:05 PST 2023


On Mon, Jan 2, 2023 at 7:20 PM Nicklas Larsson <n_larsson at yahoo.com> wrote:
> On 2 Jan 2023, at 13:48, Markus Neteler <neteler at osgeo.org> wrote:
>> On Wed, Dec 21, 2022 at 9:25 PM Nicklas Larsson via grass-dev
>>>
>>> Installing clang-format is perhaps most easily done with:
>>> python -m pip install 'clang-format==15.0.6'
>>>
>>> Formatting may be done with something like (following works on Mac):
>>> find -E . -regex '.*\.(cpp|hpp|c|h)' -exec clang-format -i {} \+
>>
>> ... it fails on Linux
>>
> Try something like (untested):
>
> find . -regex '.*\.(cpp|hpp|c|h)' -exec clang-format -i {} \;

That seems to work!

> or manually with:
> clang-format -I <file>
>
[...]
> I am trying to fix the conflicts in
> https://github.com/OSGeo/grass/pull/2684
>
> Conflicting files:
>
> include/grass/iostream/mm.h
> lib/db/dbmi_base/dbmscap.c
> lib/external/ccmath/ccmath.h
> lib/gis/spawn.c
> lib/gis/user_config.c
> lib/iostream/rtimer.cpp
> lib/pngdriver/graph_set.c
> lib/rst/interp_float/point2d.c
> raster/r.terraflow/filldepr.cpp
> raster/r.terraflow/flow.cpp
> raster/r.terraflow/main.cpp
> raster/r.viewshed/statusstructure.cpp
>
> The reason will be the missing clang-format update which I don't know
> how to apply on Linux.
>
>> Not quite sure what you mean.

Probably I was confused and it needs a rebase...

> Did you try:
>
> python -m pip install 'clang-format==15.0.6’
>
> But I suspect any version 15 will do, perhaps even v. 14.
>
> A tip to use the .clang-format file from main for branches without it:

... this I was looking for (sorry for my unclear wish)!

> 1. git checkout main
> 2. cp .clang-forrmat ../.clang-format
> 3. check out branch
> 4. clang-format searches upwards in dir hierarchy  for next ‘.clang-format’ file
> 5. run clang-format from grass source dir

Will try.

Thanks,
Markus


More information about the grass-dev mailing list