All of lore.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: "Nakul V S via GitGitGadget" <gitgitgadget@gmail.com>
Cc: git@vger.kernel.org,  Patrick Steinhardt <ps@pks.im>,
	 Phillip Wood <phillip.wood123@gmail.com>,
	 Nakul V S <vsnakul@gmail.com>
Subject: Re: [PATCH v2] sequencer: refuse to pick or revert shallow boundary commits
Date: Sun, 01 Nov 2026 10:08:20 -0800	[thread overview]
Message-ID: <xmqqbj881l2j.fsf@gitster.g> (raw)
In-Reply-To: <pull.2273.v2.git.1793455522168.gitgitgadget@gmail.com> (Nakul V. S. via GitGitGadget's message of "Sat, 31 Oct 2026 14:05:22 +0000")

"Nakul V S via GitGitGadget" <gitgitgadget@gmail.com> writes:

> From: Nakul V S <vsnakul@gmail.com>
>
> In a shallow repository, the commits at the edge of the downloaded
> history are recorded in $GIT_DIR/shallow and have their parents hidden
> from the revision machinery.  Such a "shallow boundary" commit looks
> like a root commit that added every file in its tree at once.
>
> Reverting it therefore removes every tracked file, and cherry-picking
> or rebasing it adds all of them again.  In a "git clone --depth=1" this
> is the only commit there is, so "git revert HEAD" empties the working
> tree, which is almost never what the user meant.
>
> Refuse to do so by default for "revert", "cherry-pick" and "rebase".
> For "revert" and "cherry-pick" only, add --allow-shallow-boundary to
> override the check; it is remembered across --continue.  "rebase"
> always refuses, and the error message suggests "git fetch --unshallow"
> instead.
>
> The check is made when the list of commits to replay is built, not when
> each commit is picked, so a command that is going to be refused does so
> before it has done anything: no commit is created, HEAD and the working
> tree are untouched, and no sequencer or rebase state is left behind for
> the user to clean up.
>
> The "apply" backend of "rebase" does not go through the sequencer, so
> it checks the commits "git format-patch" is about to turn into patches
> before it rewinds HEAD.  This is skipped altogether in a repository
> that is not shallow.
>
> A "pick" or "revert" line for a shallow boundary commit that the user
> types into the todo list by hand is not checked, as the check is not
> made again after the todo list has been edited.  "git commit --amend"
> is also left alone for now.
>
> Signed-off-by: Nakul V S <vsnakul@gmail.com>
> ---
>     sequencer: refuse to pick or revert shallow boundary commits by default
>     
>     Changes since v1:
>     
>      * Also refuse cherry-pick and rebase (merge, interactive and --apply
>        backends), as suggested by Phillip.
>      * Check when the list of commits is built rather than in
>        do_pick_commit(), so a refused command leaves no state behind. Uses a
>        single shared helper.
>      * --allow-shallow-boundary is now accepted by cherry-pick as well, and
>        is saved across --continue.
>      * Dropped the option from the revert synopsis.
>      * rebase --autostash restores the user's changes if the rebase is
>        refused.
>      * Rebased onto current master.
>     
>     Not covered here: git commit --amend, and pick/revert lines typed into
>     the rebase todo by hand.
>
> Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-2273%2Fvsnakul%2Fsequencer-shallow-boundary-check-v2
> Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2273/vsnakul/sequencer-shallow-boundary-check-v2
> Pull-Request: https://github.com/gitgitgadget/git/pull/2273
>
> Range-diff vs v1:

For a single-patch series a large range-diff like this before the
patch makes it very distracting.  Isn't there a way to tell
GitGitGadget not to do this (or perhaps add it after the patch)?

> diff --git a/shallow.c b/shallow.c
> index 8e244a5669..bc31ff5232 100644
> --- a/shallow.c
> +++ b/shallow.c
> @@ -92,6 +92,15 @@ int is_repository_shallow(struct repository *r)
>  	return r->parsed_objects->is_shallow;
>  }
>  
> +int is_shallow_boundary_commit(struct repository *r, const struct object_id *oid)
> +{
> +	struct commit_graft *graft;
> +	if (!is_repository_shallow(r))
> +		return 0;
> +	graft = lookup_commit_graft(r, oid);
> +	return graft && graft->nr_parent < 0;
> +}
> +

Please check how badly your change conflicts with at least 'next'
and 'seen' before sending any non-trivial patch.  Doing so would
have shown you that you do not need to write this function, and
should instead discuss the best course to resolve the conflict with
Harald, who wrote f8bc48ea42 (object-name: explain why <rev>~N fails
in a shallow clone, 2026-09-23).

That other topic is currently stagnant.  You can see how topics are
doing by visiting the mailing list archive.  For example, a trial
merge of your patch into 'seen' would have shown that Harald's
f8bc48ea42 is highly relevant.  Using its Message-ID, you can find
it on the lore archive:

  https://lore.kernel.org/git/pull.2413.v3.git.git.1790189759802.gitgitgadget@gmail.com/

The archive shows that v3 was posted without replying to reviews on
v2, and no new reviewers have shown interest since then, leaving the
topic stuck.

The best path forward is for someone with a stake in getting this
topic unstuck, such as yourself, to provide a fresh review.  This
can help push it to the finish line, or help us realize that it is
not viable so the topic can be dropped.  In the former case, you can
reuse the function introduced by that topic in your patch.  In the
latter case, we no longer need to worry about the two topics
conflicting.

Thanks.

      parent reply	other threads:[~2026-11-01 18:08 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-21 10:09 [PATCH] sequencer: refuse to revert shallow boundary commits by default Nakul V S via GitGitGadget
2026-10-21 15:20 ` Phillip Wood
2026-10-21 19:11   ` Junio C Hamano
2026-10-26 10:58     ` Phillip Wood
2026-10-31 17:22       ` Nakul V S
2026-10-31 17:29     ` Nakul V S
2026-10-31 17:18   ` Nakul V S
2026-10-31 14:05 ` [PATCH v2] sequencer: refuse to pick or revert shallow boundary commits Nakul V S via GitGitGadget
2026-11-01  2:30   ` Junio C Hamano
2026-11-01 18:08   ` Junio C Hamano [this message]

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=xmqqbj881l2j.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=gitgitgadget@gmail.com \
    --cc=phillip.wood123@gmail.com \
    --cc=ps@pks.im \
    --cc=vsnakul@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.