* [PATCH v7 1/6] lib: add function to get the number of threads matching a search
2011-11-15 20:08 [PATCH v7 0/6] lib/cli: limit number of messages in search results Jani Nikula
@ 2011-11-15 20:08 ` Jani Nikula
2011-11-15 20:08 ` [PATCH v7 2/6] cli: add options --offset and --limit to notmuch search Jani Nikula
` (5 subsequent siblings)
6 siblings, 0 replies; 10+ messages in thread
From: Jani Nikula @ 2011-11-15 20:08 UTC (permalink / raw)
To: notmuch
Add function notmuch_query_count_threads() to get the number of threads
matching a search. This is done by performing a search and figuring out the
number of unique thread IDs in the matching messages, a significantly
heavier operation than notmuch_query_count_messages().
Signed-off-by: Jani Nikula <jani@nikula.org>
---
lib/notmuch.h | 14 ++++++++++++++
lib/query.cc | 44 ++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 58 insertions(+), 0 deletions(-)
diff --git a/lib/notmuch.h b/lib/notmuch.h
index c4330e4..9f23a10 100644
--- a/lib/notmuch.h
+++ b/lib/notmuch.h
@@ -609,6 +609,20 @@ notmuch_threads_destroy (notmuch_threads_t *threads);
unsigned
notmuch_query_count_messages (notmuch_query_t *query);
+/* Return the number of threads matching a search.
+ *
+ * This function performs a search and returns the number of unique thread IDs
+ * in the matching messages. This is the same as number of threads matching a
+ * search.
+ *
+ * Note that this is a significantly heavier operation than
+ * notmuch_query_count_messages().
+ *
+ * If an error occurs, this function may return 0.
+ */
+unsigned
+notmuch_query_count_threads (notmuch_query_t *query);
+
/* Get the thread ID of 'thread'.
*
* The returned string belongs to 'thread' and as such, should not be
diff --git a/lib/query.cc b/lib/query.cc
index 6f02b04..b6c0f12 100644
--- a/lib/query.cc
+++ b/lib/query.cc
@@ -457,3 +457,47 @@ notmuch_query_count_messages (notmuch_query_t *query)
return count;
}
+
+unsigned
+notmuch_query_count_threads (notmuch_query_t *query)
+{
+ notmuch_messages_t *messages;
+ GHashTable *hash;
+ unsigned int count;
+ notmuch_sort_t sort;
+
+ sort = query->sort;
+ query->sort = NOTMUCH_SORT_UNSORTED;
+ messages = notmuch_query_search_messages (query);
+ query->sort = sort;
+ if (messages == NULL)
+ return 0;
+
+ hash = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, NULL);
+ if (hash == NULL) {
+ talloc_free (messages);
+ return 0;
+ }
+
+ while (notmuch_messages_valid (messages)) {
+ notmuch_message_t *message = notmuch_messages_get (messages);
+ const char *thread_id = notmuch_message_get_thread_id (message);
+ char *thread_id_copy = talloc_strdup (messages, thread_id);
+ if (unlikely (thread_id_copy == NULL)) {
+ notmuch_message_destroy (message);
+ count = 0;
+ goto DONE;
+ }
+ g_hash_table_insert (hash, thread_id_copy, NULL);
+ notmuch_message_destroy (message);
+ notmuch_messages_move_to_next (messages);
+ }
+
+ count = g_hash_table_size (hash);
+
+ DONE:
+ g_hash_table_unref (hash);
+ talloc_free (messages);
+
+ return count;
+}
--
1.7.5.4
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH v7 2/6] cli: add options --offset and --limit to notmuch search
2011-11-15 20:08 [PATCH v7 0/6] lib/cli: limit number of messages in search results Jani Nikula
2011-11-15 20:08 ` [PATCH v7 1/6] lib: add function to get the number of threads matching a search Jani Nikula
@ 2011-11-15 20:08 ` Jani Nikula
2011-11-15 20:08 ` [PATCH v7 3/6] cli: drop unused code from notmuch count Jani Nikula
` (4 subsequent siblings)
6 siblings, 0 replies; 10+ messages in thread
From: Jani Nikula @ 2011-11-15 20:08 UTC (permalink / raw)
To: notmuch
Add options --offset=[-]N and --limit=M to notmuch search to determine the
first result and maximum number of results to display.
Option --limit=M limits the maximum number of results to display to M.
Option --offset=[-]N skips the first N results; with the leading '-' skip
until the Nth result from the end.
Note that --offset with a negative N for thread or summary output requires
counting the number of matching threads in advance.
Signed-off-by: Jani Nikula <jani@nikula.org>
---
NEWS | 5 ++++
notmuch-search.c | 68 ++++++++++++++++++++++++++++++++++++++++++++---------
notmuch.1 | 19 +++++++++++++-
notmuch.c | 9 +++++++
4 files changed, 87 insertions(+), 14 deletions(-)
diff --git a/NEWS b/NEWS
index 88f7b20..f224d02 100644
--- a/NEWS
+++ b/NEWS
@@ -23,6 +23,11 @@ Add search terms to "notmuch dump"
search/show/tag. The output file argument of dump is deprecated in
favour of using stdout.
+Add "notmuch search" --offset and --limit options
+
+ The search command now takes options --offset=[-]N and --limit=N to limit
+ the number of results shown.
+
Optimizations
-------------
diff --git a/notmuch-search.c b/notmuch-search.c
index 6f04d9a..36686d1 100644
--- a/notmuch-search.c
+++ b/notmuch-search.c
@@ -194,13 +194,22 @@ static int
do_search_threads (const search_format_t *format,
notmuch_query_t *query,
notmuch_sort_t sort,
- output_t output)
+ output_t output,
+ int offset,
+ int limit)
{
notmuch_thread_t *thread;
notmuch_threads_t *threads;
notmuch_tags_t *tags;
time_t date;
int first_thread = 1;
+ int i;
+
+ if (offset < 0) {
+ offset += notmuch_query_count_threads (query);
+ if (offset < 0)
+ offset = 0;
+ }
threads = notmuch_query_search_threads (query);
if (threads == NULL)
@@ -208,17 +217,22 @@ do_search_threads (const search_format_t *format,
fputs (format->results_start, stdout);
- for (;
- notmuch_threads_valid (threads);
- notmuch_threads_move_to_next (threads))
+ for (i = 0;
+ notmuch_threads_valid (threads) && (limit < 0 || i < offset + limit);
+ notmuch_threads_move_to_next (threads), i++)
{
int first_tag = 1;
+ thread = notmuch_threads_get (threads);
+
+ if (i < offset) {
+ notmuch_thread_destroy (thread);
+ continue;
+ }
+
if (! first_thread)
fputs (format->item_sep, stdout);
- thread = notmuch_threads_get (threads);
-
if (output == OUTPUT_THREADS) {
format->item_id (thread, "thread:",
notmuch_thread_get_thread_id (thread));
@@ -271,12 +285,21 @@ do_search_threads (const search_format_t *format,
static int
do_search_messages (const search_format_t *format,
notmuch_query_t *query,
- output_t output)
+ output_t output,
+ int offset,
+ int limit)
{
notmuch_message_t *message;
notmuch_messages_t *messages;
notmuch_filenames_t *filenames;
int first_message = 1;
+ int i;
+
+ if (offset < 0) {
+ offset += notmuch_query_count_messages (query);
+ if (offset < 0)
+ offset = 0;
+ }
messages = notmuch_query_search_messages (query);
if (messages == NULL)
@@ -284,10 +307,13 @@ do_search_messages (const search_format_t *format,
fputs (format->results_start, stdout);
- for (;
- notmuch_messages_valid (messages);
- notmuch_messages_move_to_next (messages))
+ for (i = 0;
+ notmuch_messages_valid (messages) && (limit < 0 || i < offset + limit);
+ notmuch_messages_move_to_next (messages), i++)
{
+ if (i < offset)
+ continue;
+
message = notmuch_messages_get (messages);
if (output == OUTPUT_FILES) {
@@ -394,6 +420,8 @@ notmuch_search_command (void *ctx, int argc, char *argv[])
const search_format_t *format = &format_text;
int i, ret;
output_t output = OUTPUT_SUMMARY;
+ int offset = 0;
+ int limit = -1; /* unlimited */
argc--; argv++; /* skip subcommand argument */
@@ -412,6 +440,22 @@ notmuch_search_command (void *ctx, int argc, char *argv[])
fprintf (stderr, "Invalid value for --sort: %s\n", opt);
return 1;
}
+ } else if (STRNCMP_LITERAL (argv[i], "--offset=") == 0) {
+ char *p;
+ opt = argv[i] + sizeof ("--offset=") - 1;
+ offset = strtol (opt, &p, 10);
+ if (*opt == '\0' || p == opt || *p != '\0') {
+ fprintf (stderr, "Invalid value for --offset: %s\n", opt);
+ return 1;
+ }
+ } else if (STRNCMP_LITERAL (argv[i], "--limit=") == 0) {
+ char *p;
+ opt = argv[i] + sizeof ("--limit=") - 1;
+ limit = strtoul (opt, &p, 10);
+ if (*opt == '\0' || p == opt || *p != '\0') {
+ fprintf (stderr, "Invalid value for --limit: %s\n", opt);
+ return 1;
+ }
} else if (STRNCMP_LITERAL (argv[i], "--format=") == 0) {
opt = argv[i] + sizeof ("--format=") - 1;
if (strcmp (opt, "text") == 0) {
@@ -478,11 +522,11 @@ notmuch_search_command (void *ctx, int argc, char *argv[])
default:
case OUTPUT_SUMMARY:
case OUTPUT_THREADS:
- ret = do_search_threads (format, query, sort, output);
+ ret = do_search_threads (format, query, sort, output, offset, limit);
break;
case OUTPUT_MESSAGES:
case OUTPUT_FILES:
- ret = do_search_messages (format, query, output);
+ ret = do_search_messages (format, query, output, offset, limit);
break;
case OUTPUT_TAGS:
ret = do_search_tags (notmuch, format, query);
diff --git a/notmuch.1 b/notmuch.1
index bba479e..cda777b 100644
--- a/notmuch.1
+++ b/notmuch.1
@@ -214,11 +214,26 @@ when sorting by
.B newest\-first
the threads will be sorted by the newest message in each thread.
-.RE
-.RS 4
By default, results will be displayed in reverse chronological order,
(that is, the newest results will be displayed first).
+.RE
+
+.RS 4
+.TP 4
+.BR \-\-offset=[\-]N
+
+Skip displaying the first N results. With the leading '\-', start at the Nth
+result from the end.
+.RE
+
+.RS 4
+.TP 4
+.BR \-\-limit=N
+Limit the number of displayed results to N.
+.RE
+
+.RS 4
See the
.B "SEARCH SYNTAX"
section below for details of the supported syntax for <search-terms>.
diff --git a/notmuch.c b/notmuch.c
index e004c6c..394371d 100644
--- a/notmuch.c
+++ b/notmuch.c
@@ -222,6 +222,15 @@ static command_t commands[] = {
"\t\t(oldest-first) or reverse chronological order\n"
"\t\t(newest-first), which is the default.\n"
"\n"
+ "\t--offset=[-]N\n"
+ "\n"
+ "\t\tSkip displaying the first N results. With the leading '-',\n"
+ "\t\tstart at the Nth result from the end.\n"
+ "\n"
+ "\t--limit=N\n"
+ "\n"
+ "\t\tLimit the number of displayed results to N.\n"
+ "\n"
"\tSee \"notmuch help search-terms\" for details of the search\n"
"\tterms syntax." },
{ "show", notmuch_show_command,
--
1.7.5.4
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH v7 3/6] cli: drop unused code from notmuch count
2011-11-15 20:08 [PATCH v7 0/6] lib/cli: limit number of messages in search results Jani Nikula
2011-11-15 20:08 ` [PATCH v7 1/6] lib: add function to get the number of threads matching a search Jani Nikula
2011-11-15 20:08 ` [PATCH v7 2/6] cli: add options --offset and --limit to notmuch search Jani Nikula
@ 2011-11-15 20:08 ` Jani Nikula
2011-11-15 20:08 ` [PATCH v7 4/6] cli: add support for --output parameter in " Jani Nikula
` (3 subsequent siblings)
6 siblings, 0 replies; 10+ messages in thread
From: Jani Nikula @ 2011-11-15 20:08 UTC (permalink / raw)
To: notmuch
Remove unused code within #if 0 blocks from notmuch count.
Signed-off-by: Jani Nikula <jani@nikula.org>
---
notmuch-count.c | 32 --------------------------------
1 files changed, 0 insertions(+), 32 deletions(-)
diff --git a/notmuch-count.c b/notmuch-count.c
index 0d700a9..a35be40 100644
--- a/notmuch-count.c
+++ b/notmuch-count.c
@@ -29,11 +29,6 @@ notmuch_count_command (void *ctx, int argc, char *argv[])
notmuch_query_t *query;
char *query_str;
int i;
-#if 0
- char *opt, *end;
- int i, first = 0, max_threads = -1;
- notmuch_sort_t sort = NOTMUCH_SORT_NEWEST_FIRST;
-#endif
argc--; argv++; /* skip subcommand argument */
@@ -42,33 +37,6 @@ notmuch_count_command (void *ctx, int argc, char *argv[])
i++;
break;
}
-#if 0
- if (STRNCMP_LITERAL (argv[i], "--first=") == 0) {
- opt = argv[i] + sizeof ("--first=") - 1;
- first = strtoul (opt, &end, 10);
- if (*opt == '\0' || *end != '\0') {
- fprintf (stderr, "Invalid value for --first: %s\n", opt);
- return 1;
- }
- } else if (STRNCMP_LITERAL (argv[i], "--max-threads=") == 0) {
- opt = argv[i] + sizeof ("--max-threads=") - 1;
- max_threads = strtoul (opt, &end, 10);
- if (*opt == '\0' || *end != '\0') {
- fprintf (stderr, "Invalid value for --max-threads: %s\n", opt);
- return 1;
- }
- } else if (STRNCMP_LITERAL (argv[i], "--sort=") == 0) {
- opt = argv[i] + sizeof ("--sort=") - 1;
- if (strcmp (opt, "oldest-first") == 0) {
- sort = NOTMUCH_SORT_OLDEST_FIRST;
- } else if (strcmp (opt, "newest-first") == 0) {
- sort = NOTMUCH_SORT_NEWEST_FIRST;
- } else {
- fprintf (stderr, "Invalid value for --sort: %s\n", opt);
- return 1;
- }
- } else
-#endif
{
fprintf (stderr, "Unrecognized option: %s\n", argv[i]);
return 1;
--
1.7.5.4
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH v7 4/6] cli: add support for --output parameter in notmuch count
2011-11-15 20:08 [PATCH v7 0/6] lib/cli: limit number of messages in search results Jani Nikula
` (2 preceding siblings ...)
2011-11-15 20:08 ` [PATCH v7 3/6] cli: drop unused code from notmuch count Jani Nikula
@ 2011-11-15 20:08 ` Jani Nikula
2011-11-15 20:08 ` [PATCH v7 5/6] test: add tests for " Jani Nikula
` (2 subsequent siblings)
6 siblings, 0 replies; 10+ messages in thread
From: Jani Nikula @ 2011-11-15 20:08 UTC (permalink / raw)
To: notmuch
Add support for --output=messages (which remains the default) and
--output=threads to notmuch count.
Signed-off-by: Jani Nikula <jani@nikula.org>
---
NEWS | 5 +++++
notmuch-count.c | 18 ++++++++++++++++--
notmuch.1 | 29 +++++++++++++++++++++++++----
notmuch.c | 20 ++++++++++++++++----
4 files changed, 62 insertions(+), 10 deletions(-)
diff --git a/NEWS b/NEWS
index f224d02..7bd9987 100644
--- a/NEWS
+++ b/NEWS
@@ -28,6 +28,11 @@ Add "notmuch search" --offset and --limit options
The search command now takes options --offset=[-]N and --limit=N to limit
the number of results shown.
+Add "notmuch count --output" option
+
+ The count command is now capable of counting threads in addition to
+ messages. This is selected using the new --output=(threads|messages) option.
+
Optimizations
-------------
diff --git a/notmuch-count.c b/notmuch-count.c
index a35be40..20ce334 100644
--- a/notmuch-count.c
+++ b/notmuch-count.c
@@ -29,6 +29,7 @@ notmuch_count_command (void *ctx, int argc, char *argv[])
notmuch_query_t *query;
char *query_str;
int i;
+ notmuch_bool_t output_messages = TRUE;
argc--; argv++; /* skip subcommand argument */
@@ -37,7 +38,17 @@ notmuch_count_command (void *ctx, int argc, char *argv[])
i++;
break;
}
- {
+ if (STRNCMP_LITERAL (argv[i], "--output=") == 0) {
+ const char *opt = argv[i] + sizeof ("--output=") - 1;
+ if (strcmp (opt, "threads") == 0) {
+ output_messages = FALSE;
+ } else if (strcmp (opt, "messages") == 0) {
+ output_messages = TRUE;
+ } else {
+ fprintf (stderr, "Invalid value for --output: %s\n", opt);
+ return 1;
+ }
+ } else {
fprintf (stderr, "Unrecognized option: %s\n", argv[i]);
return 1;
}
@@ -71,7 +82,10 @@ notmuch_count_command (void *ctx, int argc, char *argv[])
return 1;
}
- printf ("%u\n", notmuch_query_count_messages(query));
+ if (output_messages)
+ printf ("%u\n", notmuch_query_count_messages (query));
+ else
+ printf ("%u\n", notmuch_query_count_threads (query));
notmuch_query_destroy (query);
notmuch_database_close (notmuch);
diff --git a/notmuch.1 b/notmuch.1
index cda777b..bc2f965 100644
--- a/notmuch.1
+++ b/notmuch.1
@@ -372,14 +372,35 @@ section below for details of the supported syntax for <search-terms>.
.RE
.RS 4
.TP 4
-.BR count " <search-term>..."
+.BR count " [options...] <search-term>..."
Count messages matching the search terms.
-The number of matching messages is output to stdout.
+The number of matching messages (or threads) is output to stdout.
-With no search terms, a count of all messages in the database will be
-displayed.
+With no search terms, a count of all messages (or threads) in the database will
+be displayed.
+
+Supported options for
+.B count
+include
+.RS 4
+.TP 4
+.B \-\-output=(messages|threads)
+
+.RS 4
+.TP 4
+.B messages
+
+Output the number of matching messages. This is the default.
+.RE
+.RS 4
+.TP 4
+.B threads
+
+Output the number of matching threads.
+.RE
+.RE
.RE
.RE
diff --git a/notmuch.c b/notmuch.c
index 394371d..77973f8 100644
--- a/notmuch.c
+++ b/notmuch.c
@@ -328,12 +328,24 @@ static command_t commands[] = {
"\tSee \"notmuch help search-terms\" for details of the search\n"
"\tterms syntax." },
{ "count", notmuch_count_command,
- "<search-terms> [...]",
+ "[options...] <search-terms> [...]",
"Count messages matching the search terms.",
- "\tThe number of matching messages is output to stdout.\n"
+ "\tThe number of matching messages (or threads) is output to stdout.\n"
+ "\n"
+ "\tWith no search terms, a count of all messages (or threads) in\n"
+ "\tthe database will be displayed.\n"
+ "\n"
+ "\tSupported options for count include:\n"
+ "\n"
+ "\t--output=(messages|threads)\n"
+ "\n"
+ "\t\tmessages (default)\n"
+ "\n"
+ "\t\tOutput the number of matching messages.\n"
+ "\n"
+ "\t\tthreads\n"
"\n"
- "\tWith no search terms, a count of all messages in the database\n"
- "\twill be displayed.\n"
+ "\t\tOutput the number of matching threads.\n"
"\n"
"\tSee \"notmuch help search-terms\" for details of the search\n"
"\tterms syntax." },
--
1.7.5.4
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH v7 5/6] test: add tests for notmuch count
2011-11-15 20:08 [PATCH v7 0/6] lib/cli: limit number of messages in search results Jani Nikula
` (3 preceding siblings ...)
2011-11-15 20:08 ` [PATCH v7 4/6] cli: add support for --output parameter in " Jani Nikula
@ 2011-11-15 20:08 ` Jani Nikula
2011-11-15 20:08 ` [PATCH v7 6/6] test: add tests for notmuch search --offset and --limit Jani Nikula
2011-11-15 23:41 ` [PATCH v7 0/6] lib/cli: limit number of messages in search results David Bremner
6 siblings, 0 replies; 10+ messages in thread
From: Jani Nikula @ 2011-11-15 20:08 UTC (permalink / raw)
To: notmuch
Signed-off-by: Jani Nikula <jani@nikula.org>
---
test/count | 40 ++++++++++++++++++++++++++++++++++++++++
test/notmuch-test | 1 +
2 files changed, 41 insertions(+), 0 deletions(-)
create mode 100755 test/count
diff --git a/test/count b/test/count
new file mode 100755
index 0000000..300b171
--- /dev/null
+++ b/test/count
@@ -0,0 +1,40 @@
+#!/usr/bin/env bash
+test_description='"notmuch count" for messages and threads'
+. ./test-lib.sh
+
+add_email_corpus
+
+SEARCH="\"*\""
+
+test_begin_subtest "message count is the default for notmuch count"
+test_expect_equal \
+ "`notmuch search --output=messages ${SEARCH} | wc -l`" \
+ "`notmuch count ${SEARCH}`"
+
+test_begin_subtest "message count with --output=messages"
+test_expect_equal \
+ "`notmuch search --output=messages ${SEARCH} | wc -l`" \
+ "`notmuch count --output=messages ${SEARCH}`"
+
+test_begin_subtest "thread count with --output=threads"
+test_expect_equal \
+ "`notmuch search --output=threads ${SEARCH} | wc -l`" \
+ "`notmuch count --output=threads ${SEARCH}`"
+
+test_begin_subtest "thread count is the default for notmuch search"
+test_expect_equal \
+ "`notmuch search ${SEARCH} | wc -l`" \
+ "`notmuch count --output=threads ${SEARCH}`"
+
+SEARCH="from:cworth and not from:cworth"
+test_begin_subtest "count with no matching messages"
+test_expect_equal \
+ "0" \
+ "`notmuch count --output=messages ${SEARCH}`"
+
+test_begin_subtest "count with no matching threads"
+test_expect_equal \
+ "0" \
+ "`notmuch count --output=threads ${SEARCH}`"
+
+test_done
diff --git a/test/notmuch-test b/test/notmuch-test
index bbabf28..29de30d 100755
--- a/test/notmuch-test
+++ b/test/notmuch-test
@@ -19,6 +19,7 @@ cd $(dirname "$0")
TESTS="
basic
new
+ count
search
search-output
search-by-folder
--
1.7.5.4
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH v7 6/6] test: add tests for notmuch search --offset and --limit
2011-11-15 20:08 [PATCH v7 0/6] lib/cli: limit number of messages in search results Jani Nikula
` (4 preceding siblings ...)
2011-11-15 20:08 ` [PATCH v7 5/6] test: add tests for " Jani Nikula
@ 2011-11-15 20:08 ` Jani Nikula
2011-11-15 23:41 ` [PATCH v7 0/6] lib/cli: limit number of messages in search results David Bremner
6 siblings, 0 replies; 10+ messages in thread
From: Jani Nikula @ 2011-11-15 20:08 UTC (permalink / raw)
To: notmuch
Signed-off-by: Jani Nikula <jani@nikula.org>
---
test/notmuch-test | 1 +
test/search-limiting | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 72 insertions(+), 0 deletions(-)
create mode 100755 test/search-limiting
diff --git a/test/notmuch-test b/test/notmuch-test
index 29de30d..adfd589 100755
--- a/test/notmuch-test
+++ b/test/notmuch-test
@@ -25,6 +25,7 @@ TESTS="
search-by-folder
search-position-overlap-bug
search-insufficient-from-quoting
+ search-limiting
tagging
json
multipart
diff --git a/test/search-limiting b/test/search-limiting
new file mode 100755
index 0000000..303762c
--- /dev/null
+++ b/test/search-limiting
@@ -0,0 +1,71 @@
+#!/usr/bin/env bash
+test_description='"notmuch search" --offset and --limit parameters'
+. ./test-lib.sh
+
+add_email_corpus
+
+for outp in messages threads; do
+ test_begin_subtest "${outp}: limit does the right thing"
+ notmuch search --output=${outp} "*" | head -n 20 >expected
+ notmuch search --output=${outp} --limit=20 "*" >output
+ test_expect_equal_file expected output
+
+ test_begin_subtest "${outp}: concatenation of limited searches"
+ notmuch search --output=${outp} "*" | head -n 20 >expected
+ notmuch search --output=${outp} --limit=10 "*" >output
+ notmuch search --output=${outp} --limit=10 --offset=10 "*" >>output
+ test_expect_equal_file expected output
+
+ test_begin_subtest "${outp}: limit larger than result set"
+ N=`notmuch count --output=${outp} "*"`
+ notmuch search --output=${outp} "*" >expected
+ notmuch search --output=${outp} --limit=$((1 + ${N})) "*" >output
+ test_expect_equal_file expected output
+
+ test_begin_subtest "${outp}: limit = 0"
+ test_expect_equal "`notmuch search --output=${outp} --limit=0 "*"`" ""
+
+ test_begin_subtest "${outp}: offset does the right thing"
+ # note: tail -n +N is 1-based
+ notmuch search --output=${outp} "*" | tail -n +21 >expected
+ notmuch search --output=${outp} --offset=20 "*" >output
+ test_expect_equal_file expected output
+
+ test_begin_subtest "${outp}: offset = 0"
+ notmuch search --output=${outp} "*" >expected
+ notmuch search --output=${outp} --offset=0 "*" >output
+ test_expect_equal_file expected output
+
+ test_begin_subtest "${outp}: negative offset"
+ notmuch search --output=${outp} "*" | tail -n 20 >expected
+ notmuch search --output=${outp} --offset=-20 "*" >output
+ test_expect_equal_file expected output
+
+ test_begin_subtest "${outp}: negative offset"
+ notmuch search --output=${outp} "*" | tail -n 1 >expected
+ notmuch search --output=${outp} --offset=-1 "*" >output
+ test_expect_equal_file expected output
+
+ test_begin_subtest "${outp}: negative offset combined with limit"
+ notmuch search --output=${outp} "*" | tail -n 20 | head -n 10 >expected
+ notmuch search --output=${outp} --offset=-20 --limit=10 "*" >output
+ test_expect_equal_file expected output
+
+ test_begin_subtest "${outp}: negative offset combined with equal limit"
+ notmuch search --output=${outp} "*" | tail -n 20 >expected
+ notmuch search --output=${outp} --offset=-20 --limit=20 "*" >output
+ test_expect_equal_file expected output
+
+ test_begin_subtest "${outp}: negative offset combined with large limit"
+ notmuch search --output=${outp} "*" | tail -n 20 >expected
+ notmuch search --output=${outp} --offset=-20 --limit=50 "*" >output
+ test_expect_equal_file expected output
+
+ test_begin_subtest "${outp}: negative offset larger then results"
+ N=`notmuch count --output=${outp} "*"`
+ notmuch search --output=${outp} "*" >expected
+ notmuch search --output=${outp} --offset=-$((1 + ${N})) "*" >output
+ test_expect_equal_file expected output
+done
+
+test_done
--
1.7.5.4
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH v7 0/6] lib/cli: limit number of messages in search results
2011-11-15 20:08 [PATCH v7 0/6] lib/cli: limit number of messages in search results Jani Nikula
` (5 preceding siblings ...)
2011-11-15 20:08 ` [PATCH v7 6/6] test: add tests for notmuch search --offset and --limit Jani Nikula
@ 2011-11-15 23:41 ` David Bremner
2011-11-16 10:00 ` Jani Nikula
6 siblings, 1 reply; 10+ messages in thread
From: David Bremner @ 2011-11-15 23:41 UTC (permalink / raw)
To: Jani Nikula, notmuch
On Tue, 15 Nov 2011 22:08:47 +0200, Jani Nikula <jani@nikula.org> wrote:
> v7, s/--first/--offset/ and s/--maxitems/--limit/ and rebased against master
> since since id:"cover.1321217854.git.jani@nikula.org"
>
Pushed, and thanks for referring back to the other thread.
d
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v7 0/6] lib/cli: limit number of messages in search results
2011-11-15 23:41 ` [PATCH v7 0/6] lib/cli: limit number of messages in search results David Bremner
@ 2011-11-16 10:00 ` Jani Nikula
2011-11-16 11:16 ` David Bremner
0 siblings, 1 reply; 10+ messages in thread
From: Jani Nikula @ 2011-11-16 10:00 UTC (permalink / raw)
To: David Bremner, notmuch
On Tue, 15 Nov 2011 19:41:57 -0400, David Bremner <david@tethera.net> wrote:
> On Tue, 15 Nov 2011 22:08:47 +0200, Jani Nikula <jani@nikula.org> wrote:
> > v7, s/--first/--offset/ and s/--maxitems/--limit/ and rebased against master
> > since since id:"cover.1321217854.git.jani@nikula.org"
> >
>
> Pushed, and thanks for referring back to the other thread.
Thanks. For future reference, do you prefer In-Reply-To: for the
previous version, or like above? IMHO the original threads get too
cluttered if the versions keep accumulating, but I don't know how that
affects your nmbug workflows.
BR,
Jani.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v7 0/6] lib/cli: limit number of messages in search results
2011-11-16 10:00 ` Jani Nikula
@ 2011-11-16 11:16 ` David Bremner
0 siblings, 0 replies; 10+ messages in thread
From: David Bremner @ 2011-11-16 11:16 UTC (permalink / raw)
To: Jani Nikula, notmuch
On Wed, 16 Nov 2011 10:00:51 +0000, Jani Nikula <jani@nikula.org> wrote:
>
> Thanks. For future reference, do you prefer In-Reply-To: for the
> previous version, or like above? IMHO the original threads get too
> cluttered if the versions keep accumulating, but I don't know how that
> affects your nmbug workflows.
I could live with either, but I agree we should develop a "best practice"
^ permalink raw reply [flat|nested] 10+ messages in thread