git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Hans Jerry Illikainen <hji@dyntopia.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH v2 1/1] gpg-interface: add minTrustLevel as a configuration option
Date: Tue, 24 Dec 2019 11:02:53 -0800	[thread overview]
Message-ID: <xmqqblrx5yxu.fsf@gitster-ct.c.googlers.com> (raw)
In-Reply-To: <20191222003123.10555-2-hji@dyntopia.com> (Hans Jerry Illikainen's message of "Sun, 22 Dec 2019 00:31:23 +0000")

Hans Jerry Illikainen <hji@dyntopia.com> writes:

> +				/* Do we have trust level? */
> +				if (sigcheck_gpg_status[i].flags & GPG_STATUS_TRUST_LEVEL) {
> +					/*
> +					 * GPG v1 and v2 differs in how the
> +					 * TRUST_ lines are written.  Some
> +					 * trust lines contain no additional
> +					 * space-separated information for v1.
> +					 */
> +					next = strchr(line, ' ');
> +					if (!next)
> +						next = strchrnul(line, '\n');
> +					trust = xmemdupz(line, next - line);

I wonder if telling strcspn() to stop at either SP or LF is more in
line with the existing codebase [*1*] and/or more readable.  It
would make this part to:

		size_t trust_size = strcspn(line, " \n");
		trust = xmemdupz(line, trust_size);

without the need to use or update the 'next' variable, if I am not
mistaken?

By the way, while we are looking at this patch, I notice that,
throughout the function, the use of variable 'next' feels rather
misleading, at least to me.

When I see a loop that iterates over a block of lines, and a
variable 'line' is used to point at the beginning of the current
line at the beginning of each iteration and the code in the
iteration updates a pointer 'next', I'd expect 'next' (or perhaps
'next+1') to become the new value of 'line' when the current round
of the iteration ends (i.e. the name 'next' would stand for 'here is
where we expect the next line to start').  But the code we see in
this function uses it for 'here is the end of the current _token_ on
the line', primarily so that it can do something to the byte range
(line,<end-of-token>) and it never gets used as 'now we are done
with the line, let's move on to the next line'.

This matters because it makes it unclear to decide if the above two
lines I gave as a counter-proposal is sufficient, or if it also
needs to say "next = line + trust_size" to keep 'next' up-to-date.
The name of the varirable implies it should be, but the way the
code uses 'next' says it is a throw-away variable whose value does
not matter once we have done with the end of the current token.

I wonder if the code becomes less misleading if we either (1)
renamed 'next' to a name that hints more strongly that it is not the
'next' line but the end of the current token we are interested in,
or (2) get rid of the pointer and instead counted size of the
current token we are interested in, or perhaps both?  

This is not the fault of this patch, but I just mention it before I
forget.

Thanks.

  reply	other threads:[~2019-12-24 19:05 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-16 15:32 [PATCH 0/1] gpg-interface: add minTrustLevel as a configuration option Hans Jerry Illikainen
2019-12-16 15:32 ` [PATCH 1/1] " Hans Jerry Illikainen
2019-12-20 22:57   ` SZEDER Gábor
2019-12-21 18:59     ` Hans Jerry Illikainen
2019-12-23 14:50       ` Randall S. Becker
2019-12-24 11:30         ` Hans Jerry Illikainen
2019-12-24 14:20           ` Randall S. Becker
2019-12-16 20:58 ` [PATCH 0/1] " Junio C Hamano
2019-12-18 23:59   ` Hans Jerry Illikainen
2019-12-19  0:01 ` [PATCH v1 " Hans Jerry Illikainen
2019-12-19  0:01   ` [PATCH v1 1/1] " Hans Jerry Illikainen
2019-12-22  0:31   ` [PATCH v2 0/1] " Hans Jerry Illikainen
2019-12-22  0:31     ` [PATCH v2 1/1] " Hans Jerry Illikainen
2019-12-24 19:02       ` Junio C Hamano [this message]
2019-12-27 13:46         ` Hans Jerry Illikainen
2019-12-27 22:21           ` Junio C Hamano
2019-12-22  0:44     ` [PATCH v2 0/1] " Hans Jerry Illikainen
2019-12-27 13:55     ` [PATCH v3 " Hans Jerry Illikainen
2019-12-27 13:55       ` [PATCH v3 1/1] " Hans Jerry Illikainen

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: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to=xmqqblrx5yxu.fsf@gitster-ct.c.googlers.com \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=hji@dyntopia.com \
    /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://80x24.org/mirrors/git.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).