[PATCH 2/6] lib: add closure parameter to compact status update callback
authorJani Nikula <jani@nikula.org>
Fri, 1 Nov 2013 14:27:11 +0000 (15:27 +0100)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:57:50 +0000 (09:57 -0800)
19/c878142dce67b361e375460aee7fead559e451 [new file with mode: 0644]

diff --git a/19/c878142dce67b361e375460aee7fead559e451 b/19/c878142dce67b361e375460aee7fead559e451
new file mode 100644 (file)
index 0000000..98e867d
--- /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 3B638431FC9\r
+       for <notmuch@notmuchmail.org>; Fri,  1 Nov 2013 07:27:46 -0700 (PDT)\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 25yFSB0D2kMX for <notmuch@notmuchmail.org>;\r
+       Fri,  1 Nov 2013 07:27:41 -0700 (PDT)\r
+Received: from mail-ee0-f53.google.com (mail-ee0-f53.google.com\r
+ [74.125.83.53])       (using TLSv1 with cipher RC4-SHA (128/128 bits))        (No client\r
+ certificate requested)        by olra.theworths.org (Postfix) with ESMTPS id\r
+ 1E4E5431FBC   for <notmuch@notmuchmail.org>; Fri,  1 Nov 2013 07:27:36 -0700\r
+ (PDT)\r
+Received: by mail-ee0-f53.google.com with SMTP id e51so2013825eek.26\r
+       for <notmuch@notmuchmail.org>; Fri, 01 Nov 2013 07:27:36 -0700 (PDT)\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=rz5bv7liRBm4y//K57izlkVQPIQLZc6lDfkaQX3iIZw=;\r
+       b=Tt+yIskH3xzNUsFiJdkVMtxg1zEBTmPHoG5jmQldRm7/2yFi7ijKxm/B/cvcwNAziY\r
+       hwu5AL6hNk+FmrpJoYalp5q9PVVbeBDiukuYXQpOXTcqfq9pqiGWtWlJ2px+SlqTVMoJ\r
+       KLS1yvJ8MEIW2W3xshwfecg/iWTN+QrqvHc3cY6S51CkLb3TB/r1YjCLcrIQJgv3kdx7\r
+       13ZqJrNI8x/iSLDZBCb9J6UeqUpN/zVqCCjjQpa9C9dDN5TK2oyM+VDgT+RECylfj55M\r
+       yQ8/hX4qHsUtxNmXpmvBDyIo75vikXOZ8eSIhzBxJK6rxAU7U9tUErIR2vC7lyTxxdrs\r
+       Q7ng==\r
+X-Gm-Message-State:\r
+ ALoCoQlV9kWLn1raZmNX3hx+oYsnKTMBLKyJjiDH/b89VOOz8ArL4H4ku4dPLbvVX6FrBM98AxxY\r
+X-Received: by 10.14.87.3 with SMTP id x3mr143320eee.76.1383316055990;\r
+       Fri, 01 Nov 2013 07:27:35 -0700 (PDT)\r
+Received: from localhost ([2001:4b98:dc0:43:216:3eff:fe1b:25f3])\r
+       by mx.google.com with ESMTPSA id s3sm8404377eeo.3.2013.11.01.07.27.34\r
+       for <multiple recipients>\r
+       (version=TLSv1.1 cipher=RC4-SHA bits=128/128);\r
+       Fri, 01 Nov 2013 07:27:35 -0700 (PDT)\r
+From: Jani Nikula <jani@nikula.org>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 2/6] lib: add closure parameter to compact status update\r
+       callback\r
+Date: Fri,  1 Nov 2013 15:27:11 +0100\r
+Message-Id:\r
+ <2a58adbdc1257f16579692544b4bcbadca3d3045.1383315568.git.jani@nikula.org>\r
+X-Mailer: git-send-email 1.7.2.5\r
+In-Reply-To: <cover.1383315568.git.jani@nikula.org>\r
+References: <cover.1383315568.git.jani@nikula.org>\r
+In-Reply-To: <cover.1383315568.git.jani@nikula.org>\r
+References: <cover.1383315568.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: Fri, 01 Nov 2013 14:27:46 -0000\r
+\r
+This provides much more flexibility for the caller, and can still be\r
+done without soname bumps.\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 3dfea0f..da549b4 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 = talloc_new (NULL);\r
+     char *notmuch_path, *xapian_path, *compact_xapian_path;\r
+@@ -909,7 +912,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
+@@ -947,7 +950,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.7.2.5\r
+\r