Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id E4700431FD7 for ; Tue, 13 Mar 2012 19:31:36 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.7 X-Spam-Level: X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 2th75KH-+UWj for ; Tue, 13 Mar 2012 19:31:34 -0700 (PDT) Received: from dmz-mailsec-scanner-3.mit.edu (DMZ-MAILSEC-SCANNER-3.MIT.EDU [18.9.25.14]) by olra.theworths.org (Postfix) with ESMTP id B85A2431FAE for ; Tue, 13 Mar 2012 19:31:34 -0700 (PDT) X-AuditID: 1209190e-b7f7c6d0000008c3-92-4f600306a025 Received: from mailhub-auth-1.mit.edu ( [18.9.21.35]) by dmz-mailsec-scanner-3.mit.edu (Symantec Messaging Gateway) with SMTP id 0E.82.02243.603006F4; Tue, 13 Mar 2012 22:31:34 -0400 (EDT) Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103]) by mailhub-auth-1.mit.edu (8.13.8/8.9.2) with ESMTP id q2E2VYen007532; Tue, 13 Mar 2012 22:31:34 -0400 Received: from drake.mit.edu (209-6-116-242.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com [209.6.116.242]) (authenticated bits=0) (User authenticated as amdragon@ATHENA.MIT.EDU) by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id q2E2VWG3023783 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); Tue, 13 Mar 2012 22:31:33 -0400 (EDT) Received: from amthrax by drake.mit.edu with local (Exim 4.77) (envelope-from ) id 1S7dzw-0007DC-IS; Tue, 13 Mar 2012 22:31:32 -0400 From: Austin Clements To: notmuch@notmuchmail.org Subject: [PATCH 1/2] lib: Expose query debug output via an environment variable Date: Tue, 13 Mar 2012 22:31:30 -0400 Message-Id: <1331692291-27671-2-git-send-email-amdragon@mit.edu> X-Mailer: git-send-email 1.7.7.3 In-Reply-To: <1331692291-27671-1-git-send-email-amdragon@mit.edu> References: <1331692291-27671-1-git-send-email-amdragon@mit.edu> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrIIsWRmVeSWpSXmKPExsUixCmqrMvGnOBv0NcqaXH95kxmB0aPZ6tu MQcwRnHZpKTmZJalFunbJXBlNK2fw1QwQaDi84q0BsZO3i5GTg4JAROJ1+/XsULYYhIX7q1n 62Lk4hAS2McocbT/LDtIQkhgA6PE+on5EIn7TBLHfl9hh3DmM0ocuLeeGaSKTUBDYtv+5Ywg toiAtMTOu7OBxnJwMAuoSfzpUgEJCwv4S8w+PhlsKIuAqsTfyUuZQGxeAQeJhU2tjBBXKEic W30OrIZTwFHi0v95jBBHOEg0LH/PNoGRfwEjwypG2ZTcKt3cxMyc4tRk3eLkxLy81CJdY73c zBK91JTSTYzgkJHk28H49aDSIUYBDkYlHl7h2nh/IdbEsuLK3EOMkhxMSqK8kW+BQnxJ+SmV GYnFGfFFpTmpxYcYJTiYlUR4X0wFyvGmJFZWpRblw6SkOViUxHnVtN75CQmkJ5akZqemFqQW wWRlODiUJHhVQIYKFqWmp1akZeaUIKSZODhBhvMADS//DjK8uCAxtzgzHSJ/ilFRSpz3zhug hABIIqM0D64XFtOvGMWBXhHmXQlSxQNMB3Ddr4AGMwENLvkWBzK4JBEhJdXAyLjgm9k7n09V n5V7rmqGu8yU+/HDe+uE7wpNP3pMv/vp3VjDwnmp+gj3xfCGzBDtlpff8lnbJs38tfRYzMKc 0+1hWblhYt9MpjSc2BVyXtNEcu3UpkONHyd0Vd3dO53JQOj9nuI7l5j3GG+vn3N1j/NcyS/f Z0u33CiI8Xte1VFR8Obn1fa7f5VYijMSDbWYi4oTAbBDShTEAgAA X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 14 Mar 2012 02:31:37 -0000 Allow query debugging to be enabled at run-time by setting the NOTMUCH_DEBUG_QUERY environment variable to a non-empty string. Previously, enabling query debugging required recompiling, but parsed queries are often useful for tracking down bugs in situations where recompiling is inconvenient. --- lib/query.cc | 24 +++++++++++++++--------- 1 files changed, 15 insertions(+), 9 deletions(-) diff --git a/lib/query.cc b/lib/query.cc index ab18fbc..1e5e99a 100644 --- a/lib/query.cc +++ b/lib/query.cc @@ -64,15 +64,21 @@ _notmuch_doc_id_set_init (void *ctx, notmuch_doc_id_set_t *doc_ids, GArray *arr); +static notmuch_bool_t +_debug_query (void) +{ + char *env = getenv ("NOTMUCH_DEBUG_QUERY"); + return (env && strcmp (env, "") != 0); +} + notmuch_query_t * notmuch_query_create (notmuch_database_t *notmuch, const char *query_string) { notmuch_query_t *query; -#ifdef DEBUG_QUERY - fprintf (stderr, "Query string is:\n%s\n", query_string); -#endif + if (_debug_query ()) + fprintf (stderr, "Query string is:\n%s\n", query_string); query = talloc (NULL, notmuch_query_t); if (unlikely (query == NULL)) @@ -255,9 +261,9 @@ notmuch_query_search_messages (notmuch_query_t *query) break; } -#if DEBUG_QUERY - fprintf (stderr, "Final query is:\n%s\n", final_query.get_description().c_str()); -#endif + if (_debug_query ()) + fprintf (stderr, "Final query is:\n%s\n", + final_query.get_description ().c_str ()); enquire.set_query (final_query); @@ -531,9 +537,9 @@ notmuch_query_count_messages (notmuch_query_t *query) enquire.set_weighting_scheme(Xapian::BoolWeight()); enquire.set_docid_order(Xapian::Enquire::ASCENDING); -#if DEBUG_QUERY - fprintf (stderr, "Final query is:\n%s\n", final_query.get_description().c_str()); -#endif + if (_debug_query ()) + fprintf (stderr, "Final query is:\n%s\n", + final_query.get_description ().c_str ()); enquire.set_query (final_query); -- 1.7.7.3