Re: [PATCH 1/2] Add Google Inc. to AUTHORS as a contributor.
[notmuch-archives.git] / c5 / 1d9eed1c924c7e0554e7d46a4ae3b63677a217
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 olra.theworths.org (Postfix) with ESMTP id E226E431FC2\r
6         for <notmuch@notmuchmail.org>; Wed, 17 Oct 2012 23:44:02 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: 0\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
12         autolearn=disabled\r
13 Received: from olra.theworths.org ([127.0.0.1])\r
14         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
15         with ESMTP id BsfIFA5JngjT for <notmuch@notmuchmail.org>;\r
16         Wed, 17 Oct 2012 23:44:01 -0700 (PDT)\r
17 Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34])\r
18         by olra.theworths.org (Postfix) with ESMTP id 7ADBD431FB6\r
19         for <notmuch@notmuchmail.org>; Wed, 17 Oct 2012 23:44:01 -0700 (PDT)\r
20 Received: from guru.guru-group.fi (localhost [IPv6:::1])\r
21         by guru.guru-group.fi (Postfix) with ESMTP id B7D8B1000E5;\r
22         Thu, 18 Oct 2012 09:44:04 +0300 (EEST)\r
23 From: Tomi Ollila <tomi.ollila@iki.fi>\r
24 To: Ben Gamari <bgamari.foss@gmail.com>, notmuch@notmuchmail.org\r
25 Subject: Re: [PATCH 1/3] Add notmuch_database_close_compact\r
26 In-Reply-To: <1350487737-32058-2-git-send-email-bgamari.foss@gmail.com>\r
27 References: <1350487737-32058-1-git-send-email-bgamari.foss@gmail.com>\r
28         <1350487737-32058-2-git-send-email-bgamari.foss@gmail.com>\r
29 User-Agent: Notmuch/0.14+51~g62cd13b (http://notmuchmail.org) Emacs/24.2.1\r
30         (x86_64-unknown-linux-gnu)\r
31 X-Face: HhBM'cA~<r"^Xv\KRN0P{vn'Y"Kd;zg_y3S[4)KSN~s?O\"QPoL\r
32         $[Xv_BD:i/F$WiEWax}R(MPS`^UaptOGD`*/=@\1lKoVa9tnrg0TW?"r7aRtgk[F\r
33         !)g;OY^,BjTbr)Np:%c_o'jj,Z\r
34 Date: Thu, 18 Oct 2012 09:44:04 +0300\r
35 Message-ID: <m262681dqj.fsf@guru.guru-group.fi>\r
36 MIME-Version: 1.0\r
37 Content-Type: text/plain\r
38 X-BeenThere: notmuch@notmuchmail.org\r
39 X-Mailman-Version: 2.1.13\r
40 Precedence: list\r
41 List-Id: "Use and development of the notmuch mail system."\r
42         <notmuch.notmuchmail.org>\r
43 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
44         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
45 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
46 List-Post: <mailto:notmuch@notmuchmail.org>\r
47 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
48 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
49         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
50 X-List-Received-Date: Thu, 18 Oct 2012 06:44:03 -0000\r
51 \r
52 On Wed, Oct 17 2012, Ben Gamari <bgamari.foss@gmail.com> wrote:\r
53 \r
54 > ---\r
55 >  configure       |   21 ++++++++++++++++++++-\r
56 >  lib/database.cc |   54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++\r
57 >  lib/notmuch.h   |   14 ++++++++++++++\r
58 >  3 files changed, 88 insertions(+), 1 deletion(-)\r
59 >\r
60 > diff --git a/configure b/configure\r
61 > index acb90a8..6551b13 100755\r
62 > --- a/configure\r
63 > +++ b/configure\r
64 > @@ -270,7 +270,8 @@ printf "Checking for Xapian development files... "\r
65 >  have_xapian=0\r
66 >  for xapian_config in ${XAPIAN_CONFIG}; do\r
67 >      if ${xapian_config} --version > /dev/null 2>&1; then\r
68 > -     printf "Yes (%s).\n" $(${xapian_config} --version | sed -e 's/.* //')\r
69 > +     xapian_version=$(${xapian_config} --version | sed -e 's/.* //')\r
70 > +     printf "Yes (%s).\n" ${xapian_version}\r
71 >       have_xapian=1\r
72 >       xapian_cxxflags=$(${xapian_config} --cxxflags)\r
73 >       xapian_ldflags=$(${xapian_config} --libs)\r
74 > @@ -282,6 +283,20 @@ if [ ${have_xapian} = "0" ]; then\r
75 >      errors=$((errors + 1))\r
76 >  fi\r
77 >  \r
78 > +have_xapian_compact=0\r
79 > +if [ ${have_xapian} = "1" ]; then\r
80 > +    printf "Checking for Xapian compact support... "\r
81 > +    case "${xapian_version}" in\r
82 > +        0.*|1.[01].*|1.2.[0-5])\r
83 > +            printf "No.\n" ;;\r
84 > +        [1-9]*.[0-9]*.[0-9]*) \r
85 > +            have_xapian_compact=1\r
86 > +            printf "Yes.\n" ;;\r
87 > +        *)\r
88 > +            printf "Unknown version.\n" ;;\r
89 > +    esac\r
90 > +fi\r
91 \r
92 This is pretty good approximation(*) for the version check, but some\r
93 comments are in place, like mentioning that compaction is supported\r
94 in Xapian versions 1.2.6 and newer (as the code is not obvious to\r
95 casual reader).\r
96 \r
97 (*) The match for yes part gives some room for non-digit version\r
98 parts (if that would ever be needed) and also it rules out (most) \r
99 cases where garbage were assigned to xapian_version.\r
100 \r
101 Tomi\r
102 \r
103 > +\r
104 >  printf "Checking for GMime development files... "\r
105 >  have_gmime=0\r
106 >  IFS=';'\r
107 > @@ -679,6 +694,9 @@ LINKER_RESOLVES_LIBRARY_DEPENDENCIES = ${linker_resolves_library_dependencies}\r
108 >  XAPIAN_CXXFLAGS = ${xapian_cxxflags}\r
109 >  XAPIAN_LDFLAGS = ${xapian_ldflags}\r
110 >  \r
111 > +# Whether compact is supported by this version of Xapian\r
112 > +HAVE_XAPIAN_COMPACT = ${have_xapian_compact}\r
113 > +\r
114 >  # Flags needed to compile and link against GMime-2.4\r
115 >  GMIME_CFLAGS = ${gmime_cflags}\r
116 >  GMIME_LDFLAGS = ${gmime_ldflags}\r
117 > @@ -715,6 +733,7 @@ CONFIGURE_CFLAGS = -DHAVE_GETLINE=\$(HAVE_GETLINE) \$(GMIME_CFLAGS)      \\\r
118 >  CONFIGURE_CXXFLAGS = -DHAVE_GETLINE=\$(HAVE_GETLINE) \$(GMIME_CFLAGS)    \\\r
119 >                    \$(TALLOC_CFLAGS) -DHAVE_VALGRIND=\$(HAVE_VALGRIND) \\\r
120 >                    \$(VALGRIND_CFLAGS) \$(XAPIAN_CXXFLAGS)             \\\r
121 > +                     -DHAVE_XAPIAN_COMPACT=\$(HAVE_XAPIAN_COMPACT)       \\\r
122 >                       -DHAVE_STRCASESTR=\$(HAVE_STRCASESTR)\r
123 >  CONFIGURE_LDFLAGS =  \$(GMIME_LDFLAGS) \$(TALLOC_LDFLAGS) \$(XAPIAN_LDFLAGS)\r
124 >  EOF\r
125 > diff --git a/lib/database.cc b/lib/database.cc\r
126 > index 761dc1a..6e83a61 100644\r
127 > --- a/lib/database.cc\r
128 > +++ b/lib/database.cc\r
129 > @@ -781,6 +781,60 @@ notmuch_database_close (notmuch_database_t *notmuch)\r
130 >  }\r
131 >  \r
132 >  void\r
133 > +notmuch_database_close_compact (notmuch_database_t *notmuch)\r
134 > +{\r
135 > +    void *local = talloc_new (NULL);\r
136 > +    Xapian::Compactor compactor;\r
137 > +    char *notmuch_path, *xapian_path, *compact_xapian_path, *old_xapian_path;\r
138 > +\r
139 > +#if HAVE_XAPIAN_COMPACT\r
140 > +    if (! (notmuch_path = talloc_asprintf (local, "%s/%s", notmuch->path, ".notmuch"))) {\r
141 > +     fprintf (stderr, "Out of memory\n");\r
142 > +     goto DONE;\r
143 > +    }\r
144 > +\r
145 > +    if (! (xapian_path = talloc_asprintf (local, "%s/%s", notmuch_path, "xapian"))) {\r
146 > +     fprintf (stderr, "Out of memory\n");\r
147 > +     goto DONE;\r
148 > +    }\r
149 > +\r
150 > +    if (! (compact_xapian_path = talloc_asprintf (local, "%s.compact", xapian_path))) {\r
151 > +     fprintf (stderr, "Out of memory\n");\r
152 > +     goto DONE;\r
153 > +    }\r
154 > +\r
155 > +    if (! (old_xapian_path = talloc_asprintf (local, "%s.old", xapian_path))) {\r
156 > +     fprintf (stderr, "Out of memory\n");\r
157 > +     goto DONE;\r
158 > +    }\r
159 > +\r
160 > +    try {\r
161 > +     compactor.set_renumber(false);\r
162 > +     compactor.add_source(xapian_path);\r
163 > +     compactor.set_destdir(compact_xapian_path);\r
164 > +     compactor.compact();\r
165 > +\r
166 > +     if (rename(xapian_path, old_xapian_path)) {\r
167 > +         fprintf (stderr, "Error moving old database out of the way\n");\r
168 > +         goto DONE;\r
169 > +     }\r
170 > +\r
171 > +     if (rename(compact_xapian_path, xapian_path)) {\r
172 > +         fprintf (stderr, "Error moving compacted database\n");\r
173 > +         goto DONE;\r
174 > +     }\r
175 > +    } catch (Xapian::InvalidArgumentError e) {\r
176 > +     fprintf (stderr, "Error while compacting: %s", e.get_msg().c_str());\r
177 > +    }\r
178 > +    \r
179 > +#endif\r
180 > +\r
181 > +    notmuch_database_close(notmuch);\r
182 > +DONE:\r
183 > +    talloc_free(local);\r
184 > +}\r
185 > +\r
186 > +void\r
187 >  notmuch_database_destroy (notmuch_database_t *notmuch)\r
188 >  {\r
189 >      notmuch_database_close (notmuch);\r
190 > diff --git a/lib/notmuch.h b/lib/notmuch.h\r
191 > index 3633bed..50babfb 100644\r
192 > --- a/lib/notmuch.h\r
193 > +++ b/lib/notmuch.h\r
194 > @@ -215,6 +215,20 @@ notmuch_database_open (const char *path,\r
195 >  void\r
196 >  notmuch_database_close (notmuch_database_t *database);\r
197 >  \r
198 > +/* Close the given notmuch database and then compact it.\r
199 > + *\r
200 > + * After notmuch_database_close_compact has been called, calls to\r
201 > + * other functions on objects derived from this database may either\r
202 > + * behave as if the database had not been closed (e.g., if the\r
203 > + * required data has been cached) or may fail with a\r
204 > + * NOTMUCH_STATUS_XAPIAN_EXCEPTION.\r
205 > + *\r
206 > + * notmuch_database_close_compact can be called multiple times.  Later\r
207 > + * calls have no effect.\r
208 > + */\r
209 > +void\r
210 > +notmuch_database_close_compact (notmuch_database_t *notmuch);\r
211 > +\r
212 >  /* Destroy the notmuch database, closing it if necessary and freeing\r
213 >  * all associated resources. */\r
214 >  void\r
215 > -- \r
216 > 1.7.10.4\r
217 >\r
218 > _______________________________________________\r
219 > notmuch mailing list\r
220 > notmuch@notmuchmail.org\r
221 > http://notmuchmail.org/mailman/listinfo/notmuch\r