From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by arlo.cworth.org (Postfix) with ESMTP id 9089F6DE023E for ; Sat, 1 Sep 2018 10:11:58 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: 0.471 X-Spam-Level: X-Spam-Status: No, score=0.471 tagged_above=-999 required=5 tests=[AWL=-0.181, SPF_NEUTRAL=0.652] autolearn=disabled Received: from arlo.cworth.org ([127.0.0.1]) by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Ep8Pn1hnZkvm for ; Sat, 1 Sep 2018 10:11:57 -0700 (PDT) X-Greylist: delayed 311 seconds by postgrey-1.36 at arlo; Sat, 01 Sep 2018 10:11:56 PDT Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34]) by arlo.cworth.org (Postfix) with ESMTP id BBF096DE023D for ; Sat, 1 Sep 2018 10:11:56 -0700 (PDT) Received: from guru.guru-group.fi (localhost [IPv6:::1]) by guru.guru-group.fi (Postfix) with ESMTP id 1D1B51000E3; Sat, 1 Sep 2018 20:11:49 +0300 (EEST) From: Tomi Ollila To: David Bremner , notmuch@notmuchmail.org Subject: Re: [PATCH 04/15] lib/thread: sort sibling messages by date In-Reply-To: <20180830112915.11761-5-david@tethera.net> References: <20180830112915.11761-1-david@tethera.net> <20180830112915.11761-5-david@tethera.net> User-Agent: Notmuch/0.27+14~ge594ae3 (https://notmuchmail.org) Emacs/25.2.1 (x86_64-unknown-linux-gnu) X-Face: HhBM'cA~ MIME-Version: 1.0 Content-Type: text/plain X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.26 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: Sat, 01 Sep 2018 17:11:58 -0000 On Thu, Aug 30 2018, David Bremner wrote: > For non-root messages, this should not should anything currently, as > the messages are already added in date order. In the future we will > add some non-root messages in a second pass out of order and the > sorting will be useful. It does fix the order of multiple > root-messages (although it is overkill for that). > --- > lib/message.cc | 47 +++++++++++++++++++++++++++++++++++++ > lib/notmuch-private.h | 3 +++ > lib/thread.cc | 6 +++++ > test/T510-thread-replies.sh | 2 -- > 4 files changed, 56 insertions(+), 2 deletions(-) > > diff --git a/lib/message.cc b/lib/message.cc > index 153e4bed..59e42d36 100644 > --- a/lib/message.cc > +++ b/lib/message.cc > @@ -588,6 +588,53 @@ _notmuch_message_add_reply (notmuch_message_t *message, > _notmuch_message_list_add_message (message->replies, reply); > } > > +static int > +_cmpmsg (const void *pa, const void *pb) > +{ > + notmuch_message_t **a = (notmuch_message_t **) pa; > + notmuch_message_t **b = (notmuch_message_t **) pb; > + time_t time_a = notmuch_message_get_date (*a); > + time_t time_b = notmuch_message_get_date (*b); > + > + return (int) difftime (time_a, time_b); time_t is often 64 bits now (and I suspect signed). int is often 32-bits (gcc -dM -E -xc /dev/null | grep -i size to verify), perhaps time_t as return value ? > +} > + > +notmuch_message_list_t * > +_notmuch_message_sort_subtrees (void *ctx, notmuch_message_list_t *list) > +{ > + > + size_t count = 0; > + size_t capacity = 16; > + > + if (! list) > + return list; > + > + void *local = talloc_new (NULL); > + notmuch_message_list_t *new_list = _notmuch_message_list_create (ctx); > + notmuch_message_t **message_array = talloc_zero_array (local, notmuch_message_t *, capacity); > + > + for (notmuch_messages_t *messages = _notmuch_messages_create (list); > + notmuch_messages_valid (messages); > + notmuch_messages_move_to_next (messages)) { > + notmuch_message_t *root = notmuch_messages_get (messages); > + if (count >= capacity) { > + capacity *= 2; > + message_array = talloc_realloc (local, message_array, notmuch_message_t *, capacity); > + } > + message_array[count++] = root; > + root->replies = _notmuch_message_sort_subtrees (root, root->replies); > + } > + > + qsort (message_array, count, sizeof (notmuch_message_t *), _cmpmsg); > + for (size_t i = 0; i < count; i++) { > + _notmuch_message_list_add_message (new_list, message_array[i]); > + } > + > + talloc_free (local); > + talloc_free (list); > + return new_list; > +} > + > notmuch_messages_t * > notmuch_message_get_replies (notmuch_message_t *message) > { > diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h > index 499d73d4..725f9a7e 100644 > --- a/lib/notmuch-private.h > +++ b/lib/notmuch-private.h > @@ -539,6 +539,9 @@ _notmuch_message_remove_unprefixed_terms (notmuch_message_t *message); > const char * > _notmuch_message_get_thread_id_only(notmuch_message_t *message); > > +notmuch_message_list_t * > +_notmuch_message_sort_subtrees (void *ctx, notmuch_message_list_t *list); > + > /* sha1.c */ > > char * > diff --git a/lib/thread.cc b/lib/thread.cc > index e961c76b..b599a97d 100644 > --- a/lib/thread.cc > +++ b/lib/thread.cc > @@ -429,6 +429,12 @@ _resolve_thread_relationships (notmuch_thread_t *thread) > _notmuch_message_list_add_message (thread->toplevel_list, message); > } > > + /* XXX this could be made conditional on messages being inserted > + * (out of order) in later passes > + */ > + thread->toplevel_list = _notmuch_message_sort_subtrees (thread, thread->toplevel_list); > + > + > /* XXX: After scanning through the entire list looking for parents > * via "In-Reply-To", we should do a second pass that looks at the > * list of messages IDs in the "References" header instead. (And > diff --git a/test/T510-thread-replies.sh b/test/T510-thread-replies.sh > index 753c7ae1..72af50df 100755 > --- a/test/T510-thread-replies.sh > +++ b/test/T510-thread-replies.sh > @@ -192,7 +192,6 @@ EOF > test_expect_equal_file EXPECTED OUTPUT > > test_begin_subtest "reply to ghost (RT)" > -test_subtest_known_broken > notmuch show --entire-thread=true id:87bmc6lp3h.fsf@len.workgroup | grep ^Subject: | head -1 > OUTPUT > cat < EXPECTED > Subject: FYI: xxxx xxxxxxx xxxxxxxxxxxx xxx > @@ -200,7 +199,6 @@ EOF > test_expect_equal_file EXPECTED OUTPUT > > test_begin_subtest "reply to ghost (RT/tree view)" > -test_subtest_known_broken > test_emacs '(notmuch-tree "id:87bmc6lp3h.fsf@len.workgroup") > (notmuch-test-wait) > (test-output) > -- > 2.18.0 > > _______________________________________________ > notmuch mailing list > notmuch@notmuchmail.org > https://notmuchmail.org/mailman/listinfo/notmuch