Git development
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: Alexander Kuleshov <kuleshovmail@gmail.com>
Cc: git@vger.kernel.org, Junio C Hamano <gitster@pobox.com>
Subject: Re: [PATCH] git: make was_alias and done_help non-static
Date: Mon, 2 Mar 2015 15:29:18 -0500	[thread overview]
Message-ID: <20150302202918.GA22211@peff.net> (raw)
In-Reply-To: <1425297757-16431-1-git-send-email-kuleshovmail@gmail.com>

On Mon, Mar 02, 2015 at 06:02:37PM +0600, Alexander Kuleshov wrote:

> 'was_alias' variable does not need to store it's value on each
> iteration in the loop, anyway this variable changes it's value with run_argv.
> 
> 'done_help' variable does not need to be static variable too if we'll move it
> out the loop.
> 
> So these variables do not need to be static.

Agreed, but...

> diff --git a/git.c b/git.c
> index 1780233..96723b8 100644
> --- a/git.c
> +++ b/git.c
> @@ -619,6 +619,7 @@ int main(int argc, char **av)
>  {
>  	const char **argv = (const char **) av;
>  	const char *cmd;
> +	int done_help, was_alias;

Now done_help is not initialized, but we read from it before assigning
it. And I think there is no need for was_alias to go outside the loop,
right?

>  	startup_info = &git_startup_info;
>  
> @@ -681,8 +682,6 @@ int main(int argc, char **av)
>  	setup_path();
>  
>  	while (1) {
> -		static int done_help = 0;
> -		static int was_alias = 0;
>  		was_alias = run_argv(&argc, &argv);

Dropping the initialization of was_alias is fine, since we always assign
to it before reading. That becomes more obvious if we leave it in the
loop, and we can even assign in its declaration.

So all together, like:

diff --git a/git.c b/git.c
index acde36a..8dbe12f 100644
--- a/git.c
+++ b/git.c
@@ -635,6 +635,7 @@ int main(int argc, char **av)
 {
 	const char **argv = (const char **) av;
 	const char *cmd;
+	int done_help = 0;
 
 	startup_info = &git_startup_info;
 
@@ -697,9 +698,7 @@ int main(int argc, char **av)
 	setup_path();
 
 	while (1) {
-		static int done_help = 0;
-		static int was_alias = 0;
-		was_alias = run_argv(&argc, &argv);
+		int was_alias = run_argv(&argc, &argv);
 		if (errno != ENOENT)
 			break;
 		if (was_alias) {

  reply	other threads:[~2015-03-02 20:29 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-02 12:02 [PATCH] git: make was_alias and done_help non-static Alexander Kuleshov
2015-03-02 20:29 ` Jeff King [this message]
2015-03-03 10:58 ` Stefan Näwe

Reply instructions:

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

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

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150302202918.GA22211@peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=kuleshovmail@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox