From: David Bremner <david@tethera.net>
To: notmuch@notmuchmail.org
Subject: [PATCH 1/3] lib/sexp: provide relative lastmod queries
Date: Sun, 14 Aug 2022 12:02:57 -0300 [thread overview]
Message-ID: <20220814150259.517361-1-david@tethera.net> (raw)
Test the relatively trivial logic changes for the sexp query parser
first before refactoring that logic to share with the infix query
parser.
---
doc/man7/notmuch-sexp-queries.rst | 3 +++
lib/parse-sexp.cc | 6 ++++++
test/T081-sexpr-search.sh | 30 ++++++++++++++++++++++++++++++
test/T570-revision-tracking.sh | 8 ++++++++
4 files changed, 47 insertions(+)
diff --git a/doc/man7/notmuch-sexp-queries.rst b/doc/man7/notmuch-sexp-queries.rst
index d28f40bb..422154c7 100644
--- a/doc/man7/notmuch-sexp-queries.rst
+++ b/doc/man7/notmuch-sexp-queries.rst
@@ -125,6 +125,9 @@ bounds. Either upper or lower bound may be specified as ``""`` or
``*`` to specify the lowest possible lower bound or highest possible
upper bound.
+``lastmod`` ranges support negative arguments, interpreted relative to
+the most recent database revision (see :option:`count --lastmod`).
+
.. _field-table:
.. table:: Fields with supported modifiers
diff --git a/lib/parse-sexp.cc b/lib/parse-sexp.cc
index 0f14d8b7..e9ef4268 100644
--- a/lib/parse-sexp.cc
+++ b/lib/parse-sexp.cc
@@ -575,6 +575,9 @@ _sexp_parse_range (notmuch_database_t *notmuch, const _sexp_prefix_t *prefix,
return NOTMUCH_STATUS_BAD_QUERY_SYNTAX;
}
+ if (from_idx < 0)
+ from_idx += notmuch_database_get_revision (notmuch, NULL);
+
try {
if (EMPTY_STRING (to))
to_idx = LONG_MAX;
@@ -585,6 +588,9 @@ _sexp_parse_range (notmuch_database_t *notmuch, const _sexp_prefix_t *prefix,
return NOTMUCH_STATUS_BAD_QUERY_SYNTAX;
}
+ if (to_idx < 0)
+ to_idx += notmuch_database_get_revision (notmuch, NULL);
+
output = Xapian::Query (Xapian::Query::OP_VALUE_RANGE, NOTMUCH_VALUE_LAST_MOD,
Xapian::sortable_serialise (from_idx),
Xapian::sortable_serialise (to_idx));
diff --git a/test/T081-sexpr-search.sh b/test/T081-sexpr-search.sh
index ce6b11b6..0c7db9c2 100755
--- a/test/T081-sexpr-search.sh
+++ b/test/T081-sexpr-search.sh
@@ -934,6 +934,14 @@ notmuch search lastmod:$revision..$revision | notmuch_search_sanitize > EXPECTED
notmuch search --query=sexp "(and (lastmod $revision))" | notmuch_search_sanitize > OUTPUT
test_expect_equal_file EXPECTED OUTPUT
+test_begin_subtest "lastmod query, one argument (negative)"
+notmuch tag +4EFC743A.3060609@april.org id:4EFC743A.3060609@april.org
+revision=$(notmuch count --lastmod '*' | cut -f3)
+revision1=$((revision - 1))
+notmuch search lastmod:$revision1..$revision1 | notmuch_search_sanitize > EXPECTED
+notmuch search --query=sexp "(lastmod -1)" | notmuch_search_sanitize > OUTPUT
+test_expect_equal_file_nonempty EXPECTED OUTPUT
+
test_begin_subtest "lastmod query, two arguments"
notmuch tag +keithp from:keithp
revision2=$(notmuch count --lastmod '*' | cut -f3)
@@ -941,16 +949,38 @@ notmuch search lastmod:$revision..$revision2 | notmuch_search_sanitize > EXPECTE
notmuch search --query=sexp "(and (lastmod $revision $revision2))" | notmuch_search_sanitize > OUTPUT
test_expect_equal_file EXPECTED OUTPUT
+test_begin_subtest "lastmod query, two arguments, first negative"
+revdiff=$((revision2 - revision))
+notmuch search lastmod:$revision..$revision2 | notmuch_search_sanitize > EXPECTED
+notmuch search --query=sexp "(lastmod -$revdiff $revision2)" | notmuch_search_sanitize > OUTPUT
+test_expect_equal_file EXPECTED OUTPUT
+
+test_begin_subtest "lastmod query, two arguments, second negative"
+revdiff=$((revision2 - revision))
+notmuch search lastmod:..$revision | notmuch_search_sanitize > EXPECTED
+notmuch search --query=sexp "(lastmod 0 -$revdiff)" | notmuch_search_sanitize > OUTPUT
+test_expect_equal_file EXPECTED OUTPUT
+
test_begin_subtest "lastmod query, lower bound only"
notmuch search lastmod:$revision.. | notmuch_search_sanitize > EXPECTED
notmuch search --query=sexp "(lastmod $revision \"\")" | notmuch_search_sanitize > OUTPUT
test_expect_equal_file_nonempty EXPECTED OUTPUT
+test_begin_subtest "lastmod query, lower bound only (negative)"
+notmuch search lastmod:$revision.. | notmuch_search_sanitize > EXPECTED
+notmuch search --query=sexp "(lastmod -$revdiff \"\")" | notmuch_search_sanitize > OUTPUT
+test_expect_equal_file_nonempty EXPECTED OUTPUT
+
test_begin_subtest "lastmod query, upper bound only"
notmuch search lastmod:..$revision2 | notmuch_search_sanitize > EXPECTED
notmuch search --query=sexp "(lastmod \"\" $revision2)" | notmuch_search_sanitize > OUTPUT
test_expect_equal_file_nonempty EXPECTED OUTPUT
+test_begin_subtest "lastmod query, upper bound only (negative)"
+notmuch search lastmod:..$revision | notmuch_search_sanitize > EXPECTED
+notmuch search --query=sexp "(lastmod \"\" -$revdiff)" | notmuch_search_sanitize > OUTPUT
+test_expect_equal_file_nonempty EXPECTED OUTPUT
+
test_begin_subtest "lastmod query, lower bound only, using *"
notmuch search lastmod:$revision.. | notmuch_search_sanitize > EXPECTED
notmuch search --query=sexp "(lastmod $revision *)" | notmuch_search_sanitize > OUTPUT
diff --git a/test/T570-revision-tracking.sh b/test/T570-revision-tracking.sh
index e1cc684d..aaa45468 100755
--- a/test/T570-revision-tracking.sh
+++ b/test/T570-revision-tracking.sh
@@ -95,4 +95,12 @@ subtotal=$(notmuch count lastmod:..$lastmod)
result=$(($subtotal == $total-1))
test_expect_equal 1 "$result"
+if [ $NOTMUCH_HAVE_SFSEXP -eq 1 ]; then
+ test_begin_subtest 'exclude one message using negative lastmod (sexp)'
+ total=$(notmuch count '*')
+ notmuch tag +${RANDOM} id:4EFC743A.3060609@april.org
+ count=$(notmuch count --query=sexp '(lastmod -1 *)')
+ test_expect_equal 1 "$count"
+fi
+
test_done
--
2.35.1
next reply other threads:[~2022-08-14 15:03 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-14 15:02 David Bremner [this message]
2022-08-14 15:02 ` [PATCH 2/3] lib: factor out lastmod range handling from sexp parser David Bremner
2022-08-14 15:02 ` [PATCH 3/3] lib: add field processor for lastmod: prefix David Bremner
2022-09-03 11:49 ` [PATCH 1/3] lib/sexp: provide relative lastmod queries 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=20220814150259.517361-1-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).