[PATCH v6 6/7] cli: search: Add --output=count

Michal Sojka sojkam1 at fel.cvut.cz
Mon Nov 3 13:39:26 PST 2014


Hi Tomi,

On Mon, Nov 03 2014, Tomi Ollila wrote:
> On Sun, Nov 02 2014, Michal Sojka <sojkam1 at fel.cvut.cz> wrote:
>
>> On 2. listopadu 2014 10:29:28 CET, Mark Walters <markwalters1009 at gmail.com> wrote:
>>>
>>>Hi
>>>
>>>On Sun, 02 Nov 2014, Michal Sojka <sojkam1 at fel.cvut.cz> wrote:
>>>> On Sat, Nov 01 2014, Mark Walters wrote:
>>>>> On Fri, 31 Oct 2014, Michal Sojka <sojkam1 at fel.cvut.cz> wrote:
>>>>>> This output can be used with --output=recipients or --output=sender
>>>>>> and in addition to the addresses, it prints how many times was each
>>>>>> address encountered during search.
>>>>>
>>>>> Hi
>>>>>
>>>>> I have a couple comments on this patch.
>>>>>
>>>>>> ---
>>>>>>  completion/notmuch-completion.bash |  2 +-
>>>>>>  completion/notmuch-completion.zsh  |  2 +-
>>>>>>  doc/man1/notmuch-search.rst        |  9 +++++--
>>>>>>  notmuch-search.c                   | 51
>>>++++++++++++++++++++++++++++++++------
>>>>>>  4 files changed, 52 insertions(+), 12 deletions(-)
>>>>>>
>>>>>> diff --git a/completion/notmuch-completion.bash
>>>b/completion/notmuch-completion.bash
>>>>>> index cfbd389..39cd829 100644
>>>>>> --- a/completion/notmuch-completion.bash
>>>>>> +++ b/completion/notmuch-completion.bash
>>>>>> @@ -294,7 +294,7 @@ _notmuch_search()
>>>>>>  	    return
>>>>>>  	    ;;
>>>>>>  	--output)
>>>>>> -	    COMPREPLY=( $( compgen -W "summary threads messages files
>>>tags sender recipients" -- "${cur}" ) )
>>>>>> +	    COMPREPLY=( $( compgen -W "summary threads messages files
>>>tags sender recipients count" -- "${cur}" ) )
>>>>>>  	    return
>>>>>>  	    ;;
>>>>>>  	--sort)
>>>>>> diff --git a/completion/notmuch-completion.zsh
>>>b/completion/notmuch-completion.zsh
>>>>>> index 3e52a00..d7e5a5e 100644
>>>>>> --- a/completion/notmuch-completion.zsh
>>>>>> +++ b/completion/notmuch-completion.zsh
>>>>>> @@ -53,7 +53,7 @@ _notmuch_search()
>>>>>>      '--max-threads=[display only the first x threads from the
>>>search results]:number of threads to show: ' \
>>>>>>      '--first=[omit the first x threads from the search
>>>results]:number of threads to omit: ' \
>>>>>>      '--sort=[sort results]:sorting:((newest-first\:"reverse
>>>chronological order" oldest-first\:"chronological order"))' \
>>>>>> -    '--output=[select what to output]:output:((summary threads
>>>messages files tags sender recipients))'
>>>>>> +    '--output=[select what to output]:output:((summary threads
>>>messages files tags sender recipients count))'
>>>>>>  }
>>>>>>  
>>>>>>  _notmuch()
>>>>>> diff --git a/doc/man1/notmuch-search.rst
>>>b/doc/man1/notmuch-search.rst
>>>>>> index 42f17e4..ec89200 100644
>>>>>> --- a/doc/man1/notmuch-search.rst
>>>>>> +++ b/doc/man1/notmuch-search.rst
>>>>>> @@ -96,9 +96,14 @@ Supported options for **search** include
>>>>>>              Like **sender** but for addresses from *To*, *Cc* and
>>>>>>  	    *Bcc* headers.
>>>>>>  
>>>>>> +	**count**
>>>>>> +	    Can be used in combination with **sender** or
>>>>>> +	    **recipients** to print the count of how many times was
>>>>>> +	    the address encountered during search.
>>>>>> +
>>>>>>  	This option can be given multiple times to combine different
>>>>>> -	outputs. Currently, this is only supported for **sender** and
>>>>>> -	**recipients** outputs.
>>>>>> +	outputs. Currently, this is only supported for **sender**,
>>>>>> +	**recipients** and **count** outputs.
>>>>>
>>>>> It might be worth saying that the results will be slower if count is
>>>>> specified.
>>>>
>>>> I wrote something like this in
>>>> id:1414889400-30977-10-git-send-email-sojkam1 at fel.cvut.cz.
>>>>
>>>>>
>>>>>>      ``--sort=``\ (**newest-first**\ \|\ **oldest-first**)
>>>>>
>>>>> I think sort works as expected if count is not specified, but does
>>>not
>>>>> with count. 
>>>>
>>>> Agreed.
>>>>
>>>>> Maybe count can be done by doing two passes? 
>>>>
>>>> What do you mean by pass?
>>>
>>>I mean iterating through the messages twice: so the first time would
>>>fill in the count in the hash map, and the second iteration would print
>>>the addresses.
>>
>> That's what the patch does. Only the second time it iterates the hash.
>
> Sorry 
>
> And we loose the order ? (or not ?) do we have "orderedhash" there...
> I'd like to save the order

What would be the use case?

If you really want to preserve the order, we could save a sequence
number in mailbox_t and sort the hash table entries before printing. But
this could be implemented later and enabled by a special command line
option. notmuch search --output=tags does not preserve order either.

> (but that is not so important) -- but more importantly, are tests
> robusts --- ah there is sort -n in the test...

Yes.

-Michal


More information about the notmuch mailing list