--- /dev/null
+Return-Path: <tomi.ollila@iki.fi>\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 4483D431FB6\r
+ for <notmuch@notmuchmail.org>; Tue, 21 Aug 2012 00:35:08 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
+ 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 wQu4IE9wGVsi for <notmuch@notmuchmail.org>;\r
+ Tue, 21 Aug 2012 00:35:07 -0700 (PDT)\r
+Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34])\r
+ by olra.theworths.org (Postfix) with ESMTP id 0C613431FAE\r
+ for <notmuch@notmuchmail.org>; Tue, 21 Aug 2012 00:35:07 -0700 (PDT)\r
+Received: by guru.guru-group.fi (Postfix, from userid 501)\r
+ id 9CE1C100386; Tue, 21 Aug 2012 10:35:14 +0300 (EEST)\r
+From: Tomi Ollila <tomi.ollila@iki.fi>\r
+To: Ben Gamari <bgamari.foss@gmail.com>, notmuch@notmuchmail.org\r
+Subject: Re: [PATCH 1/3] Add notmuch_database_close_compact\r
+In-Reply-To: <1345476704-17091-2-git-send-email-bgamari.foss@gmail.com>\r
+References: <1345476704-17091-1-git-send-email-bgamari.foss@gmail.com>\r
+ <1345476704-17091-2-git-send-email-bgamari.foss@gmail.com>\r
+User-Agent: Notmuch/0.13.2+128~g2eb637a (http://notmuchmail.org) Emacs/23.1.1\r
+ (x86_64-redhat-linux-gnu)\r
+X-Face: HhBM'cA~<r"^Xv\KRN0P{vn'Y"Kd;zg_y3S[4)KSN~s?O\"QPoL\r
+ $[Xv_BD:i/F$WiEWax}R(MPS`^UaptOGD`*/=@\1lKoVa9tnrg0TW?"r7aRtgk[F\r
+ !)g;OY^,BjTbr)Np:%c_o'jj,Z\r
+Date: Tue, 21 Aug 2012 10:35:14 +0300\r
+Message-ID: <m27gssitot.fsf@guru.guru-group.fi>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=us-ascii\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: Tue, 21 Aug 2012 07:35:08 -0000\r
+\r
+On Mon, Aug 20 2012, Ben Gamari <bgamari.foss@gmail.com> wrote:\r
+\r
+> ---\r
+> configure | 25 ++++++++++++++++++++++++-\r
+> lib/database.cc | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++\r
+> lib/notmuch.h | 14 ++++++++++++++\r
+> 3 files changed, 92 insertions(+), 1 deletion(-)\r
+>\r
+> diff --git a/configure b/configure\r
+> index dc0dba4..370fedd 100755\r
+> --- a/configure\r
+> +++ b/configure\r
+> @@ -270,7 +270,8 @@ printf "Checking for Xapian development files... "\r
+> have_xapian=0\r
+> for xapian_config in ${XAPIAN_CONFIG}; do\r
+> if ${xapian_config} --version > /dev/null 2>&1; then\r
+> - printf "Yes (%s).\n" $(${xapian_config} --version | sed -e 's/.* //')\r
+> + xapian_version=$(${xapian_config} --version | sed -e 's/.* //')\r
+> + printf "Yes (%s).\n" ${xapian_version}\r
+> have_xapian=1\r
+> xapian_cxxflags=$(${xapian_config} --cxxflags)\r
+> xapian_ldflags=$(${xapian_config} --libs)\r
+> @@ -282,6 +283,24 @@ if [ ${have_xapian} = "0" ]; then\r
+> errors=$((errors + 1))\r
+> fi\r
+> \r
+> +have_xapian_compact=0\r
+> +if [ ${have_xapian} = "1" ]; then\r
+> + printf "Checking for Xapian compact support... "\r
+> + IFS='.'\r
+> + old_args=$@\r
+> + set -- ${xapian_version}\r
+> + xapian_major_version=$1\r
+> + xapian_minor_version=$2\r
+> + xapian_subminor_version=$3\r
+> + set -- ${old_args}\r
+\r
+The part above breaks the argument vector in case there are spaces in \r
+args (I though $IFS chars, but try the script), execute:\r
+\r
+$ echo '#!/bin/bash\r
+IFS=.\r
+for x in "$@"; do echo $x; done; echo\r
+foo=$@\r
+for x in $foo; do echo $x; done; echo\r
+set -- $foo\r
+for x in "$@"; do echo $x; done; echo\r
+' > foo.bash\r
+\r
+$ bash foo.bash a "b c" d\r
+\r
+Also, after processing, IFS is not restored (to $DEFAULT_IFS)\r
+\r
+an alternative is to put the code in function like the following\r
+way:\r
+\r
+set_xapian_version ()\r
+{\r
+ xapian_major_version=$1\r
+ xapian_minor_version=$2\r
+ xapian_subminor_version=$3\r
+}\r
+\r
+have_xapian_compact=0\r
+if [ ${have_xapian} = "1" ]; then\r
+ printf "Checking for Xapian compact support... "\r
+ IFS=.\r
+ set_xapian_version ${xapian_version}\r
+ IFS=$DEFAULT_IFS\r
+ if [ "${xapian_major_version}" -gt 1 ] || [ ${xapian_minor_version} -gt 2 ] || [ ${xapian_subminor_version} -ge 6 ]; then\r
+ printf "Yes.\n"\r
+ have_xapian_compact=1\r
+ else\r
+ printf "No.\n"\r
+ fi\r
+fi\r
+\r
+Hmm, I guess the check above is to determine whether xapian version is\r
+1.2.6 or newer, but is there xapian version 1.1.6 or 1.0.6 or 0.3.0 or so ?\r
+\r
+I am not qualified to comment about compaction itself :)\r
+\r
+In the last patch you give copyright to Carl (which is OK). However I'd\r
+debate whether it is good practise to declare Carl as author; I'd say that\r
+is OK if he agrees to claim authorship to your potentially shi^H^H^Hperfect\r
+code ;)\r
+\r
+There are at least a few style issues below: e.g. no space between function\r
+name and opening parenthesis.\r
+\r
+Tomi\r
+\r
+\r
+> + if [ "${xapian_major_version}" -gt 1 ] || [ ${xapian_minor_version} -gt 2 ] || [ ${xapian_subminor_version} -ge 6 ]; then\r
+> + printf "Yes.\n"\r
+> + have_xapian_compact=1\r
+> + else\r
+> + printf "No.\n"\r
+> + fi\r
+> +fi\r
+> +\r
+> printf "Checking for GMime development files... "\r
+> have_gmime=0\r
+> IFS=';'\r
+> @@ -675,6 +694,9 @@ LINKER_RESOLVES_LIBRARY_DEPENDENCIES = ${linker_resolves_library_dependencies}\r
+> XAPIAN_CXXFLAGS = ${xapian_cxxflags}\r
+> XAPIAN_LDFLAGS = ${xapian_ldflags}\r
+> \r
+> +# Whether compact is supported by this version of Xapian\r
+> +HAVE_XAPIAN_COMPACT = ${have_xapian_compact}\r
+> +\r
+> # Flags needed to compile and link against GMime-2.4\r
+> GMIME_CFLAGS = ${gmime_cflags}\r
+> GMIME_LDFLAGS = ${gmime_ldflags}\r
+> @@ -711,6 +733,7 @@ CONFIGURE_CFLAGS = -DHAVE_GETLINE=\$(HAVE_GETLINE) \$(GMIME_CFLAGS) \\\r
+> CONFIGURE_CXXFLAGS = -DHAVE_GETLINE=\$(HAVE_GETLINE) \$(GMIME_CFLAGS) \\\r
+> \$(TALLOC_CFLAGS) -DHAVE_VALGRIND=\$(HAVE_VALGRIND) \\\r
+> \$(VALGRIND_CFLAGS) \$(XAPIAN_CXXFLAGS) \\\r
+> + -DHAVE_XAPIAN_COMPACT=\$(HAVE_XAPIAN_COMPACT) \\\r
+> -DHAVE_STRCASESTR=\$(HAVE_STRCASESTR)\r
+> CONFIGURE_LDFLAGS = \$(GMIME_LDFLAGS) \$(TALLOC_LDFLAGS) \$(XAPIAN_LDFLAGS)\r
+> EOF\r
+> diff --git a/lib/database.cc b/lib/database.cc\r
+> index 761dc1a..6e83a61 100644\r
+> --- a/lib/database.cc\r
+> +++ b/lib/database.cc\r
+> @@ -781,6 +781,60 @@ notmuch_database_close (notmuch_database_t *notmuch)\r
+> }\r
+> \r
+> void\r
+> +notmuch_database_close_compact (notmuch_database_t *notmuch)\r
+> +{\r
+> + void *local = talloc_new (NULL);\r
+> + Xapian::Compactor compactor;\r
+> + char *notmuch_path, *xapian_path, *compact_xapian_path, *old_xapian_path;\r
+> +\r
+> +#if HAVE_XAPIAN_COMPACT\r
+> + if (! (notmuch_path = talloc_asprintf (local, "%s/%s", notmuch->path, ".notmuch"))) {\r
+> + fprintf (stderr, "Out of memory\n");\r
+> + goto DONE;\r
+> + }\r
+> +\r
+> + if (! (xapian_path = talloc_asprintf (local, "%s/%s", notmuch_path, "xapian"))) {\r
+> + fprintf (stderr, "Out of memory\n");\r
+> + goto DONE;\r
+> + }\r
+> +\r
+> + if (! (compact_xapian_path = talloc_asprintf (local, "%s.compact", xapian_path))) {\r
+> + fprintf (stderr, "Out of memory\n");\r
+> + goto DONE;\r
+> + }\r
+> +\r
+> + if (! (old_xapian_path = talloc_asprintf (local, "%s.old", xapian_path))) {\r
+> + fprintf (stderr, "Out of memory\n");\r
+> + goto DONE;\r
+> + }\r
+> +\r
+> + try {\r
+> + compactor.set_renumber(false);\r
+> + compactor.add_source(xapian_path);\r
+> + compactor.set_destdir(compact_xapian_path);\r
+> + compactor.compact();\r
+> +\r
+> + if (rename(xapian_path, old_xapian_path)) {\r
+> + fprintf (stderr, "Error moving old database out of the way\n");\r
+> + goto DONE;\r
+> + }\r
+> +\r
+> + if (rename(compact_xapian_path, xapian_path)) {\r
+> + fprintf (stderr, "Error moving compacted database\n");\r
+> + goto DONE;\r
+> + }\r
+> + } catch (Xapian::InvalidArgumentError e) {\r
+> + fprintf (stderr, "Error while compacting: %s", e.get_msg().c_str());\r
+> + }\r
+> + \r
+> +#endif\r
+> +\r
+> + notmuch_database_close(notmuch);\r
+> +DONE:\r
+> + talloc_free(local);\r
+> +}\r
+> +\r
+> +void\r
+> notmuch_database_destroy (notmuch_database_t *notmuch)\r
+> {\r
+> notmuch_database_close (notmuch);\r
+> diff --git a/lib/notmuch.h b/lib/notmuch.h\r
+> index 3633bed..50babfb 100644\r
+> --- a/lib/notmuch.h\r
+> +++ b/lib/notmuch.h\r
+> @@ -215,6 +215,20 @@ notmuch_database_open (const char *path,\r
+> void\r
+> notmuch_database_close (notmuch_database_t *database);\r
+> \r
+> +/* Close the given notmuch database and then compact it.\r
+> + *\r
+> + * After notmuch_database_close_compact has been called, calls to\r
+> + * other functions on objects derived from this database may either\r
+> + * behave as if the database had not been closed (e.g., if the\r
+> + * required data has been cached) or may fail with a\r
+> + * NOTMUCH_STATUS_XAPIAN_EXCEPTION.\r
+> + *\r
+> + * notmuch_database_close_compact can be called multiple times. Later\r
+> + * calls have no effect.\r
+> + */\r
+> +void\r
+> +notmuch_database_close_compact (notmuch_database_t *notmuch);\r
+> +\r
+> /* Destroy the notmuch database, closing it if necessary and freeing\r
+> * all associated resources. */\r
+> void\r
+> -- \r
+> 1.7.9.5\r
+>\r
+> _______________________________________________\r
+> notmuch mailing list\r
+> notmuch@notmuchmail.org\r
+> http://notmuchmail.org/mailman/listinfo/notmuch\r