Flat search and threaded views
[notmuch-archives.git] / 42 / cfd4d3d27400ac01a270aeaa4704a8918f8c1c
1 Return-Path: <aperez@hikari.localdomain>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5         by olra.theworths.org (Postfix) with ESMTP id DC56B431FBC\r
6         for <notmuch@notmuchmail.org>; Sun, 22 Nov 2009 16:09:36 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 Received: from olra.theworths.org ([127.0.0.1])\r
9         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
10         with ESMTP id BE2jBL0gfPEr for <notmuch@notmuchmail.org>;\r
11         Sun, 22 Nov 2009 16:09:36 -0800 (PST)\r
12 Received: from alice.connectical.com (alice.connectical.com [208.89.208.235])\r
13         by olra.theworths.org (Postfix) with ESMTP id 2E0DE431FAE\r
14         for <notmuch@notmuchmail.org>; Sun, 22 Nov 2009 16:09:36 -0800 (PST)\r
15 Received: (qmail 1559 invoked from network); 23 Nov 2009 00:09:27 -0000\r
16 Received: from 28.218.27.77.dynamic.mundo-r.com (HELO hikari.localdomain)\r
17         (aperez@77.27.218.28)\r
18         by alice.connectical.com with ESMTPA; 23 Nov 2009 00:09:27 -0000\r
19 Received: by hikari.localdomain (Postfix, from userid 500)\r
20         id D6575310915F; Mon, 23 Nov 2009 01:10:44 +0100 (CET)\r
21 From: Adrian Perez <aperez@igalia.com>\r
22 To: notmuch@notmuchmail.org\r
23 Date: Mon, 23 Nov 2009 01:10:44 +0100\r
24 Message-Id: <1258935044-30169-1-git-send-email-aperez@igalia.com>\r
25 X-Mailer: git-send-email 1.6.5.2\r
26 In-Reply-To: <1258762638-22905-1-git-send-email-aperez@igalia.com>\r
27 References: <1258762638-22905-1-git-send-email-aperez@igalia.com>\r
28 Subject: [notmuch] [PATCH] Support for printing file paths in new command\r
29 X-BeenThere: notmuch@notmuchmail.org\r
30 X-Mailman-Version: 2.1.12\r
31 Precedence: list\r
32 List-Id: "Use and development of the notmuch mail system."\r
33         <notmuch.notmuchmail.org>\r
34 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
35         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
36 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
37 List-Post: <mailto:notmuch@notmuchmail.org>\r
38 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
39 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
40         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
41 X-List-Received-Date: Mon, 23 Nov 2009 00:09:37 -0000\r
42 \r
43 For very large mail boxes, it is desirable to know which files are being\r
44 processed e.g. when a crash occurs to know which one was the cause. Also,\r
45 it may be interesting to have a better idea of how the operation is\r
46 progressing when processing mailboxes with big messages.\r
47 \r
48 This patch adds support for printing messages as they are processed by\r
49 "notmuch new":\r
50 \r
51 * The "new" command now supports a "--verbose" flag.\r
52 \r
53 * When running in verbose mode, the file path of the message about to be\r
54   processed is printed in the following format:\r
55 \r
56     current/total: /path/to/message/file\r
57 \r
58   Where "current" is the number of messages processed so far and "total" is\r
59   the total count of files to be processed.\r
60 \r
61 * The status line is erased using an ANSI sequence "\033[K" (erase current\r
62   line from the cursor to the end of line) each time it is refreshed. This\r
63   should not pose a problem because nearly every terminal supports it.\r
64 \r
65 * When output is not being sent to a terminal, then each file processed is\r
66   printed in a new line and ANSI escapes are not used at all.\r
67 \r
68 * The signal handler for SIGALRM and the timer are not enabled when running\r
69   in verbose mode, because we are already printing progress with each file,\r
70   periodical reports are not neccessary.\r
71 ---\r
72  notmuch-client.h |    2 ++\r
73  notmuch-new.c    |   32 +++++++++++++++++++++++++++++---\r
74  notmuch.c        |   11 +++++++++--\r
75  3 files changed, 40 insertions(+), 5 deletions(-)\r
76 \r
77 diff --git a/notmuch-client.h b/notmuch-client.h\r
78 index ea77686..4fe182e 100644\r
79 --- a/notmuch-client.h\r
80 +++ b/notmuch-client.h\r
81 @@ -74,6 +74,8 @@ typedef void (*add_files_callback_t) (notmuch_message_t *message);\r
82  typedef struct {\r
83      int ignore_read_only_directories;\r
84      int saw_read_only_directory;\r
85 +    int output_is_a_tty;\r
86 +    int verbose;\r
87  \r
88      int total_files;\r
89      int processed_files;\r
90 diff --git a/notmuch-new.c b/notmuch-new.c\r
91 index 0dd2784..b5c6cc6 100644\r
92 --- a/notmuch-new.c\r
93 +++ b/notmuch-new.c\r
94 @@ -179,6 +179,19 @@ add_files_recursive (notmuch_database_t *notmuch,\r
95             if (path_dbtime == 0 || st->st_mtime > path_dbtime) {\r
96                 state->processed_files++;\r
97  \r
98 +               if (state->verbose) {\r
99 +                   if (state->output_is_a_tty)\r
100 +                       printf("\r\033[K");\r
101 +\r
102 +                   printf ("%i/%i: %s",\r
103 +                           state->processed_files,\r
104 +                           state->total_files,\r
105 +                           next);\r
106 +\r
107 +                   putchar((state->output_is_a_tty) ? '\r' : '\n');\r
108 +                   fflush (stdout);\r
109 +               }\r
110 +\r
111                 status = notmuch_database_add_message (notmuch, next, &message);\r
112                 switch (status) {\r
113                     /* success */\r
114 @@ -275,7 +288,7 @@ add_files (notmuch_database_t *notmuch,\r
115      }\r
116  \r
117      /* Setup our handler for SIGALRM */\r
118 -    if (isatty (fileno (stdout)) && ! debugger_is_active ()) {\r
119 +    if (state->output_is_a_tty && ! debugger_is_active () && ! state->verbose) {\r
120         memset (&action, 0, sizeof (struct sigaction));\r
121         action.sa_handler = handle_sigalrm;\r
122         sigemptyset (&action.sa_mask);\r
123 @@ -296,6 +309,7 @@ add_files (notmuch_database_t *notmuch,\r
124  \r
125      /* Now stop the timer. */\r
126      if (timer_is_active) {\r
127 +       /* Now stop the timer. */\r
128         timerval.it_interval.tv_sec = 0;\r
129         timerval.it_interval.tv_usec = 0;\r
130         timerval.it_value.tv_sec = 0;\r
131 @@ -380,8 +394,7 @@ count_files (const char *path, int *count)\r
132  }\r
133  \r
134  int\r
135 -notmuch_new_command (void *ctx,\r
136 -                    unused (int argc), unused (char *argv[]))\r
137 +notmuch_new_command (void *ctx, int argc, char *argv[])\r
138  {\r
139      notmuch_config_t *config;\r
140      notmuch_database_t *notmuch;\r
141 @@ -393,6 +406,19 @@ notmuch_new_command (void *ctx,\r
142      const char *db_path;\r
143      char *dot_notmuch_path;\r
144      struct sigaction action;\r
145 +    int i;\r
146 +\r
147 +    add_files_state.verbose = 0;\r
148 +    add_files_state.output_is_a_tty = isatty (fileno (stdout));\r
149 +\r
150 +    for (i = 0; i < argc && argv[i][0] == '-'; i++) {\r
151 +       if (STRNCMP_LITERAL (argv[i], "--verbose") == 0) {\r
152 +           add_files_state.verbose = 1;\r
153 +       } else {\r
154 +           fprintf (stderr, "Unrecognized option: %s\n", argv[i]);\r
155 +           return 1;\r
156 +       }\r
157 +    }\r
158  \r
159      /* Setup our handler for SIGINT */\r
160      memset (&action, 0, sizeof (struct sigaction));\r
161 diff --git a/notmuch.c b/notmuch.c\r
162 index 5cc8e4c..8cb1310 100644\r
163 --- a/notmuch.c\r
164 +++ b/notmuch.c\r
165 @@ -107,8 +107,8 @@ command_t commands[] = {\r
166        "\t\tInvoking notmuch with no command argument will run setup if\n"\r
167        "\t\tthe setup command has not previously been completed." },\r
168      { "new", notmuch_new_command,\r
169 -      NULL,\r
170 -      "Find and import new messages to the notmuch database.",\r
171 +      "[--verbose]",\r
172 +      "\t\tFind and import new messages to the notmuch database.",\r
173        "\t\tScans all sub-directories of the mail directory, performing\n"\r
174        "\t\tfull-text indexing on new messages that are found. Each new\n"\r
175        "\t\tmessage will be tagged as both \"inbox\" and \"unread\".\n"\r
176 @@ -122,6 +122,13 @@ command_t commands[] = {\r
177        "\t\tis delivered and you wish to incorporate it into the database.\n"\r
178        "\t\tThese subsequent runs will be much quicker than the initial run.\n"\r
179        "\n"\r
180 +      "\t\tSupported options for new include:\n"\r
181 +      "\n"\r
182 +      "\t\t--verbose\n"\r
183 +      "\n"\r
184 +      "\t\t\tVerbose operation. Shows paths of message files as\n"\r
185 +      "\t\t\tthey are being indexed.\n"\r
186 +      "\n"\r
187        "\t\tNote: \"notmuch new\" runs (other than the first run) will\n"\r
188        "\t\tskip any read-only directories, so you can use that to mark\n"\r
189        "\t\tdirectories that will not receive any new mail (and make\n"\r
190 -- \r
191 1.6.5.2\r
192 \r