public inbox for git@vger.kernel.org 
 help / color / mirror / Atom feed
From: Patrick Steinhardt <ps@pks•im>
To: Junio C Hamano <gitster@pobox•com>
Cc: git@vger•kernel.org
Subject: Re: [PATCH 2/2] builtin/history: implement "drop" subcommand
Date: Wed, 3 Jun 2026 12:06:43 +0200	[thread overview]
Message-ID: <ah_8s1Q1Kg0dgw6a@pks.im> (raw)
In-Reply-To: <xmqqbjdt25e3.fsf@gitster.g>

On Tue, Jun 02, 2026 at 08:43:48AM +0900, Junio C Hamano wrote:
> Patrick Steinhardt <ps@pks•im> writes:
[snip]
> > +static int update_worktree(struct repository *repo,
> > +			   const struct commit *old_head,
> > +			   const struct commit *new_head,
> > +			   bool dry_run)
> > +{
> > +...
> > +
> > +out:
> > +	clear_unpack_trees_porcelain(&opts);
> > +	rollback_lock_file(&lock);
> > +	release_index(&index);
> > +	free(desc_buf[0]);
> > +	free(desc_buf[1]);
> > +	return ret;
> > +}
> 
> The function looks very familiar---anybody who wants to perform
> "checkout <other-commit>" needs to do exactly the above.  It is a
> bit surprising and disappointing that this topic needs to *invent*
> its own helper function and carry it as a file-scope static.

It certainly is. We basically have this whole dance in ~8 different
locations by now, and given the verbosity that is required for the whole
setup it's a good hint that the interface is not exactly great.

One of the functions that we might be able to reuse is `reset_head()`...
goes down the rabbit hole... ugh, this is turning out to be somewhat
painful. I'll send a v2 that does the whole exercise, but I'm not a 100%
convinced it's the right thing to do. There's various assumptions that
we have to break:

  - It assumes that the index is always clean.

  - We don't have a dry-run mode.

  - We need to stop it from updating any refs.

  - We need to introduce another field to let the caller decide which
    commit we're moving from.

So I'm 7 commits deep now adapting the function to our needs. But maybe
the end result is ultimately worth it...? We'll see.

Patrick

  reply	other threads:[~2026-06-03 10:06 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-01 15:36 [PATCH 0/2] builtin/history: introduce "drop" subcommand Patrick Steinhardt
2026-06-01 15:36 ` [PATCH 1/2] builtin/history: split handling of ref updates into two phases Patrick Steinhardt
2026-06-01 15:36 ` [PATCH 2/2] builtin/history: implement "drop" subcommand Patrick Steinhardt
2026-06-01 23:43   ` Junio C Hamano
2026-06-03 10:06     ` Patrick Steinhardt [this message]
2026-06-02  7:31   ` Pablo Sabater
2026-06-03 10:06     ` Patrick Steinhardt
2026-06-03 16:13 ` [PATCH v2 0/9] builtin/history: introduce " Patrick Steinhardt
2026-06-03 16:14   ` [PATCH v2 1/9] read-cache: split out function to drop unmerged entries to stage 0 Patrick Steinhardt
2026-06-03 16:14   ` [PATCH v2 2/9] reset: drop `USE_THE_REPOSITORY_VARIABLE` Patrick Steinhardt
2026-06-03 16:14   ` [PATCH v2 3/9] reset: modernize flags passed to `reset_head()` Patrick Steinhardt
2026-06-03 18:01     ` Kristoffer Haugsbakk
2026-06-03 16:14   ` [PATCH v2 4/9] reset: introduce dry-run mode Patrick Steinhardt
2026-06-03 18:18     ` Kristoffer Haugsbakk
2026-06-03 23:49     ` Junio C Hamano
2026-06-03 16:14   ` [PATCH v2 5/9] reset: introduce ability to skip reference updates Patrick Steinhardt
2026-06-03 23:51     ` Junio C Hamano
2026-06-04  9:01       ` Patrick Steinhardt
2026-06-03 16:14   ` [PATCH v2 6/9] reset: allow the caller to specify the current HEAD object Patrick Steinhardt
2026-06-03 16:14   ` [PATCH v2 7/9] reset: stop assuming that the caller passes in a clean index Patrick Steinhardt
2026-06-03 16:14   ` [PATCH v2 8/9] builtin/history: split handling of ref updates into two phases Patrick Steinhardt
2026-06-03 16:14   ` [PATCH v2 9/9] builtin/history: implement "drop" subcommand Patrick Steinhardt
2026-06-03 19:04     ` Kristoffer Haugsbakk
2026-06-04  9:02       ` Patrick Steinhardt
2026-06-03 23:58     ` Junio C Hamano
2026-06-04  9:02       ` Patrick Steinhardt

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=ah_8s1Q1Kg0dgw6a@pks.im \
    --to=ps@pks$(echo .)im \
    --cc=git@vger$(echo .)kernel.org \
    --cc=gitster@pobox$(echo .)com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox