From: Junio C Hamano <gitster@pobox.com>
To: Bello Olamide <belkid98@gmail.com>
Cc: git@vger.kernel.org, usmanakinyemi202@gmail.com,
christian.couder@gmail.com
Subject: Re: [Outreachy PATCH v3 1/2] gpg-interface: replace strbuf_split*() with string_list_split*()
Date: Mon, 20 Oct 2025 08:09:16 -0700 [thread overview]
Message-ID: <xmqq5xc9390j.fsf@gitster.g> (raw)
In-Reply-To: <CAD=f0L8Zc=rRwCo0QHWnf8OCXidubJrQYpeQg=gLXV=npO-T1g@mail.gmail.com> (Bello Olamide's message of "Mon, 20 Oct 2025 07:32:18 +0100")
Bello Olamide <belkid98@gmail.com> writes:
>> > - fingerprint_ret = strbuf_detach(fingerprint[1], NULL);
>> > - strbuf_list_free(fingerprint);
>> > + fingerprint_ret = xstrdup(split.items[1].string);
>> > + string_list_clear(&split, 0);
>>
>> OK. This is a straight-forward rewrite that is fairly faithful to
>> the original.
>>
>> But I wonder why the original was written in such a convoluted way
>> to just extract the first part of a string that is space delimited
>> tokens. It is obviously not your fault that the original is written
>> that way, bit I would have expected it to be done more like this:
>>
>> char *begin = fingerprint_stdout.buf;
>> char *delim = strchr(begin, ' ');
>> if (!delim)
>> die_errno("Barf!");
>> fingerprint_ret = xmemdupz(begin, end - begin);
>>
>> Am I missing something?
What I was missing was that we use fingerprint[1], not
fingerprint[0]. So we need to do the strchr() twice, i.e.
char *begin = fingerprint_stdout.buf;
char *delim = strchr(begin, ' ');
if (!delim)
die_errno("Barf!");
begin = delim + 1
delim = strchr(begin, ' ');
if (!delim)
die_errno("Barf!");
fingerprint_ret = xmemdupz(begin, end - begin);
> Okay something like this which just finds the desired token and
> returns a copy?
> char *begin = fingerprint_stdout.buf;
> char *end = begin + fingerprint_stdout.len;
> char *space, *start, *endtok;
>
> space = memchr(begin, ' ', end-begin);
> if (!space)
> die_errno(_("failed to get the ssh fingerprint for key '%s'"),
> signing_key);
> start = space + 1;
> while (start < end && (*start = ' ' || *start == '\t'))
> start++;
The original does not seem to care and uses the whole
fingerprint[1].buf; do we really care about tabs? The same for
looking at CR or LF.
Even if we cared, we shouldn't have to open code strcspn() like this
;-)
next prev parent reply other threads:[~2025-10-20 15:09 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-19 12:07 [Outreachy PATCH v3 0/2] gpg-interface.c: use string_list_split*() instead of strbuf_split*() Olamide Caleb Bello
2025-10-19 12:07 ` [Outreachy PATCH v3 1/2] gpg-interface: replace strbuf_split*() with string_list_split*() Olamide Caleb Bello
2025-10-19 15:52 ` Junio C Hamano
2025-10-20 6:32 ` Bello Olamide
2025-10-20 15:09 ` Junio C Hamano [this message]
2025-10-20 16:31 ` Junio C Hamano
2025-10-20 18:15 ` Bello Olamide
2025-10-20 18:12 ` Bello Olamide
2025-10-20 16:45 ` Kristoffer Haugsbakk
2025-10-20 18:25 ` Bello Olamide
2025-10-20 18:37 ` Kristoffer Haugsbakk
2025-10-20 18:50 ` Bello Olamide
2025-10-19 12:07 ` [Outreachy PATCH v3 2/2] gpg-interface: use string_list_split*() instead of strbuf_split*() Olamide Caleb Bello
2025-10-19 16:00 ` Junio C Hamano
2025-10-20 8:15 ` Bello Olamide
2025-10-20 15:18 ` Junio C Hamano
2025-10-20 19:02 ` Bello Olamide
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=xmqq5xc9390j.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=belkid98@gmail.com \
--cc=christian.couder@gmail.com \
--cc=git@vger.kernel.org \
--cc=usmanakinyemi202@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 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 NNTP newsgroup(s).