git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Victoria Dye <vdye@github.com>
To: Elijah Newren via GitGitGadget <gitgitgadget@gmail.com>,
	git@vger.kernel.org
Cc: Derrick Stolee <stolee@gmail.com>,
	Lessley Dennington <lessleydennington@gmail.com>,
	Elijah Newren <newren@gmail.com>
Subject: Re: [PATCH 3/6] sparse-checkout: enable `set` to initialize sparse-checkout mode
Date: Sat, 4 Dec 2021 16:40:00 -0500	[thread overview]
Message-ID: <bb738571-f90c-7df5-2e20-ff716ed8a4f0@github.com> (raw)
In-Reply-To: <a90687eb4c1ea6569250391cd2a8111a0e338316.1638648020.git.gitgitgadget@gmail.com>

Elijah Newren via GitGitGadget wrote:
> From: Elijah Newren <newren@gmail.com>
> 
> The previously suggested workflow:
>   git sparse-checkout init ...
>   git sparse-checkout set ...
> 
> Suffered from three problems:
>   1) It would delete nearly all files in the first step, then
>      restore them in the second.  That was poor performance and
>      forced unnecessary rebuilds.
>   2) The two-step process resulted in two progress bars, which
>      was suboptimal from a UI point of view for wrappers that
>      invoked both of these commands but only exposed a single
>      command to their end users.
>   3) With cone mode, the first step would delete nearly all
>      ignored files everywhere, because everything was considered
>      to be outside of the specified sparsity paths.  (The user was
>      not allowed to specify any sparsity paths in the `init` step.)
> 
> Avoid these problems by teaching `set` to understand the extra
> parameters that `init` takes and performing any necessary initialization
> if not already in a sparse checkout.
> 

I really like this change! It always seemed weird that `set` would
implicitly `init`, but without any of the options in `init`.

> Signed-off-by: Elijah Newren <newren@gmail.com>
> ---
>  builtin/sparse-checkout.c | 52 ++++++++++++++++++++++++++++++++++++++-
>  1 file changed, 51 insertions(+), 1 deletion(-)
> 
> diff --git a/builtin/sparse-checkout.c b/builtin/sparse-checkout.c
> index e252b82136e..cf6a6c6c3a7 100644
> --- a/builtin/sparse-checkout.c
> +++ b/builtin/sparse-checkout.c
> @@ -682,17 +682,26 @@ static int sparse_checkout_add(int argc, const char **argv, const char *prefix)
>  }
>  
>  static char const * const builtin_sparse_checkout_set_usage[] = {
> -	N_("git sparse-checkout set (--stdin | <patterns>)"),
> +	N_("git sparse-checkout set [--cone] [--[no-]sparse-index] (--stdin | <patterns>)"),

Since `cone` is an `OPT_BOOL`, shouldn't it appear in the usage string as
`--[no-]cone`? Without a `--no-cone` option, it's not clear how a user would
disable cone mode (since `set` preserves the existing cone mode setting if
`--cone` isn't given).

>  	NULL
>  };
>  
>  static struct sparse_checkout_set_opts {
> +	int cone_mode;
> +	int sparse_index;
>  	int use_stdin;
>  } set_opts;
>  
>  static int sparse_checkout_set(int argc, const char **argv, const char *prefix)
>  {
> +	int mode, record_mode;
> +	const char *default_patterns[] = {"/*", "!/*/"};
> +
>  	static struct option builtin_sparse_checkout_set_options[] = {
> +		OPT_BOOL(0, "cone", &set_opts.cone_mode,
> +			 N_("initialize the sparse-checkout in cone mode")),
> +		OPT_BOOL(0, "sparse-index", &set_opts.sparse_index,
> +			 N_("toggle the use of a sparse index")),
>  		OPT_BOOL(0, "stdin", &set_opts.use_stdin,
>  			 N_("read patterns from standard in")),

I know this isn't part of this patch, but is `stdin` really a bool (i.e.
someone might specify `--no-stdin`)? If not, I think `OPT_SET_INT` might be
more appropriate.

>  		OPT_END(),
> @@ -700,11 +709,52 @@ static int sparse_checkout_set(int argc, const char **argv, const char *prefix)
>  
>  	repo_read_index(the_repository);
>  
> +	set_opts.cone_mode = -1;
> +	set_opts.sparse_index = -1;
> +
>  	argc = parse_options(argc, argv, prefix,
>  			     builtin_sparse_checkout_set_options,
>  			     builtin_sparse_checkout_set_usage,
>  			     PARSE_OPT_KEEP_UNKNOWN);
>  
> +	/* Determine if we need to record the mode; ensure sparse checkout on */
> +	record_mode = (set_opts.cone_mode != -1) || !core_apply_sparse_checkout;
> +	core_apply_sparse_checkout = 1;
> +
> +	/* If not specified, use previous definition of cone mode */
> +	if (set_opts.cone_mode == -1 && core_apply_sparse_checkout)

I *think* this is supposed go before the `core_apply_sparse_checkout = 1;`
above it (if the intention is to only use the pre-existing cone mode setting
when already in a sparse checkout). If not, the `core_apply_sparse_checkout`
part of the condition is redundant and can be removed entirely.

> +		set_opts.cone_mode = core_sparse_checkout_cone;
> +
> +	/* Set cone/non-cone mode appropriately */
> +	if (set_opts.cone_mode == 1) {
> +		mode = MODE_CONE_PATTERNS;
> +		core_sparse_checkout_cone = 1;
> +	} else {
> +		mode = MODE_ALL_PATTERNS;
> +	}
> +	if (record_mode && set_config(mode))
> +		return 1;
> +
> +	/* Set sparse-index/non-sparse-index mode if specified */
> +	if (set_opts.sparse_index >= 0) {
> +		if (set_sparse_index_config(the_repository, set_opts.sparse_index) < 0)
> +			die(_("failed to modify sparse-index config"));
> +
> +		/* force an index rewrite */
> +		repo_read_index(the_repository);
> +		the_repository->index->updated_workdir = 1;
> +	}
> +
> +	/*
> +	 * Cone mode automatically specifies the toplevel directory.  For
> +	 * non-cone mode, if nothing is specified, manually select just the
> +	 * top-level directory (much as 'init' would do).
> +	 */
> +	if (!core_sparse_checkout_cone && argc == 0) {
> +		argv = default_patterns;
> +		argc = 2;
> +	}
> +
>  	return modify_pattern_list(argc, argv, set_opts.use_stdin, REPLACE);
>  }
>  
> 


  reply	other threads:[~2021-12-04 21:40 UTC|newest]

Thread overview: 63+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-04 20:00 [PATCH 0/6] sparse-checkout: make set subsume init Elijah Newren via GitGitGadget
2021-12-04 20:00 ` [PATCH 1/6] sparse-checkout: pass use_stdin as a parameter instead of as a global Elijah Newren via GitGitGadget
2021-12-04 20:00 ` [PATCH 2/6] sparse-checkout: break apart functions for sparse_checkout_(set|add) Elijah Newren via GitGitGadget
2021-12-04 20:00 ` [PATCH 3/6] sparse-checkout: enable `set` to initialize sparse-checkout mode Elijah Newren via GitGitGadget
2021-12-04 21:40   ` Victoria Dye [this message]
2021-12-07 17:04     ` Elijah Newren
2021-12-07 20:36       ` Lessley Dennington
2021-12-07 16:42   ` Derrick Stolee
2021-12-07 18:18     ` Elijah Newren
2021-12-04 20:00 ` [PATCH 4/6] git-sparse-checkout.txt: update to document that set handles init Elijah Newren via GitGitGadget
2021-12-04 21:48   ` Victoria Dye
2021-12-07 16:45     ` Derrick Stolee
2021-12-07 17:06     ` Elijah Newren
2021-12-07 20:42   ` Lessley Dennington
2021-12-07 21:13     ` Elijah Newren
2021-12-07 22:36       ` Lessley Dennington
2021-12-04 20:00 ` [PATCH 5/6] Documentation: clarify/correct a few sparsity related statements Elijah Newren via GitGitGadget
2021-12-04 20:00 ` [PATCH 6/6] clone: avoid using deprecated `sparse-checkout init` Elijah Newren via GitGitGadget
2021-12-07 16:48 ` [PATCH 0/6] sparse-checkout: make set subsume init Derrick Stolee
2021-12-07 20:20 ` [PATCH v2 00/10] " Elijah Newren via GitGitGadget
2021-12-07 20:20   ` [PATCH v2 01/10] sparse-checkout: pass use_stdin as a parameter instead of as a global Elijah Newren via GitGitGadget
2021-12-07 20:20   ` [PATCH v2 02/10] sparse-checkout: break apart functions for sparse_checkout_(set|add) Elijah Newren via GitGitGadget
2021-12-07 20:20   ` [PATCH v2 03/10] sparse-checkout: add sanity-checks on initial sparsity state Elijah Newren via GitGitGadget
2021-12-07 20:20   ` [PATCH v2 04/10] sparse-checkout: disallow --no-stdin as an argument to set Elijah Newren via GitGitGadget
2021-12-07 20:20   ` [PATCH v2 05/10] sparse-checkout: split out code for tweaking settings config Elijah Newren via GitGitGadget
2021-12-07 20:20   ` [PATCH v2 06/10] sparse-checkout: enable `set` to initialize sparse-checkout mode Elijah Newren via GitGitGadget
2021-12-07 20:20   ` [PATCH v2 07/10] sparse-checkout: enable reapply to take --[no-]{cone,sparse-index} Elijah Newren via GitGitGadget
2021-12-07 20:20   ` [PATCH v2 08/10] git-sparse-checkout.txt: update to document init/set/reapply changes Elijah Newren via GitGitGadget
2021-12-07 20:20   ` [PATCH v2 09/10] Documentation: clarify/correct a few sparsity related statements Elijah Newren via GitGitGadget
2021-12-07 20:20   ` [PATCH v2 10/10] clone: avoid using deprecated `sparse-checkout init` Elijah Newren via GitGitGadget
2021-12-07 21:05   ` [PATCH v2 00/10] sparse-checkout: make set subsume init Derrick Stolee
2021-12-08 14:16   ` Victoria Dye
2021-12-10  3:56   ` [PATCH v3 " Elijah Newren via GitGitGadget
2021-12-10  3:56     ` [PATCH v3 01/10] sparse-checkout: pass use_stdin as a parameter instead of as a global Elijah Newren via GitGitGadget
2021-12-10  3:56     ` [PATCH v3 02/10] sparse-checkout: break apart functions for sparse_checkout_(set|add) Elijah Newren via GitGitGadget
2021-12-10  3:56     ` [PATCH v3 03/10] sparse-checkout: add sanity-checks on initial sparsity state Elijah Newren via GitGitGadget
2021-12-13 18:11       ` Junio C Hamano
2021-12-14  2:25         ` Elijah Newren
2021-12-10  3:56     ` [PATCH v3 04/10] sparse-checkout: disallow --no-stdin as an argument to set Elijah Newren via GitGitGadget
2021-12-10  3:56     ` [PATCH v3 05/10] sparse-checkout: split out code for tweaking settings config Elijah Newren via GitGitGadget
2021-12-10  3:56     ` [PATCH v3 06/10] sparse-checkout: enable `set` to initialize sparse-checkout mode Elijah Newren via GitGitGadget
2021-12-10  3:56     ` [PATCH v3 07/10] sparse-checkout: enable reapply to take --[no-]{cone,sparse-index} Elijah Newren via GitGitGadget
2021-12-13 18:23       ` Junio C Hamano
2021-12-14  2:39         ` Elijah Newren
2021-12-10  3:56     ` [PATCH v3 08/10] git-sparse-checkout.txt: update to document init/set/reapply changes Elijah Newren via GitGitGadget
2021-12-10  3:56     ` [PATCH v3 09/10] Documentation: clarify/correct a few sparsity related statements Elijah Newren via GitGitGadget
2021-12-10  3:56     ` [PATCH v3 10/10] clone: avoid using deprecated `sparse-checkout init` Elijah Newren via GitGitGadget
2021-12-14  4:09     ` [PATCH v4 00/10] sparse-checkout: make set subsume init Elijah Newren via GitGitGadget
2021-12-14  4:09       ` [PATCH v4 01/10] sparse-checkout: pass use_stdin as a parameter instead of as a global Elijah Newren via GitGitGadget
2021-12-14  4:09       ` [PATCH v4 02/10] sparse-checkout: break apart functions for sparse_checkout_(set|add) Elijah Newren via GitGitGadget
2021-12-14  4:09       ` [PATCH v4 03/10] sparse-checkout: add sanity-checks on initial sparsity state Elijah Newren via GitGitGadget
2021-12-14  4:09       ` [PATCH v4 04/10] sparse-checkout: disallow --no-stdin as an argument to set Elijah Newren via GitGitGadget
2021-12-14  4:09       ` [PATCH v4 05/10] sparse-checkout: split out code for tweaking settings config Elijah Newren via GitGitGadget
2021-12-14  4:09       ` [PATCH v4 06/10] sparse-checkout: enable `set` to initialize sparse-checkout mode Elijah Newren via GitGitGadget
2021-12-14  4:09       ` [PATCH v4 07/10] sparse-checkout: enable reapply to take --[no-]{cone,sparse-index} Elijah Newren via GitGitGadget
2021-12-23  0:47         ` Jiang Xin
2021-12-23 17:09           ` Elijah Newren
2021-12-23 19:09             ` Junio C Hamano
2021-12-14  4:09       ` [PATCH v4 08/10] git-sparse-checkout.txt: update to document init/set/reapply changes Elijah Newren via GitGitGadget
2021-12-14  4:09       ` [PATCH v4 09/10] Documentation: clarify/correct a few sparsity related statements Elijah Newren via GitGitGadget
2021-12-14  7:38         ` Bagas Sanjaya
2021-12-14  7:48           ` Elijah Newren
2021-12-14  4:09       ` [PATCH v4 10/10] clone: avoid using deprecated `sparse-checkout init` Elijah Newren via GitGitGadget

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=bb738571-f90c-7df5-2e20-ff716ed8a4f0@github.com \
    --to=vdye@github.com \
    --cc=git@vger.kernel.org \
    --cc=gitgitgadget@gmail.com \
    --cc=lessleydennington@gmail.com \
    --cc=newren@gmail.com \
    --cc=stolee@gmail.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).