aboutsummaryrefslogtreecommitdiffhomepage
path: root/notmuch-search.c
diff options
context:
space:
mode:
authorGravatar Carl Worth <cworth@cworth.org>2009-11-12 22:35:16 -0800
committerGravatar Carl Worth <cworth@cworth.org>2009-11-12 22:35:16 -0800
commitf7b49d658ad507b72d01b06d56975dba0b7cafc8 (patch)
tree69df4deaed2a6362c449ff8df566cfeb6bea2abe /notmuch-search.c
parent5f5e9b8662d562a3d8bd9ab7144fc1fead1c3d22 (diff)
notmuch search: Add support for a --reverse option to reverse sort order.
Note that the difference between thread results in date order and thread results in reverse-date order is not simply a matter of reversing the final results. When sorting in date order, the threads are sorted by the oldest message in the thread. When sorting in reverse-date order, the threads are sorted by the newest message in the thread. This difference means that we might want an explicit option in the interface to reverse the order, (even though the default will be to display the inbox in date order and global searches in reverse-date order).
Diffstat (limited to 'notmuch-search.c')
-rw-r--r--notmuch-search.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/notmuch-search.c b/notmuch-search.c
index a0a71bbd..8db09c77 100644
--- a/notmuch-search.c
+++ b/notmuch-search.c
@@ -34,6 +34,7 @@ notmuch_search_command (void *ctx, int argc, char *argv[])
time_t date;
int i, first = 0, max_threads = -1;
char *opt, *end;
+ notmuch_sort_t sort = NOTMUCH_SORT_DATE;
for (i = 0; i < argc && argv[i][0] == '-'; i++) {
if (strcmp (argv[i], "--") == 0) {
@@ -54,6 +55,11 @@ notmuch_search_command (void *ctx, int argc, char *argv[])
fprintf (stderr, "Invalid value for --max-threads: %s\n", opt);
return 1;
}
+ } else if (strcmp (argv[i], "--reverse") == 0) {
+ sort = NOTMUCH_SORT_DATE_REVERSE;
+ } else {
+ fprintf (stderr, "Unrecognized option: %s\n", argv[i]);
+ return 1;
}
}
@@ -80,6 +86,8 @@ notmuch_search_command (void *ctx, int argc, char *argv[])
return 1;
}
+ notmuch_query_set_sort (query, sort);
+
for (threads = notmuch_query_search_threads (query, first, max_threads);
notmuch_threads_has_more (threads);
notmuch_threads_advance (threads))
@@ -88,7 +96,11 @@ notmuch_search_command (void *ctx, int argc, char *argv[])
thread = notmuch_threads_get (threads);
- date = notmuch_thread_get_oldest_date (thread);
+ if (sort == NOTMUCH_SORT_DATE)
+ date = notmuch_thread_get_oldest_date (thread);
+ else
+ date = notmuch_thread_get_newest_date (thread);
+
relative_date = notmuch_time_relative_date (ctx, date);
printf ("thread:%s %12s [%d/%d] %s; %s",