From a134d13794c6f743c844b39c1dbc5f25e33eea60 Mon Sep 17 00:00:00 2001 From: David Bremner Date: Fri, 5 Jun 2015 19:28:38 +0200 Subject: [PATCH] [PATCH 6/6] lib: Add "lastmod:" queries for filtering by last modification --- f8/dde1297741f227505eca33233639a71184c7b6 | 157 ++++++++++++++++++++++ 1 file changed, 157 insertions(+) create mode 100644 f8/dde1297741f227505eca33233639a71184c7b6 diff --git a/f8/dde1297741f227505eca33233639a71184c7b6 b/f8/dde1297741f227505eca33233639a71184c7b6 new file mode 100644 index 000000000..0d09a6d95 --- /dev/null +++ b/f8/dde1297741f227505eca33233639a71184c7b6 @@ -0,0 +1,157 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by arlo.cworth.org (Postfix) with ESMTP id 2C3BA6DE1785 + for ; Fri, 5 Jun 2015 10:31:40 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at cworth.org +X-Spam-Flag: NO +X-Spam-Score: 0.234 +X-Spam-Level: +X-Spam-Status: No, score=0.234 tagged_above=-999 required=5 tests=[AWL=0.224, + T_HEADER_FROM_DIFFERENT_DOMAINS=0.01] autolearn=disabled +Received: from arlo.cworth.org ([127.0.0.1]) + by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id aRPszRHIhMQF for ; + Fri, 5 Jun 2015 10:31:38 -0700 (PDT) +Received: from mx.xen14.node3324.gplhost.com (gitolite.debian.net + [87.98.215.224]) + by arlo.cworth.org (Postfix) with ESMTPS id 0EFC06DE18DF + for ; Fri, 5 Jun 2015 10:31:38 -0700 (PDT) +Received: from remotemail by mx.xen14.node3324.gplhost.com with local (Exim + 4.80) (envelope-from ) + id 1Z0vRM-0002nr-CN; Fri, 05 Jun 2015 17:29:56 +0000 +Received: (nullmailer pid 24258 invoked by uid 1000); Fri, 05 Jun 2015 + 17:28:42 -0000 +From: David Bremner +To: notmuch@notmuchmail.org +Subject: [PATCH 6/6] lib: Add "lastmod:" queries for filtering by last + modification +Date: Fri, 5 Jun 2015 19:28:38 +0200 +Message-Id: <1433525318-23756-7-git-send-email-david@tethera.net> +X-Mailer: git-send-email 2.1.4 +In-Reply-To: <1433525318-23756-1-git-send-email-david@tethera.net> +References: <1432936375-astroid-4-0i1n6yczs2-1520@strange> + <1433525318-23756-1-git-send-email-david@tethera.net> +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.18 +Precedence: list +List-Id: "Use and development of the notmuch mail system." + +List-Unsubscribe: , + +List-Archive: +List-Post: +List-Help: +List-Subscribe: , + +X-List-Received-Date: Fri, 05 Jun 2015 17:31:40 -0000 + +From: Austin Clements + +The implementation is essentially the same as the date range search +prior to Jani's fancy date parser. +--- + doc/man7/notmuch-search-terms.rst | 8 ++++++++ + lib/database-private.h | 1 + + lib/database.cc | 4 ++++ + test/T570-revision-tracking.sh | 18 ++++++++++++++++++ + 4 files changed, 31 insertions(+) + +diff --git a/doc/man7/notmuch-search-terms.rst b/doc/man7/notmuch-search-terms.rst +index 1d27ac1..d9f213e 100644 +--- a/doc/man7/notmuch-search-terms.rst ++++ b/doc/man7/notmuch-search-terms.rst +@@ -54,6 +54,8 @@ indicate user-supplied values): + + - date:.. + ++- lastmod:.. ++ + The **from:** prefix is used to match the name or address of the sender + of an email message. + +@@ -124,6 +126,12 @@ The time range can also be specified using timestamps with a syntax of: + Each timestamp is a number representing the number of seconds since + 1970-01-01 00:00:00 UTC. + ++The **lastmod:** prefix can be used to restrict the result by the ++database revision number of when messages were last modified (tags ++were added/removed or filenames changed). This is usually used in ++conjunction with the **--db-revision** argument to **notmuch search** ++to find messages that have changed since an earlier query. ++ + Operators + --------- + +diff --git a/lib/database-private.h b/lib/database-private.h +index 4e93257..3fb10f7 100644 +--- a/lib/database-private.h ++++ b/lib/database-private.h +@@ -176,6 +176,7 @@ struct _notmuch_database { + Xapian::TermGenerator *term_gen; + Xapian::ValueRangeProcessor *value_range_processor; + Xapian::ValueRangeProcessor *date_range_processor; ++ Xapian::ValueRangeProcessor *last_mod_range_processor; + }; + + /* Prior to database version 3, features were implied by the database +diff --git a/lib/database.cc b/lib/database.cc +index ba8b8d9..a7daa44 100644 +--- a/lib/database.cc ++++ b/lib/database.cc +@@ -986,6 +986,7 @@ notmuch_database_open_verbose (const char *path, + notmuch->term_gen->set_stemmer (Xapian::Stem ("english")); + notmuch->value_range_processor = new Xapian::NumberValueRangeProcessor (NOTMUCH_VALUE_TIMESTAMP); + notmuch->date_range_processor = new ParseTimeValueRangeProcessor (NOTMUCH_VALUE_TIMESTAMP); ++ notmuch->last_mod_range_processor = new Xapian::NumberValueRangeProcessor (NOTMUCH_VALUE_LAST_MOD, "lastmod:"); + + notmuch->query_parser->set_default_op (Xapian::Query::OP_AND); + notmuch->query_parser->set_database (*notmuch->xapian_db); +@@ -993,6 +994,7 @@ notmuch_database_open_verbose (const char *path, + notmuch->query_parser->set_stemming_strategy (Xapian::QueryParser::STEM_SOME); + notmuch->query_parser->add_valuerangeprocessor (notmuch->value_range_processor); + notmuch->query_parser->add_valuerangeprocessor (notmuch->date_range_processor); ++ notmuch->query_parser->add_valuerangeprocessor (notmuch->last_mod_range_processor); + + for (i = 0; i < ARRAY_SIZE (BOOLEAN_PREFIX_EXTERNAL); i++) { + prefix_t *prefix = &BOOLEAN_PREFIX_EXTERNAL[i]; +@@ -1071,6 +1073,8 @@ notmuch_database_close (notmuch_database_t *notmuch) + notmuch->value_range_processor = NULL; + delete notmuch->date_range_processor; + notmuch->date_range_processor = NULL; ++ delete notmuch->last_mod_range_processor; ++ notmuch->last_mod_range_processor = NULL; + + return status; + } +diff --git a/test/T570-revision-tracking.sh b/test/T570-revision-tracking.sh +index bb09bf6..7ad8b2a 100755 +--- a/test/T570-revision-tracking.sh ++++ b/test/T570-revision-tracking.sh +@@ -72,4 +72,22 @@ test_expect_success 'tag succeeds with correct db revision' \ + + test_expect_code 1 'tag fails with incorrect db revision' \ + "notmuch show --db-revision=this-is-no-uuid '*' +test2" ++ ++test_begin_subtest 'lastmod:0.. matches everything' ++total=$(notmuch count '*') ++modtotal=$(notmuch count lastmod:0..) ++test_expect_equal "$total" "$modtotal" ++ ++test_begin_subtest 'lastmod:1000000.. matches nothing' ++modtotal=$(notmuch count lastmod:1000000..) ++test_expect_equal 0 "$modtotal" ++ ++test_begin_subtest 'exclude one message using lastmod' ++lastmod=$(notmuch count --output=modifications '*' | cut -f2) ++total=$(notmuch count '*') ++notmuch tag +4EFC743A.3060609@april.org id:4EFC743A.3060609@april.org ++subtotal=$(notmuch count lastmod:..$lastmod) ++result=$(($subtotal == $total-1)) ++test_expect_equal 1 "$result" ++ + test_done +-- +2.1.4 + -- 2.26.2