git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 1/2] sparse-index.c: remove set_index_sparse_config()

From
Derrick Stolee <stolee@gmail.com>
Date
May 5, 2021, 14:01 UTC
Message-ID
<a9f4ec53-f9f0-3522-6ad2-510b46605a53@gmail.com>
In-Reply-To
<patch-1.2-6872fd6a59b-20210505T121028Z-avarab@gmail.com>
On 5/5/2021 8:11 AM, Ævar Arnfjörð Bjarmason wrote:
Show 52 quoted lines
> Remove the set_index_sparse_config() function by folding it into
> set_sparse_index_config(), which was its only user.
> 
> Since 122ba1f7b52 (sparse-checkout: toggle sparse index from builtin,
> 2021-03-30) the flow of this code hasn't made much sense, we'd get
> "enabled" in set_sparse_index_config(), proceed to call
> set_index_sparse_config() with it.
> 
> There we'd call prepare_repo_settings() and set
> "repo->settings.sparse_index = 1", only to needlessly call
> prepare_repo_settings() again in set_sparse_index_config() (where it
> would early abort), and finally setting "repo->settings.sparse_index =
> enabled".
> 
> Instead we can just call prepare_repo_settings() once, and set the
> variable to "enabled" in the first place.
> 
> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
> ---
>  sparse-index.c | 11 +----------
>  1 file changed, 1 insertion(+), 10 deletions(-)
> 
> diff --git a/sparse-index.c b/sparse-index.c
> index 6f21397e2ee..b0d5dc5f081 100644
> --- a/sparse-index.c
> +++ b/sparse-index.c
> @@ -102,7 +102,7 @@ static int convert_to_sparse_rec(struct index_state *istate,
>  	return num_converted - start_converted;
>  }
>  
> -static int set_index_sparse_config(struct repository *repo, int enable)
> +int set_sparse_index_config(struct repository *repo, int enable)
>  {
>  	int res;
>  	char *config_path = repo_git_path(repo, "config.worktree");
> @@ -111,15 +111,6 @@ static int set_index_sparse_config(struct repository *repo, int enable)
>  					    enable ? "true" : NULL);
>  	free(config_path);
>  
> -	prepare_repo_settings(repo);
> -	repo->settings.sparse_index = 1;
> -	return res;
> -}
> -
> -int set_sparse_index_config(struct repository *repo, int enable)
> -{
> -	int res = set_index_sparse_config(repo, enable);
> -
>  	prepare_repo_settings(repo);
>  	repo->settings.sparse_index = enable;
>  	return res;
> 

This cleanup makes sense to me. The previous code was confusing and this is an improvement.

Thanks, -Stolee

Previous: Ævar Arnfjörð BjarmasonNext: Ævar Arnfjörð Bjarmason
Message 3 of 8 in “sparse-index.c: minor prepare_repo_settings() fixes”
  1. 0/2 sparse-index.c: minor prepare_repo_settings() fixesÆvar Arnfjörð Bjarmason, May 5, 2021
  2. 1/2 sparse-index.c: remove set_index_sparse_config()Ævar Arnfjörð Bjarmason, May 5, 2021
  3. Derrick StoleeMay 5, 2021
  4. 2/2 sparse-index.c: don't call prepare_repo_settings() twice in a rowÆvar Arnfjörð Bjarmason, May 5, 2021
  5. Derrick StoleeMay 5, 2021
  6. Junio C HamanoMay 6, 2021
  7. Ævar Arnfjörð BjarmasonMay 6, 2021
  8. Derrick StoleeMay 17, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.