From: David Edmondson Date: Wed, 21 May 2014 10:47:23 +0000 (+0100) Subject: Re: [PATCH] emacs: make sure tagging on an empty query is harmless X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=a3144ce1b92b802e2a7312894ec9ffa011f98270;p=notmuch-archives.git Re: [PATCH] emacs: make sure tagging on an empty query is harmless --- diff --git a/48/19a1b47f75db096af476216ecf7b9321453289 b/48/19a1b47f75db096af476216ecf7b9321453289 new file mode 100644 index 000000000..550c771ee --- /dev/null +++ b/48/19a1b47f75db096af476216ecf7b9321453289 @@ -0,0 +1,177 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by olra.theworths.org (Postfix) with ESMTP id DB1D3431FCB + for ; Wed, 21 May 2014 03:47:36 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: -0.7 +X-Spam-Level: +X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 + tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled +Received: from olra.theworths.org ([127.0.0.1]) + by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id Tfyz5r-Saq7U for ; + Wed, 21 May 2014 03:47:32 -0700 (PDT) +Received: from mail-wi0-f169.google.com (mail-wi0-f169.google.com + [209.85.212.169]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id E0CC8431FC7 + for ; Wed, 21 May 2014 03:47:31 -0700 (PDT) +Received: by mail-wi0-f169.google.com with SMTP id hi2so8232030wib.4 + for ; Wed, 21 May 2014 03:47:29 -0700 (PDT) +X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; + d=1e100.net; s=20130820; + h=x-gm-message-state:to:cc:subject:in-reply-to:references:user-agent + :from:date:message-id:mime-version:content-type; + bh=wsw89nD/+Xn1rzy3UkihdIVKMNw7TRbtvzH9343IWIY=; + b=FFVYwZfk61wBAP6CGd4uPKDFC5iZCAmxzLmhuCcKGPIfuC5+ChvBdHdZOQ8vqbz8/R + 6Hb3aC6C8MPGqr5AcT/JdPjArya7cs8iqyhcnX6xc+4Fo8B+lkVItHdd/TosVxZ3uaGf + gg2O+lUFPztdYM8d+LHBo01NHXXO2r9quxlGRMrmHj9oI9liilqV7FSa0r5bTEWxoy7z + fjNnMHzgr4zd0fBUBPjiGjYcO7I3xBth6MMSXOkm8nVT+Asnm6EjymsJPw+XHmpVKd2I + Z5PqG28SWAGA6vL+mitWsUa+dkfc8yRmEyHCcMmlPHj8P0HsU5Yv6sZRGNUukPEN0gqp + m4LQ== +X-Gm-Message-State: + ALoCoQkfoA+Sqoanex8SVUYxQpv86/URsjfxfQlWfayGBj5Gw+wGZeYxUQ7Ts5jgR9Ppnab+5QAG +X-Received: by 10.194.187.107 with SMTP id fr11mr1552816wjc.70.1400669249358; + Wed, 21 May 2014 03:47:29 -0700 (PDT) +Received: from localhost ([2a01:348:1a2:1:a288:b4ff:fe8a:77d8]) + by mx.google.com with ESMTPSA id l4sm22093993wjf.14.2014.05.21.03.47.27 + for + (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); + Wed, 21 May 2014 03:47:28 -0700 (PDT) +To: Mark Walters , notmuch@notmuchmail.org +Subject: Re: [PATCH] emacs: make sure tagging on an empty query is harmless +In-Reply-To: <1400666330-4363-1-git-send-email-markwalters1009@gmail.com> +References: <87iop0ynl2.fsf@qmul.ac.uk> + <1400666330-4363-1-git-send-email-markwalters1009@gmail.com> +User-Agent: Notmuch/0.18 (http://notmuchmail.org) Emacs/24.3.1 + (x86_64-pc-linux-gnu) +From: David Edmondson +Date: Wed, 21 May 2014 11:47:23 +0100 +Message-ID: +MIME-Version: 1.0 +Content-Type: multipart/signed; boundary="=-=-="; + micalg=pgp-sha1; protocol="application/pgp-signature" +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.13 +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: Wed, 21 May 2014 10:47:37 -0000 + +--=-=-= +Content-Type: text/plain +Content-Transfer-Encoding: quoted-printable + +On Wed, May 21 2014, Mark Walters wrote: +> Currently notmuch-tag throws a "wrong-type-argument stringp nil" if +> passed a nil query-string. Catch this and provide a more useful error +> message. This fixes a case in notmuch-tree (if you try to tag when at +> the end of the buffer). +> +> Secondly, as pointed out by David (dme) +> `notmuch-search-find-stable-query-region' can return the query string +> () if there are no messages in the region. This gets passed to notmuch +> tag, and due to interactions in the optimize_query code in +> notmuch-tag.c becomes, in the case tag-change is -inbox, "( () ) and +> (tag:inbox)". This query matches some strange collection of messages +> which then get archived. This should probably be fixed, but in any +> case make `notmuch-search-find-stable-query-region' return a nil +> query-string in this case. +> +> This avoids data-loss (random tag removal) in this case. +> --- +> +> This is my attempt to solve the same problem as the parent. I prefer +> not throwing an error in n.s.f.s.q.r as it is difficult for the caller +> to catch cleanly. Throwing it in notmuch-tag is fine as the caller can +> trivially check for query-string being nil before calling notmuch-tag +> if it wants to deal with it gracefully. +> +> If people do prefer an error in n.s.f.s.q.r as in the parent patch +> then I think we should update the error message. The first hunk of +> this should also be applied to catch nil queries to notmuch-tag gracefull= +y. + +I'm fine with this approach. + +> Although this has been present for a while I think it is a dataloss +> issue so a fix should go in for 0.18.1 + +As someone who has had to reconstruct a couple of times after being +bitten by this, I would agree. + +> Best wishes +> +> Mark +> +> +> +> +> emacs/notmuch-tag.el | 2 ++ +> emacs/notmuch.el | 6 ++++-- +> 2 files changed, 6 insertions(+), 2 deletions(-) +> +> diff --git a/emacs/notmuch-tag.el b/emacs/notmuch-tag.el +> index 07c260e..f54aa9d 100644 +> --- a/emacs/notmuch-tag.el +> +++ b/emacs/notmuch-tag.el +> @@ -387,6 +387,8 @@ (defun notmuch-tag (query tag-changes) +> (unless (string-match-p "^[-+]\\S-+$" tag-change) +> (error "Tag must be of the form `+this_tag' or `-that_tag'"))) +> tag-changes) +> + (unless query +> + (error "Nothing to tag!")) +> (unless (null tag-changes) +> (run-hooks 'notmuch-before-tag-hook) +> (if (<=3D (length query) notmuch-tag-argument-limit) +> diff --git a/emacs/notmuch.el b/emacs/notmuch.el +> index 6c0bc1b..1adea9c 100644 +> --- a/emacs/notmuch.el +> +++ b/emacs/notmuch.el +> @@ -428,14 +428,16 @@ (defun notmuch-search-find-stable-query-region (beg= + end &optional only-matched) +> "Return the stable query for the current region. +>=20=20 +> If ONLY-MATCHED is non-nil, include only matched messages. If it +> -is nil, include both matched and unmatched messages." +> +is nil, include both matched and unmatched messages. If there are +> +no messages in the region then return nil." +> (let ((query-list nil) (all (not only-matched))) +> (dolist (queries (notmuch-search-properties-in-region :query beg end= +)) +> (when (first queries) +> (push (first queries) query-list)) +> (when (and all (second queries)) +> (push (second queries) query-list))) +> - (concat "(" (mapconcat 'identity query-list ") or (") ")"))) +> + (when query-list +> + (concat "(" (mapconcat 'identity query-list ") or (") ")")))) +>=20=20 +> (defun notmuch-search-find-authors () +> "Return the authors for the current thread" +> --=20 +> 1.7.10.4 + +--=-=-= +Content-Type: application/pgp-signature; name="signature.asc" + +-----BEGIN PGP SIGNATURE----- +Version: GnuPG v1 + +iKYEARECAGYFAlN8hDtfFIAAAAAALgAoaXNzdWVyLWZwckBub3RhdGlvbnMub3Bl +bnBncC5maWZ0aGhvcnNlbWFuLm5ldDc1M0Y5NDJDMEExNjc3MDE4OURGMUYyMDY5 +RUNEMEFCRjA0OTY1MTYACgkQaezQq/BJZRbTSgCfTWVy50oKivVSuv+yxAEbssCh +wZgAn3Gy1ONB1wkLpN+xBZLKLHXwJdog +=JHTn +-----END PGP SIGNATURE----- +--=-=-=--