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 9B8B56DE1B72
\r
6 for <notmuch@notmuchmail.org>; Sun, 5 Apr 2015 16:00:43 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at cworth.org
\r
11 X-Spam-Status: No, score=0.585 tagged_above=-999 required=5 tests=[AWL=0.575,
\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 I7n22twWl2Oh for <notmuch@notmuchmail.org>;
\r
16 Sun, 5 Apr 2015 16:00:41 -0700 (PDT)
\r
17 Received: from mx.xen14.node3324.gplhost.com (gitolite.debian.net
\r
19 by arlo.cworth.org (Postfix) with ESMTPS id 915B96DE1B6F
\r
20 for <notmuch@notmuchmail.org>; Sun, 5 Apr 2015 16:00:41 -0700 (PDT)
\r
21 Received: from remotemail by mx.xen14.node3324.gplhost.com with local (Exim
\r
22 4.80) (envelope-from <bremner@tesseract.cs.unb.ca>)
\r
23 id 1YetWJ-0002nb-U2; Sun, 05 Apr 2015 22:59:59 +0000
\r
24 Received: (nullmailer pid 2241 invoked by uid 1000); Sun, 05 Apr 2015
\r
26 From: David Bremner <david@tethera.net>
\r
27 To: notmuch@notmuchmail.org
\r
28 Subject: [WIP2 03/12] lib: API to retrieve database revision and UUID
\r
29 Date: Mon, 6 Apr 2015 07:59:05 +0900
\r
30 Message-Id: <1428274754-1698-4-git-send-email-david@tethera.net>
\r
31 X-Mailer: git-send-email 2.1.4
\r
32 In-Reply-To: <1428274754-1698-1-git-send-email-david@tethera.net>
\r
33 References: <1428274754-1698-1-git-send-email-david@tethera.net>
\r
34 Cc: Austin Clements <aclements@csail.mit.edu>
\r
35 X-BeenThere: notmuch@notmuchmail.org
\r
36 X-Mailman-Version: 2.1.18
\r
38 List-Id: "Use and development of the notmuch mail system."
\r
39 <notmuch.notmuchmail.org>
\r
40 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
41 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
42 List-Archive: <http://notmuchmail.org/pipermail/notmuch/>
\r
43 List-Post: <mailto:notmuch@notmuchmail.org>
\r
44 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
45 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
46 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
47 X-List-Received-Date: Sun, 05 Apr 2015 23:00:43 -0000
\r
49 From: Austin Clements <aclements@csail.mit.edu>
\r
51 This exposes the committed database revision to library users along
\r
52 with a UUID that can be used to detect when revision numbers are no
\r
53 longer comparable (e.g., because the database has been replaced).
\r
55 lib/database-private.h | 1 +
\r
56 lib/database.cc | 11 +++++++++++
\r
57 lib/notmuch.h | 18 ++++++++++++++++++
\r
58 test/T570-revision-tracking.sh | 37 +++++++++++++++++++++++++++++++++++++
\r
59 4 files changed, 67 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 4378979..f88bdb3 100644
\r
76 --- a/lib/database.cc
\r
77 +++ b/lib/database.cc
\r
78 @@ -978,6 +978,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 @@ -1651,6 +1653,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 20c4e01..b6be727 100644
\r
105 --- a/lib/notmuch.h
\r
106 +++ b/lib/notmuch.h
\r
107 @@ -461,6 +461,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..8c12740
\r
136 +++ b/test/T570-revision-tracking.sh
\r
138 +#!/usr/bin/env bash
\r
139 +test_description="database revision tracking"
\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
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("revision=%d\nuuid_len=%d\n", revision, strlen (uuid));
\r
166 +cat <<'EOF' >EXPECTED
\r
172 +test_expect_equal_file OUTPUT EXPECTED
\r