Re: [PATCH 3/5] nmbug-status: Add an nmbug-status(5) man page
[notmuch-archives.git] / 28 / 96c6f28e2e1dc2f573df43df7acc3b05ba0222
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 82B9E6DE0B7C\r
6  for <notmuch@notmuchmail.org>; Thu, 24 Sep 2015 11:34:54 -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.144\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.144 tagged_above=-999 required=5\r
12  tests=[AWL=-0.168, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=-0.01,\r
13  RCVD_IN_MSPIKE_WL=-0.01, URIBL_SBL=0.644, URIBL_SBL_A=0.1]\r
14  autolearn=disabled\r
15 Received: from arlo.cworth.org ([127.0.0.1])\r
16  by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)\r
17  with ESMTP id NBZ1QLCyxlg9 for <notmuch@notmuchmail.org>;\r
18  Thu, 24 Sep 2015 11:34:52 -0700 (PDT)\r
19 Received: from mail-wi0-f174.google.com (mail-wi0-f174.google.com\r
20  [209.85.212.174])\r
21  by arlo.cworth.org (Postfix) with ESMTPS id 9DCC56DE0B64\r
22  for <notmuch@notmuchmail.org>; Thu, 24 Sep 2015 11:34:51 -0700 (PDT)\r
23 Received: by wiclk2 with SMTP id lk2so125067381wic.1\r
24  for <notmuch@notmuchmail.org>; Thu, 24 Sep 2015 11:34:49 -0700 (PDT)\r
25 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
26  d=1e100.net; s=20130820;\r
27  h=x-gm-message-state:from:to:subject:in-reply-to:references\r
28  :user-agent:date:message-id:mime-version:content-type;\r
29  bh=AbjQtlAGaBJ7UpHzwYDcPbI+XjKqIo8M9MaZdTgxqDQ=;\r
30  b=luQgGMFqrXZc8Zyzn21LO8p7nJmUB4V+eIGNsiDAcwJmzTOoqiv2UK0gdXeRB6AfkR\r
31  PNDwj9k7TywwCR4NGv2nREhNlxtYqk7X4mlZ5KJH5Gd32uvTYZt/gF64lN0YJWxsHvv2\r
32  nsaF9tWk2FVE4UHVdrn2jZ+z2UyUQiepti6XOI0jWPfpiNdX+/K1bRJaCTFreH1zajor\r
33  rOqqnY8eFnwTCenWB4DSflRJpWE2H9OwlmO/txqE4Uy4hzly3rCepjyyjDwd5T0RtbQv\r
34  b/DVazpfyzjQyfxj8b+ZKCJHzsh9VFRNK0t+yHAJLzRSh9F4mWOmuogUZ6FzUhQWNILF\r
35  yRCQ==\r
36 X-Gm-Message-State:\r
37  ALoCoQkmzFWDH7PeSVSxjElnnYSyDjjz6qpObdf8KjHfZ9DXRGmL6LVDpYJFDztbJHgemVfvuX/Q\r
38 X-Received: by 10.194.116.67 with SMTP id ju3mr1165206wjb.143.1443119689474;\r
39  Thu, 24 Sep 2015 11:34:49 -0700 (PDT)\r
40 Received: from localhost (mobile-access-bcee63-221.dhcp.inet.fi.\r
41  [188.238.99.221])\r
42  by smtp.gmail.com with ESMTPSA id jj8sm169536wid.2.2015.09.24.11.34.48\r
43  (version=TLSv1/SSLv3 cipher=OTHER);\r
44  Thu, 24 Sep 2015 11:34:48 -0700 (PDT)\r
45 From: Jani Nikula <jani@nikula.org>\r
46 To: David Bremner <david@tethera.net>, notmuch@notmuchmail.org\r
47 Subject: Re: [PATCH v2 6/9] cli: change the data structure for notmuch address\r
48  deduplication\r
49 In-Reply-To: <87fv242e2a.fsf@zancas.localnet>\r
50 References: <cover.1441308761.git.jani@nikula.org>\r
51  <d8bb01aff648f9b73ec5f09f0e86e42dac2a21a6.1441308761.git.jani@nikula.org>\r
52  <87fv242e2a.fsf@zancas.localnet>\r
53 User-Agent: Notmuch/0.20.2+66~gb33abd9 (http://notmuchmail.org) Emacs/24.4.1\r
54  (x86_64-pc-linux-gnu)\r
55 Date: Thu, 24 Sep 2015 21:34:30 +0300\r
56 Message-ID: <87612zwts9.fsf@nikula.org>\r
57 MIME-Version: 1.0\r
58 Content-Type: text/plain\r
59 X-BeenThere: notmuch@notmuchmail.org\r
60 X-Mailman-Version: 2.1.18\r
61 Precedence: list\r
62 List-Id: "Use and development of the notmuch mail system."\r
63  <notmuch.notmuchmail.org>\r
64 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
65  <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
66 List-Archive: <http://notmuchmail.org/pipermail/notmuch/>\r
67 List-Post: <mailto:notmuch@notmuchmail.org>\r
68 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
69 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
70  <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
71 X-List-Received-Date: Thu, 24 Sep 2015 18:34:54 -0000\r
72 \r
73 On Thu, 24 Sep 2015, David Bremner <david@tethera.net> wrote:\r
74 > Jani Nikula <jani@nikula.org> writes:\r
75 >\r
76 >\r
77 >> +    else\r
78 >> +    v = !!m1->name - !!m2->name;\r
79 >\r
80 > Is this really idiomatic? It seems a little difficult to follow to me.\r
81 \r
82 Probably depends on whether you're accustomed to using !! for\r
83 "normalizing" zero and non-zero to 0 and 1, respectively.\r
84 \r
85 The alternative seemed a bit too verbose for my liking:\r
86 \r
87     if (m1->name && m2->name)\r
88         v = strcmp (m1->name, m2->name);\r
89     else if (!m1->name && !m2->name)\r
90         v = 0;\r
91     else if (m1->name)\r
92         v = 1;\r
93     else\r
94         v = -1;\r
95 \r
96 I can live with that if you think the verbosity is in order here. (Or am\r
97 I missing an obvious better alternative?)\r
98 \r
99 BR,\r
100 Jani.\r
101 \r
102 \r
103 >\r
104 >>  /* Returns TRUE iff name and addr is duplicate. If not, stores the\r
105 >>   * name/addr pair in order to detect subsequent duplicates. */\r
106 >>  static notmuch_bool_t\r
107 >>  is_duplicate (const search_context_t *ctx, const char *name, const char *addr)\r
108 >>  {\r
109 >>      char *key;\r
110 >> +    GList *list, *l;\r
111 >>      mailbox_t *mailbox;\r
112 >>  \r
113 >> -    key = talloc_asprintf (ctx->format, "%s <%s>", name, addr);\r
114 >> -    if (! key)\r
115 >> -    return FALSE;\r
116 >> +    list = g_hash_table_lookup (ctx->addresses, addr);\r
117 >> +    if (list) {\r
118 >> +    mailbox_t find = {\r
119 >> +        .name = name,\r
120 >> +        .addr = addr,\r
121 >> +    };\r
122 >> +\r
123 >> +    l = g_list_find_custom (list, &find, mailbox_compare);\r
124 >> +    if (l) {\r
125 >> +        mailbox = l->data;\r
126 >> +        mailbox->count++;\r
127 >> +        return TRUE;\r
128 >> +    }\r
129 >>  \r
130 >> -    mailbox = g_hash_table_lookup (ctx->addresses, key);\r
131 >> -    if (mailbox) {\r
132 >> -    mailbox->count++;\r
133 >> -    talloc_free (key);\r
134 >> -    return TRUE;\r
135 >> +    mailbox = new_mailbox (ctx->format, name, addr);\r
136 >> +    if (! mailbox)\r
137 >> +        return FALSE;\r
138 >> +\r
139 >> +    /*\r
140 >> +     * XXX: It would be more efficient to prepend to the list, but\r
141 >> +     * then we'd have to store the changed list head back to the\r
142 >> +     * hash table. This check is here just to avoid the compiler\r
143 >> +     * warning for unused result.\r
144 >> +     */\r
145 >> +    if (list != g_list_append (list, mailbox))\r
146 >> +        INTERNAL_ERROR ("appending to list changed list head\n");\r
147 >> +\r
148 >> +    return FALSE;\r
149 >>      }\r
150 >>  \r
151 >> +    key = talloc_strdup (ctx->format, addr);\r
152 >> +    if (! key)\r
153 >> +    return FALSE;\r
154 >> +\r
155 >>      mailbox = new_mailbox (ctx->format, name, addr);\r
156 >>      if (! mailbox)\r
157 >>      return FALSE;\r
158 >>  \r
159 >> -    g_hash_table_insert (ctx->addresses, key, mailbox);\r
160 >> +    list = g_list_append (NULL, mailbox);\r
161 >> +    if (! list)\r
162 >> +    return FALSE;\r
163 >> +\r
164 >> +    g_hash_table_insert (ctx->addresses, key, list);\r
165 >>  \r
166 >>      return FALSE;\r
167 >>  }\r
168 >> @@ -401,12 +445,21 @@ _talloc_free_for_g_hash (void *ptr)\r
169 >>  }\r
170 >>  \r
171 >>  static void\r
172 >> -print_hash_value (unused (gpointer key), gpointer value, gpointer user_data)\r
173 >> +_list_free_for_g_hash (void *ptr)\r
174 >> +{\r
175 >> +    g_list_free_full (ptr, _talloc_free_for_g_hash);\r
176 >> +}\r
177 >> +\r
178 >> +static void\r
179 >> +print_list_value (void *mailbox, void *context)\r
180 >>  {\r
181 >> -    const mailbox_t *mailbox = value;\r
182 >> -    search_context_t *ctx = user_data;\r
183 >> +    print_mailbox (context, mailbox);\r
184 >> +}\r
185 >>  \r
186 >> -    print_mailbox (ctx, mailbox);\r
187 >> +static void\r
188 >> +print_hash_value (unused (void *key), void *list, void *context)\r
189 >> +{\r
190 >> +    g_list_foreach (list, print_list_value, context);\r
191 >>  }\r
192 >>  \r
193 >>  static int\r
194 >> @@ -792,8 +845,9 @@ notmuch_address_command (notmuch_config_t *config, int argc, char *argv[])\r
195 >>                               argc - opt_index, argv + opt_index))\r
196 >>      return EXIT_FAILURE;\r
197 >>  \r
198 >> -    ctx->addresses = g_hash_table_new_full (g_str_hash, g_str_equal,\r
199 >> -                                        _talloc_free_for_g_hash, _talloc_free_for_g_hash);\r
200 >> +    ctx->addresses = g_hash_table_new_full (strcase_hash, strcase_equal,\r
201 >> +                                        _talloc_free_for_g_hash,\r
202 >> +                                        _list_free_for_g_hash);\r
203 >>  \r
204 >>      ret = do_search_messages (ctx);\r
205 >>  \r
206 >> -- \r
207 >> 2.1.4\r
208 >>\r
209 >> _______________________________________________\r
210 >> notmuch mailing list\r
211 >> notmuch@notmuchmail.org\r
212 >> http://notmuchmail.org/mailman/listinfo/notmuch\r