Git development
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Okhuomon Ajayi <okhuomonajayi54@gmail.com>
Cc: git@vger.kernel.org,  christian.couder@gmail.com,  ps@pks.im,
	usmanakinyemi202@gmail.com,  siddharthasthana31@gmail.com,
	kaartic.sivaraam@gmail.com
Subject: Re: [PATCH v5 3/6] notes: use the tree's repository when reading notes
Date: Wed, 25 Nov 2026 19:37:38 -0800	[thread overview]
Message-ID: <xmqq4id4s1od.fsf@gitster.g> (raw)
In-Reply-To: <20261125220214.35881-4-okhuomonajayi54@gmail.com> (Okhuomon Ajayi's message of "Wed, 25 Nov 2026 23:02:11 +0100")

Okhuomon Ajayi <okhuomonajayi54@gmail.com> writes:

> note_tree_find(), add_non_note(), load_subtree(), remove_note()
> and format_note() already have the notes tree, but still read
> objects and hash algorithms from the_repository.
>
> Read them from t->repo, the repository stored on the tree.
>
> note_tree_find(), add_non_note() and load_subtree() do not check
> for a NULL tree themselves. add_note(), remove_note() and
> get_note() replace a NULL tree with the default notes tree and
> assert that it is initialized before those helpers run.
> format_note() does the same NULL swap, and initializes the tree
> if it is not already. load_subtree() is also reached when a
> lookup unpacks a subtree, which is still after that check.
> copy_note() is the one public function that does not do this;
> the next patch adds the guard.

"A, B, and C do not check for NULL, and D, E, and F do." may not be
stating any lies, but such a description gives a very disorganized
feeling, as readers are not directly told where you are going with
it.  Make it clear where the entry points are, who calls leaf
helpers that do not use notes_tree_or_default(), and state that
these callers themselves use notes_tree_or_default() to cope with a
NULL tree.  Before going there, step back a bit and give a wider
picture, i.e., have you done enough to make sure readers understand
why notes_tree_or_default() matters in the first place?

    In the previous step, we added a '.repo' member to a notes tree
    object so that you can tell which repository object you are
    working with.  The notes tree objects are passed around in
    various call chains, but many functions like note_tree_find() do
    not pay attention to '.repo' and instead use hardcoded
    the_repository.

    There is a catch in the existing API contract around notes tree
    objects.  Passing NULL in place of a notes tree object is
    allowed, and tells the API to "use the default notes tree
    object".  Which means a few things.

    - An existing call chain may pass notes tree 't' around, but it
      may be NULL.  You cannot blindly dereference 't->repo'.

    - High-level API entry points like add_note() may receive NULL
      in their 't' parameter, but they replace NULL with a pointer
      to the default notes tree object by calling
      notes_tree_or_default() upon entry, so after that, the use of
      't->repo' is (almost) always safe.

    - Helper functions that are only called from these API entry
      point functions may not check the NULL-ness of 't', but rely
      entirely on their callers to have turned NULL into the default
      notes tree object.

    Now, X, Y, and Z, as we saw in patch [1/6], are the high-level
    entry points that guarantee their notes tree pointer always
    points at a valid notes tree.  A, B, and C are helper functions
    that can be reached only from X, Y, and Z.  We can replace all
    uses of the_repository in these functions with '.repo' safely.

    There are some cases where such a replacement is not sufficient.
    For example, copy_note(), even though it takes a notes tree
    object, does not use 't' itself, so it does not bother calling
    notes_tree_or_default() to ensure that 't' is a valid notes tree
    object.  In order to replace its reference to the_repository
    with '.repo', we would need to do such and such things, which
    will be done in later steps.

or something like that, perhaps.

  reply	other threads:[~2026-11-26  3:37 UTC|newest]

Thread overview: 86+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-31 10:45 [Outreachy PATCH] notes-utils: use the passed repository for notes refs Okhuomon Ajayi
2026-11-02 11:01 ` Patrick Steinhardt
2026-11-02 11:10   ` Okhuomon Ajayi
2026-11-03  8:49 ` [Outreachy PATCH v2 0/2] notes-utils: stop using the_repository Okhuomon Ajayi
2026-11-03  8:49   ` [Outreachy PATCH v2 1/2] notes-utils: use the passed repository for notes refs Okhuomon Ajayi
2026-11-03  9:45     ` Karthik Nayak
2026-11-03 18:01       ` Junio C Hamano
2026-11-05  7:43         ` [Outreachy PATCH] notes-utils: hide functions that still need the_repository Okhuomon Ajayi
2026-11-05 14:22           ` Patrick Steinhardt
2026-11-05 14:47             ` Okhuomon Ajayi
2026-11-05 17:56             ` Junio C Hamano
2026-11-05 20:33               ` [Outreachy PATCH 0/6] notes: use the repository stored in the notes tree Okhuomon Ajayi
2026-11-05 20:33                 ` [Outreachy PATCH 1/6] notes: store the repository in struct notes_tree Okhuomon Ajayi
2026-11-09  9:18                   ` Patrick Steinhardt
2026-11-09 10:27                     ` Okhuomon Ajayi
2026-11-05 20:33                 ` [Outreachy PATCH 2/6] notes: use the tree's repository when reading notes Okhuomon Ajayi
2026-11-05 20:33                 ` [Outreachy PATCH 3/6] notes: use the tree's repository when writing and pruning Okhuomon Ajayi
2026-11-05 20:33                 ` [Outreachy PATCH 4/6] notes: pass the repository to the ref glob helpers Okhuomon Ajayi
2026-11-05 20:33                 ` [Outreachy PATCH 5/6] notes: pass the repository to the combine_notes callbacks Okhuomon Ajayi
2026-11-09  9:18                   ` Patrick Steinhardt
2026-11-09 10:11                     ` Okhuomon Ajayi
2026-11-24 15:28                       ` Christian Couder
2026-11-24 16:13                         ` Okhuomon Ajayi
2026-11-13 11:40                     ` Okhuomon Ajayi
2026-11-23  9:23                       ` Okhuomon Ajayi
2026-11-24 15:26                   ` Christian Couder
2026-11-24 15:49                     ` Okhuomon Ajayi
2026-11-05 20:33                 ` [Outreachy PATCH 6/6] notes-utils: use the given repository Okhuomon Ajayi
2026-11-24 17:21                 ` [PATCH v2 0/5] notes: start passing the repository through notes.[ch] Okhuomon Ajayi
2026-11-24 17:21                   ` [PATCH v2 1/5] notes: store the repository in struct notes_tree Okhuomon Ajayi
2026-11-25  0:34                     ` Junio C Hamano
2026-11-25  6:39                       ` Okhuomon Ajayi
2026-11-24 17:21                   ` [PATCH v2 2/5] notes: use the tree's repository when reading notes Okhuomon Ajayi
2026-11-25  0:54                     ` Junio C Hamano
2026-11-25  6:45                       ` Okhuomon Ajayi
2026-11-25  8:25                         ` Christian Couder
2026-11-25 18:13                           ` Okhuomon Ajayi
2026-11-25 19:09                             ` Junio C Hamano
2026-11-25 20:36                               ` Okhuomon Ajayi
2026-11-25 17:50                         ` Junio C Hamano
2026-11-25 18:19                           ` Okhuomon Ajayi
2026-11-24 17:21                   ` [PATCH v2 3/5] notes: use the tree's repository when writing and pruning Okhuomon Ajayi
2026-11-25  0:54                     ` Junio C Hamano
2026-11-25  6:48                       ` Okhuomon Ajayi
2026-11-24 17:21                   ` [PATCH v2 4/5] notes: pass the repository to the ref glob helpers Okhuomon Ajayi
2026-11-25  5:12                     ` Junio C Hamano
2026-11-24 17:21                   ` [PATCH v2 5/5] notes: pass the repository to the combine_notes callbacks Okhuomon Ajayi
2026-11-24 22:50                   ` [PATCH v2 0/5] notes: start passing the repository through notes.[ch] Junio C Hamano
2026-11-25  6:24                     ` Okhuomon Ajayi
2026-11-25  1:14                   ` Junio C Hamano
2026-11-25  6:35                     ` Okhuomon Ajayi
2026-11-25 22:02                   ` [PATCH v5 0/6] " Okhuomon Ajayi
2026-11-25 22:02                     ` [PATCH v5 1/6] notes: add notes_tree_or_default() Okhuomon Ajayi
2026-11-26  2:57                       ` Junio C Hamano
2026-11-26 16:57                         ` Okhuomon Ajayi
2026-11-25 22:02                     ` [PATCH v5 2/6] notes: store the repository in struct notes_tree Okhuomon Ajayi
2026-11-26  3:17                       ` Junio C Hamano
2026-11-25 22:02                     ` [PATCH v5 3/6] notes: use the tree's repository when reading notes Okhuomon Ajayi
2026-11-26  3:37                       ` Junio C Hamano [this message]
2026-11-26 20:57                         ` Okhuomon Ajayi
2026-11-25 22:02                     ` [PATCH v5 4/6] notes: use the tree's repository when writing and pruning Okhuomon Ajayi
2026-11-25 22:02                     ` [PATCH v5 5/6] notes: pass the repository to the ref glob helpers Okhuomon Ajayi
2026-11-25 22:02                     ` [PATCH v5 6/6] notes: pass the repository to the combine_notes callbacks Okhuomon Ajayi
2026-11-26  3:57                     ` [PATCH v5 0/6] notes: start passing the repository through notes.[ch] Junio C Hamano
2026-11-26 21:07                       ` Okhuomon Ajayi
2026-11-26 21:33                   ` [PATCH v6 " Okhuomon Ajayi
2026-11-26 21:33                     ` [PATCH v6 1/6] notes: add notes_tree_or_default() Okhuomon Ajayi
2026-11-26 21:33                     ` [PATCH v6 2/6] notes: store the repository in struct notes_tree Okhuomon Ajayi
2026-11-26 21:33                     ` [PATCH v6 3/6] notes: use the tree's repository when reading notes Okhuomon Ajayi
2026-11-27 13:13                       ` Christian Couder
2026-11-26 21:33                     ` [PATCH v6 4/6] notes: use the tree's repository when writing and pruning Okhuomon Ajayi
2026-11-26 21:33                     ` [PATCH v6 5/6] notes: pass the repository to the ref glob helpers Okhuomon Ajayi
2026-11-26 21:33                     ` [PATCH v6 6/6] notes: pass the repository to the combine_notes callbacks Okhuomon Ajayi
2026-11-27 13:22                     ` [PATCH v6 0/6] notes: start passing the repository through notes.[ch] Christian Couder
2026-11-27 13:52                       ` Okhuomon Ajayi
2026-11-27 18:19                         ` Junio C Hamano
2026-11-27 22:04                     ` [PATCH v7 " Okhuomon Ajayi
2026-11-27 22:04                       ` [PATCH v7 1/6] notes: add notes_tree_or_default() Okhuomon Ajayi
2026-11-27 22:04                       ` [PATCH v7 2/6] notes: store the repository in struct notes_tree Okhuomon Ajayi
2026-11-27 22:04                       ` [PATCH v7 3/6] notes: use the tree's repository when reading notes Okhuomon Ajayi
2026-11-27 22:04                       ` [PATCH v7 4/6] notes: use the tree's repository when writing and pruning Okhuomon Ajayi
2026-11-27 22:04                       ` [PATCH v7 5/6] notes: pass the repository to the ref glob helpers Okhuomon Ajayi
2026-11-27 22:04                       ` [PATCH v7 6/6] notes: pass the repository to the combine_notes callbacks Okhuomon Ajayi
2026-11-03  8:49   ` [Outreachy PATCH v2 2/2] notes-utils: pass the repository to init_copy_notes_for_rewrite() Okhuomon Ajayi
2026-11-03  9:48   ` [Outreachy PATCH v2 0/2] notes-utils: stop using the_repository Karthik Nayak
2026-11-03 10:27     ` Patrick Steinhardt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqq4id4s1od.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=christian.couder@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=kaartic.sivaraam@gmail.com \
    --cc=okhuomonajayi54@gmail.com \
    --cc=ps@pks.im \
    --cc=siddharthasthana31@gmail.com \
    --cc=usmanakinyemi202@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox