From: "René Scharfe" <l.s.r@web.de>
To: Heiko Voigt <hvoigt@hvoigt.net>
Cc: Git List <git@vger.kernel.org>,
Stefan Beller <sbeller@google.com>,
Lars Schneider <larsxschneider@gmail.com>,
Junio C Hamano <gitster@pobox.com>
Subject: Re: [PATCH] submodule-config: use explicit empty string instead of strbuf in config_from()
Date: Thu, 21 Jul 2016 20:57:03 +0200 [thread overview]
Message-ID: <57911AFF.7030107@web.de> (raw)
In-Reply-To: <20160720082515.GA823@book.hvoigt.net>
Am 20.07.2016 um 10:25 schrieb Heiko Voigt:
> Hi,
>
> On Tue, Jul 19, 2016 at 09:05:43PM +0200, René Scharfe wrote:
>> Use a string constant instead of an empty strbuf to shorten the code
>> and make it easier to read.
>
> This must have been some oversight from my original code. I also can not
> see any purpose.
>
>> Signed-off-by: Rene Scharfe <l.s.r@web.de>
>> ---
>> ... unless someone can come up with a suitable non-empty string to feed
>> to git_config_from_mem() as its name parameter.
>
> If we would want to be absolutely correct we could use something like
> "SHA1:.gitmodules". E.g. like we use to lookup the blob in
> gitmodule_sha1_from_commit():
>
> strbuf_addf(&rev, "%s:.gitmodules", sha1_to_hex(commit_sha1));
>
> And now I see where this was leftover from... before extracting this
> function this code was filling the strbuf.
>
> How about this instead?
I like it.
> ---8<------
> Subject: [PATCH] fix passing a name for config from submodules
>
> In commit 959b5455 we implemented the initial version of the submodule
> config cache. During development of that initial version we extracted
> the function gitmodule_sha1_from_commit(). During that process we missed
> that the strbuf rev was still used in config_from() and now is left
> empty. Lets fix this by also returning this string.
>
> Signed-off-by: Heiko Voigt <hvoigt@hvoigt.net>
> ---
>
> Its not exactly pretty with all the releases before the returns but
> this is what I could quickly come up with...
Indeed.
> submodule-config.c | 23 +++++++++++++++--------
> 1 file changed, 15 insertions(+), 8 deletions(-)
>
> diff --git a/submodule-config.c b/submodule-config.c
> index 077db40..dccea59 100644
> --- a/submodule-config.c
> +++ b/submodule-config.c
> @@ -371,9 +371,9 @@ static int parse_config(const char *var, const char *value, void *data)
> }
>
> static int gitmodule_sha1_from_commit(const unsigned char *commit_sha1,
> - unsigned char *gitmodules_sha1)
> + unsigned char *gitmodules_sha1,
> + struct strbuf *rev)
> {
> - struct strbuf rev = STRBUF_INIT;
> int ret = 0;
>
> if (is_null_sha1(commit_sha1)) {
> @@ -381,11 +381,10 @@ static int gitmodule_sha1_from_commit(const unsigned char *commit_sha1,
> return 1;
> }
>
> - strbuf_addf(&rev, "%s:.gitmodules", sha1_to_hex(commit_sha1));
> - if (get_sha1(rev.buf, gitmodules_sha1) >= 0)
> + strbuf_addf(rev, "%s:.gitmodules", sha1_to_hex(commit_sha1));
> + if (get_sha1(rev->buf, gitmodules_sha1) >= 0)
> ret = 1;
>
> - strbuf_release(&rev);
> return ret;
> }
>
> @@ -420,8 +419,10 @@ static const struct submodule *config_from(struct submodule_cache *cache,
> return entry->config;
> }
>
> - if (!gitmodule_sha1_from_commit(commit_sha1, sha1))
> + if (!gitmodule_sha1_from_commit(commit_sha1, sha1, &rev)) {
> + strbuf_release(&rev);
> return NULL;
> + }
>
> switch (lookup_type) {
> case lookup_name:
> @@ -431,14 +432,19 @@ static const struct submodule *config_from(struct submodule_cache *cache,
> submodule = cache_lookup_path(cache, sha1, key);
> break;
> }
> - if (submodule)
> + if (submodule) {
> + strbuf_release(&rev);
> return submodule;
> + }
>
> config = read_sha1_file(sha1, &type, &config_size);
> - if (!config)
> + if (!config) {
> + strbuf_release(&rev);
> return NULL;
> + }
>
> if (type != OBJ_BLOB) {
> + strbuf_release(&rev);
> free(config);
> return NULL;
> }
A separate patch could combine the previous two conditionals; free(NULL)
is allowed.
> @@ -450,6 +456,7 @@ static const struct submodule *config_from(struct submodule_cache *cache,
> parameter.overwrite = 0;
> git_config_from_mem(parse_config, "submodule-blob", rev.buf,
> config, config_size, ¶meter);
> + strbuf_release(&rev);
> free(config);
>
> switch (lookup_type) {
>
next prev parent reply other threads:[~2016-07-21 18:57 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-07-19 19:05 [PATCH] submodule-config: use explicit empty string instead of strbuf in config_from() René Scharfe
2016-07-19 19:15 ` Junio C Hamano
2016-07-19 19:24 ` Stefan Beller
2016-07-20 8:25 ` Heiko Voigt
2016-07-21 18:57 ` René Scharfe [this message]
2016-07-25 14:37 ` Heiko Voigt
2016-07-25 14:58 ` Junio C Hamano
2016-07-26 9:49 ` [PATCH 1/2] fix passing a name for config from submodules Heiko Voigt
2016-07-26 17:22 ` Stefan Beller
2016-07-26 22:02 ` Junio C Hamano
2016-07-28 12:49 ` [PATCH 1/3] submodule-config: passing name reference for .gitmodule blobs Heiko Voigt
2016-07-28 16:26 ` Stefan Beller
2016-07-28 12:49 ` [PATCH 2/3] submodule-config: combine early return code into one goto Heiko Voigt
2016-07-28 12:50 ` [PATCH 3/3] submodule-config: fix test binary crashing when no arguments given Heiko Voigt
2016-07-28 11:17 ` [PATCH 1/2] fix passing a name for config from submodules Heiko Voigt
2016-07-28 12:55 ` [PATCH] document how to reference previous commits Heiko Voigt
2016-07-28 15:38 ` Junio C Hamano
2016-07-28 15:57 ` Stefan Beller
2016-08-17 11:36 ` Heiko Voigt
2016-08-17 17:45 ` Junio C Hamano
2016-07-28 14:59 ` [PATCH 1/2] fix passing a name for config from submodules Junio C Hamano
2016-07-26 9:49 ` [PATCH 2/2] submodule-config: combine error checking if clauses Heiko Voigt
2016-07-26 17:24 ` Stefan Beller
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=57911AFF.7030107@web.de \
--to=l.s.r@web.de \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=hvoigt@hvoigt.net \
--cc=larsxschneider@gmail.com \
--cc=sbeller@google.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.