[PATCH 6/7] cli: add --quiet option to notmuch new
authorJani Nikula <jani@nikula.org>
Sun, 19 Jan 2014 20:32:27 +0000 (22:32 +0200)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:59:10 +0000 (09:59 -0800)
66/b08ca9634107209f85f61e2eb4a964b7085633 [new file with mode: 0644]

diff --git a/66/b08ca9634107209f85f61e2eb4a964b7085633 b/66/b08ca9634107209f85f61e2eb4a964b7085633
new file mode 100644 (file)
index 0000000..edaa9ef
--- /dev/null
@@ -0,0 +1,206 @@
+Return-Path: <jani@nikula.org>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id 13653431FC0\r
+       for <notmuch@notmuchmail.org>; Sun, 19 Jan 2014 12:33:20 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References"\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.7\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
+       tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id rzCcvvGjV2VT for <notmuch@notmuchmail.org>;\r
+       Sun, 19 Jan 2014 12:33:14 -0800 (PST)\r
+Received: from mail-ee0-f53.google.com (mail-ee0-f53.google.com\r
+ [74.125.83.53])       (using TLSv1 with cipher RC4-SHA (128/128 bits))        (No client\r
+ certificate requested)        by olra.theworths.org (Postfix) with ESMTPS id\r
+ B6A21431FC2   for <notmuch@notmuchmail.org>; Sun, 19 Jan 2014 12:32:52 -0800\r
+ (PST)\r
+Received: by mail-ee0-f53.google.com with SMTP id t10so3032743eei.26\r
+       for <notmuch@notmuchmail.org>; Sun, 19 Jan 2014 12:32:51 -0800 (PST)\r
+X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
+       d=1e100.net; s=20130820;\r
+       h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\r
+       :references:in-reply-to:references;\r
+       bh=D6+aP1uMxK+c/ZCQHQ9Eh2ohBxFQLkC73CpVyS+ltqY=;\r
+       b=PyHRhlKtzJ9GIjYOEkZfmP71jzfSGJ4qgKCBPd9aVCF9kguXY0Fnhtiw3hkRTOF9nD\r
+       jb0yr9SpePuqkVNVeZfp8we6A+79ACpecOP5CbtRcO4f0FJmhDzbrKtA8+fdwktVpMAN\r
+       nuGeQnuo8pKbH7oRkXHzqz7Aset+4t936Y164QE68a+I63xPLtPyiWh4n5/OwvFmcq1f\r
+       wwxSwlTPqyYyfs2gW9RGKvCH5eWArvCKHR2QbwD3axwy/dG2V2gY29h5gEcJ6op56woK\r
+       q+wJ7MZK00IuWXANMV/a8WVyEA6ICMrQsVfYAf7mYNPrCISwsYueiYhUtlvriHGDWdu6\r
+       RtAQ==\r
+X-Gm-Message-State:\r
+ ALoCoQluG5CPOvlfLZtvpjLunBlKofP5cwr3pioIxaNK3qFMAlT/fkatUC4dYFnrwTa4+F2doidd\r
+X-Received: by 10.14.2.73 with SMTP id 49mr14223995eee.15.1390163571572;\r
+       Sun, 19 Jan 2014 12:32:51 -0800 (PST)\r
+Received: from localhost (dsl-hkibrasgw2-58c36f-91.dhcp.inet.fi.\r
+       [88.195.111.91])\r
+       by mx.google.com with ESMTPSA id v1sm46527413eef.9.2014.01.19.12.32.50\r
+       for <multiple recipients>\r
+       (version=TLSv1.2 cipher=RC4-SHA bits=128/128);\r
+       Sun, 19 Jan 2014 12:32:50 -0800 (PST)\r
+From: Jani Nikula <jani@nikula.org>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 6/7] cli: add --quiet option to notmuch new\r
+Date: Sun, 19 Jan 2014 22:32:27 +0200\r
+Message-Id:\r
+ <276371280dfbf8d98a9970b68910e1c030769641.1390163335.git.jani@nikula.org>\r
+X-Mailer: git-send-email 1.8.5.2\r
+In-Reply-To: <cover.1390163335.git.jani@nikula.org>\r
+References: <cover.1390163335.git.jani@nikula.org>\r
+In-Reply-To: <cover.1390163335.git.jani@nikula.org>\r
+References: <cover.1390163335.git.jani@nikula.org>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Sun, 19 Jan 2014 20:33:20 -0000\r
+\r
+Tie it to --verbose (resulting in verbosity levels of quiet, normal,\r
+and verbose) but leave --debug orthogonal. Do some drive-by cleaning\r
+while at it.\r
+---\r
+ notmuch-new.c | 47 ++++++++++++++++++++++++++++++++---------------\r
+ 1 file changed, 32 insertions(+), 15 deletions(-)\r
+\r
+diff --git a/notmuch-new.c b/notmuch-new.c\r
+index c443181..cd74489 100644\r
+--- a/notmuch-new.c\r
++++ b/notmuch-new.c\r
+@@ -34,9 +34,15 @@ typedef struct _filename_list {\r
+     _filename_node_t **tail;\r
+ } _filename_list_t;\r
\r
++enum verbosity {\r
++    VERBOSITY_QUIET,\r
++    VERBOSITY_NORMAL,\r
++    VERBOSITY_VERBOSE,\r
++};\r
++\r
+ typedef struct {\r
+     int output_is_a_tty;\r
+-    notmuch_bool_t verbose;\r
++    enum verbosity verbosity;\r
+     notmuch_bool_t debug;\r
+     const char **new_tags;\r
+     size_t new_tags_length;\r
+@@ -566,13 +572,11 @@ add_files (notmuch_database_t *notmuch,\r
\r
+       state->processed_files++;\r
\r
+-      if (state->verbose) {\r
++      if (state->verbosity >= VERBOSITY_VERBOSE) {\r
+           if (state->output_is_a_tty)\r
+               printf("\r\033[K");\r
\r
+-          printf ("%i/%i: %s",\r
+-                  state->processed_files,\r
+-                  state->total_files,\r
++          printf ("%i/%i: %s", state->processed_files, state->total_files,\r
+                   next);\r
\r
+           putchar((state->output_is_a_tty) ? '\r' : '\n');\r
+@@ -741,7 +745,7 @@ count_files (const char *path, int *count, add_files_state_t *state)\r
+       entry_type = dirent_type (path, entry);\r
+       if (entry_type == S_IFREG) {\r
+           *count = *count + 1;\r
+-          if (*count % 1000 == 0) {\r
++          if (*count % 1000 == 0 && state->verbosity >= VERBOSITY_NORMAL) {\r
+               printf ("Found %d files so far.\r", *count);\r
+               fflush (stdout);\r
+           }\r
+@@ -917,13 +921,15 @@ notmuch_new_command (notmuch_config_t *config, int argc, char *argv[])\r
+     int i;\r
+     notmuch_bool_t timer_is_active = FALSE;\r
+     notmuch_bool_t no_hooks = FALSE;\r
++    notmuch_bool_t quiet = FALSE, verbose = FALSE;\r
\r
+-    add_files_state.verbose = FALSE;\r
++    add_files_state.verbosity = VERBOSITY_NORMAL;\r
+     add_files_state.debug = FALSE;\r
+     add_files_state.output_is_a_tty = isatty (fileno (stdout));\r
\r
+     notmuch_opt_desc_t options[] = {\r
+-      { NOTMUCH_OPT_BOOLEAN,  &add_files_state.verbose, "verbose", 'v', 0 },\r
++      { NOTMUCH_OPT_BOOLEAN,  &quiet, "quiet", 'q', 0 },\r
++      { NOTMUCH_OPT_BOOLEAN,  &verbose, "verbose", 'v', 0 },\r
+       { NOTMUCH_OPT_BOOLEAN,  &add_files_state.debug, "debug", 'd', 0 },\r
+       { NOTMUCH_OPT_BOOLEAN,  &no_hooks, "no-hooks", 'n', 0 },\r
+       { 0, 0, 0, 0, 0 }\r
+@@ -933,6 +939,12 @@ notmuch_new_command (notmuch_config_t *config, int argc, char *argv[])\r
+     if (opt_index < 0)\r
+       return EXIT_FAILURE;\r
\r
++    /* quiet trumps verbose */\r
++    if (quiet)\r
++      add_files_state.verbosity = VERBOSITY_QUIET;\r
++    else if (verbose)\r
++      add_files_state.verbosity = VERBOSITY_VERBOSE;\r
++\r
+     add_files_state.new_tags = notmuch_config_get_new_tags (config, &add_files_state.new_tags_length);\r
+     add_files_state.new_ignore = notmuch_config_get_new_ignore (config, &add_files_state.new_ignore_length);\r
+     add_files_state.synchronize_flags = notmuch_config_get_maildir_synchronize_flags (config);\r
+@@ -954,7 +966,8 @@ notmuch_new_command (notmuch_config_t *config, int argc, char *argv[])\r
+       if (interrupted)\r
+           return EXIT_FAILURE;\r
\r
+-      printf ("Found %d total files (that's not much mail).\n", count);\r
++      if (add_files_state.verbosity >= VERBOSITY_NORMAL)\r
++          printf ("Found %d total files (that's not much mail).\n", count);\r
+       if (notmuch_database_create (db_path, &notmuch))\r
+           return EXIT_FAILURE;\r
+       add_files_state.total_files = count;\r
+@@ -964,11 +977,14 @@ notmuch_new_command (notmuch_config_t *config, int argc, char *argv[])\r
+           return EXIT_FAILURE;\r
\r
+       if (notmuch_database_needs_upgrade (notmuch)) {\r
+-          printf ("Welcome to a new version of notmuch! Your database will now be upgraded.\n");\r
++          if (add_files_state.verbosity >= VERBOSITY_NORMAL)\r
++              printf ("Welcome to a new version of notmuch! Your database will now be upgraded.\n");\r
+           gettimeofday (&add_files_state.tv_start, NULL);\r
+-          notmuch_database_upgrade (notmuch, upgrade_print_progress,\r
++          notmuch_database_upgrade (notmuch,\r
++                                    add_files_state.verbosity >= VERBOSITY_NORMAL ? upgrade_print_progress : NULL,\r
+                                     &add_files_state);\r
+-          printf ("Your notmuch database has now been upgraded to database format version %u.\n",\r
++          if (add_files_state.verbosity >= VERBOSITY_NORMAL)\r
++              printf ("Your notmuch database has now been upgraded to database format version %u.\n",\r
+                   notmuch_database_get_version (notmuch));\r
+       }\r
\r
+@@ -999,8 +1015,8 @@ notmuch_new_command (notmuch_config_t *config, int argc, char *argv[])\r
+     add_files_state.removed_directories = _filename_list_create (config);\r
+     add_files_state.directory_mtimes = _filename_list_create (config);\r
\r
+-    if (! debugger_is_active () && add_files_state.output_is_a_tty\r
+-      && ! add_files_state.verbose) {\r
++    if (add_files_state.verbosity == VERBOSITY_NORMAL &&\r
++      add_files_state.output_is_a_tty && ! debugger_is_active ()) {\r
+       setup_progress_printing_timer ();\r
+       timer_is_active = TRUE;\r
+     }\r
+@@ -1053,7 +1069,8 @@ notmuch_new_command (notmuch_config_t *config, int argc, char *argv[])\r
+     if (timer_is_active)\r
+       stop_progress_printing_timer ();\r
\r
+-    print_results (&add_files_state);\r
++    if (add_files_state.verbosity >= VERBOSITY_NORMAL)\r
++      print_results (&add_files_state);\r
\r
+     if (ret)\r
+       fprintf (stderr, "Note: A fatal error was encountered: %s\n",\r
+-- \r
+1.8.5.2\r
+\r