From: Junio C Hamano <gitster@pobox.com>
To: Max Horn <max@quendi.de>
Cc: Tanay Abhra <tanayabh@gmail.com>, git@vger.kernel.org
Subject: Re: [PATCH V2] commit.c: Use skip_prefix() instead of starts_with()
Date: Mon, 03 Mar 2014 15:45:34 -0800 [thread overview]
Message-ID: <xmqqbnxmn8wx.fsf@gitster.dls.corp.google.com> (raw)
In-Reply-To: <176A3D83-AFFB-4EF4-A1CB-3A953F692166@quendi.de> (Max Horn's message of "Mon, 3 Mar 2014 23:59:20 +0100")
Max Horn <max@quendi.de> writes:
> On 03.03.2014, at 20:43, Junio C Hamano <gitster@pobox.com> wrote:
>
>> Tanay Abhra <tanayabh@gmail.com> writes:
>>
>>> @@ -1193,9 +1194,9 @@ static void parse_gpg_output(struct signature_check *sigc)
>>> for (i = 0; i < ARRAY_SIZE(sigcheck_gpg_status); i++) {
>>> const char *found, *next;
>>>
>>> - if (starts_with(buf, sigcheck_gpg_status[i].check + 1)) {
>>> + if (found = skip_prefix(buf, sigcheck_gpg_status[i].check + 1)) {
>>> /* At the very beginning of the buffer */
>>> - found = buf + strlen(sigcheck_gpg_status[i].check + 1);
>>> + ;
>>> } else {
>>> found = strstr(buf, sigcheck_gpg_status[i].check);
>>> if (!found)
>>
>> This hunk looks good. It can be a separate patch but they are both
>> minor changes so it is OK to have it in a single patch.
>
> Hm, but that hunk also introduces an assignment in a conditional,
> and introduces an empty block. Maybe like this?
Much better.
If we anticipate that we may add _more_ ways to find the thing
later, then I would say this code structure is better:
/* Is it at the beginning of the buffer? */
found = skip_prefix(...);
if (!found) {
/* Oh, maybe it is on the second or later line? */
found = ... find it on a later line...
}
if (!found)
continue;
but I do not think that is the case for this particular one. We
either try to find it at the very beginning (i.e. no leading
newline), or we have some other lines before it (i.e. require
leading newline), and there will be no future extension, so what you
suggested below looks sensible.
> diff --git a/commit.c b/commit.c
> index 6bf4fe0..0ee0725 100644
> --- a/commit.c
> +++ b/commit.c
> @@ -1193,10 +1193,8 @@ static void parse_gpg_output(struct signature_check *sigc)
> for (i = 0; i < ARRAY_SIZE(sigcheck_gpg_status); i++) {
> const char *found, *next;
>
> - if (starts_with(buf, sigcheck_gpg_status[i].check + 1)) {
> - /* At the very beginning of the buffer */
> - found = buf + strlen(sigcheck_gpg_status[i].check + 1);
> - } else {
> + found = skip_prefix(buf, sigcheck_gpg_status[i].check + 1);
> + if (!found) {
> found = strstr(buf, sigcheck_gpg_status[i].check);
> if (!found)
> continue;
prev parent reply other threads:[~2014-03-03 23:45 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-03-03 15:59 [PATCH V2] commit.c: Use skip_prefix() instead of starts_with() Tanay Abhra
2014-03-03 19:43 ` Junio C Hamano
2014-03-03 22:59 ` Max Horn
2014-03-03 23:45 ` Junio C Hamano [this message]
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqqbnxmn8wx.fsf@gitster.dls.corp.google.com \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=max@quendi.de \
--cc=tanayabh@gmail.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.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.