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 2C28A431FD0 for ; Sun, 3 Jul 2011 10:17:58 -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 bwy0xnHscZbu for ; Sun, 3 Jul 2011 10:17:56 -0700 (PDT) Received: from dmz-mailsec-scanner-4.mit.edu (DMZ-MAILSEC-SCANNER-4.MIT.EDU [18.9.25.15]) by olra.theworths.org (Postfix) with ESMTP id F0BCF431FB6 for ; Sun, 3 Jul 2011 10:17:55 -0700 (PDT) X-AuditID: 1209190f-b7c82ae000000a20-4f-4e10a448440e Received: from mailhub-auth-2.mit.edu ( [18.7.62.36]) by dmz-mailsec-scanner-4.mit.edu (Symantec Messaging Gateway) with SMTP id C7.34.02592.844A01E4; Sun, 3 Jul 2011 13:18:00 -0400 (EDT) Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103]) by mailhub-auth-2.mit.edu (8.13.8/8.9.2) with ESMTP id p63HHsIx021268; Sun, 3 Jul 2011 13:17:55 -0400 Received: from awakening.csail.mit.edu (awakening.csail.mit.edu [18.26.4.91]) (authenticated bits=0) (User authenticated as amdragon@ATHENA.MIT.EDU) by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id p63HHrnC027795 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); Sun, 3 Jul 2011 13:17:54 -0400 (EDT) Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.72) (envelope-from ) id 1QdQIh-0001AG-Mb; Sun, 03 Jul 2011 13:17:43 -0400 Date: Sun, 3 Jul 2011 13:17:43 -0400 From: Austin Clements To: Pieter Praet Subject: Re: [PATCH 2/2] [RFC] possible solution for "Race condition for '*' command" Message-ID: <20110703171743.GL15901@mit.edu> References: <87zkkwydag.fsf@praet.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87zkkwydag.fsf@praet.org> User-Agent: Mutt/1.5.20 (2009-06-14) X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprAKsWRmVeSWpSXmKPExsUixG6nouuxRMDPYM1VaYvrN2cyW/x+fYPZ gcnj2apbzB4d+y6zBjBFcdmkpOZklqUW6dslcGXsO7uBpeCKccXMdUuZGxjXa3QxcnJICJhI PP6/nRHCFpO4cG89WxcjF4eQwD5Gidm/JjJBOOsZJX7PbIByTjBJTOv6BuUsAcqsbGYF6WcR UJF4ev0fG4jNJqAhsW3/crC5IgLKEqef/GQHsZkFpCW+/W5mArGFBcIlpn54BlbPK6Aj8erV HrB6IYFciecf/rBDxAUlTs58wgLRqyVx499LoF4OsDnL/3GAhDkF1CWWf9oHVi4KdMK1/e1s ExiFZiHpnoWkexZC9wJG5lWMsim5Vbq5iZk5xanJusXJiXl5qUW6Jnq5mSV6qSmlmxhBgc0p yb+D8dtBpUOMAhyMSjy8DJME/IRYE8uKK3MPMUpyMCmJ8qotBgrxJeWnVGYkFmfEF5XmpBYf YpTgYFYS4T1QBZTjTUmsrEotyodJSXOwKInzlnv/9xUSSE8sSc1OTS1ILYLJynBwKEnw5oIM FSxKTU+tSMvMKUFIM3FwggznARq+AKSGt7ggMbc4Mx0if4pRl2PN2keHGYVY8vLzUqXEeZtA igRAijJK8+DmwBLSK0ZxoLeEeWeBVPEAkxncpFdAS5iAlmTm84IsKUlESEk1MC52aDlooHEl qKlW2bLy00W12DPypiUVzrd2iPr9O3BrdfPNJ6tj59T/KxZeWmX1wu7/pFiGre45Wyb8uSCg Yemd8+uL9eKSTRek7yxvPzDfxeDVfMvpVQeYzn3LvGaz8vLR2ckpP5bNvXxEOi8+u8/RLLPw xqa1u9a35Z/kT9G89DzRY7ols6MSS3FGoqEWc1FxIgBs/DhsIwMAAA== Cc: notmuch@notmuchmail.org 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: Sun, 03 Jul 2011 17:17:58 -0000 Quoth Pieter Praet on Jul 02 at 4:20 pm: > On Fri, 1 Jul 2011 12:37:11 -0400, Austin Clements wrote: > Non-text part: multipart/alternative > > On Jul 1, 2011 10:55 AM, "Austin Clements" wrote: > > > > > > On Thu, Jun 30, 2011 at 3:38 PM, Pieter Praet wrote: > > > > Ok, even though my very first reply [1] may have created the impression > > > > that I understood the issue, I clearly didn't... > > > > > > > > The test [2] needs a more applicable commit message, and the subsequent > > > > patch [3] points more or less in the right direction, but the Message-Id > > > > list should be local to the *search buffer* rather than to the > > > > `notmuch-search-operate-all' function. > > > > > > > > `notmuch-search' could: > > > > - run "notmuch-command search" with the "--output=messages" option > > > > instead of a plain search, > > > > - maintain a buffer-local var with a list of returned Message-Id's, > > > > - ...and populate the buffer based on that list. > > > > > > > > As such we'd have -for each individual search buffer- a canonical list > > > > of Message-Id's (i.e. messages which actually *match* the query AND are > > > > currently visible in the search buffer), to be used by > > > > `notmuch-search-operate-all' et al. > > > > > > > > > > > > Peace > > > > > > > > > > > > [1] id:"87fwmuxxgd.fsf@praet.org" > > > > [2] id:"1309450108-2793-2-git-send-email-pieter@praet.org" > > > > [3] id:"1309450108-2793-1-git-send-email-pieter@praet.org" > > > > > > Ideally, this wouldn't be per-buffer, but per *line*. This race > > > equally affects adding and removing tags from individual results, > > > since that's done using a thread: query, whose results could have > > > changed since the original search. > > > > > > This almost certainly requires support from the notmuch core. The > > > good news is that the library already provides this information, so > > > there will be virtually no performance hit for outputting it. > > > > Actually, with a smidgeon of library support, you could even use document > > IDs for this, rather than message IDs, which would make the tagging > > operations (even '*') no more expensive than they are now. (Of course, it > > would be good to know just how much overhead going through message IDs > > actually introduces.) > Non-text part: text/html > > > That would be awesome! > > Though I'd rather leave the plumbing to someone sufficiently capable, > so, if leaving libnotmuch hacking out of the equation, how would one go > about doing this? > > I (ignorantly) assume we'd get `notmuch-search-process-filter' > to append each line with an invisible field containing a list > of matching Message-Id's, presumably obtained via > `notmuch_thread_get_matched_messages' (@ lib/thread.cc) ? Here's a super-hacky patch that adds an "id:x or id:y or ..." query string to the end of each search line, right after the list of tags. This is just the C side; care to prototype the elisp side? I also added a --stdin argument to notmuch tag that'll read the query string from stdin, since these queries could get very long (though ARG_MAX appears to be 2 megs these days, so maybe this wasn't necessary for prototyping). diff --git a/notmuch-search.c b/notmuch-search.c index faccaf7..65fe438 100644 --- a/notmuch-search.c +++ b/notmuch-search.c @@ -190,6 +190,23 @@ format_thread_json (const void *ctx, talloc_free (ctx_quote); } +static void +show_message_ids (notmuch_messages_t *messages, notmuch_bool_t first) +{ + notmuch_message_t *message; + + for (; + notmuch_messages_valid (messages); + notmuch_messages_move_to_next (messages)) { + if (!first) + fputs (" or ", stdout); + first = FALSE; + message = notmuch_messages_get (messages); + printf ("id:\"%s\"", notmuch_message_get_message_id (message)); + show_message_ids (notmuch_message_get_replies (message), FALSE); + } +} + static int do_search_threads (const search_format_t *format, notmuch_query_t *query, @@ -252,6 +269,12 @@ do_search_threads (const search_format_t *format, fputs (format->tag_end, stdout); + if (format == &format_text) { + notmuch_messages_t *toplevel = notmuch_thread_get_toplevel_messages (thread); + fputs (" ", stdout); + show_message_ids (toplevel, TRUE); + } + fputs (format->item_end, stdout); } diff --git a/notmuch-tag.c b/notmuch-tag.c index 6204ae3..5609d02 100644 --- a/notmuch-tag.c +++ b/notmuch-tag.c @@ -30,6 +30,36 @@ handle_sigint (unused (int sig)) interrupted = 1; } +static char* +query_string_from_stdin (void *ctx) +{ + char *query_string = talloc_strdup (ctx, ""); + char buf[4096]; + + if (query_string == NULL) { + fprintf (stderr, "Out of memory.\n"); + return NULL; + } + + while (1) { + ssize_t r = read(0, buf, sizeof (buf)); + if (r < 0) { + fprintf (stderr, "Error reading from stdin: %s\n", + strerror (errno)); + return NULL; + } else if (r == 0) { + break; + } + query_string = talloc_strndup_append (query_string, buf, r); + if (!query_string) { + fprintf (stderr, "Out of memory.\n"); + return NULL; + } + } + + return query_string; +} + int notmuch_tag_command (void *ctx, unused (int argc), unused (char *argv[])) { @@ -44,6 +74,7 @@ notmuch_tag_command (void *ctx, unused (int argc), unused (char *argv[])) notmuch_message_t *message; struct sigaction action; notmuch_bool_t synchronize_flags; + notmuch_bool_t use_stdin = FALSE; int i; /* Setup our handler for SIGINT */ @@ -70,7 +101,9 @@ notmuch_tag_command (void *ctx, unused (int argc), unused (char *argv[])) i++; break; } - if (argv[i][0] == '+') { + if (STRNCMP_LITERAL (argv[i], "--stdin") == 0) { + use_stdin = TRUE; + } else if (argv[i][0] == '+') { add_tags[add_tags_count++] = i; } else if (argv[i][0] == '-') { remove_tags[remove_tags_count++] = i; @@ -84,7 +117,13 @@ notmuch_tag_command (void *ctx, unused (int argc), unused (char *argv[])) return 1; } - query_string = query_string_from_args (ctx, argc - i, &argv[i]); + if (use_stdin) + query_string = query_string_from_stdin (ctx); + else + query_string = query_string_from_args (ctx, argc - i, &argv[i]); + + if (!query_string) + return 1; if (*query_string == '\0') { fprintf (stderr, "Error: notmuch tag requires at least one search term.\n");