[PATCH 1/3] test: add functions to count how much times notmuch was called

2011-11-30 Thread Tomi Ollila
On Wed, 30 Nov 2011 01:03:27 +0400, Dmitry Kurochkin  wrote:
> Hi Tomi.
> 
> On Tue, 29 Nov 2011 14:58:00 +0200, Tomi Ollila  wrote:
> > Hi Dmitry.

[ ... ]

> > 
> > The (posix) shell command language defines 'Arithmetic Expansion' in
> > 
> > http://pubs.opengroup.org/onlinepubs/007908799/xcu/chap2.html#tag_001_006_004
> > 
> > I.e. using format $(( expression )) makes shell doing the arithetic itself
> > instead of forking a process (or two!) to do so.
> > 
> 
> I though expr was a builtin.  Now I agree that it is better to replace
> it with $(()), even though I still prefer the expr syntax.

Actually, I thought also that expr was a builtin. That makes the resolution
'forks subshell to execute builtin expr' below wrong. If it were a builtin
then bash would also fork only once (to get details right). I re-tested
with zsh using 'builtin pwd' and '/bin/pwd' instead of 'expr' -- only one fork 
in each case. So, those who examined my tests with deep interest also note
this correction.


> > Normally in this case it is not so big deal (and still it isn't, but...)
> > In this  particular case the shell wrapper counting notmuch launches and
> > exec'ing it the wrapper could do this without fork(2)ing a single time
> > (i.e. keep the process count unchanged compared to execing notmuch
> > directly)
> > 
> > Anyway, many opinions; as far as it works I'm fine with it :) 
> > 
> > Now that you feel relaxed, check the results of some further
> > experimentation ;) :
> > 
> > excerpt from man strace:
> > 
> >-ff If the -o filename option is in effect,  each  processes
> >trace  is  written  to  filename.pid  where  pid  is the
> >numeric process id of each process.
> > 
> > Executing  rm -f forked.*; strace -ff -o forked bash -c 'echo $(( 5 + 5 ))' 
> > 
> > will output '10' and create just one 'forked.' file
> > 
> > Executing  rm -f forked.*; strace -ff -o forked bash -c 'echo $(expr 5 + 
> > 5)' 
> > 
> > output 10 as expected, but there is now *3* forked. files !
> > 
> > bash does not optmize; it forks subshell to execute $(...) and then
> > there just works as usual (forks subshell to execute builtin expr))
> > 
> > Executing  rm -f forked.*; strace -ff -o forked bash -c 'echo $(exec expr 5 
> > + 5)' 
> > 
> > (the added 'exec' takes off one fork -- just 2 forked. files appear).
> > 
> > I did the same tests using dash, ksh & zsh on linux system, and every one
> > of these managed to optimize one fork out in the above 3 fork case.
> > 
> 
> Thanks for details.
> 
> Regards,
>   Dmitry
> 
> > 
> > Tomi

Tomi


Re: [PATCH 1/3] test: add functions to count how much times notmuch was called

2011-11-30 Thread Tomi Ollila
On Wed, 30 Nov 2011 01:03:27 +0400, Dmitry Kurochkin 
 wrote:
> Hi Tomi.
> 
> On Tue, 29 Nov 2011 14:58:00 +0200, Tomi Ollila  wrote:
> > Hi Dmitry.

[ ... ]

> > 
> > The (posix) shell command language defines 'Arithmetic Expansion' in
> > 
> > http://pubs.opengroup.org/onlinepubs/007908799/xcu/chap2.html#tag_001_006_004
> > 
> > I.e. using format $(( expression )) makes shell doing the arithetic itself
> > instead of forking a process (or two!) to do so.
> > 
> 
> I though expr was a builtin.  Now I agree that it is better to replace
> it with $(()), even though I still prefer the expr syntax.

Actually, I thought also that expr was a builtin. That makes the resolution
'forks subshell to execute builtin expr' below wrong. If it were a builtin
then bash would also fork only once (to get details right). I re-tested
with zsh using 'builtin pwd' and '/bin/pwd' instead of 'expr' -- only one fork 
in each case. So, those who examined my tests with deep interest also note
this correction.


> > Normally in this case it is not so big deal (and still it isn't, but...)
> > In this  particular case the shell wrapper counting notmuch launches and
> > exec'ing it the wrapper could do this without fork(2)ing a single time
> > (i.e. keep the process count unchanged compared to execing notmuch
> > directly)
> > 
> > Anyway, many opinions; as far as it works I'm fine with it :) 
> > 
> > Now that you feel relaxed, check the results of some further
> > experimentation ;) :
> > 
> > excerpt from man strace:
> > 
> >-ff If the -o filename option is in effect,  each  processes
> >trace  is  written  to  filename.pid  where  pid  is the
> >numeric process id of each process.
> > 
> > Executing  rm -f forked.*; strace -ff -o forked bash -c 'echo $(( 5 + 5 ))' 
> > 
> > will output '10' and create just one 'forked.' file
> > 
> > Executing  rm -f forked.*; strace -ff -o forked bash -c 'echo $(expr 5 + 
> > 5)' 
> > 
> > output 10 as expected, but there is now *3* forked. files !
> > 
> > bash does not optmize; it forks subshell to execute $(...) and then
> > there just works as usual (forks subshell to execute builtin expr))
> > 
> > Executing  rm -f forked.*; strace -ff -o forked bash -c 'echo $(exec expr 5 
> > + 5)' 
> > 
> > (the added 'exec' takes off one fork -- just 2 forked. files appear).
> > 
> > I did the same tests using dash, ksh & zsh on linux system, and every one
> > of these managed to optimize one fork out in the above 3 fork case.
> > 
> 
> Thanks for details.
> 
> Regards,
>   Dmitry
> 
> > 
> > Tomi

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


[PATCH 1/3] test: add functions to count how much times notmuch was called

2011-11-30 Thread Dmitry Kurochkin
Hi Tomi.

On Tue, 29 Nov 2011 14:58:00 +0200, Tomi Ollila  wrote:
> Hi Dmitry.
> 
> On Tue, 29 Nov 2011 01:26:39 +0400, Dmitry Kurochkin  gmail.com> wrote:
> > Hi Tomi.
> > 
> > On Mon, 28 Nov 2011 22:42:50 +0200, Tomi Ollila  
> > wrote:
> > > On Mon, 28 Nov 2011 07:28:13 +0400, Dmitry Kurochkin  > > gmail.com> wrote:
> [ ... ]
> > > > +# Creates a script that counts how much time it is executed and calls
> > > > +# notmuch.  $notmuch_counter_command is set to the path to the
> > > > +# generated script.  Use notmuch_counter_value() function to get the
> > > > +# current counter value.
> > > > +notmuch_counter_reset () {
> > > > +   notmuch_counter_command="$TMP_DIRECTORY/notmuch_counter"
> > > > +   if [ ! -x "$notmuch_counter_command" ]; then
> > > > +   
> > > > notmuch_counter_state_path="$TMP_DIRECTORY/notmuch_counter.state"
> > > > +   cat >"$notmuch_counter_command" < > > > +#!/bin/sh
> > > > +
> > > > +count=\$(cat "$notmuch_counter_state_path")
> > > > +echo -n \$(expr \$count + 1) > "$notmuch_counter_state_path"
> > > > +
> > > > +exec notmuch "\$@"
> > > > +EOF
> > > > +   chmod +x "$notmuch_counter_command" || return
> > > > +   fi
> > > > +
> > > > +   echo -n 0 > "$notmuch_counter_state_path"
> > > > +}
> > > > +
> > > > +# Returns the current notmuch counter value.
> > > > +notmuch_counter_value () {
> > > > +   if [ -r "$notmuch_counter_state_path" ]; then
> > > > +   count=$(cat "$notmuch_counter_state_path")
> > > > +   else
> > > > +   count=0
> > > > +   fi
> > > > +   echo -n $count
> > > > +}
> > > > +
> > > 
> > > Good work! It would be nice if the state file contained newline after
> > > count number.
> > 
> > I wonder why it is actually nice :)  I do not have strong preference
> > here.  So a newline is added in v3.  Also a newline is added to
> > notmuch_counter_value() output for consistency.
> 
> It is nice when I enter cat /path/to/notmuch_counter from command
> line and shell prompt is not appended at the end of the file contents
> (but on next line :)
> 
> > 
> > > Also some optimizations could be done:
> > > 
> > 
> > (Would be nice if you send a diff, or a human-friendly description of
> > the changes.)
> 
> Ok, I'll try to do this according to your wishes next time.
> 
> > >   cat >"$notmuch_counter_command" < > > #!/bin/sh
> > > 
> > > read count < "$notmuch_counter_state_path"
> > 
> > Nice.  Fixed in the new patch version.
> > 
> > > echo \$((count + 1)) > "$notmuch_counter_state_path"
> > > 
> > 
> > I do not think this is really an optimization.  And I find expr more
> > clear than using $(()).  I always have troubles remembering "random
> > special char syntax" (yeah, not a Perl fan :)), prefer human friendly
> > words.
> 
> The (posix) shell command language defines 'Arithmetic Expansion' in
> 
> http://pubs.opengroup.org/onlinepubs/007908799/xcu/chap2.html#tag_001_006_004
> 
> I.e. using format $(( expression )) makes shell doing the arithetic itself
> instead of forking a process (or two!) to do so.
> 

I though expr was a builtin.  Now I agree that it is better to replace
it with $(()), even though I still prefer the expr syntax.

> Normally in this case it is not so big deal (and still it isn't, but...)
> In this  particular case the shell wrapper counting notmuch launches and
> exec'ing it the wrapper could do this without fork(2)ing a single time
> (i.e. keep the process count unchanged compared to execing notmuch
> directly)
> 
> Anyway, many opinions; as far as it works I'm fine with it :) 
> 
> Now that you feel relaxed, check the results of some further
> experimentation ;) :
> 
> excerpt from man strace:
> 
>-ff If the -o filename option is in effect,  each  processes
>trace  is  written  to  filename.pid  where  pid  is the
>numeric process id of each process.
> 
> Executing  rm -f forked.*; strace -ff -o forked bash -c 'echo $(( 5 + 5 ))' 
> 
> will output '10' and create just one 'forked.' file
> 
> Executing  rm -f forked.*; strace -ff -o forked bash -c 'echo $(expr 5 + 5)' 
> 
> output 10 as expected, but there is now *3* forked. files !
> 
> bash does not optmize; it forks subshell to execute $(...) and then
> there just works as usual (forks subshell to execute builtin expr))
> 
> Executing  rm -f forked.*; strace -ff -o forked bash -c 'echo $(exec expr 5 + 
> 5)' 
> 
> (the added 'exec' takes off one fork -- just 2 forked. files appear).
> 
> I did the same tests using dash, ksh & zsh on linux system, and every one
> of these managed to optimize one fork out in the above 3 fork case.
> 

Thanks for details.

Regards,
  Dmitry

> 
> Tomi


[PATCH 1/3] test: add functions to count how much times notmuch was called

2011-11-29 Thread Tomi Ollila
Hi Dmitry.

On Tue, 29 Nov 2011 01:26:39 +0400, Dmitry Kurochkin  wrote:
> Hi Tomi.
> 
> On Mon, 28 Nov 2011 22:42:50 +0200, Tomi Ollila  wrote:
> > On Mon, 28 Nov 2011 07:28:13 +0400, Dmitry Kurochkin  > gmail.com> wrote:
[ ... ]
> > > +# Creates a script that counts how much time it is executed and calls
> > > +# notmuch.  $notmuch_counter_command is set to the path to the
> > > +# generated script.  Use notmuch_counter_value() function to get the
> > > +# current counter value.
> > > +notmuch_counter_reset () {
> > > + notmuch_counter_command="$TMP_DIRECTORY/notmuch_counter"
> > > + if [ ! -x "$notmuch_counter_command" ]; then
> > > + 
> > > notmuch_counter_state_path="$TMP_DIRECTORY/notmuch_counter.state"
> > > + cat >"$notmuch_counter_command" < > > +#!/bin/sh
> > > +
> > > +count=\$(cat "$notmuch_counter_state_path")
> > > +echo -n \$(expr \$count + 1) > "$notmuch_counter_state_path"
> > > +
> > > +exec notmuch "\$@"
> > > +EOF
> > > + chmod +x "$notmuch_counter_command" || return
> > > + fi
> > > +
> > > + echo -n 0 > "$notmuch_counter_state_path"
> > > +}
> > > +
> > > +# Returns the current notmuch counter value.
> > > +notmuch_counter_value () {
> > > + if [ -r "$notmuch_counter_state_path" ]; then
> > > + count=$(cat "$notmuch_counter_state_path")
> > > + else
> > > + count=0
> > > + fi
> > > + echo -n $count
> > > +}
> > > +
> > 
> > Good work! It would be nice if the state file contained newline after
> > count number.
> 
> I wonder why it is actually nice :)  I do not have strong preference
> here.  So a newline is added in v3.  Also a newline is added to
> notmuch_counter_value() output for consistency.

It is nice when I enter cat /path/to/notmuch_counter from command
line and shell prompt is not appended at the end of the file contents
(but on next line :)

> 
> > Also some optimizations could be done:
> > 
> 
> (Would be nice if you send a diff, or a human-friendly description of
> the changes.)

Ok, I'll try to do this according to your wishes next time.

> > cat >"$notmuch_counter_command" < > #!/bin/sh
> > 
> > read count < "$notmuch_counter_state_path"
> 
> Nice.  Fixed in the new patch version.
> 
> > echo \$((count + 1)) > "$notmuch_counter_state_path"
> > 
> 
> I do not think this is really an optimization.  And I find expr more
> clear than using $(()).  I always have troubles remembering "random
> special char syntax" (yeah, not a Perl fan :)), prefer human friendly
> words.

The (posix) shell command language defines 'Arithmetic Expansion' in

http://pubs.opengroup.org/onlinepubs/007908799/xcu/chap2.html#tag_001_006_004

I.e. using format $(( expression )) makes shell doing the arithetic itself
instead of forking a process (or two!) to do so.

Normally in this case it is not so big deal (and still it isn't, but...)
In this  particular case the shell wrapper counting notmuch launches and
exec'ing it the wrapper could do this without fork(2)ing a single time
(i.e. keep the process count unchanged compared to execing notmuch
directly)

Anyway, many opinions; as far as it works I'm fine with it :) 

Now that you feel relaxed, check the results of some further
experimentation ;) :

excerpt from man strace:

   -ff If the -o filename option is in effect,  each  processes
   trace  is  written  to  filename.pid  where  pid  is the
   numeric process id of each process.

Executing  rm -f forked.*; strace -ff -o forked bash -c 'echo $(( 5 + 5 ))' 

will output '10' and create just one 'forked.' file

Executing  rm -f forked.*; strace -ff -o forked bash -c 'echo $(expr 5 + 5)' 

output 10 as expected, but there is now *3* forked. files !

bash does not optmize; it forks subshell to execute $(...) and then
there just works as usual (forks subshell to execute builtin expr))

Executing  rm -f forked.*; strace -ff -o forked bash -c 'echo $(exec expr 5 + 
5)' 

(the added 'exec' takes off one fork -- just 2 forked. files appear).

I did the same tests using dash, ksh & zsh on linux system, and every one
of these managed to optimize one fork out in the above 3 fork case.


Tomi


Re: [PATCH 1/3] test: add functions to count how much times notmuch was called

2011-11-29 Thread Dmitry Kurochkin
Hi Tomi.

On Tue, 29 Nov 2011 14:58:00 +0200, Tomi Ollila  wrote:
> Hi Dmitry.
> 
> On Tue, 29 Nov 2011 01:26:39 +0400, Dmitry Kurochkin 
>  wrote:
> > Hi Tomi.
> > 
> > On Mon, 28 Nov 2011 22:42:50 +0200, Tomi Ollila  wrote:
> > > On Mon, 28 Nov 2011 07:28:13 +0400, Dmitry Kurochkin 
> > >  wrote:
> [ ... ]
> > > > +# Creates a script that counts how much time it is executed and calls
> > > > +# notmuch.  $notmuch_counter_command is set to the path to the
> > > > +# generated script.  Use notmuch_counter_value() function to get the
> > > > +# current counter value.
> > > > +notmuch_counter_reset () {
> > > > +   notmuch_counter_command="$TMP_DIRECTORY/notmuch_counter"
> > > > +   if [ ! -x "$notmuch_counter_command" ]; then
> > > > +   
> > > > notmuch_counter_state_path="$TMP_DIRECTORY/notmuch_counter.state"
> > > > +   cat >"$notmuch_counter_command" < > > > +#!/bin/sh
> > > > +
> > > > +count=\$(cat "$notmuch_counter_state_path")
> > > > +echo -n \$(expr \$count + 1) > "$notmuch_counter_state_path"
> > > > +
> > > > +exec notmuch "\$@"
> > > > +EOF
> > > > +   chmod +x "$notmuch_counter_command" || return
> > > > +   fi
> > > > +
> > > > +   echo -n 0 > "$notmuch_counter_state_path"
> > > > +}
> > > > +
> > > > +# Returns the current notmuch counter value.
> > > > +notmuch_counter_value () {
> > > > +   if [ -r "$notmuch_counter_state_path" ]; then
> > > > +   count=$(cat "$notmuch_counter_state_path")
> > > > +   else
> > > > +   count=0
> > > > +   fi
> > > > +   echo -n $count
> > > > +}
> > > > +
> > > 
> > > Good work! It would be nice if the state file contained newline after
> > > count number.
> > 
> > I wonder why it is actually nice :)  I do not have strong preference
> > here.  So a newline is added in v3.  Also a newline is added to
> > notmuch_counter_value() output for consistency.
> 
> It is nice when I enter cat /path/to/notmuch_counter from command
> line and shell prompt is not appended at the end of the file contents
> (but on next line :)
> 
> > 
> > > Also some optimizations could be done:
> > > 
> > 
> > (Would be nice if you send a diff, or a human-friendly description of
> > the changes.)
> 
> Ok, I'll try to do this according to your wishes next time.
> 
> > >   cat >"$notmuch_counter_command" < > > #!/bin/sh
> > > 
> > > read count < "$notmuch_counter_state_path"
> > 
> > Nice.  Fixed in the new patch version.
> > 
> > > echo \$((count + 1)) > "$notmuch_counter_state_path"
> > > 
> > 
> > I do not think this is really an optimization.  And I find expr more
> > clear than using $(()).  I always have troubles remembering "random
> > special char syntax" (yeah, not a Perl fan :)), prefer human friendly
> > words.
> 
> The (posix) shell command language defines 'Arithmetic Expansion' in
> 
> http://pubs.opengroup.org/onlinepubs/007908799/xcu/chap2.html#tag_001_006_004
> 
> I.e. using format $(( expression )) makes shell doing the arithetic itself
> instead of forking a process (or two!) to do so.
> 

I though expr was a builtin.  Now I agree that it is better to replace
it with $(()), even though I still prefer the expr syntax.

> Normally in this case it is not so big deal (and still it isn't, but...)
> In this  particular case the shell wrapper counting notmuch launches and
> exec'ing it the wrapper could do this without fork(2)ing a single time
> (i.e. keep the process count unchanged compared to execing notmuch
> directly)
> 
> Anyway, many opinions; as far as it works I'm fine with it :) 
> 
> Now that you feel relaxed, check the results of some further
> experimentation ;) :
> 
> excerpt from man strace:
> 
>-ff If the -o filename option is in effect,  each  processes
>trace  is  written  to  filename.pid  where  pid  is the
>numeric process id of each process.
> 
> Executing  rm -f forked.*; strace -ff -o forked bash -c 'echo $(( 5 + 5 ))' 
> 
> will output '10' and create just one 'forked.' file
> 
> Executing  rm -f forked.*; strace -ff -o forked bash -c 'echo $(expr 5 + 5)' 
> 
> output 10 as expected, but there is now *3* forked. files !
> 
> bash does not optmize; it forks subshell to execute $(...) and then
> there just works as usual (forks subshell to execute builtin expr))
> 
> Executing  rm -f forked.*; strace -ff -o forked bash -c 'echo $(exec expr 5 + 
> 5)' 
> 
> (the added 'exec' takes off one fork -- just 2 forked. files appear).
> 
> I did the same tests using dash, ksh & zsh on linux system, and every one
> of these managed to optimize one fork out in the above 3 fork case.
> 

Thanks for details.

Regards,
  Dmitry

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


[PATCH 1/3] test: add functions to count how much times notmuch was called

2011-11-29 Thread Jameson Graef Rollins
On Tue, 29 Nov 2011 01:26:39 +0400, Dmitry Kurochkin  wrote:
> > echo \$((count + 1)) > "$notmuch_counter_state_path"
> 
> I do not think this is really an optimization.  And I find expr more
> clear than using $(()).  I always have troubles remembering "random
> special char syntax" (yeah, not a Perl fan :)), prefer human friendly
> words.

This allows the shell to do the math itself, without calling a
subprocess.  I agree with Tomi that $(()) is a little cleaner.

jamie.
-- next part --
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 835 bytes
Desc: not available
URL: 



Re: [PATCH 1/3] test: add functions to count how much times notmuch was called

2011-11-29 Thread Jameson Graef Rollins
On Tue, 29 Nov 2011 01:26:39 +0400, Dmitry Kurochkin 
 wrote:
> > echo \$((count + 1)) > "$notmuch_counter_state_path"
> 
> I do not think this is really an optimization.  And I find expr more
> clear than using $(()).  I always have troubles remembering "random
> special char syntax" (yeah, not a Perl fan :)), prefer human friendly
> words.

This allows the shell to do the math itself, without calling a
subprocess.  I agree with Tomi that $(()) is a little cleaner.

jamie.


pgpjimZCych9s.pgp
Description: PGP signature
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


Re: [PATCH 1/3] test: add functions to count how much times notmuch was called

2011-11-29 Thread Tomi Ollila
Hi Dmitry.

On Tue, 29 Nov 2011 01:26:39 +0400, Dmitry Kurochkin 
 wrote:
> Hi Tomi.
> 
> On Mon, 28 Nov 2011 22:42:50 +0200, Tomi Ollila  wrote:
> > On Mon, 28 Nov 2011 07:28:13 +0400, Dmitry Kurochkin 
> >  wrote:
[ ... ]
> > > +# Creates a script that counts how much time it is executed and calls
> > > +# notmuch.  $notmuch_counter_command is set to the path to the
> > > +# generated script.  Use notmuch_counter_value() function to get the
> > > +# current counter value.
> > > +notmuch_counter_reset () {
> > > + notmuch_counter_command="$TMP_DIRECTORY/notmuch_counter"
> > > + if [ ! -x "$notmuch_counter_command" ]; then
> > > + 
> > > notmuch_counter_state_path="$TMP_DIRECTORY/notmuch_counter.state"
> > > + cat >"$notmuch_counter_command" < > > +#!/bin/sh
> > > +
> > > +count=\$(cat "$notmuch_counter_state_path")
> > > +echo -n \$(expr \$count + 1) > "$notmuch_counter_state_path"
> > > +
> > > +exec notmuch "\$@"
> > > +EOF
> > > + chmod +x "$notmuch_counter_command" || return
> > > + fi
> > > +
> > > + echo -n 0 > "$notmuch_counter_state_path"
> > > +}
> > > +
> > > +# Returns the current notmuch counter value.
> > > +notmuch_counter_value () {
> > > + if [ -r "$notmuch_counter_state_path" ]; then
> > > + count=$(cat "$notmuch_counter_state_path")
> > > + else
> > > + count=0
> > > + fi
> > > + echo -n $count
> > > +}
> > > +
> > 
> > Good work! It would be nice if the state file contained newline after
> > count number.
> 
> I wonder why it is actually nice :)  I do not have strong preference
> here.  So a newline is added in v3.  Also a newline is added to
> notmuch_counter_value() output for consistency.

It is nice when I enter cat /path/to/notmuch_counter from command
line and shell prompt is not appended at the end of the file contents
(but on next line :)

> 
> > Also some optimizations could be done:
> > 
> 
> (Would be nice if you send a diff, or a human-friendly description of
> the changes.)

Ok, I'll try to do this according to your wishes next time.

> > cat >"$notmuch_counter_command" < > #!/bin/sh
> > 
> > read count < "$notmuch_counter_state_path"
> 
> Nice.  Fixed in the new patch version.
> 
> > echo \$((count + 1)) > "$notmuch_counter_state_path"
> > 
> 
> I do not think this is really an optimization.  And I find expr more
> clear than using $(()).  I always have troubles remembering "random
> special char syntax" (yeah, not a Perl fan :)), prefer human friendly
> words.

The (posix) shell command language defines 'Arithmetic Expansion' in

http://pubs.opengroup.org/onlinepubs/007908799/xcu/chap2.html#tag_001_006_004

I.e. using format $(( expression )) makes shell doing the arithetic itself
instead of forking a process (or two!) to do so.

Normally in this case it is not so big deal (and still it isn't, but...)
In this  particular case the shell wrapper counting notmuch launches and
exec'ing it the wrapper could do this without fork(2)ing a single time
(i.e. keep the process count unchanged compared to execing notmuch
directly)

Anyway, many opinions; as far as it works I'm fine with it :) 

Now that you feel relaxed, check the results of some further
experimentation ;) :

excerpt from man strace:

   -ff If the -o filename option is in effect,  each  processes
   trace  is  written  to  filename.pid  where  pid  is the
   numeric process id of each process.

Executing  rm -f forked.*; strace -ff -o forked bash -c 'echo $(( 5 + 5 ))' 

will output '10' and create just one 'forked.' file

Executing  rm -f forked.*; strace -ff -o forked bash -c 'echo $(expr 5 + 5)' 

output 10 as expected, but there is now *3* forked. files !

bash does not optmize; it forks subshell to execute $(...) and then
there just works as usual (forks subshell to execute builtin expr))

Executing  rm -f forked.*; strace -ff -o forked bash -c 'echo $(exec expr 5 + 
5)' 

(the added 'exec' takes off one fork -- just 2 forked. files appear).

I did the same tests using dash, ksh & zsh on linux system, and every one
of these managed to optimize one fork out in the above 3 fork case.


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


Re: [PATCH 1/3] test: add functions to count how much times notmuch was called

2011-11-29 Thread Dmitry Kurochkin
Hi Tomi.

On Mon, 28 Nov 2011 22:42:50 +0200, Tomi Ollila  wrote:
> On Mon, 28 Nov 2011 07:28:13 +0400, Dmitry Kurochkin 
>  wrote:
> 
> [...]
> > +
> > +These allow to count how many times notmuch binary is called.
> > +notmuch_counter_reset() function generates a script that counts
> > +how many times it is called and resets the counter to zero.  The
> > +function sets $notmuch_counter_command variable to the path to the
> > +generated script that should be called instead of notmuch to do
> > +the counting.  The notmuch_counter_value() function prints the
> > +current counter value.
> > diff --git a/test/test-lib.sh b/test/test-lib.sh
> > index 076f929..880bed9 100644
> > --- a/test/test-lib.sh
> > +++ b/test/test-lib.sh
> > @@ -868,6 +868,38 @@ test_emacs () {
> > emacsclient --socket-name="$EMACS_SERVER" --eval "(progn $@)"
> >  }
> >  
> > +# Creates a script that counts how much time it is executed and calls
> > +# notmuch.  $notmuch_counter_command is set to the path to the
> > +# generated script.  Use notmuch_counter_value() function to get the
> > +# current counter value.
> > +notmuch_counter_reset () {
> > +   notmuch_counter_command="$TMP_DIRECTORY/notmuch_counter"
> > +   if [ ! -x "$notmuch_counter_command" ]; then
> > +   
> > notmuch_counter_state_path="$TMP_DIRECTORY/notmuch_counter.state"
> > +   cat >"$notmuch_counter_command" < > +#!/bin/sh
> > +
> > +count=\$(cat "$notmuch_counter_state_path")
> > +echo -n \$(expr \$count + 1) > "$notmuch_counter_state_path"
> > +
> > +exec notmuch "\$@"
> > +EOF
> > +   chmod +x "$notmuch_counter_command" || return
> > +   fi
> > +
> > +   echo -n 0 > "$notmuch_counter_state_path"
> > +}
> > +
> > +# Returns the current notmuch counter value.
> > +notmuch_counter_value () {
> > +   if [ -r "$notmuch_counter_state_path" ]; then
> > +   count=$(cat "$notmuch_counter_state_path")
> > +   else
> > +   count=0
> > +   fi
> > +   echo -n $count
> > +}
> > +
> 
> Good work! It would be nice if the state file contained newline after
> count number.

I wonder why it is actually nice :)  I do not have strong preference
here.  So a newline is added in v3.  Also a newline is added to
notmuch_counter_value() output for consistency.

> Also some optimizations could be done:
> 

(Would be nice if you send a diff, or a human-friendly description of
the changes.)

>   cat >"$notmuch_counter_command" < #!/bin/sh
> 
> read count < "$notmuch_counter_state_path"

Nice.  Fixed in the new patch version.

> echo \$((count + 1)) > "$notmuch_counter_state_path"
> 

I do not think this is really an optimization.  And I find expr more
clear than using $(()).  I always have troubles remembering "random
special char syntax" (yeah, not a Perl fan :)), prefer human friendly
words.

> exec notmuch "\$@"
> EOF
>   chmod +x "$notmuch_counter_command" || return
>   fi
> 
>   echo 0 > "$notmuch_counter_state_path"
> }
> 
> # Returns the current notmuch counter value.
> notmuch_counter_value () {
>   if [ -r "$notmuch_counter_state_path" ]; then
>   read count < "$notmuch_counter_state_path"

Also changes in v3.

Regards,
  Dmitry

>   else
>   count=0
>   fi
>   echo -n $count
> }
> 
> 
> Tomi
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


Re: [PATCH 1/3] test: add functions to count how much times notmuch was called

2011-11-29 Thread Tomi Ollila
On Mon, 28 Nov 2011 07:28:13 +0400, Dmitry Kurochkin 
 wrote:

[...]
> +
> +These allow to count how many times notmuch binary is called.
> +notmuch_counter_reset() function generates a script that counts
> +how many times it is called and resets the counter to zero.  The
> +function sets $notmuch_counter_command variable to the path to the
> +generated script that should be called instead of notmuch to do
> +the counting.  The notmuch_counter_value() function prints the
> +current counter value.
> diff --git a/test/test-lib.sh b/test/test-lib.sh
> index 076f929..880bed9 100644
> --- a/test/test-lib.sh
> +++ b/test/test-lib.sh
> @@ -868,6 +868,38 @@ test_emacs () {
>   emacsclient --socket-name="$EMACS_SERVER" --eval "(progn $@)"
>  }
>  
> +# Creates a script that counts how much time it is executed and calls
> +# notmuch.  $notmuch_counter_command is set to the path to the
> +# generated script.  Use notmuch_counter_value() function to get the
> +# current counter value.
> +notmuch_counter_reset () {
> + notmuch_counter_command="$TMP_DIRECTORY/notmuch_counter"
> + if [ ! -x "$notmuch_counter_command" ]; then
> + 
> notmuch_counter_state_path="$TMP_DIRECTORY/notmuch_counter.state"
> + cat >"$notmuch_counter_command" < +#!/bin/sh
> +
> +count=\$(cat "$notmuch_counter_state_path")
> +echo -n \$(expr \$count + 1) > "$notmuch_counter_state_path"
> +
> +exec notmuch "\$@"
> +EOF
> + chmod +x "$notmuch_counter_command" || return
> + fi
> +
> + echo -n 0 > "$notmuch_counter_state_path"
> +}
> +
> +# Returns the current notmuch counter value.
> +notmuch_counter_value () {
> + if [ -r "$notmuch_counter_state_path" ]; then
> + count=$(cat "$notmuch_counter_state_path")
> + else
> + count=0
> + fi
> + echo -n $count
> +}
> +

Good work! It would be nice if the state file contained newline after
count number. Also some optimizations could be done:

cat >"$notmuch_counter_command" < "$notmuch_counter_state_path"

exec notmuch "\$@"
EOF
chmod +x "$notmuch_counter_command" || return
fi

echo 0 > "$notmuch_counter_state_path"
}

# Returns the current notmuch counter value.
notmuch_counter_value () {
if [ -r "$notmuch_counter_state_path" ]; then
read count < "$notmuch_counter_state_path"
else
count=0
fi
echo -n $count
}


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


[PATCH 1/3] test: add functions to count how much times notmuch was called

2011-11-29 Thread Dmitry Kurochkin
Hi Tomi.

On Mon, 28 Nov 2011 22:42:50 +0200, Tomi Ollila  wrote:
> On Mon, 28 Nov 2011 07:28:13 +0400, Dmitry Kurochkin  gmail.com> wrote:
> 
> [...]
> > +
> > +These allow to count how many times notmuch binary is called.
> > +notmuch_counter_reset() function generates a script that counts
> > +how many times it is called and resets the counter to zero.  The
> > +function sets $notmuch_counter_command variable to the path to the
> > +generated script that should be called instead of notmuch to do
> > +the counting.  The notmuch_counter_value() function prints the
> > +current counter value.
> > diff --git a/test/test-lib.sh b/test/test-lib.sh
> > index 076f929..880bed9 100644
> > --- a/test/test-lib.sh
> > +++ b/test/test-lib.sh
> > @@ -868,6 +868,38 @@ test_emacs () {
> > emacsclient --socket-name="$EMACS_SERVER" --eval "(progn $@)"
> >  }
> >  
> > +# Creates a script that counts how much time it is executed and calls
> > +# notmuch.  $notmuch_counter_command is set to the path to the
> > +# generated script.  Use notmuch_counter_value() function to get the
> > +# current counter value.
> > +notmuch_counter_reset () {
> > +   notmuch_counter_command="$TMP_DIRECTORY/notmuch_counter"
> > +   if [ ! -x "$notmuch_counter_command" ]; then
> > +   
> > notmuch_counter_state_path="$TMP_DIRECTORY/notmuch_counter.state"
> > +   cat >"$notmuch_counter_command" < > +#!/bin/sh
> > +
> > +count=\$(cat "$notmuch_counter_state_path")
> > +echo -n \$(expr \$count + 1) > "$notmuch_counter_state_path"
> > +
> > +exec notmuch "\$@"
> > +EOF
> > +   chmod +x "$notmuch_counter_command" || return
> > +   fi
> > +
> > +   echo -n 0 > "$notmuch_counter_state_path"
> > +}
> > +
> > +# Returns the current notmuch counter value.
> > +notmuch_counter_value () {
> > +   if [ -r "$notmuch_counter_state_path" ]; then
> > +   count=$(cat "$notmuch_counter_state_path")
> > +   else
> > +   count=0
> > +   fi
> > +   echo -n $count
> > +}
> > +
> 
> Good work! It would be nice if the state file contained newline after
> count number.

I wonder why it is actually nice :)  I do not have strong preference
here.  So a newline is added in v3.  Also a newline is added to
notmuch_counter_value() output for consistency.

> Also some optimizations could be done:
> 

(Would be nice if you send a diff, or a human-friendly description of
the changes.)

>   cat >"$notmuch_counter_command" < #!/bin/sh
> 
> read count < "$notmuch_counter_state_path"

Nice.  Fixed in the new patch version.

> echo \$((count + 1)) > "$notmuch_counter_state_path"
> 

I do not think this is really an optimization.  And I find expr more
clear than using $(()).  I always have troubles remembering "random
special char syntax" (yeah, not a Perl fan :)), prefer human friendly
words.

> exec notmuch "\$@"
> EOF
>   chmod +x "$notmuch_counter_command" || return
>   fi
> 
>   echo 0 > "$notmuch_counter_state_path"
> }
> 
> # Returns the current notmuch counter value.
> notmuch_counter_value () {
>   if [ -r "$notmuch_counter_state_path" ]; then
>   read count < "$notmuch_counter_state_path"

Also changes in v3.

Regards,
  Dmitry

>   else
>   count=0
>   fi
>   echo -n $count
> }
> 
> 
> Tomi


[PATCH 1/3] test: add functions to count how much times notmuch was called

2011-11-28 Thread Tomi Ollila
On Mon, 28 Nov 2011 07:28:13 +0400, Dmitry Kurochkin  wrote:

[...]
> +
> +These allow to count how many times notmuch binary is called.
> +notmuch_counter_reset() function generates a script that counts
> +how many times it is called and resets the counter to zero.  The
> +function sets $notmuch_counter_command variable to the path to the
> +generated script that should be called instead of notmuch to do
> +the counting.  The notmuch_counter_value() function prints the
> +current counter value.
> diff --git a/test/test-lib.sh b/test/test-lib.sh
> index 076f929..880bed9 100644
> --- a/test/test-lib.sh
> +++ b/test/test-lib.sh
> @@ -868,6 +868,38 @@ test_emacs () {
>   emacsclient --socket-name="$EMACS_SERVER" --eval "(progn $@)"
>  }
>  
> +# Creates a script that counts how much time it is executed and calls
> +# notmuch.  $notmuch_counter_command is set to the path to the
> +# generated script.  Use notmuch_counter_value() function to get the
> +# current counter value.
> +notmuch_counter_reset () {
> + notmuch_counter_command="$TMP_DIRECTORY/notmuch_counter"
> + if [ ! -x "$notmuch_counter_command" ]; then
> + 
> notmuch_counter_state_path="$TMP_DIRECTORY/notmuch_counter.state"
> + cat >"$notmuch_counter_command" < +#!/bin/sh
> +
> +count=\$(cat "$notmuch_counter_state_path")
> +echo -n \$(expr \$count + 1) > "$notmuch_counter_state_path"
> +
> +exec notmuch "\$@"
> +EOF
> + chmod +x "$notmuch_counter_command" || return
> + fi
> +
> + echo -n 0 > "$notmuch_counter_state_path"
> +}
> +
> +# Returns the current notmuch counter value.
> +notmuch_counter_value () {
> + if [ -r "$notmuch_counter_state_path" ]; then
> + count=$(cat "$notmuch_counter_state_path")
> + else
> + count=0
> + fi
> + echo -n $count
> +}
> +

Good work! It would be nice if the state file contained newline after
count number. Also some optimizations could be done:

cat >"$notmuch_counter_command" < "$notmuch_counter_state_path"

exec notmuch "\$@"
EOF
chmod +x "$notmuch_counter_command" || return
fi

echo 0 > "$notmuch_counter_state_path"
}

# Returns the current notmuch counter value.
notmuch_counter_value () {
if [ -r "$notmuch_counter_state_path" ]; then
read count < "$notmuch_counter_state_path"
else
count=0
fi
echo -n $count
}


Tomi


[PATCH 1/3] test: add functions to count how much times notmuch was called

2011-11-28 Thread Dmitry Kurochkin
The patch adds two auxiliary functions and a variable:

  notmuch_counter_reset
  $notmuch_counter_command
  notmuch_counter_value

They allow to count how many times notmuch binary is called.
notmuch_counter_reset() function generates a script that counts how
many times it is called and resets the counter to zero.  The function
sets $notmuch_counter_command variable to the path to the generated
script that should be called instead of notmuch to do the counting.
The notmuch_counter_value() function returns the current counter
value.
---
 test/README  |   16 ++--
 test/test-lib.sh |   32 
 2 files changed, 46 insertions(+), 2 deletions(-)

diff --git a/test/README b/test/README
index 2481f16..5dc0638 100644
--- a/test/README
+++ b/test/README
@@ -187,8 +187,8 @@ library for your script to use.
is to summarize successes and failures in the test script and
exit with an appropriate error code.

-There are also a number of mail-specific functions which are useful in
-writing tests:
+There are also a number of notmuch-specific auxiliary functions and
+variables which are useful in writing tests:

   generate_message

@@ -212,3 +212,15 @@ writing tests:
 will initialize the mail database to a known state of 50 sample
 messages, (culled from the early history of the notmuch mailing
 list).
+
+  notmuch_counter_reset
+  $notmuch_counter_command
+  notmuch_counter_value
+
+These allow to count how many times notmuch binary is called.
+notmuch_counter_reset() function generates a script that counts
+how many times it is called and resets the counter to zero.  The
+function sets $notmuch_counter_command variable to the path to the
+generated script that should be called instead of notmuch to do
+the counting.  The notmuch_counter_value() function prints the
+current counter value.
diff --git a/test/test-lib.sh b/test/test-lib.sh
index 076f929..880bed9 100644
--- a/test/test-lib.sh
+++ b/test/test-lib.sh
@@ -868,6 +868,38 @@ test_emacs () {
emacsclient --socket-name="$EMACS_SERVER" --eval "(progn $@)"
 }

+# Creates a script that counts how much time it is executed and calls
+# notmuch.  $notmuch_counter_command is set to the path to the
+# generated script.  Use notmuch_counter_value() function to get the
+# current counter value.
+notmuch_counter_reset () {
+   notmuch_counter_command="$TMP_DIRECTORY/notmuch_counter"
+   if [ ! -x "$notmuch_counter_command" ]; then
+   
notmuch_counter_state_path="$TMP_DIRECTORY/notmuch_counter.state"
+   cat >"$notmuch_counter_command" < "$notmuch_counter_state_path"
+
+exec notmuch "\$@"
+EOF
+   chmod +x "$notmuch_counter_command" || return
+   fi
+
+   echo -n 0 > "$notmuch_counter_state_path"
+}
+
+# Returns the current notmuch counter value.
+notmuch_counter_value () {
+   if [ -r "$notmuch_counter_state_path" ]; then
+   count=$(cat "$notmuch_counter_state_path")
+   else
+   count=0
+   fi
+   echo -n $count
+}
+
 test_reset_state_ () {
test_subtest_known_broken_=
 }
-- 
1.7.7.3



[PATCH 1/3] test: add functions to count how much times notmuch was called

2011-11-28 Thread Dmitry Kurochkin
On Sun, 27 Nov 2011 21:44:23 -0500, Austin Clements  wrote:
> On Sat, 26 Nov 2011 05:44:36 +0400, Dmitry Kurochkin  gmail.com> wrote:
> > The patch adds two auxiliary functions and a variable:
> > 
> >   notmuch_counter_reset
> >   $notmuch_counter
> >   notmuch_counter
> > 
> > They allow to count how many times notmuch binary is called.
> > notmuch_counter_reset() function generates a script that counts how
> > many times it is called and resets the counter to zero.  The function
> > sets $notmuch_counter variable to the path to the generated script
> > that should be called instead of notmuch to do the counting.  The
> > notmuch_counter() function returns the current counter value.
> 
> Great idea!
> 
> > ---
> >  test/README  |   16 ++--
> >  test/test-lib.sh |   32 
> >  2 files changed, 46 insertions(+), 2 deletions(-)
> > 
> > diff --git a/test/README b/test/README
> > index 2481f16..1570f7c 100644
> > --- a/test/README
> > +++ b/test/README
> > @@ -187,8 +187,8 @@ library for your script to use.
> > is to summarize successes and failures in the test script and
> > exit with an appropriate error code.
> >  
> > -There are also a number of mail-specific functions which are useful in
> > -writing tests:
> > +There are also a number of notmuch-specific auxiliary functions and
> > +variables which are useful in writing tests:
> >  
> >generate_message
> >  
> > @@ -212,3 +212,15 @@ writing tests:
> >  will initialize the mail database to a known state of 50 sample
> >  messages, (culled from the early history of the notmuch mailing
> >  list).
> > +
> > +  notmuch_counter_reset
> > +  $notmuch_counter
> > +  notmuch_counter
> 
> From the name, I would expect $notmuch_counter to be the counter value
> (ignoring the difficulty of implementing that).  Perhaps
> $notmuch_counter_command, since it's meant to be bound to
> notmuch-command?
> 

renamed

> notmuch_counter is okay, but maybe notmuch_counter_value?
> 

renamed

> > +
> > +These allow to count how many times notmuch binary is called.
> > +notmuch_counter_reset() function generates a script that counts
> > +how many times it is called and resets the counter to zero.  The
> > +function sets $notmuch_counter variable to the path to the
> > +generated script that should be called instead of notmuch to do
> > +the counting.  The notmuch_counter() function returns the current
> > +counter value.
> 
> It doesn't return the counter value, it prints it.
> 

indeed, fixed

> > diff --git a/test/test-lib.sh b/test/test-lib.sh
> > index 93867b0..e3b85d0 100755
> > --- a/test/test-lib.sh
> > +++ b/test/test-lib.sh
> > @@ -864,6 +864,38 @@ test_emacs () {
> > emacsclient --socket-name="$EMACS_SERVER" --eval "(progn $@)"
> >  }
> >  
> > +# Creates a script that counts how much time it is executed and calls
> > +# notmuch.  $notmuch_counter is set to the path to the generated
> > +# script.  Use notmuch_counter() function to get the current counter
> > +# value.
> > +notmuch_counter_reset () {
> > +   notmuch_counter="$TMP_DIRECTORY/notmuch_counter"
> > +   if [ ! -x "$notmuch_counter" ]; then
> > +   
> > notmuch_counter_state_path="$TMP_DIRECTORY/notmuch_counter.state"
> > +   cat <"$notmuch_counter"
> 
> This is totally a stylistic pet peeve, but consider
>   cat >"$notmuch_counter" < 

fixed

> > +#!/bin/sh
> > +
> > +count=\$(cat "$notmuch_counter_state_path")
> > +echo -n \$(expr \$count + 1) > "$notmuch_counter_state_path"
> > +
> > +exec notmuch "\$@"
> > +EOF
> > +   chmod +x "$notmuch_counter" || return
> > +   fi
> > +
> > +   echo -n 0 > "$notmuch_counter_state_path" || return
> 
> What are the || return's for?
> 

If echo failed by some reason, that is an error.

Thank you for the reviews.  I will send amended series soon.

Regards,
  Dmitry

> > +}
> > +
> > +# Returns the current notmuch counter value.
> > +notmuch_counter () {
> > +   if [ -r "$notmuch_counter_state_path" ]; then
> > +   count=$(cat "$notmuch_counter_state_path")
> > +   else
> > +   count=0
> > +   fi
> > +   echo -n $count
> > +}
> > +
> >  
> >  find_notmuch_path ()
> >  {
> > -- 
> > 1.7.7.3
> > 
> > ___
> > notmuch mailing list
> > notmuch at notmuchmail.org
> > http://notmuchmail.org/mailman/listinfo/notmuch
> > 


[PATCH 1/3] test: add functions to count how much times notmuch was called

2011-11-27 Thread Austin Clements
On Sat, 26 Nov 2011 05:44:36 +0400, Dmitry Kurochkin  wrote:
> The patch adds two auxiliary functions and a variable:
> 
>   notmuch_counter_reset
>   $notmuch_counter
>   notmuch_counter
> 
> They allow to count how many times notmuch binary is called.
> notmuch_counter_reset() function generates a script that counts how
> many times it is called and resets the counter to zero.  The function
> sets $notmuch_counter variable to the path to the generated script
> that should be called instead of notmuch to do the counting.  The
> notmuch_counter() function returns the current counter value.

Great idea!

> ---
>  test/README  |   16 ++--
>  test/test-lib.sh |   32 
>  2 files changed, 46 insertions(+), 2 deletions(-)
> 
> diff --git a/test/README b/test/README
> index 2481f16..1570f7c 100644
> --- a/test/README
> +++ b/test/README
> @@ -187,8 +187,8 @@ library for your script to use.
> is to summarize successes and failures in the test script and
> exit with an appropriate error code.
>  
> -There are also a number of mail-specific functions which are useful in
> -writing tests:
> +There are also a number of notmuch-specific auxiliary functions and
> +variables which are useful in writing tests:
>  
>generate_message
>  
> @@ -212,3 +212,15 @@ writing tests:
>  will initialize the mail database to a known state of 50 sample
>  messages, (culled from the early history of the notmuch mailing
>  list).
> +
> +  notmuch_counter_reset
> +  $notmuch_counter
> +  notmuch_counter

>From the name, I would expect $notmuch_counter to be the counter value
(ignoring the difficulty of implementing that).  Perhaps
$notmuch_counter_command, since it's meant to be bound to
notmuch-command?

notmuch_counter is okay, but maybe notmuch_counter_value?

> +
> +These allow to count how many times notmuch binary is called.
> +notmuch_counter_reset() function generates a script that counts
> +how many times it is called and resets the counter to zero.  The
> +function sets $notmuch_counter variable to the path to the
> +generated script that should be called instead of notmuch to do
> +the counting.  The notmuch_counter() function returns the current
> +counter value.

It doesn't return the counter value, it prints it.

> diff --git a/test/test-lib.sh b/test/test-lib.sh
> index 93867b0..e3b85d0 100755
> --- a/test/test-lib.sh
> +++ b/test/test-lib.sh
> @@ -864,6 +864,38 @@ test_emacs () {
>   emacsclient --socket-name="$EMACS_SERVER" --eval "(progn $@)"
>  }
>  
> +# Creates a script that counts how much time it is executed and calls
> +# notmuch.  $notmuch_counter is set to the path to the generated
> +# script.  Use notmuch_counter() function to get the current counter
> +# value.
> +notmuch_counter_reset () {
> + notmuch_counter="$TMP_DIRECTORY/notmuch_counter"
> + if [ ! -x "$notmuch_counter" ]; then
> + 
> notmuch_counter_state_path="$TMP_DIRECTORY/notmuch_counter.state"
> + cat <"$notmuch_counter"

This is totally a stylistic pet peeve, but consider
  cat >"$notmuch_counter" < +#!/bin/sh
> +
> +count=\$(cat "$notmuch_counter_state_path")
> +echo -n \$(expr \$count + 1) > "$notmuch_counter_state_path"
> +
> +exec notmuch "\$@"
> +EOF
> + chmod +x "$notmuch_counter" || return
> + fi
> +
> + echo -n 0 > "$notmuch_counter_state_path" || return

What are the || return's for?

> +}
> +
> +# Returns the current notmuch counter value.
> +notmuch_counter () {
> + if [ -r "$notmuch_counter_state_path" ]; then
> + count=$(cat "$notmuch_counter_state_path")
> + else
> + count=0
> + fi
> + echo -n $count
> +}
> +
>  
>  find_notmuch_path ()
>  {
> -- 
> 1.7.7.3
> 
> ___
> notmuch mailing list
> notmuch at notmuchmail.org
> http://notmuchmail.org/mailman/listinfo/notmuch
> 


[PATCH 1/3] test: add functions to count how much times notmuch was called

2011-11-27 Thread Dmitry Kurochkin
The patch adds two auxiliary functions and a variable:

  notmuch_counter_reset
  $notmuch_counter_command
  notmuch_counter_value

They allow to count how many times notmuch binary is called.
notmuch_counter_reset() function generates a script that counts how
many times it is called and resets the counter to zero.  The function
sets $notmuch_counter_command variable to the path to the generated
script that should be called instead of notmuch to do the counting.
The notmuch_counter_value() function returns the current counter
value.
---
 test/README  |   16 ++--
 test/test-lib.sh |   32 
 2 files changed, 46 insertions(+), 2 deletions(-)

diff --git a/test/README b/test/README
index 2481f16..5dc0638 100644
--- a/test/README
+++ b/test/README
@@ -187,8 +187,8 @@ library for your script to use.
is to summarize successes and failures in the test script and
exit with an appropriate error code.
 
-There are also a number of mail-specific functions which are useful in
-writing tests:
+There are also a number of notmuch-specific auxiliary functions and
+variables which are useful in writing tests:
 
   generate_message
 
@@ -212,3 +212,15 @@ writing tests:
 will initialize the mail database to a known state of 50 sample
 messages, (culled from the early history of the notmuch mailing
 list).
+
+  notmuch_counter_reset
+  $notmuch_counter_command
+  notmuch_counter_value
+
+These allow to count how many times notmuch binary is called.
+notmuch_counter_reset() function generates a script that counts
+how many times it is called and resets the counter to zero.  The
+function sets $notmuch_counter_command variable to the path to the
+generated script that should be called instead of notmuch to do
+the counting.  The notmuch_counter_value() function prints the
+current counter value.
diff --git a/test/test-lib.sh b/test/test-lib.sh
index 076f929..880bed9 100644
--- a/test/test-lib.sh
+++ b/test/test-lib.sh
@@ -868,6 +868,38 @@ test_emacs () {
emacsclient --socket-name="$EMACS_SERVER" --eval "(progn $@)"
 }
 
+# Creates a script that counts how much time it is executed and calls
+# notmuch.  $notmuch_counter_command is set to the path to the
+# generated script.  Use notmuch_counter_value() function to get the
+# current counter value.
+notmuch_counter_reset () {
+   notmuch_counter_command="$TMP_DIRECTORY/notmuch_counter"
+   if [ ! -x "$notmuch_counter_command" ]; then
+   
notmuch_counter_state_path="$TMP_DIRECTORY/notmuch_counter.state"
+   cat >"$notmuch_counter_command" < "$notmuch_counter_state_path"
+
+exec notmuch "\$@"
+EOF
+   chmod +x "$notmuch_counter_command" || return
+   fi
+
+   echo -n 0 > "$notmuch_counter_state_path"
+}
+
+# Returns the current notmuch counter value.
+notmuch_counter_value () {
+   if [ -r "$notmuch_counter_state_path" ]; then
+   count=$(cat "$notmuch_counter_state_path")
+   else
+   count=0
+   fi
+   echo -n $count
+}
+
 test_reset_state_ () {
test_subtest_known_broken_=
 }
-- 
1.7.7.3

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


Re: [PATCH 1/3] test: add functions to count how much times notmuch was called

2011-11-27 Thread Dmitry Kurochkin
On Sun, 27 Nov 2011 21:44:23 -0500, Austin Clements  wrote:
> On Sat, 26 Nov 2011 05:44:36 +0400, Dmitry Kurochkin 
>  wrote:
> > The patch adds two auxiliary functions and a variable:
> > 
> >   notmuch_counter_reset
> >   $notmuch_counter
> >   notmuch_counter
> > 
> > They allow to count how many times notmuch binary is called.
> > notmuch_counter_reset() function generates a script that counts how
> > many times it is called and resets the counter to zero.  The function
> > sets $notmuch_counter variable to the path to the generated script
> > that should be called instead of notmuch to do the counting.  The
> > notmuch_counter() function returns the current counter value.
> 
> Great idea!
> 
> > ---
> >  test/README  |   16 ++--
> >  test/test-lib.sh |   32 
> >  2 files changed, 46 insertions(+), 2 deletions(-)
> > 
> > diff --git a/test/README b/test/README
> > index 2481f16..1570f7c 100644
> > --- a/test/README
> > +++ b/test/README
> > @@ -187,8 +187,8 @@ library for your script to use.
> > is to summarize successes and failures in the test script and
> > exit with an appropriate error code.
> >  
> > -There are also a number of mail-specific functions which are useful in
> > -writing tests:
> > +There are also a number of notmuch-specific auxiliary functions and
> > +variables which are useful in writing tests:
> >  
> >generate_message
> >  
> > @@ -212,3 +212,15 @@ writing tests:
> >  will initialize the mail database to a known state of 50 sample
> >  messages, (culled from the early history of the notmuch mailing
> >  list).
> > +
> > +  notmuch_counter_reset
> > +  $notmuch_counter
> > +  notmuch_counter
> 
> From the name, I would expect $notmuch_counter to be the counter value
> (ignoring the difficulty of implementing that).  Perhaps
> $notmuch_counter_command, since it's meant to be bound to
> notmuch-command?
> 

renamed

> notmuch_counter is okay, but maybe notmuch_counter_value?
> 

renamed

> > +
> > +These allow to count how many times notmuch binary is called.
> > +notmuch_counter_reset() function generates a script that counts
> > +how many times it is called and resets the counter to zero.  The
> > +function sets $notmuch_counter variable to the path to the
> > +generated script that should be called instead of notmuch to do
> > +the counting.  The notmuch_counter() function returns the current
> > +counter value.
> 
> It doesn't return the counter value, it prints it.
> 

indeed, fixed

> > diff --git a/test/test-lib.sh b/test/test-lib.sh
> > index 93867b0..e3b85d0 100755
> > --- a/test/test-lib.sh
> > +++ b/test/test-lib.sh
> > @@ -864,6 +864,38 @@ test_emacs () {
> > emacsclient --socket-name="$EMACS_SERVER" --eval "(progn $@)"
> >  }
> >  
> > +# Creates a script that counts how much time it is executed and calls
> > +# notmuch.  $notmuch_counter is set to the path to the generated
> > +# script.  Use notmuch_counter() function to get the current counter
> > +# value.
> > +notmuch_counter_reset () {
> > +   notmuch_counter="$TMP_DIRECTORY/notmuch_counter"
> > +   if [ ! -x "$notmuch_counter" ]; then
> > +   
> > notmuch_counter_state_path="$TMP_DIRECTORY/notmuch_counter.state"
> > +   cat <"$notmuch_counter"
> 
> This is totally a stylistic pet peeve, but consider
>   cat >"$notmuch_counter" < 

fixed

> > +#!/bin/sh
> > +
> > +count=\$(cat "$notmuch_counter_state_path")
> > +echo -n \$(expr \$count + 1) > "$notmuch_counter_state_path"
> > +
> > +exec notmuch "\$@"
> > +EOF
> > +   chmod +x "$notmuch_counter" || return
> > +   fi
> > +
> > +   echo -n 0 > "$notmuch_counter_state_path" || return
> 
> What are the || return's for?
> 

If echo failed by some reason, that is an error.

Thank you for the reviews.  I will send amended series soon.

Regards,
  Dmitry

> > +}
> > +
> > +# Returns the current notmuch counter value.
> > +notmuch_counter () {
> > +   if [ -r "$notmuch_counter_state_path" ]; then
> > +   count=$(cat "$notmuch_counter_state_path")
> > +   else
> > +   count=0
> > +   fi
> > +   echo -n $count
> > +}
> > +
> >  
> >  find_notmuch_path ()
> >  {
> > -- 
> > 1.7.7.3
> > 
> > ___
> > notmuch mailing list
> > notmuch@notmuchmail.org
> > http://notmuchmail.org/mailman/listinfo/notmuch
> > 
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


Re: [PATCH 1/3] test: add functions to count how much times notmuch was called

2011-11-27 Thread Austin Clements
On Sat, 26 Nov 2011 05:44:36 +0400, Dmitry Kurochkin 
 wrote:
> The patch adds two auxiliary functions and a variable:
> 
>   notmuch_counter_reset
>   $notmuch_counter
>   notmuch_counter
> 
> They allow to count how many times notmuch binary is called.
> notmuch_counter_reset() function generates a script that counts how
> many times it is called and resets the counter to zero.  The function
> sets $notmuch_counter variable to the path to the generated script
> that should be called instead of notmuch to do the counting.  The
> notmuch_counter() function returns the current counter value.

Great idea!

> ---
>  test/README  |   16 ++--
>  test/test-lib.sh |   32 
>  2 files changed, 46 insertions(+), 2 deletions(-)
> 
> diff --git a/test/README b/test/README
> index 2481f16..1570f7c 100644
> --- a/test/README
> +++ b/test/README
> @@ -187,8 +187,8 @@ library for your script to use.
> is to summarize successes and failures in the test script and
> exit with an appropriate error code.
>  
> -There are also a number of mail-specific functions which are useful in
> -writing tests:
> +There are also a number of notmuch-specific auxiliary functions and
> +variables which are useful in writing tests:
>  
>generate_message
>  
> @@ -212,3 +212,15 @@ writing tests:
>  will initialize the mail database to a known state of 50 sample
>  messages, (culled from the early history of the notmuch mailing
>  list).
> +
> +  notmuch_counter_reset
> +  $notmuch_counter
> +  notmuch_counter

>From the name, I would expect $notmuch_counter to be the counter value
(ignoring the difficulty of implementing that).  Perhaps
$notmuch_counter_command, since it's meant to be bound to
notmuch-command?

notmuch_counter is okay, but maybe notmuch_counter_value?

> +
> +These allow to count how many times notmuch binary is called.
> +notmuch_counter_reset() function generates a script that counts
> +how many times it is called and resets the counter to zero.  The
> +function sets $notmuch_counter variable to the path to the
> +generated script that should be called instead of notmuch to do
> +the counting.  The notmuch_counter() function returns the current
> +counter value.

It doesn't return the counter value, it prints it.

> diff --git a/test/test-lib.sh b/test/test-lib.sh
> index 93867b0..e3b85d0 100755
> --- a/test/test-lib.sh
> +++ b/test/test-lib.sh
> @@ -864,6 +864,38 @@ test_emacs () {
>   emacsclient --socket-name="$EMACS_SERVER" --eval "(progn $@)"
>  }
>  
> +# Creates a script that counts how much time it is executed and calls
> +# notmuch.  $notmuch_counter is set to the path to the generated
> +# script.  Use notmuch_counter() function to get the current counter
> +# value.
> +notmuch_counter_reset () {
> + notmuch_counter="$TMP_DIRECTORY/notmuch_counter"
> + if [ ! -x "$notmuch_counter" ]; then
> + 
> notmuch_counter_state_path="$TMP_DIRECTORY/notmuch_counter.state"
> + cat <"$notmuch_counter"

This is totally a stylistic pet peeve, but consider
  cat >"$notmuch_counter" < +#!/bin/sh
> +
> +count=\$(cat "$notmuch_counter_state_path")
> +echo -n \$(expr \$count + 1) > "$notmuch_counter_state_path"
> +
> +exec notmuch "\$@"
> +EOF
> + chmod +x "$notmuch_counter" || return
> + fi
> +
> + echo -n 0 > "$notmuch_counter_state_path" || return

What are the || return's for?

> +}
> +
> +# Returns the current notmuch counter value.
> +notmuch_counter () {
> + if [ -r "$notmuch_counter_state_path" ]; then
> + count=$(cat "$notmuch_counter_state_path")
> + else
> + count=0
> + fi
> + echo -n $count
> +}
> +
>  
>  find_notmuch_path ()
>  {
> -- 
> 1.7.7.3
> 
> ___
> notmuch mailing list
> notmuch@notmuchmail.org
> http://notmuchmail.org/mailman/listinfo/notmuch
> 
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


[PATCH 1/3] test: add functions to count how much times notmuch was called

2011-11-26 Thread Dmitry Kurochkin
The patch adds two auxiliary functions and a variable:

  notmuch_counter_reset
  $notmuch_counter
  notmuch_counter

They allow to count how many times notmuch binary is called.
notmuch_counter_reset() function generates a script that counts how
many times it is called and resets the counter to zero.  The function
sets $notmuch_counter variable to the path to the generated script
that should be called instead of notmuch to do the counting.  The
notmuch_counter() function returns the current counter value.
---
 test/README  |   16 ++--
 test/test-lib.sh |   32 
 2 files changed, 46 insertions(+), 2 deletions(-)

diff --git a/test/README b/test/README
index 2481f16..1570f7c 100644
--- a/test/README
+++ b/test/README
@@ -187,8 +187,8 @@ library for your script to use.
is to summarize successes and failures in the test script and
exit with an appropriate error code.

-There are also a number of mail-specific functions which are useful in
-writing tests:
+There are also a number of notmuch-specific auxiliary functions and
+variables which are useful in writing tests:

   generate_message

@@ -212,3 +212,15 @@ writing tests:
 will initialize the mail database to a known state of 50 sample
 messages, (culled from the early history of the notmuch mailing
 list).
+
+  notmuch_counter_reset
+  $notmuch_counter
+  notmuch_counter
+
+These allow to count how many times notmuch binary is called.
+notmuch_counter_reset() function generates a script that counts
+how many times it is called and resets the counter to zero.  The
+function sets $notmuch_counter variable to the path to the
+generated script that should be called instead of notmuch to do
+the counting.  The notmuch_counter() function returns the current
+counter value.
diff --git a/test/test-lib.sh b/test/test-lib.sh
index 93867b0..e3b85d0 100755
--- a/test/test-lib.sh
+++ b/test/test-lib.sh
@@ -864,6 +864,38 @@ test_emacs () {
emacsclient --socket-name="$EMACS_SERVER" --eval "(progn $@)"
 }

+# Creates a script that counts how much time it is executed and calls
+# notmuch.  $notmuch_counter is set to the path to the generated
+# script.  Use notmuch_counter() function to get the current counter
+# value.
+notmuch_counter_reset () {
+   notmuch_counter="$TMP_DIRECTORY/notmuch_counter"
+   if [ ! -x "$notmuch_counter" ]; then
+   
notmuch_counter_state_path="$TMP_DIRECTORY/notmuch_counter.state"
+   cat <"$notmuch_counter"
+#!/bin/sh
+
+count=\$(cat "$notmuch_counter_state_path")
+echo -n \$(expr \$count + 1) > "$notmuch_counter_state_path"
+
+exec notmuch "\$@"
+EOF
+   chmod +x "$notmuch_counter" || return
+   fi
+
+   echo -n 0 > "$notmuch_counter_state_path" || return
+}
+
+# Returns the current notmuch counter value.
+notmuch_counter () {
+   if [ -r "$notmuch_counter_state_path" ]; then
+   count=$(cat "$notmuch_counter_state_path")
+   else
+   count=0
+   fi
+   echo -n $count
+}
+

 find_notmuch_path ()
 {
-- 
1.7.7.3



[PATCH 1/3] test: add functions to count how much times notmuch was called

2011-11-25 Thread Dmitry Kurochkin
The patch adds two auxiliary functions and a variable:

  notmuch_counter_reset
  $notmuch_counter
  notmuch_counter

They allow to count how many times notmuch binary is called.
notmuch_counter_reset() function generates a script that counts how
many times it is called and resets the counter to zero.  The function
sets $notmuch_counter variable to the path to the generated script
that should be called instead of notmuch to do the counting.  The
notmuch_counter() function returns the current counter value.
---
 test/README  |   16 ++--
 test/test-lib.sh |   32 
 2 files changed, 46 insertions(+), 2 deletions(-)

diff --git a/test/README b/test/README
index 2481f16..1570f7c 100644
--- a/test/README
+++ b/test/README
@@ -187,8 +187,8 @@ library for your script to use.
is to summarize successes and failures in the test script and
exit with an appropriate error code.
 
-There are also a number of mail-specific functions which are useful in
-writing tests:
+There are also a number of notmuch-specific auxiliary functions and
+variables which are useful in writing tests:
 
   generate_message
 
@@ -212,3 +212,15 @@ writing tests:
 will initialize the mail database to a known state of 50 sample
 messages, (culled from the early history of the notmuch mailing
 list).
+
+  notmuch_counter_reset
+  $notmuch_counter
+  notmuch_counter
+
+These allow to count how many times notmuch binary is called.
+notmuch_counter_reset() function generates a script that counts
+how many times it is called and resets the counter to zero.  The
+function sets $notmuch_counter variable to the path to the
+generated script that should be called instead of notmuch to do
+the counting.  The notmuch_counter() function returns the current
+counter value.
diff --git a/test/test-lib.sh b/test/test-lib.sh
index 93867b0..e3b85d0 100755
--- a/test/test-lib.sh
+++ b/test/test-lib.sh
@@ -864,6 +864,38 @@ test_emacs () {
emacsclient --socket-name="$EMACS_SERVER" --eval "(progn $@)"
 }
 
+# Creates a script that counts how much time it is executed and calls
+# notmuch.  $notmuch_counter is set to the path to the generated
+# script.  Use notmuch_counter() function to get the current counter
+# value.
+notmuch_counter_reset () {
+   notmuch_counter="$TMP_DIRECTORY/notmuch_counter"
+   if [ ! -x "$notmuch_counter" ]; then
+   
notmuch_counter_state_path="$TMP_DIRECTORY/notmuch_counter.state"
+   cat <"$notmuch_counter"
+#!/bin/sh
+
+count=\$(cat "$notmuch_counter_state_path")
+echo -n \$(expr \$count + 1) > "$notmuch_counter_state_path"
+
+exec notmuch "\$@"
+EOF
+   chmod +x "$notmuch_counter" || return
+   fi
+
+   echo -n 0 > "$notmuch_counter_state_path" || return
+}
+
+# Returns the current notmuch counter value.
+notmuch_counter () {
+   if [ -r "$notmuch_counter_state_path" ]; then
+   count=$(cat "$notmuch_counter_state_path")
+   else
+   count=0
+   fi
+   echo -n $count
+}
+
 
 find_notmuch_path ()
 {
-- 
1.7.7.3

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