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 67848431FBD for ; Wed, 17 Oct 2012 08:29:41 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.799 X-Spam-Level: X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_FROM=0.001, 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 szXn9dfTS7vg for ; Wed, 17 Oct 2012 08:29:40 -0700 (PDT) Received: from mail-qc0-f181.google.com (mail-qc0-f181.google.com [209.85.216.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id DBF03431FC0 for ; Wed, 17 Oct 2012 08:29:39 -0700 (PDT) Received: by mail-qc0-f181.google.com with SMTP id x40so6907021qcp.26 for ; Wed, 17 Oct 2012 08:29:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references :mime-version:content-type:content-transfer-encoding; bh=J0bW1jacLjTDc2u9iaTaEloAeiVJNsJVGdV88eBoyBA=; b=JrayjuRUCX3Hd3t20D2BXmnJp8ZLOpmegFFmDUom3ipUq72cF/V46tN/5G+mKpGOdL u6IbIkrBW5e3DO9fu/GabkSmb6mPwkPPbqH1vtJK8xFeCs8BS3lP6sFWXyPBzQoNhmKk xZlzrBKU98QGfjHZgIzPrgwHDrWAWrnSBF35xF2dJ/WddDnP+OptN0PR6CqJhuaU4RsI NbhezRrt4Lb/hylhHTFa7gzR5JE4G/XsDn1gRoybMAE2LzBygSqbx4hButEoKzGnJm/5 BReE8KvyPWf4R04040yDJV3gy+ClemhEYI6OtauvuAWors9IQKqOZJSFmcCo3WYFNATR YLEw== Received: by 10.49.72.199 with SMTP id f7mr43853326qev.43.1350487779701; Wed, 17 Oct 2012 08:29:39 -0700 (PDT) Received: from ben-laptop.hasb.physics.cns (physicsnat56.physics.umass.edu. [128.119.50.38]) by mx.google.com with ESMTPS id eq10sm13366039qab.0.2012.10.17.08.29.39 (version=SSLv3 cipher=OTHER); Wed, 17 Oct 2012 08:29:39 -0700 (PDT) From: Ben Gamari To: notmuch@notmuchmail.org Subject: =?UTF-8?q?=5BPATCH=203/3=5D=20Add=20notmuch=20compact=20command?= Date: Wed, 17 Oct 2012 11:28:57 -0400 Message-Id: <1350487737-32058-4-git-send-email-bgamari.foss@gmail.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1350487737-32058-1-git-send-email-bgamari.foss@gmail.com> References: <1350487737-32058-1-git-send-email-bgamari.foss@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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: Wed, 17 Oct 2012 15:29:41 -0000 --- Makefile.local | 1 + notmuch-client.h | 3 +++ notmuch-compact.c | 43 +++++++++++++++++++++++++++++++++++++++++++ notmuch.c | 3 +++ 4 files changed, 50 insertions(+) create mode 100644 notmuch-compact.c diff --git a/Makefile.local b/Makefile.local index 7f2d4f1..e050ba6 100644 --- a/Makefile.local +++ b/Makefile.local @@ -258,6 +258,7 @@ notmuch_client_srcs = \ gmime-filter-headers.c \ hooks.c \ notmuch.c \ + notmuch-compact.c \ notmuch-config.c \ notmuch-count.c \ notmuch-dump.c \ diff --git a/notmuch-client.h b/notmuch-client.h index ae9344b..a6c624b 100644 --- a/notmuch-client.h +++ b/notmuch-client.h @@ -157,6 +157,9 @@ int notmuch_cat_command (void *ctx, int argc, char *argv[]); int +notmuch_compact_command (void *ctx, int argc, char *argv[]); + +int notmuch_config_command (void *ctx, int argc, char *argv[]); const char * diff --git a/notmuch-compact.c b/notmuch-compact.c new file mode 100644 index 0000000..6deb2ec --- /dev/null +++ b/notmuch-compact.c @@ -0,0 +1,43 @@ +/* notmuch - Not much of an email program, (just index and search) + * + * Copyright © 2009 Carl Worth + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://www.gnu.org/licenses/ . + * + * Author: Carl Worth + */ + +#include "notmuch-client.h" + +int +notmuch_compact_command (void *ctx, unused (int argc), unused (char *argv[])) +{ + notmuch_config_t *config; + notmuch_database_t *notmuch; + + config = notmuch_config_open (ctx, NULL, NULL); + if (config == NULL) + return 1; + + if (notmuch_database_open (notmuch_config_get_database_path (config), + NOTMUCH_DATABASE_MODE_READ_WRITE, ¬much)) + return 1; + + printf ("Compacting database... "); + notmuch_database_close_compact (notmuch); + printf ("Done.\n"); + notmuch_database_destroy (notmuch); + + return 0; +} diff --git a/notmuch.c b/notmuch.c index 477a09c..7b6c5ae 100644 --- a/notmuch.c +++ b/notmuch.c @@ -74,6 +74,9 @@ static command_t commands[] = { { "restore", notmuch_restore_command, "[--accumulate] []", "Restore the tags from the given dump file (see 'dump')." }, + { "compact", notmuch_compact_command, + NULL, + "Compacts the database." }, { "config", notmuch_config_command, "[get|set]
. [value ...]", "Get or set settings in the notmuch configuration file." }, -- 1.7.10.4