Commit graph

7423 commits

Author SHA1 Message Date
David Bremner
5500868bd9 emacs: mark notmuch-query.el as obsolete
The only functionality actually used by notmuch is the base function
notmuch-query-get-threads; the other functions in this file have
nothing to do with that (single) use.  Move that function into
notmuch-lib.el and rename to reflect use. Deprecate the other
functions in notmuch-query.el.
2022-07-03 17:08:08 -03:00
David Bremner
6a9ae99099 lib/sexp: add parameter expansion for regex and wildcard
Fix the bug reported at [1].

The parameter expansion for regex and wildcard modifiers has to be
done a bit differently, because their arguments are not s-expressions
defining complete Xapian queries.

[1]: id:87o7yxqxy6.fsf@code.pm
2022-07-01 08:37:00 -03:00
David Bremner
4464a5d073 test/sexp: add known broken tests for macro param inside rx/wildcard
These tests replicate the problem reported by Eric Colson [1] (for the
regex case).

[1]: id:87o7yxqxy6.fsf@code.pm
2022-07-01 08:34:36 -03:00
Michael J Gruber
2a5e1cf98b make git ignore new build products
nmbug and notmuch-git are new build products. Make git ignore them just
like other build products.

Signed-off-by: Michael J Gruber <git@grubix.eu>
2022-07-01 08:30:40 -03:00
David Bremner
d73ddec5b8 doc/sexp: document range queries.
Give examples for date fields, as these are commonly useful for user
queries.
2022-06-25 19:52:42 -03:00
David Bremner
e7ffb74041 lib/sexp: allow * as alias for "" in range searches.
It can be tedious to use "" inside of a string, e.g. in a shell script.
2022-06-25 19:49:55 -03:00
David Bremner
7863234586 lib/sexp: special case "" as an argument in lastmod ranges.
Support this syntax for constincy with (data from to) ranges.
2022-06-25 19:49:55 -03:00
David Bremner
254912821f test/sexp: one sided range searches.
The date range parsing machinery already knows how to do something
appropriate with an empty string, but the lastmod parsing blindly
tries to parse each atom as a number.
2022-06-25 19:49:55 -03:00
David Bremner
6f749dd24a lib: check for writable db in n_m_tags_maildir_flags
The database needs to be writable because the list of stored file
names will change in general.
2022-06-25 16:06:34 -03:00
David Bremner
3f27cce71f lib: add NOTMUCH_STATUS_CLOSED_DATABASE, use in _n_d_ensure_writable
In order for a database to actually be writeable, it must be the case that it
is open, not just the correct type of Xapian object. By explicitely
checking, we are able to provide better error reporting, in particular
for the previously broken test in T566-lib-message.
2022-06-25 16:06:18 -03:00
David Bremner
7e654e2a45 lib: Add missing private status values.
These were missed when the corresponding status codes were added.
2022-06-25 16:06:10 -03:00
David Bremner
e70df92085 lib/tag: handle NULL argument to notmuch_tags_valid
Make the behaviour when passed NULL consistent with
notmuch_filenames_valid. The library already passes the result of
notmuch_message_get_tags without checking for NULL, so it should be
handled.
2022-06-25 16:05:45 -03:00
David Bremner
00ec2b271d test: add known broken test for notmuch_tags_valid (NULL)
This should return false, but currently segfaults.

Start a new file for tags library API related tests. This is maybe
overkill, but new C boilerplate which doesn't corrupt the database is
needed anyway.
2022-06-25 16:05:32 -03:00
David Bremner
8ade833ec2 test: error handling for n_m_tags_to_maildir_flags
The closed database case should fail gracefully, but currently it
segfaults.
2022-06-25 16:05:16 -03:00
David Bremner
9e9d0e5ffc test: error handling in _n_message_{add,remove}_filename
Use a closed database to force throwing a Xapian exception. Leave the
check vague to accomodate a potential explicit check for open database.
2022-06-25 12:55:02 -03:00
David Bremner
879ec9d76a lib/message: check return status from _n_m_add_{path,folder}_terms
Mainly to propagate information about Xapian exceptions.
2022-06-25 12:55:02 -03:00
David Bremner
b102d0ad11 lib/message: check return status of _n_m_{add,remove}_term
Xapian exceptions are not something that can be ignored, in general.
2022-06-25 12:55:02 -03:00
David Bremner
7d5a9bd3ae lib: define macro NODISCARD
In either C++17 (or later) mode, or when running cppcheck, this can be
used to selectively generate warnings about discarded return values.
2022-06-25 12:55:02 -03:00
David Bremner
bc80ff829a lib/message: drop _notmuch_message_get_thread_id_only
This function has been unused since commit 4083fd8.
2022-06-25 12:55:02 -03:00
David Bremner
a581755fbb test: _notmuch_message_remove_term catches exceptions.
Unfortunately we can't differentiate between the two distinct error
conditions for Document::remove_term.
2022-06-25 12:55:02 -03:00
David Bremner
f48d2e2ff8 lib/message: catch exceptions in _n_m_add_term
Some code movement is needed to make sure the cache is only
invalidated when the Xapian operation succeeds.
2022-06-25 12:55:02 -03:00
David Bremner
2707c06a0f test: define test_private_C
When testing error handling, it is sometimes difficult to cover a
particular error path deterministically. Introduce a test function to
allow calling lower level functions directly.
2022-06-25 12:55:02 -03:00
David Bremner
bfcf9a6c10 CLI: set NOTMUCH_CONFIG in hooks.
This addresses a bug report / feature request of Uwe Kleine-König. The
assumption is that we always load a config file in the CLI (i.e. we
never pass "" as the config file argument to
notmuch_database_open_with_config).

[1]: id:8baa58c3-7ab9-ec03-1bbd-28aa5be838f2@kleine-koenig.org
2022-06-18 08:24:46 -03:00
David Bremner
e167825bca test: add known broken tests for setting NOTMUCH_CONFIG in hooks
Setting this according to --config was requested by Uwe
Kleine-König. There are some other ways that the configuration file
might be found in current notmuch, so check those as well.

As a bonus, fix a bug in the hook tests that left NOTMUCH_CONFIG set
even though a config file was provided via NOTMUCH_PROFILE.

[1]: id:8baa58c3-7ab9-ec03-1bbd-28aa5be838f2@kleine-koenig.org
2022-06-18 08:23:31 -03:00
David Bremner
8d3d98991d debian: install notmuch-git
Use a separate binary package to avoid dragging in dependencies on
python and git for those that do not want them.
2022-06-17 08:40:19 -03:00
David Bremner
7d1e5a5348 CLI/git: add safety checks for checkout and commit
Commits or checkouts that modify a large fraction of the messages in
the database should be relatively rare (and in some automated process,
probably non-existent). For initial setup, where such operations are
expected, the user can pass --force.
2022-06-17 08:40:19 -03:00
David Bremner
99e85823c8 CLI/git: support configuration for repo location / prefix
This is probably more convenient than always passing a command line
argument.

Use notmuch-config for consistency with other notmuch CLI tools.

Now that there is something relevant in the config files, test the
--config option.
2022-06-17 08:40:19 -03:00
David Bremner
8ed68c1bbe CLI/git: change defaults for repo and prefix
The previous defaults were not suitable for personal (i.e. not
bugtracking for notmuch development) use.

Provide two ways for the user to select nmbug compatible defaults;
command line argument and checking the name of the script.
2022-06-17 08:40:19 -03:00
David Bremner
e50a413906 doc/notmuch-git: initial documentation
This is mainly derived from the various help outputs from the script,
with some massaging of markup and addition of links.
2022-06-17 08:40:19 -03:00
David Bremner
66ccf420c2 CLI/git: cache git indices
If the private index file matches a previously known revision of the
database, we can update the index incrementally using the recorded
lastmod counter. This is typically much faster than a full update,
although it could be slower in the case of large changes to the
database.

The "git-read-tree HEAD" is also a bottleneck, but unfortunately
sometimes is needed. Cache the index checksum and hash to reduce the
number of times the operation is run. The overall design is a
simplified version of the PrivateIndex class.
2022-06-17 08:40:19 -03:00
David Bremner
5ef56fe812 CLI/git: add @timed decorator, time a few functions
Perf will show which binaries are using the CPU cycles, and standard
python profilers will show which python functions, but neither is
great at finding which call to an external binary is taking time, or
locating I/O hotspots.
2022-06-17 08:40:19 -03:00
David Bremner
f67d7c9e7a CLI/git: replace enumeration of tags with sexp query.
Unlike the (current) infix query parser provided by Xapian, the
notmuch specific sexp query parser supports prefixed wildcard queries,
so use those. In addition to being somewhat faster, this avoids
needing to escape all of the user's tags to pass via the shell.
2022-06-17 08:40:19 -03:00
David Bremner
b355973abc test/git: add known broken test for tag with quotes.
There is current insufficient sanitization and/or escaping of tag names
internally in notmuch-git.
2022-06-17 08:40:19 -03:00
David Bremner
d4d5737165 CLI/git: suppress warnings about initial branch name
The canonical nmbug repository still uses "master" as the main branch
name, so defer any potential switch away from that name.
2022-06-17 08:40:19 -03:00
David Bremner
b010584163 CLI/git: rename environment variables.
Although the code required to support both new and old environment
variables is small, it complicates the semantics of configuration, and
make the documentation harder to follow.
2022-06-17 08:40:19 -03:00
David Bremner
a85c82f99a test: initial tests for notmuch-git
Exercise the main functionality of notmuch-git.  add_git_repos() will
hopefully be simplifed when an init subcommand is added.
2022-06-17 08:40:19 -03:00
W. Trevor King
14ac68ae11 CLI/git: Add an 'init' command
For folks that want to start versioning a new tag-space, instead of
cloning one that someone else has already started.

The empty-blob hash-object call avoids errors like:

  $ nmbug commit
  error: invalid object 100644 e69de29bb2 for
'tags/...'
  fatal: git-write-tree: error building trees
  'git HASH(0x9ef3eb8) write-tree' exited with nonzero value

David Bremner suggested [1]:

  $ git hash-object -w /dev/null

instead of my Python version of:

  $ git hash-object -w --stdin <&-

but I expect that closing stdin is more portable than the /dev/null
path (which doesn't exist on Windows, for example).

The --bare init and use of NMBGIT as the work tree (what could go
wrong with an empty commit?) are suggestions from Michal Sojka [2].

[1]: id:87y4vu6uvf.fsf@maritornes.cs.unb.ca
     http://thread.gmane.org/gmane.mail.notmuch.general/18626/focus=18720
[2]: id:87a93a5or2.fsf@resox.2x.cz
     http://thread.gmane.org/gmane.mail.notmuch.general/19495/focus=19767
2022-06-17 08:40:19 -03:00
David Bremner
a01378e48d CLI/git: make existance of config branch optional on clone
This branch is actually only used by an associated
utility (notmuch-report), and notmuch-git works fine without it.
2022-06-17 08:40:19 -03:00
David Bremner
b7b111b9b5 notmuch-git: add --git-dir, --tag-prefix arguments
It is often more convenient to use command line arguments than
environment variables.
2022-06-17 08:40:19 -03:00
David Bremner
b7c31f6581 CLI/git: drop support for python < 3.2
Debian stable had python 3.4.2 3 releases ago (approximately 6 years
ago), so attempting to keep track of the changes in python is probably
no longer worthwhile. We already require python 3.5 for the
python-cffi bindings (although those are not yet used in notmuch-git).
2022-06-17 08:40:19 -03:00
David Bremner
803ac83c46 nmbug: promote to user tool "notmuch-git"
Initially just a rename, and drop the --version argument that clashes
with the global notmuch --version argument.
2022-06-17 08:40:19 -03:00
jao
9695e4c38d emacs: use message-dont-reply-to-names when composing replies
notmuch-mua functions for replies now use the built-in customizable
variable message-dont-reply-to-names with the same semantics as
message-mode.
2022-06-16 08:51:19 -03:00
Leo Okawa Ericson
fb4a0967ca emacs: Make notmuch-show-next-thread return nil on failure
Having notmuch-show-next-thread return non-nil on success and nil on
failure makes it easier for users to interact with notmuch via elisp.

This commit changes notmuch-search-show-thread too since the return
value of notmuch-show-next-thread depends on notmuch-search-show-thread.

Amended by db: fix whitespace in T450-emacs-show
2022-06-13 08:06:51 -03:00
David Bremner
a5504e8b1c CLI: document handling of --config for external commands
Create a section of the notmuch(1) manpage to have some place to put
this documentation.
2022-06-13 07:28:35 -03:00
David Bremner
5cbddf7e7a CLI: pass --config to external commands via NOTMUCH_CONFIG.
This makes `notmuch --config foo external-subcommand` work
consistently with the built in subcommands.
2022-06-13 07:28:05 -03:00
David Bremner
eaa5199f5b test: initial tests for external commands
The main goal is to test the setting of NOTMUCH_CONFIG, but also
include a basic sanity test for execing scripts.
2022-06-13 07:27:06 -03:00
David Bremner
82957c9632 CLI: mention sexp-queries in help topics, alphabetize
There does not seem to be an easy way to automate maintaining this
list, but new topics are not added very often.
2022-06-13 07:18:26 -03:00
David Bremner
52470ddfbf CLI: simplify help command
This will allow "notmuch help" to work for arbitrary external commands
and for any added non-command topics (such as notmuch-sexp-queries).
2022-06-13 07:17:59 -03:00
Damien Cassou
3a6b479a73 emacs: change where notmuch-mua-mail moves point
Move point to the position that makes the most sense instead of always
moving point to the TO.  This is useful when TO/SUBJECT are passed as
argument.

Amended by db: move news item to UNRELEASED.
2022-06-02 08:21:56 -03:00
jao
66369ddf1c emacs: notmuch-show-header-line: allow format strings and functions
If a string value is assigned to notmuch-show-header-line, it's used
as a format string to be passed passed to format-spec with `%s`
substituted by the message's subject.  If a function is given, it's
called with the subject as argument, and its return value used as
header line.

As before, t means displaying the subject and nil not using any header
line.

Signed-off-by: jao <jao@gnu.org>
Amended-by: db, docstring spelling fix
2022-06-01 08:36:20 -03:00