From: Erik Faye-Lund Date: Wed, 11 Mar 2009 01:19:46 GMT Subject: Re: Removed unnecessary use of global variables. Message-ID: <55ef48ab-403d-41b8-bf16-203bb0f73fc7@b16g2000yqb.googlegroups.com> In-Reply-To: <1236730168-7164-1-git-send-email-kusmabite@gmail.com> Sorry about the whole double-post thing, this whole submitting patches over email thing is new to me, and I'm making too many mistakes right now. Hopefully, I'll improve in the future ;) On Mar 11, 1:09 am, Erik Faye-Lund wrote: > 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 > introduced a parameter for similar > purposes. > > 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. > > Signed-off-by: Erik Faye-Lund > --- >  connect.c |   16 ++++++---------- >  1 files changed, 6 insertions(+), 10 deletions(-) > > 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); > + >         if (!strcmp(var, "core.gitproxy")) { >                 const char *for_pos; >                 int matchlen = -1; > @@ -421,16 +420,13 @@ static int git_proxy_command_options(const char *var, const char *value, >                 return 0; >         } > > -       return git_default_config(var, value, cb); > +       return git_default_config(var, value, data); >  } > >  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 > > -- > To unsubscribe from this list: send the line "unsubscribe git" in > the body of a message to majord...@vger.kernel.org > More majordomo info at  http://vger.kernel.org/majordomo-info.html