From: Pranit Bauva <pranit.bauva@gmail.com>
To: Matthieu Moy <Matthieu.Moy@grenoble-inp.fr>
Cc: Junio C Hamano <gitster@pobox.com>,
Git List <git@vger.kernel.org>,
Lars Schneider <larsxschneider@gmail.com>,
Christian Couder <chriscool@tuxfamily.org>,
Christian Couder <christian.couder@gmail.com>,
Jeff King <peff@peff.net>
Subject: Re: [PATCH] builtin/commit.c: memoize git-path for COMMIT_EDITMSG
Date: Tue, 24 May 2016 17:11:20 +0530 [thread overview]
Message-ID: <CAFZEwPMmMEQMuT0+ap00e5UgccDfYZ75qbovRL_d8qWZ0_2XWw@mail.gmail.com> (raw)
In-Reply-To: <vpq1t4rri2a.fsf@anie.imag.fr>
Hey Matthieu,
On Tue, May 24, 2016 at 1:41 PM, Matthieu Moy
<Matthieu.Moy@grenoble-inp.fr> wrote:
> Junio C Hamano <gitster@pobox.com> writes:
>
>> Pranit Bauva <pranit.bauva@gmail.com> writes:
>>
>>> static const char *use_message_buffer;
>>> -static const char commit_editmsg[] = "COMMIT_EDITMSG";
>>> +static const char commit_editmsg_path[] = git_path_commit_editmsg();
>>
>> The function defined with the macro looks like
>>
>> const char *git_path_commit_editmsg(void)
>> {
>> static char *ret;
>> if (!ret)
>> ret = git_pathdup("COMMIT_EDITMSG");
>> return ret;
>> }
>>
>> so receiving its result to "const char v[]" looks somewhat
>> suspicious.
>>
>> More importantly, when is this function evaluated and returned value
>> used to fill commit_editmsg_path[]?
>
> I may have missed something, but I'd say "never", as the code is not
> compilable at least with my gcc:
>
> builtin/commit.c:98:1: error: invalid initializer
> static const char commit_editmsg_path[] = git_path_commit_editmsg();
> ^
>
> AFAIK, initializing a global variable with a function call is allowed in
> C++, but not in C.
I wasn't aware of this fact. Thanks.
> And indeed, this construct is a huge source of trouble, as it would mean
> that git_path_commit_editmsg() is called 1) unconditionnally, and 2)
> before entering main().
>
> 1) means that the function call is made even when git is called for
> another command. This is terrible for the startup time: if all git
> commands have a not-totally-immediate initializer, then all commands
> would need to run the initializers for all other commands. 2) means it's
> a nightmare to debug, as you can hardly predict when the code will be
> executed.
Yes I agree that this approach will definitely cause a lot of
problems. I will re-roll with how Junio suggested.
> --
> Matthieu Moy
> http://www-verimag.imag.fr/~moy/
> --
> To unsubscribe from this list: send the line "unsubscribe git" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2016-05-24 11:41 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-23 18:16 [PATCH] builtin/commit.c: memoize git-path for COMMIT_EDITMSG Pranit Bauva
2016-05-23 19:16 ` Junio C Hamano
2016-05-24 5:54 ` Pranit Bauva
2016-05-24 6:35 ` Pranit Bauva
2016-05-24 8:11 ` Matthieu Moy
2016-05-24 11:41 ` Pranit Bauva [this message]
2016-05-24 22:25 ` Junio C Hamano
2016-05-24 19:19 ` [PATCH v2] " Pranit Bauva
2016-06-07 14:55 ` Pranit Bauva
2016-06-09 6:58 ` Jeff King
2016-06-09 9:54 ` Pranit Bauva
2016-06-09 17:04 ` Junio C Hamano
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=CAFZEwPMmMEQMuT0+ap00e5UgccDfYZ75qbovRL_d8qWZ0_2XWw@mail.gmail.com \
--to=pranit.bauva@gmail.com \
--cc=Matthieu.Moy@grenoble-inp.fr \
--cc=chriscool@tuxfamily.org \
--cc=christian.couder@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=larsxschneider@gmail.com \
--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).