From: Junio C Hamano <gitster@pobox.com>
To: Stefan Beller <sbeller@google.com>
Cc: larsxschneider@gmail.com, git@vger.kernel.org
Subject: Re: [PATCH] worktree: initialize return value for submodule_uses_worktrees
Date: Tue, 27 Dec 2016 14:12:28 -0800 [thread overview]
Message-ID: <xmqqa8bh6myb.fsf@gitster.mtv.corp.google.com> (raw)
In-Reply-To: <20161227175013.12747-1-sbeller@google.com> (Stefan Beller's message of "Tue, 27 Dec 2016 09:50:13 -0800")
Stefan Beller <sbeller@google.com> writes:
> When the worktrees directory is empty, the `ret` will be returned
> uninitialized. Fix it by initializing the value.
>
> Signed-off-by: Stefan Beller <sbeller@google.com>
> ---
>
> This goes on top of 1a248cf (origin/sb/submodule-embed-gitdir);
> ideally to be squashed, but as it is in next already, as a separate
> patch.
>
> Thanks,
> Stefan
If you initialize it at the definition site, it would be more
consistent if these "return 0" we see earlier parts of the function
also returned "ret" instead of "0". A better alternative would be
to initialize it to 0 before it starts to matter, i.e. immediately
before the
while (readdir()) {
if (is_dot_or_dotdot())
continue;
ret = 1;
break;
}
loop. I also wonder if that loop is easier to read
for (has_paths = 0; !has_paths && (d = readdir(dir)) != NULL; ) {
if (is_dot_or_dotdot())
continue;
has_paths = 1;
}
or even make it a helper function "is_empty_directory(const char *)".
Having said that, I'll queue this as-is and will merge to 'master'
by the end of the day, as I'm planning to disappear until early next
year, so please do not "reroll" this to add yet another integration
cycle to my day.
Thanks.
> worktree.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/worktree.c b/worktree.c
> index d4606aa8cd..828fd7a0ad 100644
> --- a/worktree.c
> +++ b/worktree.c
> @@ -387,7 +387,7 @@ int submodule_uses_worktrees(const char *path)
> struct strbuf sb = STRBUF_INIT;
> DIR *dir;
> struct dirent *d;
> - int ret;
> + int ret = 0;
> struct repository_format format;
>
> submodule_gitdir = git_pathdup_submodule(path, "%s", "");
next prev parent reply other threads:[~2016-12-27 22:12 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-12-22 22:18 What's cooking in git.git (Dec 2016, #07; Thu, 22) Junio C Hamano
2016-12-23 10:18 ` Duy Nguyen
2016-12-23 17:46 ` Junio C Hamano
2016-12-24 10:50 ` Duy Nguyen
2016-12-23 23:55 ` Lars Schneider
2016-12-26 20:33 ` Stefan Beller
2016-12-27 17:50 ` [PATCH] worktree: initialize return value for submodule_uses_worktrees Stefan Beller
2016-12-27 22:12 ` Junio C Hamano [this message]
2016-12-27 22:18 ` Stefan Beller
2016-12-27 22:47 ` 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=xmqqa8bh6myb.fsf@gitster.mtv.corp.google.com \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--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.
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).