Article View: linux.kernel.git
Article #4216Re: [PATCH v2] history: refuse to rewrite branches used by other worktrees
From: Aniket Gupta
Date: Tue, 01 Dec 2026 18:11
Date: Tue, 01 Dec 2026 18:11
66 lines
14009 bytes
14009 bytes
> 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?
Technical Details
Message-ID:
<20261201181153.88521-1-aniketgupta3001@gmail.com>Path:
mbox-mo1.pugleaf.net!news-lon.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!git+bounces-76812-linux-kernel-git=dewy.ruReferences:
<20261123103911.98860-1-aniketgupta3001@gmail.com> <20261127173252.7794-1-aniketgupta3001@gmail.com> <aw7I-t56lb5S1Z49@pks.im>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lon.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!git+bounces-76812-linux-kernel-git=dewy.ru
From: aniketgupta3001@gmail.com (Aniket Gupta)
Newsgroups: linux.kernel.git
Subject: Re: [PATCH v2] history: refuse to rewrite branches used by other worktrees
Date: Tue, 1 Dec 2026 23:41:53 +0530
Organization: Usenet Network
Message-ID: <20261201181153.88521-1-aniketgupta3001@gmail.com>
References: <20261123103911.98860-1-aniketgupta3001@gmail.com> <20261127173252.7794-1-aniketgupta3001@gmail.com> <aw7I-t56lb5S1Z49@pks.im>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
logging-data="1785084"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:sONk6LY8QOkzAZyk/FhBkmZi//M= sha256:A54X830kgpN9+j6QT6bO65+7kMku1JxgLiUZVNQwzZk=
sha1:J+L4pKL9CwyUw8m7wyn5iI0HIho= sha256:VpE3FS/WHoQqduH6X3YAMI6tNObQZPeTz82hCROjZRQ=
List-ID: <git.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
by mail.dewy.ru (Postfix) with ESMTP id 5BC14117453; Tue, 1 Dec 2026 21:12:16 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -1.949
X-Spam-Status: No, score=-1.949 tagged_above=-9999 required=6.31
tests=[DCC_CHECK=1.1, DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1,
DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.001,
FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249,
MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
header.d=gmail.com
X-Received: from mail.dewy.ru ([127.0.0.1])
by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
with ESMTP id mO-5tYROiuSH;
Tue, 1 Dec 2026 21:12:13 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=git+bounces-76812-linux-kernel-git=dewy.ru@vger.kernel.org; receiver=<UNKNOWN>
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=gmail.com
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
by mail.dewy.ru (Postfix) with ESMTPS id 0B73A117421; Tue, 1 Dec 2026 21:12:05 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
by sea.lore.kernel.org (Postfix) with ESMTP id 6A16F29746; Tue, 1 Dec 2026 18:12:02 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
t=1796148722;
b=lePZIcZcLNnS/DnkYxVZseaHuhZDkFkoAABEB2+W6eebGbn0io5fGGKOGUVl5mUK232R
GoAtZjXNUI1xDvJMewNo9jybaA7tGlTFQLsnPDpilwYX7M/R6T7b/VLdXlq20sfJ2yijJ
mZ2CGDEfNhaEeGoX3UdWhgACk4gTi8WWImqYsw95GxFVMhH7GdrAdJc0yNEU0/6ePhtAR
PbQKMlvdbbw7kPtaEAA54JrAJJh9X7jD7zc+3hqjmXQRENYg5GgSbQ1Q8GWPFUBz5+F10
X1RjziCzdmFJGkDwDuHOUPLC+6C25n14FTVQzEPJb8HJlg1tBUanEqckJDsdnrrLXRQ==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1796148722;
h=X-Original-To:Received: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:X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
List-Unsubscribe:List-Owner:Precedence:MIME-Version:
Content-Transfer-Encoding;
bh=JsRUd9RJXKn5YClbKDSPiOG6SMxe33EukwNFaUG+zsg=;
b=g8sNK2Zn0dKnpqK3JtZ3T623YSLDuNmGBCusL/lfQSnuCrBLAbwYJ2lxrMN05oEgnI0o
Knx2w6RB9rwsztOdf5oc0hKITiSGp0Ux3pZUaqkp1YMd1RukAgcVduzPK0gFtDwPlvqbj
Wk/+Wb4VHtX0Ic8q8t0a5P8cjZJFuRn4hroHGdx6xBiTbbDS4R0kwlTAMh6LPq4zlBYD3
he8B7jIT2w7LBTy9X1IzcFWWkMX0ltyXKf8yhsSLfd3pc+GLwZkJQgTWww1hfshNJuw7f
9y3lu+GFCXKjzum/5KwvgwgGHl2AR5HEe8aifGpUffyJy9PwcKXq28Pny3h0/Uqgz2w==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org;
dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=pTDrijCh;
dmarc=pass header.from=gmail.com;
spf=pass smtp.mailfrom=gmail.com;
arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
by smtp.subspace.kernel.org (Postfix) with ESMTP id 424D0606A32C;
Tue, 1 Dec 2026 18:12:02 +0000 (UTC)
X-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
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.214.179
X-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==
X-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==
X-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
X-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 <git@vger.kernel.org>; Tue, 1 Dec 2026 18:12:00 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 11B84606A31A
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com
X-Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-2f03eeda984so65969395ad.2
for <git@vger.kernel.org>; Tue, 01 Dec 2026 10:12:00 -0800 (PST)
X-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)
X-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)
X-Cc: git@vger.kernel.org,
Toon Claes <toon@iotcl.com>,
Junio C Hamano <gitster@pobox.com>,
phillip.wood@dunelm.org.uk,
Nikita Bobko <nikita@nbobko.com>
X-Mailer: git-send-email 2.54.0
X-In-Reply-To: <aw7I-t56lb5S1Z49@pks.im>
X-Mailing-List: git@vger.kernel.org
X-List-Post: <mailto:git@vger.kernel.org>
X-List-Help: <mailto:git+help@vger.kernel.org>
X-List-Subscribe: <mailto:git+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:git+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:git+owner@vger.kernel.org>
X-Precedence: list