Re: [PATCH] lib: reword comment about XFOLDER: prefix
[notmuch-archives.git] / ec / 0d6a1c6aed34e6ead8fb66fdf42481b34c39e6
1 Return-Path: <tomi.ollila@iki.fi>\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 BC7136DE00DF\r
6  for <notmuch@notmuchmail.org>; Thu,  6 Aug 2015 03:27:06 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at cworth.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: 1.251\r
10 X-Spam-Level: *\r
11 X-Spam-Status: No, score=1.251 tagged_above=-999 required=5 tests=[AWL=-0.145,\r
12   SPF_NEUTRAL=0.652, URIBL_SBL=0.644, URIBL_SBL_A=0.1] 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 VQhvfVQl_bYk for <notmuch@notmuchmail.org>;\r
16  Thu,  6 Aug 2015 03:27:03 -0700 (PDT)\r
17 Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34])\r
18  by arlo.cworth.org (Postfix) with ESMTP id 566DD6DE00DE\r
19  for <notmuch@notmuchmail.org>; Thu,  6 Aug 2015 03:27:02 -0700 (PDT)\r
20 Received: from guru.guru-group.fi (localhost [IPv6:::1])\r
21  by guru.guru-group.fi (Postfix) with ESMTP id 5486F100046;\r
22  Thu,  6 Aug 2015 13:26:51 +0300 (EEST)\r
23 From: Tomi Ollila <tomi.ollila@iki.fi>\r
24 To: David Bremner <david@tethera.net>, notmuch@notmuchmail.org\r
25 Subject: Re: [PATCH 3/6] lib: API to retrieve database revision and UUID\r
26 In-Reply-To: <1433525318-23756-4-git-send-email-david@tethera.net>\r
27 References: <1432936375-astroid-4-0i1n6yczs2-1520@strange>\r
28  <1433525318-23756-1-git-send-email-david@tethera.net>\r
29  <1433525318-23756-4-git-send-email-david@tethera.net>\r
30 User-Agent: Notmuch/0.20.2+42~gbf3bfb8 (http://notmuchmail.org) Emacs/24.3.1\r
31  (x86_64-unknown-linux-gnu)\r
32 X-Face: HhBM'cA~<r"^Xv\KRN0P{vn'Y"Kd;zg_y3S[4)KSN~s?O\"QPoL\r
33  $[Xv_BD:i/F$WiEWax}R(MPS`^UaptOGD`*/=@\1lKoVa9tnrg0TW?"r7aRtgk[F\r
34  !)g;OY^,BjTbr)Np:%c_o'jj,Z\r
35 Date: Thu, 06 Aug 2015 13:26:51 +0300\r
36 Message-ID: <m2lhdoemqc.fsf@guru.guru-group.fi>\r
37 MIME-Version: 1.0\r
38 Content-Type: text/plain\r
39 Cc: Austin Clements <aclements@csail.mit.edu>\r
40 X-BeenThere: notmuch@notmuchmail.org\r
41 X-Mailman-Version: 2.1.18\r
42 Precedence: list\r
43 List-Id: "Use and development of the notmuch mail system."\r
44  <notmuch.notmuchmail.org>\r
45 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
46  <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
47 List-Archive: <http://notmuchmail.org/pipermail/notmuch/>\r
48 List-Post: <mailto:notmuch@notmuchmail.org>\r
49 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
50 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
51  <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
52 X-List-Received-Date: Thu, 06 Aug 2015 10:27:06 -0000\r
53 \r
54 On Fri, Jun 05 2015, David Bremner <david@tethera.net> wrote:\r
55 \r
56 > From: Austin Clements <aclements@csail.mit.edu>\r
57 >\r
58 > This exposes the committed database revision to library users along\r
59 > with a UUID that can be used to detect when revision numbers are no\r
60 > longer comparable (e.g., because the database has been replaced).\r
61 > ---\r
62 >  lib/database-private.h         |  1 +\r
63 >  lib/database.cc                | 11 +++++++++++\r
64 >  lib/notmuch.h                  | 18 ++++++++++++++++++\r
65 >  test/T570-revision-tracking.sh | 37 +++++++++++++++++++++++++++++++++++++\r
66 >  test/test-lib.sh               |  5 +++++\r
67 >  5 files changed, 72 insertions(+)\r
68 >  create mode 100755 test/T570-revision-tracking.sh\r
69 >\r
70 > diff --git a/lib/database-private.h b/lib/database-private.h\r
71 > index 5c5a2bb..4e93257 100644\r
72 > --- a/lib/database-private.h\r
73 > +++ b/lib/database-private.h\r
74 > @@ -170,6 +170,7 @@ struct _notmuch_database {\r
75 >       * under a higher revision number, which can be generated with\r
76 >       * notmuch_database_new_revision. */\r
77 >      unsigned long revision;\r
78 > +    const char *uuid;\r
79 >  \r
80 >      Xapian::QueryParser *query_parser;\r
81 >      Xapian::TermGenerator *term_gen;\r
82 > diff --git a/lib/database.cc b/lib/database.cc\r
83 > index a68a487..ba8b8d9 100644\r
84 > --- a/lib/database.cc\r
85 > +++ b/lib/database.cc\r
86 > @@ -978,6 +978,8 @@ notmuch_database_open_verbose (const char *path,\r
87 >           notmuch->revision = 0;\r
88 >       else\r
89 >           notmuch->revision = Xapian::sortable_unserialise (last_mod);\r
90 > +     notmuch->uuid = talloc_strdup (\r
91 > +         notmuch, notmuch->xapian_db->get_uuid ().c_str ());\r
92 >  \r
93 >       notmuch->query_parser = new Xapian::QueryParser;\r
94 >       notmuch->term_gen = new Xapian::TermGenerator;\r
95 > @@ -1651,6 +1653,15 @@ DONE:\r
96 >      return NOTMUCH_STATUS_SUCCESS;\r
97 >  }\r
98 >  \r
99 > +unsigned long\r
100 > +notmuch_database_get_revision (notmuch_database_t *notmuch,\r
101 > +                             const char **uuid)\r
102 > +{\r
103 > +    if (uuid)\r
104 > +     *uuid = notmuch->uuid;\r
105 > +    return notmuch->revision;\r
106 > +}\r
107 > +\r
108 >  /* We allow the user to use arbitrarily long paths for directories. But\r
109 >   * we have a term-length limit. So if we exceed that, we'll use the\r
110 >   * SHA-1 of the path for the database term.\r
111 > diff --git a/lib/notmuch.h b/lib/notmuch.h\r
112 > index 20c4e01..b6be727 100644\r
113 > --- a/lib/notmuch.h\r
114 > +++ b/lib/notmuch.h\r
115 > @@ -461,6 +461,24 @@ notmuch_status_t\r
116 >  notmuch_database_end_atomic (notmuch_database_t *notmuch);\r
117 >  \r
118 >  /**\r
119 > + * Return the committed database revision and UUID.\r
120 > + *\r
121 > + * The database revision number increases monotonically with each\r
122 > + * commit to the database.  Hence, all messages and message changes\r
123 > + * committed to the database (that is, visible to readers) have a last\r
124 > + * modification revision <= the committed database revision.  Any\r
125 > + * messages committed in the future will be assigned a modification\r
126 > + * revision > the committed database revision.\r
127 > + *\r
128 > + * The UUID is a NUL-terminated opaque string that uniquely identifies\r
129 > + * this database.  Two revision numbers are only comparable if they\r
130 > + * have the same database UUID.\r
131 > + */\r
132 > +unsigned long\r
133 > +notmuch_database_get_revision (notmuch_database_t *notmuch,\r
134 > +                             const char **uuid);\r
135 > +\r
136 > +/**\r
137 >   * Retrieve a directory object from the database for 'path'.\r
138 >   *\r
139 >   * Here, 'path' should be a path relative to the path of 'database'\r
140 > diff --git a/test/T570-revision-tracking.sh b/test/T570-revision-tracking.sh\r
141 > new file mode 100755\r
142 > index 0000000..74a7c49\r
143 > --- /dev/null\r
144 > +++ b/test/T570-revision-tracking.sh\r
145 > @@ -0,0 +1,37 @@\r
146 > +#!/usr/bin/env bash\r
147 > +test_description="database revision tracking"\r
148 > +\r
149 > +. ./test-lib.sh\r
150 > +\r
151 > +add_email_corpus\r
152 > +\r
153 > +test_begin_subtest "notmuch_database_get_revision"\r
154 > +test_C ${MAIL_DIR} <<'EOF'\r
155 > +#include <stdio.h>\r
156 > +#include <string.h>\r
157 > +#include <notmuch.h>\r
158 > +int main (int argc, char** argv)\r
159 > +{\r
160 > +   notmuch_database_t *db;\r
161 > +   notmuch_status_t stat;\r
162 > +   unsigned long revision;\r
163 > +   const char *uuid;\r
164 > +\r
165 > +   unsigned long rev;\r
166 > +\r
167 > +   stat = notmuch_database_open (argv[1], NOTMUCH_DATABASE_MODE_READ_ONLY, &db);\r
168 > +   if (stat)\r
169 > +       fputs ("open failed\n", stderr);\r
170 > +   revision = notmuch_database_get_revision (db, &uuid);\r
171 > +   printf("%s\t%lu\n", uuid, revision);\r
172 > +}\r
173 > +EOF\r
174 > +notmuch_uuid_sanitize < OUTPUT > CLEAN\r
175 > +cat <<'EOF' >EXPECTED\r
176 > +== stdout ==\r
177 > +UUID 53\r
178 > +== stderr ==\r
179 > +EOF\r
180 > +test_expect_equal_file EXPECTED CLEAN\r
181 > +\r
182 > +test_done\r
183 > diff --git a/test/test-lib.sh b/test/test-lib.sh\r
184 > index 23085e7..1ec6c5a 100644\r
185 > --- a/test/test-lib.sh\r
186 > +++ b/test/test-lib.sh\r
187 > @@ -719,6 +719,11 @@ notmuch_date_sanitize ()\r
188 >      sed \\r
189 >       -e 's/^Date: Fri, 05 Jan 2001 .*0000/Date: GENERATED_DATE/'\r
190 >  }\r
191 > +\r
192 > +notmuch_uuid_sanitize ()\r
193 > +{\r
194 > +    sed  's/^[a-f0-9][a-f0-9-]*/UUID/'\r
195 > +}\r
196 \r
197 Pretty much good so far. Here the output in "%s\t%lu\n" is good but\r
198 I am not sure whether in --count output... more of that later.\r
199 \r
200 notmuch_uuid_sanitize () could be more generic:\r
201 \r
202 notmuch_uuid_sanitize ()\r
203 {\r
204     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
205 }\r
206 \r
207 Oh, and `. ./test-lib.sh || exit 1` :D\r
208 \r
209 \r
210 Tomi\r
211 \r
212 >  # End of notmuch helper functions\r
213 >  \r
214 >  # Use test_set_prereq to tell that a particular prerequisite is available.\r
215 > -- \r
216 > 2.1.4\r