[PATCH 1/2] WIP: provide alternate API for n_d_remove_message

Subject: [PATCH 1/2] WIP: provide alternate API for n_d_remove_message

Date: Fri, 31 Jul 2020 07:33:12 -0300

To: notmuch@notmuchmail.org

Cc: David Bremner

From: David Bremner


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
_______________________________________________
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-leave@notmuchmail.org

Thread: