From: David Bremner <david@tethera.net>
To: notmuch@notmuchmail.org
Subject: [RFC PATCH v2 6/8] WIP: support tag --output=lastmod
Date: Sat, 29 Jan 2022 15:44:38 -0400 [thread overview]
Message-ID: <20220129194439.2790761-7-david@tethera.net> (raw)
In-Reply-To: <20220129194439.2790761-1-david@tethera.net>
needs documentation, possibly more tests.
output format subject to change.
See the tests for examples of how this could be used in an undo facility
---
notmuch-tag.c | 25 ++++++++++++++++++++-----
test/T150-tagging.sh | 31 +++++++++++++++++++++++++++++++
2 files changed, 51 insertions(+), 5 deletions(-)
diff --git a/notmuch-tag.c b/notmuch-tag.c
index c6ac51d2..95598091 100644
--- a/notmuch-tag.c
+++ b/notmuch-tag.c
@@ -124,12 +124,14 @@ _optimize_tag_query (void *ctx, const char *orig_query_string,
*/
static int
tag_query (void *ctx, notmuch_database_t *notmuch, const char *query_string,
- tag_op_list_t *tag_ops, tag_op_flag_t flags)
+ tag_op_list_t *tag_ops, tag_op_flag_t flags, int output)
{
notmuch_query_t *query;
notmuch_messages_t *messages;
notmuch_message_t *message;
notmuch_status_t status;
+ unsigned long before;
+ const char* uuid_before = NULL;
int ret = NOTMUCH_STATUS_SUCCESS;
@@ -159,6 +161,10 @@ tag_query (void *ctx, notmuch_database_t *notmuch, const char *query_string,
if (print_status_query ("notmuch tag", query, status))
return status;
+ if (output == OUTPUT_LASTMOD) {
+ before = notmuch_database_get_revision (notmuch, &uuid_before);
+ }
+
for (;
notmuch_messages_valid (messages) && ! interrupted;
notmuch_messages_move_to_next (messages)) {
@@ -171,12 +177,21 @@ tag_query (void *ctx, notmuch_database_t *notmuch, const char *query_string,
notmuch_query_destroy (query);
+ if (output == OUTPUT_LASTMOD) {
+ const char *uuid_after = NULL;
+ unsigned long after = notmuch_database_get_revision (notmuch, &uuid_after);
+ if (strcmp (uuid_before, uuid_after))
+ INTERNAL_ERROR ("uuid changed while holding write lock %s %s", uuid_before, uuid_after);
+
+ printf ("%s\t%lu\t%lu\n", uuid_before, before + 1, after);
+ }
+
return ret || interrupted;
}
static int
tag_file (void *ctx, notmuch_database_t *notmuch, tag_op_flag_t flags,
- FILE *input)
+ FILE *input, int output)
{
char *line = NULL;
char *query_string = NULL;
@@ -209,7 +224,7 @@ tag_file (void *ctx, notmuch_database_t *notmuch, tag_op_flag_t flags,
if (ret < 0)
break;
- ret = tag_query (ctx, notmuch, query_string, tag_ops, flags);
+ ret = tag_query (ctx, notmuch, query_string, tag_ops, flags, output);
if (ret)
break;
}
@@ -314,9 +329,9 @@ notmuch_tag_command (notmuch_database_t *notmuch, int argc, char *argv[])
tag_flags |= TAG_FLAG_REMOVE_ALL;
if (batch)
- ret = tag_file (notmuch, notmuch, tag_flags, input);
+ ret = tag_file (notmuch, notmuch, tag_flags, input, output);
else
- ret = tag_query (notmuch, notmuch, query_string, tag_ops, tag_flags);
+ ret = tag_query (notmuch, notmuch, query_string, tag_ops, tag_flags, output);
notmuch_database_destroy (notmuch);
diff --git a/test/T150-tagging.sh b/test/T150-tagging.sh
index ce33dade..baf55598 100755
--- a/test/T150-tagging.sh
+++ b/test/T150-tagging.sh
@@ -53,6 +53,21 @@ output=$(notmuch tag --output=none +tag7 '*' 2>&1)
notmuch tag -tag7 '*'
test_expect_equal "$output" ""
+test_begin_subtest "--output=lastmod produces 3 columns"
+output=$(notmuch tag --output=lastmod +tag7 '*' | sed 's/[0-9a-f][0-9a-f]*/n/g' )
+notmuch tag -tag7 '*'
+test_expect_equal "$output" "n-n-n-n-n n n"
+
+test_begin_subtest "--output=lastmod provides undo"
+notmuch dump > BEFORE
+tag=${RANDOM}
+notmuch count --lastmod '*' | cut -f 2 >> BEFORE
+notmuch tag --output=lastmod "+$tag" '*' > OUTPUT
+read uuid from to < OUTPUT
+notmuch tag --uuid="$uuid" "-$tag" lastmod:"$from".."$to"
+notmuch dump > AFTER
+echo "$uuid" >> AFTER
+test_expect_equal_file BEFORE AFTER
test_begin_subtest "Remove all"
notmuch tag --remove-all One
@@ -118,6 +133,13 @@ cat > batch.in <<EOF
-tag5 +tag6 Two
EOF
+# partial input for use in undoing above changes
+cat > restore.in <<EOF
+-%40 +tag5 -tag6 --
+-tag1 +tag1 +tag4 +tag4 --
++tag5 -tag6 --
+EOF
+
cat > batch.expected <<EOF
thread:XXX 2001-01-05 [1/1] Notmuch Test Suite; One (@ inbox tag6 unread)
thread:XXX 2001-01-05 [1/1] Notmuch Test Suite; Two (inbox tag4 tag6 unread)
@@ -151,6 +173,15 @@ notmuch search \* | notmuch_search_sanitize >> OUTPUT
notmuch restore --format=batch-tag < backup.tags
test_expect_equal_file batch.expected OUTPUT
+backup_database
+test_begin_subtest "--batch --input --output=lastmod"
+notmuch dump > EXPECTED
+notmuch tag --batch --input=batch.in --output=lastmod | awk '{printf " lastmod:%d..%d\n", $2, $3}' > queries
+paste restore.in queries | notmuch tag --batch
+notmuch dump > OUTPUT
+test_expect_equal_file EXPECTED OUTPUT
+restore_database
+
test_begin_subtest "--batch --input --remove-all"
notmuch dump --format=batch-tag > backup.tags
notmuch tag +foo +bar -- One
--
2.34.1
next prev parent reply other threads:[~2022-01-29 19:46 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-29 19:44 v2 undo tag operations in emacs David Bremner
2022-01-29 19:44 ` [RFC PATCH v2 1/8] test: split variable settings to their own file David Bremner
2022-01-29 19:44 ` [RFC PATCH v2 2/8] test/emacs: split out emacs related tests David Bremner
2022-01-29 19:44 ` [RFC PATCH v2 3/8] WIP enable running test_emacs from performance tests David Bremner
2022-01-29 19:44 ` [RFC PATCH v2 4/8] perf-test: inital emacs tests David Bremner
2022-01-29 19:44 ` [RFC PATCH v2 5/8] cli/tag: add --output={none,lastmod} argument David Bremner
2022-01-29 19:44 ` David Bremner [this message]
2022-01-29 19:44 ` [RFC PATCH v2 7/8] WIP/emacs: keep tag history David Bremner
2022-01-29 19:44 ` [RFC PATCH v2 8/8] WIP: add notmuch-tag-undo David Bremner
2022-02-02 14:34 ` David Bremner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://notmuchmail.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220129194439.2790761-7-david@tethera.net \
--to=david@tethera.net \
--cc=notmuch@notmuchmail.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).