git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Tanay Abhra <tanayabh@gmail.com>
To: Eric Sunshine <sunshine@sunshineco.com>
Cc: Git List <git@vger.kernel.org>,
	Ramkumar Ramachandra <artagnon@gmail.com>,
	Matthieu Moy <Matthieu.Moy@grenoble-inp.fr>
Subject: Re: [RFC/PATCH] imap-send.c: replace git_config with git_config_get_string
Date: Thu, 26 Jun 2014 13:44:47 +0530	[thread overview]
Message-ID: <53ABD677.4040808@gmail.com> (raw)
In-Reply-To: <CAPig+cTStpB09Fh3bAF2NcdWR9W_UMaL5qutvUuQNfEL4=GwNw@mail.gmail.com>



On 6/25/2014 12:39 PM, Eric Sunshine wrote:
> On Mon, Jun 23, 2014 at 6:41 AM, Tanay Abhra <tanayabh@gmail.com> wrote:
>> Use git_config_get_string instead of git_config to take advantage of
>> the config hash-table api which provides a cleaner control flow.
> 
> You may want to mention as a side-note the slight behavior change
> introduced by this patch. The original code complained about any
> unknown boolean "imap.*" key, whereas the new code does not.
> 

Also, my code is error prone. Previous one had all NULL values returned
as config_non_boolean. But, now I have to add a NULL check to every strdup
in the code.

More below,

> 
>> Signed-off-by: Tanay Abhra <tanayabh@gmail.com>
>> ---
>>  imap-send.c | 68 ++++++++++++++++++++++++++-----------------------------------
>>  1 file changed, 29 insertions(+), 39 deletions(-)
>>
>> diff --git a/imap-send.c b/imap-send.c
>> index 83a6ed2..87bd418 100644
>> --- a/imap-send.c
>> +++ b/imap-send.c
>> @@ -1326,47 +1326,37 @@ static int split_msg(struct strbuf *all_msgs, struct strbuf *msg, int *ofs)
>>
>>  static char *imap_folder;
>>
>> -static int git_imap_config(const char *key, const char *val, void *cb)
>> +static void git_imap_config(void)
>>  {
>> -       char imap_key[] = "imap.";
>> -
>> -       if (strncmp(key, imap_key, sizeof imap_key - 1))
>> -               return 0;
>> -
>> -       key += sizeof imap_key - 1;
>> -
>> -       /* check booleans first, and barf on others */
>> -       if (!strcmp("sslverify", key))
>> -               server.ssl_verify = git_config_bool(key, val);
>> -       else if (!strcmp("preformattedhtml", key))
>> -               server.use_html = git_config_bool(key, val);
>> -       else if (!val)
>> -               return config_error_nonbool(key);
>> -
>> -       if (!strcmp("folder", key)) {
>> -               imap_folder = xstrdup(val);
>> -       } else if (!strcmp("host", key)) {
>> -               if (starts_with(val, "imap:"))
>> -                       val += 5;
>> -               else if (starts_with(val, "imaps:")) {
>> -                       val += 6;
>> +       const char *value;
> 
> Observation: If you name this variable 'val', which is the name of the
> argument to the function in the original code, you will get a slightly
> smaller and more readable diff. 

Noted.

> 
>> +       if (!git_config_get_string("imap.sslverify", &value))
>> +               server.ssl_verify = git_config_bool("sslverify", value);
> 
> I realize that you are just replicating the behavior of the original
> code, but the error message emitted here for a non-bool value is less
> than desirable since it throws away context (namely, the "imap."
> prefix). You can improve the message, and help the user resolve the
> error more quickly, by presenting the full configuration key (namely,
> "imap.sslverify"). Such a change would deserve mention in the commit
> message. Alternately, it could be fixed in a follow-up patch.
> 

Yes, I thought so also when writing the patch. Will change it in the next
iteration.

Thanks.
Tanay Abhra.

>> +       if (!git_config_get_string("imap.preformattedhtml", &value))
>> +               server.use_html = git_config_bool("preformattedhtml", value);
> 
> Ditto regarding error message: "imap.preformattedhtml"
> 
>> +       if (!git_config_get_string("imap.folder", &value))
>> +               imap_folder = xstrdup(value);
>> +       if (!git_config_get_string("imap.host", &value)) {
>> +               if (starts_with(value, "imap:"))
>> +                       value += 5;
>> +               else if (starts_with(value, "imaps:")) {
>> +                       value += 6;
>>                         server.use_ssl = 1;
>>                 }
>> -               if (starts_with(val, "//"))
>> -                       val += 2;
>> -               server.host = xstrdup(val);
>> -       } else if (!strcmp("user", key))
>> -               server.user = xstrdup(val);
>> -       else if (!strcmp("pass", key))
>> -               server.pass = xstrdup(val);
>> -       else if (!strcmp("port", key))
>> -               server.port = git_config_int(key, val);
>> -       else if (!strcmp("tunnel", key))
>> -               server.tunnel = xstrdup(val);
>> -       else if (!strcmp("authmethod", key))
>> -               server.auth_method = xstrdup(val);
>> -
>> -       return 0;
>> +               if (starts_with(value, "//"))
>> +                       value += 2;
>> +               server.host = xstrdup(value);
>> +       }
>> +       if (!git_config_get_string("imap.user", &value))
>> +               server.user = xstrdup(value);
>> +       if (!git_config_get_string("imap.pass", &value))
>> +               server.pass = xstrdup(value);
>> +       if (!git_config_get_string("imap.port", &value))
>> +               server.port = git_config_int("port", value);
> 
> Same regarding diagnostic: "imap.port"
> 
>> +       if (!git_config_get_string("imap.tunnel", &value))
>> +               server.tunnel = xstrdup(value);
>> +       if (!git_config_get_string("imap.authmethod", &value))
>> +               server.auth_method = xstrdup(value);
>>  }
>>
>>  int main(int argc, char **argv)
>> @@ -1387,7 +1377,7 @@ int main(int argc, char **argv)
>>                 usage(imap_send_usage);
>>
>>         setup_git_directory_gently(&nongit_ok);
>> -       git_config(git_imap_config, NULL);
>> +       git_imap_config();
>>
>>         if (!server.port)
>>                 server.port = server.use_ssl ? 993 : 143;
>> --
>> 1.9.0.GIT
> 

  reply	other threads:[~2014-06-26  8:15 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-23 10:41 [RFC/PATCH V2] alias.c: replace git_config with git_config_get_string Tanay Abhra
2014-06-23 10:41 ` [RFC/PATCH V2] branch.c: " Tanay Abhra
2014-06-25  4:45   ` Eric Sunshine
2014-06-26  8:09     ` Tanay Abhra
2014-06-29 11:06       ` Eric Sunshine
2014-06-23 10:41 ` [RFC/PATCH] imap-send.c: " Tanay Abhra
2014-06-25  7:09   ` Eric Sunshine
2014-06-26  8:14     ` Tanay Abhra [this message]
2014-06-26 16:50   ` Matthieu Moy
2014-06-26 23:57     ` Karsten Blees
2014-06-23 10:41 ` [RFC/PATCH] notes-util.c: " Tanay Abhra
2014-06-25  7:54   ` Eric Sunshine
2014-06-26  8:19     ` Tanay Abhra
2014-06-29 11:01       ` Eric Sunshine
2014-06-30 13:34         ` Karsten Blees
2014-06-30 14:32           ` Eric Sunshine
2014-06-30 14:54             ` Karsten Blees
2014-06-30 14:39           ` Tanay Abhra
2014-06-30 15:56             ` Karsten Blees
2014-06-30 16:21               ` Tanay Abhra
2014-06-30 17:52               ` Junio C Hamano
2014-07-01  8:36             ` Matthieu Moy
2014-06-23 10:41 ` [RFC/PATCH] notes.c: " Tanay Abhra
2014-06-25  8:06   ` Eric Sunshine
2014-06-26  8:20     ` Tanay Abhra
2014-06-23 10:41 ` [RFC/PATCH] pager.c: " Tanay Abhra
2014-06-25  3:59   ` Eric Sunshine
2014-06-26  8:24     ` Tanay Abhra
2014-06-26 18:46     ` Karsten Blees
2014-06-27 11:55       ` Matthieu Moy
2014-06-27 16:57         ` Karsten Blees
2014-06-27 19:19           ` Matthieu Moy
2014-06-28  5:20             ` Karsten Blees
2014-06-28  6:01               ` Matthieu Moy
2014-06-28 14:29                 ` Karsten Blees
2014-06-29 12:04                   ` Matthieu Moy
2014-06-23 22:38 ` [RFC/PATCH V2] alias.c: " Jonathan Nieder
2014-06-24  1:50   ` Tanay Abhra
2014-06-25  2:12 ` Eric Sunshine
2014-06-26  8:24   ` Tanay Abhra
2014-06-26 16:39 ` Matthieu Moy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=53ABD677.4040808@gmail.com \
    --to=tanayabh@gmail.com \
    --cc=Matthieu.Moy@grenoble-inp.fr \
    --cc=artagnon@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=sunshine@sunshineco.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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 NNTP newsgroup(s).