Re: [PATCH] Fix typo in Message.maildir_flags_to_tags
[notmuch-archives.git] / 9e / 607fb30a07296d7541affbcd1ee20244822f7c
1 Return-Path: <david@tethera.net>\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 705EE6DE0C1E\r
6  for <notmuch@notmuchmail.org>; Thu, 24 Sep 2015 05:34:22 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at cworth.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: 0.112\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0.112 tagged_above=-999 required=5 tests=[AWL=0.112]\r
12  autolearn=disabled\r
13 Received: from arlo.cworth.org ([127.0.0.1])\r
14  by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)\r
15  with ESMTP id BVL9venosmGo for <notmuch@notmuchmail.org>;\r
16  Thu, 24 Sep 2015 05:34:20 -0700 (PDT)\r
17 Received: from gitolite.debian.net (gitolite.debian.net [87.98.215.224])\r
18  by arlo.cworth.org (Postfix) with ESMTPS id 3C4C06DE0B7C\r
19  for <notmuch@notmuchmail.org>; Thu, 24 Sep 2015 05:34:20 -0700 (PDT)\r
20 Received: from remotemail by gitolite.debian.net with local (Exim 4.80)\r
21  (envelope-from <david@tethera.net>)\r
22  id 1Zf5hQ-0006ga-I3; Thu, 24 Sep 2015 12:32:32 +0000\r
23 Received: (nullmailer pid 9111 invoked by uid 1000); Thu, 24 Sep 2015\r
24  12:32:13 -0000\r
25 From: David Bremner <david@tethera.net>\r
26 To: Jani Nikula <jani@nikula.org>, notmuch@notmuchmail.org\r
27 Subject: Re: [PATCH v2 6/9] cli: change the data structure for notmuch\r
28  address deduplication\r
29 In-Reply-To:\r
30  <d8bb01aff648f9b73ec5f09f0e86e42dac2a21a6.1441308761.git.jani@nikula.org>\r
31 References: <cover.1441308761.git.jani@nikula.org>\r
32  <d8bb01aff648f9b73ec5f09f0e86e42dac2a21a6.1441308761.git.jani@nikula.org>\r
33 User-Agent: Notmuch/0.20.2+73~gd432116 (http://notmuchmail.org) Emacs/24.5.1\r
34  (x86_64-pc-linux-gnu)\r
35 Date: Thu, 24 Sep 2015 09:32:13 -0300\r
36 Message-ID: <87fv242e2a.fsf@zancas.localnet>\r
37 MIME-Version: 1.0\r
38 Content-Type: text/plain\r
39 X-BeenThere: notmuch@notmuchmail.org\r
40 X-Mailman-Version: 2.1.18\r
41 Precedence: list\r
42 List-Id: "Use and development of the notmuch mail system."\r
43  <notmuch.notmuchmail.org>\r
44 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
45  <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
46 List-Archive: <http://notmuchmail.org/pipermail/notmuch/>\r
47 List-Post: <mailto:notmuch@notmuchmail.org>\r
48 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
49 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
50  <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
51 X-List-Received-Date: Thu, 24 Sep 2015 12:34:22 -0000\r
52 \r
53 Jani Nikula <jani@nikula.org> writes:\r
54 \r
55 \r
56 > +    else\r
57 > +     v = !!m1->name - !!m2->name;\r
58 \r
59 Is this really idiomatic? It seems a little difficult to follow to me.\r
60 \r
61 >  /* Returns TRUE iff name and addr is duplicate. If not, stores the\r
62 >   * name/addr pair in order to detect subsequent duplicates. */\r
63 >  static notmuch_bool_t\r
64 >  is_duplicate (const search_context_t *ctx, const char *name, const char *addr)\r
65 >  {\r
66 >      char *key;\r
67 > +    GList *list, *l;\r
68 >      mailbox_t *mailbox;\r
69 >  \r
70 > -    key = talloc_asprintf (ctx->format, "%s <%s>", name, addr);\r
71 > -    if (! key)\r
72 > -     return FALSE;\r
73 > +    list = g_hash_table_lookup (ctx->addresses, addr);\r
74 > +    if (list) {\r
75 > +     mailbox_t find = {\r
76 > +         .name = name,\r
77 > +         .addr = addr,\r
78 > +     };\r
79 > +\r
80 > +     l = g_list_find_custom (list, &find, mailbox_compare);\r
81 > +     if (l) {\r
82 > +         mailbox = l->data;\r
83 > +         mailbox->count++;\r
84 > +         return TRUE;\r
85 > +     }\r
86 >  \r
87 > -    mailbox = g_hash_table_lookup (ctx->addresses, key);\r
88 > -    if (mailbox) {\r
89 > -     mailbox->count++;\r
90 > -     talloc_free (key);\r
91 > -     return TRUE;\r
92 > +     mailbox = new_mailbox (ctx->format, name, addr);\r
93 > +     if (! mailbox)\r
94 > +         return FALSE;\r
95 > +\r
96 > +     /*\r
97 > +      * XXX: It would be more efficient to prepend to the list, but\r
98 > +      * then we'd have to store the changed list head back to the\r
99 > +      * hash table. This check is here just to avoid the compiler\r
100 > +      * warning for unused result.\r
101 > +      */\r
102 > +     if (list != g_list_append (list, mailbox))\r
103 > +         INTERNAL_ERROR ("appending to list changed list head\n");\r
104 > +\r
105 > +     return FALSE;\r
106 >      }\r
107 >  \r
108 > +    key = talloc_strdup (ctx->format, addr);\r
109 > +    if (! key)\r
110 > +     return FALSE;\r
111 > +\r
112 >      mailbox = new_mailbox (ctx->format, name, addr);\r
113 >      if (! mailbox)\r
114 >       return FALSE;\r
115 >  \r
116 > -    g_hash_table_insert (ctx->addresses, key, mailbox);\r
117 > +    list = g_list_append (NULL, mailbox);\r
118 > +    if (! list)\r
119 > +     return FALSE;\r
120 > +\r
121 > +    g_hash_table_insert (ctx->addresses, key, list);\r
122 >  \r
123 >      return FALSE;\r
124 >  }\r
125 > @@ -401,12 +445,21 @@ _talloc_free_for_g_hash (void *ptr)\r
126 >  }\r
127 >  \r
128 >  static void\r
129 > -print_hash_value (unused (gpointer key), gpointer value, gpointer user_data)\r
130 > +_list_free_for_g_hash (void *ptr)\r
131 > +{\r
132 > +    g_list_free_full (ptr, _talloc_free_for_g_hash);\r
133 > +}\r
134 > +\r
135 > +static void\r
136 > +print_list_value (void *mailbox, void *context)\r
137 >  {\r
138 > -    const mailbox_t *mailbox = value;\r
139 > -    search_context_t *ctx = user_data;\r
140 > +    print_mailbox (context, mailbox);\r
141 > +}\r
142 >  \r
143 > -    print_mailbox (ctx, mailbox);\r
144 > +static void\r
145 > +print_hash_value (unused (void *key), void *list, void *context)\r
146 > +{\r
147 > +    g_list_foreach (list, print_list_value, context);\r
148 >  }\r
149 >  \r
150 >  static int\r
151 > @@ -792,8 +845,9 @@ notmuch_address_command (notmuch_config_t *config, int argc, char *argv[])\r
152 >                                argc - opt_index, argv + opt_index))\r
153 >       return EXIT_FAILURE;\r
154 >  \r
155 > -    ctx->addresses = g_hash_table_new_full (g_str_hash, g_str_equal,\r
156 > -                                         _talloc_free_for_g_hash, _talloc_free_for_g_hash);\r
157 > +    ctx->addresses = g_hash_table_new_full (strcase_hash, strcase_equal,\r
158 > +                                         _talloc_free_for_g_hash,\r
159 > +                                         _list_free_for_g_hash);\r
160 >  \r
161 >      ret = do_search_messages (ctx);\r
162 >  \r
163 > -- \r
164 > 2.1.4\r
165 >\r
166 > _______________________________________________\r
167 > notmuch mailing list\r
168 > notmuch@notmuchmail.org\r
169 > http://notmuchmail.org/mailman/listinfo/notmuch\r