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

Re: [PATCH] Removed unnecessary use of global variables.

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Mar 11, 2009, 10:30 UTC
Message-ID
<alpine.DEB.1.00.0903111126280.10279@pacific.mpi-cbg.de>
In-Reply-To
<1236730168-7164-1-git-send-email-kusmabite@gmail.com>
Hi,
On Wed, 11 Mar 2009, Erik Faye-Lund wrote:
Show 7 quoted lines
> git_config() now takes a third data-parameter that is passed back
> to the callback-function. At the time this code was written, that
> parameter did not exist, so a somewhat nasty (but by all means
> correct) use of global variables was introduced. In commit
> ef90d6d4208a5130185b04f06e5f90a5f9959fe3 Johannes Schindelin
> <Johannes.Schindelin@gmx.de> introduced a parameter for similar
> purposes.

We tend to quote commits in this form: ef90d6d(Provide git_config with a callback-data parameter)

> I've changed the code to utilize this parameter to pass the
> string. In addition, I've made the function calculate the string
> length on usage instead, to reduce the parameters needed to what
> the callback-interface supplies.

Usually, commit messages are held in a more imperative form than a subjective one:

	Utilize this parameter to pass the string.
Show 20 quoted lines
> diff --git a/connect.c b/connect.c
> index 2f23ab3..98fbaea 100644
> --- a/connect.c
> +++ b/connect.c
> @@ -371,14 +371,13 @@ static void git_tcp_connect(int fd[2], char *host, int flags)
>  	fd[1] = dup(sockfd);
>  }
>  
> -
>  static char *git_proxy_command;
> -static const char *rhost_name;
> -static int rhost_len;
> -
>  static int git_proxy_command_options(const char *var, const char *value,
> -		void *cb)
> +		void *data)
>  {
> +	const char *rhost_name = data;
> +	const size_t rhost_len = strlen(rhost_name);
> +

git_proxy_command_options is called for each and every config variable. The idea of having the length in a local variable was to avoid recalculating the length each and every time. I think I'd actually use a strbuf for that.

BTW I would not rename "cb", as it is only distracting the reader of the patch.

But I like the idea of your patch (as you can see from me replying ;-)

Thanks, Dscho

Previous: Johannes SchindelinNext: Nanako Shiraishi
Message 4 of 6 in “Removed unnecessary use of global variables.”
  1. Removed unnecessary use of global variables.Erik Faye-Lund, Mar 11, 2009
  2. Erik Faye-LundMar 11, 2009
  3. Johannes SchindelinMar 11, 2009
  4. Johannes SchindelinMar 11, 2009
  5. Nanako ShiraishiMar 11, 2009
  6. Junio C HamanoMar 11, 2009

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.