aboutsummaryrefslogtreecommitdiff
path: root/notmuch-tag.c
AgeCommit message (Collapse)Author
2021-09-04CLI/tag: enable sexp queriesDavid Bremner
We have to rewrite _optimize_tag_query here because it is generating a query string in the infix Xapian syntax. Luckily this is easy to do with the sexp query syntax.
2021-09-04CLI: make variable n_requested_db_uuid file scope.David Bremner
It turns out that now that we pass an open database into the subcommands, it is easy to check any requested uuid against the database at the same time as we process the other shared arguments. This results in overall less boilerplate code, as well as making a CLI scope function and variable file scope in notmuch.c.
2021-05-14CLI: make static message strings constDavid Bremner
This is both a bit clearer and avoids the possibility of modification.
2021-04-06CLI: drop notmuch_config_t from subcommand interface.David Bremner
At this point it is unused in all subcommands.
2021-03-13cli: run uncrustifyuncrustify
This is the result of running $ uncrustify --replace --config devel/uncrustify.cfg *.c *.h in the top level source directory Line breaks were then adjusted manually to keep argc and argv together.
2021-02-06cli/tag: convert to new config framework.David Bremner
In addition to changing configuration access, change talloc context for allocation.
2021-02-06CLI: add (unused) database argument to subcommands.David Bremner
This will allow transitioning individual subcommands to the new configuration framework. Eventually when they are all converted we can remove the notmuch_config_t * argument. For now, live with the parameter shadowing in some some subcommands; it will go away when they are converted.
2017-10-09cli: convert notmuch_bool_t to stdboolJani Nikula
C99 stdbool turned 18 this year. There really is no reason to use our own, except in the library interface for backward compatibility. Convert the cli and test binaries to stdbool.
2017-10-04cli: use designated initializers for opt descJani Nikula
Several changes at once, just to not have to change the same lines several times over: - Use designated initializers to initialize opt desc arrays. - Only initialize the needed fields. - Remove arg_id (short options) as unused. - Replace opt_type and output_var with several type safe output variables, where the output variable being non-NULL determines the type. Introduce checks to ensure only one is set. The downside is some waste of const space per argument; this could be saved by retaining opt_type and using a union, but that's still pretty verbose. - Fix some variables due to the type safety. Mostly a good thing, but leads to some enums being changed to ints. This is pedantically correct, but somewhat annoying. We could also cast, but that defeats the purpose a bit. - Terminate the opt desc arrays using {}. The output variable type safety and the ability to add new fields for just some output types or arguments are the big wins. For example, if we wanted to add a variable to set when the argument is present, we could do so for just the arguments that need it. Beauty is in the eye of the beholder, but I think this looks nice when defining the arguments, and reduces some of the verbosity we have there.
2017-08-30cppcheck: close files during shutdownDavid Bremner
Fix the following cppcheck errors: notmuch-count.c:207: error: Resource leak: input notmuch-tag.c:238: error: Resource leak: input We know that the program is shutting down here, but it does no harm to clean up a bit.
2017-03-22lib: replace deprecated n_q_search_messages with status returning versionDavid Bremner
This function was deprecated in notmuch 0.21. We re-use the name for a status returning version, and deprecate the _st name.
2016-06-05Use https instead of http where possibleDaniel Kahn Gillmor
Many of the external links found in the notmuch source can be resolved using https instead of http. This changeset addresses as many as i could find, without touching the e-mail corpus or expected outputs found in tests.
2015-11-19cli: Allow combining --remove-all and --batchDaniel Schoepe
This patch removes the restriction on notmuch-tag that disallows using both --remove-all and --batch. Combining the two options removes tags on all messages affected by each query before applying the new tags.
2015-09-23cli: convert remainder of CLI to n_q_search_{messages,threads}_stDavid Bremner
I think it would be no real problem to cut and paste the gdb based error message test from count to the other clients modified here, but I'm not currently convinced it's worth the trouble since the code path being tested is almost the the same, and the tests are relatively heavyweight.
2015-08-14cli: add global option "--uuid"David Bremner
The function notmuch_exit_if_unmatched_db_uuid is split from notmuch_process_shared_options because it needs an open notmuch database. There are two exceptional cases in uuid handling. 1) notmuch config and notmuch setup don't currently open the database, so it doesn't make sense to check the UUID. 2) notmuch compact opens the database inside the library, so we either need to open the database just to check uuid, or change the API.
2015-06-01cli: define shared options, use for --help and --versionDavid Bremner
Unfortunately it seems trickier to support --config globally The non-trivial changes are in notmuch.c; most of the other changes consists of blindly inserting two lines into every subcommand.
2015-05-31cli: change "setup" to "set up" where used as a verbJ. Lewis Muir
The word "setup" is a noun, not a verb. Change occurrences of "setup" where used as a verb to "set up".
2014-01-18cli: clean up exit status code returned by the cli commandsJani Nikula
Apart from the status codes for format mismatches, the non-zero exit status codes have been arbitrary. Make the cli consistently return either EXIT_SUCCESS or EXIT_FAILURE.
2013-06-29tag-util: move out 'tag' command-line checkPeter Wang
Move an error condition specific to the 'tag' command out of parse_tag_command_line so that parse_tag_command_line can be used for the forthcoming 'insert' command.
2013-03-30cli: add --remove-all option to "notmuch tag"Jani Nikula
Add --remove-all option to "notmuch tag" to remove all tags from the messages matching query before applying the tag changes. This allows removal of all tags and unconditional setting of the tags of a message: $ notmuch tag --remove-all id:foo@example.com $ notmuch tag --remove-all +foo +bar id:foo@example.com without having to resort to the complicated (and still quoting broken): $ notmuch tag $(notmuch search --output=tags '*' | sed 's/^/-/') \ id:foo@example.com $ notmuch tag $(notmuch search --output=tags '*' | sed 's/^/-/') \ +foo +bar id:foo@example.com
2013-03-30cli: make caller check tag count in parse_tag_command_lineJani Nikula
2013-03-08cli: move config open/close to main() from subcommandsJani Nikula
This allows specifying config file as a top level argument to notmuch, and generally makes it possible to override config file options in main(), without having to touch the subcommands. If the config file does not exist, one will be created for the notmuch main command and setup and help subcommands. Help is special in this regard; the config is created just to avoid errors about missing config, but it will not be saved. This also makes notmuch config the talloc context for subcommands.
2013-03-07cli: config: make notmuch_config_open() "is new" parameter input onlyJani Nikula
We now have a notmuch_config_is_new() function to query whether a config was created or not. Change the notmuch_config_open() is_new parameter into boolean create_new to determine whether the function should create a new config if one doesn't exist. This reduces the complexity of the API.
2013-01-19notmuch-tag: initialize with enum instead of 0David Bremner
This is just a cosmetic fix to make the "type" of ret more clear.
2013-01-14cli: propagate batch tagging warnings to exit valueTomi Ollila
In case last input for batch tagging was either invalid or skippable line, notmuch command exited with non-zero value. After this change if there is at least one invalid line, notmuch command will exit with non-zero value. Additionally, skipped lines (last or other) doesn't cause non-zero value to be returned.
2013-01-09cli: bail out and propagate tagging errors in notmuch tagJani Nikula
Checking and propagating tag_op_list_apply() errors is especially important with batch tagging, as the processing of the batch input would not stop otherwise. Additionally this sets the exit code, which is useful in scripts. Amended by: David Bremner
2013-01-07cli: add support for batch tagging operations to "notmuch tag"Jani Nikula
Add support for batch tagging operations through stdin to "notmuch tag". This can be enabled with the new --batch command line option to "notmuch tag". The input must consist of lines of the format: +<tag>|-<tag> [...] [--] <query> [...] Each line is interpreted similarly to "notmuch tag" command line arguments. The delimiter is one or more spaces ' '. Any characters in <tag> MAY be hex encoded with %NN where NN is the hexadecimal value of the character. Any ' ' and '%' characters in <tag> and MUST be hex encoded (using %20 and %25, respectively). For future-proofing, any '"' characters in <tag> SHOULD be hex-encoded. Any characters that are not part of <tag> or MUST NOT be hex encoded. <query> is passed verbatim to Xapian Leading and trailing space ' ' is ignored. Empty lines and lines beginning with '#' are ignored. Signed-off-by: Jani Nikula <jani@nikula.org> Hacked-like-crazy-by: David Bremner <david@tethera.net>
2013-01-07notmuch-tag.c: convert to use tag-utilDavid Bremner
Command line parsing is factored out into a function parse_tag_command_line in tag-util.c. There is some duplicated code eliminated in tag_query, and a bunch of translation from using the bare tag_op structs to using that tag-utils API.
2013-01-06util: Factor out boolean term quoting routineAustin Clements
This is now a generic boolean term quoting function. It performs minimal quoting to produce user-friendly queries. This could live in tag-util as well, but it is really nothing specific to tags (although the conventions are specific to Xapian). The API is changed from "caller-allocates" to "readline-like". The scan for max tag length is pushed down into the quoting routine. Furthermore, this now combines the term prefix with the quoted term; arguably this is just as easy to do in the caller, but this will nicely parallel the boolean term parsing function to be introduced shortly. This is an amalgamation of code written by David Bremner and myself.
2012-11-16notmuch-tag: tidy formattingDavid Bremner
This is just the result of running uncrustify.
2012-10-27tag: Disallow adding malformed tags to messagesAustin Clements
This disallows adding empty tags, since nothing but confusion follows in their wake, and disallows adding tags that begin with "-" because they are also confusing, the tag "-" is impossible to remove using the CLI, and because the syntax for removing such tags conflicts with long argument syntax. This does not place any restrictions on what tags can be removed, as that would make it difficult for people who have the misfortune of already having malformed tags to remove these tags.
2012-05-05lib/cli: Make notmuch_database_open return a status codeAustin Clements
It has been a long-standing issue that notmuch_database_open doesn't return any indication of why it failed. This patch changes its prototype to return a notmuch_status_t and set an out-argument to the database itself, like other functions that return both a status and an object. In the interest of atomicity, this also updates every use in the CLI so that notmuch still compiles. Since this patch does not update the bindings, the Python bindings test fails.
2012-04-28Use notmuch_database_destroy instead of notmuch_database_closeJustus Winter
Adapt the notmuch binaries source to the notmuch_database_close split. Signed-off-by: Justus Winter <4winter@informatik.uni-hamburg.de>
2012-03-30cli: refactor "notmuch tag" query tagging into a separate functionJani Nikula
Refactor to make tagging code easier to reuse in the future. No functional changes. Signed-off-by: Jani Nikula <jani@nikula.org>
2012-03-30cli: refactor "notmuch tag" data structures for tagging operationsJani Nikula
To simplify code, keep all tagging operations in a single array instead of separate add and remove arrays. Apply tag changes in the order specified on the command line, instead of first removing and then adding the tags. This results in a minor functional change: If a tag is both added and removed, the last specified operation is now used. Previously the tag was always added. Change the relevant test to reflect the new behaviour. Signed-off-by: Jani Nikula <jani@nikula.org>
2012-02-08tag: remove unused attribute from notmuch_tag_command() argumentsDmitry Kurochkin
Argc and argv arguments are used in notmuch_tag_command() function. So unused attribute is not appropriate for them.
2012-01-21Silence buildbot warnings about unused resultsAustin Clements
This ignores the results of the two writes in sigint handlers even harder than before. While my libc lacks the declarations that trigger these warnings, this can be tested by adding the following to notmuch.h: __attribute__((warn_unused_result)) ssize_t write(int fd, const void *buf, size_t count);
2011-12-21notmuch: Quiet buildbot warnings.David Edmondson
Cast away the result of various *write functions. Provide a default value for some variables to avoid "use before set" warnings.
2011-11-28tag: Automatically limit to messages whose tags will actually change.Austin Clements
This optimizes the user's tagging query to exclude messages that won't be affected by the tagging operation, saving computation and IO for redundant tagging operations. For example, notmuch tag +notmuch to:notmuch@notmuchmail.org will now use the query ( to:notmuch@notmuchmail.org ) and (not tag:"notmuch") In the past, we've often suggested that people do this exact transformation by hand for slow tagging operations. This makes that unnecessary.
2011-10-22cli: change argument parsing convention for subcommandsDavid Bremner
previously we deleted the subcommand name from argv before passing to the subcommand. In this version, the deletion is done in the actual subcommands. Although this causes some duplication of code, it allows us to be more flexible about how we parse command line arguments in the subcommand, including possibly using off-the-shelf routines like getopt_long that expect the name of the command in argv[0].
2011-05-11Remove some variables which were set but not used.Carl Worth
gcc (at least as of version 4.6.0) is kind enough to point these out to us, (when given -Wunused-but-set-variable explicitly or implicitly via -Wunused or -Wall). One of these cases was a legitimately unused variable. Two were simply variables (named ignored) we were assigning only to squelch a warning about unused function return values. I don't seem to be getting those warnings even without setting the ignored variable. And the gcc docs. say that the correct way to squelch that warning is with a cast to (void) anyway.
2010-11-11lib: Rework interface for maildir_flags synchronizationCarl Worth
Instead of having an API for setting a library-wide flag for synchronization (notmuch_database_set_maildir_sync) we instead implement maildir synchronization with two new library functions: notmuch_message_maildir_flags_to_tags and notmuch_message_tags_to_maildir_flags These functions are nicely documented here, (though the implementation does not quite match the documentation yet---as plainly evidenced by the current results of the test suite).
2010-11-11Avoid abbreviation, preferring notmuch_config_get_maildir_synchronize_flagsCarl Worth
Since the name of the configuration parameter here is: maildir.synchronize_flags the convention is that the functions to get and set this parameter should match it in name. Hence: notmuch_config_get_maildir_synchronize_flags etc. (as opposed to notmuch_config_get_maildir_sync).
2010-11-10Make maildir synchronization configurableMichal Sojka
This adds group [maildir] and key 'synchronize_flags' to the configuration file. Its value enables (true) or diables (false) the synchronization between notmuch tags and maildir flags. By default, the synchronization is disabled.
2010-04-21notmuch-tag: don't sort messages before applying tag changesSebastian Spaeth
It's not neccessary to sort the results before we apply tags. Xapian contributor Olly Betts says that savings might be bigger with a cold file cache and (as unsorted implies really sorted by document id) a better cache locality when applying tags to messages. Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
2010-03-09lib: Rename iterator functions to prepare for reverse iteration.Carl Worth
We rename 'has_more' to 'valid' so that it can function whether iterating in a forward or reverse direction. We also rename 'advance' to 'move_to_next' to setup parallel naming with the proposed functions 'move_to_first', 'move_to_last', and 'move_to_previous'.
2009-12-01Avoid compiler warnings due to ignored write return valuesDirk-Jan C. Binnema
Glibc (at least) provides the warn_unused_result attribute on write, (if optimizing and _FORTIFY_SOURCE is defined). So we explicitly ignore the return value in our signal handler, where we couldn't do anything anyway. Compile with: make CFLAGS="-O -D_FORTIFY_SOURCE" before this commit to see the warning.
2009-11-23lib/query: Drop the first and max_messages arguments from search_messages.Carl Worth
These only existed to support the chunky-searching hack, but that was recently dropped anyway.
2009-11-21Rename NOTMUCH_DATABASE_MODE_WRITABLE to NOTMUCH_DATABASE_MODE_READ_WRITECarl Worth
And correspondingly, READONLY to READ_ONLY.
2009-11-21Permit opening the notmuch database in read-only mode.Chris Wilson
We only rarely need to actually open the database for writing, but we always create a Xapian::WritableDatabase. This has the effect of preventing searches and like whilst updating the index. Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk> Acked-by: Carl Worth <cworth@cworth.org>