From: Derrick Stolee Date: Wed, 03 Aug 2022 14:30:20 GMT Subject: Re: [PATCH v1 6/7] mv: from in-cone to out-of-cone Message-ID: <1db0d83d-0239-5a5f-3390-822ee780172e@github.com> In-Reply-To: <9a568923-0b2c-8c41-e774-bcf8e6e9d9ea@gmail.com> On 8/3/2022 7:50 AM, Shaoxuan Yuan wrote: > On 7/20/2022 2:14 AM, Derrick Stolee wrote: >>> -        if ((mode & SPARSE) && >>> -            (path_in_sparse_checkout(dst, &the_index))) { >>> -            int dst_pos; >>> +        if (ignore_sparse && >>> +            core_apply_sparse_checkout && >>> +            core_sparse_checkout_cone) { >>> >>> -            dst_pos = cache_name_pos(dst, strlen(dst)); >>> -            active_cache[dst_pos]->ce_flags &= ~CE_SKIP_WORKTREE; >>> +            /* from out-of-cone to in-cone */ >>> +            if ((mode & SPARSE) && >>> +                path_in_sparse_checkout(dst, &the_index)) { >>> +                int dst_pos = cache_name_pos(dst, strlen(dst)); >>> +                struct cache_entry *dst_ce = active_cache[dst_pos]; >>> >>> -            if (checkout_entry(active_cache[dst_pos], &state, NULL, NULL)) >>> -                die(_("cannot checkout %s"), active_cache[dst_pos]->name); >>> +                dst_ce->ce_flags &= ~CE_SKIP_WORKTREE; >>> + >>> +                if (checkout_entry(dst_ce, &state, NULL, NULL)) >>> +                    die(_("cannot checkout %s"), dst_ce->name); >>> +                continue; >>> +            } >> >> Here, it helps to ignore whitespace changes. This out to in was already >> handled by the existing implementation. > > Yes, I think it would be better to let `diff` ignore the existing > implementation. Are you suggesting the `-w` (--ignore-all-space) option > of `diff`? I tried this option and it does not work. But another reason > is that there *are* some changes that are different from the original > out-to-in implementation, so even though it looks a bit messy, I think > it makes sense. I'm just making a note that I looked at this not in its patch form, but as a commit diff where I could use the '-w' option to get a nice view. It's not possible to do that in the patch. >>> +            /* from in-cone to out-of-cone */ >>> +            if ((dst_mode & SKIP_WORKTREE_DIR) && >> >> This is disjoint from the other case (because of !path_in_sparse_checkout()), >> so maybe we could short-circuit with an "else if" here? You could put your >> comments about the in-to-out or out-to-in inside the if blocks. > > I tried an else-if but it does clutter the code a bit. I think I'll > leave it as-is. Or do you mind show me a diff of your approach? To be > honest, this disjoint here looks logically cleaner to me. Here's the diff I had in mind: --- >8 --- diff --git a/builtin/mv.c b/builtin/mv.c index df1f69f1a7..111aafb69a 100644 --- a/builtin/mv.c +++ b/builtin/mv.c @@ -455,10 +455,9 @@ int cmd_mv(int argc, const char **argv, const char *prefix) if (ignore_sparse && core_apply_sparse_checkout && core_sparse_checkout_cone) { - - /* from out-of-cone to in-cone */ if ((mode & SPARSE) && path_in_sparse_checkout(dst, &the_index)) { + /* from out-of-cone to in-cone */ int dst_pos = cache_name_pos(dst, strlen(dst)); struct cache_entry *dst_ce = active_cache[dst_pos]; @@ -466,13 +465,10 @@ int cmd_mv(int argc, const char **argv, const char *prefix) if (checkout_entry(dst_ce, &state, NULL, NULL)) die(_("cannot checkout %s"), dst_ce->name); - continue; - } - - /* from in-cone to out-of-cone */ - if ((dst_mode & SKIP_WORKTREE_DIR) && - !(mode & SPARSE) && - !path_in_sparse_checkout(dst, &the_index)) { + } else if ((dst_mode & SKIP_WORKTREE_DIR) && + !(mode & SPARSE) && + !path_in_sparse_checkout(dst, &the_index)) { + /* from in-cone to out-of-cone */ int dst_pos = cache_name_pos(dst, strlen(dst)); struct cache_entry *dst_ce = active_cache[dst_pos]; char *src_dir = dirname(xstrdup(src)); --- >8 --- I agree with you that the whitespace breaking the two cases is nice, but relying on that "continue;" to keep these cases disjoint is easy to miss and I'd rather let the code be clearer about the cases. Thanks, -Stolee