1 Return-Path: <bremner@tethera.net>
\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 arlo.cworth.org (Postfix) with ESMTP id 4E7806DE1633
\r
6 for <notmuch@notmuchmail.org>; Sun, 6 Sep 2015 06:58:45 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at cworth.org
\r
11 X-Spam-Status: No, score=2.649 tagged_above=-999 required=5 tests=[AWL=-1.041,
\r
12 RCVD_IN_BRBL_LASTEXT=1.644, RCVD_IN_SBL=2.596, RP_MATCHES_RCVD=-0.55]
\r
14 Received: from arlo.cworth.org ([127.0.0.1])
\r
15 by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)
\r
16 with ESMTP id 4IASAOxUZILH for <notmuch@notmuchmail.org>;
\r
17 Sun, 6 Sep 2015 06:58:43 -0700 (PDT)
\r
18 Received: from yantan.tethera.net (yantan.tethera.net [199.188.72.155])
\r
19 by arlo.cworth.org (Postfix) with ESMTPS id 8B76E6DE1636
\r
20 for <notmuch@notmuchmail.org>; Sun, 6 Sep 2015 06:58:43 -0700 (PDT)
\r
21 Received: from remotemail by yantan.tethera.net with local (Exim 4.80)
\r
22 (envelope-from <bremner@tethera.net>)
\r
23 id 1ZYZnX-0002x9-2s; Sun, 06 Sep 2015 10:15:55 -0300
\r
24 Received: (nullmailer pid 29728 invoked by uid 1000); Sun, 06 Sep 2015
\r
26 From: David Bremner <david@tethera.net>
\r
27 To: notmuch@notmuchmail.org
\r
28 Subject: [PATCH 2/3] cli/count: update to use notmuch_query_search_messages_st
\r
29 Date: Sun, 6 Sep 2015 10:15:46 -0300
\r
30 Message-Id: <1441545347-29549-2-git-send-email-david@tethera.net>
\r
31 X-Mailer: git-send-email 2.5.1
\r
32 In-Reply-To: <1441545347-29549-1-git-send-email-david@tethera.net>
\r
33 References: <1441545347-29549-1-git-send-email-david@tethera.net>
\r
34 X-BeenThere: notmuch@notmuchmail.org
\r
35 X-Mailman-Version: 2.1.18
\r
37 List-Id: "Use and development of the notmuch mail system."
\r
38 <notmuch.notmuchmail.org>
\r
39 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
40 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
41 List-Archive: <http://notmuchmail.org/pipermail/notmuch/>
\r
42 List-Post: <mailto:notmuch@notmuchmail.org>
\r
43 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
44 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
45 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
46 X-List-Received-Date: Sun, 06 Sep 2015 13:58:45 -0000
\r
48 This brings back status information that may have been hidden by the
\r
49 great library logging conversion.
\r
51 Note the change of the internal API / return-value for count_files The
\r
52 other count calls to the lib will also get error handling when that
\r
53 API is updated in the lib.
\r
55 notmuch-count.c | 22 ++++++++++++++++------
\r
56 test/T060-count.sh | 30 ++++++++++++++++++++++++++++++
\r
57 2 files changed, 46 insertions(+), 6 deletions(-)
\r
59 diff --git a/notmuch-count.c b/notmuch-count.c
\r
60 index f26e726..65e1f4e 100644
\r
61 --- a/notmuch-count.c
\r
62 +++ b/notmuch-count.c
\r
63 @@ -34,17 +34,19 @@ enum {
\r
67 -static unsigned int
\r
68 +/* Return the number of files matching the query, or -1 for an error */
\r
70 count_files (notmuch_query_t *query)
\r
72 notmuch_messages_t *messages;
\r
73 notmuch_message_t *message;
\r
74 notmuch_filenames_t *filenames;
\r
75 - unsigned int count = 0;
\r
76 + notmuch_status_t status;
\r
79 - messages = notmuch_query_search_messages (query);
\r
80 - if (messages == NULL)
\r
82 + status = notmuch_query_search_messages_st (query, &messages);
\r
83 + if (print_status_query ("notmuch count", query, status))
\r
87 notmuch_messages_valid (messages);
\r
88 @@ -72,6 +74,7 @@ print_count (notmuch_database_t *notmuch, const char *query_str,
\r
90 notmuch_query_t *query;
\r
93 unsigned long revision;
\r
96 @@ -93,7 +96,13 @@ print_count (notmuch_database_t *notmuch, const char *query_str,
\r
97 printf ("%u", notmuch_query_count_threads (query));
\r
100 - printf ("%u", count_files (query));
\r
101 + count = count_files (query);
\r
102 + if (count >= 0) {
\r
103 + printf ("%u", count);
\r
111 @@ -104,6 +113,7 @@ print_count (notmuch_database_t *notmuch, const char *query_str,
\r
112 fputs ("\n", stdout);
\r
116 notmuch_query_destroy (query);
\r
119 diff --git a/test/T060-count.sh b/test/T060-count.sh
\r
120 index 5ef3879..3fec94e 100755
\r
121 --- a/test/T060-count.sh
\r
122 +++ b/test/T060-count.sh
\r
123 @@ -93,5 +93,35 @@ notmuch count --output=messages >>EXPECTED
\r
124 notmuch count --output=messages tag:inbox >>EXPECTED
\r
125 test_expect_equal_file EXPECTED OUTPUT
\r
128 +test_begin_subtest "error message for database open"
\r
129 +dd if=/dev/zero of="${MAIL_DIR}/.notmuch/xapian/postlist.DB" count=3
\r
130 +notmuch count '*' 2>OUTPUT 1>/dev/null
\r
131 +output=$(sed 's/^\(A Xapian exception [^:]*\):.*$/\1/' OUTPUT)
\r
132 +test_expect_equal "${output}" "A Xapian exception occurred opening database"
\r
135 +cat <<EOF > count-files.gdb
\r
136 +set breakpoint pending on
\r
139 +shell cp /dev/null ${MAIL_DIR}/.notmuch/xapian/postlist.DB
\r
146 +test_begin_subtest "error message from query_search_messages"
\r
147 +gdb --batch-silent --return-child-result -x count-files.gdb \
\r
148 + --args notmuch count --output=files '*' 2>OUTPUT 1>/dev/null
\r
149 +cat <<EOF > EXPECTED
\r
150 +notmuch count: A Xapian exception occurred
\r
151 +A Xapian exception occurred performing query
\r
152 +Query string was: *
\r
154 +sed 's/^\(A Xapian exception [^:]*\):.*$/\1/' < OUTPUT > OUTPUT.clean
\r
155 +test_expect_equal_file EXPECTED OUTPUT.clean
\r