From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id +FHdI9Al82Et6QAAgWs5BA (envelope-from ) for ; Fri, 28 Jan 2022 00:08:00 +0100 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id wM65INAl82EwGwEAauVa8A (envelope-from ) for ; Fri, 28 Jan 2022 00:08:00 +0100 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 4B209157DD for ; Fri, 28 Jan 2022 00:08:00 +0100 (CET) Received: from yantan.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 36E9D5F733; Thu, 27 Jan 2022 23:07:49 +0000 (UTC) Received: from fethera.tethera.net (fethera.tethera.net [IPv6:2607:5300:60:c5::1]) by mail.notmuchmail.org (Postfix) with ESMTP id 4D2E55F722 for ; Thu, 27 Jan 2022 23:07:46 +0000 (UTC) Received: by fethera.tethera.net (Postfix, from userid 1001) id BE2D65FBD2; Thu, 27 Jan 2022 18:07:45 -0500 (EST) Received: (nullmailer pid 1576900 invoked by uid 1000); Thu, 27 Jan 2022 23:07:43 -0000 From: David Bremner To: notmuch@notmuchmail.org Subject: [PATCH 2/2] WIP: support tag --output=lastmod Date: Thu, 27 Jan 2022 19:07:40 -0400 Message-Id: <20220127230740.1576802-3-david@tethera.net> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220127230740.1576802-1-david@tethera.net> References: <20220127230740.1576802-1-david@tethera.net> MIME-Version: 1.0 Message-ID-Hash: RGMEHAQIABZNQJEH3KQTMUPG2IVJWD7W X-Message-ID-Hash: RGMEHAQIABZNQJEH3KQTMUPG2IVJWD7W 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-Country: DE ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1643324880; 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: in-reply-to:in-reply-to:references:references:list-id:list-help: list-owner:list-unsubscribe:list-subscribe:list-post; bh=FR/61kMiC2YIkO1ItwbX8UkBndRM6ozTbOfUoD7WCaI=; b=m5NfuD2Rl3BDeh8QqKYLzMalgeDwL9HvfHCcE1/MRDZSW1il/UWxR9n7tGgkiOjLVKfDrl NsidsxrJ9LUv6/onZ4KKPp06DhTG5WRSAnC7imVcFb7m3+tJ78MMlA0QH2Wtq3rKqvMcSy 33X9yvfZs8D3e6JozQcxsv0m4t05hzULlUH0TKFIlVbyNpgqFBqqs0vGY4XGYMoGU+R22q AtO977EffYtOC7fEHRhe71DEuBxxgqef+CdJTAtx7m3omNMKu9kUbPsKoJ59TXO0GcBVQc ThKvTxWH07E14FlQYWCYP4W54gTI98Y6ijcugOkyAzepVvkLxXb26aq/Povptg== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1643324880; a=rsa-sha256; cv=none; b=r0795c0g4+WYOH4nXrW9+XmGJPGHG/pkEu+ukBtYunCjzvgjSrO2LDa5J+cK3SRkR9xNT6 dMPnPYvxqZ74cqqF/NAiEZvajAMJLPxtYCTbamsXGt8WT095HfCtKNFkcsnkr+gi/JsgfK HypUl276hy4wpdwRAaxDPiXvlwpzXhd+11Zmnp/fDWWKZtUBvN7vCbdq9bU0ceUpQXIem2 6VQYNstWfceP6zMeHNyCVjZoAIct/foIRdJmOKLBXLWEIhih27MqfL7QaAGKLcS5eAVO9o wp8cPpPQBsbnkyGh29eidwlYAyLKlqUbo7Y42Lo/sQDgnlNL4zQ5T3GRbRQWNA== 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.86 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: 4B209157DD X-Spam-Score: -1.86 X-Migadu-Scanner: scn0.migadu.com X-TUID: M80tIqWaQkuj 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 < restore.in < batch.expected <> 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