unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: "Robin Jarry" <robin@jarry.cc>
To: "Tomi Ollila" <tomi.ollila@iki.fi>, <notmuch@notmuchmail.org>
Cc: Tim Culverhouse <tim@timculverhouse.com>
Subject: Re: [PATCH] cli: add options --offset and --limit to notmuch show
Date: Wed, 12 Oct 2022 22:02:08 +0200	[thread overview]
Message-ID: <CNK7O52EP74B.V5Q5T90NJF2Q@marty> (raw)
In-Reply-To: <y3a23ky.1t6gr8-too@iki.fi>

Hi Tomi,

Tomi Ollila, Oct 12, 2022 at 21:39:
> > diff --git a/notmuch-show.c b/notmuch-show.c
> > index ee9efa7448d7..ad31e0123268 100644
> > --- a/notmuch-show.c
> > +++ b/notmuch-show.c
> > @@ -1159,6 +1159,18 @@ do_show_threaded (void *ctx,
> >      notmuch_thread_t *thread;
> >      notmuch_messages_t *messages;
> >      notmuch_status_t status, res = NOTMUCH_STATUS_SUCCESS;
> > +    int i;
> > +
> > +    if (params->offset < 0) {
> > +	unsigned count;
> > +	notmuch_status_t s = notmuch_query_count_threads (query, &count);
> > +	if (print_status_query ("notmuch search", query, s))
> > +	    return 1;
> > +
> > +	params->offset += count;
> > +	if (params->offset < 0)
>
> this check and setting it to 0 is mystic to me, probably same code as in
> search (?) probably it is good (?) (will not comment the same below)

Yes, I copy/pasted that code from notmuch-search.c. I believe this to
handle the case where:

    --limit=N && --offset=-M && M > count

After adding count to offset, you may end up with a negative offset
which makes the loop exit condition invalid and the --limit value would
not be enforced as expected:

    i < params->offset + params->limit

> > diff --git a/test/T131-show-limiting.sh b/test/T131-show-limiting.sh
> > new file mode 100755
> > index 000000000000..a3da35944a3e
> > --- /dev/null
> > +++ b/test/T131-show-limiting.sh
> > @@ -0,0 +1,81 @@
> > +#!/usr/bin/env bash
> > +test_description='"notmuch show" --offset and --limit parameters'
> > +. $(dirname "$0")/test-lib.sh || exit 1
> > +
> > +add_email_corpus
> > +
> > +function show() {
>
> 'function' not used in other function defitions in other files, so this is
> inconsistent (otherwise the content looks "better" than what I see usual ;D)

I concur that this is a bash-only construct. I could remove the function
keyword and we would have the same result.

> > +    test_begin_subtest "${outp}: offset = 0"
>
> inconsistent ${outp} (where $outp used elsewhere) ...  

Indeed. I had removed all the ${} except this one. For consistency with
the other test scripts, I could add them back everywhere. I don't mind
either way.

I'll hold off for other remarks before sending a v2.

Cheers,

  reply	other threads:[~2022-10-12 20:02 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-11 22:19 [PATCH] cli: add options --offset and --limit to notmuch show Robin Jarry
2022-10-11 22:25 ` Robin Jarry
2022-10-12 19:39 ` Tomi Ollila
2022-10-12 20:02   ` Robin Jarry [this message]
2022-10-14  8:16     ` Tomi Ollila

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CNK7O52EP74B.V5Q5T90NJF2Q@marty \
    --to=robin@jarry.cc \
    --cc=notmuch@notmuchmail.org \
    --cc=tim@timculverhouse.com \
    --cc=tomi.ollila@iki.fi \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).