--- /dev/null
+Return-Path: <jani@nikula.org>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by arlo.cworth.org (Postfix) with ESMTP id E94CC6DE1422\r
+ for <notmuch@notmuchmail.org>; Sun, 30 Aug 2015 00:45:51 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at cworth.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.033\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.033 tagged_above=-999 required=5\r
+ tests=[AWL=-0.057, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=-0.01,\r
+ RCVD_IN_MSPIKE_WL=-0.01, URIBL_SBL=0.644, URIBL_SBL_A=0.1]\r
+ autolearn=disabled\r
+Received: from arlo.cworth.org ([127.0.0.1])\r
+ by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id byTyleT2gh1d for <notmuch@notmuchmail.org>;\r
+ Sun, 30 Aug 2015 00:45:50 -0700 (PDT)\r
+Received: from mail-wi0-f175.google.com (mail-wi0-f175.google.com\r
+ [209.85.212.175])\r
+ by arlo.cworth.org (Postfix) with ESMTPS id 87EF26DE00CB\r
+ for <notmuch@notmuchmail.org>; Sun, 30 Aug 2015 00:45:49 -0700 (PDT)\r
+Received: by wicpl12 with SMTP id pl12so3317022wic.0\r
+ for <notmuch@notmuchmail.org>; Sun, 30 Aug 2015 00:45:48 -0700 (PDT)\r
+X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
+ d=1e100.net; s=20130820;\r
+ h=x-gm-message-state:from:to:subject:in-reply-to:references\r
+ :user-agent:date:message-id:mime-version:content-type;\r
+ bh=qSlXICt/pbAC9rCNI1L5nMjtwb7TGNF+NmQB6hAjvhA=;\r
+ b=EPo3kTyUr5wWepVSU8zDSmvWwBB+65wwEWURmMi22B9pD2JgsA14MasEaZnr/G2IxM\r
+ BgUMQGSGy25ywLhwYnlgJl7aT6nwajw5FqG0A4dXJswFQMFOgEWXzwc74hs+pzZKNjfO\r
+ VjoQ3aPDgsSaV5ywDuWPPYLqvGG26vLzcdOmnNd0yT/3YmgTh5LWadBnDQL/1ofHbWYO\r
+ heIjFKiGcLMH9rW9MWwbazrdmPWeDjSqcHP+whXGrnV3KYpONVBPw4PuTPNhXy7BH75g\r
+ 4Wm63UCDCaklVWf5jm0wFy4KAA1YalDcPBdPHG9gkrKpaM5qrGIiB8rvr7C3ueS/7Pnj\r
+ sI2g==\r
+X-Gm-Message-State:\r
+ ALoCoQmZpX8oV9HKzmP18JAPpmYSiLLlBj91yFNkkidXzvHdkxP9n7HMxF0Lk+v+65snEE1uFd9F\r
+X-Received: by 10.180.82.7 with SMTP id e7mr13160658wiy.19.1440920747872;\r
+ Sun, 30 Aug 2015 00:45:47 -0700 (PDT)\r
+Received: from localhost (mobile-access-bcee4f-131.dhcp.inet.fi.\r
+ [188.238.79.131])\r
+ by smtp.gmail.com with ESMTPSA id du6sm11961009wib.24.2015.08.30.00.45.46\r
+ (version=TLSv1/SSLv3 cipher=OTHER);\r
+ Sun, 30 Aug 2015 00:45:47 -0700 (PDT)\r
+From: Jani Nikula <jani@nikula.org>\r
+To: David Bremner <david@tethera.net>, notmuch@notmuchmail.org\r
+Subject: Re: [RFC PATCH 4/5] cli: change the data structure for notmuch\r
+ address deduplication\r
+In-Reply-To: <87a8t9tuka.fsf@maritornes.cs.unb.ca>\r
+References: <cover.1440859765.git.jani@nikula.org>\r
+ <ffe5975fd070d3e8e22602b01ceb8bf0d7d47ae0.1440859765.git.jani@nikula.org>\r
+ <87a8t9tuka.fsf@maritornes.cs.unb.ca>\r
+User-Agent: Notmuch/0.20.2+66~gb33abd9 (http://notmuchmail.org) Emacs/24.4.1\r
+ (x86_64-pc-linux-gnu)\r
+Date: Sun, 30 Aug 2015 10:45:46 +0300\r
+Message-ID: <87h9nh1aol.fsf@nikula.org>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.18\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch/>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Sun, 30 Aug 2015 07:45:52 -0000\r
+\r
+On Sun, 30 Aug 2015, David Bremner <david@tethera.net> wrote:\r
+> Jani Nikula <jani@nikula.org> writes:\r
+>\r
+>> \r
+>> +static int\r
+>> +strcase_equal (const void *a, const void *b)\r
+>> +{\r
+>> + return strcasecmp (a, b) == 0;\r
+>> +}\r
+>> +\r
+>> +static unsigned int\r
+>> +strcase_hash (const void *ptr)\r
+>> +{\r
+>> + const char *s = ptr;\r
+>> +\r
+>> + /* This is the djb2 hash. */\r
+>> + unsigned int hash = 5381;\r
+>> + while (s && *s) {\r
+>> + hash = ((hash << 5) + hash) + tolower (*s);\r
+>> + s++;\r
+>> + }\r
+>> +\r
+>> + return hash;\r
+>> +}\r
+>> +\r
+>\r
+> as discussed, these functions probably need to be factored out into\r
+> libutil.\r
+\r
+Ack.\r
+\r
+>\r
+>> + l = g_list_find_custom (list, mailbox, mailbox_compare);\r
+>> + if (l) {\r
+>> + talloc_free (mailbox);\r
+>> + mailbox = l->data;\r
+>> + mailbox->count++;\r
+>> + return TRUE;\r
+>> + }\r
+>\r
+> I found this use of mailbox as a temporary variable confusing; despite\r
+> the obvious return I thought it might have something to do with the\r
+> g_list_append below. Maybe just make a block scope temporary variable?\r
+\r
+This is how the function would turn out with that. Better, I guess? I\r
+also tried to think of ways to combine the two g_list_append paths here,\r
+but in the end doing it like this has most clarity I think.\r
+\r
+static notmuch_bool_t\r
+is_duplicate (const search_context_t *ctx, const char *name, const char *addr)\r
+{\r
+ char *key;\r
+ GList *list, *l;\r
+ mailbox_t *mailbox;\r
+\r
+ list = g_hash_table_lookup (ctx->addresses, addr);\r
+ if (list) {\r
+ mailbox_t find = {\r
+ .name = name,\r
+ .addr = addr,\r
+ };\r
+\r
+ l = g_list_find_custom (list, &find, mailbox_compare);\r
+ if (l) {\r
+ mailbox = l->data;\r
+ mailbox->count++;\r
+ return TRUE;\r
+ }\r
+\r
+ mailbox = new_mailbox (ctx->format, name, addr);\r
+ if (! mailbox)\r
+ return FALSE;\r
+\r
+ g_list_append (list, mailbox);\r
+ return FALSE;\r
+ }\r
+\r
+ key = talloc_strdup (ctx->format, addr);\r
+ if (! key)\r
+ return FALSE;\r
+\r
+ mailbox = new_mailbox (ctx->format, name, addr);\r
+ if (! mailbox)\r
+ return FALSE;\r
+\r
+ list = g_list_append (NULL, mailbox);\r
+ if (! list)\r
+ return FALSE;\r
+\r
+ g_hash_table_insert (ctx->addresses, key, list);\r
+\r
+ return FALSE;\r
+}\r
+\r
+>> +\r
+>> + g_list_append (list, mailbox);\r
+>> + return FALSE;\r
+>> }\r
+>> \r
+>> - mailbox = new_mailbox (ctx->format, name, addr);\r
+>> - if (! mailbox)\r
+>> + key = talloc_strdup (ctx->format, addr);\r
+>> + if (! key)\r
+>> return FALSE;\r
+>\r
+> I guess this doesn't make the error handling worse; both old and new\r
+> code silently ignore OOM if I understand correctly. Do you happen to\r
+> understand the original choice of using ctx->format rather than that\r
+> ctx->notmuch for a talloc parent? it doesn't seem to get deallocated any\r
+> earlier.\r
+\r
+I don't know or understand that part of the history. It doesn't really\r
+matter though because the deallocation is explicitly done on all keys\r
+and values via g_hash_table_unref.\r
+\r
+BR,\r
+Jani.\r