{"thread":{"id":"37886","subject":"[PATCH v2] imap-send: Use parse options API to determine verbosity","startedAt":"2014-11-05T22:53:20Z","lastAt":"2014-11-06T00:30:26Z","messageCount":3,"participants":["Bernhard Reiter","Junio C Hamano"],"isPatch":true,"patchVersion":2,"patchTotal":null},"messages":[{"id":"251419","messageId":"545AAA60.3040207@raz.or.at","threadId":"37886","inReplyTo":null,"subject":"[PATCH v2] imap-send: Use parse options API to determine verbosity","fromName":"Bernhard Reiter","fromEmail":"ockham@raz.or.at","sentAt":"2014-11-05T22:53:20Z","receivedAt":"2014-11-05T22:53:20Z","isPatch":true,"sender":{"key":"ockham@raz.or.at","avatar":"https://avatars.githubusercontent.com/u/96308?v=4"},"body":"Signed-off-by: Bernhard Reiter <ockham@raz.or.at>\n---\nIn reply to <xmqqk339ibal.fsf@gitster.dls.corp.google.com>.\n\nThanks for bearing with me. I should've given the corresponding verbosity\nvalues more thought myself in the first place.\n\n Documentation/git-imap-send.txt | 14 +++++++++++++-\n imap-send.c                     | 25 +++++++++++++++----------\n 2 files changed, 28 insertions(+), 11 deletions(-)\n\ndiff --git a/Documentation/git-imap-send.txt b/Documentation/git-imap-send.txt\nindex c7c0d21..0897131 100644\n--- a/Documentation/git-imap-send.txt\n+++ b/Documentation/git-imap-send.txt\n@@ -9,7 +9,7 @@ git-imap-send - Send a collection of patches from stdin to an IMAP folder\n SYNOPSIS\n --------\n [verse]\n-'git imap-send'\n+'git imap-send' [-v] [-q]\n \n \n DESCRIPTION\n@@ -26,6 +26,18 @@ Typical usage is something like:\n git format-patch --signoff --stdout --attach origin | git imap-send\n \n \n+OPTIONS\n+-------\n+\n+-v::\n+--verbose::\n+\tBe verbose.\n+\n+-q::\n+--quiet::\n+\tBe quiet.\n+\n+\n CONFIGURATION\n -------------\n \ndiff --git a/imap-send.c b/imap-send.c\nindex 70bcc7a..6efaae8 100644\n--- a/imap-send.c\n+++ b/imap-send.c\n@@ -26,11 +26,19 @@\n #include \"credential.h\"\n #include \"exec_cmd.h\"\n #include \"run-command.h\"\n+#include \"parse-options.h\"\n #ifdef NO_OPENSSL\n typedef void *SSL;\n #endif\n \n-static const char imap_send_usage[] = \"git imap-send < <mbox>\";\n+static int verbosity;\n+\n+static const char * const imap_send_usage[] = { \"git imap-send [-v] [-q] < <mbox>\", NULL };\n+\n+static struct option imap_send_options[] = {\n+\tOPT__VERBOSITY(&verbosity),\n+\tOPT_END()\n+};\n \n #undef DRV_OK\n #define DRV_OK          0\n@@ -38,8 +46,6 @@ static const char imap_send_usage[] = \"git imap-send < <mbox>\";\n #define DRV_BOX_BAD     -2\n #define DRV_STORE_BAD   -3\n \n-static int Verbose, Quiet;\n-\n __attribute__((format (printf, 1, 2)))\n static void imap_info(const char *, ...);\n __attribute__((format (printf, 1, 2)))\n@@ -418,7 +424,7 @@ static int buffer_gets(struct imap_buffer *b, char **s)\n \t\t\tif (b->buf[b->offset + 1] == '\\n') {\n \t\t\t\tb->buf[b->offset] = 0;  /* terminate the string */\n \t\t\t\tb->offset += 2; /* next line */\n-\t\t\t\tif (Verbose)\n+\t\t\t\tif (0 < verbosity)\n \t\t\t\t\tputs(*s);\n \t\t\t\treturn 0;\n \t\t\t}\n@@ -433,7 +439,7 @@ static void imap_info(const char *msg, ...)\n {\n \tva_list va;\n \n-\tif (!Quiet) {\n+\tif (verbosity >= 0) {\n \t\tva_start(va, msg);\n \t\tvprintf(msg, va);\n \t\tva_end(va);\n@@ -445,7 +451,7 @@ static void imap_warn(const char *msg, ...)\n {\n \tva_list va;\n \n-\tif (Quiet < 2) {\n+\tif (-2 < verbosity) {\n \t\tva_start(va, msg);\n \t\tvfprintf(stderr, msg, va);\n \t\tva_end(va);\n@@ -522,7 +528,7 @@ static struct imap_cmd *issue_imap_cmd(struct imap_store *ctx,\n \t\t\t\t  cmd->tag, cmd->cmd, cmd->cb.dlen,\n \t\t\t\t  CAP(LITERALPLUS) ? \"+\" : \"\");\n \n-\tif (Verbose) {\n+\tif (0 < verbosity) {\n \t\tif (imap->num_in_progress)\n \t\t\tprintf(\"(%d in progress) \", imap->num_in_progress);\n \t\tif (!starts_with(cmd->cmd, \"LOGIN\"))\n@@ -1352,12 +1358,11 @@ int main(int argc, char **argv)\n \n \tgit_setup_gettext();\n \n-\tif (argc != 1)\n-\t\tusage(imap_send_usage);\n-\n \tsetup_git_directory_gently(&nongit_ok);\n \tgit_imap_config();\n \n+\targc = parse_options(argc, (const char **)argv, \"\", imap_send_options, imap_send_usage, 0);\n+\n \tif (!server.port)\n \t\tserver.port = server.use_ssl ? 993 : 143;\n \n-- \n2.1.2.556.g44ebd84\n"},{"id":"251422","messageId":"xmqqbnoli4e0.fsf@gitster.dls.corp.google.com","threadId":"37886","inReplyTo":"545AAA60.3040207@raz.or.at","subject":"Re: [PATCH v2] imap-send: Use parse options API to determine verbosity","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2014-11-06T00:01:11Z","receivedAt":"2014-11-06T00:01:11Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Bernhard Reiter <ockham@raz.or.at> writes:\n\n> Signed-off-by: Bernhard Reiter <ockham@raz.or.at>\n> ---\n> In reply to <xmqqk339ibal.fsf@gitster.dls.corp.google.com>.\n>\n> Thanks for bearing with me. I should've given the corresponding verbosity\n> values more thought myself in the first place.\n\nThe original defined and even used these two variables, but as far\nas I can tell they were always set to 0 and nobody modified them.\nHence, we would be OK as long as the end result will behave the same\nas before without any -v/-q from the command line ;-)\n\nThanks.  This version looks more sensible.\n\n> -\tif (argc != 1)\n> -\t\tusage(imap_send_usage);\n> -\n>  \tsetup_git_directory_gently(&nongit_ok);\n>  \tgit_imap_config();\n>  \n> +\targc = parse_options(argc, (const char **)argv, \"\", imap_send_options, imap_send_usage, 0);\n> +\n\n... except we might want to check argc here and say something about\nmissing or excess parameters, which was lost in the change in this\nhunk.  I think (without giving it a real thought, though ;-) you\nwould expect that nothing remains on the command line after\nparse_options() has done its thing, no?\n\n\n>  \tif (!server.port)\n>  \t\tserver.port = server.use_ssl ? 993 : 143;\n"},{"id":"251423","messageId":"xmqq7fz9i319.fsf@gitster.dls.corp.google.com","threadId":"37886","inReplyTo":"xmqqbnoli4e0.fsf@gitster.dls.corp.google.com","subject":"Re: [PATCH v2] imap-send: Use parse options API to determine verbosity","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2014-11-06T00:30:26Z","receivedAt":"2014-11-06T00:30:26Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> Thanks.  This version looks more sensible.\n>\n>> -\tif (argc != 1)\n>> -\t\tusage(imap_send_usage);\n>> -\n>>  \tsetup_git_directory_gently(&nongit_ok);\n>>  \tgit_imap_config();\n>>  \n>> + argc = parse_options(argc, (const char **)argv, \"\",\n>> imap_send_options, imap_send_usage, 0);\n>> +\n>\n> ... except we might want to check argc here and say something about\n> missing or excess parameters, which was lost in the change in this\n> hunk.  I think (without giving it a real thought, though ;-) you\n> would expect that nothing remains on the command line after\n> parse_options() has done its thing, no?\n>\n>\n>>  \tif (!server.port)\n>>  \t\tserver.port = server.use_ssl ? 993 : 143;\n\nSo here is what I ended up queuing for now.  I think the new check\non argc is correct but I wouldn't be surprised if I had off-by-one\nerror or something silly like that ;-).\n\n-- >8 --\nFrom: Bernhard Reiter <ockham@raz.or.at>\nDate: Wed, 5 Nov 2014 15:29:21 +0100\nSubject: [PATCH] imap-send: use parse options API to determine verbosity\n\nThe -v/-q options were sort-of supported but without using the\nparse-options API, and were not documented.\n\nSigned-off-by: Bernhard Reiter <ockham@raz.or.at>\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n Documentation/git-imap-send.txt | 14 +++++++++++++-\n imap-send.c                     | 28 ++++++++++++++++++----------\n 2 files changed, 31 insertions(+), 11 deletions(-)\n\ndiff --git a/Documentation/git-imap-send.txt b/Documentation/git-imap-send.txt\nindex c7c0d21..0897131 100644\n--- a/Documentation/git-imap-send.txt\n+++ b/Documentation/git-imap-send.txt\n@@ -9,7 +9,7 @@ git-imap-send - Send a collection of patches from stdin to an IMAP folder\n SYNOPSIS\n --------\n [verse]\n-'git imap-send'\n+'git imap-send' [-v] [-q]\n \n \n DESCRIPTION\n@@ -26,6 +26,18 @@ Typical usage is something like:\n git format-patch --signoff --stdout --attach origin | git imap-send\n \n \n+OPTIONS\n+-------\n+\n+-v::\n+--verbose::\n+\tBe verbose.\n+\n+-q::\n+--quiet::\n+\tBe quiet.\n+\n+\n CONFIGURATION\n -------------\n \ndiff --git a/imap-send.c b/imap-send.c\nindex 70bcc7a..7f9d30e 100644\n--- a/imap-send.c\n+++ b/imap-send.c\n@@ -26,11 +26,19 @@\n #include \"credential.h\"\n #include \"exec_cmd.h\"\n #include \"run-command.h\"\n+#include \"parse-options.h\"\n #ifdef NO_OPENSSL\n typedef void *SSL;\n #endif\n \n-static const char imap_send_usage[] = \"git imap-send < <mbox>\";\n+static int verbosity;\n+\n+static const char * const imap_send_usage[] = { \"git imap-send [-v] [-q] < <mbox>\", NULL };\n+\n+static struct option imap_send_options[] = {\n+\tOPT__VERBOSITY(&verbosity),\n+\tOPT_END()\n+};\n \n #undef DRV_OK\n #define DRV_OK          0\n@@ -38,8 +46,6 @@ static const char imap_send_usage[] = \"git imap-send < <mbox>\";\n #define DRV_BOX_BAD     -2\n #define DRV_STORE_BAD   -3\n \n-static int Verbose, Quiet;\n-\n __attribute__((format (printf, 1, 2)))\n static void imap_info(const char *, ...);\n __attribute__((format (printf, 1, 2)))\n@@ -418,7 +424,7 @@ static int buffer_gets(struct imap_buffer *b, char **s)\n \t\t\tif (b->buf[b->offset + 1] == '\\n') {\n \t\t\t\tb->buf[b->offset] = 0;  /* terminate the string */\n \t\t\t\tb->offset += 2; /* next line */\n-\t\t\t\tif (Verbose)\n+\t\t\t\tif (0 < verbosity)\n \t\t\t\t\tputs(*s);\n \t\t\t\treturn 0;\n \t\t\t}\n@@ -433,7 +439,7 @@ static void imap_info(const char *msg, ...)\n {\n \tva_list va;\n \n-\tif (!Quiet) {\n+\tif (0 <= verbosity) {\n \t\tva_start(va, msg);\n \t\tvprintf(msg, va);\n \t\tva_end(va);\n@@ -445,7 +451,7 @@ static void imap_warn(const char *msg, ...)\n {\n \tva_list va;\n \n-\tif (Quiet < 2) {\n+\tif (-2 < verbosity) {\n \t\tva_start(va, msg);\n \t\tvfprintf(stderr, msg, va);\n \t\tva_end(va);\n@@ -522,7 +528,7 @@ static struct imap_cmd *issue_imap_cmd(struct imap_store *ctx,\n \t\t\t\t  cmd->tag, cmd->cmd, cmd->cb.dlen,\n \t\t\t\t  CAP(LITERALPLUS) ? \"+\" : \"\");\n \n-\tif (Verbose) {\n+\tif (0 < verbosity) {\n \t\tif (imap->num_in_progress)\n \t\t\tprintf(\"(%d in progress) \", imap->num_in_progress);\n \t\tif (!starts_with(cmd->cmd, \"LOGIN\"))\n@@ -1352,12 +1358,14 @@ int main(int argc, char **argv)\n \n \tgit_setup_gettext();\n \n-\tif (argc != 1)\n-\t\tusage(imap_send_usage);\n-\n \tsetup_git_directory_gently(&nongit_ok);\n \tgit_imap_config();\n \n+\targc = parse_options(argc, (const char **)argv, \"\", imap_send_options, imap_send_usage, 0);\n+\n+\tif (argc)\n+\t\tusage_with_options(imap_send_usage, imap_send_options);\n+\n \tif (!server.port)\n \t\tserver.port = server.use_ssl ? 993 : 143;\n \n-- \n2.2.0-rc0-55-gac00a8d\n"}]}