From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=202.12.124.147 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796131096; b=A/FU4wvKFWOBMkGy5ib0I+hafBhsAMeYOh5Uf3QbNw3xj+wyR5HaAZfA9r8WeEFgu7cH pPV751bZBDcH3c16I74wjZKuBBF9OME83r9r1zpBtbfLqFFRWiM50ECHg9qUSriBnox1z rDwUWeMHXvknMHD1aMn5GDIBStQQ1YAMH1ZgcaEGcV8lswcVsxxQRhsijGF+7MGbvfhnY NQw5Z2WxJVdSSHaDvptfeGKx+wuxnkZxlSIjbG5E7lLSyOddP1Uqg+jFjBYGyokjsKJVu 6EvVJt3PgY/TWxwejqiR54QgNe2IyUo6nSo69SVmBFjTDHFSKq7sAeIkZydcfaez9CA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796131096; h=DMARC-Filter:Received:Received:DKIM-Signature:DKIM-Signature: X-DKIM2-Info:DKIM2-Signature:X-DKIM2-Info:Message-Instance: X-ME-Sender:X-ME-Received:X-ME-Proxy-Cause:X-ME-Proxy:Feedback-ID: Received:Received:Date:From:To:Cc:Subject:Message-ID:References: MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=PX/MIh7QIQpSHXD6HCWO9j6zg7SLCT8yM3dWf/ojM7A=; b=PlJBipQ87MuDVc60IuSYxpJaAgA6MIhq5iVE2RWUo1jnx0NQfhDl82aX7/UVou16Bz+a UDa+2XEkOBwi7cRIfgLaTgoNhkkxFgKR4s9aAuEOFE+JNh9nmukQcHvIOY1e3JAVFJ67n nk0MWaAiSpWI5sABwK3otsRiG+jTjjnkLMlXZR//r75wKOWncf9VnqXp/fehrIWZzOMiX p3U8TXqB+fU3EzwsajwcnTxmiJVE3tEapZbo+2dXZqj83s7NY0XgC8dkQEIvPwML4z8vM 0YMqr0zxrB6DP79r8zdgtinxt5wLjYBRW/hF8VWiQnp2zHfYXbgJQ1/yQ5b16odtO0g== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass header.d=pks.im header.i=@pks.im header.a=rsa-sha256 header.s=fm3 header.b=CrCSakWL; dkim=pass header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm3 header.b=nplY35Ju; arc=none smtp.remote-ip=202.12.124.147 Received: from fout-b4-smtp.messagingengine.com (fout-b4-smtp.messagingengine.com [202.12.124.147]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7FD6A606A31A for ; Tue, 1 Dec 2026 13:18:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 7FD6A606A31A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=pks.im header.i=@pks.im header.a=rsa-sha256 header.s=fm3 header.b=CrCSakWL; dkim=pass (2048-bit key, unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm3 header.b=nplY35Ju Received: from phl-compute-04.internal (phl-compute-04.internal [10.202.2.44]) by mailfout.stl.internal (Postfix) with ESMTP id C2C3F1D003E7 for ; Tue, 1 Dec 2026 08:18:14 -0500 (EST) Received: from phl-frontend-03 ([10.202.2.162]) by phl-compute-04.internal (MEProxy); Tue, 01 Dec 2026 08:18:14 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1796131094; x=1796217494; bh=PX/MIh7QIQ pSHXD6HCWO9j6zg7SLCT8yM3dWf/ojM7A=; b=CrCSakWLEky/BTQSPxqz9ELvtQ l6Q9GXKTnPPQUGvSAJnyTfBNylDfrTmyDHwEEKJntqvtko4USMDZ+eJtCHaaOXPl zYjHZs/ysqZPA/lCIK7Cy/sr6YjDCkLWWSe6wCBuh+vRUmMCLYSCKMjAUJvPixsM ehZj2tB/m0maFZErTXTythkVPMSGGVXlSzP4d+0EDwqIPCVK9tfJYwRJe1Btirou uqnPxrIYSec+aT2hj383T3aVx8BAxRr1um+uxCtXyPk3F6UbhOw3unsA4D3fwuYl BWXaU7nCvvBP9JTWt8cq8HKPvY2AtRMWTpLM6dTwk0DPUg88c4+011dqD6xQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t= 1796131094; x=1796217494; bh=PX/MIh7QIQpSHXD6HCWO9j6zg7SLCT8yM3d Wf/ojM7A=; b=nplY35JuHVjJGJCGzTRRxcbb3XrVcxYxgPAgNjLmCOcpsMob+nD ZaTdSW0dVeCGSuoWdvwdB98HmDIwf5ulWvj/J4uoQz2QGMkkL0DKplGS3YCGJ4XQ bCVBw6l7xqSsNyo2LMwoBTSPe5p6y28FkTEA4f/v4wJEenkrBcp3RnvhKBi9fp9G M6pmAj6xePfv4WPV3QmqNgEuRAYWZOcevkbCuFbbXGAw2FihFZ1laBARztKP+RDh ZgS+0zJvfqUmkFbY/gsp8/FCOnzwzRA8/+eFiLuXaNkgODBvDJPMZQlVAvCFQf7V O39NX5rKnjhXfwY3rcs+i+RudNblk79Vk/Q== X-DKIM2-Info: draft=ietf-dkim-dkim2-spec-09; repo=github.com/dkim2wg/interop; date=2026-11-03; sw=lmtpprox; action=sign d=pks.im a=rsa-sha256; DKIM2-Signature: i=1; m=1; t=1796131094; d=pks.im; mf=PHBzQHBrcy5pbT4=; rt=PGdpdEB2Z2VyLmtlcm5lbC5vcmc+; s=fm3:rsa-sha256:B9hu/wMdWyAtAvW/JmDSm0OciCG+7Mp8k+t25XFQbYBxCC7 lrhZxjGdVN2AcLRaAxKPrznvCGnbidebIgj4sCW5QVpKcM+pe6gLaGU2b0rN8T+R AAV7Xf6dbv69fl1wCOsm/hUOvHI5OQIjHcpLWWXrWwogp3MV2cdqO0VzAjiPqFGA ilzM2b9DRT3p+fOOXTNX1JoNbgC/6FTDu2Jdy4zUauex2HXFOeXiJ9uLPNDd+/3v XMmlHjADT0oAjfzkjwhFPjvfrN3k2VMH1RwCfq1S4dEqgaTjtLexJdymvOHRK9E7 EQymErjr3vUVbA5RlTbdP49cdjXArv8xbtJPD1g==; X-DKIM2-Info: draft=ietf-dkim-dkim2-spec-09; repo=github.com/dkim2wg/interop; date=2026-11-03; sw=lmtpprox; action=mi-m=1; hc=12; hn=cc,content-disposition,content-type,date,feedback-id,from, in-reply-to,message-id,mime-version,references,subject,to; Message-Instance: m=1; h=sha256:1OC1WY89qwM7oc4GXPDtdPs00EtVFNw0A82YvKvkcuQ=:lo1V6wF0UF90c38jZqeisUZF29iHRyF7TxEiBKqf/1s=; X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: dmFkZTFy+vqyIupLnhso3URJGwDjPg5oJkw7eWDqEeFjPjCA079msS53Hz7H+jp+8SUXiv kgNR64fAj9UAfZu0aiq9taAxvoKTpE1rfJqNIxnBrZkNYtJtHx0MSHaTAsroPbM+TWq2/q PlI4SALX8BwkuDnPE+raYWAl4UwjivkQqXFu5TTAgDZrjkh/7KpI69fVrrAXjMyeCpE6j2 EVigTZ/qb6ibzzF9qoGmbLEft30/swseetliWL7aRiCLmCpfrm1CPwnVj4JpfzdtwY1/7+ rDgjGXNzzTGn+QmPmWONntST84drw//DscJv2OfOIekLsvSbPWn0TOycxUBUvDOBxtiMGo UMQD5ilZzQ2y9Htp6jSlKeV5n4xT+6IhJRKsrCFTVpbZKPmThiaT2fPy/6XeyB5FgZHTxy iPsCNvqPqaXtgN1nMbD7auISfCE1iA3XlTEr650tfqPECh3DeFJI6azbyRn1woBCaGDpJb t9xfDvSKgeYUrP3LuoRL3SWfDbQjCqULMKZid90vVdt6J1OeA3zvBK1F1R9pUybp1xu+0G IaRsHP63aIJthVrTny2KgsxHUhlAqZL2qEKdl4x2QtEBk/KqsY3r7KwJfWKQ/g2ft+3SFG MDq0pLvmFib0HNL515LVsMZUVp0nji0hefRuIhi6jp4uR+AdBZcJgYygqzYg X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 1 Dec 2026 08:18:13 -0500 (EST) Received: by mail (OpenSMTPD) with ESMTPSA id 112ae557 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 1 Dec 2026 13:18:10 +0000 (UTC) Date: Tue, 1 Dec 2026 14:18:08 +0100 From: Patrick Steinhardt To: Aniket Gupta Cc: git@vger.kernel.org, Toon Claes , Junio C Hamano , Phillip Wood , Nikita Bobko Subject: Re: [PATCH v2] history: refuse to rewrite branches used by other worktrees Message-ID: References: <20261123103911.98860-1-aniketgupta3001@gmail.com> <20261127173252.7794-1-aniketgupta3001@gmail.com> X-Mailing-List: git@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20261127173252.7794-1-aniketgupta3001@gmail.com> On Fri, Nov 27, 2026 at 11:02:52PM +0530, Aniket Gupta wrote: > diff --git a/builtin/history.c b/builtin/history.c > index 43ba76f5a1..d0a3287c1d 100644 > --- a/builtin/history.c > +++ b/builtin/history.c What follows is a bunch of additional logic to verify whether we'd end up rewriting any commit that is checked out anywhere. Would it make sense to maybe split this up into a sequence of commits, where each of the commits introduces one such new check? This is not necessarily a blocking comment, especially not in the case where this change may already be good enough. > @@ -260,15 +263,100 @@ static int parse_ref_action(const struct option *opt, const char *value, int uns > return 0; > } > > -static int revwalk_contains_merges(struct repository *repo, > - const struct strvec *revwalk_args) > +/* > + * Return the path of the worktree that uses "refname", if rewriting it would > + * leave the index and working tree of that worktree behind. The branch that > + * the current worktree has checked out is fine, unless another worktree has > + * it checked out as well. > + */ > +static char *branch_used_elsewhere(struct repository *repo, > + const char *refname, > + const char *head_target) > +{ > + char *path = NULL; > + > + if (head_target && !strcmp(refname, head_target)) { > + struct worktree **worktrees = get_worktrees(repo); > + > + for (int i = 0; worktrees[i]; i++) { s/int/size_t/ > + if (!worktrees[i]->is_current && > + is_shared_symref(worktrees[i], "HEAD", refname)) { This function name confused me quite a bit at first. What the function does is to check whether the given refname belongs to the worktree, which makes sense I guess. But it also checks whether this worktree is currently in the process of being rebased or bisected: if (wt->is_detached && !strcmp(symref, "HEAD")) { if (is_worktree_being_rebased(wt, target)) return 1; if (is_worktree_being_bisected(wt, target)) return 1; } So doesn't this make `rebase_in_progress()` obsolete, at least for worktrees other than the current one? What this function doesn't check is whether any of the worktrees is detached on a specific commit ID that we'd end up rewriting. But I think that's actually intentional, as it doesn't really matter for our usecase of git-history(1). > + path = xstrdup(worktrees[i]->path); > + break; > + } > + } > + free_worktrees(worktrees); > + } else { > + const char *checked_out = branch_checked_out(refname); > + > + if (checked_out) > + path = xstrdup(checked_out); > + } I'm probably missing something, but the way we handle `head_target` seems weird to me. It is getting resolved to whatever we have checked out in the current worktree. But do we even care about whether the currently checked out branch is used anywhere else? What I would have expected us to do is that we take the list of pending ref updates that we compute in `handle_reference_updates()` and verify that none of those refs that we're updating is checked out or being rebased/bisected. But as far as I can see, this check here comes before we have even computed those ref updates in the first place. So we're verifying the pre-rewrite state, not the state after already having performed the history rewrite where the ref updates are now pending. And consequently, I think we don't reject some updates that may happen in worktrees. But even if we detected all of them, we would now be racy as we should perform the validation at the point in time where we have already gathered expected old and new commit IDs for the ref updates, shouldn't we? I may be missing something very obvious, but I think as-is these checks are somewhat broken? Thanks! Patrick