Article View: linux.kernel.git
Article #3880Re: [PATCH v5 1/6] notes: add notes_tree_or_default()
From: Junio C Hamano
Date: Thu, 26 Nov 2026 02:57
Date: Thu, 26 Nov 2026 02:57
48 lines
14196 bytes
14196 bytes
Okhuomon Ajayi <okhuomonajayi54@gmail.com> writes:
> Several notes entry points repeat the same check: a NULL tree
> means the default notes tree, and the tree must already be
> initialized.
>
> Use one helper for that check. notes_tree_init() asserts that
> the tree is not yet initialized, free_notes() only frees what is
> there, and format_note() initializes the tree when it is not, so
> those three keep their own checks.
At this point in the series, the initialization function is still called
init_notes(), as the rename to notes_tree_init() happens in the next
patch.
> diff --git a/notes.c b/notes.c
> index ec9c2cb150..a73a51e1a0 100644
> --- a/notes.c
> +++ b/notes.c
> @@ -1140,14 +1140,20 @@ void load_display_notes(struct display_notes_opt *opt)
> string_list_clear(&display_notes_refs, 0);
> }
>
> +static struct notes_tree *notes_tree_or_default(struct notes_tree *t)
> +{
> + if (!t)
> + t = &default_notes_tree;
> + assert(t->initialized);
> + return t;
> +}
> +
> int add_note(struct notes_tree *t, const struct object_id *object_oid,
> const struct object_id *note_oid, combine_notes_fn combine_notes)
> {
> struct leaf_node *l;
>
> - if (!t)
> - t = &default_notes_tree;
> - assert(t->initialized);
> + t = notes_tree_or_default(t);
I somehow thought you would leave assert() outside the helper, which
might give us a better abstraction in the longer term, but I do not mind
either way.
As a way to prepare for making copy_note() safer in a later step,
keeping this step a pure refactoring makes sense.
Technical Details
Message-ID:
<xmqqh5h4s3j1.fsf@gitster.g>Path:
mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.endofthelinebbs.com!usenet.network!.POSTED!vger.kernel.org!git+bounces-76417-linux-kernel-git=dewy.ruReferences:
<20261124172146.18330-1-okhuomonajayi54@gmail.com> <20261125220214.35881-1-okhuomonajayi54@gmail.com> <20261125220214.35881-2-okhuomonajayi54@gmail.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.endofthelinebbs.com!usenet.network!.POSTED!vger.kernel.org!git+bounces-76417-linux-kernel-git=dewy.ru
From: gitster@pobox.com (Junio C Hamano)
Newsgroups: linux.kernel.git
Subject: Re: [PATCH v5 1/6] notes: add notes_tree_or_default()
Date: Wed, 25 Nov 2026 18:57:38 -0800
Organization: Usenet Network
Message-ID: <xmqqh5h4s3j1.fsf@gitster.g>
References: <20261124172146.18330-1-okhuomonajayi54@gmail.com>
<20261125220214.35881-1-okhuomonajayi54@gmail.com>
<20261125220214.35881-2-okhuomonajayi54@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: usenet.network;
logging-data="366136"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:tW4DtxHskmlbJWbiF21gE8aDmRM= sha256:jiv1jrRnXuSsQHipM9mgevn4ycK1ejI/W1DCgLeGpog=
sha1:6RNSYDe0LUB129XfpcKrh4rZ6SI= sha256:tEJqQBHbwqWuv+NNl0orRJIw/uflnYowPC7KCukSHJQ=
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 3543C125EA3; Thu, 26 Nov 2026 05:58:04 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -1.95
X-Spam-Status: No, score=-1.95 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,
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,
URIBL_BLOCKED=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=LD+9GvHG; dkim=pass (2048-bit key)
header.d=messagingengine.com header.b=ycReuWsK
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 sBkULpQvNTue;
Thu, 26 Nov 2026 05:58:00 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=git+bounces-76417-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 tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
by mail.dewy.ru (Postfix) with ESMTPS id E4CA5125EAC; Thu, 26 Nov 2026 05:57:45 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
by tor.lore.kernel.org (Postfix) with ESMTP id 56EA42D72A; Thu, 26 Nov 2026 02:57:44 +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=1795661861;
b=JrAej4fIBqIlRkvAzXdHs++Mp0yt5/2SyqExyS8/Gl2UEancYSxWvyFrh7eMVZW2xXbG
S/HDD7TGWqJ2CbMdNfdyRs6qeYdzmR0vk8nS/iY+x0M+X5FxjbdivOudf+Zd1zFcCVg/Q
5Kle5tlzSfqwWMhVJqxoRVQwJrTG4ORXeRqcvkBbuw2EZWrsiQfWOnPgsxSWkskSwXyiA
PS876ZEn/WWNBZ9xkeR6bGdqWuHkfjF6zw6fI33xME5uPjqPTf+SSabZG94Ij0zckm08P
/7xwGyHJ1k0iYnFQN89VQgT4kvUkQL1uoQJJyucbfO//N1dScys5QRC9AKMKHbbaqJA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1795661861;
h=X-Original-To:Received: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:From:To:Cc:Subject:In-Reply-To:
References:Date:Message-ID:User-Agent:X-Mailing-List:List-Id:
List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
Precedence:MIME-Version:Content-Type;
bh=VhvOSTafLu/Dst5ospwRXnsCds2Xg+QCAlopEs1qifs=;
b=BCn78u9ylW0WS/sEk+Bl/iY1du5l69BQ2rDCr30zJSlWBmyDT9ZNwvqGkE35o5YVLYZw
y2kurtdRjG4AqP+aWKgtZXGaW5VMknK6K4jblBA91SkeO+O5RkC8M/3Bz1sBBe3vewkbz
J3bBejfLdcPdEq4DEZ/KRuP3fS1siYV/OTzwSevVZ+Eqh2xDeVZqlEP4JJ7tJIF4QIoO9
O+8O/4hwONgCXtW17VGmC3WPo9TA7uVY48+HNgrzlpCbQIU+cQYi2NIEW+P61nYQdg9I7
9PMM5bJP6P+58L6rB24LlQxTg0JMuidZRWNptjFb195TeKOTvU6BX0vpTHXjIn72bfg==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org;
dkim=pass header.d=pobox.com header.i=@pobox.com header.a=rsa-sha256 header.s=fm2 header.b=LD+9GvHG;
dkim=pass header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm3 header.b=ycReuWsK;
dmarc=pass header.from=pobox.com;
spf=pass smtp.mailfrom=pobox.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 D4B03606A32C;
Thu, 26 Nov 2026 02:57:41 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
dkim=pass (2048-bit key, unprotected) header.d=pobox.com header.i=@pobox.com header.a=rsa-sha256 header.s=fm2 header.b=LD+9GvHG;
dkim=pass (2048-bit key, unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm3 header.b=ycReuWsK
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=202.12.124.151
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
t=1795661861;
b=VaRyXpz6+nIutuiU3uUEecRTs1cA04D646Ren3ZsaCSjn7B0WQCOmXYHjCdG8GWJBJbZ
1Gm4I/ViycVUy4M3hK1rIFCG4XRfsoAeq7imRVj+qwUgurQw81VAPGJPl+ma4HXnQla0i
QWnd+LT7qYWkXVk98+Lqr7+P4wytA6jeWmVylGH8nZ1+jyOF9I4OJC3pG3YNBC8PsRI4V
J+9GsdMWW4zpz9uuscAHlLYr3PDAiORSL8tu8hlFk+RZyD4AyIOKy2MuMax/BxSrdVxF0
UO/ecn3WWkkUuLGzZvUtErbsQMBvwCv0O98Qf5s+5O7V93JHVQPrLDreLE6IJr3ig6A==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1795661861;
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:From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID:
User-Agent:MIME-Version:Content-Type;
bh=VhvOSTafLu/Dst5ospwRXnsCds2Xg+QCAlopEs1qifs=;
b=VpBSKLy1vXoQn+Jl3q3m7GQ7acU2GbZmIoAjvk4D4g6RSh4yXvvMdwFDFtmVt7zviRvN
UzPZ1NGVjWMTH/q0Vpw1dbJuE+Zb6SUx7BXETttlTXW8b1uAnw35PXdQkc//c0jAHILkZ
CwJ6uyt6t1uj/RGG54KTkT/iCVjhRo3j/mTNhIVOyYgVx692VNvhQmlFrwk6tqhczSPtb
GKOEzWvDXOt+XDfFXqRyE0Y5FXRhPK+7I9IBRjDiBs/wok/EE2003rRwQwZTYEdxS5ksx
yOpD9W/7LZTg5uM9P8TTLDxPcTgXsd9ZLbUcNjNZ6oOmEh5cxZBcSaeFYOYWKi73z6w==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org;
dmarc=pass header.from=pobox.com;
spf=pass smtp.mailfrom=pobox.com;
dkim=pass header.d=pobox.com header.i=@pobox.com header.a=rsa-sha256 header.s=fm2 header.b=LD+9GvHG;
dkim=pass header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm3 header.b=ycReuWsK;
arc=none smtp.remote-ip=202.12.124.151
X-Received: from fout-b8-smtp.messagingengine.com (fout-b8-smtp.messagingengine.com [202.12.124.151])
(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 9816F606A31E
for <git@vger.kernel.org>; Thu, 26 Nov 2026 02:57:40 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 9816F606A31E
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-10.internal (phl-compute-10.internal [10.202.2.50])
by mailfout.stl.internal (Postfix) with ESMTP id EF56A1D00554
for <git@vger.kernel.org>; Wed, 25 Nov 2026 21:57:39 -0500 (EST)
X-Received: from phl-frontend-02 ([10.202.2.161])
by phl-compute-10.internal (MEProxy); Wed, 25 Nov 2026 21:57:40 -0500
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=fm2; t=1795661859; x=1795748259; bh=VhvOSTafLu
/Dst5ospwRXnsCds2Xg+QCAlopEs1qifs=; b=LD+9GvHGVAUyhl4iAZxcV2/rU6
KpQ/OsrKs0KpIoorIKikedLdSClw5gTpd+VZR+YmuXTTp9FQLyIfMqb1D6lNtUYJ
R2R+kDPxH9TJ6IW0bMjPWxmm6U60TG8Wgw2THqkQTk0uHtOTr7ztAEaenMVfDFn7
gSYat2jokheTNiBaBwl7x32i7pEEoft/Y/X3WoeBO118vH3QLJgOLN2yfBtmNlQM
CjOXBLPo+kShKDVOuzveqw6SlE7a2FaKKSOXmDFSreceMhEORrB0gz925XnBCbPM
R3pN7utxITOkHrr2GXhuT5Pok+b3WQX0TBlW5/99q/Et4ZJYPYUMniq/Yd8A==
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=fm3; t=
1795661859; x=1795748259; bh=VhvOSTafLu/Dst5ospwRXnsCds2Xg+QCAlo
pEs1qifs=; b=ycReuWsK0FIU+QRnyjovvZtxHyP4EtHiUHpsvHE41c/oTeBl6Fi
KBBunqo7gaxQjnisy8CD5f1aRY+N6zYPa3oROVWIszJeKFLmsybZ3/eYjreWwGW9
En06tymaVevkxJ32MbCOJTQwxWYLaLTubEjSFLupJZFf7RkFdzGAmmQkK3hYPaJG
gxJ0JRmgksQ0nFhpntMHwY7fhHeTldcm+TU3K0FJ1nm0Sn0sNd9ImYvVN9xu6aQh
3YxZnXz8EAUdVS4EZbAYyrESFc0YvQDm9lYJagI+UJXHG92k2sUZBBH9/J0mj2aX
5slsInVHNnvouIgd+qkK69CQYAcmUwcBzgQ==
X-DKIM2-Info: draft=ietf-dkim-dkim2-spec-09;
repo=github.com/dkim2wg/interop; date=2026-11-03; sw=lmtpprox;
action=sign d=pobox.com a=rsa-sha256;
X-DKIM2-Signature: i=1; m=1; t=1795661859; d=pobox.com;
mf=PGdpdHN0ZXJAcG9ib3guY29tPg==;
rt=PGdpdEB2Z2VyLmtlcm5lbC5vcmc+;
s=fm2:rsa-sha256:Dzha9+E3C/2NqnTKigpOneKxuOfk18RpsZJIeAJX5zBeL1S
wdWvZHImECwehjKWi3iPE+3F0iX/tjBkWazorlO0X2mIgZKm5oHLxdYN+AANvLJy
B1Qc43gYD9CoUPgptt9xX/OUAFfr/tdjX6RzxET9XIb+7ouStlycEPY17Xe8pt+6
4N6UE2tXBez/wvVSORpR5GW6IXJh0iwfxGUVAerU/G6CWZ3sGdzyHoeSsQEOuOz/
Fbf720TJDfKn3tB8zzXhtCg6RbDWA0KyCHhi6airb9LvLlPnWiRDz5HMajDQ4OLj
dmwe+qpC/cgDJXPxVxBQUXfJN7R3txKe8CEr9uA==;
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-type,date,feedback-id,from,in-reply-to,message-id,
mime-version,references,subject,to,user-agent;
X-Message-Instance: m=1; h=sha256:QcwIdhepp/IneVAM+Mz7RDMMOjG697KXZQSdGokNxiE=:c+ZXJjDt0yWRQLexyK/lWDwS8bVnxisVkEUfxxCoKoM=;
X-ME-Sender: <xms:I6AHa-qtJjX1pInMGLOgtA-2pzxbTo5C7net84G81JVQKIEgO2K-5Q>
<xme:I6AHa7tD2S-QMfH0PAUDF2JoNcFvgbd5jsNdrcDSbROiH0XCbsx440xkp1fSMS2_s
2XVYlH9Ge2oh6dcFjfZE2JNXWalv2OPQLW1Z4m3Jgh-Uh4J82CpV9I>
X-ME-Received: <xmr:I6AHa5aWTMC2OTkNEHGmdSQZ0jo2R-JJWFx9jS1_4AcwZMe7JhaoR2TZlntQ6vOFKyDuXK9ySHAbJQ7BtnEmw24cmJkcYdEaTUkHjCw>
X-ME-Proxy-Cause: dmFkZTF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2026 21:57:39 -0500 (EST)
X-Cc: git@vger.kernel.org, christian.couder@gmail.com, ps@pks.im,
usmanakinyemi202@gmail.com, siddharthasthana31@gmail.com,
kaartic.sivaraam@gmail.com
X-In-Reply-To: <20261125220214.35881-2-okhuomonajayi54@gmail.com> (Okhuomon
Ajayi's message of "Wed, 25 Nov 2026 23:02:09 +0100")
X-User-Agent: Gnus/5.13 (Gnus v5.13)
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