public inbox for [email protected]  
help / color / mirror / Atom feed
From: Richard Guo <[email protected]>
To: Bharath Rupireddy <[email protected]>
Cc: PostgreSQL-development <[email protected]>
Subject: Re: Regarding the order of the header file includes
Date: Tue, 12 Mar 2024 19:39:16 +0800
Message-ID: <CAMbWs49gq5dA8SVZbpP5Cnm2yXxFeJPvhApEBkE=5v2k_aYw9Q@mail.gmail.com> (raw)
In-Reply-To: <CALj2ACVVhf6sU0emYgO3xEdrnh6B1GjfcbOZHvOE0F-RE=zNOA@mail.gmail.com>
References: <CAMbWs4-WhpCFMbXCjtJ+FzmjfPrp7Hw1pk4p+ZpU95Kh3ofZ1A@mail.gmail.com>
	<CALj2ACU=RcL4FfKr=TJEeTWD0xz17Pt9aFP_E8SRfFdn47Wa-w@mail.gmail.com>
	<CAMbWs4930LQ2y=NYuKpnFpS90L_xWkdEMJd1ev0=ZJ=6NuAm4Q@mail.gmail.com>
	<CALj2ACVVhf6sU0emYgO3xEdrnh6B1GjfcbOZHvOE0F-RE=zNOA@mail.gmail.com>

On Fri, Mar 8, 2024 at 6:58 PM Bharath Rupireddy <
[email protected]> wrote:

> On Thu, Mar 7, 2024 at 12:39 PM Richard Guo <[email protected]>
> 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


view thread (5+ messages)

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected]
  Subject: Re: Regarding the order of the header file includes
  In-Reply-To: <CAMbWs49gq5dA8SVZbpP5Cnm2yXxFeJPvhApEBkE=5v2k_aYw9Q@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox