Re: Regarding the order of the header file includes

From: Richard Guo <guofenglinux(at)gmail(dot)com>
To: Bharath Rupireddy <bharath(dot)rupireddyforpostgres(at)gmail(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Regarding the order of the header file includes
Date: 2024-03-12 11:39:16
Message-ID: CAMbWs49gq5dA8SVZbpP5Cnm2yXxFeJPvhApEBkE=5v2k_aYw9Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, Mar 8, 2024 at 6:58 PM Bharath Rupireddy <
bharath(dot)rupireddyforpostgres(at)gmail(dot)com> wrote:

> On Thu, Mar 7, 2024 at 12:39 PM Richard Guo <guofenglinux(at)gmail(dot)com>
> wrote:
> >
> > While rebasing one of my patches I noticed that the header file includes
> > in relnode.c are not sorted in order. So I wrote a naive script to see
> > if any other C files have the same issue. The script is:
> >
> > #!/bin/bash
> >
> > find . -name "*.c" | while read -r file; do
> > headers=$(grep -o '#include "[^>]*"' "$file" |
> > grep -v "postgres.h" | grep -v "postgres_fe.h" |
> > sed 's/\.h"//g')
> >
> > sorted_headers=$(echo "$headers" | sort)
> >
> > results=$(diff <(echo "$headers") <(echo "$sorted_headers"))
> >
> > if [[ $? != 0 ]]; then
> > echo "Headers in '$file' are out of order"
> > echo $results
> > echo
> > fi
> > done
>
> Cool. Isn't it a better idea to improve this script to auto-order the
> header files and land it under src/tools/pginclude/headerssort? It can
> then be reusable and be another code beautification weapon one can use
> before the code release.

Yeah, perhaps. However the current script is quite unrefined and would
require a lot of effort to make it a reusable tool. I will add it to my
to-do list and hopefully one day I can get back to it. Feel free to
mess around with it if someone is interested.

> FWIW, I'm getting the syntax error when ran the above shell script:
>
> headerssort.sh: 10: Syntax error: "(" unexpected

I think the error is due to line 10 containing bash-style syntax. Hmm,
have you tried to use 'bash' instead of 'sh' to run this script?

Thanks
Richard

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Jelte Fennema-Nio 2024-03-12 11:41:02 Re: [EXTERNAL] Re: Add non-blocking version of PQcancel
Previous Message Daniel Gustafsson 2024-03-12 11:09:52 Re: Disconnect if socket cannot be put into non-blocking mode