git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH] git: make was_alias and done_help non-static
@ 2015-03-02 12:02 Alexander Kuleshov
  2015-03-02 20:29 ` Jeff King
  2015-03-03 10:58 ` Stefan Näwe
  0 siblings, 2 replies; 3+ messages in thread
From: Alexander Kuleshov @ 2015-03-02 12:02 UTC (permalink / raw
  To: git; +Cc: Junio C Hamano, Alexander Kuleshov

'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.

Signed-off-by: Alexander Kuleshov <kuleshovmail@gmail.com>
Helped-by: Eric Sunshine <sunshine@sunshineco.com>
---
 git.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

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;
 
 	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);
 		if (errno != ENOENT)
 			break;
-- 
2.3.1.422.ge618558

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] git: make was_alias and done_help non-static
  2015-03-02 12:02 [PATCH] git: make was_alias and done_help non-static Alexander Kuleshov
@ 2015-03-02 20:29 ` Jeff King
  2015-03-03 10:58 ` Stefan Näwe
  1 sibling, 0 replies; 3+ messages in thread
From: Jeff King @ 2015-03-02 20:29 UTC (permalink / raw
  To: Alexander Kuleshov; +Cc: git, Junio C Hamano

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) {

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] git: make was_alias and done_help non-static
  2015-03-02 12:02 [PATCH] git: make was_alias and done_help non-static Alexander Kuleshov
  2015-03-02 20:29 ` Jeff King
@ 2015-03-03 10:58 ` Stefan Näwe
  1 sibling, 0 replies; 3+ messages in thread
From: Stefan Näwe @ 2015-03-03 10:58 UTC (permalink / raw
  To: Alexander Kuleshov, git@vger.kernel.org; +Cc: Junio C Hamano

Am 02.03.2015 um 13:02 schrieb Alexander Kuleshov:
> '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.

s/it's/its/


> '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.
> 
> Signed-off-by: Alexander Kuleshov <kuleshovmail@gmail.com>
> Helped-by: Eric Sunshine <sunshine@sunshineco.com>
> ---
>  git.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> 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;
>  
>  	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);
>  		if (errno != ENOENT)
>  			break;
> 

/S
-- 
----------------------------------------------------------------
/dev/random says: Recovery program for excessive talkers: On-and-on-Anon.
python -c "print '73746566616e2e6e616577654061746c61732d656c656b74726f6e696b2e636f6d'.decode('hex')" 
GPG Key fingerprint = 2DF5 E01B 09C3 7501 BCA9  9666 829B 49C5 9221 27AF

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-03-03 11:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-03-02 12:02 [PATCH] git: make was_alias and done_help non-static Alexander Kuleshov
2015-03-02 20:29 ` Jeff King
2015-03-03 10:58 ` Stefan Näwe

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).