unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: David Bremner <david@tethera.net>
To: notmuch@notmuchmail.org
Cc: David Bremner <david@tethera.net>
Subject: [PATCH 1/2] WIP: provide alternate API for n_d_remove_message
Date: Fri, 31 Jul 2020 07:33:12 -0300	[thread overview]
Message-ID: <20200731103313.1460011-2-david@tethera.net> (raw)
In-Reply-To: <20200731103313.1460011-1-david@tethera.net>

the idea is to reduce code duplication and extra object creation with notmuch new
---
 lib/database.cc | 18 ++++++++++++++----
 lib/notmuch.h   |  5 +++++
 2 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/lib/database.cc b/lib/database.cc
index 75189685..72592a88 100644
--- a/lib/database.cc
+++ b/lib/database.cc
@@ -2035,8 +2035,16 @@ notmuch_status_t
 notmuch_database_remove_message (notmuch_database_t *notmuch,
 				 const char *filename)
 {
+    return notmuch_database_remove_filename (notmuch, filename, NULL);
+}
+
+notmuch_status_t
+notmuch_database_remove_filename (notmuch_database_t *notmuch,
+			      const char *filename,
+			      notmuch_message_t **message_ptr) {
+
+    notmuch_message_t *message = NULL;
     notmuch_status_t status;
-    notmuch_message_t *message;
 
     status = notmuch_database_find_message_by_filename (notmuch, filename,
 							&message);
@@ -2048,12 +2056,14 @@ notmuch_database_remove_message (notmuch_database_t *notmuch,
 	else if (status == NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID)
 	    _notmuch_message_sync (message);
 
-	notmuch_message_destroy (message);
+	if (message_ptr) {
+	    *message_ptr = message;
+	} else {
+	    notmuch_message_destroy (message);
+	}
     }
-
     return status;
 }
-
 notmuch_status_t
 notmuch_database_find_message_by_filename (notmuch_database_t *notmuch,
 					   const char *filename,
diff --git a/lib/notmuch.h b/lib/notmuch.h
index f9e9cc41..e4c3d2ee 100644
--- a/lib/notmuch.h
+++ b/lib/notmuch.h
@@ -734,6 +734,11 @@ notmuch_database_find_message_by_filename (notmuch_database_t *notmuch,
 					   const char *filename,
 					   notmuch_message_t **message);
 
+notmuch_status_t
+notmuch_database_remove_filename (notmuch_database_t *notmuch,
+				  const char *filename,
+				  notmuch_message_t **message);
+
 /**
  * Return a list of all tags found in the database.
  *
-- 
2.27.0

  reply	other threads:[~2020-07-31 10:33 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-31 10:33 Request for testing: incremental improvement in move / rename handling David Bremner
2020-07-31 10:33 ` David Bremner [this message]
2020-07-31 10:33 ` [PATCH 2/2] WIP: use new API in notmuch-new David Bremner

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=20200731103313.1460011-2-david@tethera.net \
    --to=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).