From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.214.179 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796148721; b=P4DwkQgJft6RHar3D93xnHpi5Ypt3TE2czVaKWLwD2yhEZvsuLh9wXUaUEwAhwJljX/j q247D7yilOHJ0FwQXdK+tUTiAEVdUWNbZfhMjCP40HqsS5Gy9suDwWUezoRd1rhumq0Oq pw2haQ+MqGZndAVAOkib2HR9dXp2sfIXJA7eGkerQa1nxPXLVlLrWu8vH9oRAnrpmTRcK +9Gby8+UkCwiONBuGwyHByXmjfSKhTrPO0cqL8VrcRL406TGRlqCsWqdr2wNwBBXb9B6z /lcatZx8MN41JXcA9T0ckjz7qcdaFh+zWNgr9qLZhhIc+I1A4CkXRsGInITazIMbicQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796148721; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:To:Cc:Subject: Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=JsRUd9RJXKn5YClbKDSPiOG6SMxe33EukwNFaUG+zsg=; b=1BBlxAgqJ2KQE6J9afxpvqS6k1ynrEMU0xYzdjzMRHknPvUas/DMtqA6XSa/qmnfCdDh yw9Rg6f3gQ9NSFvbz/0kMEX5p/j+cE+Y1tydhnNw0MvOTaAT243fZiW+ZXwl+A4GMuFgC qN7XFXIjh4+8NK26zUNZyWwTSKngTIFsRbxj5sEEXxmyW3CmANGDcfi/ZEOmplwP4R95S Z/dof/kulPlE2l3QISJa9rGUgHq/S3DqMwdZ2xzEOp3yXEzIvbWvm39ton2zIuJmH68zd OjB2dvxmxtASEEdB2Ut8exHnNIBes/Qp4c7aT2lw9QI9zF7+VGzoKEwqDAIejjng2IQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=pTDrijCh; arc=none smtp.remote-ip=209.85.214.179 Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 11B84606A31A for ; Tue, 1 Dec 2026 18:12:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 11B84606A31A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=pTDrijCh Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-2f03eeda984so65969395ad.2 for ; Tue, 01 Dec 2026 10:12:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796148720; x=1796753520; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=JsRUd9RJXKn5YClbKDSPiOG6SMxe33EukwNFaUG+zsg=; b=pTDrijChiSR+MlfG+6VIQbfZVI+D1Y7wWmERIOeZPnWDs+qP7ex2t3Vlhz062dfVk5 HBnxkcsGxRvnm2rHNw4D5f6Jl32hb/RsoYcdOhF64M+jZzFBTPsGrAWSza5isn2HurSK PBRX8rgB/Q+RYFJ+LPPbjWyQ0OccZSlmXLpRvDSAk5ZknioV6TPYxDsJ1aJWJ70958QO 1KWDcibg+tRUlxuSuh9zTr1NKp+3LLHotfPE9ukUoBTW0pyOJsol7yzwxqwUJcb4cjCP CxaN881AVgkjuXw38K/UVjbclUkUS0XXWGZb+tjL2FCLxJRhqx+G5JESAe8WHa0Bb7Ft rH1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796148720; x=1796753520; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=JsRUd9RJXKn5YClbKDSPiOG6SMxe33EukwNFaUG+zsg=; b=vuKxzTxlAgS3N8r+8Qva0xGWPVRqGzwimPm1nLuhAf6FjlCih/GUkP568KWzMmACq/ ZRMetJoGPJavW96jXI7mB1WsZ96JUOOvOj2UH8jX5rpTALCaB4PYlQKFnXuG45UPmvhW iaFrxZmR0wz+72qxLBA6U+pXxTfDpHRh5he0/PLLMUkbUEXpTVcXOVEhgOeWVsU3ypvh wiUQUgvff60M8V2ckeTvvwM0k9u3Jty0wM40r7JYg4gmLBZVs8nRpkIcdaSbHyy5MaSK c50P+B0uK0lJtSJt1WBovOORAx3cC3InDm7qz4PM3HRCrmTVz/B8Q982Fa2MNjFuwiQD dbQw== X-Gm-Message-State: APuU4Z8CGJ/0pxtBxEZv2RGyiXDPPXcoJ6ZfOqzc7iIBJNQKEBGY2GXE lU5rqHvSLlzujUhAJpoBrDwCfL4xJ9M2RHyRt6Jt4cCUeiJOMTY7I1T5 X-Gm-Gg: AZFdTZdgveq2l0GZwbNQSxwDybZ9f8zd+niWwm6Y62uk8/zvr/sDg3hLz1ceBPEYxfj c9VBq/xxP7JJ9QevrHdbSrgdtUVK2AQaSavPV3scSbUYsAvaV3Yez4sIHQPKtYvYyIdCqL+6KrJ xNOWHS3vUYXzj8odpkayeqpgSeOD9ZQThT66vAj+h2MrKePWojkvt13m6XXORhLPwzx9SvWZCUt l2TlOPKWwghifxCql1nTtRFugWYkrQmEs96DZlXdVM0ThhSG4D5wGiMYqanr793Zk7Vt0y77pOi PWGk9DBafVVnUp2nV314jiJAmr3QTd+uUjppjUy1Wx5fKPDKcYRGVRo1dbj41tIBfazB3NM36dU 6HnMu1mjNiytIyP0iiZJIzK3v7lWgosC/K4+SN+VMwflIqTKxFqd4QxH9e9fa7GaWdg3Sio3I1n yhZfyNeZlu0aXrBIZynEkdgsxMbTXOEEKmNxWybcMRDLC95EoPdCktp27nwT46Ws8G8UBy1Sx1z ysoPjV3bgwm/UReCWuscmnLPYhFLPrGvbgMtmMNMP4JchzVzU1snse5f4P3PiFcdRxlGfCtmam9 MmApS5Wd236sMk925Ot/DjffddgPuo2CbDtQfHKaenVQJ6JUdigtZrioTHPrh2yVrtFtGiKaO0k lOv2VVlbcpWOt/+8ap2Y9IA== X-Received: by 2002:a17:903:32ce:b0:2ed:146c:cbad with SMTP id d9443c01a7336-2f03f17cdf9mr407759645ad.19.1796148719950; Tue, 01 Dec 2026 10:11:59 -0800 (PST) Received: from localhost.localdomain ([223.190.80.135]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2f070a12491sm164390435ad.8.2026.12.01.10.11.56 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 01 Dec 2026 10:11:59 -0800 (PST) From: Aniket Gupta To: Patrick Steinhardt Cc: git@vger.kernel.org, Toon Claes , Junio C Hamano , phillip.wood@dunelm.org.uk, Nikita Bobko Subject: Re: [PATCH v2] history: refuse to rewrite branches used by other worktrees Date: Tue, 1 Dec 2026 23:41:53 +0530 Message-ID: <20261201181153.88521-1-aniketgupta3001@gmail.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: 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-Transfer-Encoding: 8bit > 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? I feel that there are no separate checks left to split now, primarily because the branches that are checked out, rebased, bisected or going to be updated by "rebase --update-refs", all come from one list in branch.c, and history.c only has to check against it. A separate commit for the new function in branch.c would add a function that nothing uses yet, so maybe we can keep it as one patch? > s/int/size_t/ The check has moved to branch.c, so both worktree loops shall be gone in v3. > So doesn't this make `rebase_in_progress()` obsolete, at least for > worktrees other than the current one? I dont think so. It only looks at the current worktree, which is_shared_symref() skips. If the current worktree is rebasing a detached HEAD, there is no branch to refuse, so this function is what stops us from rewriting HEAD in the middle of it. Rebases of a branch in other worktrees will be covered by the list in branch.c in v3. > 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). It is intentional. I had tried a worktree that is detached on a rewritten commit: its HEAD stays where it was and its status is clean. > 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? Yup. As Phillip says, it is confusing if the HEAD of one worktree changes because a branch was rewritten from another. That is why head mode refuses the current branch when another worktree uses it. In v2, the current branch could still be rewritten while another worktree's "rebase --update-refs" was about to update it. > 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. Yes v2 missed the --update-refs case, and v3 will fix it. The refs we check are the same ones that get updated as both come from the same commits. We check early on purpose. If we waited, "reword" and the other commands would first ask for a message and only then refuse. > 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? This indeed is a gap. If a worktree starts using a branch while the history is being rewritten, for eg while the editor is open, we will not notice. I repro'd that with a "reword" editor that adds a worktree. Phillip sketched a way to close it with a file that records the refs being rewritten and that other worktrees and commands check. The checks seemed like a good first step. Maybe we can leave that for later?