Message ID | 3687637915f4fdf62d15791f5cf41f9ea7838f4e.1639108573.git.gitgitgadget@gmail.com (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | sparse-checkout: make set subsume init | expand |
"Elijah Newren via GitGitGadget" <gitgitgadget@gmail.com> writes: > From: Elijah Newren <newren@gmail.com> > > Folks may want to switch to or from cone mode, or to or from a > sparse-index without changing their sparsity paths. Allow them to do so > using the reapply command. Interesting. Are there certain pattern that would make sense only in one of the modes but not the other? If there isn't any such pattern, this feature perfectly makes sense, I would think. If an existing pattern changes its meaning between the old mode and the new mode, that is very much fine---that is what the user wanted to achieve by switching between the modes with "reapply". Thanks. > Reviewed-by: Derrick Stolee <dstolee@microsoft.com> > Reviewed-by: Victoria Dye <vdye@github.com> > Signed-off-by: Elijah Newren <newren@gmail.com> > --- > builtin/sparse-checkout.c | 18 +++++++++++++++++- > 1 file changed, 17 insertions(+), 1 deletion(-) > > diff --git a/builtin/sparse-checkout.c b/builtin/sparse-checkout.c > index 1ecdc3ddd5a..9d2a05677c4 100644 > --- a/builtin/sparse-checkout.c > +++ b/builtin/sparse-checkout.c > @@ -759,13 +759,22 @@ static int sparse_checkout_set(int argc, const char **argv, const char *prefix) > } > > static char const * const builtin_sparse_checkout_reapply_usage[] = { > - N_("git sparse-checkout reapply"), > + N_("git sparse-checkout reapply [--[no-]cone] [--[no-]sparse-index] "), > NULL > }; > > +static struct sparse_checkout_reapply_opts { > + int cone_mode; > + int sparse_index; > +} reapply_opts; > + > static int sparse_checkout_reapply(int argc, const char **argv) > { > static struct option builtin_sparse_checkout_reapply_options[] = { > + OPT_BOOL(0, "cone", &reapply_opts.cone_mode, > + N_("initialize the sparse-checkout in cone mode")), > + OPT_BOOL(0, "sparse-index", &reapply_opts.sparse_index, > + N_("toggle the use of a sparse index")), > OPT_END(), > }; > > @@ -777,6 +786,13 @@ static int sparse_checkout_reapply(int argc, const char **argv) > builtin_sparse_checkout_reapply_usage, 0); > > repo_read_index(the_repository); > + > + reapply_opts.cone_mode = -1; > + reapply_opts.sparse_index = -1; > + > + if (update_modes(&reapply_opts.cone_mode, &reapply_opts.sparse_index)) > + return 1; > + > return update_working_directory(NULL); > }
On Mon, Dec 13, 2021 at 10:23 AM Junio C Hamano <gitster@pobox.com> wrote: > > "Elijah Newren via GitGitGadget" <gitgitgadget@gmail.com> writes: > > > From: Elijah Newren <newren@gmail.com> > > > > Folks may want to switch to or from cone mode, or to or from a > > sparse-index without changing their sparsity paths. Allow them to do so > > using the reapply command. > > Interesting. > > Are there certain pattern that would make sense only in one of the > modes but not the other? If there isn't any such pattern, this > feature perfectly makes sense, I would think. Good question. Valid cone mode patterns are a strict subset of the possible sparsity patterns. So, switching from cone to non-cone mode trivially makes sense. Understanding why switching in the other direction is okay takes a bit more understanding... Stolee designed cone mode such that when it's active, and someone edits .git/info/sparse-checkout and adds patterns of their own (which users might do because that had been suggested for several years in the read-tree docs -- and still is), then the code will print a warning ("disabling cone pattern matching") and operate in non-cone mode. As such, the sparsity does not "break" when they switch modes if they have non-cone patterns; they'll just get warnings. Further, we're making `reapply` consistent with `init` here. Stolee made `init` usable for switching modes in an active sparse-checkout (though it wasn't well documented, and it's slightly confusing to users who might worry that they'll lose their sparsity patterns by using `init`). We're just copying that ability from `init` over in `reapply`, and recommending using the latter rather than the former. > If an existing pattern changes its meaning between the old mode and > the new mode, that is very much fine---that is what the user wanted > to achieve by switching between the modes with "reapply". > > Thanks.
diff --git a/builtin/sparse-checkout.c b/builtin/sparse-checkout.c index 1ecdc3ddd5a..9d2a05677c4 100644 --- a/builtin/sparse-checkout.c +++ b/builtin/sparse-checkout.c @@ -759,13 +759,22 @@ static int sparse_checkout_set(int argc, const char **argv, const char *prefix) } static char const * const builtin_sparse_checkout_reapply_usage[] = { - N_("git sparse-checkout reapply"), + N_("git sparse-checkout reapply [--[no-]cone] [--[no-]sparse-index] "), NULL }; +static struct sparse_checkout_reapply_opts { + int cone_mode; + int sparse_index; +} reapply_opts; + static int sparse_checkout_reapply(int argc, const char **argv) { static struct option builtin_sparse_checkout_reapply_options[] = { + OPT_BOOL(0, "cone", &reapply_opts.cone_mode, + N_("initialize the sparse-checkout in cone mode")), + OPT_BOOL(0, "sparse-index", &reapply_opts.sparse_index, + N_("toggle the use of a sparse index")), OPT_END(), }; @@ -777,6 +786,13 @@ static int sparse_checkout_reapply(int argc, const char **argv) builtin_sparse_checkout_reapply_usage, 0); repo_read_index(the_repository); + + reapply_opts.cone_mode = -1; + reapply_opts.sparse_index = -1; + + if (update_modes(&reapply_opts.cone_mode, &reapply_opts.sparse_index)) + return 1; + return update_working_directory(NULL); }