]> git.notmuchmail.org Git - notmuch/commitdiff
notmuch search: Add support for a --reverse option to reverse sort order.
authorCarl Worth <cworth@cworth.org>
Fri, 13 Nov 2009 06:35:16 +0000 (22:35 -0800)
committerCarl Worth <cworth@cworth.org>
Fri, 13 Nov 2009 06:35:16 +0000 (22:35 -0800)
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).

lib/notmuch.h
lib/query.cc
lib/thread.cc
notmuch-search.c

index 6469744df36251294fd62d0ba9e4cd1b07224b51..d0b0d9e43f5bc302e25cb67bccb771772b739df6 100644 (file)
@@ -299,8 +299,8 @@ notmuch_query_create (notmuch_database_t *database,
 
 /* Sort values for notmuch_query_set_sort */
 typedef enum {
 
 /* Sort values for notmuch_query_set_sort */
 typedef enum {
-    NOTMUCH_SORT_DATE_OLDEST_FIRST,
-    NOTMUCH_SORT_DATE_NEWEST_FIRST,
+    NOTMUCH_SORT_DATE,
+    NOTMUCH_SORT_DATE_REVERSE,
     NOTMUCH_SORT_MESSAGE_ID
 } notmuch_sort_t;
 
     NOTMUCH_SORT_MESSAGE_ID
 } notmuch_sort_t;
 
index e853d4ec8e46b55b260fc0264b1756bf59eb26a1..7c1df90c39cce262246b1930f913f90e57a34f46 100644 (file)
@@ -61,7 +61,7 @@ notmuch_query_create (notmuch_database_t *notmuch,
 
     query->query_string = talloc_strdup (query, query_string);
 
 
     query->query_string = talloc_strdup (query, query_string);
 
-    query->sort = NOTMUCH_SORT_DATE_OLDEST_FIRST;
+    query->sort = NOTMUCH_SORT_DATE;
 
     return query;
 }
 
     return query;
 }
@@ -123,10 +123,10 @@ notmuch_query_search_messages (notmuch_query_t *query,
        }
 
        switch (query->sort) {
        }
 
        switch (query->sort) {
-       case NOTMUCH_SORT_DATE_OLDEST_FIRST:
+       case NOTMUCH_SORT_DATE:
            enquire.set_sort_by_value (NOTMUCH_VALUE_TIMESTAMP, FALSE);
            break;
            enquire.set_sort_by_value (NOTMUCH_VALUE_TIMESTAMP, FALSE);
            break;
-       case NOTMUCH_SORT_DATE_NEWEST_FIRST:
+       case NOTMUCH_SORT_DATE_REVERSE:
            enquire.set_sort_by_value (NOTMUCH_VALUE_TIMESTAMP, TRUE);
            break;
        case NOTMUCH_SORT_MESSAGE_ID:
            enquire.set_sort_by_value (NOTMUCH_VALUE_TIMESTAMP, TRUE);
            break;
        case NOTMUCH_SORT_MESSAGE_ID:
index df1d0db7fae0ac0f4e8d8f6c400d31dc09b2b3b6..ffecc9d0d558822ca8a1c30566664d14e7cb1858 100644 (file)
@@ -186,7 +186,7 @@ _notmuch_thread_create (void *ctx,
     thread->oldest = 0;
     thread->newest = 0;
 
     thread->oldest = 0;
     thread->newest = 0;
 
-    notmuch_query_set_sort (thread_id_query, NOTMUCH_SORT_DATE_OLDEST_FIRST);
+    notmuch_query_set_sort (thread_id_query, NOTMUCH_SORT_DATE);
 
     for (messages = notmuch_query_search_messages (thread_id_query, 0, -1);
         notmuch_messages_has_more (messages);
 
     for (messages = notmuch_query_search_messages (thread_id_query, 0, -1);
         notmuch_messages_has_more (messages);
index a0a71bbd7992e02e4f3b42b1bf55939fac0bdc64..8db09c7765afde6e4e2f89f9e90dea818d11560e 100644 (file)
@@ -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;
     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) {
 
     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;
            }
                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;
     }
 
        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))
     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);
 
 
        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",
        relative_date = notmuch_time_relative_date (ctx, date);
 
        printf ("thread:%s %12s [%d/%d] %s; %s",