1 Return-Path: <bremner@tesseract.cs.unb.ca>
\r
2 X-Original-To: notmuch@notmuchmail.org
\r
3 Delivered-To: notmuch@notmuchmail.org
\r
4 Received: from localhost (localhost [127.0.0.1])
\r
5 by arlo.cworth.org (Postfix) with ESMTP id 2A8E96DE1654
\r
6 for <notmuch@notmuchmail.org>; Sun, 9 Aug 2015 02:26:00 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at cworth.org
\r
11 X-Spam-Status: No, score=0.141 tagged_above=-999 required=5 tests=[AWL=0.131,
\r
12 T_HEADER_FROM_DIFFERENT_DOMAINS=0.01] autolearn=disabled
\r
13 Received: from arlo.cworth.org ([127.0.0.1])
\r
14 by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)
\r
15 with ESMTP id CWoOsZkh87qr for <notmuch@notmuchmail.org>;
\r
16 Sun, 9 Aug 2015 02:25:58 -0700 (PDT)
\r
17 Received: from gitolite.debian.net (gitolite.debian.net [87.98.215.224])
\r
18 by arlo.cworth.org (Postfix) with ESMTPS id 38D896DE02D2
\r
19 for <notmuch@notmuchmail.org>; Sun, 9 Aug 2015 02:25:58 -0700 (PDT)
\r
20 Received: from remotemail by gitolite.debian.net with local (Exim 4.80)
\r
21 (envelope-from <bremner@tesseract.cs.unb.ca>)
\r
22 id 1ZOMqy-0005W1-7R; Sun, 09 Aug 2015 09:25:16 +0000
\r
23 Received: (nullmailer pid 7063 invoked by uid 1000); Sun, 09 Aug 2015
\r
25 From: David Bremner <david@tethera.net>
\r
26 To: notmuch@notmuchmail.org
\r
27 Subject: [PATCH 2/5] lib: API to retrieve database revision and UUID
\r
28 Date: Sun, 9 Aug 2015 11:24:42 +0200
\r
29 Message-Id: <1439112285-6681-3-git-send-email-david@tethera.net>
\r
30 X-Mailer: git-send-email 2.1.4
\r
31 In-Reply-To: <1439112285-6681-1-git-send-email-david@tethera.net>
\r
32 References: <1439112285-6681-1-git-send-email-david@tethera.net>
\r
33 Cc: Austin Clements <aclements@csail.mit.edu>
\r
34 X-BeenThere: notmuch@notmuchmail.org
\r
35 X-Mailman-Version: 2.1.18
\r
37 List-Id: "Use and development of the notmuch mail system."
\r
38 <notmuch.notmuchmail.org>
\r
39 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
40 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
41 List-Archive: <http://notmuchmail.org/pipermail/notmuch/>
\r
42 List-Post: <mailto:notmuch@notmuchmail.org>
\r
43 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
44 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
45 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
46 X-List-Received-Date: Sun, 09 Aug 2015 09:26:00 -0000
\r
48 From: Austin Clements <aclements@csail.mit.edu>
\r
50 This exposes the committed database revision to library users along
\r
51 with a UUID that can be used to detect when revision numbers are no
\r
52 longer comparable (e.g., because the database has been replaced).
\r
54 lib/database-private.h | 1 +
\r
55 lib/database.cc | 11 +++++++++++
\r
56 lib/notmuch.h | 18 ++++++++++++++++++
\r
57 test/T570-revision-tracking.sh | 37 +++++++++++++++++++++++++++++++++++++
\r
58 test/test-lib.sh | 5 +++++
\r
59 5 files changed, 72 insertions(+)
\r
60 create mode 100755 test/T570-revision-tracking.sh
\r
62 diff --git a/lib/database-private.h b/lib/database-private.h
\r
63 index 5c5a2bb..4e93257 100644
\r
64 --- a/lib/database-private.h
\r
65 +++ b/lib/database-private.h
\r
66 @@ -170,6 +170,7 @@ struct _notmuch_database {
\r
67 * under a higher revision number, which can be generated with
\r
68 * notmuch_database_new_revision. */
\r
69 unsigned long revision;
\r
72 Xapian::QueryParser *query_parser;
\r
73 Xapian::TermGenerator *term_gen;
\r
74 diff --git a/lib/database.cc b/lib/database.cc
\r
75 index 52e2e8f..fc78769 100644
\r
76 --- a/lib/database.cc
\r
77 +++ b/lib/database.cc
\r
78 @@ -992,6 +992,8 @@ notmuch_database_open_verbose (const char *path,
\r
79 notmuch->revision = 0;
\r
81 notmuch->revision = Xapian::sortable_unserialise (last_mod);
\r
82 + notmuch->uuid = talloc_strdup (
\r
83 + notmuch, notmuch->xapian_db->get_uuid ().c_str ());
\r
85 notmuch->query_parser = new Xapian::QueryParser;
\r
86 notmuch->term_gen = new Xapian::TermGenerator;
\r
87 @@ -1666,6 +1668,15 @@ DONE:
\r
88 return NOTMUCH_STATUS_SUCCESS;
\r
92 +notmuch_database_get_revision (notmuch_database_t *notmuch,
\r
93 + const char **uuid)
\r
96 + *uuid = notmuch->uuid;
\r
97 + return notmuch->revision;
\r
100 /* We allow the user to use arbitrarily long paths for directories. But
\r
101 * we have a term-length limit. So if we exceed that, we'll use the
\r
102 * SHA-1 of the path for the database term.
\r
103 diff --git a/lib/notmuch.h b/lib/notmuch.h
\r
104 index 421c19d..a7ac012 100644
\r
105 --- a/lib/notmuch.h
\r
106 +++ b/lib/notmuch.h
\r
107 @@ -468,6 +468,24 @@ notmuch_status_t
\r
108 notmuch_database_end_atomic (notmuch_database_t *notmuch);
\r
111 + * Return the committed database revision and UUID.
\r
113 + * The database revision number increases monotonically with each
\r
114 + * commit to the database. Hence, all messages and message changes
\r
115 + * committed to the database (that is, visible to readers) have a last
\r
116 + * modification revision <= the committed database revision. Any
\r
117 + * messages committed in the future will be assigned a modification
\r
118 + * revision > the committed database revision.
\r
120 + * The UUID is a NUL-terminated opaque string that uniquely identifies
\r
121 + * this database. Two revision numbers are only comparable if they
\r
122 + * have the same database UUID.
\r
125 +notmuch_database_get_revision (notmuch_database_t *notmuch,
\r
126 + const char **uuid);
\r
129 * Retrieve a directory object from the database for 'path'.
\r
131 * Here, 'path' should be a path relative to the path of 'database'
\r
132 diff --git a/test/T570-revision-tracking.sh b/test/T570-revision-tracking.sh
\r
133 new file mode 100755
\r
134 index 0000000..e0a5703
\r
136 +++ b/test/T570-revision-tracking.sh
\r
138 +#!/usr/bin/env bash
\r
139 +test_description="database revision tracking"
\r
141 +. ./test-lib.sh || exit 1
\r
145 +test_begin_subtest "notmuch_database_get_revision"
\r
146 +test_C ${MAIL_DIR} <<'EOF'
\r
147 +#include <stdio.h>
\r
148 +#include <string.h>
\r
149 +#include <notmuch.h>
\r
150 +int main (int argc, char** argv)
\r
152 + notmuch_database_t *db;
\r
153 + notmuch_status_t stat;
\r
154 + unsigned long revision;
\r
155 + const char *uuid;
\r
157 + unsigned long rev;
\r
159 + stat = notmuch_database_open (argv[1], NOTMUCH_DATABASE_MODE_READ_ONLY, &db);
\r
161 + fputs ("open failed\n", stderr);
\r
162 + revision = notmuch_database_get_revision (db, &uuid);
\r
163 + printf("%s\t%lu\n", uuid, revision);
\r
166 +notmuch_uuid_sanitize < OUTPUT > CLEAN
\r
167 +cat <<'EOF' >EXPECTED
\r
172 +test_expect_equal_file EXPECTED CLEAN
\r
175 diff --git a/test/test-lib.sh b/test/test-lib.sh
\r
176 index 0bf7163..126911f 100644
\r
177 --- a/test/test-lib.sh
\r
178 +++ b/test/test-lib.sh
\r
179 @@ -720,6 +720,11 @@ notmuch_date_sanitize ()
\r
181 -e 's/^Date: Fri, 05 Jan 2001 .*0000/Date: GENERATED_DATE/'
\r
184 +notmuch_uuid_sanitize ()
\r
186 + 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
188 # End of notmuch helper functions
\r
190 # Use test_set_prereq to tell that a particular prerequisite is available.
\r