From: Junio C Hamano <gitster@pobox.com>
To: Jeff King <peff@peff.net>
Cc: git@vger.kernel.org
Subject: Re: [PATCH 3/6] config: drop useless length variable in write_pair()
Date: Fri, 10 Apr 2020 14:51:20 -0700 [thread overview]
Message-ID: <xmqq4ktrhuw7.fsf@gitster.c.googlers.com> (raw)
In-Reply-To: <20200410194445.GC1363756@coredump.intra.peff.net> (Jeff King's message of "Fri, 10 Apr 2020 15:44:45 -0400")
Jeff King <peff@peff.net> writes:
> We compute the length of a subset of a string, but then use that length
> only to feed a "%.*s" printf placeholder for the same string. We can
> just use "%s" to achieve the same thing.
Heh, makes readers wonder why the original author wrote such a
convoluted code.
> The variable became useless in cb891a5989 (Use a strbuf for building up
> section header and key/value pair strings., 2007-12-14), which swapped
> out a write() which _did_ use the length for a strbuf_addf() call.
And that history, i.e. the %.*s formatter being a direct translation
from write(2), explains it.
Thanks.
> Signed-off-by: Jeff King <peff@peff.net>
> ---
> config.c | 4 +---
> 1 file changed, 1 insertion(+), 3 deletions(-)
>
> diff --git a/config.c b/config.c
> index ff7998df46..7ea588a7e0 100644
> --- a/config.c
> +++ b/config.c
> @@ -2545,7 +2545,6 @@ static ssize_t write_pair(int fd, const char *key, const char *value,
> {
> int i;
> ssize_t ret;
> - int length = strlen(key + store->baselen + 1);
> const char *quote = "";
> struct strbuf sb = STRBUF_INIT;
>
> @@ -2564,8 +2563,7 @@ static ssize_t write_pair(int fd, const char *key, const char *value,
> if (i && value[i - 1] == ' ')
> quote = "\"";
>
> - strbuf_addf(&sb, "\t%.*s = %s",
> - length, key + store->baselen + 1, quote);
> + strbuf_addf(&sb, "\t%s = %s", key + store->baselen + 1, quote);
>
> for (i = 0; value[i]; i++)
> switch (value[i]) {
next prev parent reply other threads:[~2020-04-10 21:51 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-10 19:42 [PATCH 0/6] better handling of gigantic config files Jeff King
2020-04-10 19:43 ` [PATCH 1/6] remote: drop auto-strlen behavior of make_branch() and make_rewrite() Jeff King
2020-04-10 21:44 ` Junio C Hamano
2020-04-10 19:44 ` [PATCH 2/6] parse_config_key(): return subsection len as size_t Jeff King
2020-04-10 19:44 ` [PATCH 3/6] config: drop useless length variable in write_pair() Jeff King
2020-04-10 21:51 ` Junio C Hamano [this message]
2020-04-10 19:46 ` [PATCH 4/6] git_config_parse_key(): return baselen as size_t Jeff King
2020-04-10 19:47 ` [PATCH 5/6] config: use size_t to store parsed variable baselen Jeff King
2020-04-10 19:50 ` [PATCH 6/6] config: reject parsing of files over INT_MAX Jeff King
2020-04-10 22:04 ` Junio C Hamano
2020-04-10 22:15 ` Jeff King
2020-04-13 0:47 ` Taylor Blau
2020-04-13 22:14 ` Junio C Hamano
2020-04-13 0:49 ` [PATCH 0/6] better handling of gigantic config files Taylor Blau
2020-04-13 17:20 ` Jeff King
2020-04-13 17:23 ` Taylor Blau
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=xmqq4ktrhuw7.fsf@gitster.c.googlers.com \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=peff@peff.net \
/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).