--- /dev/null
+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 CA0A3431FBC\r
+ for <notmuch@notmuchmail.org>; Sat, 7 Mar 2015 05:56:53 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 1.738\r
+X-Spam-Level: *\r
+X-Spam-Status: No, score=1.738 tagged_above=-999 required=5\r
+ tests=[DNS_FROM_AHBL_RHSBL=2.438, RCVD_IN_DNSWL_LOW=-0.7]\r
+ 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 EMKrDKcGxhdA for <notmuch@notmuchmail.org>;\r
+ Sat, 7 Mar 2015 05:56:50 -0800 (PST)\r
+Received: from mail-we0-f176.google.com (mail-we0-f176.google.com\r
+ [74.125.82.176]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id 3D9F9431FAE\r
+ for <notmuch@notmuchmail.org>; Sat, 7 Mar 2015 05:56:50 -0800 (PST)\r
+Received: by wesw55 with SMTP id w55so1818361wes.2\r
+ for <notmuch@notmuchmail.org>; Sat, 07 Mar 2015 05:56:49 -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:subject:in-reply-to:references\r
+ :user-agent:date:message-id:mime-version:content-type;\r
+ bh=C2OcpB5z8BzYAn05Cre1UZauYjX8OKLVmWif22t4t+8=;\r
+ b=P12wS/D2R8i9LQWwytN6UXUTEN3xgVs3yIAM2A10gSgvh8ktXyVJdI+gH4hcjgyler\r
+ LU2SH3WJLBWsF4iCw8N3iCNAvUSBpxCW/xtBvzIoqz4QIEqWTTKLVnGERQ40qXmvZLBF\r
+ Nly4q6aKCyE/9plY8tsA3JVgqhqjAHShSKNTDDhlPEqAz2PLWn8UCDiBEjkvw6Me0HYd\r
+ G6tErUfZcw3/ZTf341OqvWae71qj4g1c7hVSrJruoQzvPleQmalzCebttZfWm9H/Sj5q\r
+ 7TyxmqQTIlXCTyUdvlABkfu0L/C8Fp/TZK5RrzIQPOrf/WV6o/u9DVe2m6OAW/RnP60o\r
+ zOmw==\r
+X-Gm-Message-State:\r
+ ALoCoQmCEFAa/NMX+xO//NG/cujMCrVrotrSdfngfmNm2MbA39qmif+mprXuEZFV6AV7ZxIkBqEG\r
+X-Received: by 10.195.11.73 with SMTP id eg9mr38904056wjd.62.1425736609241;\r
+ Sat, 07 Mar 2015 05:56:49 -0800 (PST)\r
+Received: from localhost (mobile-internet-bcee3b-76.dhcp.inet.fi.\r
+ [188.238.59.76]) by mx.google.com with ESMTPSA id\r
+ md2sm10644777wic.19.2015.03.07.05.56.47\r
+ (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\r
+ Sat, 07 Mar 2015 05:56:48 -0800 (PST)\r
+From: Jani Nikula <jani@nikula.org>\r
+To: David Bremner <david@tethera.net>, notmuch@notmuchmail.org\r
+Subject: Re: [PATCH 1/4] lib: add versions of notmuch_query_count_{message,\r
+ threads} with status return\r
+In-Reply-To: <1425717797-19990-2-git-send-email-david@tethera.net>\r
+References: <1419971380-10307-6-git-send-email-david@tethera.net>\r
+ <1425717797-19990-1-git-send-email-david@tethera.net>\r
+ <1425717797-19990-2-git-send-email-david@tethera.net>\r
+User-Agent: Notmuch/0.19+74~g6aeef2e (http://notmuchmail.org) Emacs/24.4.1\r
+ (x86_64-pc-linux-gnu)\r
+Date: Sat, 07 Mar 2015 15:57:08 +0200\r
+Message-ID: <87vbicj4gb.fsf@nikula.org>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain\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: Sat, 07 Mar 2015 13:56:54 -0000\r
+\r
+On Sat, 07 Mar 2015, David Bremner <david@tethera.net> wrote:\r
+> Although I think it's a pretty bad idea to continue using the old API,\r
+> this allows both a more gentle transition for clients of the library,\r
+> and allows us to break one monolithic change into a series\r
+\r
+We should probably bump LIBNOTMUCH_MINOR_VERSION for this.\r
+\r
+See nitpicks inline below, up to you if you decide if they're worthwhile\r
+changes, generally LGTM.\r
+\r
+> ---\r
+> lib/database.cc | 8 +++++++-\r
+> lib/notmuch.h | 34 ++++++++++++++++++++++++++++++----\r
+> lib/query.cc | 36 +++++++++++++++++++++++++++++-------\r
+> 3 files changed, 66 insertions(+), 12 deletions(-)\r
+>\r
+> diff --git a/lib/database.cc b/lib/database.cc\r
+> index 3974e2e..d92eec0 100644\r
+> --- a/lib/database.cc\r
+> +++ b/lib/database.cc\r
+> @@ -1275,7 +1275,13 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,\r
+> if (new_features &\r
+> (NOTMUCH_FEATURE_FILE_TERMS | NOTMUCH_FEATURE_BOOL_FOLDER)) {\r
+> notmuch_query_t *query = notmuch_query_create (notmuch, "");\r
+> - total += notmuch_query_count_messages (query);\r
+> + unsigned msg_count;\r
+\r
+Personal preference, I always want to specify "unsigned int" instead of\r
+just "unsigned". Same all around patches 1 and 2.\r
+\r
+> +\r
+> + status = notmuch_query_count_messages_st (query, &msg_count);\r
+> + if (status)\r
+> + goto DONE;\r
+> +\r
+> + total += msg_count;\r
+> notmuch_query_destroy (query);\r
+> }\r
+> if (new_features & NOTMUCH_FEATURE_DIRECTORY_DOCS) {\r
+> diff --git a/lib/notmuch.h b/lib/notmuch.h\r
+> index 3e326bf..a0fc276 100644\r
+> --- a/lib/notmuch.h\r
+> +++ b/lib/notmuch.h\r
+> @@ -914,12 +914,23 @@ notmuch_threads_destroy (notmuch_threads_t *threads);\r
+> * This function performs a search and returns Xapian's best\r
+> * guess as to number of matching messages.\r
+> *\r
+> - * If a Xapian exception occurs, this function may return 0 (after\r
+> - * printing a message).\r
+> + * The version returning the count directly instead of a status value \r
+> + * is deprecated.\r
+> + *\r
+> + * Return value (of the _st) version:\r
+> + *\r
+> + * NOTMUCH_STATUS_SUCCESS: query complete successfully.\r
+> + *\r
+> + * NOTMUCH_STATUS_XAPIAN_EXCEPTION: a Xapian exception occured. The\r
+> + * value of *count is not defined.\r
+> */\r
+\r
+I'd really like to have separate doc comments for both the\r
+functions. The original and now deprecated version can be be a brief\r
+one, with a reference to the _st version documentation. If you move the\r
+_st version declaration here, above the original declaration, the diff\r
+should remain small.\r
+\r
+Perhaps reference the library version number when this was added?\r
+\r
+> +\r
+> unsigned\r
+> notmuch_query_count_messages (notmuch_query_t *query);\r
+> \r
+> +notmuch_status_t\r
+> +notmuch_query_count_messages_st (notmuch_query_t *query, unsigned *count);\r
+> +\r
+> /**\r
+> * Return the number of threads matching a search.\r
+> *\r
+> @@ -928,13 +939,28 @@ notmuch_query_count_messages (notmuch_query_t *query);\r
+> * search.\r
+> *\r
+> * Note that this is a significantly heavier operation than\r
+> - * notmuch_query_count_messages().\r
+> + * notmuch_query_count_messages{_st}().\r
+> + *\r
+> + * The version returning the count directly instead of a status value \r
+> + * is deprecated.\r
+> *\r
+> - * If an error occurs, this function may return 0.\r
+> + * Return values (of the _st version):\r
+> + *\r
+> + * NOTMUCH_STATUS_OUT_OF_MEMORY: Memory allocation failed. The value\r
+> + * of *count is not defined\r
+> +\r
+> + * NOTMUCH_STATUS_SUCCESS: query complete successfully.\r
+> + *\r
+> + * NOTMUCH_STATUS_XAPIAN_EXCEPTION: a Xapian exception occured. The\r
+> + * value of *count is not defined.\r
+> */\r
+\r
+Same as above.\r
+\r
+> +\r
+> unsigned\r
+> notmuch_query_count_threads (notmuch_query_t *query);\r
+> \r
+> +notmuch_status_t\r
+> +notmuch_query_count_threads_st (notmuch_query_t *query, unsigned *count);\r
+> +\r
+> /**\r
+> * Get the thread ID of 'thread'.\r
+> *\r
+> diff --git a/lib/query.cc b/lib/query.cc\r
+> index 9279915..883d128 100644\r
+> --- a/lib/query.cc\r
+> +++ b/lib/query.cc\r
+> @@ -541,6 +541,16 @@ notmuch_threads_destroy (notmuch_threads_t *threads)\r
+> unsigned\r
+> notmuch_query_count_messages (notmuch_query_t *query)\r
+> {\r
+> + notmuch_status_t status;\r
+> + unsigned count;\r
+> +\r
+> + status = notmuch_query_count_messages_st (query, &count);\r
+> + return status ? 0 : count;\r
+> +}\r
+> +\r
+> +notmuch_status_t\r
+> +notmuch_query_count_messages_st (notmuch_query_t *query, unsigned *count_out)\r
+> +{\r
+> notmuch_database_t *notmuch = query->notmuch;\r
+> const char *query_string = query->query_string;\r
+> Xapian::doccount count = 0;\r
+> @@ -595,30 +605,42 @@ notmuch_query_count_messages (notmuch_query_t *query)\r
+> fprintf (stderr, "A Xapian exception occurred: %s\n",\r
+> error.get_msg().c_str());\r
+> fprintf (stderr, "Query string was: %s\n", query->query_string);\r
+> + return NOTMUCH_STATUS_XAPIAN_EXCEPTION;\r
+> }\r
+> \r
+> - return count;\r
+> + *count_out=count;\r
+\r
+Spaces around "="?\r
+\r
+> + return NOTMUCH_STATUS_SUCCESS;\r
+> }\r
+> \r
+> unsigned\r
+> notmuch_query_count_threads (notmuch_query_t *query)\r
+> {\r
+> + notmuch_status_t status;\r
+> + unsigned count;\r
+> +\r
+> + status = notmuch_query_count_threads_st (query, &count);\r
+> + return status ? 0 : count;\r
+> +}\r
+> + \r
+> +notmuch_status_t\r
+> +notmuch_query_count_threads_st (notmuch_query_t *query, unsigned *count)\r
+> +{\r
+> notmuch_messages_t *messages;\r
+> GHashTable *hash;\r
+> - unsigned int count;\r
+> notmuch_sort_t sort;\r
+> + notmuch_status_t ret = NOTMUCH_STATUS_SUCCESS;\r
+> \r
+> sort = query->sort;\r
+> query->sort = NOTMUCH_SORT_UNSORTED;\r
+> messages = notmuch_query_search_messages (query);\r
+> query->sort = sort;\r
+> if (messages == NULL)\r
+> - return 0;\r
+> + return NOTMUCH_STATUS_XAPIAN_EXCEPTION;\r
+> \r
+> hash = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, NULL);\r
+> if (hash == NULL) {\r
+> talloc_free (messages);\r
+> - return 0;\r
+> + return NOTMUCH_STATUS_OUT_OF_MEMORY;\r
+> }\r
+> \r
+> while (notmuch_messages_valid (messages)) {\r
+> @@ -627,7 +649,7 @@ notmuch_query_count_threads (notmuch_query_t *query)\r
+> char *thread_id_copy = talloc_strdup (messages, thread_id);\r
+> if (unlikely (thread_id_copy == NULL)) {\r
+> notmuch_message_destroy (message);\r
+> - count = 0;\r
+> + ret = NOTMUCH_STATUS_OUT_OF_MEMORY;\r
+> goto DONE;\r
+> }\r
+> g_hash_table_insert (hash, thread_id_copy, NULL);\r
+> @@ -635,11 +657,11 @@ notmuch_query_count_threads (notmuch_query_t *query)\r
+> notmuch_messages_move_to_next (messages);\r
+> }\r
+> \r
+> - count = g_hash_table_size (hash);\r
+> + *count = g_hash_table_size (hash);\r
+> \r
+> DONE:\r
+> g_hash_table_unref (hash);\r
+> talloc_free (messages);\r
+> \r
+> - return count;\r
+> + return ret;\r
+> }\r
+> -- \r
+> 2.1.4\r
+>\r
+> _______________________________________________\r
+> notmuch mailing list\r
+> notmuch@notmuchmail.org\r
+> http://notmuchmail.org/mailman/listinfo/notmuch\r