Commit graph

6477 commits

Author SHA1 Message Date
Carl Worth
203a717d64 notmuch_database_add_message: Do not return a message on failure.
The recent, disastrous failure of "notmuch new" would have been
avoided with this change. The new_command function was basically
assuming that it would only get a message object on success so
wasn't destroying the message in the other cases.
2009-10-27 16:19:20 -07:00
Carl Worth
854f82fb91 notmuch_database_close: Explicitly flush the Xapian database.
This would have helped with the recent bug causing "notmuch new"
to not record any results in the database. I'm not sure why
the explicit flush would be required, (shouldn't the destructor
always ensure that things flush?), but perhaps some outstanding
references from the leak prevented that.

In any case, an explicit flush on close() seems to make sense.
2009-10-27 16:17:22 -07:00
Carl Worth
b0190e59ac Merge branch to fix broken "notmuch setup" and "notmuch new"
I'm trying to stick to a habit of fixing previously-introduced bugs
on side branches off of the commit that introduced the bug. The
idea here is to make it easy to find the commits to cherry pick
if bisecting in the future lands on one of the broken commits.
2009-10-27 16:12:08 -07:00
Carl Worth
8969720108 Fix "notmuch new" (bad performance, and no committing of results).
We were incorrectly only destroying messages in the case of
successful addition to the database, and not in other cases,
(such as failure due to FILE_NOT_EMAIL).

I'm still not entirely sure why this was performing abysmally, (as in
making an operation that should take a small fraction of a second take
10 seconds), nor why it was causing the database to entirely fail to
get new results.

But fortunately, this all seems to work now.
2009-10-27 16:07:27 -07:00
Carl Worth
16003e1f8f Unbreak the "notmuch setup" command.
The recent addition of support for automatically adding tags to
new messages for "notmuch new" caused "notmuch setup" to segfault.
The fix is simple, (just need to move a destroy function to inside
a nearby if block).

Did I mention recently we need to add a test suite?
2009-10-27 12:00:58 -07:00
Carl Worth
38bc6ba920 TODO: Several more ideas that have come to mind, that I don't want to forget.
Some of these are simple little code cleanups, but it's nice to write them
down rather than trying to remember them.
2009-10-27 11:35:30 -07:00
Carl Worth
f2bcc256fb TODO: More notes on archive-thread and race conditions.
Interstingly, it's our simple "notmuch" client that's going to be the
most difficult to fix. There's just not as much information preserved
in the textual representation from "notmuch search" as there is in the
objects returned from notmuch_query_search_threads.
2009-10-27 10:19:46 -07:00
Carl Worth
c690420076 TODO: Add "notmuch tag" and thoughts on avoiding races in archiving threads.
The archive-thread race condition doesn't even exist now because there's
no command for modifying tags at the level of a thread (just individual
messages).
2009-10-27 10:04:48 -07:00
Carl Worth
31db02a8c1 notmuch restore: Fix to remove all tags before adding tags.
This means that the restore operation will now properly pick up the
removal of tags indicated by the tag just not being present in the
dump file.

We added a few new public functions in order to support this:

	notmuch_message_freeze
	notmuch_message_remove_all_tags
	notmuch_message_thaw
2009-10-26 22:53:39 -07:00
Carl Worth
9c4efa8487 notmuch restore: Don't bother printing tag values.
The code was just a little messy here with three parallel conditions
testing for message == NULL.
2009-10-26 22:19:08 -07:00
Carl Worth
ae0bd3f503 add_message: Add an optional parameter for getting the just-added message.
We use this to implement the addition of "inbox" and "unread" tags
for all messages added by "notmuch new".
2009-10-26 21:44:05 -07:00
Carl Worth
d07dd49aac Fix incorrect name of _notmuch_thread_get_subject.
Somehow this naming with an underscore crept in, (but only in the
private header, so notmuch.c was compiling with no prototype). Fix
to be the notmuch_thread_get_subject originally intended.
2009-10-26 20:11:58 -07:00
Carl Worth
c12823648e Add public notmuch_thread_get_subject
And use this in "notmuch search" to display subject line as well as
thread ID.
2009-10-26 17:35:31 -07:00
Carl Worth
8e96a87fff Remove all calls to g_strdup_printf
Replacing them with calls to talloc_asprintf if possible, otherwise
to asprintf (with it's painful error-handling leaving the pointer
undefined).
2009-10-26 15:17:10 -07:00
Carl Worth
94f01d9de9 Add notmuch_thread_get_tags
And augment "notmuch search" to print tag values as well as thread ID
values. This tool is almost usable now.
2009-10-26 14:46:14 -07:00
Carl Worth
ef3ab5781a tags: Replace sort() and reset() with prepare_iterator().
The previous functions were always called together, so we might as
well just have one function for this. Also, the reset() name was
poor, and prepare_iterator() is much more descriptive.
2009-10-26 14:12:56 -07:00
Carl Worth
1726c5c814 Fix memory leak in notmuch_thread_results_t
If we were using a talloc-based resizing array then this wouldn't
have happened. Of course, thanks to valgrind for catching this.
2009-10-26 14:02:58 -07:00
Carl Worth
3dce200788 tags: Re-implement tags iterator to avoid having C++ in the interface
We want to be able to iterate over tags stored in various ways, so
the previous TermIterator-based tags object just wasn't general
enough. The new interface is nice and simple, and involves only
C datatypes.
2009-10-26 14:02:51 -07:00
Carl Worth
46ba33b115 notmuch restore: Fix leak of FILE* object.
Apparently, I didn't copy enough of the "notmuch dump" implementation
since it didn't have a similar leak.
2009-10-26 13:36:40 -07:00
Carl Worth
789495919a Hide away the details of the implementation of notmuch_tags_t.
We will soon be wanting multiple different implementations of
notmuch_tags_t iterators, so we need to keep the actual structure
as an implementation detail inside of tags.cc.
2009-10-26 06:00:07 -07:00
Carl Worth
2affed0851 Move terms and tags code to a new tags.cc file.
We want to start using this from both message.cc and thread.cc so we
need it in a place we can share the code. This also requires a new
notmuch-private-cxx.h header file for interfaces that include
C++-specific datatypes (such as Xapian::Document).
2009-10-26 05:53:40 -07:00
Carl Worth
b42c4418a4 results_get: Fix to return NULL if past the end of the results
We had documented both notmuch_thread_results_get and
notmuch_message_results_get to return NULL if (! has_more)
but we hadn't actually implemented that. Fix.
2009-10-26 05:14:51 -07:00
Carl Worth
e8d8906d9c Add TODO file.
I've been maintaining this for a while now, so I might as well
start tracking it with revision control as well.
2009-10-25 23:18:05 -07:00
Carl Worth
1ba3d46fab Add an initial implementation of a notmuch_thread_t object.
We've now got a new notmuch_query_search_threads and a
notmuch_threads_result_t iterator. The thread object itself
doesn't do much yet, (just allows one to get the thread_id),
but that's at least enough to see that "notmuch search" is
actually doing something now, (since it has been converted
to print thread IDs instead of message IDs).

And maybe that's all we need. Getting the messages belonging
to a thread is as simple as a notmuch_query_search_messages
with a string of "thread:<thread-id>".

Though it would be convenient to add notmuch_thread_get_messages
which could use the existing notmuch_message_results_t iterator.

Now we just need an implementation of "notmuch show" and we'll
have something somewhat usable.
2009-10-25 23:12:20 -07:00
Carl Worth
cd467cafb5 Rename notmuch_query_search to notmuch_query_search_messages
Along with renaming notmuch_results_t to notmuch_message_results_t.
The new type is quite a mouthful, but I don't expect it to be
used much other than the for-loop idiom in the documentation,
(which does at least fit nicely within 80 columns).

This is all in preparation for the addition of a new
notmuch_query_search_threads of course.
2009-10-25 22:22:07 -07:00
Carl Worth
70f9d0ad42 Drop dead function add_term.
Even with the recent warnings work, gcc didn't tell me about a static
function that I'm not calling? Apparently I get "defined but not
used" in C files, but not C++ files. That's bogus, and yet one more
reason for me to push the C++ to a minimal lower layer.
2009-10-25 16:14:07 -07:00
Carl Worth
179629b672 Fix missing xapian-flags when generating dependencies.
I didn't notice this because `xapian-config -cxxflags` gives empty
output on my system. But for someone with the xapian library
installed in some non-standard location this would be important.
2009-10-25 16:09:31 -07:00
Carl Worth
445234ac1f Drop unused variable.
I didn't end up adding any of the warnings options that aren't allowed
for C++, (such as -Wold-style-definition, -Wnested-externs,
-Werror-implicit-function-declaration, -Wstrict-prototypes,
-Wmissing-prototypes, or -Wbad-function-cast). So for now we can
drop the separate C and C++ variables for warnings.
2009-10-25 16:07:46 -07:00
Carl Worth
3bd4a2eaaa Add -Wswitch-enum and fix warnings.
Having to enumerate all the enum values at every switch is annoying,
but this warning actually found a bug, (missing support for
NOTMUCH_STATUS_OUT_OF_MEMORY in notmuch_status_to_string).
2009-10-25 16:03:45 -07:00
Carl Worth
c7482b4dce Add -Wmising-declarations and fix warnings.
Wow, lots of missing 'static' on internal functions.
2009-10-25 15:58:05 -07:00
Carl Worth
eb7b8cf31a Add -Wwrite-strings and fix warnings.
Need to be const-clean when handling string literals.
2009-10-25 15:55:23 -07:00
Carl Worth
884ac59256 Re-enable the warning for unused parameters.
It's easy enough to squelch the warning with an __attribute__ ((unused))
and it might just catch something for us in the future.
2009-10-25 15:53:27 -07:00
Carl Worth
cc48812cb5 Add -Wextra and fix warnings.
When adding -Wextra we also add -Wno-ununsed-parameters since that
function means well enough, but is really annoying in practice.

So the warnings we fix here are basically all comparsions between
signed and unsigned values.
2009-10-25 15:52:14 -07:00
Carl Worth
067c547b23 Rework Makefile just a bit to enable adding flags for more compiler warnings
We have to carefully separate the C and C++ flags here since a
bunch of the warnings options for gcc are valid for compiling C,
but not for C++.
2009-10-25 15:19:36 -07:00
Carl Worth
be9e3ee313 _notmuch_database_linke_message: Fix error-status propagation.
The _notmuch_database_link_message_to_parents function was void
in an earlier draft. Now, ensure that we don't miss any error
return value from it.
2009-10-25 15:01:20 -07:00
Carl Worth
a360670c03 Change database to store only a single thread ID per message.
Instead of supporting multiple thread IDs, we now merge together
thread IDs if one message is ever found to belong to more than one
thread. This allows for constructing complete threads when, for
example, a child message doesn't include a complete list of References
headers back to the beginning of the thread.

It also simplifies dealing with mapping a message ID to a thread ID
which is now a simple get_thread_id just like get_message_id, (and no
longer an iterator-based thing like get_tags).
2009-10-25 14:54:13 -07:00
Carl Worth
ec77f6b50c link_message: Remove dead code.
We dropped the THREAD_ID value from the database a while back, but here
is code that's carefully computing that value and then never doing
anything with it. Delete, delete, delete.
2009-10-25 11:05:16 -07:00
Carl Worth
6b20dbff86 add_message: Pull the thread-stitching portion out into new _notmuch_database_link_message
The function was getting too long-winded before. Add since I'm about
to change how we handle the thread linking, it's convenient to have
it in an isolated function.
2009-10-25 11:03:55 -07:00
Carl Worth
7b227a6bf7 Add an INTERNAL_ERROR macro and use it for all internal errors.
We were previously just doing fprintf;exit at each point, but I
wanted to add file and line-number details to all messages, so it
makes sense to use a single macro for that.
2009-10-25 10:54:49 -07:00
Carl Worth
3b8e3ab666 add_message: Propagate error status from notmuch_message_create_for_message_id
What a great feeling to remove an XXX comment.
2009-10-25 10:54:43 -07:00
Carl Worth
9f673f3cf8 notmuch dump: Eliminate extra space in error message.
Little details can make big impressions.
2009-10-25 09:20:13 -07:00
Carl Worth
a8ae2cd214 Move read-only-archive hint from "notmuch setup" to "notmuch new"
The "notmuch setup" output was getting overwhelmingly verbose.

Also, some people might not have a lot of mail, so might never need
this optimization. It's much better to move the hint to the time
when the user could actually benefit from it, (it's easy to detect
that "notmuch new" took more than 1 second, and we know if there
are any read-only directories there or not).
2009-10-25 09:14:16 -07:00
Carl Worth
32ecfe72a1 Add comment documenting our current database schema.
I've got schemes to change this schema somewhat dramatically, so I
want a place to be able to record and review those changes.
2009-10-25 08:57:09 -07:00
Carl Worth
1c2bac747e Drop the storage of thread ID(s) in a value.
Now that we are iterating over the thread terms instead, we can
drop this redundant storage (which should shrink our database a
tiny bit).
2009-10-25 00:31:20 -07:00
Carl Worth
5941b91a5e Convert notmuch_thread_ids_t to notmuch_terms_t
Aside from increased code sharing, the benefit here is that now
thread_ids iterates over the terms of a message rather than the
thread_id value. So we'll now be able to drop that value.
2009-10-25 00:31:19 -07:00
Carl Worth
28dd86af05 Implement notmuch_tags_t on top of new notmuch_terms_t
The generic notmuch_terms_t iterator should provide support for
notmuch_thread_ids_t when we switch as well, (And it would be
interesting to see if we could reasonably make this support a
PostingIterator too. Time will tell.)
2009-10-25 00:31:13 -07:00
Carl Worth
9ec68aa9c4 Shuffle the value numbers around in the database.
First, it's nice that for now we don't have any users yet, so we
can make incompatible changes to the database layout like this
without causing trouble. ;-)

There are a few reasons for this change. First, we now use value 0
uniformly as a timestamp for both mail and timestamp documents, (which
lets us cleanup an ugly and fragile bare 0 in the add_value and
get_value calls in the timestamp code).

Second, I want to drop the thread value entirely, so putting it at the
end of the list means we can drop it as compatible change in the
future. (I almost want to drop the message-ID value too, but it's nice
to be able to sort on it to get diff-able output from "notmuch dump".)

But the thread value we never use as a value, (we would never sort on
it, for example). And it's totally redundant with the thread terms we
store already. So expect it to disappear soon.
2009-10-24 23:05:08 -07:00
Carl Worth
65a272832e Invent our own prefix values.
We're now dropping all pretense of keeping the database directly
compatible with sup's current xapian backend. (But perhaps someone
might write a new nothmuch backend for sup in the future.)

In coming up with the prefix values here, I tried to follow the
conventions of http://xapian.org/docs/omega/termprefixes.html as
closely as makes sense, (with some domain translation from "web"
to "email archive").
2009-10-24 22:57:47 -07:00
Carl Worth
0aa355cc8f Split BOOLEAN_PREFIX into INTERNAL and EXTERNAL subsets.
The idea here is that only some of the prefix names (such as "id" and
"tag") actually make sense in external user-supplied query
strings. Other things like "type" are internal implementation details
of how we store things in the database. So internal machinery will add
those terms to the database and we don't need to support them in the
string itself.

With this, we can now simply loop over the external prefix values to
let the quiery parser know about them. So as we add prefixes in the
future, we'll only need to add them to this list.
2009-10-24 22:38:43 -07:00
Carl Worth
2a9b4fce7c Change all occurrences of "msgid" to "id".
What's good for the user is good for the internals.
2009-10-24 22:29:49 -07:00