Re: [feature request] emacs: use `notmuch insert` for FCC
[notmuch-archives.git] / c1 / 0a91964dd6f927d7ac9dedfa7a099b3b9a5eca
1 Return-Path: <aclements@csail.mit.edu>\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 41067431FBC\r
6         for <notmuch@notmuchmail.org>; Wed, 24 Sep 2014 14:20:44 -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: -2.3\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-2.3 tagged_above=-999 required=5\r
12         tests=[RCVD_IN_DNSWL_MED=-2.3] 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 WtR9-lQ9g+c8 for <notmuch@notmuchmail.org>;\r
16         Wed, 24 Sep 2014 14:20:38 -0700 (PDT)\r
17 Received: from dmz-mailsec-scanner-4.mit.edu (dmz-mailsec-scanner-4.mit.edu\r
18         [18.9.25.15])\r
19         (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))\r
20         (No client certificate requested)\r
21         by olra.theworths.org (Postfix) with ESMTPS id B56AB431FAF\r
22         for <notmuch@notmuchmail.org>; Wed, 24 Sep 2014 14:20:38 -0700 (PDT)\r
23 X-AuditID: 1209190f-f79aa6d000005b45-a9-542335a538f7\r
24 Received: from mailhub-auth-2.mit.edu ( [18.7.62.36])\r
25         (using TLS with cipher AES256-SHA (256/256 bits))\r
26         (Client did not present a certificate)\r
27         by dmz-mailsec-scanner-4.mit.edu (Symantec Messaging Gateway) with SMTP\r
28         id 63.9B.23365.5A533245; Wed, 24 Sep 2014 17:20:38 -0400 (EDT)\r
29 Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11])\r
30         by mailhub-auth-2.mit.edu (8.13.8/8.9.2) with ESMTP id s8OLKYuY021561; \r
31         Wed, 24 Sep 2014 17:20:34 -0400\r
32 Received: from drake.dyndns.org (q-1.n.148.220.37.qore.nl [37.220.148.94] (may\r
33         be forged)) (authenticated bits=0)\r
34         (User authenticated as amdragon@ATHENA.MIT.EDU)\r
35         by outgoing.mit.edu (8.13.8/8.12.4) with ESMTP id s8OLKUxX018469\r
36         (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NOT);\r
37         Wed, 24 Sep 2014 17:20:32 -0400\r
38 Received: from amthrax by drake.dyndns.org with local (Exim 4.84)\r
39         (envelope-from <aclements@csail.mit.edu>)\r
40         id 1XWtzB-00029S-TY; Wed, 24 Sep 2014 17:20:29 -0400\r
41 From: Austin Clements <aclements@csail.mit.edu>\r
42 To: notmuch@notmuchmail.org\r
43 Subject: [PATCH v2] lib: Simplify close and codify aborting atomic section\r
44 Date: Wed, 24 Sep 2014 17:20:23 -0400\r
45 Message-Id: <1411593623-8234-1-git-send-email-aclements@csail.mit.edu>\r
46 X-Mailer: git-send-email 2.1.0\r
47 In-Reply-To: <1411400615-20934-1-git-send-email-amdragon@mit.edu>\r
48 References: <1411400615-20934-1-git-send-email-amdragon@mit.edu>\r
49 X-Brightmail-Tracker:\r
50  H4sIAAAAAAAAA+NgFrrMIsWRmVeSWpSXmKPExsUixG6norvMVDnEYHI7s8WN1m5Gi+s3ZzJb\r
51         XFlznt2B2ePZqlvMHlsOvWf22P39J0sAcxSXTUpqTmZZapG+XQJXxoUb/SwFx6QqDq/5ydzA\r
52         uEO0i5GTQ0LARGL7+lWMELaYxIV769m6GLk4hARmM0n8efKIBcLZyCixqnESI4RzgUli1rRv\r
53         LCAtQgJLGCX2/rMGsdkE9CVWrJ3ECmKLCEhL7Lw7G8xmFvCWmP11NTuILSzgJXH8zhYmEJtF\r
54         QFXiZM8xsBpeATeJK39fQJ0hJ7Fh938wm1PAUeLexJmsELscJH5Pf8k+gZF/ASPDKkbZlNwq\r
55         3dzEzJzi1GTd4uTEvLzUIl0TvdzMEr3UlNJNjKDw4pTk38H47aDSIUYBDkYlHt4J4kohQqyJ\r
56         ZcWVuYcYJTmYlER51+orhwjxJeWnVGYkFmfEF5XmpBYfYpTgYFYS4VX5CFTOm5JYWZValA+T\r
57         kuZgURLn3fSDL0RIID2xJDU7NbUgtQgmK8PBoSTBe9QEaKhgUWp6akVaZk4JQpqJgxNkOA/Q\r
58         8NMgNbzFBYm5xZnpEPlTjLoc6zq/9TMJseTl56VKifMeBCkSACnKKM2DmwNLC68YxYHeEuat\r
59         BKniAaYUuEmvgJYwAS25f1weZElJIkJKqoHRh7tw+vb/4U4BsnMLYuZ+NpTdytJ68Zx2YPpK\r
60         vcPX5aSEwq7ECnbvrLHcrr7pV6Vs7cpgObHFQS0/Jh+cViB731Hbj9ltVZyV5KlivjSJJPXX\r
61         /MVTd/jIK89tYmba2f7ee7W4VL21FvOvXrd337pnf3vy7rjqoZ/ZU5yOu9nKZyya83/RgV1K\r
62         LMUZiYZazEXFiQDvLj9h5gIAAA==\r
63 X-BeenThere: notmuch@notmuchmail.org\r
64 X-Mailman-Version: 2.1.13\r
65 Precedence: list\r
66 List-Id: "Use and development of the notmuch mail system."\r
67         <notmuch.notmuchmail.org>\r
68 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
69         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
70 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
71 List-Post: <mailto:notmuch@notmuchmail.org>\r
72 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
73 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
74         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
75 X-List-Received-Date: Wed, 24 Sep 2014 21:20:44 -0000\r
76 \r
77 From: Austin Clements <amdragon@mit.edu>\r
78 \r
79 In Xapian, closing a database implicitly aborts any outstanding\r
80 transaction and commits changes.  For historical reasons,\r
81 notmuch_database_close had grown to almost, but not quite duplicate\r
82 this behavior.  Before closing the database, it would explicitly (and\r
83 unnecessarily) commit it.  However, if there was an outstanding\r
84 transaction (ie atomic section), commit would throw a Xapian\r
85 exception, which notmuch_database_close would unnecessarily print to\r
86 stderr, even though notmuch_database_close would ultimately abort the\r
87 transaction anyway when it called close.\r
88 \r
89 This patch simplifies notmuch_database_close to just call\r
90 Database::close.  This works for both read-only and read/write\r
91 databases, takes care of committing changes, unifies the exception\r
92 handling path, and codifies aborting outstanding transactions.  This\r
93 is currently the only way to abort an atomic section (and may remain\r
94 so, since it would be difficult to roll back things we may have cached\r
95 from rolled-back modifications).\r
96 ---\r
97  lib/database.cc | 23 +++++++----------------\r
98  lib/notmuch.h   |  5 +++++\r
99  2 files changed, 12 insertions(+), 16 deletions(-)\r
100 \r
101 diff --git a/lib/database.cc b/lib/database.cc\r
102 index a3a7cd3..1f7ff2a 100644\r
103 --- a/lib/database.cc\r
104 +++ b/lib/database.cc\r
105 @@ -903,28 +903,19 @@ notmuch_database_close (notmuch_database_t *notmuch)\r
106  {\r
107      notmuch_status_t status = NOTMUCH_STATUS_SUCCESS;\r
108  \r
109 -    try {\r
110 -       if (notmuch->xapian_db != NULL &&\r
111 -           notmuch->mode == NOTMUCH_DATABASE_MODE_READ_WRITE)\r
112 -           (static_cast <Xapian::WritableDatabase *> (notmuch->xapian_db))->flush ();\r
113 -    } catch (const Xapian::Error &error) {\r
114 -       status = NOTMUCH_STATUS_XAPIAN_EXCEPTION;\r
115 -       if (! notmuch->exception_reported) {\r
116 -           fprintf (stderr, "Error: A Xapian exception occurred flushing database: %s\n",\r
117 -                    error.get_msg().c_str());\r
118 -       }\r
119 -    }\r
120 -\r
121      /* Many Xapian objects (and thus notmuch objects) hold references to\r
122       * the database, so merely deleting the database may not suffice to\r
123 -     * close it.  Thus, we explicitly close it here. */\r
124 +     * close it.  Thus, we explicitly close it here.  This will\r
125 +     * implicitly abort any outstanding transaction and commit changes. */\r
126      if (notmuch->xapian_db != NULL) {\r
127         try {\r
128             notmuch->xapian_db->close();\r
129         } catch (const Xapian::Error &error) {\r
130 -           /* don't clobber previous error status */\r
131 -           if (status == NOTMUCH_STATUS_SUCCESS)\r
132 -               status = NOTMUCH_STATUS_XAPIAN_EXCEPTION;\r
133 +           status = NOTMUCH_STATUS_XAPIAN_EXCEPTION;\r
134 +           if (! notmuch->exception_reported) {\r
135 +               fprintf (stderr, "Error: A Xapian exception occurred closing database: %s\n",\r
136 +                        error.get_msg().c_str());\r
137 +           }\r
138         }\r
139      }\r
140  \r
141 diff --git a/lib/notmuch.h b/lib/notmuch.h\r
142 index fe2340b..5c40c67 100644\r
143 --- a/lib/notmuch.h\r
144 +++ b/lib/notmuch.h\r
145 @@ -292,6 +292,11 @@ notmuch_database_open (const char *path,\r
146   * notmuch_database_close can be called multiple times.  Later calls\r
147   * have no effect.\r
148   *\r
149 + * If the caller is currently in an atomic section (there was a\r
150 + * notmuch_database_begin_atomic without a matching\r
151 + * notmuch_database_end_atomic), this will abort the atomic section,\r
152 + * discarding any modifications made in the atomic section.\r
153 + *\r
154   * Return value:\r
155   *\r
156   * NOTMUCH_STATUS_SUCCESS: Successfully closed the database.\r
157 -- \r
158 2.1.0\r
159 \r