1 Return-Path: <jani@nikula.org>
\r
2 X-Original-To: notmuch@notmuchmail.org
\r
3 Delivered-To: notmuch@notmuchmail.org
\r
4 Received: from localhost (localhost [127.0.0.1])
\r
5 by arlo.cworth.org (Postfix) with ESMTP id 2D7626DE1271
\r
6 for <notmuch@notmuchmail.org>; Fri, 25 Sep 2015 09:48:45 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at cworth.org
\r
11 X-Spam-Status: No, score=-0.513 tagged_above=-999 required=5 tests=[AWL=0.207,
\r
12 RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01]
\r
14 Received: from arlo.cworth.org ([127.0.0.1])
\r
15 by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)
\r
16 with ESMTP id fAQjkAqo8-uS for <notmuch@notmuchmail.org>;
\r
17 Fri, 25 Sep 2015 09:48:43 -0700 (PDT)
\r
18 Received: from mail-wi0-f173.google.com (mail-wi0-f173.google.com
\r
20 by arlo.cworth.org (Postfix) with ESMTPS id 29B626DE0B64
\r
21 for <notmuch@notmuchmail.org>; Fri, 25 Sep 2015 09:48:43 -0700 (PDT)
\r
22 Received: by wiclk2 with SMTP id lk2so29886671wic.0
\r
23 for <notmuch@notmuchmail.org>; Fri, 25 Sep 2015 09:48:41 -0700 (PDT)
\r
24 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
\r
25 d=1e100.net; s=20130820;
\r
26 h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to
\r
28 bh=bTtx3JWHo+A/OFwZ8eU8V8k7Kk1T6eVxK75jkReLZK8=;
\r
29 b=Or9VdLXF6hCHQ8DxmNXTGOisUBOkZArkyJbwDWA3BrZ5mVYBsPTupILF7Y9H+dZaYo
\r
30 4L/mtwXdO/cpl5jIa5c7UU8lUpRRDPrKZlZmYcMTc+W9ZyXyzY/HUJGT1T7WuBeaaFNq
\r
31 rk7FnTsaDBMydPOgsYabHjaenZAhwSpbuHqaAC+kwMB2mIpBfTdxGISMMSJbnGwj1x5l
\r
32 AWflv6POtfYTXPld9HTlCEIV8dZRRQ13VmRJ3mhlRAU3FPRJOIloIn0C84uVFUd2s+J/
\r
33 /CpT3aaF7PMKPGfU4GYBoo9Sipdn78AbjF3xzuKlWgiw/czsn0t1H8GV4Qc75RgXnqKe
\r
36 ALoCoQlIxvFmFLHeDfEAA/5pGeOtg2U5F2N7WKc9GmEpTYWbvJWaSgVzGtF6V0RW+JFbcxmx4ueE
\r
37 X-Received: by 10.180.107.164 with SMTP id hd4mr4754539wib.94.1443199721667;
\r
38 Fri, 25 Sep 2015 09:48:41 -0700 (PDT)
\r
39 Received: from localhost (mobile-access-bcee63-221.dhcp.inet.fi.
\r
41 by smtp.gmail.com with ESMTPSA id hk5sm4205985wjb.6.2015.09.25.09.48.40
\r
42 (version=TLSv1/SSLv3 cipher=OTHER);
\r
43 Fri, 25 Sep 2015 09:48:40 -0700 (PDT)
\r
44 From: Jani Nikula <jani@nikula.org>
\r
45 To: David Bremner <david@tethera.net>, Jani Nikula <jani@nikula.org>,
\r
46 notmuch@notmuchmail.org
\r
47 Subject: [PATCH 6/9 v3 part 2/2] cli: change the data structure for notmuch
\r
48 address deduplication
\r
49 Date: Fri, 25 Sep 2015 19:48:20 +0300
\r
50 Message-Id: <1443199700-16654-2-git-send-email-jani@nikula.org>
\r
51 X-Mailer: git-send-email 2.1.4
\r
52 In-Reply-To: <1443199700-16654-1-git-send-email-jani@nikula.org>
\r
53 References: <878u7v2y3x.fsf@zancas.localnet>
\r
54 <1443199700-16654-1-git-send-email-jani@nikula.org>
\r
55 X-BeenThere: notmuch@notmuchmail.org
\r
56 X-Mailman-Version: 2.1.18
\r
58 List-Id: "Use and development of the notmuch mail system."
\r
59 <notmuch.notmuchmail.org>
\r
60 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
61 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
62 List-Archive: <http://notmuchmail.org/pipermail/notmuch/>
\r
63 List-Post: <mailto:notmuch@notmuchmail.org>
\r
64 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
65 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
66 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
67 X-List-Received-Date: Fri, 25 Sep 2015 16:48:45 -0000
\r
69 Currently we key the address hash table with the case sensitive "name
\r
70 <address>". Switch to case insensitive keying with just address, and
\r
71 store the case sensitive name and address in linked lists. This will
\r
72 be helpful in adding support for different deduplication schemes in
\r
75 There will be a slight performance penalty for the current full case
\r
76 sensitive name + address deduplication, but this is simpler as a whole
\r
77 when other deduplication schemes are added, and I expect the schemes
\r
78 to be added to become more popular than the current default.
\r
80 Aparet from the possible performance penalty, the only user visible
\r
81 change should be the change in the output ordering for
\r
82 --output=count. The order is not guaranteed (and is based on hash
\r
83 table traversal) currently anyway, so this should be of no
\r
88 v3: abstract strcmp_null
\r
90 notmuch-client.h | 1 +
\r
91 notmuch-search.c | 80 +++++++++++++++++++++++++++++++++++++++++++++-----------
\r
92 2 files changed, 66 insertions(+), 15 deletions(-)
\r
94 diff --git a/notmuch-client.h b/notmuch-client.h
\r
95 index de8a3b15f865..3bd2903ec54a 100644
\r
96 --- a/notmuch-client.h
\r
97 +++ b/notmuch-client.h
\r
98 @@ -48,6 +48,7 @@ typedef GMimeCryptoContext notmuch_crypto_context_t;
\r
101 #include <signal.h>
\r
102 +#include <ctype.h>
\r
104 #include "talloc-extra.h"
\r
106 diff --git a/notmuch-search.c b/notmuch-search.c
\r
107 index 966c310f8f18..6cac0fcdc1df 100644
\r
108 --- a/notmuch-search.c
\r
109 +++ b/notmuch-search.c
\r
110 @@ -265,30 +265,70 @@ static mailbox_t *new_mailbox (void *ctx, const char *name, const char *addr)
\r
114 +static int mailbox_compare (const void *v1, const void *v2)
\r
116 + const mailbox_t *m1 = v1, *m2 = v2;
\r
119 + ret = strcmp_null (m1->name, m2->name);
\r
121 + ret = strcmp (m1->addr, m2->addr);
\r
126 /* Returns TRUE iff name and addr is duplicate. If not, stores the
\r
127 * name/addr pair in order to detect subsequent duplicates. */
\r
128 static notmuch_bool_t
\r
129 is_duplicate (const search_context_t *ctx, const char *name, const char *addr)
\r
133 mailbox_t *mailbox;
\r
135 - key = talloc_asprintf (ctx->format, "%s <%s>", name, addr);
\r
138 + list = g_hash_table_lookup (ctx->addresses, addr);
\r
140 + mailbox_t find = {
\r
145 + l = g_list_find_custom (list, &find, mailbox_compare);
\r
147 + mailbox = l->data;
\r
148 + mailbox->count++;
\r
152 + mailbox = new_mailbox (ctx->format, name, addr);
\r
156 - mailbox = g_hash_table_lookup (ctx->addresses, key);
\r
158 - mailbox->count++;
\r
159 - talloc_free (key);
\r
162 + * XXX: It would be more efficient to prepend to the list, but
\r
163 + * then we'd have to store the changed list head back to the
\r
164 + * hash table. This check is here just to avoid the compiler
\r
165 + * warning for unused result.
\r
167 + if (list != g_list_append (list, mailbox))
\r
168 + INTERNAL_ERROR ("appending to list changed list head\n");
\r
173 + key = talloc_strdup (ctx->format, addr);
\r
177 mailbox = new_mailbox (ctx->format, name, addr);
\r
181 - g_hash_table_insert (ctx->addresses, key, mailbox);
\r
182 + list = g_list_append (NULL, mailbox);
\r
186 + g_hash_table_insert (ctx->addresses, key, list);
\r
190 @@ -401,12 +441,21 @@ _talloc_free_for_g_hash (void *ptr)
\r
194 -print_hash_value (unused (gpointer key), gpointer value, gpointer user_data)
\r
195 +_list_free_for_g_hash (void *ptr)
\r
197 - const mailbox_t *mailbox = value;
\r
198 - search_context_t *ctx = user_data;
\r
199 + g_list_free_full (ptr, _talloc_free_for_g_hash);
\r
202 - print_mailbox (ctx, mailbox);
\r
204 +print_list_value (void *mailbox, void *context)
\r
206 + print_mailbox (context, mailbox);
\r
210 +print_hash_value (unused (void *key), void *list, void *context)
\r
212 + g_list_foreach (list, print_list_value, context);
\r
216 @@ -794,8 +843,9 @@ notmuch_address_command (notmuch_config_t *config, int argc, char *argv[])
\r
217 argc - opt_index, argv + opt_index))
\r
218 return EXIT_FAILURE;
\r
220 - ctx->addresses = g_hash_table_new_full (g_str_hash, g_str_equal,
\r
221 - _talloc_free_for_g_hash, _talloc_free_for_g_hash);
\r
222 + ctx->addresses = g_hash_table_new_full (strcase_hash, strcase_equal,
\r
223 + _talloc_free_for_g_hash,
\r
224 + _list_free_for_g_hash);
\r
226 ret = do_search_messages (ctx);
\r