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

Re: [PATCH 3/6] sparse-checkout: enable `set` to initialize sparse-checkout mode

From
Lessley Dennington <lessleydennington@gmail.com>
Date
Dec 7, 2021, 20:36 UTC
Message-ID
<6e09ab19-7ffb-e58e-7b08-6e560b421c06@gmail.com>
In-Reply-To
<CABPp-BF-7DRmE+DPZOFuCYwSRdD8yk4pPsYpFN4=5fALEkqATg@mail.gmail.com>
On 12/7/21 9:04 AM, Elijah Newren wrote:
Show 55 quoted lines
> On Sat, Dec 4, 2021 at 1:40 PM Victoria Dye <vdye@github.com> wrote:
>>
>> 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).
> 
> Yeah, fair point.  When copying from init I probably should have double checked.
> 
> Also, it makes me wonder if we should just make cone mode the default...
> 

That was actually my first thought when reviewing this change! It feels like this would be a great moment to take the leap on that, but I can also see it warranting a separate series.

Show 93 quoted lines
>>>        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.
> 
> Good point.  OPT_SET_INT() wouldn't fix it, though; you need to use
> OPT_BOOL_F or OPT_SET_INT_F and pass PARSE_OPT_NONEG as a flag.  I can
> include that.
> 
>>>                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.
> 
> Eek.  I had it there originally, then moved it later while doing
> various changes.  This definitely should be later; thanks for
> catching.
> 
>>> +             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);
>>>   }
Previous: Elijah NewrenNext: Derrick Stolee
Message 7 of 63 in “sparse-checkout: make set subsume init”
  1. 0/6 sparse-checkout: make set subsume initElijah Newren via GitGitGadget, Dec 4, 2021
  2. 1/6 sparse-checkout: pass use_stdin as a parameter instead of as a globalElijah Newren via GitGitGadget, Dec 4, 2021
  3. 2/6 sparse-checkout: break apart functions for sparse_checkout_(set|add)Elijah Newren via GitGitGadget, Dec 4, 2021
  4. 3/6 sparse-checkout: enable `set` to initialize sparse-checkout modeElijah Newren via GitGitGadget, Dec 4, 2021
  5. Victoria DyeDec 4, 2021
  6. Elijah NewrenDec 7, 2021
  7. Lessley DenningtonDec 7, 2021
  8. Derrick StoleeDec 7, 2021
  9. Elijah NewrenDec 7, 2021
  10. 4/6 git-sparse-checkout.txt: update to document that set handles initElijah Newren via GitGitGadget, Dec 4, 2021
  11. Victoria DyeDec 4, 2021
  12. Derrick StoleeDec 7, 2021
  13. Elijah NewrenDec 7, 2021
  14. Lessley DenningtonDec 7, 2021
  15. Elijah NewrenDec 7, 2021
  16. Lessley DenningtonDec 7, 2021
  17. 5/6 Documentation: clarify/correct a few sparsity related statementsElijah Newren via GitGitGadget, Dec 4, 2021
  18. 6/6 clone: avoid using deprecated `sparse-checkout init`Elijah Newren via GitGitGadget, Dec 4, 2021
  19. Derrick StoleeDec 7, 2021
  20. 00/10 sparse-checkout: make set subsume initElijah Newren via GitGitGadget, Dec 7, 2021
  21. 01/10 sparse-checkout: pass use_stdin as a parameter instead of as a globalElijah Newren via GitGitGadget, Dec 7, 2021
  22. 02/10 sparse-checkout: break apart functions for sparse_checkout_(set|add)Elijah Newren via GitGitGadget, Dec 7, 2021
  23. 03/10 sparse-checkout: add sanity-checks on initial sparsity stateElijah Newren via GitGitGadget, Dec 7, 2021
  24. 04/10 sparse-checkout: disallow --no-stdin as an argument to setElijah Newren via GitGitGadget, Dec 7, 2021
  25. 05/10 sparse-checkout: split out code for tweaking settings configElijah Newren via GitGitGadget, Dec 7, 2021
  26. 06/10 sparse-checkout: enable `set` to initialize sparse-checkout modeElijah Newren via GitGitGadget, Dec 7, 2021
  27. 07/10 sparse-checkout: enable reapply to take --[no-]{cone,sparse-index}Elijah Newren via GitGitGadget, Dec 7, 2021
  28. 08/10 git-sparse-checkout.txt: update to document init/set/reapply changesElijah Newren via GitGitGadget, Dec 7, 2021
  29. 09/10 Documentation: clarify/correct a few sparsity related statementsElijah Newren via GitGitGadget, Dec 7, 2021
  30. 10/10 clone: avoid using deprecated `sparse-checkout init`Elijah Newren via GitGitGadget, Dec 7, 2021
  31. Derrick StoleeDec 7, 2021
  32. Victoria DyeDec 8, 2021
  33. 00/10 sparse-checkout: make set subsume initElijah Newren via GitGitGadget, Dec 10, 2021
  34. 01/10 sparse-checkout: pass use_stdin as a parameter instead of as a globalElijah Newren via GitGitGadget, Dec 10, 2021
  35. 02/10 sparse-checkout: break apart functions for sparse_checkout_(set|add)Elijah Newren via GitGitGadget, Dec 10, 2021
  36. 03/10 sparse-checkout: add sanity-checks on initial sparsity stateElijah Newren via GitGitGadget, Dec 10, 2021
  37. Junio C HamanoDec 13, 2021
  38. Elijah NewrenDec 14, 2021
  39. 04/10 sparse-checkout: disallow --no-stdin as an argument to setElijah Newren via GitGitGadget, Dec 10, 2021
  40. 06/10 sparse-checkout: enable `set` to initialize sparse-checkout modeElijah Newren via GitGitGadget, Dec 10, 2021
  41. 05/10 sparse-checkout: split out code for tweaking settings configElijah Newren via GitGitGadget, Dec 10, 2021
  42. 07/10 sparse-checkout: enable reapply to take --[no-]{cone,sparse-index}Elijah Newren via GitGitGadget, Dec 10, 2021
  43. Junio C HamanoDec 13, 2021
  44. Elijah NewrenDec 14, 2021
  45. 08/10 git-sparse-checkout.txt: update to document init/set/reapply changesElijah Newren via GitGitGadget, Dec 10, 2021
  46. 09/10 Documentation: clarify/correct a few sparsity related statementsElijah Newren via GitGitGadget, Dec 10, 2021
  47. 10/10 clone: avoid using deprecated `sparse-checkout init`Elijah Newren via GitGitGadget, Dec 10, 2021
  48. 00/10 sparse-checkout: make set subsume initElijah Newren via GitGitGadget, Dec 14, 2021
  49. 01/10 sparse-checkout: pass use_stdin as a parameter instead of as a globalElijah Newren via GitGitGadget, Dec 14, 2021
  50. 02/10 sparse-checkout: break apart functions for sparse_checkout_(set|add)Elijah Newren via GitGitGadget, Dec 14, 2021
  51. 03/10 sparse-checkout: add sanity-checks on initial sparsity stateElijah Newren via GitGitGadget, Dec 14, 2021
  52. 04/10 sparse-checkout: disallow --no-stdin as an argument to setElijah Newren via GitGitGadget, Dec 14, 2021
  53. 05/10 sparse-checkout: split out code for tweaking settings configElijah Newren via GitGitGadget, Dec 14, 2021
  54. 07/10 sparse-checkout: enable reapply to take --[no-]{cone,sparse-index}Elijah Newren via GitGitGadget, Dec 14, 2021
  55. Jiang XinDec 23, 2021
  56. Elijah NewrenDec 23, 2021
  57. Junio C HamanoDec 23, 2021
  58. 09/10 Documentation: clarify/correct a few sparsity related statementsElijah Newren via GitGitGadget, Dec 14, 2021
  59. Bagas SanjayaDec 14, 2021
  60. Elijah NewrenDec 14, 2021
  61. 08/10 git-sparse-checkout.txt: update to document init/set/reapply changesElijah Newren via GitGitGadget, Dec 14, 2021
  62. 06/10 sparse-checkout: enable `set` to initialize sparse-checkout modeElijah Newren via GitGitGadget, Dec 14, 2021
  63. 10/10 clone: avoid using deprecated `sparse-checkout init`Elijah Newren via GitGitGadget, Dec 14, 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.