"snoozing" with notmuch?
[notmuch-archives.git] / 0b / 805168aa99438b362e1d6de3cdb2321d99bc22
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 B28BF6DE1749\r
6  for <notmuch@notmuchmail.org>; Fri,  5 Jun 2015 10:30:26 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at cworth.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: 0.241\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0.241 tagged_above=-999 required=5 tests=[AWL=0.231, \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 eU4SwRI5xFYP for <notmuch@notmuchmail.org>;\r
16  Fri,  5 Jun 2015 10:30:20 -0700 (PDT)\r
17 Received: from mx.xen14.node3324.gplhost.com (gitolite.debian.net\r
18  [87.98.215.224])\r
19  by arlo.cworth.org (Postfix) with ESMTPS id 0DA6E6DE1617\r
20  for <notmuch@notmuchmail.org>; Fri,  5 Jun 2015 10:30:20 -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 1Z0vR3-0002ng-RE; Fri, 05 Jun 2015 17:29:37 +0000\r
24 Received: (nullmailer pid 24252 invoked by uid 1000); Fri, 05 Jun 2015\r
25  17:28:42 -0000\r
26 From: David Bremner <david@tethera.net>\r
27 To: notmuch@notmuchmail.org\r
28 Subject: [PATCH 3/6] lib: API to retrieve database revision and UUID\r
29 Date: Fri,  5 Jun 2015 19:28:35 +0200\r
30 Message-Id: <1433525318-23756-4-git-send-email-david@tethera.net>\r
31 X-Mailer: git-send-email 2.1.4\r
32 In-Reply-To: <1433525318-23756-1-git-send-email-david@tethera.net>\r
33 References: <1432936375-astroid-4-0i1n6yczs2-1520@strange>\r
34  <1433525318-23756-1-git-send-email-david@tethera.net>\r
35 Cc: Austin Clements <aclements@csail.mit.edu>\r
36 X-BeenThere: notmuch@notmuchmail.org\r
37 X-Mailman-Version: 2.1.18\r
38 Precedence: list\r
39 List-Id: "Use and development of the notmuch mail system."\r
40  <notmuch.notmuchmail.org>\r
41 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
42  <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
43 List-Archive: <http://notmuchmail.org/pipermail/notmuch/>\r
44 List-Post: <mailto:notmuch@notmuchmail.org>\r
45 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
46 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
47  <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
48 X-List-Received-Date: Fri, 05 Jun 2015 17:30:26 -0000\r
49 \r
50 From: Austin Clements <aclements@csail.mit.edu>\r
51 \r
52 This exposes the committed database revision to library users along\r
53 with a UUID that can be used to detect when revision numbers are no\r
54 longer comparable (e.g., because the database has been replaced).\r
55 ---\r
56  lib/database-private.h         |  1 +\r
57  lib/database.cc                | 11 +++++++++++\r
58  lib/notmuch.h                  | 18 ++++++++++++++++++\r
59  test/T570-revision-tracking.sh | 37 +++++++++++++++++++++++++++++++++++++\r
60  test/test-lib.sh               |  5 +++++\r
61  5 files changed, 72 insertions(+)\r
62  create mode 100755 test/T570-revision-tracking.sh\r
63 \r
64 diff --git a/lib/database-private.h b/lib/database-private.h\r
65 index 5c5a2bb..4e93257 100644\r
66 --- a/lib/database-private.h\r
67 +++ b/lib/database-private.h\r
68 @@ -170,6 +170,7 @@ struct _notmuch_database {\r
69       * under a higher revision number, which can be generated with\r
70       * notmuch_database_new_revision. */\r
71      unsigned long revision;\r
72 +    const char *uuid;\r
73  \r
74      Xapian::QueryParser *query_parser;\r
75      Xapian::TermGenerator *term_gen;\r
76 diff --git a/lib/database.cc b/lib/database.cc\r
77 index a68a487..ba8b8d9 100644\r
78 --- a/lib/database.cc\r
79 +++ b/lib/database.cc\r
80 @@ -978,6 +978,8 @@ notmuch_database_open_verbose (const char *path,\r
81             notmuch->revision = 0;\r
82         else\r
83             notmuch->revision = Xapian::sortable_unserialise (last_mod);\r
84 +       notmuch->uuid = talloc_strdup (\r
85 +           notmuch, notmuch->xapian_db->get_uuid ().c_str ());\r
86  \r
87         notmuch->query_parser = new Xapian::QueryParser;\r
88         notmuch->term_gen = new Xapian::TermGenerator;\r
89 @@ -1651,6 +1653,15 @@ DONE:\r
90      return NOTMUCH_STATUS_SUCCESS;\r
91  }\r
92  \r
93 +unsigned long\r
94 +notmuch_database_get_revision (notmuch_database_t *notmuch,\r
95 +                               const char **uuid)\r
96 +{\r
97 +    if (uuid)\r
98 +       *uuid = notmuch->uuid;\r
99 +    return notmuch->revision;\r
100 +}\r
101 +\r
102  /* We allow the user to use arbitrarily long paths for directories. But\r
103   * we have a term-length limit. So if we exceed that, we'll use the\r
104   * SHA-1 of the path for the database term.\r
105 diff --git a/lib/notmuch.h b/lib/notmuch.h\r
106 index 20c4e01..b6be727 100644\r
107 --- a/lib/notmuch.h\r
108 +++ b/lib/notmuch.h\r
109 @@ -461,6 +461,24 @@ notmuch_status_t\r
110  notmuch_database_end_atomic (notmuch_database_t *notmuch);\r
111  \r
112  /**\r
113 + * Return the committed database revision and UUID.\r
114 + *\r
115 + * The database revision number increases monotonically with each\r
116 + * commit to the database.  Hence, all messages and message changes\r
117 + * committed to the database (that is, visible to readers) have a last\r
118 + * modification revision <= the committed database revision.  Any\r
119 + * messages committed in the future will be assigned a modification\r
120 + * revision > the committed database revision.\r
121 + *\r
122 + * The UUID is a NUL-terminated opaque string that uniquely identifies\r
123 + * this database.  Two revision numbers are only comparable if they\r
124 + * have the same database UUID.\r
125 + */\r
126 +unsigned long\r
127 +notmuch_database_get_revision (notmuch_database_t *notmuch,\r
128 +                               const char **uuid);\r
129 +\r
130 +/**\r
131   * Retrieve a directory object from the database for 'path'.\r
132   *\r
133   * Here, 'path' should be a path relative to the path of 'database'\r
134 diff --git a/test/T570-revision-tracking.sh b/test/T570-revision-tracking.sh\r
135 new file mode 100755\r
136 index 0000000..74a7c49\r
137 --- /dev/null\r
138 +++ b/test/T570-revision-tracking.sh\r
139 @@ -0,0 +1,37 @@\r
140 +#!/usr/bin/env bash\r
141 +test_description="database revision tracking"\r
142 +\r
143 +. ./test-lib.sh\r
144 +\r
145 +add_email_corpus\r
146 +\r
147 +test_begin_subtest "notmuch_database_get_revision"\r
148 +test_C ${MAIL_DIR} <<'EOF'\r
149 +#include <stdio.h>\r
150 +#include <string.h>\r
151 +#include <notmuch.h>\r
152 +int main (int argc, char** argv)\r
153 +{\r
154 +   notmuch_database_t *db;\r
155 +   notmuch_status_t stat;\r
156 +   unsigned long revision;\r
157 +   const char *uuid;\r
158 +\r
159 +   unsigned long rev;\r
160 +\r
161 +   stat = notmuch_database_open (argv[1], NOTMUCH_DATABASE_MODE_READ_ONLY, &db);\r
162 +   if (stat)\r
163 +       fputs ("open failed\n", stderr);\r
164 +   revision = notmuch_database_get_revision (db, &uuid);\r
165 +   printf("%s\t%lu\n", uuid, revision);\r
166 +}\r
167 +EOF\r
168 +notmuch_uuid_sanitize < OUTPUT > CLEAN\r
169 +cat <<'EOF' >EXPECTED\r
170 +== stdout ==\r
171 +UUID   53\r
172 +== stderr ==\r
173 +EOF\r
174 +test_expect_equal_file EXPECTED CLEAN\r
175 +\r
176 +test_done\r
177 diff --git a/test/test-lib.sh b/test/test-lib.sh\r
178 index 23085e7..1ec6c5a 100644\r
179 --- a/test/test-lib.sh\r
180 +++ b/test/test-lib.sh\r
181 @@ -719,6 +719,11 @@ notmuch_date_sanitize ()\r
182      sed \\r
183         -e 's/^Date: Fri, 05 Jan 2001 .*0000/Date: GENERATED_DATE/'\r
184  }\r
185 +\r
186 +notmuch_uuid_sanitize ()\r
187 +{\r
188 +    sed  's/^[a-f0-9][a-f0-9-]*/UUID/'\r
189 +}\r
190  # End of notmuch helper functions\r
191  \r
192  # Use test_set_prereq to tell that a particular prerequisite is available.\r
193 -- \r
194 2.1.4\r
195 \r