This patch series modifies notmuch new to perform all operations atomically and to perform maildir flag synchronization eagerly. As a result, notmuch new can be interrupted without risking database consistency or losing track of messages, but still without losing progress in the middle of a big import. This also paves the way for fixing the antisocial locking behavior of notmuch new.
While there are quite a few patches in the series, each one is bite-sized and you can see the number of atomicity violations dropping with nearly every patch using the test added by the first patch. On my test machine, these patches have no affect on performance. These patches are also available on the atomic-new-v1 branch at http://awakening.csail.mit.edu/git/notmuch.git/