[PATCH] psql : Improve code for help option
Hi.
I found some redundant code in psql/help.c, so I propose a patch to fix
it.
In the current help.c, the variable "user" is set to the value of
$PGUSER (or get_user_name).
However, $PGUSER is referenced again in the code that follows.
We can replace this part with "user", I think.
Regards.
--
Kota Miyake
Attachments:
psql_help.patchtext/x-diff; name=psql_help.patchDownload
diff --git a/src/bin/psql/help.c b/src/bin/psql/help.c
index e44120bf76..75a2217cac 100644
--- a/src/bin/psql/help.c
+++ b/src/bin/psql/help.c
@@ -134,9 +134,7 @@ usage(unsigned short int pager)
fprintf(output, _(" -p, --port=PORT database server port (default: \"%s\")\n"),
env ? env : DEF_PGPORT_STR);
/* Display default user */
- env = getenv("PGUSER");
- if (!env)
- env = user;
+ env = user;
fprintf(output, _(" -U, --username=USERNAME database user name (default: \"%s\")\n"), env);
fprintf(output, _(" -w, --no-password never prompt for password\n"));
fprintf(output, _(" -W, --password force password prompt (should happen automatically)\n"));
On 2021/03/02 11:57, miyake_kouta wrote:
Hi.
I found some redundant code in psql/help.c, so I propose a patch to fix it.
In the current help.c, the variable "user" is set to the value of $PGUSER (or get_user_name).
However, $PGUSER is referenced again in the code that follows.
We can replace this part with "user", I think.
Good catch!
fprintf(output, _(" -U, --username=USERNAME database user name (default: \"%s\")\n"), env);
We can simplify the code more and remove "env = user"
by just using "user" instead of "env" in the above?
Regards,
--
Fujii Masao
Advanced Computing Technology Center
Research and Development Headquarters
NTT DATA CORPORATION
2021-03-03 00:09, Fujii Masao wrote:
We can simplify the code more and remove "env = user"
by just using "user" instead of "env" in the above?
Thank you for your comment.
I updated my patch and replaced "env" with "user".
Please check.
Regards.
--
Kota Miyake
Attachments:
v02_psql_help.patchtext/x-diff; name=v02_psql_help.patchDownload
diff --git a/src/bin/psql/help.c b/src/bin/psql/help.c
index e44120bf76..edb17ed5dc 100644
--- a/src/bin/psql/help.c
+++ b/src/bin/psql/help.c
@@ -133,11 +133,7 @@ usage(unsigned short int pager)
env = getenv("PGPORT");
fprintf(output, _(" -p, --port=PORT database server port (default: \"%s\")\n"),
env ? env : DEF_PGPORT_STR);
- /* Display default user */
- env = getenv("PGUSER");
- if (!env)
- env = user;
- fprintf(output, _(" -U, --username=USERNAME database user name (default: \"%s\")\n"), env);
+ fprintf(output, _(" -U, --username=USERNAME database user name (default: \"%s\")\n"), user);
fprintf(output, _(" -w, --no-password never prompt for password\n"));
fprintf(output, _(" -W, --password force password prompt (should happen automatically)\n"));
On 2021/03/03 12:27, miyake_kouta wrote:
2021-03-03 00:09, Fujii Masao wrote:
We can simplify the code more and remove "env = user"
by just using "user" instead of "env" in the above?Thank you for your comment.
I updated my patch and replaced "env" with "user".
Please check.
Thanks for updating the patch!
LGTM. Barrying any objection, I will commit this patch.
Regards,
--
Fujii Masao
Advanced Computing Technology Center
Research and Development Headquarters
NTT DATA CORPORATION
Hi,
I have reviewed the patch and it looks good to me.
Thanks and Regards,
Nitin Jadhav
On Wed, Mar 3, 2021 at 1:09 PM Fujii Masao <masao.fujii@oss.nttdata.com>
wrote:
Show quoted text
On 2021/03/03 12:27, miyake_kouta wrote:
2021-03-03 00:09, Fujii Masao wrote:
We can simplify the code more and remove "env = user"
by just using "user" instead of "env" in the above?Thank you for your comment.
I updated my patch and replaced "env" with "user".
Please check.Thanks for updating the patch!
LGTM. Barrying any objection, I will commit this patch.Regards,
--
Fujii Masao
Advanced Computing Technology Center
Research and Development Headquarters
NTT DATA CORPORATION