[PATCH] psql : Improve code for help option

Started by miyake_koutaalmost 5 years ago6 messages
#1miyake_kouta
miyake_kouta@oss.nttdata.com
1 attachment(s)

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"));
#2Fujii Masao
masao.fujii@oss.nttdata.com
In reply to: miyake_kouta (#1)
Re: [PATCH] psql : Improve code for help option

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

#3miyake_kouta
miyake_kouta@oss.nttdata.com
In reply to: Fujii Masao (#2)
1 attachment(s)
Re: [PATCH] psql : Improve code for help option

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"));
 
#4Fujii Masao
masao.fujii@oss.nttdata.com
In reply to: miyake_kouta (#3)
Re: [PATCH] psql : Improve code for help option

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

#5Nitin Jadhav
nitinjadhavpostgres@gmail.com
In reply to: Fujii Masao (#4)
Re: [PATCH] psql : Improve code for help option

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

#6Fujii Masao
masao.fujii@oss.nttdata.com
In reply to: Nitin Jadhav (#5)
Re: [PATCH] psql : Improve code for help option

On 2021/03/03 17:05, Nitin Jadhav wrote:

Hi,

I have reviewed the patch and it looks good to me.

Thanks! Pushed.

Regards,

--
Fujii Masao
Advanced Computing Technology Center
Research and Development Headquarters
NTT DATA CORPORATION