unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Tomi Ollila <tomi.ollila@iki.fi>
To: David Bremner <david@tethera.net>, notmuch@notmuchmail.org
Subject: Re: [PATCH 04/15] lib/thread: sort sibling messages by date
Date: Sat, 01 Sep 2018 20:11:49 +0300	[thread overview]
Message-ID: <m2d0txqh0q.fsf@guru.guru-group.fi> (raw)
In-Reply-To: <20180830112915.11761-5-david@tethera.net>

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 <<EOF > 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

  reply	other threads:[~2018-09-01 17:11 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-30 11:29 threading replies fixes v3 David Bremner
2018-08-30 11:29 ` [PATCH 01/15] util: add DEBUG_PRINTF, rename error_util.h -> debug_print.h David Bremner
2018-09-01 17:06   ` Tomi Ollila
2018-09-03 11:54     ` David Bremner
2018-08-30 11:29 ` [PATCH 02/15] test: start threading test corpus David Bremner
2018-08-30 11:29 ` [PATCH 03/15] test: add known broken tests for "ghost roots" David Bremner
2018-08-30 11:29 ` [PATCH 04/15] lib/thread: sort sibling messages by date David Bremner
2018-09-01 17:11   ` Tomi Ollila [this message]
2018-09-03 15:18     ` David Bremner
2018-08-30 11:29 ` [PATCH 05/15] lib: read reference terms into message struct David Bremner
2018-08-30 11:29 ` [PATCH 06/15] lib/thread: refactor in_reply_to test David Bremner
2018-09-01 20:02   ` Tomi Ollila
2018-08-30 11:29 ` [PATCH 07/15] lib/thread: initial use of references as for fallback parenting David Bremner
2018-08-30 11:29 ` [PATCH 08/15] lib: calculate message depth in thread David Bremner
2018-08-30 11:29 ` [PATCH 09/15] lib/thread: rewrite _parent_or_toplevel to use depths David Bremner
2018-08-30 11:29 ` [PATCH 10/15] lib/thread: change _resolve_thread_relationships " David Bremner
2018-08-30 11:29 ` [PATCH 11/15] test: add known broken test for good In-Reply-To / bad References David Bremner
2018-08-30 11:29 ` [PATCH 12/15] test/thread-replies: mangle In-Reply-To's David Bremner
2018-08-30 11:29 ` [PATCH 13/15] util/string-util: export skip_space David Bremner
2018-08-30 11:29 ` [PATCH 14/15] lib: add _notmuch_message_id_parse_strict David Bremner
2018-09-01 20:27   ` Tomi Ollila
2018-08-30 11:29 ` [PATCH 15/15] lib: change parent strategy to use In-Reply-To if it looks sane David Bremner
2018-09-01 20:29   ` Tomi Ollila

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m2d0txqh0q.fsf@guru.guru-group.fi \
    --to=tomi.ollila@iki.fi \
    --cc=david@tethera.net \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).