Re: [RFC PATCH 5/5] cli: add support for deduplicating based on case insensitive address

2015-08-31 Thread David Bremner
Tomi Ollila  writes:

>> I can live with the current argument syntax, but since a certain a mount
>> of bikeshedding is expected, here is an alternative suggestion
>>
>> --deduplication={none|mailbox|address}
>
> (is s/deduplicate/deduplication/ intended or accidental change?)

accidental. hmm. well,

--deduplicate={no|mailbox|address}

is a few characters shorter.

> Is this complete alternative to --deduplicate={no|yes|address},
> respectively?

Yes

___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


Re: [RFC PATCH 5/5] cli: add support for deduplicating based on case insensitive address

2015-08-31 Thread Tomi Ollila
On Sun, Aug 30 2015, David Bremner  wrote:

> Jani Nikula  writes:
>
>> Consider all variants of an email address as one, and print the most
>> common variant.
>
> Other than the quibbles already mentioned, the series looks ok to
> me. For production it should have one or two tests I guess. Oh, and man
> page updates. But you knew that I guess.
>
> I can live with the current argument syntax, but since a certain a mount
> of bikeshedding is expected, here is an alternative suggestion
>
> --deduplication={none|mailbox|address}

(is s/deduplicate/deduplication/ intended or accidental change?)

Is this complete alternative to --deduplicate={no|yes|address}, respectively?

If it is it looks somewhat better to me (provided that it is accurate)
anyway, the user command line interface looks good to me.



Tomi
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


Re: [RFC PATCH 5/5] cli: add support for deduplicating based on case insensitive address

2015-08-30 Thread David Bremner
Jani Nikula  writes:

> Consider all variants of an email address as one, and print the most
> common variant.

Other than the quibbles already mentioned, the series looks ok to
me. For production it should have one or two tests I guess. Oh, and man
page updates. But you knew that I guess.

I can live with the current argument syntax, but since a certain a mount
of bikeshedding is expected, here is an alternative suggestion

--deduplication={none|mailbox|address}
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


[RFC PATCH 5/5] cli: add support for deduplicating based on case insensitive address

2015-08-29 Thread Jani Nikula
Consider all variants of an email address as one, and print the most
common variant.
---
 notmuch-search.c | 33 -
 1 file changed, 32 insertions(+), 1 deletion(-)

diff --git a/notmuch-search.c b/notmuch-search.c
index 60311393198d..537298788ab9 100644
--- a/notmuch-search.c
+++ b/notmuch-search.c
@@ -447,6 +447,31 @@ _list_free_for_g_hash (void *ptr)
 g_list_free_full (ptr, _talloc_free_for_g_hash);
 }
 
+/* Print the most common variant of a list of unique mailboxes, and
+ * conflate the counts. */
+static void
+print_popular (const search_context_t *ctx, GList *list)
+{
+GList *l;
+mailbox_t *mailbox = NULL, *m;
+int max = 0;
+int total = 0;
+
+for (l = list; l; l = l->next) {
+   m = l->data;
+   total += m->count;
+   if (m->count > max) {
+   mailbox = m;
+   max = m->count;
+   }
+}
+
+/* The original count is no longer needed, so overwrite. */
+mailbox->count = total;
+
+print_mailbox (ctx, mailbox);
+}
+
 static void
 print_list_value (void *mailbox, void *context)
 {
@@ -456,7 +481,12 @@ print_list_value (void *mailbox, void *context)
 static void
 print_hash_value (unused (void *key), void *list, void *context)
 {
-g_list_foreach (list, print_list_value, context);
+const search_context_t *ctx = context;
+
+if (ctx->dupe == 1)
+   print_popular (ctx, list);
+else
+   g_list_foreach (list, print_list_value, context);
 }
 
 static int
@@ -817,6 +847,7 @@ notmuch_address_command (notmuch_config_t *config, int 
argc, char *argv[])
{ NOTMUCH_OPT_KEYWORD, &ctx->dupe, "deduplicate", 'x',
  (notmuch_keyword_t []){ { "yes", -1 },
  { "no", 0 },
+ { "address", 1 },
  { 0, 0 } } },
{ NOTMUCH_OPT_INHERIT, (void *) &common_options, NULL, 0, 0 },
{ NOTMUCH_OPT_INHERIT, (void *) ¬much_shared_options, NULL, 0, 0 },
-- 
2.1.4

___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch