From: Austin Clements <amdragon@MIT.EDU>
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 [thread overview]
Message-ID: <1331692291-27671-2-git-send-email-amdragon@mit.edu> (raw)
In-Reply-To: <1331692291-27671-1-git-send-email-amdragon@mit.edu>
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
next prev parent reply other threads:[~2012-03-14 2:31 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-03-14 2:31 [PATCH 0/2] Query debug improvements Austin Clements
2012-03-14 2:31 ` Austin Clements [this message]
2012-03-14 2:31 ` [PATCH 2/2] lib: Add exclude query debug output Austin Clements
2012-03-17 6:02 ` [PATCH 0/2] Query debug improvements Jameson Graef Rollins
2012-03-18 12:48 ` David Bremner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://notmuchmail.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1331692291-27671-2-git-send-email-amdragon@mit.edu \
--to=amdragon@mit.edu \
--cc=notmuch@notmuchmail.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).