* [PATCH v2] connect.c: remove a few globals by using git_config callback data
@ 2009-03-11 2:38 Erik Faye-Lund
2009-03-11 11:52 ` Johannes Schindelin
0 siblings, 1 reply; 4+ messages in thread
From: Erik Faye-Lund @ 2009-03-11 2:38 UTC (permalink / raw)
To: git; +Cc: Erik Faye-Lund
Since ef90d6d (Provide git_config with a callback-data parameter,
2008-05-14), git_config() takes a callback data pointer that can be
used to pass extra parameters to the parsing function. The codepath
to parse configuration variables related to git proxy predates this
facility and used a pair of file scope static variables instead.
This patch removes the need for these global variables by passing the
name of the host we are trying to access as the callback data.
Signed-off-by: Erik Faye-Lund <kusmabite@gmail.com>
---
connect.c | 9 +++------
1 files changed, 3 insertions(+), 6 deletions(-)
diff --git a/connect.c b/connect.c
index 2f23ab3..0a35cc1 100644
--- a/connect.c
+++ b/connect.c
@@ -373,8 +373,6 @@ static void git_tcp_connect(int fd[2], char *host, int flags)
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)
@@ -383,6 +381,8 @@ static int git_proxy_command_options(const char *var, const char *value,
const char *for_pos;
int matchlen = -1;
int hostlen;
+ const char *rhost_name = cb;
+ int rhost_len = strlen(rhost_name);
if (git_proxy_command)
return 0;
@@ -426,11 +426,8 @@ static int git_proxy_command_options(const char *var, const char *value,
static int git_use_proxy(const char *host)
{
- rhost_name = host;
- rhost_len = strlen(host);
git_proxy_command = getenv("GIT_PROXY_COMMAND");
- git_config(git_proxy_command_options, NULL);
- rhost_name = NULL;
+ git_config(git_proxy_command_options, (void*)host);
return (git_proxy_command && *git_proxy_command);
}
--
1.6.2.GIT
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH v2] connect.c: remove a few globals by using git_config callback data
2009-03-11 2:38 [PATCH v2] connect.c: remove a few globals by using git_config callback data Erik Faye-Lund
@ 2009-03-11 11:52 ` Johannes Schindelin
2009-03-11 13:17 ` Erik Faye-Lund
0 siblings, 1 reply; 4+ messages in thread
From: Johannes Schindelin @ 2009-03-11 11:52 UTC (permalink / raw)
To: Erik Faye-Lund; +Cc: git
Hi,
On Wed, 11 Mar 2009, Erik Faye-Lund wrote:
> Since ef90d6d (Provide git_config with a callback-data parameter,
> 2008-05-14), git_config() takes a callback data pointer that can be
> used to pass extra parameters to the parsing function. The codepath
> to parse configuration variables related to git proxy predates this
> facility and used a pair of file scope static variables instead.
>
> This patch removes the need for these global variables by passing the
> name of the host we are trying to access as the callback data.
>
> Signed-off-by: Erik Faye-Lund <kusmabite@gmail.com>
Thanks!
> @@ -383,6 +381,8 @@ static int git_proxy_command_options(const char *var, const char *value,
> const char *for_pos;
> int matchlen = -1;
> int hostlen;
> + const char *rhost_name = cb;
> + int rhost_len = strlen(rhost_name);
I see that you still calculate the length everytime
git_proxy_command_options() is called -- which is for every config
variable.
> @@ -426,11 +426,8 @@ static int git_proxy_command_options(const char *var, const char *value,
>
> static int git_use_proxy(const char *host)
> {
> - rhost_name = host;
> - rhost_len = strlen(host);
> git_proxy_command = getenv("GIT_PROXY_COMMAND");
> - git_config(git_proxy_command_options, NULL);
> - rhost_name = NULL;
> + git_config(git_proxy_command_options, (void*)host);
The (void *) should not be needed.
Thanks,
Dscho
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH v2] connect.c: remove a few globals by using git_config callback data
2009-03-11 11:52 ` Johannes Schindelin
@ 2009-03-11 13:17 ` Erik Faye-Lund
2009-03-11 13:28 ` Johannes Schindelin
0 siblings, 1 reply; 4+ messages in thread
From: Erik Faye-Lund @ 2009-03-11 13:17 UTC (permalink / raw)
To: Johannes Schindelin; +Cc: Erik Faye-Lund, git
Thanks for the feedback.
On Wed, Mar 11, 2009 at 12:52 PM, Johannes Schindelin
<Johannes.Schindelin@gmx.de> wrote:
>> @@ -383,6 +381,8 @@ static int git_proxy_command_options(const char *var, const char *value,
>> const char *for_pos;
>> int matchlen = -1;
>> int hostlen;
>> + const char *rhost_name = cb;
>> + int rhost_len = strlen(rhost_name);
>
> I see that you still calculate the length everytime
> git_proxy_command_options() is called -- which is for every config
> variable.
Actually, the length-calculation is now moved inside the check for
"core.gitproxy", so it should only trigger for each config variable
that is "core.gitproxy". Hopefully, this should usually be just once
;)
This change was suggested as a compromise by Junio.
>
>> + git_config(git_proxy_command_options, (void*)host);
>
> The (void *) should not be needed.
Actually, it is - it casts away the const-ness of the string. Removing
the cast generates a warning on my installation of GCC. Perhaps I
should have made that clearer by casting to "char*" instead of
"void*"?
--
Erik "kusma" Faye-Lund
kusmabite@gmail.com
(+47) 986 59 656
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] connect.c: remove a few globals by using git_config callback data
2009-03-11 13:17 ` Erik Faye-Lund
@ 2009-03-11 13:28 ` Johannes Schindelin
0 siblings, 0 replies; 4+ messages in thread
From: Johannes Schindelin @ 2009-03-11 13:28 UTC (permalink / raw)
To: Erik Faye-Lund; +Cc: Erik Faye-Lund, git
[-- Attachment #1: Type: TEXT/PLAIN, Size: 1407 bytes --]
Hi,
On Wed, 11 Mar 2009, Erik Faye-Lund wrote:
> On Wed, Mar 11, 2009 at 12:52 PM, Johannes Schindelin
> <Johannes.Schindelin@gmx.de> wrote:
> >> @@ -383,6 +381,8 @@ static int git_proxy_command_options(const char *var, const char *value,
> >> const char *for_pos;
> >> int matchlen = -1;
> >> int hostlen;
> >> + const char *rhost_name = cb;
> >> + int rhost_len = strlen(rhost_name);
> >
> > I see that you still calculate the length everytime
> > git_proxy_command_options() is called -- which is for every config
> > variable.
>
> Actually, the length-calculation is now moved inside the check for
> "core.gitproxy", so it should only trigger for each config variable
> that is "core.gitproxy". Hopefully, this should usually be just once
> ;)
>
> This change was suggested as a compromise by Junio.
Ah, okay, I am lacking time to read all emails today, so I missed that
one.
> >> + git_config(git_proxy_command_options, (void*)host);
> >
> > The (void *) should not be needed.
>
> Actually, it is - it casts away the const-ness of the string. Removing
> the cast generates a warning on my installation of GCC. Perhaps I
> should have made that clearer by casting to "char*" instead of
> "void*"?
Oh, that's why... Thanks for the clarification! Now only a space between
the void and the star, and I am happy!
Ciao,
Dscho
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2009-03-11 13:30 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-03-11 2:38 [PATCH v2] connect.c: remove a few globals by using git_config callback data Erik Faye-Lund
2009-03-11 11:52 ` Johannes Schindelin
2009-03-11 13:17 ` Erik Faye-Lund
2009-03-11 13:28 ` Johannes Schindelin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox