🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.git
Article #543

Re: [PATCH] sequencer: don't clobber HEAD ref name in worktree lookup

#543
From: Junio C Hamano
Date: Wed, 14 Oct 2026 19:44
97 lines
13529 bytes
Andy Koppe <andy.koppe@gmail.com> writes:

> add_decorations_to_list() skips the branch that HEAD points to, because
> the rebase updates it anyway, as per aa37f3e1d89 (sequencer: ignore HEAD
> ref under --update-refs, 2022-07-19).
>
> However, it keeps the name of that branch in the static buffer returned
> by refs_resolve_ref_unsafe(). If another branch on the same commit is
> checked out in a different worktree, branch_checked_out() overwrites
> that buffer. If the current branch comes after the other branch in the
> list of decorations, it gets a "checked out" comment in the todo list
> instead of being skipped, and the branch whose name ended up in the
> buffer is skipped in its place.

So obviously broken original, so cleanly corrected.  I very much
like it.

Will queue.  thanks.

>
> Decorations are processed in reverse alphabetical order, so this depends
> on the branch names. The test added in 94304b9f48e (sequencer: comment
> checked-out branch properly, 2024-11-25) happens to trigger the problem
> and expects its result.
>
> Fix it by using refs_resolve_refdup(), correct that test's expectation,
> and add a test with checked-out branches sorting both before and after
> the current branch.
>
> Signed-off-by: Andy Koppe <andy.koppe@gmail.com>
> ---
>  sequencer.c       | 11 ++++++-----
>  t/t3400-rebase.sh | 21 ++++++++++++++++++++-
>  2 files changed, 26 insertions(+), 6 deletions(-)
>
> diff --git a/sequencer.c b/sequencer.c
> index 6dae43e4db..c672b6e127 100644
> --- a/sequencer.c
> +++ b/sequencer.c
> @@ -6577,11 +6577,11 @@ static int add_decorations_to_list(const struct commit *commit,
>  				   struct todo_add_branch_context *ctx)
>  {
>  	const struct name_decoration *decoration = get_name_decoration(&commit->object);
> -	const char *head_ref = refs_resolve_ref_unsafe(get_main_ref_store(the_repository),
> -						       "HEAD",
> -						       RESOLVE_REF_READING,
> -						       NULL,
> -						       NULL);
> +	char *head_ref = refs_resolve_refdup(get_main_ref_store(the_repository),
> +					     "HEAD",
> +					     RESOLVE_REF_READING,
> +					     NULL,
> +					     NULL);
>  
>  	while (decoration) {
>  		struct todo_item *item;
> @@ -6633,6 +6633,7 @@ static int add_decorations_to_list(const struct commit *commit,
>  		decoration = decoration->next;
>  	}
>  
> +	free(head_ref);
>  	return 0;
>  }
>  
> diff --git a/t/t3400-rebase.sh b/t/t3400-rebase.sh
> index accaaba4d4..0e7ef33eb1 100755
> --- a/t/t3400-rebase.sh
> +++ b/t/t3400-rebase.sh
> @@ -483,7 +483,26 @@ test_expect_success 'git rebase --update-ref with core.commentChar and branch on
>  	GIT_SEQUENCE_EDITOR="cat >actual" git -c core.commentChar=% \
>  		 rebase -i --update-refs base &&
>  	test_grep "% Ref refs/heads/wt-topic checked out at" actual &&
> -	test_grep "% Ref refs/heads/topic2 checked out at" actual
> +	test_grep ! "Ref refs/heads/topic2" actual
> +'
> +
> +test_expect_success 'git rebase --update-refs ignores current branch with branches on worktrees' '
> +	test_when_finished git branch -D base current a-topic z-topic &&
> +	test_when_finished git checkout main &&
> +	test_when_finished git worktree remove z-topic &&
> +	test_when_finished git worktree remove a-topic &&
> +	git checkout -b base main &&
> +	git checkout -b current &&
> +	test_commit msg4 &&
> +	git worktree add a-topic &&
> +	git worktree add z-topic &&
> +	git checkout base &&
> +	test_commit msg5 &&
> +	git checkout current &&
> +	GIT_SEQUENCE_EDITOR="cat >actual" git rebase -i --update-refs base &&
> +	test_grep "# Ref refs/heads/a-topic checked out at" actual &&
> +	test_grep "# Ref refs/heads/z-topic checked out at" actual &&
> +	test_grep ! "refs/heads/current" actual
>  '
>  
>  test_done
Technical Details
Message-ID: <xmqqik34qd6s.fsf@gitster.g>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer05.iad!feed-me.highwinds-media.com!peer04.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!nntp.comgw.net!eternal-september.org!feeder.eternal-september.org!usenet.network!.POSTED!vger.kernel.org!git+bounces-72055-linux-kernel-git=dewy.ru
References: <20261014165824.2214234-1-andy.koppe@gmail.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer05.iad!feed-me.highwinds-media.com!peer04.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!nntp.comgw.net!eternal-september.org!feeder.eternal-september.org!usenet.network!.POSTED!vger.kernel.org!git+bounces-72055-linux-kernel-git=dewy.ru
From: gitster@pobox.com (Junio C Hamano)
Newsgroups: linux.kernel.git
Subject: Re: [PATCH] sequencer: don't clobber HEAD ref name in worktree lookup
Date: Wed, 14 Oct 2026 12:44:59 -0700
Organization: Usenet Network
Message-ID: <xmqqik34qd6s.fsf@gitster.g>
References: <20261014165824.2214234-1-andy.koppe@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: usenet.network;
	logging-data="2375271"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:l2N8rG0YWBkasPF+rVlc0XlrNP4= sha256:4PC3Ot4Ez1nlSDz2q/KPU1R+q+rk5yGW+qVRG9q2hIQ=
	sha1:ZXDOQj3gaWTB6LKHe03PuMc738A= sha256:wy+mbK7626Plxwz2YQWNXRNXN8GE3+OBxsgmQKZPpow=
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 0F4FB1101C4; Wed, 14 Oct 2026 22:46:02 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -0.75
X-Spam-Status: No, score=-0.75 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
	DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.25,
	MAILING_LIST_MULTI=-1, 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=pobox.com header.b=J7JAjlO5; dkim=pass (2048-bit key)
	header.d=messagingengine.com header.b=wOlTZAbC
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 0uJWuxlG6Fvb;
	Wed, 14 Oct 2026 22:45:58 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=git+bounces-72055-linux-kernel-git=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=pobox.com
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id 8B1CA1101C1; Wed, 14 Oct 2026 22:45:43 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.90.174.1])
	by sea.lore.kernel.org (Postfix) with ESMTP id 0364C33CEC; Wed, 14 Oct 2026 19:45:05 +0000 (UTC)
X-Received: from localhost.localdomain (localhost.localdomain [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id D4F29568531;
	Wed, 14 Oct 2026 19:45:04 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=pobox.com header.i=@pobox.com header.b="J7JAjlO5";
	dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="wOlTZAbC"
X-Received: from fout-a8-smtp.messagingengine.com (fout-a8-smtp.messagingengine.com [103.168.172.151])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2DAC04749F6
	for <git@vger.kernel.org>; Wed, 14 Oct 2026 19:45:01 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.151
X-ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1792007103; cv=none; b=KIOl/QETUHlwBpfz9T5N7fl2YQDED3UUA9iOagzw8lcEPjQzUrBx2MOK87qW8mdjQY6fjQiDIhKd3hqaRewMS/hmo0qiBlRn705GphrbwVQ4iRDGRd6DJykCHhx7yDPdwB3edpWHHeLNK03BTxKXNy692X1Uj1P/p+bnE0EFwI4=
X-ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1792007103; c=relaxed/simple;
	bh=3HqzPbLXg0XAZHk7B3rBHy/T9g028Ue6KRJCgJA74N8=;
	h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID:
	 MIME-Version:Content-Type; b=kTx5l3to1QQnedr+gbjLSDiqOTO9ZdA8xkcy1oSmOBuH06SNk7ZMGXDbKnFWNejWyeYWk8bJjBCYcLMTRyzXJgZOrd0J0UUWqE2lxXImoLJMYnInqOx/s/0qs3+ClOMG8dlvxU0wiTgVLqU1zAa1Ym3pbm3TDLZeYtiZwZDLUlw=
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=pobox.com; spf=pass smtp.mailfrom=pobox.com; dkim=pass (2048-bit key) header.d=pobox.com header.i=@pobox.com header.b=J7JAjlO5; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=wOlTZAbC; arc=none smtp.client-ip=103.168.172.151
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=pobox.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pobox.com
X-Received: from phl-compute-03.internal (phl-compute-03.internal [10.202.2.43])
	by mailfout.phl.internal (Postfix) with ESMTP id 4EF1DEC049C
	for <git@vger.kernel.org>; Wed, 14 Oct 2026 15:45:01 -0400 (EDT)
X-Received: from phl-frontend-01 ([10.202.2.160])
  by phl-compute-03.internal (MEProxy); Wed, 14 Oct 2026 15:45:01 -0400
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pobox.com; 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=fm1; t=1792007101; x=1792093501; bh=1ROz1h7Lr4
	oQViFaVHce7kC4QED6CdahhyfWSusifks=; b=J7JAjlO5bzbXOtX8OAXRcJOP2Q
	DIrILC34MQPKJZYWHLg7ryQmiyjF7+QvmBix6aR0UGEh+KynOqSz6swKaWxoJhF7
	r3TNf4zHPDfAVBeRlAUkfAqDPaNlOjYSirXdlwkY7rSW4OMOXwSaHu6cu7uKzTUk
	7ylLFIjp9jz9mUvgt8RXp3RbShayIJ9rtMxxXXO5XEzduZQlghB3vmCpcTwrI8Wo
	GRv/lfmjt3E/smIL9Ehrqxa7fElS2uRbrCefOVTIz7a25hXZQph1frmzjTp+0SDH
	HYbUY/6PjrWcUiwP1644APYkHZ0bUcVtHbYVAHeN9nAQfN6iXdBAY7koGmUg==
X-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=fm2; t=
	1792007101; x=1792093501; bh=1ROz1h7Lr4oQViFaVHce7kC4QED6Cdahhyf
	WSusifks=; b=wOlTZAbCEvdqBzU9vQZ9fGxyEdvtBYmfB4GlHj4vhXFshOPxIJv
	dGvp7ZQKBPb/c8Sc4KsSzmYfwv0JMMsdCbH5dvrR+xSHgNZcqx+z8J4xUmN0SCG+
	KNXMN9ujAbob0u5qOUi0PXzFwgmCq/BB0AdyXPiMN43QD4V4Hwp+CYlXf/OfSNqh
	Bw6luSFJBBX7RhdFBsJ5ZRZ0FKxf9ElgoIjpyDHFxkLbYYUVpARrMoNlNpTmJ9Dg
	O9PkdjVRNoM5K/9bxcR29qRHJ1D01/+JsZFVlCKnrgTroAXYmUDt3XOXaWoJlm25
	Ww1aQOm7FDEikn1gx8i8AglGqv0MAJy6IVQ==
X-DKIM2-Info: draft=ietf-dkim-dkim2-spec-06;
	repo=github.com/dkim2wg/interop; date=2026-10-04; sw=lmtpprox;
	action=sign d=pobox.com a=rsa-sha256;
X-DKIM2-Signature: i=1; m=1; t=1792007101; d=pobox.com;
	mf=PGdpdHN0ZXJAcG9ib3guY29tPg==;
	rt=PGdpdEB2Z2VyLmtlcm5lbC5vcmc+;
	s=fm1:rsa-sha256:ebpPzmj4hD6qGMgUf5qlvNzPXTeWLvT66NP4eiRmgShztoh
	vZ23g05gcLqo8wqr5ZQesDzrrfllMPaFPjfJhfu7/C/1NOXQ2nKqmdA4fd3ukUc9
	vK12N/2d4k6h4Q8jOPZ4GzwU4AyCBbI7l04/KptrHZKNRbEF9RTwlf29qCJ59DIc
	Pfms7ChxEE6M/g4g1/6OVct2R/jG/dIujKjxzVJjlu61nv/lEzmJfUKS7sBiV5dd
	2KNeUiPsYhXPv/8ftHt7F+NEwjWomiM4z1cB71XZyRPCm4zkVsUpffuCLyVTCrjj
	Id2DgsLGJY0JvgUefssfEPNgbCx9dzxp6WNDJvw==;
X-DKIM2-Info: draft=ietf-dkim-dkim2-spec-06;
	repo=github.com/dkim2wg/interop; date=2026-10-04; sw=lmtpprox;
	action=mi-m=1; hc=12;
	hn=cc,content-type,date,feedback-id,from,in-reply-to,message-id,
	mime-version,references,subject,to,user-agent;
X-Message-Instance: m=1; h=sha256:2hwETmFg1C07KXmCDbQHNCsgeknLqSm/z3V7eHyrpaE=:3HqzPbLXg0XAZHk7B3rBHy/T9g028Ue6KRJCgJA74N8=;
X-ME-Sender: <xms:vNvPagjH1XHGnbzkUaACH1fcrzZo4TlQf9bwHK14Vxx-zqM8RL9KV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fQMBYNaXVR45jv6P9v_FngX5x6uFu3Q>
    <xmx:vNvPalco0ynqjrEAwr8avOfNerPJkVmBRsmmpVytHHnIuLAGcY1Y3Q>
    <xmx:vNvParqxHXAvutmZkWDTRQcQdjF01q3roM-z56S1qPCRz_ED_hbdDg>
    <xmx:vdvPasXBm0rTdS5fjhq66TD652Nz7GW6kibmR7QBU103dpbDTA3ZGln2>
X-Feedback-ID: if26b431b:Fastmail
X-Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed,
 14 Oct 2026 15:45:00 -0400 (EDT)
X-Cc: git@vger.kernel.org,  Kristoffer Haugsbakk <code@khaugsbakk.name>,
  Phillip Wood <phillip.wood@dunelm.org.uk>
X-In-Reply-To: <20261014165824.2214234-1-andy.koppe@gmail.com> (Andy Koppe's
	message of "Wed, 14 Oct 2026 17:58:24 +0100")
X-User-Agent: Gnus/5.13 (Gnus v5.13)
X-Precedence: bulk
X-Mailing-List: git@vger.kernel.org
X-List-Subscribe: <mailto:git+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:git+unsubscribe@vger.kernel.org>
X-Received-Bytes: 13327