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 13BED429E41 for ; Thu, 24 Oct 2013 08:19:29 -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 ZlePl1tjfEBZ for ; Thu, 24 Oct 2013 08:19:24 -0700 (PDT) Received: from dmz-mailsec-scanner-8.mit.edu (dmz-mailsec-scanner-8.mit.edu [18.7.68.37]) by olra.theworths.org (Postfix) with ESMTP id CAE22429E42 for ; Thu, 24 Oct 2013 08:19:19 -0700 (PDT) X-AuditID: 12074425-b7f1c8e0000009c7-ea-52693a7472ef Received: from mailhub-auth-3.mit.edu ( [18.9.21.43]) by dmz-mailsec-scanner-8.mit.edu (Symantec Messaging Gateway) with SMTP id 57.31.02503.47A39625; Thu, 24 Oct 2013 11:19:16 -0400 (EDT) Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11]) by mailhub-auth-3.mit.edu (8.13.8/8.9.2) with ESMTP id r9OFJE6a030431; Thu, 24 Oct 2013 11:19:15 -0400 Received: from drake.dyndns.org (216-15-114-40.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com [216.15.114.40]) (authenticated bits=0) (User authenticated as amdragon@ATHENA.MIT.EDU) by outgoing.mit.edu (8.13.8/8.12.4) with ESMTP id r9OFJCvY012905 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); Thu, 24 Oct 2013 11:19:14 -0400 Received: from amthrax by drake.dyndns.org with local (Exim 4.77) (envelope-from ) id 1VZMgq-0006dh-Kp; Thu, 24 Oct 2013 11:19:12 -0400 From: Austin Clements To: notmuch@notmuchmail.org Subject: [PATCH v2 00/11] Fix search tagging races Date: Thu, 24 Oct 2013 11:19:00 -0400 Message-Id: <1382627951-25252-1-git-send-email-amdragon@mit.edu> X-Mailer: git-send-email 1.8.4.rc3 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrDIsWRmVeSWpSXmKPExsUixCmqrVtilRlksPituEXTdGeL1XN5LK7f nMnswOyxc9Zddo9b91+zezxbdYs5gDmKyyYlNSezLLVI3y6BK2Pdv27Wgm6Viocv+hgbGNtl uxg5OCQETCSaprh2MXICmWISF+6tZ+ti5OIQEtjHKLFscxsjhLORUaK1+T47SJWQwB0mie8f ZSEScxkl3hzfwgySYBPQkNi2fzkjiC0iIC2x8+5sVhCbWUBPYsvDzWC2sICRxPwrr8BqWARU JdreQwzlFXCQePGsgQ3iDCWJhae2sU5g5F3AyLCKUTYlt0o3NzEzpzg1Wbc4OTEvL7VI10Iv N7NELzWldBMjKFDYXVR3ME44pHSIUYCDUYmHt+FTepAQa2JZcWXuIUZJDiYlUd57pplBQnxJ +SmVGYnFGfFFpTmpxYcYJTiYlUR4p+kB5XhTEiurUovyYVLSHCxK4ry3OOyDhATSE0tSs1NT C1KLYLIyHBxKErz/LIEaBYtS01Mr0jJzShDSTBycIMN5gIbfA6nhLS5IzC3OTIfIn2JUlBLn 5QXGopAASCKjNA+uFxbJrxjFgV4R5v0A0s4DTAJw3a+ABjMBDZ6yJA1kcEkiQkqqgZF5zqO2 4u47i3bNO5jxSuH30+OKQcc3nz4YZr557Zu39xzTt7A53lU9K3eL+3nvqf9aGh8K/dhsT7H1 1qx7z3VzQeeCpvqXPcy8p8oyTnw/LhvdvyPvw/Kd3ilSm+pufhMQzjwf69Qe4Be730GtR8l4 hdzGU2tSXGoMEmosX9cw/w52WuS/I0qJpTgj0VCLuag4EQBndZoOvwIAAA== 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: Thu, 24 Oct 2013 15:19:29 -0000 This is v2 of id:1381185201-25197-1-git-send-email-amdragon@mit.edu. It fixes several comments from Mark and Jani. This has been rebased on top of the tag completion changes, so doing * from a large search buffer will no longer crash. Hence, this series depends on the (currently pending) series in id:1382487721-31776-1-git-send-email-amdragon@mit.edu. This version does not address what happens when you * on a search buffer that's still filling. With this series, it will apply to all messages that have appeared when the user finishes entering tag changes. This isn't ideal, but this seems pretty obscure and I'm not sure what the right answer is, so I'm punting it to the future. Another thing that may be worth changing in a follow-up is what messages * applies to. Currently, * applies *only* to matched messages, not all threads in the search, which I think was an accident of implementation. This series retains that behavior, but opens up the possibility of applying to all threads instead. I think that would be much more consistent and less surprising behavior. An approximate diff from v1 is below. This diff is prior to rebasing, since the post-rebase diff is not useful. diff --git a/emacs/notmuch-tag.el b/emacs/notmuch-tag.el index a4eec14..36937fb 100644 --- a/emacs/notmuch-tag.el +++ b/emacs/notmuch-tag.el @@ -242,7 +242,11 @@ 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) +(defconst notmuch-tag-argument-limit 1000 + "Use batch tagging if the tagging query is longer than this. + +This limits the length of arguments passed to the notmuch CLI to +avoid system argument length limits and performance problems.") (defun notmuch-tag (query &optional tag-changes) "Add/remove tags in TAG-CHANGES to messages matching QUERY. @@ -276,7 +280,6 @@ notmuch-after-tag-hook will be run." ;; 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) (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 diff --git a/notmuch-client.h b/notmuch-client.h index 1b14910..8bc1a2a 100644 --- a/notmuch-client.h +++ b/notmuch-client.h @@ -144,7 +144,8 @@ chomp_newline (char *str) #define NOTMUCH_FORMAT_MIN 1 /* The minimum non-deprecated structured output format version. * Requests for format versions below this will print a stern warning. - * Must be >= NOTMUCH_FORMAT_MIN and < NOTMUCH_FORMAT_CUR. + * Must be between NOTMUCH_FORMAT_MIN and NOTMUCH_FORMAT_CUR, + * inclusive. */ #define NOTMUCH_FORMAT_MIN_ACTIVE 1 diff --git a/notmuch-search.c b/notmuch-search.c index 1d14651..7c973b3 100644 --- a/notmuch-search.c +++ b/notmuch-search.c @@ -53,13 +53,13 @@ sanitize_string (const void *ctx, const char *str) * NULL. */ static int get_thread_query (notmuch_thread_t *thread, - char **matched_out, char **unmached_out) + char **matched_out, char **unmatched_out) { notmuch_messages_t *messages; char *escaped = NULL; size_t escaped_len = 0; - *matched_out = *unmached_out = NULL; + *matched_out = *unmatched_out = NULL; for (messages = notmuch_thread_get_messages (thread); notmuch_messages_valid (messages); @@ -69,17 +69,16 @@ get_thread_query (notmuch_thread_t *thread, const char *mid = notmuch_message_get_message_id (message); /* Determine which query buffer to extend */ char **buf = notmuch_message_get_flag ( - message, NOTMUCH_MESSAGE_FLAG_MATCH) ? matched_out : unmached_out; - /* Allocate the query buffer is this is the first message */ - if (!*buf && (*buf = talloc_strdup (thread, "")) == NULL) - return -1; + message, NOTMUCH_MESSAGE_FLAG_MATCH) ? matched_out : unmatched_out; /* Add this message's id: query. Since "id" is an exclusive * prefix, it is implicitly 'or'd together, so we only need to * join queries with a space. */ if (make_boolean_term (thread, "id", mid, &escaped, &escaped_len) < 0) return -1; - *buf = talloc_asprintf_append_buffer ( - *buf, "%s%s", **buf ? " " : "", escaped); + if (*buf) + *buf = talloc_asprintf_append_buffer (*buf, " %s", escaped); + else + *buf = talloc_strdup (thread, escaped); if (!*buf) return -1; }