From: Brandon Williams <bmwill@google.com>
To: Antonio Ospite <ao2@ao2.it>
Cc: git@vger.kernel.org, Jonathan Nieder <jrnieder@gmail.com>,
Stefan Beller <sbeller@google.com>, Jeff King <peff@peff.net>
Subject: Re: [PATCH 6/7] submodule-config: reuse config_from_gitmodules in repo_read_gitmodules
Date: Fri, 22 Jun 2018 09:55:14 -0700 [thread overview]
Message-ID: <20180622165514.GC244185@google.com> (raw)
In-Reply-To: <20180622162656.19338-7-ao2@ao2.it>
On 06/22, Antonio Ospite wrote:
> Reuse config_from_gitmodules in repo_read_gitmodules to remove some
> duplication and also have a single point where the .gitmodules file is
> read.
>
> The change does not introduce any new behavior, the same gitmodules_cb
> config callback is still used which only deals with configuration
> specific to submodules.
>
> The config_from_gitmodules function is moved up in the file —unchanged—
> before its users to avoid a forward declaration.
>
> Signed-off-by: Antonio Ospite <ao2@ao2.it>
> ---
> submodule-config.c | 50 +++++++++++++++++++---------------------------
> 1 file changed, 21 insertions(+), 29 deletions(-)
>
> diff --git a/submodule-config.c b/submodule-config.c
> index e50c944eb..ce204fb53 100644
> --- a/submodule-config.c
> +++ b/submodule-config.c
> @@ -591,6 +591,23 @@ static void submodule_cache_check_init(struct repository *repo)
> submodule_cache_init(repo->submodule_cache);
> }
>
> +/*
> + * Note: This function is private for a reason, the '.gitmodules' file should
> + * not be used as as a mechanism to retrieve arbitrary configuration stored in
> + * the repository.
> + *
> + * Runs the provided config function on the '.gitmodules' file found in the
> + * working directory.
> + */
> +static void config_from_gitmodules(config_fn_t fn, struct repository *repo, void *data)
> +{
> + if (repo->worktree) {
> + char *file = repo_worktree_path(repo, GITMODULES_FILE);
> + git_config_from_file(fn, file, data);
> + free(file);
> + }
> +}
> +
> static int gitmodules_cb(const char *var, const char *value, void *data)
> {
> struct repository *repo = data;
> @@ -608,19 +625,11 @@ void repo_read_gitmodules(struct repository *repo)
> {
> submodule_cache_check_init(repo);
>
> - if (repo->worktree) {
> - char *gitmodules;
> -
> - if (repo_read_index(repo) < 0)
> - return;
> -
> - gitmodules = repo_worktree_path(repo, GITMODULES_FILE);
> -
> - if (!is_gitmodules_unmerged(repo->index))
> - git_config_from_file(gitmodules_cb, gitmodules, repo);
> + if (repo_read_index(repo) < 0)
> + return;
>
> - free(gitmodules);
> - }
> + if (!is_gitmodules_unmerged(repo->index))
> + config_from_gitmodules(gitmodules_cb, repo, repo);
So the check for the repo's worktree has been pushed into
config_from_gitmodules(). This looks like the right thing to do in
order to get to a world where you'd rather read the gitmodules file from
the index instead of the worktree.
>
> repo->submodule_cache->gitmodules_read = 1;
> }
> @@ -672,23 +681,6 @@ void submodule_free(struct repository *r)
> submodule_cache_clear(r->submodule_cache);
> }
>
> -/*
> - * Note: This function is private for a reason, the '.gitmodules' file should
> - * not be used as as a mechanism to retrieve arbitrary configuration stored in
> - * the repository.
> - *
> - * Runs the provided config function on the '.gitmodules' file found in the
> - * working directory.
> - */
> -static void config_from_gitmodules(config_fn_t fn, struct repository *repo, void *data)
> -{
> - if (repo->worktree) {
> - char *file = repo_worktree_path(repo, GITMODULES_FILE);
> - git_config_from_file(fn, file, data);
> - free(file);
> - }
> -}
> -
> struct fetch_config {
> int *max_children;
> int *recurse_submodules;
> --
> 2.18.0
>
--
Brandon Williams
next prev parent reply other threads:[~2018-06-22 16:55 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-22 16:26 [PATCH 0/7] Restrict the usage of config_from_gitmodules() Antonio Ospite
2018-06-22 16:26 ` [PATCH 1/7] config: move config_from_gitmodules to submodule-config.c Antonio Ospite
2018-06-22 16:26 ` [PATCH 2/7] submodule-config: add helper function to get 'fetch' config from .gitmodules Antonio Ospite
2018-06-22 16:50 ` Brandon Williams
2018-06-22 16:26 ` [PATCH 3/7] submodule-config: add helper to get 'update-clone' " Antonio Ospite
2018-06-22 16:51 ` Brandon Williams
2018-06-22 16:26 ` [PATCH 4/7] submodule-config: make 'config_from_gitmodules' private Antonio Ospite
2018-06-22 16:26 ` [PATCH 5/7] submodule-config: pass repository as argument to config_from_gitmodules Antonio Ospite
2018-06-22 16:26 ` [PATCH 6/7] submodule-config: reuse config_from_gitmodules in repo_read_gitmodules Antonio Ospite
2018-06-22 16:55 ` Brandon Williams [this message]
2018-06-22 16:26 ` [PATCH 7/7] submodule-config: cleanup backward compatibility helpers Antonio Ospite
2018-06-22 17:09 ` Brandon Williams
2018-06-22 17:13 ` [PATCH 0/7] Restrict the usage of config_from_gitmodules() Brandon Williams
2018-06-22 20:31 ` Antonio Ospite
2018-06-22 21:13 ` Brandon Williams
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=20180622165514.GC244185@google.com \
--to=bmwill@google.com \
--cc=ao2@ao2.it \
--cc=git@vger.kernel.org \
--cc=jrnieder@gmail.com \
--cc=peff@peff.net \
--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 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 NNTP newsgroup(s).