From: David Bremner <david@tethera.net>
To: notmuch@notmuchmail.org
Subject: [PATCH 2/2] WIP: support tag --output=lastmod
Date: Thu, 27 Jan 2022 19:07:40 -0400 [thread overview]
Message-ID: <20220127230740.1576802-3-david@tethera.net> (raw)
In-Reply-To: <20220127230740.1576802-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 | 20 +++++++++++++++-----
test/T150-tagging.sh | 28 ++++++++++++++++++++++++++++
2 files changed, 43 insertions(+), 5 deletions(-)
diff --git a/notmuch-tag.c b/notmuch-tag.c
index c6ac51d2..f7344b8d 100644
--- a/notmuch-tag.c
+++ b/notmuch-tag.c
@@ -124,12 +124,13 @@ _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;
int ret = NOTMUCH_STATUS_SUCCESS;
@@ -159,6 +160,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, NULL);
+ }
+
for (;
notmuch_messages_valid (messages) && ! interrupted;
notmuch_messages_move_to_next (messages)) {
@@ -171,12 +176,17 @@ tag_query (void *ctx, notmuch_database_t *notmuch, const char *query_string,
notmuch_query_destroy (query);
+ if (output == OUTPUT_LASTMOD) {
+ unsigned long after = notmuch_database_get_revision (notmuch, NULL);
+ printf ("lastmod:%lu..%lu\n", 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 +219,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 +324,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..27b28e1e 100755
--- a/test/T150-tagging.sh
+++ b/test/T150-tagging.sh
@@ -53,6 +53,18 @@ output=$(notmuch tag --output=none +tag7 '*' 2>&1)
notmuch tag -tag7 '*'
test_expect_equal "$output" ""
+test_begin_subtest "--output=lastmod produces range"
+output=$(notmuch tag --output=lastmod +tag7 '*' | sed 's/[0-9][0-9]*/num/g' )
+notmuch tag -tag7 '*'
+test_expect_equal "$output" "lastmod:num..num"
+
+test_begin_subtest "--output=lastmod provides undo"
+notmuch dump > BEFORE
+tag=${RANDOM}
+range=$(notmuch tag --output=lastmod "+$tag" '*')
+notmuch tag "-$tag" "$range"
+notmuch dump > AFTER
+test_expect_equal_file BEFORE AFTER
test_begin_subtest "Remove all"
notmuch tag --remove-all One
@@ -118,6 +130,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 +170,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 > ranges
+paste -d ' ' restore.in ranges | 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
prev parent reply other threads:[~2022-01-27 23:08 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-27 23:07 WIP: add --output=lastmod to notmuch tag David Bremner
2022-01-27 23:07 ` [PATCH 1/2] cli/tag: add --output={none,lastmod} argument David Bremner
2022-01-27 23:07 ` David Bremner [this message]
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=20220127230740.1576802-3-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).