From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id gHBsOa4O+WLVUwEAbAwnHQ (envelope-from ) for ; Sun, 14 Aug 2022 17:03:11 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id UBNoOa4O+WIfLgAA9RJhRA (envelope-from ) for ; Sun, 14 Aug 2022 17:03:10 +0200 Received: from mail.notmuchmail.org (yantan.tethera.net [135.181.149.255]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 7438921EB7 for ; Sun, 14 Aug 2022 17:03:10 +0200 (CEST) Received: from yantan.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 06D3C5E020; Sun, 14 Aug 2022 15:03:07 +0000 (UTC) Received: from fethera.tethera.net (fethera.tethera.net [IPv6:2607:5300:60:c5::1]) by mail.notmuchmail.org (Postfix) with ESMTP id 77FFF5DC06 for ; Sun, 14 Aug 2022 15:03:04 +0000 (UTC) Received: by fethera.tethera.net (Postfix, from userid 1001) id 459595FBC0; Sun, 14 Aug 2022 11:03:03 -0400 (EDT) Received: (nullmailer pid 517375 invoked by uid 1000); Sun, 14 Aug 2022 15:03:02 -0000 From: David Bremner To: notmuch@notmuchmail.org Subject: [PATCH 1/3] lib/sexp: provide relative lastmod queries Date: Sun, 14 Aug 2022 12:02:57 -0300 Message-Id: <20220814150259.517361-1-david@tethera.net> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 Message-ID-Hash: WCRASB5XQNII56ENTO4L7YJBSQ4AB4CS X-Message-ID-Hash: WCRASB5XQNII56ENTO4L7YJBSQ4AB4CS X-MailFrom: bremner@tethera.net X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-notmuch.notmuchmail.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.3 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_IN X-Migadu-To: larch@yhetil.org X-Migadu-Country: DE ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1660489390; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding:list-id:list-help: list-owner:list-unsubscribe:list-subscribe:list-post; bh=dov/ev1Yu+5Lsy8FL1+SiJpe2ESyGWotZyu6RaJ9mPg=; b=eI1XrFgYd+FJCSVG35ega/2x4lr3PnRwS97z/CU4h3CWSxaSj0CpBdBuP7CdtkEJjW6+cS SVabZLZVKveRu8xsHH+jeOGQWDVf0jumuYX/L5S0rWIXvPo4U7fHtjuMZZ3POdbouQ8tY1 JhvOZUogSBGzNzi8fxFFh+YkFiVv0/NZQDdgQvOn6g3nYy8gxhVADzfS2if4bLLCewlaOw XGRUz61kTymg3fwoM50ITx5IpZpc1Mv7oHtOIB/Sdmt7avhwqnLRQClDU9m0io8Ec4smO4 3bfgVHDDEZ27Uybwqt3XFhU+YAmbQOp9N3rHMtr9mhvRUrrEt8dvu+n3Pl6uiQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1660489390; a=rsa-sha256; cv=none; b=NQcmqUyO5760SlyK178ljDKsJrfB/dfPtUwqWOI/Hd5j0KzEg+ag/xcVL1brS9atuPrxFf RhEYwoicpTxQfXF3mxDJXo0cmxiGep8V3tgUzbJpoWwCZfgPp6QIZttGJnp5bOW6V99tli aXyWfBWtE2ZJ2ZAnwi6uvoX6NsmMXZ7ABo7/OgQkc9O26Js+1JuLN/flw3ltWj7oOUN/mE 53bNiwybfY/veztY/heqNDoRhhmNr3rYn4Y6ZqU2PKSe1xlb0obMX9cwA/bMwI42cwkRzZ L4P+nHpaim/VnSvtTWyouH7XoNqFMiq7kK9xRGBB+XifzadnZGO6wvNZqb7lwA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 135.181.149.255 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Spam-Score: -1.82 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 135.181.149.255 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Queue-Id: 7438921EB7 X-Spam-Score: -1.82 X-Migadu-Scanner: scn0.migadu.com X-TUID: p+D9A4jHrpLs 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