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 ms5.migadu.com with LMTPS id YHNQMdkCZGIVIQEAbAwnHQ (envelope-from ) for ; Sat, 23 Apr 2022 15:44:57 +0200 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 ePJPMdkCZGIHbQEAauVa8A (envelope-from ) for ; Sat, 23 Apr 2022 15:44:57 +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 7464214ED0 for ; Sat, 23 Apr 2022 15:44:57 +0200 (CEST) Received: from yantan.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 159985F764; Sat, 23 Apr 2022 13:39:05 +0000 (UTC) Received: from fethera.tethera.net (fethera.tethera.net [IPv6:2607:5300:60:c5::1]) by mail.notmuchmail.org (Postfix) with ESMTP id C8FE05F756 for ; Sat, 23 Apr 2022 13:39:01 +0000 (UTC) Received: by fethera.tethera.net (Postfix, from userid 1001) id 02C3F5FC01; Sat, 23 Apr 2022 09:39:00 -0400 (EDT) Received: (nullmailer pid 3856569 invoked by uid 1000); Sat, 23 Apr 2022 13:38:57 -0000 From: David Bremner To: notmuch@notmuchmail.org Subject: [PATCH 10/16] CLI/git: replace enumeration of tags with sexp query. Date: Sat, 23 Apr 2022 10:38:42 -0300 Message-Id: <20220423133848.3852688-11-david@tethera.net> X-Mailer: git-send-email 2.35.2 In-Reply-To: <20220423133848.3852688-1-david@tethera.net> References: <20220423133848.3852688-1-david@tethera.net> MIME-Version: 1.0 Message-ID-Hash: A6DQ7FL7HXECLSQTORLFOTVK6AYK7UCL X-Message-ID-Hash: A6DQ7FL7HXECLSQTORLFOTVK6AYK7UCL 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=1650721497; 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=QIxjj1MbssKUPlnraoWMiTwF9chckVgySHSXCBLpoQc=; b=aT+w9aZcP53EtBcCwdWp/KTxFovWhyK9hsULUZyJV5qwTmof5snes93MwshfWZ9y9mhyYw QkYFZuccDLv9KnThTQctQB4qthZ3tfURAXKK5ca4djF9osX3eW/5uebEle2x7J85FJOMBA c0Z5RUWf3lLecM+4f6HAruiapMC2VNxJpyiykVylJ2jTsZUMHXgRI0+OgCiBw18ux//yvi +nGU8rIxrl43+7RLMZuvGTBVpDmEwB31+/cijQdcZvVAKiQzQ9hCtqvrEO9AstkNIwsCxx ctFBH8W6SvVnTiuCMhe/F7sxl9e+IbehI/u4fpi7hFr4fxB7B/k5oZ76FdsFqw== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1650721497; a=rsa-sha256; cv=none; b=OiuH1oXXmdfU0KrSy4IJTOresl3uqjU8ZiTtmxpap6Ni1kIMAc9OCd1rIi2h7sVjyu6W40 e7ZyiiacDB6vEVRxZKDXz+NGUjRRPPzs0QMviU4u80m+q1vJ9cRS8MKWI+rBowTNuz8VNN hYP9St+IyYjdozHIZuyBVpXzSaxlPSqCldFX8SeEqmSDCvNauOHt9aGGDlnMtB9k6JHuXQ zNjCm2wYVlMG0f0KtvLJz3y1u/S++86T7x4wnR1Pyk+HI2dUw2LqBgBQnt5xUs7gIkOEGM 7JMztYDEYoDTae1UCyheIMF3pqwdaSFDrQZycm+2/2hkecVhyIA7gGXzU/WytQ== 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: 6.23 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: 7464214ED0 X-Spam-Score: 6.23 X-Migadu-Scanner: scn1.migadu.com X-TUID: MjVqwUqMpOM5 Unlike the (current) infix query parser provided by Xapian, the notmuch specific sexp query parser supports prefixed wildcard queries, so use those. In addition to being somewhat faster, this avoids needing to escape all of the user's tags to pass via the shell. --- notmuch-git.in | 23 ++++++++++++++++------- test/T850-git.sh | 6 +++++- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/notmuch-git.in b/notmuch-git.in index 8b397080..d8b7e45b 100755 --- a/notmuch-git.in +++ b/notmuch-git.in @@ -258,16 +258,17 @@ def _get_remote(): stdout=_subprocess.PIPE, wait=True) return remote.strip() +def _tag_query(prefix=None): + if prefix is None: + prefix = TAG_PREFIX + return '(tag (starts-with "{:s}"))'.format(prefix.replace('"','\\\"')) def get_tags(prefix=None): "Get a list of tags with a given prefix." - if prefix is None: - prefix = TAG_PREFIX (status, stdout, stderr) = _spawn( - args=['notmuch', 'search', '--output=tags', '*'], + args=['notmuch', 'search', '--query=sexp', '--output=tags', _tag_query(prefix)], stdout=_subprocess.PIPE, wait=True) - return [tag for tag in stdout.splitlines() if tag.startswith(prefix)] - + return [tag for tag in stdout.splitlines()] def archive(treeish='HEAD', args=()): """ @@ -623,13 +624,12 @@ def get_status(): def _index_tags(): "Write notmuch tags to the nmbug.index." path = _os.path.join(NMBGIT, 'nmbug.index') - query = ' '.join('tag:"{tag}"'.format(tag=tag) for tag in get_tags()) prefix = '+{0}'.format(_ENCODED_TAG_PREFIX) _git( args=['read-tree', '--empty'], additional_env={'GIT_INDEX_FILE': path}, wait=True) with _spawn( - args=['notmuch', 'dump', '--format=batch-tag', '--', query], + args=['notmuch', 'dump', '--format=batch-tag', '--query=sexp', '--', _tag_query()], stdout=_subprocess.PIPE) as notmuch: with _git( args=['update-index', '--index-info'], @@ -872,6 +872,15 @@ if __name__ == '__main__': level = getattr(_logging, args.log_level.upper()) _LOG.setLevel(level) + (status, stdout, stderr) = _spawn( + args=['notmuch', 'config', 'get', 'built_with.sexp_queries'], + stdout=_subprocess.PIPE, wait=True) + if status != 0: + _LOG.error("failed to run notmuch") + sys.exit(1) + if stdout != "true\n": + _LOG.error("notmuch git needs sexp query support") + if not getattr(args, 'func', None): parser.print_usage() _sys.exit(1) diff --git a/test/T850-git.sh b/test/T850-git.sh index 408a6337..4bf29b20 100755 --- a/test/T850-git.sh +++ b/test/T850-git.sh @@ -7,6 +7,11 @@ add_git_repos () { notmuch git -C tags.git -p '' clone remote.git } +if [ $NOTMUCH_HAVE_SFSEXP -ne 1 ]; then + printf "Skipping due to missing sfsexp library\n" + test_done +fi + add_email_corpus add_git_repos @@ -20,7 +25,6 @@ notmuch search --output=messages '*' | sort > EXPECTED test_expect_equal_file_nonempty EXPECTED OUTPUT test_begin_subtest "commit, with quoted tag" -test_subtest_known_broken notmuch git -C clone2.git -p '' clone tags.git git -C clone2.git ls-tree -r --name-only HEAD | grep /inbox > BEFORE notmuch tag '+"quoted tag"' '*' -- 2.35.2