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 DC6D942119B for ; Wed, 29 Jun 2011 13:19:34 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.799 X-Spam-Level: X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_FROM=0.001, 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 Wz9t0-mK1uVB for ; Wed, 29 Jun 2011 13:19:34 -0700 (PDT) Received: from mail-iw0-f181.google.com (mail-iw0-f181.google.com [209.85.214.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 1682B421192 for ; Wed, 29 Jun 2011 13:19:34 -0700 (PDT) Received: by iwn37 with SMTP id 37so1501294iwn.26 for ; Wed, 29 Jun 2011 13:19:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=from:to:subject:in-reply-to:date:references:user-agent:message-id :mime-version:content-type; bh=ENjO6I2qYFPPIaPDbf3VByFnzPJZ0BWxyH+mjSUaHMk=; b=dMmirqkfYiJfTAp076iIOOQE9RmiKKfzyr/JzW1mC+EOpnEBKhAlHdecGt0+eRJV6z /4Oc2dPn01bZOJlEUJD/uYnLkXrBrWvdlvbXjll9s7T+B/Q5+GQlARl8NeislRXNlYA8 3pMHKf/dtI8Zbl0NeODcoJRUETmcy9u0mBBBE= Received: by 10.42.71.85 with SMTP id i21mr1134475icj.323.1309378773485; Wed, 29 Jun 2011 13:19:33 -0700 (PDT) Received: from localhost ([74.205.145.146]) by mx.google.com with ESMTPS id f13sm774812ibe.61.2011.06.29.13.19.32 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 29 Jun 2011 13:19:32 -0700 (PDT) From: Mark Anderson To: Pieter Praet , notmuch@notmuchmail.org, cworth@cworth.org Subject: [PATCH] Fix folder: coherence issue In-Reply-To: <87iprqxxp6.fsf@praet.org> Date: Wed, 29 Jun 2011 14:04:45 -0600 References: <87sjqvw64n.fsf@gmail.com> <87iprqxxp6.fsf@praet.org> User-Agent: Notmuch/0.5-283-gb744eac (http://notmuchmail.org) Emacs/23.2.1 (i686-pc-linux-gnu) Message-ID: <878vskie5p.fsf@gmail.com> 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, 29 Jun 2011 20:19:35 -0000 Add removal of all ZXFOLDER terms to removal of all XFOLDER terms for each message filename removal. The existing filename-list reindexing will put all the needed terms back in. Test search-folder-coherence now passes. Signed-off-by:Mark Anderson --- Once I fixed the removal instead of the addition side, things went smoothly. lib/message.cc | 31 ++++++++++++++++++++++++++++--- 1 files changed, 28 insertions(+), 3 deletions(-) diff --git a/lib/message.cc b/lib/message.cc index 8b9c84f..d993cde 100644 --- a/lib/message.cc +++ b/lib/message.cc @@ -514,6 +514,8 @@ _notmuch_message_remove_filename (notmuch_message_t *message, const char *folder_prefix = _find_prefix ("folder"); int folder_prefix_len = strlen (folder_prefix); void *local = talloc_new (message); + char *zfolder_prefix = talloc_asprintf(local, "Z%s", folder_prefix); + int zfolder_prefix_len = strlen (zfolder_prefix); char *direntry; notmuch_private_status_t private_status; notmuch_status_t status; @@ -530,9 +532,12 @@ _notmuch_message_remove_filename (notmuch_message_t *message, status = COERCE_STATUS (private_status, "Unexpected error from _notmuch_message_remove_term"); - /* Re-synchronize "folder:" terms for this message. This requires - * first removing all "folder:" terms, then adding back terms for - * all remaining filenames of the message. */ + /* Re-synchronize "folder:" terms for this message. This requires: + * 1. removing all "folder:" terms + * 2. removing all "folder:" stemmed terms + * 3. adding back terms for all remaining filenames of the message. */ + + /* 1. removing all "folder:" terms */ while (1) { i = message->doc.termlist_begin (); i.skip_to (folder_prefix); @@ -551,6 +556,26 @@ _notmuch_message_remove_filename (notmuch_message_t *message, } } + /* 2. removing all "folder:" stemmed terms */ + while (1) { + i = message->doc.termlist_begin (); + i.skip_to (zfolder_prefix); + + /* Terminate loop when no terms remain with desired prefix. */ + if (i == message->doc.termlist_end () || + strncmp ((*i).c_str (), zfolder_prefix, zfolder_prefix_len)) + { + break; + } + + try { + message->doc.remove_term ((*i)); + } catch (const Xapian::InvalidArgumentError) { + /* Ignore failure to remove non-existent term. */ + } + } + + /* 3. adding back terms for all remaining filenames of the message. */ i = message->doc.termlist_begin (); i.skip_to (direntry_prefix); -- 1.7.4.1