[PATCH] compat: expose canonicalize_file_name to C++

2021-04-16 Thread Đoàn Trần Công Danh
When compat canonicalize_file_name was introduced, it was limited to
C code only because it was used by C code only during that time.

>From 5ec6fd4d, (lib/open: check for split configuration when creating
database., 2021-02-16), lib/open.cc, which is C++, relies on the
existent of canonicalize_file_name.

Let's remove the language restriction to support those platforms don't
have canonicalize_file_name(3).
---
 compat/compat.h | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/compat/compat.h b/compat/compat.h
index 8f15e585..e418e62c 100644
--- a/compat/compat.h
+++ b/compat/compat.h
@@ -38,12 +38,9 @@ extern "C" {
 #endif
 
 #if ! HAVE_CANONICALIZE_FILE_NAME
-/* we only call this function from C, and this makes testing easier */
-#ifndef __cplusplus
 char *
 canonicalize_file_name (const char *path);
 #endif
-#endif
 
 #if ! HAVE_GETLINE
 #include 
-- 
2.31.1.192.g0881477623
___
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-le...@notmuchmail.org


[PATCH] ruby: fix ruby 3.1 warnings

2021-04-16 Thread Felipe Contreras
  init.c:214:5: warning: ‘rb_cData’ is deprecated: by: rb_cObject.  Will be 
removed in 3.1. [-Wdeprecated-declarations]

Signed-off-by: Felipe Contreras 
---
 bindings/ruby/init.c | 18 +-
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/bindings/ruby/init.c b/bindings/ruby/init.c
index 5556b43e..819fd1e3 100644
--- a/bindings/ruby/init.c
+++ b/bindings/ruby/init.c
@@ -211,7 +211,7 @@ Init_notmuch (void)
  *
  * Notmuch database interaction
  */
-notmuch_rb_cDatabase = rb_define_class_under (mod, "Database", rb_cData);
+notmuch_rb_cDatabase = rb_define_class_under (mod, "Database", rb_cObject);
 rb_define_alloc_func (notmuch_rb_cDatabase, notmuch_rb_database_alloc);
 rb_define_singleton_method (notmuch_rb_cDatabase, "open", 
notmuch_rb_database_open, -1); /* in database.c */
 rb_define_method (notmuch_rb_cDatabase, "initialize", 
notmuch_rb_database_initialize, -1); /* in database.c */
@@ -237,7 +237,7 @@ Init_notmuch (void)
  *
  * Notmuch directory
  */
-notmuch_rb_cDirectory = rb_define_class_under (mod, "Directory", rb_cData);
+notmuch_rb_cDirectory = rb_define_class_under (mod, "Directory", 
rb_cObject);
 rb_undef_method (notmuch_rb_cDirectory, "initialize");
 rb_define_method (notmuch_rb_cDirectory, "destroy!", 
notmuch_rb_directory_destroy, 0); /* in directory.c */
 rb_define_method (notmuch_rb_cDirectory, "mtime", 
notmuch_rb_directory_get_mtime, 0); /* in directory.c */
@@ -250,7 +250,7 @@ Init_notmuch (void)
  *
  * Notmuch file names
  */
-notmuch_rb_cFileNames = rb_define_class_under (mod, "FileNames", rb_cData);
+notmuch_rb_cFileNames = rb_define_class_under (mod, "FileNames", 
rb_cObject);
 rb_undef_method (notmuch_rb_cFileNames, "initialize");
 rb_define_method (notmuch_rb_cFileNames, "destroy!", 
notmuch_rb_filenames_destroy, 0); /* in filenames.c */
 rb_define_method (notmuch_rb_cFileNames, "each", 
notmuch_rb_filenames_each, 0); /* in filenames.c */
@@ -261,7 +261,7 @@ Init_notmuch (void)
  *
  * Notmuch query
  */
-notmuch_rb_cQuery = rb_define_class_under (mod, "Query", rb_cData);
+notmuch_rb_cQuery = rb_define_class_under (mod, "Query", rb_cObject);
 rb_undef_method (notmuch_rb_cQuery, "initialize");
 rb_define_method (notmuch_rb_cQuery, "destroy!", notmuch_rb_query_destroy, 
0); /* in query.c */
 rb_define_method (notmuch_rb_cQuery, "sort", notmuch_rb_query_get_sort, 
0); /* in query.c */
@@ -279,7 +279,7 @@ Init_notmuch (void)
  *
  * Notmuch threads
  */
-notmuch_rb_cThreads = rb_define_class_under (mod, "Threads", rb_cData);
+notmuch_rb_cThreads = rb_define_class_under (mod, "Threads", rb_cObject);
 rb_undef_method (notmuch_rb_cThreads, "initialize");
 rb_define_method (notmuch_rb_cThreads, "destroy!", 
notmuch_rb_threads_destroy, 0); /* in threads.c */
 rb_define_method (notmuch_rb_cThreads, "each", notmuch_rb_threads_each, 
0); /* in threads.c */
@@ -290,7 +290,7 @@ Init_notmuch (void)
  *
  * Notmuch messages
  */
-notmuch_rb_cMessages = rb_define_class_under (mod, "Messages", rb_cData);
+notmuch_rb_cMessages = rb_define_class_under (mod, "Messages", rb_cObject);
 rb_undef_method (notmuch_rb_cMessages, "initialize");
 rb_define_method (notmuch_rb_cMessages, "destroy!", 
notmuch_rb_messages_destroy, 0); /* in messages.c */
 rb_define_method (notmuch_rb_cMessages, "each", notmuch_rb_messages_each, 
0); /* in messages.c */
@@ -302,7 +302,7 @@ Init_notmuch (void)
  *
  * Notmuch thread
  */
-notmuch_rb_cThread = rb_define_class_under (mod, "Thread", rb_cData);
+notmuch_rb_cThread = rb_define_class_under (mod, "Thread", rb_cObject);
 rb_undef_method (notmuch_rb_cThread, "initialize");
 rb_define_method (notmuch_rb_cThread, "destroy!", 
notmuch_rb_thread_destroy, 0); /* in thread.c */
 rb_define_method (notmuch_rb_cThread, "thread_id", 
notmuch_rb_thread_get_thread_id, 0); /* in thread.c */
@@ -321,7 +321,7 @@ Init_notmuch (void)
  *
  * Notmuch message
  */
-notmuch_rb_cMessage = rb_define_class_under (mod, "Message", rb_cData);
+notmuch_rb_cMessage = rb_define_class_under (mod, "Message", rb_cObject);
 rb_undef_method (notmuch_rb_cMessage, "initialize");
 rb_define_method (notmuch_rb_cMessage, "destroy!", 
notmuch_rb_message_destroy, 0); /* in message.c */
 rb_define_method (notmuch_rb_cMessage, "message_id", 
notmuch_rb_message_get_message_id, 0); /* in message.c */
@@ -349,7 +349,7 @@ Init_notmuch (void)
  *
  * Notmuch tags
  */
-notmuch_rb_cTags = rb_define_class_under (mod, "Tags", rb_cData);
+notmuch_rb_cTags = rb_define_class_under (mod, "Tags", rb_cObject);
 rb_undef_method (notmuch_rb_cTags, "initialize");
 rb_define_method (notmuch_rb_cTags, "destroy!", notmuch_rb_tags_destroy, 
0); /* in tags.c */
 rb_define_method (notmuch_rb_cTags, "each", notmuch_rb_tags_ea

Re: [PATCH] test: put shim at end of LD_PRELOAD path

2021-04-16 Thread David Bremner
David Bremner  writes:

> Certain tools like the address-sanitizer fail if they are not the
> first LD_PRELOADed library. It does not seem to matter for our shims,
> as long as they are loaded before libnotmuch.

For what it's worth, I've applied this change to master.

d
___
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-le...@notmuchmail.org


Re: [PATCH v2 0/2] scaffolding for autocrypt support

2021-04-16 Thread David Bremner
Daniel Kahn Gillmor  writes:

> Hi David, all--
>
> On Sun 2021-02-21 15:21:30 +, David Edmondson wrote:
>> I started looking at how to add autocrypt support based on
>> https://git.sr.ht/~zge/autocrypt.
>
> Thanks for this work, i'm glad to see the interest in autocrypt!
>
> I tend to think that the autocrypt handling belongs in libnotmuch, and
> not just in the emacs frontend, so i'm a bit concerned about what we'll
> have to prune out of the emacs frontend if we do manage to land the
> features in libnotmuch itself.

FTR, I'm waiting for the two of you to come to some concensus before
proceding with these patches.

d
___
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-le...@notmuchmail.org


Re: [PATCH] NEWS: user visible config related changes for 0.32

2021-04-16 Thread David Bremner
David Bremner  writes:

> ---
>  NEWS | 41 +
>  1 file changed, 41 insertions(+)
>

applied to master

d
___
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-le...@notmuchmail.org


[PATCH 2/2] lib: directly traverse postlists in _n_message_delete

2021-04-16 Thread David Bremner
This is intended to fix the slow behaviour of "notmuch new" (and possibly
"notmuch reindex") when large numbers of files are deleted.

The underlying issue [1] seems to be the Xapian glass backend spending
a large amount of time in db.has_positions when running queries with
large-ish amounts of unflushed changes.

This commit removes two uses of Xapian queries [2], and replaces them with
an approximation of what Xapian would do after optimizing the
queries. This avoids the calls to has_positions (which are in any case
un-needed because we are only using boolean terms here).

[1] Thanks to "andres" on IRC for narrowing down the performance
bottleneck.

[2] Thanks to Olly Betts of Xapian fame for talking me a through a fix
that does not require people to update Xapian.
---
 lib/message.cc | 68 +-
 1 file changed, 39 insertions(+), 29 deletions(-)

diff --git a/lib/message.cc b/lib/message.cc
index 0c2eeab5..42d56acb 100644
--- a/lib/message.cc
+++ b/lib/message.cc
@@ -1356,11 +1356,10 @@ notmuch_status_t
 _notmuch_message_delete (notmuch_message_t *message)
 {
 notmuch_status_t status;
-const char *mid, *tid, *query_string;
+const char *mid, *tid;
 notmuch_message_t *ghost;
 notmuch_private_status_t private_status;
 notmuch_database_t *notmuch;
-notmuch_query_t *query;
 unsigned int count = 0;
 bool is_ghost;
 
@@ -1382,16 +1381,33 @@ _notmuch_message_delete (notmuch_message_t *message)
 if (is_ghost)
return NOTMUCH_STATUS_SUCCESS;
 
-query_string = talloc_asprintf (message, "thread:%s", tid);
-query = notmuch_query_create (notmuch, query_string);
-if (query == NULL)
-   return NOTMUCH_STATUS_OUT_OF_MEMORY;
-status = notmuch_query_count_messages (query, &count);
-if (status) {
-   notmuch_query_destroy (query);
-   return status;
+/* look for a non-ghost message in the same thread */
+try {
+   Xapian::PostingIterator thread_doc, thread_doc_end;
+   Xapian::PostingIterator mail_doc, mail_doc_end;
+
+   _notmuch_database_find_doc_ids (message->notmuch, "thread", tid, 
&thread_doc,
+   &thread_doc_end);
+   _notmuch_database_find_doc_ids (message->notmuch, "type", "mail", 
&mail_doc, &mail_doc_end);
+
+   while (count == 0 &&
+  thread_doc != thread_doc_end &&
+  mail_doc != mail_doc_end) {
+   thread_doc.skip_to (*mail_doc);
+   if (thread_doc != thread_doc_end) {
+   if (*thread_doc == *mail_doc) {
+   count++;
+   } else {
+   mail_doc.skip_to (*thread_doc);
+   if (mail_doc != mail_doc_end && *thread_doc == *mail_doc)
+   count++;
+   }
+   }
+   }
+} catch (Xapian::Error &error) {
+   LOG_XAPIAN_EXCEPTION (message, error);
+   return NOTMUCH_STATUS_XAPIAN_EXCEPTION;
 }
-
 if (count > 0) {
/* reintroduce a ghost in its place because there are still
 * other active messages in this thread: */
@@ -1410,27 +1426,21 @@ _notmuch_message_delete (notmuch_message_t *message)
notmuch_message_destroy (ghost);
status = COERCE_STATUS (private_status, "Error converting to ghost 
message");
 } else {
-   /* the thread is empty; drop all ghost messages from it */
-   notmuch_messages_t *messages;
-   status = _notmuch_query_search_documents (query,
- "ghost",
- &messages);
-   if (status == NOTMUCH_STATUS_SUCCESS) {
-   notmuch_status_t last_error = NOTMUCH_STATUS_SUCCESS;
-   while (notmuch_messages_valid (messages)) {
-   message = notmuch_messages_get (messages);
-   status = _notmuch_message_delete (message);
-   if (status) /* we'll report the last failure we see;
-* if there is more than one failure, we
-* forget about previous ones */
-   last_error = status;
-   notmuch_message_destroy (message);
-   notmuch_messages_move_to_next (messages);
+   /* the thread now contains only ghosts: delete them */
+   try {
+   Xapian::PostingIterator doc, doc_end;
+
+   _notmuch_database_find_doc_ids (message->notmuch, "thread", tid, 
&doc, &doc_end);
+
+   for (; doc != doc_end; doc++) {
+   message->notmuch->writable_xapian_db->delete_document (*doc);
}
-   status = last_error;
+   } catch (Xapian::Error &error) {
+   LOG_XAPIAN_EXCEPTION (message, error);
+   return NOTMUCH_STATUS_XAPIAN_EXCEPTION;
}
+
 }
-notmuch_query_destroy (query);
 return status;
 }
 
-- 
2.30.2
___
notmuch mailing list -- notmuch@

[PATCH 1/2] perf-tests: add test for removing files.

2021-04-16 Thread David Bremner
Without the proposed fix for deletion performance [1], this test is
probably unreasonably slow compared to others at the same
small/medium/large scale.

[1]: id:20210414021627.1236560-3-da...@tethera.net
---
 performance-test/T00-new.sh | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/performance-test/T00-new.sh b/performance-test/T00-new.sh
index a14dd13f..53de1c27 100755
--- a/performance-test/T00-new.sh
+++ b/performance-test/T00-new.sh
@@ -26,6 +26,16 @@ perl -nle 'rename "$_.renamed", $_' $manifest
 
 time_run "new ($count mv back)" 'notmuch new'
 
+xargs tar cf backup.tar < $manifest
+
+perl -nle 'unlink $_; unlink $_.copy' $manifest
+
+time_run "new ($count rm)" 'notmuch new'
+
+tar xf backup.tar
+
+time_run "new ($count restore)" 'notmuch new'
+
 perl -nle 'link $_, "$_.copy"' $manifest
 
 time_run "new ($count cp)" 'notmuch new'
-- 
2.30.2
___
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-le...@notmuchmail.org


v1 deletion patches

2021-04-16 Thread David Bremner
This version has a better commit message for 2/2 and portability fixes
(thanks to Tomi) for 1/2.

It obsoletes the WIP version [1]

[1]: id:20210414021627.1236560-1-da...@tethera.net
___
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-le...@notmuchmail.org