{"thread":{"id":"37883","subject":"imap-send: Use parse options API to determine verbosity","startedAt":"2014-11-05T14:29:21Z","lastAt":"2014-11-05T21:32:02Z","messageCount":2,"participants":["Bernhard Reiter","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"251411","messageId":"545A3441.9040403@raz.or.at","threadId":"37883","inReplyTo":null,"subject":"imap-send: Use parse options API to determine verbosity","fromName":"Bernhard Reiter","fromEmail":"ockham@raz.or.at","sentAt":"2014-11-05T14:29:21Z","receivedAt":"2014-11-05T14:29:21Z","isPatch":false,"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---\nAs requested per <xmqqzjcewq6p.fsf@gitster.dls.corp.google.com>.\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..7f40960 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 (verbosity >= 0)\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 (verbosity < 2) {\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 (verbosity >= 0) {\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.557.g06ecad4\n"},{"id":"251418","messageId":"xmqqk339ibal.fsf@gitster.dls.corp.google.com","threadId":"37883","inReplyTo":"545A3441.9040403@raz.or.at","subject":"Re: imap-send: Use parse options API to determine verbosity","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2014-11-05T21:32:02Z","receivedAt":"2014-11-05T21:32:02Z","isPatch":false,"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> As requested per <xmqqzjcewq6p.fsf@gitster.dls.corp.google.com>.\n\nHeh, I didn't quite \"request\" it, but thanks for a patch anyway.\n\n> diff --git a/imap-send.c b/imap-send.c\n> index 70bcc7a..7f40960 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\nSo it used to be Verbose and Quiet both defaulting to 0 (false).\nNow we have verbosity that defaults to 0, positive telling us to be\nverbose and negative telling us to be 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 (verbosity >= 0)\n>  \t\t\t\t\tputs(*s);\n\n... which means this should be \"if (0 < verbosity)\", i.e. we do not\nsqueak without \"-v\", no?\n\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\nThis one looks sensible; unless we are told to be \"-q\"uiet, we used\nto give this message, and we will continue to do so.\n\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 (verbosity < 2) {\n>  \t\tva_start(va, msg);\n>  \t\tvfprintf(stderr, msg, va);\n>  \t\tva_end(va);\n\nThe cut-off value \"2\" looks strange, but more importantly this\nconversion looks bogus no matter what the cut-off value is.\n\n\"As long as the verbosity is smaller than this value, emit this\nerror message????\"  That sounds backwards that you do not give the\nmessage if you see sufficient number of \"-v\" options, doesn't it?\n\nI think\n\n\tif (-2 < verbosity)\n\nwould be in line with what the original logic seems to have wanted,\nthat is \"If the caller did not ask us to be extra quiet (i.e. just\nthe regular Quiet=1 does not count), show this message\".\n\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 (verbosity >= 0) {\n\nSame comment as the one at hunk -418,7 above applies.\n"}]}