--- /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 arlo.cworth.org (Postfix) with ESMTP id BC7136DE00DF\r
+ for <notmuch@notmuchmail.org>; Thu, 6 Aug 2015 03:27:06 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at cworth.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 1.251\r
+X-Spam-Level: *\r
+X-Spam-Status: No, score=1.251 tagged_above=-999 required=5 tests=[AWL=-0.145,\r
+ SPF_NEUTRAL=0.652, URIBL_SBL=0.644, URIBL_SBL_A=0.1] autolearn=disabled\r
+Received: from arlo.cworth.org ([127.0.0.1])\r
+ by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id VQhvfVQl_bYk for <notmuch@notmuchmail.org>;\r
+ Thu, 6 Aug 2015 03:27:03 -0700 (PDT)\r
+Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34])\r
+ by arlo.cworth.org (Postfix) with ESMTP id 566DD6DE00DE\r
+ for <notmuch@notmuchmail.org>; Thu, 6 Aug 2015 03:27:02 -0700 (PDT)\r
+Received: from guru.guru-group.fi (localhost [IPv6:::1])\r
+ by guru.guru-group.fi (Postfix) with ESMTP id 5486F100046;\r
+ Thu, 6 Aug 2015 13:26:51 +0300 (EEST)\r
+From: Tomi Ollila <tomi.ollila@iki.fi>\r
+To: David Bremner <david@tethera.net>, notmuch@notmuchmail.org\r
+Subject: Re: [PATCH 3/6] lib: API to retrieve database revision and UUID\r
+In-Reply-To: <1433525318-23756-4-git-send-email-david@tethera.net>\r
+References: <1432936375-astroid-4-0i1n6yczs2-1520@strange>\r
+ <1433525318-23756-1-git-send-email-david@tethera.net>\r
+ <1433525318-23756-4-git-send-email-david@tethera.net>\r
+User-Agent: Notmuch/0.20.2+42~gbf3bfb8 (http://notmuchmail.org) Emacs/24.3.1\r
+ (x86_64-unknown-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: Thu, 06 Aug 2015 13:26:51 +0300\r
+Message-ID: <m2lhdoemqc.fsf@guru.guru-group.fi>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain\r
+Cc: Austin Clements <aclements@csail.mit.edu>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.18\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: Thu, 06 Aug 2015 10:27:06 -0000\r
+\r
+On Fri, Jun 05 2015, David Bremner <david@tethera.net> wrote:\r
+\r
+> From: Austin Clements <aclements@csail.mit.edu>\r
+>\r
+> This exposes the committed database revision to library users along\r
+> with a UUID that can be used to detect when revision numbers are no\r
+> longer comparable (e.g., because the database has been replaced).\r
+> ---\r
+> lib/database-private.h | 1 +\r
+> lib/database.cc | 11 +++++++++++\r
+> lib/notmuch.h | 18 ++++++++++++++++++\r
+> test/T570-revision-tracking.sh | 37 +++++++++++++++++++++++++++++++++++++\r
+> test/test-lib.sh | 5 +++++\r
+> 5 files changed, 72 insertions(+)\r
+> create mode 100755 test/T570-revision-tracking.sh\r
+>\r
+> diff --git a/lib/database-private.h b/lib/database-private.h\r
+> index 5c5a2bb..4e93257 100644\r
+> --- a/lib/database-private.h\r
+> +++ b/lib/database-private.h\r
+> @@ -170,6 +170,7 @@ struct _notmuch_database {\r
+> * under a higher revision number, which can be generated with\r
+> * notmuch_database_new_revision. */\r
+> unsigned long revision;\r
+> + const char *uuid;\r
+> \r
+> Xapian::QueryParser *query_parser;\r
+> Xapian::TermGenerator *term_gen;\r
+> diff --git a/lib/database.cc b/lib/database.cc\r
+> index a68a487..ba8b8d9 100644\r
+> --- a/lib/database.cc\r
+> +++ b/lib/database.cc\r
+> @@ -978,6 +978,8 @@ notmuch_database_open_verbose (const char *path,\r
+> notmuch->revision = 0;\r
+> else\r
+> notmuch->revision = Xapian::sortable_unserialise (last_mod);\r
+> + notmuch->uuid = talloc_strdup (\r
+> + notmuch, notmuch->xapian_db->get_uuid ().c_str ());\r
+> \r
+> notmuch->query_parser = new Xapian::QueryParser;\r
+> notmuch->term_gen = new Xapian::TermGenerator;\r
+> @@ -1651,6 +1653,15 @@ DONE:\r
+> return NOTMUCH_STATUS_SUCCESS;\r
+> }\r
+> \r
+> +unsigned long\r
+> +notmuch_database_get_revision (notmuch_database_t *notmuch,\r
+> + const char **uuid)\r
+> +{\r
+> + if (uuid)\r
+> + *uuid = notmuch->uuid;\r
+> + return notmuch->revision;\r
+> +}\r
+> +\r
+> /* We allow the user to use arbitrarily long paths for directories. But\r
+> * we have a term-length limit. So if we exceed that, we'll use the\r
+> * SHA-1 of the path for the database term.\r
+> diff --git a/lib/notmuch.h b/lib/notmuch.h\r
+> index 20c4e01..b6be727 100644\r
+> --- a/lib/notmuch.h\r
+> +++ b/lib/notmuch.h\r
+> @@ -461,6 +461,24 @@ notmuch_status_t\r
+> notmuch_database_end_atomic (notmuch_database_t *notmuch);\r
+> \r
+> /**\r
+> + * Return the committed database revision and UUID.\r
+> + *\r
+> + * The database revision number increases monotonically with each\r
+> + * commit to the database. Hence, all messages and message changes\r
+> + * committed to the database (that is, visible to readers) have a last\r
+> + * modification revision <= the committed database revision. Any\r
+> + * messages committed in the future will be assigned a modification\r
+> + * revision > the committed database revision.\r
+> + *\r
+> + * The UUID is a NUL-terminated opaque string that uniquely identifies\r
+> + * this database. Two revision numbers are only comparable if they\r
+> + * have the same database UUID.\r
+> + */\r
+> +unsigned long\r
+> +notmuch_database_get_revision (notmuch_database_t *notmuch,\r
+> + const char **uuid);\r
+> +\r
+> +/**\r
+> * Retrieve a directory object from the database for 'path'.\r
+> *\r
+> * Here, 'path' should be a path relative to the path of 'database'\r
+> diff --git a/test/T570-revision-tracking.sh b/test/T570-revision-tracking.sh\r
+> new file mode 100755\r
+> index 0000000..74a7c49\r
+> --- /dev/null\r
+> +++ b/test/T570-revision-tracking.sh\r
+> @@ -0,0 +1,37 @@\r
+> +#!/usr/bin/env bash\r
+> +test_description="database revision tracking"\r
+> +\r
+> +. ./test-lib.sh\r
+> +\r
+> +add_email_corpus\r
+> +\r
+> +test_begin_subtest "notmuch_database_get_revision"\r
+> +test_C ${MAIL_DIR} <<'EOF'\r
+> +#include <stdio.h>\r
+> +#include <string.h>\r
+> +#include <notmuch.h>\r
+> +int main (int argc, char** argv)\r
+> +{\r
+> + notmuch_database_t *db;\r
+> + notmuch_status_t stat;\r
+> + unsigned long revision;\r
+> + const char *uuid;\r
+> +\r
+> + unsigned long rev;\r
+> +\r
+> + stat = notmuch_database_open (argv[1], NOTMUCH_DATABASE_MODE_READ_ONLY, &db);\r
+> + if (stat)\r
+> + fputs ("open failed\n", stderr);\r
+> + revision = notmuch_database_get_revision (db, &uuid);\r
+> + printf("%s\t%lu\n", uuid, revision);\r
+> +}\r
+> +EOF\r
+> +notmuch_uuid_sanitize < OUTPUT > CLEAN\r
+> +cat <<'EOF' >EXPECTED\r
+> +== stdout ==\r
+> +UUID 53\r
+> +== stderr ==\r
+> +EOF\r
+> +test_expect_equal_file EXPECTED CLEAN\r
+> +\r
+> +test_done\r
+> diff --git a/test/test-lib.sh b/test/test-lib.sh\r
+> index 23085e7..1ec6c5a 100644\r
+> --- a/test/test-lib.sh\r
+> +++ b/test/test-lib.sh\r
+> @@ -719,6 +719,11 @@ notmuch_date_sanitize ()\r
+> sed \\r
+> -e 's/^Date: Fri, 05 Jan 2001 .*0000/Date: GENERATED_DATE/'\r
+> }\r
+> +\r
+> +notmuch_uuid_sanitize ()\r
+> +{\r
+> + sed 's/^[a-f0-9][a-f0-9-]*/UUID/'\r
+> +}\r
+\r
+Pretty much good so far. Here the output in "%s\t%lu\n" is good but\r
+I am not sure whether in --count output... more of that later.\r
+\r
+notmuch_uuid_sanitize () could be more generic:\r
+\r
+notmuch_uuid_sanitize ()\r
+{\r
+ sed 's/[0-9a-f]\{8\}-[0-9a-f]\{4\}-[0-9a-f]\{4\}-[0-9a-f]\{4\}-[0-9a-f]\{12\}/UUID/g'\r
+}\r
+\r
+Oh, and `. ./test-lib.sh || exit 1` :D\r
+\r
+\r
+Tomi\r
+\r
+> # End of notmuch helper functions\r
+> \r
+> # Use test_set_prereq to tell that a particular prerequisite is available.\r
+> -- \r
+> 2.1.4\r