From 41531353b8784bf7d844e7825af29aa16634d9a6 Mon Sep 17 00:00:00 2001 From: Jani Nikula Date: Fri, 1 Nov 2013 15:27:11 +0100 Subject: [PATCH] [PATCH 2/6] lib: add closure parameter to compact status update callback --- 19/c878142dce67b361e375460aee7fead559e451 | 185 ++++++++++++++++++++++ 1 file changed, 185 insertions(+) create mode 100644 19/c878142dce67b361e375460aee7fead559e451 diff --git a/19/c878142dce67b361e375460aee7fead559e451 b/19/c878142dce67b361e375460aee7fead559e451 new file mode 100644 index 000000000..98e867d80 --- /dev/null +++ b/19/c878142dce67b361e375460aee7fead559e451 @@ -0,0 +1,185 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by olra.theworths.org (Postfix) with ESMTP id 3B638431FC9 + for ; Fri, 1 Nov 2013 07:27:46 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" +X-Spam-Flag: NO +X-Spam-Score: -0.7 +X-Spam-Level: +X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 + tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled +Received: from olra.theworths.org ([127.0.0.1]) + by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id 25yFSB0D2kMX for ; + Fri, 1 Nov 2013 07:27:41 -0700 (PDT) +Received: from mail-ee0-f53.google.com (mail-ee0-f53.google.com + [74.125.83.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client + certificate requested) by olra.theworths.org (Postfix) with ESMTPS id + 1E4E5431FBC for ; Fri, 1 Nov 2013 07:27:36 -0700 + (PDT) +Received: by mail-ee0-f53.google.com with SMTP id e51so2013825eek.26 + for ; Fri, 01 Nov 2013 07:27:36 -0700 (PDT) +X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; + d=1e100.net; s=20130820; + h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to + :references:in-reply-to:references; + bh=rz5bv7liRBm4y//K57izlkVQPIQLZc6lDfkaQX3iIZw=; + b=Tt+yIskH3xzNUsFiJdkVMtxg1zEBTmPHoG5jmQldRm7/2yFi7ijKxm/B/cvcwNAziY + hwu5AL6hNk+FmrpJoYalp5q9PVVbeBDiukuYXQpOXTcqfq9pqiGWtWlJ2px+SlqTVMoJ + KLS1yvJ8MEIW2W3xshwfecg/iWTN+QrqvHc3cY6S51CkLb3TB/r1YjCLcrIQJgv3kdx7 + 13ZqJrNI8x/iSLDZBCb9J6UeqUpN/zVqCCjjQpa9C9dDN5TK2oyM+VDgT+RECylfj55M + yQ8/hX4qHsUtxNmXpmvBDyIo75vikXOZ8eSIhzBxJK6rxAU7U9tUErIR2vC7lyTxxdrs + Q7ng== +X-Gm-Message-State: + ALoCoQlV9kWLn1raZmNX3hx+oYsnKTMBLKyJjiDH/b89VOOz8ArL4H4ku4dPLbvVX6FrBM98AxxY +X-Received: by 10.14.87.3 with SMTP id x3mr143320eee.76.1383316055990; + Fri, 01 Nov 2013 07:27:35 -0700 (PDT) +Received: from localhost ([2001:4b98:dc0:43:216:3eff:fe1b:25f3]) + by mx.google.com with ESMTPSA id s3sm8404377eeo.3.2013.11.01.07.27.34 + for + (version=TLSv1.1 cipher=RC4-SHA bits=128/128); + Fri, 01 Nov 2013 07:27:35 -0700 (PDT) +From: Jani Nikula +To: notmuch@notmuchmail.org +Subject: [PATCH 2/6] lib: add closure parameter to compact status update + callback +Date: Fri, 1 Nov 2013 15:27:11 +0100 +Message-Id: + <2a58adbdc1257f16579692544b4bcbadca3d3045.1383315568.git.jani@nikula.org> +X-Mailer: git-send-email 1.7.2.5 +In-Reply-To: +References: +In-Reply-To: +References: +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.13 +Precedence: list +List-Id: "Use and development of the notmuch mail system." + +List-Unsubscribe: , + +List-Archive: +List-Post: +List-Help: +List-Subscribe: , + +X-List-Received-Date: Fri, 01 Nov 2013 14:27:46 -0000 + +This provides much more flexibility for the caller, and can still be +done without soname bumps. +--- + lib/database.cc | 14 +++++++++----- + lib/notmuch.h | 5 +++-- + notmuch-compact.c | 8 +++----- + 3 files changed, 15 insertions(+), 12 deletions(-) + +diff --git a/lib/database.cc b/lib/database.cc +index 3dfea0f..da549b4 100644 +--- a/lib/database.cc ++++ b/lib/database.cc +@@ -821,9 +821,11 @@ static int rmtree (const char *path) + class NotmuchCompactor : public Xapian::Compactor + { + notmuch_compact_status_cb_t status_cb; ++ void *status_closure; + + public: +- NotmuchCompactor(notmuch_compact_status_cb_t cb) : status_cb(cb) { } ++ NotmuchCompactor(notmuch_compact_status_cb_t cb, void *closure) : ++ status_cb(cb), status_closure(closure) { } + + virtual void + set_status (const std::string &table, const std::string &status) +@@ -842,7 +844,7 @@ public: + return; + } + +- status_cb(msg); ++ status_cb(msg, status_closure); + talloc_free(msg); + } + }; +@@ -861,7 +863,8 @@ public: + notmuch_status_t + notmuch_database_compact (const char* path, + const char* backup_path, +- notmuch_compact_status_cb_t status_cb) ++ notmuch_compact_status_cb_t status_cb, ++ void *closure) + { + void *local = talloc_new (NULL); + char *notmuch_path, *xapian_path, *compact_xapian_path; +@@ -909,7 +912,7 @@ notmuch_database_compact (const char* path, + } + + try { +- NotmuchCompactor compactor(status_cb); ++ NotmuchCompactor compactor(status_cb, closure); + + compactor.set_renumber(false); + compactor.add_source(xapian_path); +@@ -947,7 +950,8 @@ DONE: + notmuch_status_t + notmuch_database_compact (unused (const char* path), + unused (const char* backup_path), +- unused (notmuch_compact_status_cb_t status_cb)) ++ unused (notmuch_compact_status_cb_t status_cb), ++ unused (void *closure)) + { + fprintf (stderr, "notmuch was compiled against a xapian version lacking compaction support.\n"); + return NOTMUCH_STATUS_UNSUPPORTED_OPERATION; +diff --git a/lib/notmuch.h b/lib/notmuch.h +index 9dab555..cd301a4 100644 +--- a/lib/notmuch.h ++++ b/lib/notmuch.h +@@ -219,7 +219,7 @@ notmuch_database_close (notmuch_database_t *database); + /* A callback invoked by notmuch_database_compact to notify the user + * of the progress of the compaction process. + */ +-typedef void (*notmuch_compact_status_cb_t)(const char*); ++typedef void (*notmuch_compact_status_cb_t)(const char *message, void *closure); + + /* Compact a notmuch database, backing up the original database to the + * given path. +@@ -231,7 +231,8 @@ typedef void (*notmuch_compact_status_cb_t)(const char*); + notmuch_status_t + notmuch_database_compact (const char* path, + const char* backup_path, +- notmuch_compact_status_cb_t status_cb); ++ notmuch_compact_status_cb_t status_cb, ++ void *closure); + + /* Destroy the notmuch database, closing it if necessary and freeing + * all associated resources. +diff --git a/notmuch-compact.c b/notmuch-compact.c +index bfda40e..ee7afcf 100644 +--- a/notmuch-compact.c ++++ b/notmuch-compact.c +@@ -20,10 +20,8 @@ + + #include "notmuch-client.h" + +-void status_update_cb (const char *msg); +- +-void +-status_update_cb (const char *msg) ++static void ++status_update_cb (const char *msg, unused (void *closure)) + { + printf("%s\n", msg); + } +@@ -38,7 +36,7 @@ notmuch_compact_command (notmuch_config_t *config, + notmuch_status_t ret; + + printf ("Compacting database...\n"); +- ret = notmuch_database_compact (path, backup_path, status_update_cb); ++ ret = notmuch_database_compact (path, backup_path, status_update_cb, NULL); + if (ret) { + fprintf (stderr, "Compaction failed: %s\n", notmuch_status_to_string(ret)); + } else { +-- +1.7.2.5 + -- 2.26.2