Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 7A854431FBD for ; Wed, 9 Dec 2009 04:43:55 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id zZ0f0vkhzH2e for ; Wed, 9 Dec 2009 04:43:54 -0800 (PST) Received: from flatline.sindominio.net (flatline.sindominio.net [82.144.4.26]) by olra.theworths.org (Postfix) with ESMTP id 8E85A431FAE for ; Wed, 9 Dec 2009 04:43:53 -0800 (PST) Received: from localhost (localhost.localdomain [127.0.0.1]) by flatline.sindominio.net (Postfix) with ESMTP id E62F9348032 for ; Wed, 9 Dec 2009 13:43:51 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at sindominio.net Received: from flatline.sindominio.net ([127.0.0.1]) by localhost (flatline.sindominio.net [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id MSXUm5ImRh9n for ; Wed, 9 Dec 2009 13:43:45 +0100 (CET) Received: from blackspot (rpollan-laptop.cern.ch [137.138.192.228]) by flatline.sindominio.net (Postfix) with ESMTPA id A2C6034800A for ; Wed, 9 Dec 2009 13:43:45 +0100 (CET) Received: by blackspot (Postfix, from userid 1000) id 4EB758BBF1; Wed, 9 Dec 2009 13:45:49 +0100 (CET) From: Ruben Pollan To: notmuch@notmuchmail.org Date: Wed, 9 Dec 2009 13:45:49 +0100 Message-Id: <1260362749-31994-1-git-send-email-meskio@sindominio.net> X-Mailer: git-send-email 1.6.5.4 In-Reply-To: <20091126202347.GA16654@blackspot> References: <20091126202347.GA16654@blackspot> Subject: [notmuch] [PATCH] Added regress option to threads iterator X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 09 Dec 2009 12:43:55 -0000 Added the functions notmuch_threads_regress and notmuch_threads_is_first to notmuch library. With them is possible to iterate backwards on threads. * notmuch_threads_regress do the opposite than notmuch_threads_advance, getting the threads iterator one position backwards. * notmuch_threads_is_first return TRUE if the iterator is in the first thread. --- lib/notmuch.h | 8 ++++++++ lib/query.cc | 28 ++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 0 deletions(-) diff --git a/lib/notmuch.h b/lib/notmuch.h index 69bd98a..e28ce46 100644 --- a/lib/notmuch.h +++ b/lib/notmuch.h @@ -429,6 +429,10 @@ notmuch_query_destroy (notmuch_query_t *query); notmuch_bool_t notmuch_threads_has_more (notmuch_threads_t *threads); +/* Is the given notmuch_threads_t object on the first threads */ +notmuch_bool_t +notmuch_threads_is_first (notmuch_threads_t *threads); + /* Get the current thread from 'threads' as a notmuch_thread_t. * * Note: The returned thread belongs to 'threads' and has a lifetime @@ -451,6 +455,10 @@ notmuch_threads_get (notmuch_threads_t *threads); void notmuch_threads_advance (notmuch_threads_t *threads); +/* Regress the 'threads' iterator to the previous result. */ +void +notmuch_threads_regress (notmuch_threads_t *threads); + /* Destroy a notmuch_threads_t object. * * It's not strictly necessary to call this function. All memory from diff --git a/lib/query.cc b/lib/query.cc index 94a6860..cade17b 100644 --- a/lib/query.cc +++ b/lib/query.cc @@ -310,6 +310,12 @@ notmuch_threads_has_more (notmuch_threads_t *threads) return FALSE; } +notmuch_bool_t +notmuch_threads_is_first (notmuch_threads_t *threads) +{ + return (g_hash_table_size (threads->threads) <= 1); +} + notmuch_thread_t * notmuch_threads_get (notmuch_threads_t *threads) { @@ -329,6 +335,28 @@ notmuch_threads_advance (notmuch_threads_t *threads) } void +notmuch_threads_regress (notmuch_threads_t *threads) +{ + notmuch_message_t *message; + const char *thread_id; + + thread_id = threads->thread_id; + + while (!notmuch_messages_is_first (threads->messages)) + { + notmuch_messages_regress (threads->messages); + message = notmuch_messages_get (threads->messages); + threads->thread_id = notmuch_message_get_thread_id (message); + + if (strcmp (threads->thread_id, thread_id)) + { + g_hash_table_remove (threads->threads, thread_id); + return; + } + } +} + +void notmuch_threads_destroy (notmuch_threads_t *threads) { talloc_free (threads); -- 1.6.5.4