Re: [WIP v1 3/4] mv: add advise_to_reapply hint for moving file into cone
- From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
- Date
- Mar 31, 2022, 10:30 UTC
- Message-ID
- <220331.86ilruqup6.gmgdl@evledraar.gmail.com>
- In-Reply-To
- <20220331091755.385961-4-shaoxuan.yuan02@gmail.com>
On Thu, Mar 31 2022, Shaoxuan Yuan wrote:
Show 43 quoted lines
> Originally, the SKIP_WORKTREE bit is not removed when moving an out-of-cone
> file into sparse cone, thus the moved file does not show up in the working tree.
> Hint the user to use "git sparse-checkout reapply" to reapply the sparsity rules
> to the working tree, by which the SKIP_WORKTREE bit is removed.
>
> Signed-off-by: Shaoxuan Yuan <shaoxuan.yuan02@gmail.com>
> ---
> I offered this solution becasue I'm not sure how to turn a cache_entry's
> ce_flags back to a non-sparse state. I tried directly set it to 0 like this:
>
> ce->ce_flags = 0;
>
> But the behavior after this seems undefined. The file still won't show up
> in the working tree.
>
> And I found that "git sparse-checkout reapply" seems to be a nice fit for the
> job. But I guess if there is a way (there must be but I don't know) to do it
> direcly in the code, that could also be nice.
>
> builtin/mv.c | 9 +++++++++
> 1 file changed, 9 insertions(+)
>
> diff --git a/builtin/mv.c b/builtin/mv.c
> index 9da9205e01..5f511fb8da 100644
> --- a/builtin/mv.c
> +++ b/builtin/mv.c
> @@ -138,6 +138,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
> {
> int i, flags, gitmodules_modified = 0;
> int verbose = 0, show_only = 0, force = 0, ignore_errors = 0, ignore_sparse = 0;
> + int advise_to_reapply = 0;
> struct option builtin_mv_options[] = {
> OPT__VERBOSE(&verbose, N_("be verbose")),
> OPT__DRY_RUN(&show_only, N_("dry run")),
> @@ -383,6 +384,11 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
> pos = cache_name_pos(src, strlen(src));
> assert(pos >= 0);
> rename_cache_entry_at(pos, dst);
> + if (!advise_to_reapply &&
> + !path_in_sparse_checkout(src, &the_index) &&
> + path_in_sparse_checkout(dst, &the_index)) {
> + advise_to_reapply = 1;
> + }More odd indentation, and the braces aren't needed.
Show 10 quoted lines
> }
>
> if (gitmodules_modified)
> @@ -392,6 +398,9 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
> COMMIT_LOCK | SKIP_IF_UNCHANGED))
> die(_("Unable to write new index file"));
>
> + if (advise_to_reapply)
> + printf(_("Please use \"git sparse-checkout reapply\" to reapply the sparsity.\n"));
> +Please see 93026558512 (tracking branches: add advice to ambiguous refspec error, 2022-03-28) (the OID may change after I send this, as it's in "seen") for how to add new advise, i.e. we use advise(), add an enum field, config var etc.