--- /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 2B732431FB6\r
+ for <notmuch@notmuchmail.org>; Tue, 14 Oct 2014 09:33:08 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\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 r+QsW40HrO0c for <notmuch@notmuchmail.org>;\r
+ Tue, 14 Oct 2014 09:33:00 -0700 (PDT)\r
+Received: from mail-wi0-f171.google.com (mail-wi0-f171.google.com\r
+ [209.85.212.171]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id 08D56431FAF\r
+ for <notmuch@notmuchmail.org>; Tue, 14 Oct 2014 09:32:59 -0700 (PDT)\r
+Received: by mail-wi0-f171.google.com with SMTP id em10so10638041wid.10\r
+ for <notmuch@notmuchmail.org>; Tue, 14 Oct 2014 09:32:57 -0700 (PDT)\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;\r
+ bh=/3OJ8ww6jEGA/3hb+JUd3YiOPju3T0QHJ875msdZhNg=;\r
+ b=b9LceQH4Vu++6mZhxG6vSED6xwepq0PnF73BA2wWmahVMscoi4rzCpcdNzjQ4cDt8u\r
+ /4Gp1siEWmK4w3ScjQKZaLXH19kWY6UNrU29rHLpxL9IuyL6592NeOYLpU2rf1LmVAow\r
+ SjlP6NjQtmhibOdZ+eujxIbejYQXIBiLce2ISwRH4IMO5prOUDoZJ7I/ZCL935YIggro\r
+ 7L2DEbITVOlezeWIMKKdcMqFaN7XX3stBe1Gvu8CX56M7gGDoB79kJreBQGkcRvnWT/9\r
+ AJdJ1FJga0+JJFUSJYSx00RGSh1aF8O21IYaY/Wj5IN39HGyrB1nuIXeSyWPH9xPSCxX\r
+ n4Hg==\r
+X-Gm-Message-State:\r
+ ALoCoQl5DoojswH99guuWWSfTi06E76djL81PNzs1idcg9sm7dY7UjjK/WRPWKXHWh42Iu0N7o5g\r
+X-Received: by 10.194.239.164 with SMTP id vt4mr3383229wjc.131.1413304376948; \r
+ Tue, 14 Oct 2014 09:32:56 -0700 (PDT)\r
+Received: from localhost (mobile-internet-5d6ad2-138.dhcp.inet.fi.\r
+ [93.106.210.138])\r
+ by mx.google.com with ESMTPSA id ga7sm16287360wic.5.2014.10.14.09.32.55\r
+ for <multiple recipients>\r
+ (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\r
+ Tue, 14 Oct 2014 09:32:56 -0700 (PDT)\r
+From: Jani Nikula <jani@nikula.org>\r
+To: Sergei Shilovsky <sshilovsky@gmail.com>,\r
+ notmuch@notmuchmail.org\r
+Subject: [PATCH] lib: make notmuch_query_count_messages exact\r
+Date: Tue, 14 Oct 2014 19:32:54 +0300\r
+Message-Id: <1413304374-17997-1-git-send-email-jani@nikula.org>\r
+X-Mailer: git-send-email 2.1.1\r
+In-Reply-To: <1413298112-19912-2-git-send-email-sshilovsky@gmail.com>\r
+References: <1413298112-19912-2-git-send-email-sshilovsky@gmail.com>\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: Tue, 14 Oct 2014 16:33:08 -0000\r
+\r
+Our tests have expected this to be exact all along, but maybe\r
+inaccuracies only show up with big databases.\r
+---\r
+ devel/TODO | 5 -----\r
+ lib/notmuch.h | 6 +++---\r
+ lib/query.cc | 7 ++++++-\r
+ 3 files changed, 9 insertions(+), 9 deletions(-)\r
+\r
+diff --git a/devel/TODO b/devel/TODO\r
+index 1cf4089f1d93..116194d82ad1 100644\r
+--- a/devel/TODO\r
++++ b/devel/TODO\r
+@@ -188,11 +188,6 @@ into the shared-library interface.\r
+ Audit all libnotmuch entry points to ensure that all Xapian calls are\r
+ wrapped in a try/catch block.\r
+ \r
+-Fix the "count" functionality to be exact as Olly explained in IRC:\r
+-\r
+- ojwb> cworth: if you set the check_at_least parameter to the\r
+- database size, get_matches_estimated() will be exact\r
+-\r
+ Fix the threading of a message that has a References: header but no\r
+ In-Reply-To: header (see id:"87lixxnxpb.fsf@yoom.home.cworth.org").\r
+ \r
+diff --git a/lib/notmuch.h b/lib/notmuch.h\r
+index dae041640fdb..6091082617e7 100644\r
+--- a/lib/notmuch.h\r
++++ b/lib/notmuch.h\r
+@@ -893,10 +893,10 @@ void\r
+ notmuch_threads_destroy (notmuch_threads_t *threads);\r
+ \r
+ /**\r
+- * Return an estimate of the number of messages matching a search.\r
++ * Return the number of messages matching a search.\r
+ *\r
+- * This function performs a search and returns Xapian's best\r
+- * guess as to number of matching messages.\r
++ * This function performs a search and returns the number of matching\r
++ * messages.\r
+ *\r
+ * If a Xapian exception occurs, this function may return 0 (after\r
+ * printing a message).\r
+diff --git a/lib/query.cc b/lib/query.cc\r
+index 60ff8bd9a39e..ce26e3f3e4ed 100644\r
+--- a/lib/query.cc\r
++++ b/lib/query.cc\r
+@@ -557,7 +557,12 @@ notmuch_query_count_messages (notmuch_query_t *query)\r
+ \r
+ enquire.set_query (final_query);\r
+ \r
+- mset = enquire.get_mset (0, notmuch->xapian_db->get_doccount ());\r
++ /*\r
++ * Set the checkatleast parameter to the number of documents\r
++ * in the database to make get_matches_estimated() exact.\r
++ */\r
++ mset = enquire.get_mset (0, notmuch->xapian_db->get_doccount (),\r
++ notmuch->xapian_db->get_doccount ());\r
+ \r
+ count = mset.get_matches_estimated();\r
+ \r
+-- \r
+2.1.1\r
+\r