* [PATCH 2/2] Print nothing when search result is empty
2010-11-01 16:15 [PATCH 1/2] test: Search for non-existent message should return nothing Michal Sojka
@ 2010-11-01 16:15 ` Michal Sojka
2010-11-04 19:39 ` [PATCH 1/2] test: Search for non-existent message should return nothing Carl Worth
1 sibling, 0 replies; 3+ messages in thread
From: Michal Sojka @ 2010-11-01 16:15 UTC (permalink / raw)
To: notmuch
This change affects both text and json formats. Now, text format
behaves as before commit 6dcb7592, but json format is changed.
Earlier, the empty search returned '[]', now it returns ''. The emacs
interface seems not to be affected by this change.
---
notmuch-search.c | 18 ++++++++++++------
1 files changed, 12 insertions(+), 6 deletions(-)
diff --git a/notmuch-search.c b/notmuch-search.c
index 5907c2e..bb989da 100644
--- a/notmuch-search.c
+++ b/notmuch-search.c
@@ -189,7 +189,9 @@ do_search_threads (const void *ctx,
{
int first_tag = 1;
- if (! first_thread)
+ if (first_thread)
+ fputs (format->results_start, stdout);
+ else
fputs (format->item_sep, stdout);
thread = notmuch_threads_get (threads);
@@ -235,6 +237,9 @@ do_search_threads (const void *ctx,
notmuch_thread_destroy (thread);
}
+ if (! first_thread)
+ fputs (format->results_end, stdout);
+
return 0;
}
@@ -258,7 +263,9 @@ do_search_messages (const void *ctx,
{
message = notmuch_messages_get (messages);
- if (! first_message)
+ if (first_message)
+ fputs (format->results_start, stdout);
+ else
fputs (format->item_sep, stdout);
if (output == OUTPUT_FILES) {
@@ -276,6 +283,9 @@ do_search_messages (const void *ctx,
notmuch_messages_destroy (messages);
+ if (! first_message)
+ fputs (format->results_end, stdout);
+
return 0;
}
@@ -415,8 +425,6 @@ notmuch_search_command (void *ctx, int argc, char *argv[])
notmuch_query_set_sort (query, sort);
- fputs (format->results_start, stdout);
-
switch (output) {
default:
case OUTPUT_SUMMARY:
@@ -432,8 +440,6 @@ notmuch_search_command (void *ctx, int argc, char *argv[])
break;
}
- fputs (format->results_end, stdout);
-
notmuch_query_destroy (query);
notmuch_database_close (notmuch);
--
1.7.2.3
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH 1/2] test: Search for non-existent message should return nothing
2010-11-01 16:15 [PATCH 1/2] test: Search for non-existent message should return nothing Michal Sojka
2010-11-01 16:15 ` [PATCH 2/2] Print nothing when search result is empty Michal Sojka
@ 2010-11-04 19:39 ` Carl Worth
1 sibling, 0 replies; 3+ messages in thread
From: Carl Worth @ 2010-11-04 19:39 UTC (permalink / raw)
To: Michal Sojka, notmuch
[-- Attachment #1: Type: text/plain, Size: 758 bytes --]
On Mon, 1 Nov 2010 17:15:39 +0100, Michal Sojka <sojkam1@fel.cvut.cz> wrote:
> My scripts expect that empty search result is actually empty. Since
> commit 6dcb7592, even empty search prints a newline character and this
> breaks my scripts.
Thanks for this fix, Michal.
I get to apologize doubly on this one.
First, I'm sorry that I was greedy and tried to factor out some common
code, not realizing the bug I introduced in the process.
Second, I'm sorry I didn't get your fix into the 0.4 release, (since I
think you did send it before I wrapped that up).
I've at least pushed your fix now. Thanks especially for including a new
test (and fix!) with your bug report. That's hugely appreciated.
-Carl
--
carl.d.worth@intel.com
[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread