From: Jonathan Tan <jonathantanmy@google.com>
To: Stefan Beller <sbeller@google.com>
Cc: gitster@pobox.com, bmwill@google.com, git@vger.kernel.org,
hvoigt@hvoigt.net, seanwbehan@riseup.net
Subject: Re: [PATCH 5/6] submodule: fixup nested submodules after moving the submodule
Date: Wed, 28 Mar 2018 10:46:57 -0700 [thread overview]
Message-ID: <20180328104657.2396071270905628fd2fdca3@google.com> (raw)
In-Reply-To: <20180328172449.27012-6-sbeller@google.com>
On Wed, 28 Mar 2018 10:24:48 -0700
Stefan Beller <sbeller@google.com> wrote:
> +static void connect_wt_gitdir_in_nested(const char *sub_worktree,
> + const char *sub_gitdir)
> +{
> + int i;
> + struct repository subrepo;
> + struct strbuf sub_wt = STRBUF_INIT;
> + struct strbuf sub_gd = STRBUF_INIT;
> +
> + const struct submodule *sub;
> +
> + if (repo_init(&subrepo, sub_gitdir, sub_worktree))
> + return;
If repo_init() fails, is it because the working tree doesn't exist on
disk, so we don't need to perform any connections on submodules? I think
a comment should be added to describe this.
> +
> + if (repo_read_index(&subrepo) < 0)
> + die("index file corrupt in repo %s", subrepo.gitdir);
> +
> + for (i = 0; i < subrepo.index->cache_nr; i++) {
> + const struct cache_entry *ce = subrepo.index->cache[i];
> +
> + if (!S_ISGITLINK(ce->ce_mode))
> + continue;
> +
> + while (i + 1 < subrepo.index->cache_nr &&
> + !strcmp(ce->name, subrepo.index->cache[i + 1]->name))
> + /*
> + * Skip entries with the same name in different stages
> + * to make sure an entry is returned only once.
> + */
> + i++;
> +
> + sub = submodule_from_path(&subrepo, &null_oid, ce->name);
> + if (!sub)
> + /* submodule not checked out? */
> + continue;
> +
> + if (is_submodule_active(&subrepo, ce->name)) {
Optional: This could be combined with the previous "if" block, so that
the following lines don't need to be indented.
> + strbuf_addf(&sub_wt, "%s/%s", sub_worktree, sub->path);
> + strbuf_addf(&sub_gd, "%s/modules/%s", sub_gitdir, sub->name);
> +
> + connect_work_tree_and_git_dir(sub_wt.buf, sub_gd.buf, 0);
> + connect_wt_gitdir_in_nested(sub_wt.buf, sub_gd.buf);
What's the difference between having this call to
connect_wt_gitdir_in_nested() and just passing 1 instead of 0 to
connect_work_tree_and_git_dir()? I see that the latter uses absolute
paths, but that would seem to have the same effect. (If not, I think a
comment is warranted.)
> +
> + strbuf_reset(&sub_wt);
> + strbuf_reset(&sub_gd);
I think we normally write the resets before the strbuf_addf(), so that
it's clearer that sub_wt and sub_gd are meant to start from scratch in
every iteration.
Overall, this version of the patch is clearer - thanks.
next prev parent reply other threads:[~2018-03-28 17:47 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-27 21:39 [PATCH 0/5] Moving submodules with nested submodules Stefan Beller
2018-03-27 21:39 ` [PATCH 1/5] submodule.h: drop declaration of connect_work_tree_and_git_dir Stefan Beller
2018-03-27 21:39 ` [PATCH 2/5] submodule-config: allow submodule_free to handle arbitrary repositories Stefan Beller
2018-03-27 22:57 ` Brandon Williams
2018-03-27 22:58 ` [PATCH] grep: remove "repo" arg from non-supporting funcs Jonathan Tan
2018-03-27 23:20 ` Stefan Beller
2018-03-28 0:24 ` Jonathan Tan
2018-03-28 0:35 ` Stefan Beller
2018-03-27 21:39 ` [PATCH 3/5] submodule-config: add repository argument to submodule_from_{name, path} Stefan Beller
2018-03-27 23:04 ` Jonathan Tan
2018-03-27 23:53 ` Stefan Beller
2018-03-27 21:39 ` [PATCH 4/5] submodule-config: remove submodule_from_cache Stefan Beller
2018-03-27 23:07 ` Jonathan Tan
2018-03-27 21:39 ` [PATCH 5/5] submodule: fixup nested submodules after moving the submodule Stefan Beller
2018-03-27 23:25 ` Brandon Williams
2018-03-28 0:07 ` Jonathan Tan
2018-03-28 0:42 ` Stefan Beller
2018-03-28 17:24 ` [PATCHv2 0/6] Moving submodules with nested submodules Stefan Beller
2018-03-28 17:24 ` [PATCH 1/6] submodule.h: drop declaration of connect_work_tree_and_git_dir Stefan Beller
2018-03-28 17:24 ` [PATCH 2/6] submodule-config: allow submodule_free to handle arbitrary repositories Stefan Beller
2018-03-28 17:24 ` [PATCH 3/6] submodule-config: add repository argument to submodule_from_{name, path} Stefan Beller
2018-03-28 17:24 ` [PATCH 4/6] submodule-config: remove submodule_from_cache Stefan Beller
2018-03-28 17:24 ` [PATCH 5/6] submodule: fixup nested submodules after moving the submodule Stefan Beller
2018-03-28 17:35 ` Brandon Williams
2018-03-28 19:08 ` Stefan Beller
2018-03-28 17:46 ` Jonathan Tan [this message]
2018-03-28 17:24 ` [PATCH 6/6] grep: remove "repo" arg from non-supporting funcs Stefan Beller
2018-03-28 17:54 ` [PATCHv2 0/6] Moving submodules with nested submodules Jonathan Tan
2018-03-28 22:35 ` [PATCHv3 " Stefan Beller
2018-03-28 22:35 ` [PATCHv3 1/6] submodule.h: drop declaration of connect_work_tree_and_git_dir Stefan Beller
2018-03-28 22:35 ` [PATCHv3 2/6] grep: remove "repo" arg from non-supporting funcs Stefan Beller
2018-03-28 22:35 ` [PATCHv3 3/6] submodule-config: allow submodule_free to handle arbitrary repositories Stefan Beller
2018-03-28 22:35 ` [PATCHv3 4/6] submodule-config: add repository argument to submodule_from_{name, path} Stefan Beller
2018-03-28 22:35 ` [PATCHv3 5/6] submodule-config: remove submodule_from_cache Stefan Beller
2018-03-28 22:35 ` [PATCHv3 6/6] submodule: fixup nested submodules after moving the submodule Stefan Beller
2018-03-28 23:17 ` [PATCHv3 0/6] Moving submodules with nested submodules Jonathan Tan
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=20180328104657.2396071270905628fd2fdca3@google.com \
--to=jonathantanmy@google.com \
--cc=bmwill@google.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=hvoigt@hvoigt.net \
--cc=sbeller@google.com \
--cc=seanwbehan@riseup.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).