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
_______________________________________________
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-leave@notmuchmail.org