Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rk0Tl-009b3t-UZ for pgsql-hackers@arkaria.postgresql.org; Tue, 12 Mar 2024 11:39:34 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1rk0Tj-00AwfQ-CD for pgsql-hackers@arkaria.postgresql.org; Tue, 12 Mar 2024 11:39:31 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rk0Ti-00AwfH-SN for pgsql-hackers@lists.postgresql.org; Tue, 12 Mar 2024 11:39:31 +0000 Received: from mail-yw1-x112a.google.com ([2607:f8b0:4864:20::112a]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rk0Tf-0046wQ-J4 for pgsql-hackers@postgresql.org; Tue, 12 Mar 2024 11:39:30 +0000 Received: by mail-yw1-x112a.google.com with SMTP id 00721157ae682-609f4d8551eso41536127b3.1 for ; Tue, 12 Mar 2024 04:39:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710243568; x=1710848368; darn=postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=07NA894MeGvWBaRSCLWYMqR3rYd+Ld9j3o2QCZHlBps=; b=dUpvzfCtVVapYbOdQl9hVTVdZPNkMNXg+RKDp/z38uKSnqK+4EEfd1AwamXxZ5Jooc faLyYhc4Nhi0eGIdfLghyGTEGAkquEbQ4t2iGRHwi5bJRieEr+DuXTrGWakwqQ7LSxDv oqntTCRrlvs1Sp6pvYrcYn8ZafIc2bJi9pbPkypnyFvS4Kirqe93UITt38ShcTAdPu6/ wfy/1dxCSOguOckG1F7HOE5QexCltADI+2+XjHdPS2rRBIvRlju0aeJdSZ+3t7dRDYKk 27zjDPWHIQmOm+n7WyLM7W4aYviYnx4bmw7O716RxgI+i/r7qgkw8f1VGccnJLDpC3n2 DWaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710243568; x=1710848368; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=07NA894MeGvWBaRSCLWYMqR3rYd+Ld9j3o2QCZHlBps=; b=Rxmg7+G/4hVdAKWKGLaXLb+fnO/s6iv9bT63ILTnI5XUqhXlohZol0dMASJjDZd+MX EoHyLoTMmJQztI+HkKzsE4mMYHgHc94b+k3q6kM/M6ERm6rvX3khm6YjaZRuCCwShVRu yAlSLWRahmzU0ePMnCeBnXhUCjmycDZdqkfZIa0SyfBKOV61Sqp2naQwtEzYMhTAZiji qrmSm2vJ87mzmP9PKWj2e4AtKkV3WEiwuFtxoxKK2bQJT4CfwiM7c0BKy/uuJHlefz22 UNJqqK6pHB3rXJSW8hGi9+OZmO6vl7Z3W1WpAK66R3vb2vVGmRrKWNyexFDidJTYi3Fk 30TQ== X-Gm-Message-State: AOJu0YzkZ+Ym00Di3PODqwQUxDLE95DwwOHUKNF5dZVCq4aCczwi/iec GZ2O7cLRgDpl/3zpiWhOUuJvMk6fejyc+/CCakqYAO+SCEcwAr7FhPqrJ8zeMQv2+vxQLUctBsM 1mAJOjSYhiiIF3aEZYQuxONZdA9c= X-Google-Smtp-Source: AGHT+IH37C649W7kNgcH7sb9US8s0tz7h98RYgI2Y5kldqf3pJcKbTdiATradFo57mB6ezMbxn9wZdaWtl+d8IwlkwI= X-Received: by 2002:a25:4e8a:0:b0:dd0:d40d:1c98 with SMTP id c132-20020a254e8a000000b00dd0d40d1c98mr7559801ybb.17.1710243567759; Tue, 12 Mar 2024 04:39:27 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Richard Guo Date: Tue, 12 Mar 2024 19:39:16 +0800 Message-ID: Subject: Re: Regarding the order of the header file includes To: Bharath Rupireddy Cc: PostgreSQL-development Content-Type: multipart/alternative; boundary="00000000000055fd300613751c57" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --00000000000055fd300613751c57 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, Mar 8, 2024 at 6:58=E2=80=AFPM Bharath Rupireddy < bharath.rupireddyforpostgres@gmail.com> wrote: > On Thu, Mar 7, 2024 at 12:39=E2=80=AFPM Richard Guo > wrote: > > > > While rebasing one of my patches I noticed that the header file include= s > > 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=3D$(grep -o '#include "[^>]*"' "$file" | > > grep -v "postgres.h" | grep -v "postgres_fe.h" | > > sed 's/\.h"//g') > > > > sorted_headers=3D$(echo "$headers" | sort) > > > > results=3D$(diff <(echo "$headers") <(echo "$sorted_headers")) > > > > if [[ $? !=3D 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 --00000000000055fd300613751c57 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

On Fri, Mar 8, 2024 at 6:58=E2=80=AFPM Bh= arath Rupireddy <bharath.rupireddyforpostgres@gmail.com> wrote:
On Thu, Mar 7, 2024 at 12:39=E2=80= =AFPM Richard Guo <guofenglinux@gmail.com> wrote:
>
> While rebasing one of my patches I noticed that the header file includ= es
> in relnode.c are not sorted in order.=C2=A0 So I wrote a naive script = to see
> if any other C files have the same issue.=C2=A0 The script is:
>
> #!/bin/bash
>
> find . -name "*.c" | while read -r file; do
>=C2=A0 =C2=A0headers=3D$(grep -o '#include "[^>]*"'= ; "$file" |
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0grep -v "postgres.= h" | grep -v "postgres_fe.h" |
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0sed 's/\.h"//g= ')
>
>=C2=A0 =C2=A0sorted_headers=3D$(echo "$headers" | sort)
>
>=C2=A0 =C2=A0results=3D$(diff <(echo "$headers") <(echo= "$sorted_headers"))
>
>=C2=A0 =C2=A0if [[ $? !=3D 0 ]]; then
>=C2=A0 =C2=A0 =C2=A0echo "Headers in '$file' are out of or= der"
>=C2=A0 =C2=A0 =C2=A0echo $results
>=C2=A0 =C2=A0 =C2=A0echo
>=C2=A0 =C2=A0fi
> 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.=C2= =A0 However the current script is quite unrefined and would
require a lo= t of effort to make it a reusable tool.=C2=A0 I will add it to my
to-do = list and hopefully one day I can get back to it.=C2=A0 Feel free to
mess= around with it if someone is interested.
=C2=A0
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 s= yntax.=C2=A0 Hmm,
have you tried to use 'bash' instead of 's= h' to run this script?

Thanks
Richard
--00000000000055fd300613751c57--