From: Jani Nikula Date: Wed, 9 Oct 2013 07:18:11 +0000 (+0200) Subject: Re: [PATCH 07/11] emacs: Use notmuch tag --batch for large tag queries X-Git-Url: http://git.tremily.us/gitweb.cgi?a=commitdiff_plain;h=5bb74d882a13139673bdb34f061dc42da651b5dd;p=notmuch-archives.git Re: [PATCH 07/11] emacs: Use notmuch tag --batch for large tag queries --- diff --git a/40/a61e613fd39c1d53cdf086d6f562e08969b334 b/40/a61e613fd39c1d53cdf086d6f562e08969b334 new file mode 100644 index 000000000..ddfe9e78c --- /dev/null +++ b/40/a61e613fd39c1d53cdf086d6f562e08969b334 @@ -0,0 +1,160 @@ +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 B2697431FAF + for ; Wed, 9 Oct 2013 00:18:32 -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 K0+fiH6TNxx7 for ; + Wed, 9 Oct 2013 00:18:26 -0700 (PDT) +Received: from mail-ea0-f177.google.com (mail-ea0-f177.google.com + [209.85.215.177]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id 561A6431FAE + for ; Wed, 9 Oct 2013 00:18:26 -0700 (PDT) +Received: by mail-ea0-f177.google.com with SMTP id f15so169830eak.8 + for ; Wed, 09 Oct 2013 00:18:23 -0700 (PDT) +X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; + d=1e100.net; s=20130820; + h=x-gm-message-state:from:to:subject:in-reply-to:references + :user-agent:date:message-id:mime-version:content-type; + bh=4g+JpanAUiJWXCSMx/gDQYyGsUSocD7Fis+IhjYPD8Q=; + b=TpGFRxiL5OZ1BWZZZ6Sm1hjf+X6uz3ZcalUXD77DPXgT1sV0bn7RivD61b4h6thwWU + L/mHqVxY9s0GDjMQYnqZbT51fzr1m0zG98mIeiY1EhZhQsG+HsOjr5k8eJVt1SJ0oR75 + bxBqnwTC2s8R2cOxUTNmhKUZcDqQz+PQICfQzqLehBphXM9ujP8hxMbuzHP6QSXXzB4f + jy9NkLzYnjZ9FSvXCJ7ZhqrfA/gaFNfLlET1KkGh5rmLxRHMQjpjwwCjXGT32cUjwrYM + bTmGz05VE6X0Jv/jWt/1TSL9BDtjkcBnCgsbRT4yRgMKy0oY8yuRdRSuYidx64ryX5ew + d1Iw== +X-Gm-Message-State: + ALoCoQn89ARCUMmpEfYvAbUDl6SqNYiRxogPYe3LA3C8w7Hl+eW5AceyHEgvyIx7YvGB7pMPDioJ +X-Received: by 10.15.32.136 with SMTP id a8mr631431eev.71.1381303103805; + Wed, 09 Oct 2013 00:18:23 -0700 (PDT) +Received: from localhost ([2001:4b98:dc0:43:216:3eff:fe1b:25f3]) + by mx.google.com with ESMTPSA id + x47sm85326121eea.16.1969.12.31.16.00.00 + (version=TLSv1.1 cipher=RC4-SHA bits=128/128); + Wed, 09 Oct 2013 00:18:22 -0700 (PDT) +From: Jani Nikula +To: Austin Clements , notmuch@notmuchmail.org +Subject: Re: [PATCH 07/11] emacs: Use notmuch tag --batch for large tag + queries +In-Reply-To: <1381185201-25197-8-git-send-email-amdragon@mit.edu> +References: <1381185201-25197-1-git-send-email-amdragon@mit.edu> + <1381185201-25197-8-git-send-email-amdragon@mit.edu> +User-Agent: Notmuch/0.16+62~g9f2ae2e (http://notmuchmail.org) Emacs/23.2.1 + (x86_64-pc-linux-gnu) +Date: Wed, 09 Oct 2013 09:18:11 +0200 +Message-ID: <87iox6ap58.fsf@nikula.org> +MIME-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +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, 09 Oct 2013 07:18:32 -0000 + +On Tue, 08 Oct 2013, Austin Clements wrote: +> (Unfortunately, it's difficult to first demonstrate this problem with +> a known-broken test because modern Linux kernels have argument length +> limits in the megabytes, which makes Emacs really slow!) +> --- +> emacs/notmuch-lib.el | 8 ++++++++ +> emacs/notmuch-tag.el | 12 ++++++++++-- +> test/emacs | 8 ++++++++ +> 3 files changed, 26 insertions(+), 2 deletions(-) +> +> diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el +> index 22156f1..348112b 100644 +> --- a/emacs/notmuch-lib.el +> +++ b/emacs/notmuch-lib.el +> @@ -261,6 +261,14 @@ user-friendly queries." +> "Return a query that matches the message with id ID." +> (concat "id:" (notmuch-escape-boolean-term id))) +> +> +(defun notmuch-hex-encode (str) +> + "Hex-encode STR (e.g., as used by batch tagging). +> + +> +This replaces spaces, percents, and double quotes in STR with +> +%NN where NN is the hexadecimal value of the character." +> + (replace-regexp-in-string +> + "[ %\"]" (lambda (match) (format "%%%02x" (aref match 0))) str)) +> + +> ;; +> +> (defun notmuch-common-do-stash (text) +> diff --git a/emacs/notmuch-tag.el b/emacs/notmuch-tag.el +> index 064cfa8..a4eec14 100644 +> --- a/emacs/notmuch-tag.el +> +++ b/emacs/notmuch-tag.el +> @@ -242,6 +242,8 @@ from TAGS if present." +> (error "Changed tag must be of the form `+this_tag' or `-that_tag'"))))) +> (sort result-tags 'string<))) +> +> +(defconst notmuch-tag-argument-limit 1000) +> + +> (defun notmuch-tag (query &optional tag-changes) +> "Add/remove tags in TAG-CHANGES to messages matching QUERY. +> +> @@ -268,8 +270,14 @@ notmuch-after-tag-hook will be run." +> tag-changes) +> (unless (null tag-changes) +> (run-hooks 'notmuch-before-tag-hook) +> - (apply 'notmuch-call-notmuch-process "tag" +> - (append tag-changes (list "--" query))) +> + (if (<= (length query) notmuch-tag-argument-limit) +> + (apply 'notmuch-call-notmuch-process "tag" +> + (append tag-changes (list "--" query))) +> + ;; Use batch tag mode to avoid argument length limitations +> + (let ((batch-op (concat (mapconcat #'notmuch-hex-encode tag-changes " ") +> + " -- " query))) +> + (message "Batch tagging with %s" batch-op) + +Why the message? + +Jani. + +> + (notmuch-call-notmuch-process :stdin-string batch-op "tag" "--batch"))) +> (run-hooks 'notmuch-after-tag-hook)) +> ;; in all cases we return tag-changes as a list +> tag-changes) +> diff --git a/test/emacs b/test/emacs +> index 05295af..2917189 100755 +> --- a/test/emacs +> +++ b/test/emacs +> @@ -122,6 +122,14 @@ test_emacs "(notmuch-search \"$os_x_darwin_thread\") +> output=$(notmuch search $os_x_darwin_thread | notmuch_search_sanitize) +> test_expect_equal "$output" "thread:XXX 2009-11-18 [4/4] Jjgod Jiang, Alexander Botero-Lowry; [notmuch] Mac OS X/Darwin compatibility issues (inbox unread)" +> +> +test_begin_subtest "Add tag (large query)" +> +# We use a long query to force us into batch mode and use a funny tag +> +# that requires escaping for batch tagging. +> +test_emacs "(notmuch-tag (concat \"$os_x_darwin_thread\" \" or \" (make-string notmuch-tag-argument-limit ?x)) \"+tag-from-%-large-query\")" +> +output=$(notmuch search $os_x_darwin_thread | notmuch_search_sanitize) +> +test_expect_equal "$output" "thread:XXX 2009-11-18 [4/4] Jjgod Jiang, Alexander Botero-Lowry; [notmuch] Mac OS X/Darwin compatibility issues (inbox tag-from-%-large-query unread)" +> +notmuch tag -tag-from-%-large-query $os_x_darwin_thread +> + +> test_begin_subtest "notmuch-show: add single tag to single message" +> test_emacs "(notmuch-show \"$os_x_darwin_thread\") +> (execute-kbd-macro \"+tag-from-show-view\")" +> -- +> 1.8.4.rc3 +> +> _______________________________________________ +> notmuch mailing list +> notmuch@notmuchmail.org +> http://notmuchmail.org/mailman/listinfo/notmuch