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 2B72A6DE09CD for ; Sat, 21 Apr 2018 10:54:07 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: 0.476 X-Spam-Level: X-Spam-Status: No, score=0.476 tagged_above=-999 required=5 tests=[AWL=-0.176, 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 WpAzaNcHlOPP for ; Sat, 21 Apr 2018 10:54:06 -0700 (PDT) Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34]) by arlo.cworth.org (Postfix) with ESMTP id 0358B6DE0273 for ; Sat, 21 Apr 2018 10:54:05 -0700 (PDT) Received: from guru.guru-group.fi (localhost [IPv6:::1]) by guru.guru-group.fi (Postfix) with ESMTP id 53825100084; Sat, 21 Apr 2018 20:53:58 +0300 (EEST) From: Tomi Ollila To: David Bremner , notmuch@notmuchmail.org, David Bremner Subject: Re: [PATCH 6/6] lib: choose oldest message when breaking reference loops In-Reply-To: <20180420183135.14331-7-david@tethera.net> References: <20180414014610.15438-6-david@tethera.net> <20180420183135.14331-1-david@tethera.net> <20180420183135.14331-7-david@tethera.net> User-Agent: Notmuch/0.26.1+22~g888240d (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, 21 Apr 2018 17:54:07 -0000 On Fri, Apr 20 2018, David Bremner wrote: > This preserves a sensible thread order > --- > lib/thread.cc | 33 ++++++++++++++++++++++++--------- > test/T050-new.sh | 1 - > 2 files changed, 24 insertions(+), 10 deletions(-) > > diff --git a/lib/thread.cc b/lib/thread.cc > index dbac002f..a6dc4e5a 100644 > --- a/lib/thread.cc > +++ b/lib/thread.cc > @@ -390,20 +390,18 @@ _thread_add_matched_message (notmuch_thread_t *thread, > static void > _resolve_thread_relationships (notmuch_thread_t *thread) > { > - notmuch_message_node_t *node; > + notmuch_message_node_t *node, *first_node; > notmuch_message_t *message, *parent; > const char *in_reply_to; > > - for (node = thread->message_list->head; node; node = node->next) { > + first_node = thread->message_list->head; > + if (!first_node) Our style *dictates* space after '!'. > + return; > + > + for (node = first_node->next; node; node = node->next) { > message = node->message; > in_reply_to = _notmuch_message_get_in_reply_to (message); > - /* > - * if we reach the end of the list without finding a top-level > - * message, that means the thread is a cycle (or set of > - * cycles) and any message can be considered top-level > - */ > - if ((thread->toplevel_list->head || node->next) && > - in_reply_to && strlen (in_reply_to) && > + if (in_reply_to && strlen (in_reply_to) && > g_hash_table_lookup_extended (thread->message_hash, > in_reply_to, NULL, > (void **) &parent)) > @@ -412,6 +410,23 @@ _resolve_thread_relationships (notmuch_thread_t *thread) > _notmuch_message_list_add_message (thread->toplevel_list, message); > } > > + /* > + * if we reach the end of the list without finding a top-level > + * message, that means the thread is a cycle (or set of cycles) > + * and any message can be considered top-level. Choose the oldest > + * message, which happens to be first in our list. > + */ > + message=first_node->message; > + in_reply_to = _notmuch_message_get_in_reply_to (message); > + if (thread->toplevel_list->head && > + in_reply_to && strlen (in_reply_to) && Otherwise the series _looks_ good do me. The thing that disturbs me are these `strlen (in_reply_to)` contents. Perhaps SomeOne(TM) changes these to e.g. in_reply_to[0] in the future... Tomi > + g_hash_table_lookup_extended (thread->message_hash, > + in_reply_to, NULL, > + (void **) &parent)) > + _notmuch_message_add_reply (parent, message); > + else > + _notmuch_message_list_add_message (thread->toplevel_list, message); > + > /* 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/T050-new.sh b/test/T050-new.sh > index 320a7646..9025fa7a 100755 > --- a/test/T050-new.sh > +++ b/test/T050-new.sh > @@ -359,7 +359,6 @@ test_begin_subtest "reference loop does not crash" > test_expect_code 0 "notmuch show --format=json id:mid-loop-12@example.org id:mid-loop-21@example.org > OUTPUT" > > test_begin_subtest "reference loop ordered by date" > -test_subtest_known_broken > threadid=$(notmuch search --output=threads id:mid-loop-12@example.org) > notmuch show --format=mbox $threadid | grep '^Date' > OUTPUT > cat < EXPECTED > -- > 2.17.0 > > _______________________________________________ > notmuch mailing list > notmuch@notmuchmail.org > https://notmuchmail.org/mailman/listinfo/notmuch