--- /dev/null
+Return-Path: <bgamari.foss@gmail.com>\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 4D1E2431FDA\r
+ for <notmuch@notmuchmail.org>; Wed, 2 Oct 2013 13:31:10 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.799\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5\r
+ tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
+ FREEMAIL_FROM=0.001, 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 FlPKeZ+jBM+n for <notmuch@notmuchmail.org>;\r
+ Wed, 2 Oct 2013 13:31:05 -0700 (PDT)\r
+Received: from mail-qc0-f174.google.com (mail-qc0-f174.google.com\r
+ [209.85.216.174]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id 24E8A431FD6\r
+ for <notmuch@notmuchmail.org>; Wed, 2 Oct 2013 13:31:03 -0700 (PDT)\r
+Received: by mail-qc0-f174.google.com with SMTP id n9so944021qcw.19\r
+ for <notmuch@notmuchmail.org>; Wed, 02 Oct 2013 13:31:02 -0700 (PDT)\r
+DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;\r
+ h=from:to:cc:subject:date:message-id:in-reply-to:references\r
+ :mime-version:content-type:content-transfer-encoding;\r
+ bh=7jtcxk1tRBwBmX6VIMtPbgHsu86gjby8N+BEE5R14ys=;\r
+ b=yD6Vn4n0MJp1mvW5m1VKvTHqtlMJUPSLc1X9f7R7iSSudgLTNFxhuSEWyq2rCFKsp1\r
+ h9nbTDE9Bu1ipHpS3hqHOULB0zVMcwLbO1ziR2mliGcCkc8D55UnHfilNrBFF/jFZcZT\r
+ JlBFrIDeZKjDw6nEXV9YJsZyIHnqDlZaTnyNgMxQIVCZAwe7aRIq2VczbiUPtR84v+ot\r
+ BsE5gOd7gTDQcswTWjW/vB7mKFnNDhjtB0NlVizENWZbhYezAjv/krdQajwzU/LP875l\r
+ gv4EVdxm91xtMiOE3vNQsUqKivv2kweFdbm9tLLqJnNOrh4oLCv/wXOivuM73BfzI3CR\r
+ 6RbQ==\r
+X-Received: by 10.49.48.168 with SMTP id m8mr5373585qen.25.1380745862606;\r
+ Wed, 02 Oct 2013 13:31:02 -0700 (PDT)\r
+Received: from ben-laptop.hasb.physics.cns (gamari.physics.umass.edu.\r
+ [128.119.56.223])\r
+ by mx.google.com with ESMTPSA id fx6sm5946200qeb.1.1969.12.31.16.00.00\r
+ (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);\r
+ Wed, 02 Oct 2013 13:31:02 -0700 (PDT)\r
+From: Ben Gamari <bgamari.foss@gmail.com>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 2/3] notmuch-compact: Initial commit of CLI\r
+Date: Wed, 2 Oct 2013 16:30:47 -0400\r
+Message-Id: <1380745848-4972-3-git-send-email-bgamari.foss@gmail.com>\r
+X-Mailer: git-send-email 1.8.1.2\r
+In-Reply-To: <1380745848-4972-1-git-send-email-bgamari.foss@gmail.com>\r
+References: <1380745848-4972-1-git-send-email-bgamari.foss@gmail.com>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=UTF-8\r
+Content-Transfer-Encoding: 8bit\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: Wed, 02 Oct 2013 20:31:10 -0000\r
+\r
+Introduce the user command exposing the new compaction facility.\r
+\r
+Signed-off-by: Ben Gamari <bgamari.foss@gmail.com>\r
+---\r
+ Makefile.local | 1 +\r
+ notmuch-client.h | 3 +++\r
+ notmuch-compact.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++++\r
+ notmuch.c | 2 ++\r
+ 4 files changed, 62 insertions(+)\r
+ create mode 100644 notmuch-compact.c\r
+\r
+diff --git a/Makefile.local b/Makefile.local\r
+index b7cd266..0464a50 100644\r
+--- a/Makefile.local\r
++++ b/Makefile.local\r
+@@ -257,6 +257,7 @@ notmuch_client_srcs = \\r
+ gmime-filter-reply.c \\r
+ hooks.c \\r
+ notmuch.c \\r
++ notmuch-compact.c \\r
+ notmuch-config.c \\r
+ notmuch-count.c \\r
+ notmuch-dump.c \\r
+diff --git a/notmuch-client.h b/notmuch-client.h\r
+index afb0ddf..0bfa4da 100644\r
+--- a/notmuch-client.h\r
++++ b/notmuch-client.h\r
+@@ -204,6 +204,9 @@ notmuch_tag_command (notmuch_config_t *config, int argc, char *argv[]);\r
+ int\r
+ notmuch_config_command (notmuch_config_t *config, int argc, char *argv[]);\r
+ \r
++int\r
++notmuch_compact_command (notmuch_config_t *config, int argc, char *argv[]);\r
++\r
+ const char *\r
+ notmuch_time_relative_date (const void *ctx, time_t then);\r
+ \r
+diff --git a/notmuch-compact.c b/notmuch-compact.c\r
+new file mode 100644\r
+index 0000000..bfda40e\r
+--- /dev/null\r
++++ b/notmuch-compact.c\r
+@@ -0,0 +1,56 @@\r
++/* notmuch - Not much of an email program, (just index and search)\r
++ *\r
++ * Copyright © 2013 Ben Gamari\r
++ *\r
++ * This program is free software: you can redistribute it and/or modify\r
++ * it under the terms of the GNU General Public License as published by\r
++ * the Free Software Foundation, either version 3 of the License, or\r
++ * (at your option) any later version.\r
++ *\r
++ * This program is distributed in the hope that it will be useful,\r
++ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
++ * GNU General Public License for more details.\r
++ *\r
++ * You should have received a copy of the GNU General Public License\r
++ * along with this program. If not, see http://www.gnu.org/licenses/ .\r
++ *\r
++ * Author: Ben Gamari <bgamari.foss@gmail.com>\r
++ */\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
++{\r
++ printf("%s\n", msg);\r
++}\r
++\r
++int\r
++notmuch_compact_command (notmuch_config_t *config,\r
++ unused (int argc),\r
++ unused (char *argv[]))\r
++{\r
++ const char *path = notmuch_config_get_database_path (config);\r
++ const char *backup_path = path;\r
++ notmuch_status_t ret;\r
++\r
++ printf ("Compacting database...\n");\r
++ ret = notmuch_database_compact (path, backup_path, status_update_cb);\r
++ if (ret) {\r
++ fprintf (stderr, "Compaction failed: %s\n", notmuch_status_to_string(ret));\r
++ } else {\r
++ printf ("\n");\r
++ printf ("\n");\r
++ printf ("The old database has been moved to %s/xapian.old", backup_path);\r
++ printf ("\n");\r
++ printf ("To delete run,\n");\r
++ printf ("\n");\r
++ printf (" rm -R %s/xapian.old\n", backup_path);\r
++ printf ("\n");\r
++ }\r
++\r
++ return 0;\r
++}\r
+diff --git a/notmuch.c b/notmuch.c\r
+index 7300c21..8d303a1 100644\r
+--- a/notmuch.c\r
++++ b/notmuch.c\r
+@@ -60,6 +60,8 @@ static command_t commands[] = {\r
+ "Create a plain-text dump of the tags for each message." },\r
+ { "restore", notmuch_restore_command, FALSE,\r
+ "Restore the tags from the given dump file (see 'dump')." },\r
++ { "compact", notmuch_compact_command, FALSE,\r
++ "Compact the notmuch database." },\r
+ { "config", notmuch_config_command, FALSE,\r
+ "Get or set settings in the notmuch configuration file." },\r
+ { "help", notmuch_help_command, TRUE, /* create but don't save config */\r
+-- \r
+1.8.1.2\r
+\r