git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] git: make was_alias and done_help non-static

From
Jeff King <peff@peff.net>
Date
Mar 2, 2015, 20:29 UTC
Message-ID
<20150302202918.GA22211@peff.net>
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:
Show 7 quoted lines
> '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...
Show 9 quoted lines
> 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?

Show 9 quoted lines
>  	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) {
Previous: Alexander KuleshovNext: Stefan Näwe
Message 2 of 3 in “git: make was_alias and done_help non-static”
  1. git: make was_alias and done_help non-staticAlexander Kuleshov, Mar 2, 2015
  2. Jeff KingMar 2, 2015
  3. Stefan NäweMar 3, 2015

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.