[PATCH v2 05/11] lib: add closure parameter to compact status update callback
authorJani Nikula <jani@nikula.org>
Sun, 3 Nov 2013 12:24:45 +0000 (14:24 +0200)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:57:57 +0000 (09:57 -0800)
c8/751d1225a5957194e99cf8dc9daeab0f933279 [new file with mode: 0644]

diff --git a/c8/751d1225a5957194e99cf8dc9daeab0f933279 b/c8/751d1225a5957194e99cf8dc9daeab0f933279
new file mode 100644 (file)
index 0000000..20e0dfd
--- /dev/null
@@ -0,0 +1,185 @@
+Return-Path: <jani@nikula.org>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id A39B8429E3E\r
+       for <notmuch@notmuchmail.org>; Sun,  3 Nov 2013 04:25:30 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References"\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.7\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
+       tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id gAUrwLYers1X for <notmuch@notmuchmail.org>;\r
+       Sun,  3 Nov 2013 04:25:24 -0800 (PST)\r
+Received: from mail-ee0-f50.google.com (mail-ee0-f50.google.com\r
+ [74.125.83.50])       (using TLSv1 with cipher RC4-SHA (128/128 bits))        (No client\r
+ certificate requested)        by olra.theworths.org (Postfix) with ESMTPS id\r
+ 399E8431FDE   for <notmuch@notmuchmail.org>; Sun,  3 Nov 2013 04:25:08 -0800\r
+ (PST)\r
+Received: by mail-ee0-f50.google.com with SMTP id l10so581664eei.37\r
+       for <notmuch@notmuchmail.org>; Sun, 03 Nov 2013 04:25:07 -0800 (PST)\r
+X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
+       d=1e100.net; s=20130820;\r
+       h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\r
+       :references:in-reply-to:references;\r
+       bh=DWEBbUuiEDmuadlgd42BYlBJOj0kYq9uRut/OMxFDXU=;\r
+       b=UZW6cCtVzWaOSxChr+7+NEsrtQbc3t9DKzh0HAUtkx3XpvnKS/h3wTyJmgPSZ8AHtK\r
+       cX/8niCO5V8FJhP1gAGqhh2MWLxEBkRt9h5I+qNT9Rkq6G1iNY7G3R4orkixQVFCv1H3\r
+       G+ThAkZfXAPVRW4dRQZ7LSuSmClq7TT04n0saVdIaM0CbgV2vCxGGuwet9KXwghSjg7l\r
+       y5eMkt+Gxrlpz9mSNHfJSLm4dTNY54VSyhhBkOwf4BhhFd3lxYAKiSohlN58CEupigXu\r
+       kTgIhQH+G68O936JICRnX3+nHbOs4s7ZQOYGbct4UTqBgAlfm6xy+EyaoviMSgDdV+un\r
+       qFig==\r
+X-Gm-Message-State:\r
+ ALoCoQmVQBcBe9EnXS5MMzZUqpRurdG/L4vT9Z3KheTbGqSAvH8XmyhYp4DO6VrSdlXNaD5GQZxm\r
+X-Received: by 10.14.224.132 with SMTP id x4mr12725741eep.5.1383481506926;\r
+       Sun, 03 Nov 2013 04:25:06 -0800 (PST)\r
+Received: from localhost (dsl-hkibrasgw2-58c36f-91.dhcp.inet.fi.\r
+       [88.195.111.91])\r
+       by mx.google.com with ESMTPSA id k7sm32794500eeg.13.2013.11.03.04.25.05\r
+       for <multiple recipients>\r
+       (version=TLSv1.2 cipher=RC4-SHA bits=128/128);\r
+       Sun, 03 Nov 2013 04:25:06 -0800 (PST)\r
+From: Jani Nikula <jani@nikula.org>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v2 05/11] lib: add closure parameter to compact status update\r
+       callback\r
+Date: Sun,  3 Nov 2013 14:24:45 +0200\r
+Message-Id:\r
+ <277337f8810959b702ddc657e88577c125cbd15e.1383481295.git.jani@nikula.org>\r
+X-Mailer: git-send-email 1.8.4.rc3\r
+In-Reply-To: <cover.1383481295.git.jani@nikula.org>\r
+References: <cover.1383481295.git.jani@nikula.org>\r
+In-Reply-To: <cover.1383481295.git.jani@nikula.org>\r
+References: <cover.1383481295.git.jani@nikula.org>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Sun, 03 Nov 2013 12:25:31 -0000\r
+\r
+This provides much more flexibility for the caller.\r
+---\r
+ lib/database.cc   | 14 +++++++++-----\r
+ lib/notmuch.h     |  5 +++--\r
+ notmuch-compact.c |  8 +++-----\r
+ 3 files changed, 15 insertions(+), 12 deletions(-)\r
+\r
+diff --git a/lib/database.cc b/lib/database.cc\r
+index eadf8a7..5a01703 100644\r
+--- a/lib/database.cc\r
++++ b/lib/database.cc\r
+@@ -821,9 +821,11 @@ static int rmtree (const char *path)\r
+ class NotmuchCompactor : public Xapian::Compactor\r
+ {\r
+     notmuch_compact_status_cb_t status_cb;\r
++    void *status_closure;\r
\r
+ public:\r
+-    NotmuchCompactor(notmuch_compact_status_cb_t cb) : status_cb(cb) { }\r
++    NotmuchCompactor(notmuch_compact_status_cb_t cb, void *closure) :\r
++      status_cb(cb), status_closure(closure) { }\r
\r
+     virtual void\r
+     set_status (const std::string &table, const std::string &status)\r
+@@ -842,7 +844,7 @@ public:\r
+           return;\r
+       }\r
\r
+-      status_cb(msg);\r
++      status_cb(msg, status_closure);\r
+       talloc_free(msg);\r
+     }\r
+ };\r
+@@ -861,7 +863,8 @@ public:\r
+ notmuch_status_t\r
+ notmuch_database_compact (const char* path,\r
+                         const char* backup_path,\r
+-                        notmuch_compact_status_cb_t status_cb)\r
++                        notmuch_compact_status_cb_t status_cb,\r
++                        void *closure)\r
+ {\r
+     void *local;\r
+     char *notmuch_path, *xapian_path, *compact_xapian_path;\r
+@@ -913,7 +916,7 @@ notmuch_database_compact (const char* path,\r
+     }\r
\r
+     try {\r
+-      NotmuchCompactor compactor(status_cb);\r
++      NotmuchCompactor compactor(status_cb, closure);\r
\r
+       compactor.set_renumber(false);\r
+       compactor.add_source(xapian_path);\r
+@@ -953,7 +956,8 @@ DONE:\r
+ notmuch_status_t\r
+ notmuch_database_compact (unused (const char* path),\r
+                         unused (const char* backup_path),\r
+-                        unused (notmuch_compact_status_cb_t status_cb))\r
++                        unused (notmuch_compact_status_cb_t status_cb),\r
++                        unused (void *closure))\r
+ {\r
+     fprintf (stderr, "notmuch was compiled against a xapian version lacking compaction support.\n");\r
+     return NOTMUCH_STATUS_UNSUPPORTED_OPERATION;\r
+diff --git a/lib/notmuch.h b/lib/notmuch.h\r
+index 9dab555..cd301a4 100644\r
+--- a/lib/notmuch.h\r
++++ b/lib/notmuch.h\r
+@@ -219,7 +219,7 @@ notmuch_database_close (notmuch_database_t *database);\r
+ /* A callback invoked by notmuch_database_compact to notify the user\r
+  * of the progress of the compaction process.\r
+  */\r
+-typedef void (*notmuch_compact_status_cb_t)(const char*);\r
++typedef void (*notmuch_compact_status_cb_t)(const char *message, void *closure);\r
\r
+ /* Compact a notmuch database, backing up the original database to the\r
+  * given path.\r
+@@ -231,7 +231,8 @@ typedef void (*notmuch_compact_status_cb_t)(const char*);\r
+ notmuch_status_t\r
+ notmuch_database_compact (const char* path,\r
+                         const char* backup_path,\r
+-                        notmuch_compact_status_cb_t status_cb);\r
++                        notmuch_compact_status_cb_t status_cb,\r
++                        void *closure);\r
\r
+ /* Destroy the notmuch database, closing it if necessary and freeing\r
+  * all associated resources.\r
+diff --git a/notmuch-compact.c b/notmuch-compact.c\r
+index bfda40e..ee7afcf 100644\r
+--- a/notmuch-compact.c\r
++++ b/notmuch-compact.c\r
+@@ -20,10 +20,8 @@\r
\r
+ #include "notmuch-client.h"\r
\r
+-void status_update_cb (const char *msg);\r
+-\r
+-void\r
+-status_update_cb (const char *msg)\r
++static void\r
++status_update_cb (const char *msg, unused (void *closure))\r
+ {\r
+     printf("%s\n", msg);\r
+ }\r
+@@ -38,7 +36,7 @@ notmuch_compact_command (notmuch_config_t *config,\r
+     notmuch_status_t ret;\r
\r
+     printf ("Compacting database...\n");\r
+-    ret = notmuch_database_compact (path, backup_path, status_update_cb);\r
++    ret = notmuch_database_compact (path, backup_path, status_update_cb, NULL);\r
+     if (ret) {\r
+       fprintf (stderr, "Compaction failed: %s\n", notmuch_status_to_string(ret));\r
+     } else {\r
+-- \r
+1.8.4.rc3\r
+\r