🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.kernel.git
79 messages
79 total messages Page 1 of 2 Started by Okhuomon Ajayi Sat, 31 Oct 2026 10:45
Page 1 of 2 • 79 total messages
[Outreachy PATCH] notes-utils: use the passed repository for notes refs
#1999
Author: Okhuomon Ajayi
Date: Sat, 31 Oct 2026 10:45
40 lines
11958 bytes
create_notes_commit() and commit_notes() receive a repository,
but read and update the notes ref in the_repository.

Use the repository they are given.

Keep USE_THE_REPOSITORY_VARIABLE because
init_copy_notes_for_rewrite() still uses the_repository.

Signed-off-by: Okhuomon Ajayi <okhuomonajayi54@gmail.com>
---
 notes-utils.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/notes-utils.c b/notes-utils.c
index 5c1c75d5b8..d4606bc576 100644
--- a/notes-utils.c
+++ b/notes-utils.c
@@ -26,7 +26,7 @@ void create_notes_commit(struct repository *r,
 	if (!parents) {
 		/* Deduce parent commit from t->ref */
 		struct object_id parent_oid;
-		if (!refs_read_ref(get_main_ref_store(the_repository), t->ref, &parent_oid)) {
+		if (!refs_read_ref(get_main_ref_store(r), t->ref, &parent_oid)) {
 			struct commit *parent = lookup_commit(r, &parent_oid);
 			if (repo_parse_commit(r, parent))
 				die("Failed to find/parse commit %s", t->ref);
@@ -61,7 +61,7 @@ void commit_notes(struct repository *r, struct notes_tree *t, const char *msg)
 
 	create_notes_commit(r, t, NULL, buf.buf, buf.len, &commit_oid);
 	strbuf_insertstr(&buf, 0, "notes: ");
-	refs_update_ref(get_main_ref_store(the_repository), buf.buf,
+	refs_update_ref(get_main_ref_store(r), buf.buf,
 			t->update_ref, &commit_oid, NULL, 0,
 			UPDATE_REFS_DIE_ON_ERR);
 

base-commit: 50fe5cc63f9cd6e89b87a2c9ccf96a444f4cfdb7
-- 
2.56.0
Re: [Outreachy PATCH] notes-utils: use the passed repository for notes refs
#2130
Author: Okhuomon Ajayi
Date: Mon, 02 Nov 2026 11:10
54 lines
14124 bytes
On Mon, Nov 2, 2026 at 12:01 PM Patrick Steinhardt <ps@pks.im> wrote:
> I don't quite understand patches like this. They are _so_ close to
> getting rid of `USE_THE_REPOSITORY_VARIABLE`, but then they just skip on
> the final change that would make them work. I've already asked about
> this on one of your preceding patches.

Thanks, Patrick. You're right, I should have gone the full way here
after your comment on bundle-uri.

I'll send a v2 that also passes the repository to
init_copy_notes_for_rewrite() and updates its callers, so that
notes-utils.c can drop USE_THE_REPOSITORY_VARIABLE.

> Also, could you maybe reduce the frequency a bit with which you send new
> topics? There's a ton of in-flight patch series by you in this vicinity,
> and it gets a bit overwhelming. May I ask you to maybe batch related
> patches into bigger series (maybe 5-10 commits) so that the reviewer can
> focus on way fewer patch series overall, and then have less series in
> flight at the same point in time?

Sorry about that. I'll stop sending new topics for now, and batch
related conversions into one series from now on.

Thanks,
Okhuomon

On Mon, Nov 2, 2026 at 12:01 PM Patrick Steinhardt <ps@pks.im> wrote:
>
> On Sat, Oct 31, 2026 at 11:45:26AM +0100, Okhuomon Ajayi wrote:
> > create_notes_commit() and commit_notes() receive a repository,
> > but read and update the notes ref in the_repository.
> >
> > Use the repository they are given.
> >
> > Keep USE_THE_REPOSITORY_VARIABLE because
> > init_copy_notes_for_rewrite() still uses the_repository.
>
> I don't quite understand patches like this. They are _so_ close to
> getting rid of `USE_THE_REPOSITORY_VARIABLE`, but then they just skip on
> the final change that would make them work. I've already asked about
> this on one of your preceding patches.
>
> Also, could you maybe reduce the frequency a bit with which you send new
> topics? There's a ton of in-flight patch series by you in this vicinity,
> and it gets a bit overwhelming. May I ask you to maybe batch related
> patches into bigger series (maybe 5-10 commits) so that the reviewer can
> focus on way fewer patch series overall, and then have less series in
> flight at the same point in time?
>
> Thanks!
>
> Patrick
[Outreachy PATCH v2 0/2] notes-utils: stop using the_repository
#2219
Author: Okhuomon Ajayi
Date: Tue, 03 Nov 2026 08:49
31 lines
11707 bytes
This series removes the_repository from notes-utils.c.

Changes since v1:
- Add patch 2, which passes a repository to
  init_copy_notes_for_rewrite() and drops USE_THE_REPOSITORY_VARIABLE
  from notes-utils.c, as Patrick suggested. v1 stopped one step short
  of that.

The callers in builtin/am.c and builtin/notes.c pass the_repository,
as those files still use it everywhere. copy() in builtin/notes.c
does receive a repo that could be passed down instead, if that is
preferred.

Thanks, Patrick, for the review.

Okhuomon Ajayi (2):
  notes-utils: use the passed repository for notes refs
  notes-utils: pass the repository to init_copy_notes_for_rewrite()

 builtin/am.c    |  2 +-
 builtin/notes.c |  2 +-
 notes-utils.c   | 11 +++++------
 notes-utils.h   |  3 ++-
 sequencer.c     |  2 +-
 5 files changed, 10 insertions(+), 10 deletions(-)


base-commit: 50fe5cc63f9cd6e89b87a2c9ccf96a444f4cfdb7
-- 
2.56.0
[Outreachy PATCH v2 1/2] notes-utils: use the passed repository for notes refs
#2220
Author: Okhuomon Ajayi
Date: Tue, 03 Nov 2026 08:49
38 lines
12227 bytes
create_notes_commit() and commit_notes() receive a repository,
but read and update the notes ref in the_repository.

Use the repository they are given.

Keep USE_THE_REPOSITORY_VARIABLE because
init_copy_notes_for_rewrite() still uses the_repository.

Signed-off-by: Okhuomon Ajayi <okhuomonajayi54@gmail.com>
---
 notes-utils.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/notes-utils.c b/notes-utils.c
index 5c1c75d5b8..d4606bc576 100644
--- a/notes-utils.c
+++ b/notes-utils.c
@@ -26,7 +26,7 @@ void create_notes_commit(struct repository *r,
 	if (!parents) {
 		/* Deduce parent commit from t->ref */
 		struct object_id parent_oid;
-		if (!refs_read_ref(get_main_ref_store(the_repository), t->ref, &parent_oid)) {
+		if (!refs_read_ref(get_main_ref_store(r), t->ref, &parent_oid)) {
 			struct commit *parent = lookup_commit(r, &parent_oid);
 			if (repo_parse_commit(r, parent))
 				die("Failed to find/parse commit %s", t->ref);
@@ -61,7 +61,7 @@ void commit_notes(struct repository *r, struct notes_tree *t, const char *msg)
 
 	create_notes_commit(r, t, NULL, buf.buf, buf.len, &commit_oid);
 	strbuf_insertstr(&buf, 0, "notes: ");
-	refs_update_ref(get_main_ref_store(the_repository), buf.buf,
+	refs_update_ref(get_main_ref_store(r), buf.buf,
 			t->update_ref, &commit_oid, NULL, 0,
 			UPDATE_REFS_DIE_ON_ERR);
 
-- 
2.56.0
[Outreachy PATCH v2 2/2] notes-utils: pass the repository to init_copy_notes_for_rewrite()
#2218
Author: Okhuomon Ajayi
Date: Tue, 03 Nov 2026 08:49
105 lines
14538 bytes
init_copy_notes_for_rewrite() reads the notes.rewrite* config from
the_repository, as it is not given a repository. This is the last
use of the_repository in notes-utils.c.

Add a repository parameter to it. commit_post_rewrite() in sequencer.c
already has one and passes it on. The callers in builtin/am.c and
builtin/notes.c still use the_repository, so pass that for now.

Drop USE_THE_REPOSITORY_VARIABLE, as notes-utils.c no longer uses
the_repository.

Signed-off-by: Okhuomon Ajayi <okhuomonajayi54@gmail.com>
---
 builtin/am.c    | 2 +-
 builtin/notes.c | 2 +-
 notes-utils.c   | 7 +++----
 notes-utils.h   | 3 ++-
 sequencer.c     | 2 +-
 5 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/builtin/am.c b/builtin/am.c
index e9623b8307..daa4b601b6 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -536,7 +536,7 @@ static int copy_notes_for_rebase(const struct am_state *state)
 
 	assert(state->rebasing);
 
-	c = init_copy_notes_for_rewrite("rebase");
+	c = init_copy_notes_for_rewrite(the_repository, "rebase");
 	if (!c)
 		return 0;
 
diff --git a/builtin/notes.c b/builtin/notes.c
index 9f1f0ec840..20f7bb8377 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -366,7 +366,7 @@ static int notes_copy_from_stdin(int force, const char *rewrite_cmd)
 	const char *msg = "Notes added by 'git notes copy'";
 
 	if (rewrite_cmd) {
-		c = init_copy_notes_for_rewrite(rewrite_cmd);
+		c = init_copy_notes_for_rewrite(the_repository, rewrite_cmd);
 		if (!c)
 			return 0;
 	} else {
diff --git a/notes-utils.c b/notes-utils.c
index d4606bc576..3a3b84f79c 100644
--- a/notes-utils.c
+++ b/notes-utils.c
@@ -1,5 +1,3 @@
-#define USE_THE_REPOSITORY_VARIABLE
-
 #include "git-compat-util.h"
 #include "config.h"
 #include "commit.h"
@@ -134,7 +132,8 @@ static int notes_rewrite_config(const char *k, const char *v,
 }
 
 
-struct notes_rewrite_cfg *init_copy_notes_for_rewrite(const char *cmd)
+struct notes_rewrite_cfg *init_copy_notes_for_rewrite(struct repository *r,
+						      const char *cmd)
 {
 	struct notes_rewrite_cfg *c = xmalloc(sizeof(struct notes_rewrite_cfg));
 	const char *rewrite_mode_env = getenv(GIT_NOTES_REWRITE_MODE_ENVIRONMENT);
@@ -162,7 +161,7 @@ struct notes_rewrite_cfg *init_copy_notes_for_rewrite(const char *cmd)
 		c->refs_from_env = 1;
 		string_list_add_refs_from_colon_sep(c->refs, rewrite_refs_env);
 	}
-	repo_config(the_repository, notes_rewrite_config, c);
+	repo_config(r, notes_rewrite_config, c);
 	if (!c->enabled || !c->refs->nr) {
 		string_list_clear(c->refs, 0);
 		free(c->refs);
diff --git a/notes-utils.h b/notes-utils.h
index c54b1fe141..ef3c0f6732 100644
--- a/notes-utils.h
+++ b/notes-utils.h
@@ -45,7 +45,8 @@ struct notes_rewrite_cfg {
 };
 
 int parse_notes_merge_strategy(const char *v, enum notes_merge_strategy *s);
-struct notes_rewrite_cfg *init_copy_notes_for_rewrite(const char *cmd);
+struct notes_rewrite_cfg *init_copy_notes_for_rewrite(struct repository *r,
+						      const char *cmd);
 int copy_note_for_rewrite(struct notes_rewrite_cfg *c,
 			  const struct object_id *from_obj, const struct object_id *to_obj);
 void finish_copy_notes_for_rewrite(struct repository *r,
diff --git a/sequencer.c b/sequencer.c
index 508ec71792..a40243c56b 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -1366,7 +1366,7 @@ void commit_post_rewrite(struct repository *r,
 {
 	struct notes_rewrite_cfg *cfg;
 
-	cfg = init_copy_notes_for_rewrite("amend");
+	cfg = init_copy_notes_for_rewrite(r, "amend");
 	if (cfg) {
 		/* we are amending, so old_head is not NULL */
 		copy_note_for_rewrite(cfg, &old_head->object.oid, new_head);
-- 
2.56.0
Re: [Outreachy PATCH v2 1/2] notes-utils: use the passed repository for notes refs
#2247
Author: Junio C Hamano
Date: Tue, 03 Nov 2026 18:01
75 lines
15478 bytes
Karthik Nayak <karthik.188@gmail.com> writes:

> Okhuomon Ajayi <okhuomonajayi54@gmail.com> writes:
>
>> Keep USE_THE_REPOSITORY_VARIABLE because
>> init_copy_notes_for_rewrite() still uses the_repository.

Unfortunately, this is a highly misleading comment to leave here.

The next person would be misled into thinking that it would be just
a matter of giving a "struct repository *r" argument to that
function to lift the USE_THE_REPOSITORY_VARIABLE declaration from
there.

Looking at what <notes-utils.h> exports, the file has quite some way
to go to be free from the_repository.

 * create_notes_commit() takes "struct repository *" to pretend as
   if it can work with any repository, but the first function it
   calls is write_notes_tree() that eventually calls into
   odb_write_object() with hardcoded the_repository->objects.

 * commit_notes() calls the above create_notes_commit() and shares
   the same problem.

 * init_copy_notes_for_rewrite(), in addition to having its own
   reference to the_repository, calls load_notes_trees() that makes
   calls to init_notes() that works only on the_repository.

 * copy_note_for_rewrite() calls copy_note() which calls add_note(),
   which eventually calls into load_subtree() that can only work
   with the_repository.

In short, I think adding "struct repository *" to anything in
<notes-utils.h> is not yet a productive exercise at this point,
before cleaning up what is in the underlying things exported from
<notes.h>.

This is a tangent but there are precedents to mark the functions
that still work only on the_repository or the_hash_algo:

    $ git grep 'ifdef *USE_THE' \*.h
    environment.h:# ifdef USE_THE_REPOSITORY_VARIABLE
    hash.h:#ifdef USE_THE_REPOSITORY_VARIABLE
    hex.h:#ifdef USE_THE_REPOSITORY_VARIABLE
    path.h:# ifdef USE_THE_REPOSITORY_VARIABLE
    repository.h:#ifdef USE_THE_REPOSITORY_VARIABLE

Perhaps we need similar protection to forbid use of these functions
that still assume the_repository is available in this file?

 notes-utils.h | 4 ++++
 1 file changed, 4 insertions(+)

diff --git c/notes-utils.h w/notes-utils.h
index c54b1fe141..1503991cf6 100644
--- c/notes-utils.h
+++ w/notes-utils.h
@@ -7,6 +7,9 @@ struct commit_list;
 struct object_id;
 struct repository;
 
+/* most of the things in notes.h still only work with the_repository */
+# ifdef USE_THE_REPOSITORY_VARIABLE
+
 /*
  * Create new notes commit from the given notes tree
  *
@@ -52,4 +55,5 @@ void finish_copy_notes_for_rewrite(struct repository *r,
 				   struct notes_rewrite_cfg *c,
 				   const char *msg);
 
+# endif
 #endif
[Outreachy PATCH] notes-utils: hide functions that still need the_repository
#2400
Author: Okhuomon Ajayi
Date: Thu, 05 Nov 2026 07:43
51 lines
12390 bytes
The helpers declared in notes-utils.h call into notes.c, which
still only works on the_repository. write_notes_tree() writes
its tree into the_repository->objects.

Passing a repository argument does not make these helpers work
on another repository yet. Guard them with
USE_THE_REPOSITORY_VARIABLE, as environment.h and repository.h
do, so code that has dropped the global cannot call them by
mistake.

Suggested-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Okhuomon Ajayi <okhuomonajayi54@gmail.com>
---
This replaces my notes-utils series [1], which I'm dropping after
Junio pointed out that the functions underneath, in notes.c, still
only work on the_repository.

The guard also hides the enum and struct that notes-merge.h uses.
All current users define USE_THE_REPOSITORY_VARIABLE, so nothing
breaks today.

[1] https://lore.kernel.org/git/20261103084930.15532-1-okhuomonajayi54@gmail.com/

 notes-utils.h | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/notes-utils.h b/notes-utils.h
index c54b1fe141..1503991cf6 100644
--- a/notes-utils.h
+++ b/notes-utils.h
@@ -7,6 +7,9 @@ struct commit_list;
 struct object_id;
 struct repository;
 
+/* most of the things in notes.h still only work with the_repository */
+# ifdef USE_THE_REPOSITORY_VARIABLE
+
 /*
  * Create new notes commit from the given notes tree
  *
@@ -52,4 +55,5 @@ void finish_copy_notes_for_rewrite(struct repository *r,
 				   struct notes_rewrite_cfg *c,
 				   const char *msg);
 
+# endif
 #endif

base-commit: 0ffa3e35c7c82ab8d0de226149fb03b3f7674d05
-- 
2.56.0
Re: [Outreachy PATCH] notes-utils: hide functions that still need the_repository
#2412
Author: Okhuomon Ajayi
Date: Thu, 05 Nov 2026 14:47
12 lines
12137 bytes
On Thu, Nov 5, 2026 at 3:22 PM Patrick Steinhardt <ps@pks.im> wrote:
> Hmm. Wouldn't the better course of actions be to instead fix "notes.c"?

Fair point. I'll drop this patch and instead make notes.c to use
the repository stored in struct notes_tree, then remove
USE_THE_REPOSITORY_VARIABLE from notes-utils.c in the same series.

I'll send that as one series rather than several small topics.

Thanks,
Okhuomon
Re: [Outreachy PATCH] notes-utils: hide functions that still need the_repository
#2438
Author: Junio C Hamano
Date: Thu, 05 Nov 2026 17:56
27 lines
13831 bytes
Patrick Steinhardt <ps@pks.im> writes:

> Hmm. Wouldn't the better course of actions be to instead fix "notes.c"?
> It feels a bit weird to me to just make the whole header a pointless
> include, and we don't do that for other headers, either. We have tons of
> subsystems that still depend on `the_repository`, so what makes
> "notes-utils.h" so special that we need to drop all of its functions?

Because it invites people into removing the_repository from
notes-utils.c and think they are done, when they call helpers from
notes.c liberally if we do not.

> What we indeed do sometimes is to mark some very small subset of
> functions in a header as depending on `the_repository` in case the blast
> radius of fixing all users is simply too big to do it in a single patch
> series.

Absolutely, in the ideal world.

In this case, however, I initialy thought there was only just one or
two functions that depend on the_repository, but it turns out that
everything calls things that only work with the_repository from
notes.c and that is how this patch ended up covering almost all of
this header X-<.

So...
[Outreachy PATCH 0/6] notes: use the repository stored in the notes tree
#2462
Author: Okhuomon Ajayi
Date: Thu, 05 Nov 2026 20:33
45 lines
12559 bytes
Patrick suggested fixing notes.c instead of hiding notes-utils.h [1],
and Junio pointed out that removing the_repository from notes-utils.c
is not enough while the notes.c helpers it calls still use it [2].

This series stores the repository in struct notes_tree when the tree
is initialized, and uses it in notes.c wherever a tree is available:
reading and writing notes, pruning, and the combine_notes callbacks.
The ref glob helpers take the repository as an argument. With that,
notes-utils.c can use the repository it is given and drop
USE_THE_REPOSITORY_VARIABLE.

notes.c itself still needs the_repository for the display notes
code (load_display_notes() and the default notes tree),
expand_loose_notes_ref(), and a few uses of the_hash_algo for
sizes. Most callers outside notes.c still pass the_repository.

This replaces my patch "notes-utils: hide functions that still need
the_repository" and the earlier notes-utils series.

[1] https://lore.kernel.org/git/auyRGpaHb5rdVP0d@pks.im/
[2] https://lore.kernel.org/git/xmqq1p8zw49g.fsf@gitster.g/

Okhuomon Ajayi (6):
  notes: store the repository in struct notes_tree
  notes: use the tree's repository when reading notes
  notes: use the tree's repository when writing and pruning
  notes: pass the repository to the ref glob helpers
  notes: pass the repository to the combine_notes callbacks
  notes-utils: use the given repository

 builtin/am.c    |   2 +-
 builtin/notes.c |  10 +--
 notes-cache.c   |   3 +-
 notes-utils.c   |  20 +++---
 notes-utils.h   |   4 +-
 notes.c         | 160 ++++++++++++++++++++++++++++--------------------
 notes.h         |  38 +++++++-----
 sequencer.c     |   2 +-
 8 files changed, 141 insertions(+), 98 deletions(-)


base-commit: 0ffa3e35c7c82ab8d0de226149fb03b3f7674d05
-- 
2.56.0
[Outreachy PATCH 1/6] notes: store the repository in struct notes_tree
#2460
Author: Okhuomon Ajayi
Date: Thu, 05 Nov 2026 20:33
208 lines
18543 bytes
A notes tree is always read from one repository, but the tree
does not record which one. Later code has to fall back to
the_repository.

Store the repository on the tree. init_notes() and
load_notes_trees() take it as their first argument, and
init_notes() saves it in t->repo. notes_cache_init() passes
the repository it was given. Other callers pass
the_repository for now.

Signed-off-by: Okhuomon Ajayi <okhuomonajayi54@gmail.com>
---
 builtin/notes.c |  8 +++++---
 notes-cache.c   |  3 ++-
 notes-utils.c   |  3 ++-
 notes.c         | 26 +++++++++++++++-----------
 notes.h         |  9 ++++++---
 5 files changed, 30 insertions(+), 19 deletions(-)

diff --git a/builtin/notes.c b/builtin/notes.c
index 9f1f0ec840..7e7dff6672 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -370,7 +370,8 @@ static int notes_copy_from_stdin(int force, const char *rewrite_cmd)
 		if (!c)
 			return 0;
 	} else {
-		init_notes(NULL, NULL, NULL, NOTES_INIT_WRITABLE);
+		init_notes(the_repository, NULL, NULL, NULL,
+			   NOTES_INIT_WRITABLE);
 		t = &default_notes_tree;
 	}
 
@@ -420,7 +421,7 @@ static struct notes_tree *init_notes_check(const char *subcommand,
 {
 	struct notes_tree *t;
 	const char *ref;
-	init_notes(NULL, NULL, NULL, flags);
+	init_notes(the_repository, NULL, NULL, NULL, flags);
 	t = &default_notes_tree;
 
 	ref = (flags & NOTES_INIT_WRITABLE) ? t->update_ref : t->ref;
@@ -841,7 +842,8 @@ static int merge_commit(struct notes_merge_options *o)
 	else
 		oidclr(&parent_oid, the_repository->hash_algo);
 
-	init_notes(&t, "NOTES_MERGE_PARTIAL", combine_notes_overwrite, 0);
+	init_notes(the_repository, &t, "NOTES_MERGE_PARTIAL",
+		   combine_notes_overwrite, 0);
 
 	o->local_ref = local_ref_to_free =
 		refs_resolve_refdup(get_main_ref_store(the_repository),
diff --git a/notes-cache.c b/notes-cache.c
index 74cef802bd..7c35ebe64b 100644
--- a/notes-cache.c
+++ b/notes-cache.c
@@ -50,7 +50,8 @@ void notes_cache_init(struct repository *r, struct notes_cache *c,
 	strbuf_addf(&ref, "refs/notes/%s", name);
 	if (!notes_cache_match_validity(r, ref.buf, validity))
 		flags |= NOTES_INIT_EMPTY;
-	init_notes(&c->tree, ref.buf, combine_notes_overwrite, flags);
+	init_notes(r, &c->tree, ref.buf,
+		   combine_notes_overwrite, flags);
 	strbuf_release(&ref);
 }
 
diff --git a/notes-utils.c b/notes-utils.c
index 5c1c75d5b8..404e9a5eea 100644
--- a/notes-utils.c
+++ b/notes-utils.c
@@ -169,7 +169,8 @@ struct notes_rewrite_cfg *init_copy_notes_for_rewrite(const char *cmd)
 		free(c);
 		return NULL;
 	}
-	c->trees = load_notes_trees(c->refs, NOTES_INIT_WRITABLE);
+	c->trees = load_notes_trees(the_repository, c->refs,
+				    NOTES_INIT_WRITABLE);
 	string_list_clear(c->refs, 0);
 	free(c->refs);
 	return c;
diff --git a/notes.c b/notes.c
index ec9c2cb150..4ab3d45d7c 100644
--- a/notes.c
+++ b/notes.c
@@ -1012,8 +1012,9 @@ char *default_notes_ref(struct repository *repo)
 	return notes_ref;
 }
 
-void init_notes(struct notes_tree *t, const char *notes_ref,
-		combine_notes_fn combine_notes, int flags)
+void init_notes(struct repository *r, struct notes_tree *t,
+		const char *notes_ref, combine_notes_fn combine_notes,
+		int flags)
 {
 	struct object_id oid, object_oid;
 	unsigned short mode;
@@ -1025,7 +1026,7 @@ void init_notes(struct notes_tree *t, const char *notes_ref,
 	assert(!t->initialized);
 
 	if (!notes_ref)
-		notes_ref = to_free = default_notes_ref(the_repository);
+		notes_ref = to_free = default_notes_ref(r);
 	update_ref_namespace(NAMESPACE_NOTES, xstrdup(notes_ref));
 
 	if (!combine_notes)
@@ -1034,6 +1035,7 @@ void init_notes(struct notes_tree *t, const char *notes_ref,
 	t->root = (struct int_node *) xcalloc(1, sizeof(struct int_node));
 	t->first_non_note = NULL;
 	t->prev_non_note = NULL;
+	t->repo = r;
 	t->ref = xstrdup(notes_ref);
 	t->update_ref = (flags & NOTES_INIT_WRITABLE) ? t->ref : NULL;
 	t->combine_notes = combine_notes;
@@ -1041,15 +1043,15 @@ void init_notes(struct notes_tree *t, const char *notes_ref,
 	t->dirty = 0;
 
 	if (flags & NOTES_INIT_EMPTY ||
-	    repo_get_oid_treeish(the_repository, notes_ref, &object_oid))
+	    repo_get_oid_treeish(r, notes_ref, &object_oid))
 		goto out;
-	if (flags & NOTES_INIT_WRITABLE && refs_read_ref(get_main_ref_store(the_repository), notes_ref, &object_oid))
+	if (flags & NOTES_INIT_WRITABLE && refs_read_ref(get_main_ref_store(r), notes_ref, &object_oid))
 		die("Cannot use notes ref %s", notes_ref);
-	if (get_tree_entry(the_repository, &object_oid, "", &oid, &mode))
+	if (get_tree_entry(r, &object_oid, "", &oid, &mode))
 		die("Failed to read notes tree referenced by %s (%s)",
 		    notes_ref, oid_to_hex(&object_oid));
 
-	oidclr(&root_tree.key_oid, the_repository->hash_algo);
+	oidclr(&root_tree.key_oid, r->hash_algo);
 	oidcpy(&root_tree.val_oid, &oid);
 	load_subtree(t, &root_tree, t->root, 0);
 
@@ -1057,7 +1059,8 @@ void init_notes(struct notes_tree *t, const char *notes_ref,
 	free(to_free);
 }
 
-struct notes_tree **load_notes_trees(struct string_list *refs, int flags)
+struct notes_tree **load_notes_trees(struct repository *r,
+				     struct string_list *refs, int flags)
 {
 	struct string_list_item *item;
 	int counter = 0;
@@ -1065,7 +1068,7 @@ struct notes_tree **load_notes_trees(struct string_list *refs, int flags)
 	ALLOC_ARRAY(trees, refs->nr + 1);
 	for_each_string_list_item(item, refs) {
 		struct notes_tree *t = xcalloc(1, sizeof(struct notes_tree));
-		init_notes(t, item->string, combine_notes_ignore, flags);
+		init_notes(r, t, item->string, combine_notes_ignore, flags);
 		trees[counter++] = t;
 	}
 	trees[counter] = NULL;
@@ -1136,7 +1139,8 @@ void load_display_notes(struct display_notes_opt *opt)
 						     item->string);
 	}
 
-	display_notes_trees = load_notes_trees(&display_notes_refs, 0);
+	display_notes_trees = load_notes_trees(the_repository,
+					       &display_notes_refs, 0);
 	string_list_clear(&display_notes_refs, 0);
 }
 
@@ -1290,7 +1294,7 @@ static void format_note(struct notes_tree *t, const struct object_id *object_oid
 	if (!t)
 		t = &default_notes_tree;
 	if (!t->initialized)
-		init_notes(t, NULL, NULL, 0);
+		init_notes(the_repository, t, NULL, NULL, 0);
 
 	oid = get_note(t, object_oid);
 	if (!oid)
diff --git a/notes.h b/notes.h
index 6dc6d7b265..0f50020816 100644
--- a/notes.h
+++ b/notes.h
@@ -50,6 +50,7 @@ int combine_notes_cat_sort_uniq(struct object_id *cur_oid,
  * simultaneously.
  */
 extern struct notes_tree {
+	struct repository *repo;
 	struct int_node *root;
 	struct non_note *first_non_note, *prev_non_note;
 	char *ref;
@@ -107,8 +108,9 @@ char *default_notes_ref(struct repository *repo);
  * Precondition: The notes_tree structure is zeroed (this can be achieved with
  * memset(t, 0, sizeof(struct notes_tree)))
  */
-void init_notes(struct notes_tree *t, const char *notes_ref,
-		combine_notes_fn combine_notes, int flags);
+void init_notes(struct repository *r, struct notes_tree *t,
+		const char *notes_ref, combine_notes_fn combine_notes,
+		int flags);
 
 /*
  * Add the given note object to the given notes_tree structure
@@ -319,7 +321,8 @@ void format_display_notes(const struct object_id *object_oid,
  * Load the notes tree from each ref listed in 'refs'.  The output is
  * an array of notes_tree*, terminated by a NULL.
  */
-struct notes_tree **load_notes_trees(struct string_list *refs, int flags);
+struct notes_tree **load_notes_trees(struct repository *r,
+				     struct string_list *refs, int flags);
 
 /*
  * Add all refs that match 'glob' to the 'list'.
-- 
2.56.0
[Outreachy PATCH 2/6] notes: use the tree's repository when reading notes
#2468
Author: Okhuomon Ajayi
Date: Thu, 05 Nov 2026 20:33
88 lines
14264 bytes
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.

Signed-off-by: Okhuomon Ajayi <okhuomonajayi54@gmail.com>
---
 notes.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/notes.c b/notes.c
index 4ab3d45d7c..5c2e8815f8 100644
--- a/notes.c
+++ b/notes.c
@@ -153,7 +153,7 @@ static struct leaf_node *note_tree_find(struct notes_tree *t,
 	void **p = note_tree_search(t, &tree, &n, key_sha1);
 	if (GET_PTR_TYPE(*p) == PTR_TYPE_NOTE) {
 		struct leaf_node *l = (struct leaf_node *) CLR_PTR_TYPE(*p);
-		if (hasheq(key_sha1, l->key_oid.hash, the_repository->hash_algo))
+		if (hasheq(key_sha1, l->key_oid.hash, t->repo->hash_algo))
 			return l;
 	}
 	return NULL;
@@ -357,7 +357,7 @@ static void add_non_note(struct notes_tree *t, char *path,
 	n->next = NULL;
 	n->path = path;
 	n->mode = mode;
-	oidread(&n->oid, sha1, the_repository->hash_algo);
+	oidread(&n->oid, sha1, t->repo->hash_algo);
 	t->prev_non_note = n;
 
 	if (!t->first_non_note) {
@@ -402,9 +402,9 @@ static void load_subtree(struct notes_tree *t, struct leaf_node *subtree,
 	void *buf;
 	struct tree_desc desc;
 	struct name_entry entry;
-	const unsigned hashsz = the_hash_algo->rawsz;
+	const unsigned hashsz = t->repo->hash_algo->rawsz;
 
-	buf = fill_tree_descriptor(the_repository, &desc, &subtree->val_oid);
+	buf = fill_tree_descriptor(t->repo, &desc, &subtree->val_oid);
 	if (!buf)
 		die("Could not read %s for notes-index",
 		     oid_to_hex(&subtree->val_oid));
@@ -462,8 +462,8 @@ static void load_subtree(struct notes_tree *t, struct leaf_node *subtree,
 		CALLOC_ARRAY(l, 1);
 		oidcpy(&l->key_oid, &object_oid);
 		oidcpy(&l->val_oid, &entry.oid);
-		oid_set_algo(&l->key_oid, the_hash_algo);
-		oid_set_algo(&l->val_oid, the_hash_algo);
+		oid_set_algo(&l->key_oid, t->repo->hash_algo);
+		oid_set_algo(&l->val_oid, t->repo->hash_algo);
 		if (note_tree_insert(t, node, n, l, type,
 				     combine_notes_concatenate))
 			die("Failed to load %s %s into notes tree "
@@ -493,7 +493,7 @@ static void load_subtree(struct notes_tree *t, struct leaf_node *subtree,
 				strbuf_addch(&non_note_path, '/');
 			}
 			strbuf_addstr(&non_note_path, entry.path);
-			oid_set_algo(&entry.oid, the_hash_algo);
+			oid_set_algo(&entry.oid, t->repo->hash_algo);
 			add_non_note(t, strbuf_detach(&non_note_path, NULL),
 				     entry.mode, entry.oid.hash);
 		}
@@ -1168,8 +1168,8 @@ int remove_note(struct notes_tree *t, const unsigned char *object_sha1)
 	if (!t)
 		t = &default_notes_tree;
 	assert(t->initialized);
-	oidread(&l.key_oid, object_sha1, the_repository->hash_algo);
-	oidclr(&l.val_oid, the_repository->hash_algo);
+	oidread(&l.key_oid, object_sha1, t->repo->hash_algo);
+	oidclr(&l.val_oid, t->repo->hash_algo);
 	note_tree_remove(t, t->root, 0, &l);
 	if (is_null_oid(&l.val_oid)) /* no note was removed */
 		return 1;
@@ -1300,7 +1300,7 @@ static void format_note(struct notes_tree *t, const struct object_id *object_oid
 	if (!oid)
 		return;
 
-	if (!(msg = odb_read_object(the_repository->objects, oid, &type, &msglen)) ||
+	if (!(msg = odb_read_object(t->repo->objects, oid, &type, &msglen)) ||
 	    type != OBJ_BLOB) {
 		free(msg);
 		return;
-- 
2.56.0
[Outreachy PATCH 3/6] notes: use the tree's repository when writing and pruning
#2465
Author: Okhuomon Ajayi
Date: Thu, 05 Nov 2026 20:33
180 lines
16730 bytes
write_notes_tree() writes the notes tree into the_repository,
and prune_notes() looks for missing objects there too. Both
already have the notes tree.

Write through t->repo. tree_write_stack_finish_subtree() takes
the repository, passed down from the tree. prune_notes() hands
the repository to its callback in a small struct.

Signed-off-by: Okhuomon Ajayi <okhuomonajayi54@gmail.com>
---
 notes.c | 59 ++++++++++++++++++++++++++++++++++-----------------------
 1 file changed, 35 insertions(+), 24 deletions(-)

diff --git a/notes.c b/notes.c
index 5c2e8815f8..c83bcc29ad 100644
--- a/notes.c
+++ b/notes.c
@@ -673,16 +673,17 @@ static void tree_write_stack_init_subtree(struct tree_write_stack *tws,
 	tws->path[1] = path[1];
 }
 
-static int tree_write_stack_finish_subtree(struct tree_write_stack *tws)
+static int tree_write_stack_finish_subtree(struct repository *r,
+					   struct tree_write_stack *tws)
 {
 	int ret;
 	struct tree_write_stack *n = tws->next;
 	struct object_id s;
 	if (n) {
-		ret = tree_write_stack_finish_subtree(n);
+		ret = tree_write_stack_finish_subtree(r, n);
 		if (ret)
 			return ret;
-		ret = odb_write_object(the_repository->objects, n->buf.buf,
+		ret = odb_write_object(r->objects, n->buf.buf,
 				       n->buf.len, OBJ_TREE, &s);
 		if (ret)
 			return ret;
@@ -695,9 +696,10 @@ static int tree_write_stack_finish_subtree(struct tree_write_stack *tws)
 	return 0;
 }
 
-static int write_each_note_helper(struct tree_write_stack *tws,
-		const char *path, unsigned int mode,
-		const struct object_id *oid)
+static int write_each_note_helper(struct repository *r,
+				  struct tree_write_stack *tws,
+				  const char *path, unsigned int mode,
+				  const struct object_id *oid)
 {
 	size_t path_len = strlen(path);
 	unsigned int n = 0;
@@ -711,7 +713,7 @@ static int write_each_note_helper(struct tree_write_stack *tws,
 	}
 
 	/* tws point to last matching tree_write_stack entry */
-	ret = tree_write_stack_finish_subtree(tws);
+	ret = tree_write_stack_finish_subtree(r, tws);
 	if (ret)
 		return ret;
 
@@ -733,6 +735,7 @@ static int write_each_note_helper(struct tree_write_stack *tws,
 }
 
 struct write_each_note_data {
+	struct repository *repo;
 	struct tree_write_stack *root;
 	struct non_note **nn_list;
 	struct non_note *nn_prev;
@@ -748,8 +751,8 @@ static int write_each_non_note_until(const char *note_path,
 		if (note_path && cmp == 0)
 			; /* do nothing, prefer note to non-note */
 		else {
-			ret = write_each_note_helper(d->root, n->path, n->mode,
-						     &n->oid);
+			ret = write_each_note_helper(d->repo, d->root, n->path,
+						     n->mode, &n->oid);
 			if (ret)
 				return ret;
 		}
@@ -779,7 +782,8 @@ static int write_each_note(const struct object_id *object_oid UNUSED,
 
 	/* Weave non-note entries into note entries */
 	return  write_each_non_note_until(note_path, d) ||
-		write_each_note_helper(d->root, note_path, mode, note_oid);
+		write_each_note_helper(d->repo, d->root, note_path, mode,
+				       note_oid);
 }
 
 struct note_delete_list {
@@ -787,23 +791,28 @@ struct note_delete_list {
 	const unsigned char *sha1;
 };
 
+struct prune_notes_data {
+	struct repository *repo;
+	struct note_delete_list *list;
+};
+
 static int prune_notes_helper(const struct object_id *object_oid,
 			      const struct object_id *note_oid UNUSED,
 			      char *note_path UNUSED,
 			      void *cb_data)
 {
-	struct note_delete_list **l = (struct note_delete_list **) cb_data;
+	struct prune_notes_data *d = cb_data;
 	struct note_delete_list *n;
 
-	if (odb_has_object(the_repository->objects, object_oid,
+	if (odb_has_object(d->repo->objects, object_oid,
 			   ODB_HAS_OBJECT_RECHECK_PACKED | ODB_HAS_OBJECT_FETCH_PROMISOR))
 		return 0; /* nothing to do for this note */
 
 	/* failed to find object => prune this note */
 	n = (struct note_delete_list *) xmalloc(sizeof(*n));
-	n->next = *l;
+	n->next = d->list;
 	n->sha1 = object_oid->hash;
-	*l = n;
+	d->list = n;
 	return 0;
 }
 
@@ -1213,6 +1222,7 @@ int write_notes_tree(struct notes_tree *t, struct object_id *result)
 	root.next = NULL; /* last forward entry in list is grounded */
 	strbuf_init(&root.buf, 256 * (32 + the_hash_algo->hexsz)); /* assume 256 entries */
 	root.path[0] = root.path[1] = '\0';
+	cb_data.repo = t->repo;
 	cb_data.root = &root;
 	cb_data.nn_list = &(t->first_non_note);
 	cb_data.nn_prev = NULL;
@@ -1222,8 +1232,8 @@ int write_notes_tree(struct notes_tree *t, struct object_id *result)
 		FOR_EACH_NOTE_YIELD_SUBTREES;
 	ret = for_each_note(t, flags, write_each_note, &cb_data) ||
 	      write_each_non_note_until(NULL, &cb_data) ||
-	      tree_write_stack_finish_subtree(&root) ||
-	      odb_write_object(the_repository->objects, root.buf.buf,
+	      tree_write_stack_finish_subtree(t->repo, &root) ||
+	      odb_write_object(t->repo->objects, root.buf.buf,
 			       root.buf.len, OBJ_TREE, result);
 	strbuf_release(&root.buf);
 	return ret;
@@ -1231,25 +1241,26 @@ int write_notes_tree(struct notes_tree *t, struct object_id *result)
 
 void prune_notes(struct notes_tree *t, int flags)
 {
-	struct note_delete_list *l = NULL;
+	struct prune_notes_data d = { 0 };
 
 	if (!t)
 		t = &default_notes_tree;
 	assert(t->initialized);
 
-	for_each_note(t, 0, prune_notes_helper, &l);
+	d.repo = t->repo;
+	for_each_note(t, 0, prune_notes_helper, &d);
 
-	while (l) {
+	while (d.list) {
 		struct note_delete_list *next;
 
 		if (flags & NOTES_PRUNE_VERBOSE)
-			printf("%s\n", hash_to_hex(l->sha1));
+			printf("%s\n", hash_to_hex(d.list->sha1));
 		if (!(flags & NOTES_PRUNE_DRYRUN))
-			remove_note(t, l->sha1);
+			remove_note(t, d.list->sha1);
 
-		next = l->next;
-		free(l);
-		l = next;
+		next = d.list->next;
+		free(d.list);
+		d.list = next;
 	}
 }
 
-- 
2.56.0
[Outreachy PATCH 4/6] notes: pass the repository to the ref glob helpers
#2464
Author: Okhuomon Ajayi
Date: Thu, 05 Nov 2026 20:33
140 lines
15994 bytes
string_list_add_refs_by_glob() and
string_list_add_refs_from_colon_sep() walk refs in
the_repository. The caller already knows which repository
that is.

Take the repository as their first argument. Callers pass
the_repository for now.

Signed-off-by: Okhuomon Ajayi <okhuomonajayi54@gmail.com>
---
 notes-utils.c |  6 ++++--
 notes.c       | 21 +++++++++++++--------
 notes.h       |  6 ++++--
 3 files changed, 21 insertions(+), 12 deletions(-)

diff --git a/notes-utils.c b/notes-utils.c
index 404e9a5eea..70c619269e 100644
--- a/notes-utils.c
+++ b/notes-utils.c
@@ -123,7 +123,8 @@ static int notes_rewrite_config(const char *k, const char *v,
 		/* note that a refs/ prefix is implied in the
 		 * underlying for_each_glob_ref */
 		if (starts_with(v, "refs/notes/"))
-			string_list_add_refs_by_glob(c->refs, v);
+			string_list_add_refs_by_glob(the_repository,
+						     c->refs, v);
 		else
 			warning(_("Refusing to rewrite notes in %s"
 				" (outside of refs/notes/)"), v);
@@ -160,7 +161,8 @@ struct notes_rewrite_cfg *init_copy_notes_for_rewrite(const char *cmd)
 	}
 	if (rewrite_refs_env) {
 		c->refs_from_env = 1;
-		string_list_add_refs_from_colon_sep(c->refs, rewrite_refs_env);
+		string_list_add_refs_from_colon_sep(the_repository, c->refs,
+						    rewrite_refs_env);
 	}
 	repo_config(the_repository, notes_rewrite_config, c);
 	if (!c->enabled || !c->refs->nr) {
diff --git a/notes.c b/notes.c
index c83bcc29ad..cff63a4410 100644
--- a/notes.c
+++ b/notes.c
@@ -958,25 +958,27 @@ static int string_list_add_one_ref(const struct reference *ref, void *cb)
 /*
  * The list argument must have strdup_strings set on it.
  */
-void string_list_add_refs_by_glob(struct string_list *list, const char *glob)
+void string_list_add_refs_by_glob(struct repository *r,
+				  struct string_list *list, const char *glob)
 {
 	assert(list->strdup_strings);
 	if (has_glob_specials(glob)) {
 		struct refs_for_each_ref_options opts = {
 			.pattern = glob,
 		};
-		refs_for_each_ref_ext(get_main_ref_store(the_repository),
+		refs_for_each_ref_ext(get_main_ref_store(r),
 				      string_list_add_one_ref, list, &opts);
 	} else {
 		struct object_id oid;
-		if (repo_get_oid(the_repository, glob, &oid))
+		if (repo_get_oid(r, glob, &oid))
 			warning("notes ref %s is invalid", glob);
 		if (!unsorted_string_list_has_string(list, glob))
 			string_list_append(list, glob);
 	}
 }
 
-void string_list_add_refs_from_colon_sep(struct string_list *list,
+void string_list_add_refs_from_colon_sep(struct repository *r,
+					 struct string_list *list,
 					 const char *globs)
 {
 	struct string_list split = STRING_LIST_INIT_NODUP;
@@ -987,7 +989,7 @@ void string_list_add_refs_from_colon_sep(struct string_list *list,
 				     STRING_LIST_SPLIT_NONEMPTY);
 
 	for (i = 0; i < split.nr; i++)
-		string_list_add_refs_by_glob(list, split.items[i].string);
+		string_list_add_refs_by_glob(r, list, split.items[i].string);
 
 	string_list_clear(&split, 0);
 	free(globs_copy);
@@ -1002,7 +1004,8 @@ static int notes_display_config(const char *k, const char *v,
 	if (*load_refs && !strcmp(k, "notes.displayref")) {
 		if (!v)
 			return config_error_nonbool(k);
-		string_list_add_refs_by_glob(&display_notes_refs, v);
+		string_list_add_refs_by_glob(the_repository,
+					     &display_notes_refs, v);
 	}
 
 	return 0;
@@ -1132,7 +1135,8 @@ void load_display_notes(struct display_notes_opt *opt)
 		string_list_append_nodup(&display_notes_refs, default_notes_ref(the_repository));
 		display_ref_env = getenv(GIT_NOTES_DISPLAY_REF_ENVIRONMENT);
 		if (display_ref_env) {
-			string_list_add_refs_from_colon_sep(&display_notes_refs,
+			string_list_add_refs_from_colon_sep(the_repository,
+							    &display_notes_refs,
 							    display_ref_env);
 			load_config_refs = 0;
 		} else
@@ -1144,7 +1148,8 @@ void load_display_notes(struct display_notes_opt *opt)
 	if (opt) {
 		struct string_list_item *item;
 		for_each_string_list_item(item, &opt->extra_notes_refs)
-			string_list_add_refs_by_glob(&display_notes_refs,
+			string_list_add_refs_by_glob(the_repository,
+						     &display_notes_refs,
 						     item->string);
 	}
 
diff --git a/notes.h b/notes.h
index 0f50020816..b571ecede4 100644
--- a/notes.h
+++ b/notes.h
@@ -327,14 +327,16 @@ struct notes_tree **load_notes_trees(struct repository *r,
 /*
  * Add all refs that match 'glob' to the 'list'.
  */
-void string_list_add_refs_by_glob(struct string_list *list, const char *glob);
+void string_list_add_refs_by_glob(struct repository *r,
+				  struct string_list *list, const char *glob);
 
 /*
  * Add all refs from a colon-separated glob list 'globs' to the end of
  * 'list'.  Empty components are ignored.  This helper is used to
  * parse GIT_NOTES_DISPLAY_REF style environment variables.
  */
-void string_list_add_refs_from_colon_sep(struct string_list *list,
+void string_list_add_refs_from_colon_sep(struct repository *r,
+					 struct string_list *list,
 					 const char *globs);
 
 /* Expand inplace a note ref like "foo" or "notes/foo" into "refs/notes/foo" */
-- 
2.56.0
[Outreachy PATCH 5/6] notes: pass the repository to the combine_notes callbacks
#2461
Author: Okhuomon Ajayi
Date: Thu, 05 Nov 2026 20:33
190 lines
18087 bytes
combine_notes_concatenate() and combine_notes_cat_sort_uniq() read
and write note blobs in the_repository, even when the notes tree
belongs to another repository. The callbacks are only called from
note_tree_insert(), which has the tree.

Pass the tree's repository to all combine_notes callbacks. Also make
copy_note() use the tree's hash algorithm for its null object ID.

Signed-off-by: Okhuomon Ajayi <okhuomonajayi54@gmail.com>
---
 notes.c | 34 ++++++++++++++++++++--------------
 notes.h | 23 ++++++++++++++---------
 2 files changed, 34 insertions(+), 23 deletions(-)

diff --git a/notes.c b/notes.c
index cff63a4410..d675562bf6 100644
--- a/notes.c
+++ b/notes.c
@@ -279,7 +279,7 @@ static int note_tree_insert(struct notes_tree *t, struct int_node *tree,
 					return 0;
 				}
 
-				ret = combine_notes(&l->val_oid,
+				ret = combine_notes(t->repo, &l->val_oid,
 						    &entry->val_oid);
 				if (!ret && is_null_oid(&l->val_oid))
 					note_tree_remove(t, tree, n, entry);
@@ -816,7 +816,8 @@ static int prune_notes_helper(const struct object_id *object_oid,
 	return 0;
 }
 
-int combine_notes_concatenate(struct object_id *cur_oid,
+int combine_notes_concatenate(struct repository *r,
+			      struct object_id *cur_oid,
 			      const struct object_id *new_oid)
 {
 	char *cur_msg = NULL, *new_msg = NULL, *buf;
@@ -827,14 +828,14 @@ int combine_notes_concatenate(struct object_id *cur_oid,
 
 	/* read in both note blob objects */
 	if (!is_null_oid(new_oid))
-		new_msg = odb_read_object(the_repository->objects, new_oid,
+		new_msg = odb_read_object(r->objects, new_oid,
 					  &new_type, &new_len);
 	if (!new_msg || !new_len || new_type != OBJ_BLOB) {
 		free(new_msg);
 		return 0;
 	}
 	if (!is_null_oid(cur_oid))
-		cur_msg = odb_read_object(the_repository->objects, cur_oid,
+		cur_msg = odb_read_object(r->objects, cur_oid,
 					  &cur_type, &cur_len);
 	if (!cur_msg || !cur_len || cur_type != OBJ_BLOB) {
 		free(cur_msg);
@@ -858,20 +859,22 @@ int combine_notes_concatenate(struct object_id *cur_oid,
 	free(new_msg);
 
 	/* create a new blob object from buf */
-	ret = odb_write_object(the_repository->objects, buf,
+	ret = odb_write_object(r->objects, buf,
 			       buf_len, OBJ_BLOB, cur_oid);
 	free(buf);
 	return ret;
 }
 
-int combine_notes_overwrite(struct object_id *cur_oid,
+int combine_notes_overwrite(struct repository *r UNUSED,
+			    struct object_id *cur_oid,
 			    const struct object_id *new_oid)
 {
 	oidcpy(cur_oid, new_oid);
 	return 0;
 }
 
-int combine_notes_ignore(struct object_id *cur_oid UNUSED,
+int combine_notes_ignore(struct repository *r UNUSED,
+			 struct object_id *cur_oid UNUSED,
 			 const struct object_id *new_oid UNUSED)
 {
 	return 0;
@@ -881,7 +884,8 @@ int combine_notes_ignore(struct object_id *cur_oid UNUSED,
  * Add the lines from the named object to list, with trailing
  * newlines removed.
  */
-static int string_list_add_note_lines(struct string_list *list,
+static int string_list_add_note_lines(struct repository *r,
+				      struct string_list *list,
 				      const struct object_id *oid)
 {
 	char *data;
@@ -892,7 +896,7 @@ static int string_list_add_note_lines(struct string_list *list,
 		return 0;
 
 	/* read_sha1_file NUL-terminates */
-	data = odb_read_object(the_repository->objects, oid, &t, &len);
+	data = odb_read_object(r->objects, oid, &t, &len);
 	if (t != OBJ_BLOB || !data || !len) {
 		free(data);
 		return t != OBJ_BLOB || !data;
@@ -918,7 +922,8 @@ static int string_list_join_lines_helper(struct string_list_item *item,
 	return 0;
 }
 
-int combine_notes_cat_sort_uniq(struct object_id *cur_oid,
+int combine_notes_cat_sort_uniq(struct repository *r,
+				struct object_id *cur_oid,
 				const struct object_id *new_oid)
 {
 	struct string_list sort_uniq_list = STRING_LIST_INIT_DUP;
@@ -926,9 +931,9 @@ int combine_notes_cat_sort_uniq(struct object_id *cur_oid,
 	int ret = 1;
 
 	/* read both note blob objects into unique_lines */
-	if (string_list_add_note_lines(&sort_uniq_list, cur_oid))
+	if (string_list_add_note_lines(r, &sort_uniq_list, cur_oid))
 		goto out;
-	if (string_list_add_note_lines(&sort_uniq_list, new_oid))
+	if (string_list_add_note_lines(r, &sort_uniq_list, new_oid))
 		goto out;
 	string_list_remove_empty_items(&sort_uniq_list, 0);
 	string_list_sort_u(&sort_uniq_list, 0);
@@ -938,7 +943,7 @@ int combine_notes_cat_sort_uniq(struct object_id *cur_oid,
 				 string_list_join_lines_helper, &buf))
 		goto out;
 
-	ret = odb_write_object(the_repository->objects, buf.buf,
+	ret = odb_write_object(r->objects, buf.buf,
 			       buf.len, OBJ_BLOB, cur_oid);
 
 out:
@@ -1382,7 +1387,8 @@ int copy_note(struct notes_tree *t,
 	if (note)
 		return add_note(t, to_obj, note, combine_notes);
 	else if (existing_note)
-		return add_note(t, to_obj, null_oid(the_hash_algo), combine_notes);
+		return add_note(t, to_obj, null_oid(t->repo->hash_algo),
+				combine_notes);
 
 	return 0;
 }
diff --git a/notes.h b/notes.h
index b571ecede4..6d6f6068d8 100644
--- a/notes.h
+++ b/notes.h
@@ -13,10 +13,10 @@ struct strbuf;
  * When adding a new note annotating the same object as an existing note, it is
  * up to the caller to decide how to combine the two notes. The decision is
  * made by passing in a function of the following form. The function accepts
- * two object_ids -- of the existing note and the new note, respectively. The
- * function then combines the notes in whatever way it sees fit, and writes the
- * resulting oid into the first argument (cur_oid). A non-zero return
- * value indicates failure.
+ * the repository the notes live in and two object_ids -- of the existing
+ * note and the new note, respectively. The function then combines the notes
+ * in whatever way it sees fit, and writes the resulting oid into cur_oid.
+ * A non-zero return value indicates failure.
  *
  * The two given object_ids shall both be non-NULL and different from each
  * other. Either of them (but not both) may be == null_oid, which indicates an
@@ -27,17 +27,22 @@ struct strbuf;
  * combine_notes_concatenate(), which appends the contents of the new note to
  * the contents of the existing note.
  */
-typedef int (*combine_notes_fn)(struct object_id *cur_oid,
+typedef int (*combine_notes_fn)(struct repository *r,
+				struct object_id *cur_oid,
 				const struct object_id *new_oid);
 
 /* Common notes combinators */
-int combine_notes_concatenate(struct object_id *cur_oid,
+int combine_notes_concatenate(struct repository *r,
+			      struct object_id *cur_oid,
 			      const struct object_id *new_oid);
-int combine_notes_overwrite(struct object_id *cur_oid,
+int combine_notes_overwrite(struct repository *r,
+			    struct object_id *cur_oid,
 			    const struct object_id *new_oid);
-int combine_notes_ignore(struct object_id *cur_oid,
+int combine_notes_ignore(struct repository *r,
+			 struct object_id *cur_oid,
 			 const struct object_id *new_oid);
-int combine_notes_cat_sort_uniq(struct object_id *cur_oid,
+int combine_notes_cat_sort_uniq(struct repository *r,
+				struct object_id *cur_oid,
 				const struct object_id *new_oid);
 
 /*
-- 
2.56.0
[Outreachy PATCH 6/6] notes-utils: use the given repository
#2463
Author: Okhuomon Ajayi
Date: Thu, 05 Nov 2026 20:33
159 lines
16580 bytes
create_notes_commit() and commit_notes() take a repository, but
still read and update the notes ref in the_repository.
init_copy_notes_for_rewrite() does not take a repository at all:
it reads config and loads notes trees from the_repository.

Pass the repository through. The config callback keeps it on
struct notes_rewrite_cfg. The sequencer passes its repository;
am and notes pass the_repository for now. notes-utils.c no
longer uses the_repository, so drop USE_THE_REPOSITORY_VARIABLE.

Signed-off-by: Okhuomon Ajayi <okhuomonajayi54@gmail.com>
---
 builtin/am.c    |  2 +-
 builtin/notes.c |  2 +-
 notes-utils.c   | 21 ++++++++++-----------
 notes-utils.h   |  4 +++-
 sequencer.c     |  2 +-
 5 files changed, 16 insertions(+), 15 deletions(-)

diff --git a/builtin/am.c b/builtin/am.c
index e9623b8307..daa4b601b6 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -536,7 +536,7 @@ static int copy_notes_for_rebase(const struct am_state *state)
 
 	assert(state->rebasing);
 
-	c = init_copy_notes_for_rewrite("rebase");
+	c = init_copy_notes_for_rewrite(the_repository, "rebase");
 	if (!c)
 		return 0;
 
diff --git a/builtin/notes.c b/builtin/notes.c
index 7e7dff6672..a32af68928 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -366,7 +366,7 @@ static int notes_copy_from_stdin(int force, const char *rewrite_cmd)
 	const char *msg = "Notes added by 'git notes copy'";
 
 	if (rewrite_cmd) {
-		c = init_copy_notes_for_rewrite(rewrite_cmd);
+		c = init_copy_notes_for_rewrite(the_repository, rewrite_cmd);
 		if (!c)
 			return 0;
 	} else {
diff --git a/notes-utils.c b/notes-utils.c
index 70c619269e..7e9262411d 100644
--- a/notes-utils.c
+++ b/notes-utils.c
@@ -1,5 +1,3 @@
-#define USE_THE_REPOSITORY_VARIABLE
-
 #include "git-compat-util.h"
 #include "config.h"
 #include "commit.h"
@@ -26,7 +24,8 @@ void create_notes_commit(struct repository *r,
 	if (!parents) {
 		/* Deduce parent commit from t->ref */
 		struct object_id parent_oid;
-		if (!refs_read_ref(get_main_ref_store(the_repository), t->ref, &parent_oid)) {
+		if (!refs_read_ref(get_main_ref_store(r), t->ref,
+				   &parent_oid)) {
 			struct commit *parent = lookup_commit(r, &parent_oid);
 			if (repo_parse_commit(r, parent))
 				die("Failed to find/parse commit %s", t->ref);
@@ -61,7 +60,7 @@ void commit_notes(struct repository *r, struct notes_tree *t, const char *msg)
 
 	create_notes_commit(r, t, NULL, buf.buf, buf.len, &commit_oid);
 	strbuf_insertstr(&buf, 0, "notes: ");
-	refs_update_ref(get_main_ref_store(the_repository), buf.buf,
+	refs_update_ref(get_main_ref_store(r), buf.buf,
 			t->update_ref, &commit_oid, NULL, 0,
 			UPDATE_REFS_DIE_ON_ERR);
 
@@ -123,8 +122,7 @@ static int notes_rewrite_config(const char *k, const char *v,
 		/* note that a refs/ prefix is implied in the
 		 * underlying for_each_glob_ref */
 		if (starts_with(v, "refs/notes/"))
-			string_list_add_refs_by_glob(the_repository,
-						     c->refs, v);
+			string_list_add_refs_by_glob(c->repo, c->refs, v);
 		else
 			warning(_("Refusing to rewrite notes in %s"
 				" (outside of refs/notes/)"), v);
@@ -135,11 +133,13 @@ static int notes_rewrite_config(const char *k, const char *v,
 }
 
 
-struct notes_rewrite_cfg *init_copy_notes_for_rewrite(const char *cmd)
+struct notes_rewrite_cfg *init_copy_notes_for_rewrite(struct repository *r,
+						      const char *cmd)
 {
 	struct notes_rewrite_cfg *c = xmalloc(sizeof(struct notes_rewrite_cfg));
 	const char *rewrite_mode_env = getenv(GIT_NOTES_REWRITE_MODE_ENVIRONMENT);
 	const char *rewrite_refs_env = getenv(GIT_NOTES_REWRITE_REF_ENVIRONMENT);
+	c->repo = r;
 	c->cmd = cmd;
 	c->enabled = 1;
 	c->combine = combine_notes_concatenate;
@@ -161,18 +161,17 @@ struct notes_rewrite_cfg *init_copy_notes_for_rewrite(const char *cmd)
 	}
 	if (rewrite_refs_env) {
 		c->refs_from_env = 1;
-		string_list_add_refs_from_colon_sep(the_repository, c->refs,
+		string_list_add_refs_from_colon_sep(r, c->refs,
 						    rewrite_refs_env);
 	}
-	repo_config(the_repository, notes_rewrite_config, c);
+	repo_config(r, notes_rewrite_config, c);
 	if (!c->enabled || !c->refs->nr) {
 		string_list_clear(c->refs, 0);
 		free(c->refs);
 		free(c);
 		return NULL;
 	}
-	c->trees = load_notes_trees(the_repository, c->refs,
-				    NOTES_INIT_WRITABLE);
+	c->trees = load_notes_trees(r, c->refs, NOTES_INIT_WRITABLE);
 	string_list_clear(c->refs, 0);
 	free(c->refs);
 	return c;
diff --git a/notes-utils.h b/notes-utils.h
index c54b1fe141..14dd16f0ea 100644
--- a/notes-utils.h
+++ b/notes-utils.h
@@ -35,6 +35,7 @@ enum notes_merge_strategy {
 };
 
 struct notes_rewrite_cfg {
+	struct repository *repo;
 	struct notes_tree **trees;
 	const char *cmd;
 	int enabled;
@@ -45,7 +46,8 @@ struct notes_rewrite_cfg {
 };
 
 int parse_notes_merge_strategy(const char *v, enum notes_merge_strategy *s);
-struct notes_rewrite_cfg *init_copy_notes_for_rewrite(const char *cmd);
+struct notes_rewrite_cfg *init_copy_notes_for_rewrite(struct repository *r,
+						      const char *cmd);
 int copy_note_for_rewrite(struct notes_rewrite_cfg *c,
 			  const struct object_id *from_obj, const struct object_id *to_obj);
 void finish_copy_notes_for_rewrite(struct repository *r,
diff --git a/sequencer.c b/sequencer.c
index 508ec71792..a40243c56b 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -1366,7 +1366,7 @@ void commit_post_rewrite(struct repository *r,
 {
 	struct notes_rewrite_cfg *cfg;
 
-	cfg = init_copy_notes_for_rewrite("amend");
+	cfg = init_copy_notes_for_rewrite(r, "amend");
 	if (cfg) {
 		/* we are amending, so old_head is not NULL */
 		copy_note_for_rewrite(cfg, &old_head->object.oid, new_head);
-- 
2.56.0
Re: [Outreachy PATCH 5/6] notes: pass the repository to the combine_notes callbacks
#2692
Author: Okhuomon Ajayi
Date: Mon, 09 Nov 2026 10:11
19 lines
12449 bytes
Patrick Steinhardt <ps@pks.im> writes:

> Hmm. I was hoping that at the end of this series we'd also get rid of
> `USE_THE_REPOSITORY_VARIABLE` in "notes.c". Any reason why you decided
> to not go all the way?

I limited the series to code that already has a notes tree. The
rest needs more than that, the display notes code keeps its state
in globals, and log, format-patch, diff-tree and format-rev are
given a repository but do not pass it on. format_note() falls
back to the global default_notes_tree, where I wasn't sure which
direction to take, and expand_loose_notes_ref() only takes a
strbuf. The hash-size helpers are simpler, I just left them on
the global.

Thanks,

Okhuomon
Re: [Outreachy PATCH 1/6] notes: store the repository in struct notes_tree
#2695
Author: Okhuomon Ajayi
Date: Mon, 09 Nov 2026 10:27
25 lines
12704 bytes
Patrick Steinhardt <ps@pks.im> writes:

> I think this function should continue to receive `struct notes_tree` as
> first parameter, as this is the subsystem it belongs to. While at it,
> and as we already have to adjust all callers anyway, we might rename the
> function to `notes_tree_init()`.

I put the repository first because most functions take it as their
first argument, but you're right that this one belongs to the notes
tree. I'll put the tree first and rename it to notes_tree_init().

> Okay, here the arguments make sense. We could likewise rename to
> `notes_tree_load()` though.

I'll rename it to notes_tree_load() too.

> Oof, this interface is cursed, it really should be refactored to not
> have implicit global state. Arguably, this default notes tree should be
> either dropped, or it should be stored as part of a repository.

Agreed. It is the same global I mentioned in my reply to 5/6.

Thanks,
Okhuomon
Re: [Outreachy PATCH 5/6] notes: pass the repository to the combine_notes callbacks
#3074
Author: Okhuomon Ajayi
Date: Fri, 13 Nov 2026 11:40
21 lines
12623 bytes
Patrick, a quick ping on this series.

I replied to your 1/6 and 5/6 comments  on. The v2 I have
already renames init_notes() to notes_tree_init(), with the tree first,
and load_notes_trees() to notes_tree_load(). I left
USE_THE_REPOSITORY_VARIABLE in notes.c, for the reasons in the 5/6
reply.
Let me know if that scope is what you had in mind before I send it.

Thanks,
Okhuomon

On Mon, Nov 9, 2026 at 10:18 AM Patrick Steinhardt <ps@pks.im> wrote:

> Hmm. I was hoping that at the end of this series we'd also get rid of
> `USE_THE_REPOSITORY_VARIABLE` in "notes.c". Any reason why you decided
> to not go all the way?
>
> Patrick
Re: [Outreachy PATCH 5/6] notes: pass the repository to the combine_notes callbacks
#3608
Author: Okhuomon Ajayi
Date: Mon, 23 Nov 2026 09:23
33 lines
12995 bytes
Hi Patrick,

Gentle ping on the scope question above. If it looks fine to you, I'll
send v2 rebased on current master.

Thanks,
Okhuomon


On Fri, Nov 13, 2026 at 12:40 PM Okhuomon Ajayi
<okhuomonajayi54@gmail.com> wrote:
>
> Patrick, a quick ping on this series.
>
> I replied to your 1/6 and 5/6 comments  on. The v2 I have
> already renames init_notes() to notes_tree_init(), with the tree first,
> and load_notes_trees() to notes_tree_load(). I left
> USE_THE_REPOSITORY_VARIABLE in notes.c, for the reasons in the 5/6
> reply.
> Let me know if that scope is what you had in mind before I send it.
>
> Thanks,
> Okhuomon
>
> On Mon, Nov 9, 2026 at 10:18 AM Patrick Steinhardt <ps@pks.im> wrote:
>
> > Hmm. I was hoping that at the end of this series we'd also get rid of
> > `USE_THE_REPOSITORY_VARIABLE` in "notes.c". Any reason why you decided
> > to not go all the way?
> >
> > Patrick
Re: [Outreachy PATCH 5/6] notes: pass the repository to the combine_notes callbacks
#3708
Author: Christian Couder
Date: Tue, 24 Nov 2026 15:26
16 lines
12619 bytes
On Thu, Nov 5, 2026 at 9:34 PM Okhuomon Ajayi <okhuomonajayi54@gmail.com> wrote:
>
> combine_notes_concatenate() and combine_notes_cat_sort_uniq() read
> and write note blobs in the_repository, even when the notes tree
> belongs to another repository. The callbacks are only called from
> note_tree_insert(), which has the tree.
>
> Pass the tree's repository to all combine_notes callbacks. Also make
> copy_note() use the tree's hash algorithm for its null object ID.

It seems to me that the copy_note() change is not related to the
combine_notes callbacks, so if you moved that change to the second or
third patch in your series, the title of this commit would better suit
its content.
Re: [Outreachy PATCH 5/6] notes: pass the repository to the combine_notes callbacks
#3709
Author: Christian Couder
Date: Tue, 24 Nov 2026 15:28
42 lines
13637 bytes
On Mon, Nov 9, 2026 at 11:12 AM Okhuomon Ajayi
<okhuomonajayi54@gmail.com> wrote:
>
> Patrick Steinhardt <ps@pks.im> writes:
>
> > Hmm. I was hoping that at the end of this series we'd also get rid of
> > `USE_THE_REPOSITORY_VARIABLE` in "notes.c". Any reason why you decided
> > to not go all the way?
>
> I limited the series to code that already has a notes tree. The
> rest needs more than that, the display notes code keeps its state
> in globals, and log, format-patch, diff-tree and format-rev are
> given a repository but do not pass it on. format_note() falls
> back to the global default_notes_tree, where I wasn't sure which
> direction to take, and expand_loose_notes_ref() only takes a
> strbuf. The hash-size helpers are simpler, I just left them on
> the global.

I understand that this series was started after discussing a previous
patch focused on "notes-utils.[c,h]", but it's a bit strange that the
changes it makes in "notes.c" are limited in some ways, while
USE_THE_REPOSITORY_VARIABLE is removed from "notes-utils.[c,h]" in
patch 6/6.

For example, the hash-size helpers you left on the global are reached
from code in "notes-utils.c", like create_notes_commit() through
write_notes_tree().

I think it might be more coherent and easier to move forward if this
series was limited to its first 5 patches and if the cover letter said
right away that it's only a preparatory series. It does a big part of
the work in "notes.[c,h]" and its callers (and does it quite well),
but it doesn't go all the way in the notes subsystem. The cover letter
could also list what is left to do in "notes.c", "notes-utils.[c,h]"
and "notes-merge.[c,h]" and why, and then say that it can be addressed
by future series.

So I would encourage you to send a v2 taking into account the changes
suggested by the reviewers but limited to the first 5 patches.

Thanks.
Re: [Outreachy PATCH 5/6] notes: pass the repository to the combine_notes callbacks
#3711
Author: Okhuomon Ajayi
Date: Tue, 24 Nov 2026 15:49
33 lines
13412 bytes
On Tue, Nov 24, 2026 at 4:27 PM Christian Couder
<christian.couder@gmail.com> wrote:
> It seems to me that the copy_note() change is not related to the
> combine_notes callbacks, so if you moved that change to the second or
> third patch in your series, the title of this commit would better suit
> its content.

Looking at it again, the copy_note() change really doesn't belong with
the combine_notes callbacks. I'll move it into the writing and pruning
patch (patch 3) in v2, since copy_note() modifies the tree through
add_note(), and adjust the commit title to match.

Okhuomon

On Tue, Nov 24, 2026 at 4:27 PM Christian Couder
<christian.couder@gmail.com> wrote:
>
> On Thu, Nov 5, 2026 at 9:34 PM Okhuomon Ajayi <okhuomonajayi54@gmail.com> wrote:
> >
> > combine_notes_concatenate() and combine_notes_cat_sort_uniq() read
> > and write note blobs in the_repository, even when the notes tree
> > belongs to another repository. The callbacks are only called from
> > note_tree_insert(), which has the tree.
> >
> > Pass the tree's repository to all combine_notes callbacks. Also make
> > copy_note() use the tree's hash algorithm for its null object ID.
>
> It seems to me that the copy_note() change is not related to the
> combine_notes callbacks, so if you moved that change to the second or
> third patch in your series, the title of this commit would better suit
> its content.
Re: [Outreachy PATCH 5/6] notes: pass the repository to the combine_notes callbacks
#3712
Author: Okhuomon Ajayi
Date: Tue, 24 Nov 2026 16:13
69 lines
15460 bytes
On Tue, Nov 24, 2026 at 4:28 PM Christian Couder
<christian.couder@gmail.com> wrote:
> I think it might be more coherent and easier to move forward if this
> series was limited to its first 5 patches and if the cover letter said
> right away that it's only a preparatory series. [...] The cover letter
> could also list what is left to do in "notes.c", "notes-utils.[c,h]"
> and "notes-merge.[c,h]" and why, and then say that it can be addressed
> by future series.

That makes sense, thanks. I'll send a v2 limited to the first 5 patches
and say in the cover letter that it's a preparatory series: it does the
bulk of the work in notes.[c,h] and its callers but intentionally
doesn't finish the subsystem.

I'll also list in the cover letter what's left to do in notes.c,
notes-utils.[c,h] and notes-merge.[c,h], including the hash-size helpers
still on the global that are reached through create_notes_commit() ->
write_notes_tree(), and note that it can be handled by future series.

Thanks again for the detailed review.

Okhuomon

On Tue, Nov 24, 2026 at 4:28 PM Christian Couder
<christian.couder@gmail.com> wrote:
>
> On Mon, Nov 9, 2026 at 11:12 AM Okhuomon Ajayi
> <okhuomonajayi54@gmail.com> wrote:
> >
> > Patrick Steinhardt <ps@pks.im> writes:
> >
> > > Hmm. I was hoping that at the end of this series we'd also get rid of
> > > `USE_THE_REPOSITORY_VARIABLE` in "notes.c". Any reason why you decided
> > > to not go all the way?
> >
> > I limited the series to code that already has a notes tree. The
> > rest needs more than that, the display notes code keeps its state
> > in globals, and log, format-patch, diff-tree and format-rev are
> > given a repository but do not pass it on. format_note() falls
> > back to the global default_notes_tree, where I wasn't sure which
> > direction to take, and expand_loose_notes_ref() only takes a
> > strbuf. The hash-size helpers are simpler, I just left them on
> > the global.
>
> I understand that this series was started after discussing a previous
> patch focused on "notes-utils.[c,h]", but it's a bit strange that the
> changes it makes in "notes.c" are limited in some ways, while
> USE_THE_REPOSITORY_VARIABLE is removed from "notes-utils.[c,h]" in
> patch 6/6.
>
> For example, the hash-size helpers you left on the global are reached
> from code in "notes-utils.c", like create_notes_commit() through
> write_notes_tree().
>
> I think it might be more coherent and easier to move forward if this
> series was limited to its first 5 patches and if the cover letter said
> right away that it's only a preparatory series. It does a big part of
> the work in "notes.[c,h]" and its callers (and does it quite well),
> but it doesn't go all the way in the notes subsystem. The cover letter
> could also list what is left to do in "notes.c", "notes-utils.[c,h]"
> and "notes-merge.[c,h]" and why, and then say that it can be addressed
> by future series.
>
> So I would encourage you to send a v2 taking into account the changes
> suggested by the reviewers but limited to the first 5 patches.
>
> Thanks.
[PATCH v2 0/5] notes: start passing the repository through notes.[ch]
#3715
Author: Okhuomon Ajayi
Date: Tue, 24 Nov 2026 17:21
107 lines
15320 bytes
This is a preparatory series. It makes the code in notes.[c,h] and its
direct callers work on the repository stored in struct notes_tree instead
of the_repository. It deliberately does not convert the whole notes
subsystem yet; it does the bulk of the work in notes.[c,h] and leaves the
rest for future series.

What it does:
 - stores the repository in struct notes_tree;
 - uses the tree's repository when reading, writing and pruning notes;
 - passes the repository to the ref glob helpers and the combine_notes
   callbacks.

What is left for future series:
 - notes.c: the display-notes code keeps its state in globals, and log,
   format-patch, diff-tree and format-rev are given a repository but do
   not pass it on. format_note() still falls back to the global
   default_notes_tree, and expand_loose_notes_ref() only takes a strbuf.
   The hash-size helpers are also still on the global.
 - notes-utils.[c,h]: still use the_repository. And the hash-size helpers
   still on the global are reached from here, through create_notes_commit()
   -> write_notes_tree(), so converting notes-utils is tied to converting
   those helpers too.
 - notes-merge.[c,h]: still work on the global repository.

Changes since v1:
 - Dropped the final patch (notes-utils: use the given repository) so the
   series stays within notes.[c,h] and its callers, and reframed it as a
   preparatory series.
 - Moved the copy_note() change out of the combine_notes patch into the
   writing-and-pruning patch, where it belongs, and updated both commit
   messages.

Okhuomon Ajayi (5):
  notes: store the repository in struct notes_tree
  notes: use the tree's repository when reading notes
  notes: use the tree's repository when writing and pruning
  notes: pass the repository to the ref glob helpers
  notes: pass the repository to the combine_notes callbacks

 builtin/notes.c |   8 ++-
 notes-cache.c   |   3 +-
 notes-utils.c   |   9 ++-
 notes.c         | 164 ++++++++++++++++++++++++++++--------------------
 notes.h         |  40 +++++++-----
 5 files changed, 134 insertions(+), 90 deletions(-)

Range-diff against v1:
1:  79ca75340a = 1:  5ad0f1bd62 notes: store the repository in struct notes_tree
2:  9692b4f18c = 2:  1018419720 notes: use the tree's repository when reading notes
3:  f87b683aeb ! 3:  67a2942c09 notes: use the tree's repository when writing and pruning
    @@ Commit message
         the repository, passed down from the tree. prune_notes() hands
         the repository to its callback in a small struct.
     
    +    copy_note() also writes through the tree, by calling add_note(),
    +    so it uses the tree's hash algorithm for its null object ID.
    +
         Signed-off-by: Okhuomon Ajayi <okhuomonajayi54@gmail.com>
     
      ## notes.c ##
    @@ notes.c: int write_notes_tree(struct notes_tree *t, struct object_id *result)
      	}
      }
      
    +@@ notes.c: int copy_note(struct notes_tree *t,
    + 	if (note)
    + 		return add_note(t, to_obj, note, combine_notes);
    + 	else if (existing_note)
    +-		return add_note(t, to_obj, null_oid(the_hash_algo), combine_notes);
    ++		return add_note(t, to_obj, null_oid(t->repo->hash_algo),
    ++				combine_notes);
    + 
    + 	return 0;
    + }
4:  469aa752ab = 4:  7ea6c0e5a2 notes: pass the repository to the ref glob helpers
5:  517c056f8d ! 5:  ff8cf4d22a notes: pass the repository to the combine_notes callbacks
    @@ Commit message
         belongs to another repository. The callbacks are only called from
         note_tree_insert(), which has the tree.
     
    -    Pass the tree's repository to all combine_notes callbacks. Also make
    -    copy_note() use the tree's hash algorithm for its null object ID.
    +    Pass the tree's repository to all combine_notes callbacks.
     
         Signed-off-by: Okhuomon Ajayi <okhuomonajayi54@gmail.com>
     
    @@ notes.c: int combine_notes_cat_sort_uniq(struct object_id *cur_oid,
      			       buf.len, OBJ_BLOB, cur_oid);
      
      out:
    -@@ notes.c: int copy_note(struct notes_tree *t,
    - 	if (note)
    - 		return add_note(t, to_obj, note, combine_notes);
    - 	else if (existing_note)
    --		return add_note(t, to_obj, null_oid(the_hash_algo), combine_notes);
    -+		return add_note(t, to_obj, null_oid(t->repo->hash_algo),
    -+				combine_notes);
    - 
    - 	return 0;
    - }
     
      ## notes.h ##
     @@ notes.h: struct strbuf;
6:  75b58d578b < -:  ---------- notes-utils: use the given repository
-- 
2.56.0
[PATCH v2 1/5] notes: store the repository in struct notes_tree
#3716
Author: Okhuomon Ajayi
Date: Tue, 24 Nov 2026 17:21
230 lines
19549 bytes
A notes tree is always read from one repository, but the tree
does not record which one. Later code has to fall back to
the_repository.

Store the repository on the tree. Rename init_notes() to
notes_tree_init() and load_notes_trees() to notes_tree_load(),
since every caller changes anyway. notes_tree_init() takes the
tree first and the repository second, and saves the repository
in t->repo. notes_tree_load() takes the repository first.
notes_cache_init() passes the repository it was given. Other
callers pass the_repository for now.

Signed-off-by: Okhuomon Ajayi <okhuomonajayi54@gmail.com>
---
 builtin/notes.c |  8 +++++---
 notes-cache.c   |  3 ++-
 notes-utils.c   |  3 ++-
 notes.c         | 30 ++++++++++++++++++------------
 notes.h         | 11 +++++++----
 5 files changed, 34 insertions(+), 21 deletions(-)

diff --git a/builtin/notes.c b/builtin/notes.c
index 9f1f0ec840..725280c785 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -370,7 +370,8 @@ static int notes_copy_from_stdin(int force, const char *rewrite_cmd)
 		if (!c)
 			return 0;
 	} else {
-		init_notes(NULL, NULL, NULL, NOTES_INIT_WRITABLE);
+		notes_tree_init(NULL, the_repository, NULL, NULL,
+				NOTES_INIT_WRITABLE);
 		t = &default_notes_tree;
 	}
 
@@ -420,7 +421,7 @@ static struct notes_tree *init_notes_check(const char *subcommand,
 {
 	struct notes_tree *t;
 	const char *ref;
-	init_notes(NULL, NULL, NULL, flags);
+	notes_tree_init(NULL, the_repository, NULL, NULL, flags);
 	t = &default_notes_tree;
 
 	ref = (flags & NOTES_INIT_WRITABLE) ? t->update_ref : t->ref;
@@ -841,7 +842,8 @@ static int merge_commit(struct notes_merge_options *o)
 	else
 		oidclr(&parent_oid, the_repository->hash_algo);
 
-	init_notes(&t, "NOTES_MERGE_PARTIAL", combine_notes_overwrite, 0);
+	notes_tree_init(&t, the_repository, "NOTES_MERGE_PARTIAL",
+			combine_notes_overwrite, 0);
 
 	o->local_ref = local_ref_to_free =
 		refs_resolve_refdup(get_main_ref_store(the_repository),
diff --git a/notes-cache.c b/notes-cache.c
index 74cef802bd..b9a2940435 100644
--- a/notes-cache.c
+++ b/notes-cache.c
@@ -50,7 +50,8 @@ void notes_cache_init(struct repository *r, struct notes_cache *c,
 	strbuf_addf(&ref, "refs/notes/%s", name);
 	if (!notes_cache_match_validity(r, ref.buf, validity))
 		flags |= NOTES_INIT_EMPTY;
-	init_notes(&c->tree, ref.buf, combine_notes_overwrite, flags);
+	notes_tree_init(&c->tree, r, ref.buf,
+			combine_notes_overwrite, flags);
 	strbuf_release(&ref);
 }
 
diff --git a/notes-utils.c b/notes-utils.c
index 5c1c75d5b8..ea43fedd43 100644
--- a/notes-utils.c
+++ b/notes-utils.c
@@ -169,7 +169,8 @@ struct notes_rewrite_cfg *init_copy_notes_for_rewrite(const char *cmd)
 		free(c);
 		return NULL;
 	}
-	c->trees = load_notes_trees(c->refs, NOTES_INIT_WRITABLE);
+	c->trees = notes_tree_load(the_repository, c->refs,
+				   NOTES_INIT_WRITABLE);
 	string_list_clear(c->refs, 0);
 	free(c->refs);
 	return c;
diff --git a/notes.c b/notes.c
index ec9c2cb150..b79fe65478 100644
--- a/notes.c
+++ b/notes.c
@@ -1012,8 +1012,9 @@ char *default_notes_ref(struct repository *repo)
 	return notes_ref;
 }
 
-void init_notes(struct notes_tree *t, const char *notes_ref,
-		combine_notes_fn combine_notes, int flags)
+void notes_tree_init(struct notes_tree *t, struct repository *r,
+		     const char *notes_ref, combine_notes_fn combine_notes,
+		     int flags)
 {
 	struct object_id oid, object_oid;
 	unsigned short mode;
@@ -1025,7 +1026,7 @@ void init_notes(struct notes_tree *t, const char *notes_ref,
 	assert(!t->initialized);
 
 	if (!notes_ref)
-		notes_ref = to_free = default_notes_ref(the_repository);
+		notes_ref = to_free = default_notes_ref(r);
 	update_ref_namespace(NAMESPACE_NOTES, xstrdup(notes_ref));
 
 	if (!combine_notes)
@@ -1034,6 +1035,7 @@ void init_notes(struct notes_tree *t, const char *notes_ref,
 	t->root = (struct int_node *) xcalloc(1, sizeof(struct int_node));
 	t->first_non_note = NULL;
 	t->prev_non_note = NULL;
+	t->repo = r;
 	t->ref = xstrdup(notes_ref);
 	t->update_ref = (flags & NOTES_INIT_WRITABLE) ? t->ref : NULL;
 	t->combine_notes = combine_notes;
@@ -1041,15 +1043,15 @@ void init_notes(struct notes_tree *t, const char *notes_ref,
 	t->dirty = 0;
 
 	if (flags & NOTES_INIT_EMPTY ||
-	    repo_get_oid_treeish(the_repository, notes_ref, &object_oid))
+	    repo_get_oid_treeish(r, notes_ref, &object_oid))
 		goto out;
-	if (flags & NOTES_INIT_WRITABLE && refs_read_ref(get_main_ref_store(the_repository), notes_ref, &object_oid))
+	if (flags & NOTES_INIT_WRITABLE && refs_read_ref(get_main_ref_store(r), notes_ref, &object_oid))
 		die("Cannot use notes ref %s", notes_ref);
-	if (get_tree_entry(the_repository, &object_oid, "", &oid, &mode))
+	if (get_tree_entry(r, &object_oid, "", &oid, &mode))
 		die("Failed to read notes tree referenced by %s (%s)",
 		    notes_ref, oid_to_hex(&object_oid));
 
-	oidclr(&root_tree.key_oid, the_repository->hash_algo);
+	oidclr(&root_tree.key_oid, r->hash_algo);
 	oidcpy(&root_tree.val_oid, &oid);
 	load_subtree(t, &root_tree, t->root, 0);
 
@@ -1057,7 +1059,8 @@ void init_notes(struct notes_tree *t, const char *notes_ref,
 	free(to_free);
 }
 
-struct notes_tree **load_notes_trees(struct string_list *refs, int flags)
+struct notes_tree **notes_tree_load(struct repository *r,
+				    struct string_list *refs, int flags)
 {
 	struct string_list_item *item;
 	int counter = 0;
@@ -1065,7 +1068,8 @@ struct notes_tree **load_notes_trees(struct string_list *refs, int flags)
 	ALLOC_ARRAY(trees, refs->nr + 1);
 	for_each_string_list_item(item, refs) {
 		struct notes_tree *t = xcalloc(1, sizeof(struct notes_tree));
-		init_notes(t, item->string, combine_notes_ignore, flags);
+		notes_tree_init(t, r, item->string,
+				combine_notes_ignore, flags);
 		trees[counter++] = t;
 	}
 	trees[counter] = NULL;
@@ -1136,7 +1140,8 @@ void load_display_notes(struct display_notes_opt *opt)
 						     item->string);
 	}
 
-	display_notes_trees = load_notes_trees(&display_notes_refs, 0);
+	display_notes_trees = notes_tree_load(the_repository,
+					      &display_notes_refs, 0);
 	string_list_clear(&display_notes_refs, 0);
 }
 
@@ -1270,7 +1275,8 @@ void free_notes(struct notes_tree *t)
  * Fill the given strbuf with the notes associated with the given object.
  *
  * If the given notes_tree structure is not initialized, it will be auto-
- * initialized to the default value (see documentation for init_notes() above).
+ * initialized to the default value (see documentation for
+ * notes_tree_init() above).
  * If the given notes_tree is NULL, the internal/default notes_tree will be
  * used instead.
  *
@@ -1290,7 +1296,7 @@ static void format_note(struct notes_tree *t, const struct object_id *object_oid
 	if (!t)
 		t = &default_notes_tree;
 	if (!t->initialized)
-		init_notes(t, NULL, NULL, 0);
+		notes_tree_init(t, the_repository, NULL, NULL, 0);
 
 	oid = get_note(t, object_oid);
 	if (!oid)
diff --git a/notes.h b/notes.h
index 6dc6d7b265..c81bc99446 100644
--- a/notes.h
+++ b/notes.h
@@ -50,6 +50,7 @@ int combine_notes_cat_sort_uniq(struct object_id *cur_oid,
  * simultaneously.
  */
 extern struct notes_tree {
+	struct repository *repo;
 	struct int_node *root;
 	struct non_note *first_non_note, *prev_non_note;
 	char *ref;
@@ -63,7 +64,7 @@ extern struct notes_tree {
  * Return the default notes ref.
  *
  * The default notes ref is the notes ref that is used when notes_ref == NULL
- * is passed to init_notes().
+ * is passed to notes_tree_init().
  *
  * This the first of the following to be defined:
  * 1. The '--ref' option to 'git notes', if given
@@ -107,8 +108,9 @@ char *default_notes_ref(struct repository *repo);
  * Precondition: The notes_tree structure is zeroed (this can be achieved with
  * memset(t, 0, sizeof(struct notes_tree)))
  */
-void init_notes(struct notes_tree *t, const char *notes_ref,
-		combine_notes_fn combine_notes, int flags);
+void notes_tree_init(struct notes_tree *t, struct repository *r,
+		     const char *notes_ref, combine_notes_fn combine_notes,
+		     int flags);
 
 /*
  * Add the given note object to the given notes_tree structure
@@ -319,7 +321,8 @@ void format_display_notes(const struct object_id *object_oid,
  * Load the notes tree from each ref listed in 'refs'.  The output is
  * an array of notes_tree*, terminated by a NULL.
  */
-struct notes_tree **load_notes_trees(struct string_list *refs, int flags);
+struct notes_tree **notes_tree_load(struct repository *r,
+				    struct string_list *refs, int flags);
 
 /*
  * Add all refs that match 'glob' to the 'list'.
-- 
2.56.0
[PATCH v2 2/5] notes: use the tree's repository when reading notes
#3717
Author: Okhuomon Ajayi
Date: Tue, 24 Nov 2026 17:21
88 lines
13970 bytes
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.

Signed-off-by: Okhuomon Ajayi <okhuomonajayi54@gmail.com>
---
 notes.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/notes.c b/notes.c
index b79fe65478..9cf71651ed 100644
--- a/notes.c
+++ b/notes.c
@@ -153,7 +153,7 @@ static struct leaf_node *note_tree_find(struct notes_tree *t,
 	void **p = note_tree_search(t, &tree, &n, key_sha1);
 	if (GET_PTR_TYPE(*p) == PTR_TYPE_NOTE) {
 		struct leaf_node *l = (struct leaf_node *) CLR_PTR_TYPE(*p);
-		if (hasheq(key_sha1, l->key_oid.hash, the_repository->hash_algo))
+		if (hasheq(key_sha1, l->key_oid.hash, t->repo->hash_algo))
 			return l;
 	}
 	return NULL;
@@ -357,7 +357,7 @@ static void add_non_note(struct notes_tree *t, char *path,
 	n->next = NULL;
 	n->path = path;
 	n->mode = mode;
-	oidread(&n->oid, sha1, the_repository->hash_algo);
+	oidread(&n->oid, sha1, t->repo->hash_algo);
 	t->prev_non_note = n;
 
 	if (!t->first_non_note) {
@@ -402,9 +402,9 @@ static void load_subtree(struct notes_tree *t, struct leaf_node *subtree,
 	void *buf;
 	struct tree_desc desc;
 	struct name_entry entry;
-	const unsigned hashsz = the_hash_algo->rawsz;
+	const unsigned hashsz = t->repo->hash_algo->rawsz;
 
-	buf = fill_tree_descriptor(the_repository, &desc, &subtree->val_oid);
+	buf = fill_tree_descriptor(t->repo, &desc, &subtree->val_oid);
 	if (!buf)
 		die("Could not read %s for notes-index",
 		     oid_to_hex(&subtree->val_oid));
@@ -462,8 +462,8 @@ static void load_subtree(struct notes_tree *t, struct leaf_node *subtree,
 		CALLOC_ARRAY(l, 1);
 		oidcpy(&l->key_oid, &object_oid);
 		oidcpy(&l->val_oid, &entry.oid);
-		oid_set_algo(&l->key_oid, the_hash_algo);
-		oid_set_algo(&l->val_oid, the_hash_algo);
+		oid_set_algo(&l->key_oid, t->repo->hash_algo);
+		oid_set_algo(&l->val_oid, t->repo->hash_algo);
 		if (note_tree_insert(t, node, n, l, type,
 				     combine_notes_concatenate))
 			die("Failed to load %s %s into notes tree "
@@ -493,7 +493,7 @@ static void load_subtree(struct notes_tree *t, struct leaf_node *subtree,
 				strbuf_addch(&non_note_path, '/');
 			}
 			strbuf_addstr(&non_note_path, entry.path);
-			oid_set_algo(&entry.oid, the_hash_algo);
+			oid_set_algo(&entry.oid, t->repo->hash_algo);
 			add_non_note(t, strbuf_detach(&non_note_path, NULL),
 				     entry.mode, entry.oid.hash);
 		}
@@ -1169,8 +1169,8 @@ int remove_note(struct notes_tree *t, const unsigned char *object_sha1)
 	if (!t)
 		t = &default_notes_tree;
 	assert(t->initialized);
-	oidread(&l.key_oid, object_sha1, the_repository->hash_algo);
-	oidclr(&l.val_oid, the_repository->hash_algo);
+	oidread(&l.key_oid, object_sha1, t->repo->hash_algo);
+	oidclr(&l.val_oid, t->repo->hash_algo);
 	note_tree_remove(t, t->root, 0, &l);
 	if (is_null_oid(&l.val_oid)) /* no note was removed */
 		return 1;
@@ -1302,7 +1302,7 @@ static void format_note(struct notes_tree *t, const struct object_id *object_oid
 	if (!oid)
 		return;
 
-	if (!(msg = odb_read_object(the_repository->objects, oid, &type, &msglen)) ||
+	if (!(msg = odb_read_object(t->repo->objects, oid, &type, &msglen)) ||
 	    type != OBJ_BLOB) {
 		free(msg);
 		return;
-- 
2.56.0
[PATCH v2 3/5] notes: use the tree's repository when writing and pruning
#3718
Author: Okhuomon Ajayi
Date: Tue, 24 Nov 2026 17:21
193 lines
17182 bytes
write_notes_tree() writes the notes tree into the_repository,
and prune_notes() looks for missing objects there too. Both
already have the notes tree.

Write through t->repo. tree_write_stack_finish_subtree() takes
the repository, passed down from the tree. prune_notes() hands
the repository to its callback in a small struct.

copy_note() also writes through the tree, by calling add_note(),
so it uses the tree's hash algorithm for its null object ID.

Signed-off-by: Okhuomon Ajayi <okhuomonajayi54@gmail.com>
---
 notes.c | 62 ++++++++++++++++++++++++++++++++++-----------------------
 1 file changed, 37 insertions(+), 25 deletions(-)

diff --git a/notes.c b/notes.c
index 9cf71651ed..9d653c757a 100644
--- a/notes.c
+++ b/notes.c
@@ -673,16 +673,17 @@ static void tree_write_stack_init_subtree(struct tree_write_stack *tws,
 	tws->path[1] = path[1];
 }
 
-static int tree_write_stack_finish_subtree(struct tree_write_stack *tws)
+static int tree_write_stack_finish_subtree(struct repository *r,
+					   struct tree_write_stack *tws)
 {
 	int ret;
 	struct tree_write_stack *n = tws->next;
 	struct object_id s;
 	if (n) {
-		ret = tree_write_stack_finish_subtree(n);
+		ret = tree_write_stack_finish_subtree(r, n);
 		if (ret)
 			return ret;
-		ret = odb_write_object(the_repository->objects, n->buf.buf,
+		ret = odb_write_object(r->objects, n->buf.buf,
 				       n->buf.len, OBJ_TREE, &s);
 		if (ret)
 			return ret;
@@ -695,9 +696,10 @@ static int tree_write_stack_finish_subtree(struct tree_write_stack *tws)
 	return 0;
 }
 
-static int write_each_note_helper(struct tree_write_stack *tws,
-		const char *path, unsigned int mode,
-		const struct object_id *oid)
+static int write_each_note_helper(struct repository *r,
+				  struct tree_write_stack *tws,
+				  const char *path, unsigned int mode,
+				  const struct object_id *oid)
 {
 	size_t path_len = strlen(path);
 	unsigned int n = 0;
@@ -711,7 +713,7 @@ static int write_each_note_helper(struct tree_write_stack *tws,
 	}
 
 	/* tws point to last matching tree_write_stack entry */
-	ret = tree_write_stack_finish_subtree(tws);
+	ret = tree_write_stack_finish_subtree(r, tws);
 	if (ret)
 		return ret;
 
@@ -733,6 +735,7 @@ static int write_each_note_helper(struct tree_write_stack *tws,
 }
 
 struct write_each_note_data {
+	struct repository *repo;
 	struct tree_write_stack *root;
 	struct non_note **nn_list;
 	struct non_note *nn_prev;
@@ -748,8 +751,8 @@ static int write_each_non_note_until(const char *note_path,
 		if (note_path && cmp == 0)
 			; /* do nothing, prefer note to non-note */
 		else {
-			ret = write_each_note_helper(d->root, n->path, n->mode,
-						     &n->oid);
+			ret = write_each_note_helper(d->repo, d->root, n->path,
+						     n->mode, &n->oid);
 			if (ret)
 				return ret;
 		}
@@ -779,7 +782,8 @@ static int write_each_note(const struct object_id *object_oid UNUSED,
 
 	/* Weave non-note entries into note entries */
 	return  write_each_non_note_until(note_path, d) ||
-		write_each_note_helper(d->root, note_path, mode, note_oid);
+		write_each_note_helper(d->repo, d->root, note_path, mode,
+				       note_oid);
 }
 
 struct note_delete_list {
@@ -787,23 +791,28 @@ struct note_delete_list {
 	const unsigned char *sha1;
 };
 
+struct prune_notes_data {
+	struct repository *repo;
+	struct note_delete_list *list;
+};
+
 static int prune_notes_helper(const struct object_id *object_oid,
 			      const struct object_id *note_oid UNUSED,
 			      char *note_path UNUSED,
 			      void *cb_data)
 {
-	struct note_delete_list **l = (struct note_delete_list **) cb_data;
+	struct prune_notes_data *d = cb_data;
 	struct note_delete_list *n;
 
-	if (odb_has_object(the_repository->objects, object_oid,
+	if (odb_has_object(d->repo->objects, object_oid,
 			   ODB_HAS_OBJECT_RECHECK_PACKED | ODB_HAS_OBJECT_FETCH_PROMISOR))
 		return 0; /* nothing to do for this note */
 
 	/* failed to find object => prune this note */
 	n = (struct note_delete_list *) xmalloc(sizeof(*n));
-	n->next = *l;
+	n->next = d->list;
 	n->sha1 = object_oid->hash;
-	*l = n;
+	d->list = n;
 	return 0;
 }
 
@@ -1214,6 +1223,7 @@ int write_notes_tree(struct notes_tree *t, struct object_id *result)
 	root.next = NULL; /* last forward entry in list is grounded */
 	strbuf_init(&root.buf, 256 * (32 + the_hash_algo->hexsz)); /* assume 256 entries */
 	root.path[0] = root.path[1] = '\0';
+	cb_data.repo = t->repo;
 	cb_data.root = &root;
 	cb_data.nn_list = &(t->first_non_note);
 	cb_data.nn_prev = NULL;
@@ -1223,8 +1233,8 @@ int write_notes_tree(struct notes_tree *t, struct object_id *result)
 		FOR_EACH_NOTE_YIELD_SUBTREES;
 	ret = for_each_note(t, flags, write_each_note, &cb_data) ||
 	      write_each_non_note_until(NULL, &cb_data) ||
-	      tree_write_stack_finish_subtree(&root) ||
-	      odb_write_object(the_repository->objects, root.buf.buf,
+	      tree_write_stack_finish_subtree(t->repo, &root) ||
+	      odb_write_object(t->repo->objects, root.buf.buf,
 			       root.buf.len, OBJ_TREE, result);
 	strbuf_release(&root.buf);
 	return ret;
@@ -1232,25 +1242,26 @@ int write_notes_tree(struct notes_tree *t, struct object_id *result)
 
 void prune_notes(struct notes_tree *t, int flags)
 {
-	struct note_delete_list *l = NULL;
+	struct prune_notes_data d = { 0 };
 
 	if (!t)
 		t = &default_notes_tree;
 	assert(t->initialized);
 
-	for_each_note(t, 0, prune_notes_helper, &l);
+	d.repo = t->repo;
+	for_each_note(t, 0, prune_notes_helper, &d);
 
-	while (l) {
+	while (d.list) {
 		struct note_delete_list *next;
 
 		if (flags & NOTES_PRUNE_VERBOSE)
-			printf("%s\n", hash_to_hex(l->sha1));
+			printf("%s\n", hash_to_hex(d.list->sha1));
 		if (!(flags & NOTES_PRUNE_DRYRUN))
-			remove_note(t, l->sha1);
+			remove_note(t, d.list->sha1);
 
-		next = l->next;
-		free(l);
-		l = next;
+		next = d.list->next;
+		free(d.list);
+		d.list = next;
 	}
 }
 
@@ -1368,7 +1379,8 @@ int copy_note(struct notes_tree *t,
 	if (note)
 		return add_note(t, to_obj, note, combine_notes);
 	else if (existing_note)
-		return add_note(t, to_obj, null_oid(the_hash_algo), combine_notes);
+		return add_note(t, to_obj, null_oid(t->repo->hash_algo),
+				combine_notes);
 
 	return 0;
 }
-- 
2.56.0
[PATCH v2 4/5] notes: pass the repository to the ref glob helpers
#3719
Author: Okhuomon Ajayi
Date: Tue, 24 Nov 2026 17:21
140 lines
15961 bytes
string_list_add_refs_by_glob() and
string_list_add_refs_from_colon_sep() walk refs in
the_repository. The caller already knows which repository
that is.

Take the repository as their first argument. Callers pass
the_repository for now.

Signed-off-by: Okhuomon Ajayi <okhuomonajayi54@gmail.com>
---
 notes-utils.c |  6 ++++--
 notes.c       | 21 +++++++++++++--------
 notes.h       |  6 ++++--
 3 files changed, 21 insertions(+), 12 deletions(-)

diff --git a/notes-utils.c b/notes-utils.c
index ea43fedd43..9f70366aa9 100644
--- a/notes-utils.c
+++ b/notes-utils.c
@@ -123,7 +123,8 @@ static int notes_rewrite_config(const char *k, const char *v,
 		/* note that a refs/ prefix is implied in the
 		 * underlying for_each_glob_ref */
 		if (starts_with(v, "refs/notes/"))
-			string_list_add_refs_by_glob(c->refs, v);
+			string_list_add_refs_by_glob(the_repository,
+						     c->refs, v);
 		else
 			warning(_("Refusing to rewrite notes in %s"
 				" (outside of refs/notes/)"), v);
@@ -160,7 +161,8 @@ struct notes_rewrite_cfg *init_copy_notes_for_rewrite(const char *cmd)
 	}
 	if (rewrite_refs_env) {
 		c->refs_from_env = 1;
-		string_list_add_refs_from_colon_sep(c->refs, rewrite_refs_env);
+		string_list_add_refs_from_colon_sep(the_repository, c->refs,
+						    rewrite_refs_env);
 	}
 	repo_config(the_repository, notes_rewrite_config, c);
 	if (!c->enabled || !c->refs->nr) {
diff --git a/notes.c b/notes.c
index 9d653c757a..ed6fc9a1c2 100644
--- a/notes.c
+++ b/notes.c
@@ -958,25 +958,27 @@ static int string_list_add_one_ref(const struct reference *ref, void *cb)
 /*
  * The list argument must have strdup_strings set on it.
  */
-void string_list_add_refs_by_glob(struct string_list *list, const char *glob)
+void string_list_add_refs_by_glob(struct repository *r,
+				  struct string_list *list, const char *glob)
 {
 	assert(list->strdup_strings);
 	if (has_glob_specials(glob)) {
 		struct refs_for_each_ref_options opts = {
 			.pattern = glob,
 		};
-		refs_for_each_ref_ext(get_main_ref_store(the_repository),
+		refs_for_each_ref_ext(get_main_ref_store(r),
 				      string_list_add_one_ref, list, &opts);
 	} else {
 		struct object_id oid;
-		if (repo_get_oid(the_repository, glob, &oid))
+		if (repo_get_oid(r, glob, &oid))
 			warning("notes ref %s is invalid", glob);
 		if (!unsorted_string_list_has_string(list, glob))
 			string_list_append(list, glob);
 	}
 }
 
-void string_list_add_refs_from_colon_sep(struct string_list *list,
+void string_list_add_refs_from_colon_sep(struct repository *r,
+					 struct string_list *list,
 					 const char *globs)
 {
 	struct string_list split = STRING_LIST_INIT_NODUP;
@@ -987,7 +989,7 @@ void string_list_add_refs_from_colon_sep(struct string_list *list,
 				     STRING_LIST_SPLIT_NONEMPTY);
 
 	for (i = 0; i < split.nr; i++)
-		string_list_add_refs_by_glob(list, split.items[i].string);
+		string_list_add_refs_by_glob(r, list, split.items[i].string);
 
 	string_list_clear(&split, 0);
 	free(globs_copy);
@@ -1002,7 +1004,8 @@ static int notes_display_config(const char *k, const char *v,
 	if (*load_refs && !strcmp(k, "notes.displayref")) {
 		if (!v)
 			return config_error_nonbool(k);
-		string_list_add_refs_by_glob(&display_notes_refs, v);
+		string_list_add_refs_by_glob(the_repository,
+					     &display_notes_refs, v);
 	}
 
 	return 0;
@@ -1133,7 +1136,8 @@ void load_display_notes(struct display_notes_opt *opt)
 		string_list_append_nodup(&display_notes_refs, default_notes_ref(the_repository));
 		display_ref_env = getenv(GIT_NOTES_DISPLAY_REF_ENVIRONMENT);
 		if (display_ref_env) {
-			string_list_add_refs_from_colon_sep(&display_notes_refs,
+			string_list_add_refs_from_colon_sep(the_repository,
+							    &display_notes_refs,
 							    display_ref_env);
 			load_config_refs = 0;
 		} else
@@ -1145,7 +1149,8 @@ void load_display_notes(struct display_notes_opt *opt)
 	if (opt) {
 		struct string_list_item *item;
 		for_each_string_list_item(item, &opt->extra_notes_refs)
-			string_list_add_refs_by_glob(&display_notes_refs,
+			string_list_add_refs_by_glob(the_repository,
+						     &display_notes_refs,
 						     item->string);
 	}
 
diff --git a/notes.h b/notes.h
index c81bc99446..520a816714 100644
--- a/notes.h
+++ b/notes.h
@@ -327,14 +327,16 @@ struct notes_tree **notes_tree_load(struct repository *r,
 /*
  * Add all refs that match 'glob' to the 'list'.
  */
-void string_list_add_refs_by_glob(struct string_list *list, const char *glob);
+void string_list_add_refs_by_glob(struct repository *r,
+				  struct string_list *list, const char *glob);
 
 /*
  * Add all refs from a colon-separated glob list 'globs' to the end of
  * 'list'.  Empty components are ignored.  This helper is used to
  * parse GIT_NOTES_DISPLAY_REF style environment variables.
  */
-void string_list_add_refs_from_colon_sep(struct string_list *list,
+void string_list_add_refs_from_colon_sep(struct repository *r,
+					 struct string_list *list,
 					 const char *globs);
 
 /* Expand inplace a note ref like "foo" or "notes/foo" into "refs/notes/foo" */
-- 
2.56.0
[PATCH v2 5/5] notes: pass the repository to the combine_notes callbacks
#3720
Author: Okhuomon Ajayi
Date: Tue, 24 Nov 2026 17:21
179 lines
17340 bytes
combine_notes_concatenate() and combine_notes_cat_sort_uniq() read
and write note blobs in the_repository, even when the notes tree
belongs to another repository. The callbacks are only called from
note_tree_insert(), which has the tree.

Pass the tree's repository to all combine_notes callbacks.

Signed-off-by: Okhuomon Ajayi <okhuomonajayi54@gmail.com>
---
 notes.c | 31 ++++++++++++++++++-------------
 notes.h | 23 ++++++++++++++---------
 2 files changed, 32 insertions(+), 22 deletions(-)

diff --git a/notes.c b/notes.c
index ed6fc9a1c2..055ba84b7d 100644
--- a/notes.c
+++ b/notes.c
@@ -279,7 +279,7 @@ static int note_tree_insert(struct notes_tree *t, struct int_node *tree,
 					return 0;
 				}
 
-				ret = combine_notes(&l->val_oid,
+				ret = combine_notes(t->repo, &l->val_oid,
 						    &entry->val_oid);
 				if (!ret && is_null_oid(&l->val_oid))
 					note_tree_remove(t, tree, n, entry);
@@ -816,7 +816,8 @@ static int prune_notes_helper(const struct object_id *object_oid,
 	return 0;
 }
 
-int combine_notes_concatenate(struct object_id *cur_oid,
+int combine_notes_concatenate(struct repository *r,
+			      struct object_id *cur_oid,
 			      const struct object_id *new_oid)
 {
 	char *cur_msg = NULL, *new_msg = NULL, *buf;
@@ -827,14 +828,14 @@ int combine_notes_concatenate(struct object_id *cur_oid,
 
 	/* read in both note blob objects */
 	if (!is_null_oid(new_oid))
-		new_msg = odb_read_object(the_repository->objects, new_oid,
+		new_msg = odb_read_object(r->objects, new_oid,
 					  &new_type, &new_len);
 	if (!new_msg || !new_len || new_type != OBJ_BLOB) {
 		free(new_msg);
 		return 0;
 	}
 	if (!is_null_oid(cur_oid))
-		cur_msg = odb_read_object(the_repository->objects, cur_oid,
+		cur_msg = odb_read_object(r->objects, cur_oid,
 					  &cur_type, &cur_len);
 	if (!cur_msg || !cur_len || cur_type != OBJ_BLOB) {
 		free(cur_msg);
@@ -858,20 +859,22 @@ int combine_notes_concatenate(struct object_id *cur_oid,
 	free(new_msg);
 
 	/* create a new blob object from buf */
-	ret = odb_write_object(the_repository->objects, buf,
+	ret = odb_write_object(r->objects, buf,
 			       buf_len, OBJ_BLOB, cur_oid);
 	free(buf);
 	return ret;
 }
 
-int combine_notes_overwrite(struct object_id *cur_oid,
+int combine_notes_overwrite(struct repository *r UNUSED,
+			    struct object_id *cur_oid,
 			    const struct object_id *new_oid)
 {
 	oidcpy(cur_oid, new_oid);
 	return 0;
 }
 
-int combine_notes_ignore(struct object_id *cur_oid UNUSED,
+int combine_notes_ignore(struct repository *r UNUSED,
+			 struct object_id *cur_oid UNUSED,
 			 const struct object_id *new_oid UNUSED)
 {
 	return 0;
@@ -881,7 +884,8 @@ int combine_notes_ignore(struct object_id *cur_oid UNUSED,
  * Add the lines from the named object to list, with trailing
  * newlines removed.
  */
-static int string_list_add_note_lines(struct string_list *list,
+static int string_list_add_note_lines(struct repository *r,
+				      struct string_list *list,
 				      const struct object_id *oid)
 {
 	char *data;
@@ -892,7 +896,7 @@ static int string_list_add_note_lines(struct string_list *list,
 		return 0;
 
 	/* read_sha1_file NUL-terminates */
-	data = odb_read_object(the_repository->objects, oid, &t, &len);
+	data = odb_read_object(r->objects, oid, &t, &len);
 	if (t != OBJ_BLOB || !data || !len) {
 		free(data);
 		return t != OBJ_BLOB || !data;
@@ -918,7 +922,8 @@ static int string_list_join_lines_helper(struct string_list_item *item,
 	return 0;
 }
 
-int combine_notes_cat_sort_uniq(struct object_id *cur_oid,
+int combine_notes_cat_sort_uniq(struct repository *r,
+				struct object_id *cur_oid,
 				const struct object_id *new_oid)
 {
 	struct string_list sort_uniq_list = STRING_LIST_INIT_DUP;
@@ -926,9 +931,9 @@ int combine_notes_cat_sort_uniq(struct object_id *cur_oid,
 	int ret = 1;
 
 	/* read both note blob objects into unique_lines */
-	if (string_list_add_note_lines(&sort_uniq_list, cur_oid))
+	if (string_list_add_note_lines(r, &sort_uniq_list, cur_oid))
 		goto out;
-	if (string_list_add_note_lines(&sort_uniq_list, new_oid))
+	if (string_list_add_note_lines(r, &sort_uniq_list, new_oid))
 		goto out;
 	string_list_remove_empty_items(&sort_uniq_list, 0);
 	string_list_sort_u(&sort_uniq_list, 0);
@@ -938,7 +943,7 @@ int combine_notes_cat_sort_uniq(struct object_id *cur_oid,
 				 string_list_join_lines_helper, &buf))
 		goto out;
 
-	ret = odb_write_object(the_repository->objects, buf.buf,
+	ret = odb_write_object(r->objects, buf.buf,
 			       buf.len, OBJ_BLOB, cur_oid);
 
 out:
diff --git a/notes.h b/notes.h
index 520a816714..3aa1d3e45e 100644
--- a/notes.h
+++ b/notes.h
@@ -13,10 +13,10 @@ struct strbuf;
  * When adding a new note annotating the same object as an existing note, it is
  * up to the caller to decide how to combine the two notes. The decision is
  * made by passing in a function of the following form. The function accepts
- * two object_ids -- of the existing note and the new note, respectively. The
- * function then combines the notes in whatever way it sees fit, and writes the
- * resulting oid into the first argument (cur_oid). A non-zero return
- * value indicates failure.
+ * the repository the notes live in and two object_ids -- of the existing
+ * note and the new note, respectively. The function then combines the notes
+ * in whatever way it sees fit, and writes the resulting oid into cur_oid.
+ * A non-zero return value indicates failure.
  *
  * The two given object_ids shall both be non-NULL and different from each
  * other. Either of them (but not both) may be == null_oid, which indicates an
@@ -27,17 +27,22 @@ struct strbuf;
  * combine_notes_concatenate(), which appends the contents of the new note to
  * the contents of the existing note.
  */
-typedef int (*combine_notes_fn)(struct object_id *cur_oid,
+typedef int (*combine_notes_fn)(struct repository *r,
+				struct object_id *cur_oid,
 				const struct object_id *new_oid);
 
 /* Common notes combinators */
-int combine_notes_concatenate(struct object_id *cur_oid,
+int combine_notes_concatenate(struct repository *r,
+			      struct object_id *cur_oid,
 			      const struct object_id *new_oid);
-int combine_notes_overwrite(struct object_id *cur_oid,
+int combine_notes_overwrite(struct repository *r,
+			    struct object_id *cur_oid,
 			    const struct object_id *new_oid);
-int combine_notes_ignore(struct object_id *cur_oid,
+int combine_notes_ignore(struct repository *r,
+			 struct object_id *cur_oid,
 			 const struct object_id *new_oid);
-int combine_notes_cat_sort_uniq(struct object_id *cur_oid,
+int combine_notes_cat_sort_uniq(struct repository *r,
+				struct object_id *cur_oid,
 				const struct object_id *new_oid);
 
 /*
-- 
2.56.0
Re: [PATCH v2 0/5] notes: start passing the repository through notes.[ch]
#3753
Author: Junio C Hamano
Date: Tue, 24 Nov 2026 22:50
17 lines
13269 bytes
Okhuomon Ajayi <okhuomonajayi54@gmail.com> writes:

> This is a preparatory series.

Whatever it is, this claims to be a "v2", but in the same discussion
thread, there already is a two-patch series labelled "v2" from November
3rd.  The original sin was the initial iteration of 6-patch series from
November 5th that did not identify itself as "v3", and calling this one
"v2" again is making things worse.  This is breaking automation, e.g.,
"b4 am" gets very confused.  I could use the "--no-parent" option, but
I shouldn't have to.

The next one should probably be called "v5", as this is what should have
been "v4", probably?

Thanks.
Re: [PATCH v2 1/5] notes: store the repository in struct notes_tree
#3766
Author: Junio C Hamano
Date: Wed, 25 Nov 2026 00:34
63 lines
15561 bytes
Okhuomon Ajayi <okhuomonajayi54@gmail.com> writes:

> A notes tree is always read from one repository, but the tree
> does not record which one. Later code has to fall back to
> the_repository.
>
> Store the repository on the tree. Rename init_notes() to
> notes_tree_init() and load_notes_trees() to notes_tree_load(),
> since every caller changes anyway. notes_tree_init() takes the
> tree first and the repository second, and saves the repository
> in t->repo. notes_tree_load() takes the repository first.
> notes_cache_init() passes the repository it was given. Other
> callers pass the_repository for now.

Keeping 't' first in notes_tree_init() and putting 'r' first in
notes_tree_load() addresses the v1 (or is that v3?) feedback cleanly.

> @@ -1034,6 +1035,7 @@ void init_notes(struct notes_tree *t, const char *notes_ref,
>  	t->root = (struct int_node *) xcalloc(1, sizeof(struct int_node));
>  	t->first_non_note = NULL;
>  	t->prev_non_note = NULL;
> +	t->repo = r;
>  	t->ref = xstrdup(notes_ref);
>  	t->update_ref = (flags & NOTES_INIT_WRITABLE) ? t->ref : NULL;
>  	t->combine_notes = combine_notes;

Here we set '.repo' before checking NOTES_INIT_EMPTY or calling
repo_get_oid_treeish() makes sure that even an empty or newly created
notes tree records its repository, which is OK.  free_notes() already
zeroes the whole struct on teardown.


> @@ -107,8 +108,9 @@ char *default_notes_ref(struct repository *repo);
>   * Precondition: The notes_tree structure is zeroed (this can be achieved with
>   * memset(t, 0, sizeof(struct notes_tree)))
>   */
> -void init_notes(struct notes_tree *t, const char *notes_ref,
> -		combine_notes_fn combine_notes, int flags);
> +void notes_tree_init(struct notes_tree *t, struct repository *r,
> +		     const char *notes_ref, combine_notes_fn combine_notes,
> +		     int flags);

The comment above this declaration seems incomplete; it talks about 't'
being a notes_tree to be (re)initialized, notes_ref (even though it
replaces the underscore with a space in the explanation), combine_notes
function, but not 'flags'.  Now we are adding 'r', so perhaps it is a
good idea to give a brief explanation for that (just say "the repository
that this notes_tree belongs to" or something like that)?

> @@ -319,7 +321,8 @@ void format_display_notes(const struct object_id *object_oid,
>   * Load the notes tree from each ref listed in 'refs'.  The output is
>   * an array of notes_tree*, terminated by a NULL.
>   */
> -struct notes_tree **load_notes_trees(struct string_list *refs, int flags);
> +struct notes_tree **notes_tree_load(struct repository *r,
> +				    struct string_list *refs, int flags);

I trust all existing references to old names are converted correctly
(which should be easy to verify---if not, the result would not compile
or link).

Looking good, so far.
Re: [PATCH v2 3/5] notes: use the tree's repository when writing and pruning
#3767
Author: Junio C Hamano
Date: Wed, 25 Nov 2026 00:54
50 lines
14543 bytes
Okhuomon Ajayi <okhuomonajayi54@gmail.com> writes:

> write_notes_tree() writes the notes tree into the_repository,
> and prune_notes() looks for missing objects there too. Both
> already have the notes tree.
>
> Write through t->repo. tree_write_stack_finish_subtree() takes
> the repository, passed down from the tree. prune_notes() hands
> the repository to its callback in a small struct.
>
> copy_note() also writes through the tree, by calling add_note(),
> so it uses the tree's hash algorithm for its null object ID.
>
> Signed-off-by: Okhuomon Ajayi <okhuomonajayi54@gmail.com>
> ---
> ...
> @@ -1368,7 +1379,8 @@ int copy_note(struct notes_tree *t,
>  	if (note)
>  		return add_note(t, to_obj, note, combine_notes);
>  	else if (existing_note)
> -		return add_note(t, to_obj, null_oid(the_hash_algo), combine_notes);
> +		return add_note(t, to_obj, null_oid(t->repo->hash_algo),
> +				combine_notes);
>  
>  	return 0;
>  }

Unlike prune_notes() and write_notes_tree(), copy_notes() does not like
to be fed a NULL as 't' and use the default_notes_tree as a stand-in.
The function begins with a call to get_note()

        const struct object_id *note = get_note(t, from_obj);
        const struct object_id *existing_note = get_note(t, to_obj);

so they can give you note and existing_note back to you safely, but t
copy_note() has may still be NULL, if the caller gave it a NULL.
Dereferencing t->repo->hash_algo here would probably be wrong in such a
case.  Instead, this function probably want the same

	if (!t)
		t = &default_notes_tree();
	assert(t->initialized);

dance as the others have.

Together with the earlier review on [2/5], if we were keeping
default_notes_tree support, we probably would want to tighten
how t==NULL is handled by each function on the call graph before
moving forward, I am afraid.
Re: [PATCH v2 2/5] notes: use the tree's repository when reading notes
#3768
Author: Junio C Hamano
Date: Wed, 25 Nov 2026 00:54
25 lines
13832 bytes
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.

Hmph.

Some of these functions like remove_note() and prune_notes() use
default_notes_tree as a stand-in when NULL is passed to 't', and they
also assert t->initialized before accessing t->repo.  So it should be
safe to convert them to access t->repo instead of the_repository.

But others?  note_tree_find() calls note_tree_search() which by itself
does not touch 't' at all as far as I can tell (which means 't' can
safely be NULL for notes_tree_search() because it does not dereference
it to access t->repo).  The conversion in this step would cause them to
dereference t->repo without checking if t is not NULL or t->initialized
member.  If they are already dereferencing t in the existing code and
assuming t is initialized, then this conversion is safe.  Otherwise, I
am not sure if a mechanical the_repository -> t->repo replacement is
good here.
Re: [PATCH v2 0/5] notes: start passing the repository through notes.[ch]
#3773
Author: Junio C Hamano
Date: Wed, 25 Nov 2026 01:14
31 lines
14134 bytes
Okhuomon Ajayi <okhuomonajayi54@gmail.com> writes:

> This is a preparatory series. It makes the code in notes.[c,h] and its
> direct callers work on the repository stored in struct notes_tree instead
> of the_repository. It deliberately does not convert the whole notes
> subsystem yet; it does the bulk of the work in notes.[c,h] and leaves the
> rest for future series.

Framing this as a preparatory series and splitting out the remaining
work makes the scope very clear.

> What is left for future series:
>  - notes.c: the display-notes code keeps its state in globals, and log,
>    format-patch, diff-tree and format-rev are given a repository but do
>    not pass it on. format_note() still falls back to the global
>    default_notes_tree, and expand_loose_notes_ref() only takes a strbuf.
>    The hash-size helpers are also still on the global.
>  - notes-utils.[c,h]: still use the_repository. And the hash-size helpers
>    still on the global are reached from here, through create_notes_commit()
>    -> write_notes_tree(), so converting notes-utils is tied to converting
>    those helpers too.
>  - notes-merge.[c,h]: still work on the global repository.

It seems taht notes-cache.c also still uses the_repository in
notes_cache_match_validity(), notes_cache_write(), notes_cache_get(),
and notes_cache_put(), even though notes_cache_init() now passes its
repository parameter to notes_tree_init().

Apart from the NULL check needed in copy_note() on patch 3, the series
looks in good shape.
Re: [PATCH v2 4/5] notes: pass the repository to the ref glob helpers
#3786
Author: Junio C Hamano
Date: Wed, 25 Nov 2026 05:12
12 lines
13030 bytes
Okhuomon Ajayi <okhuomonajayi54@gmail.com> writes:

> string_list_add_refs_by_glob() and
> string_list_add_refs_from_colon_sep() walk refs in
> the_repository. The caller already knows which repository
> that is.
>
> Take the repository as their first argument. Callers pass
> the_repository for now.

OK.  The callers all seem to have been converted.  Looking good.
Re: [PATCH v2 0/5] notes: start passing the repository through notes.[ch]
#3787
Author: Okhuomon Ajayi
Date: Wed, 25 Nov 2026 06:24
33 lines
13217 bytes
On Tue, Nov 24, 2026 at 11:50 PM Junio C Hamano <gitster@pobox.com> wrote:
> Whatever it is, this claims to be a "v2", but in the same discussion
> thread, there already is a two-patch series labelled "v2" from November
> 3rd. [...] The next one should probably be called "v5", as this is what
> should have been "v4", probably?

You're right, sorry for the confusion. The Nov 3 notes-utils series was
the v2, and this topic that started on Nov 5 should have continued the
count. I'll send the next iteration as v5 so b4 and the thread stay
consistent.

Okhuomon

On Tue, Nov 24, 2026 at 11:50 PM Junio C Hamano <gitster@pobox.com> wrote:
>
> Okhuomon Ajayi <okhuomonajayi54@gmail.com> writes:
>
> > This is a preparatory series.
>
> Whatever it is, this claims to be a "v2", but in the same discussion
> thread, there already is a two-patch series labelled "v2" from November
> 3rd.  The original sin was the initial iteration of 6-patch series from
> November 5th that did not identify itself as "v3", and calling this one
> "v2" again is making things worse.  This is breaking automation, e.g.,
> "b4 am" gets very confused.  I could use the "--no-parent" option, but
> I shouldn't have to.
>
> The next one should probably be called "v5", as this is what should have
> been "v4", probably?
>
> Thanks.
Re: [PATCH v2 0/5] notes: start passing the repository through notes.[ch]
#3788
Author: Okhuomon Ajayi
Date: Wed, 25 Nov 2026 06:35
55 lines
14284 bytes
On Tue, Nov 24, 2026 at 11:50 PM Junio C Hamano <gitster@pobox.com> wrote:
> It seems taht notes-cache.c also still uses the_repository in
> notes_cache_match_validity(), notes_cache_write(), notes_cache_get(),
> and notes_cache_put(), even though notes_cache_init() now passes its
> repository parameter to notes_tree_init().

Those four do still read the_repository there, even though
notes_cache_init() now has the repository to hand down. I kept them out
to hold this series to notes.[c,h], but they are the natural next step,
so I will list them in the cover letter under what is left rather than
pull them in here. The copy_note() NULL handling I will sort out in 3/5.

Okhuomon

On Wed, Nov 25, 2026 at 2:14 AM Junio C Hamano <gitster@pobox.com> wrote:
>
> Okhuomon Ajayi <okhuomonajayi54@gmail.com> writes:
>
> > This is a preparatory series. It makes the code in notes.[c,h] and its
> > direct callers work on the repository stored in struct notes_tree instead
> > of the_repository. It deliberately does not convert the whole notes
> > subsystem yet; it does the bulk of the work in notes.[c,h] and leaves the
> > rest for future series.
>
> Framing this as a preparatory series and splitting out the remaining
> work makes the scope very clear.
>
> > What is left for future series:
> >  - notes.c: the display-notes code keeps its state in globals, and log,
> >    format-patch, diff-tree and format-rev are given a repository but do
> >    not pass it on. format_note() still falls back to the global
> >    default_notes_tree, and expand_loose_notes_ref() only takes a strbuf.
> >    The hash-size helpers are also still on the global.
> >  - notes-utils.[c,h]: still use the_repository. And the hash-size helpers
> >    still on the global are reached from here, through create_notes_commit()
> >    -> write_notes_tree(), so converting notes-utils is tied to converting
> >    those helpers too.
> >  - notes-merge.[c,h]: still work on the global repository.
>
> It seems taht notes-cache.c also still uses the_repository in
> notes_cache_match_validity(), notes_cache_write(), notes_cache_get(),
> and notes_cache_put(), even though notes_cache_init() now passes its
> repository parameter to notes_tree_init().
>
> Apart from the NULL check needed in copy_note() on patch 3, the series
> looks in good shape.
>
Re: [PATCH v2 1/5] notes: store the repository in struct notes_tree
#3789
Author: Okhuomon Ajayi
Date: Wed, 25 Nov 2026 06:39
83 lines
15651 bytes
On Mon, Nov 24, 2026 at 1:34 AM Junio C Hamano <gitster@pobox.com> wrote:
> The comment above this declaration seems incomplete; it talks about 't'
> being a notes_tree to be (re)initialized, notes_ref [...], combine_notes
> function, but not 'flags'. Now we are adding 'r', so perhaps it is a
> good idea to give a brief explanation for that [...]?

The comment doesn't mention 'flags' either. I'll add a line describing
'r' (the repository this notes_tree belongs to) and one describing 'flags'.

Okhuomon

On Wed, Nov 25, 2026 at 1:34 AM Junio C Hamano <gitster@pobox.com> wrote:
>
> Okhuomon Ajayi <okhuomonajayi54@gmail.com> writes:
>
> > A notes tree is always read from one repository, but the tree
> > does not record which one. Later code has to fall back to
> > the_repository.
> >
> > Store the repository on the tree. Rename init_notes() to
> > notes_tree_init() and load_notes_trees() to notes_tree_load(),
> > since every caller changes anyway. notes_tree_init() takes the
> > tree first and the repository second, and saves the repository
> > in t->repo. notes_tree_load() takes the repository first.
> > notes_cache_init() passes the repository it was given. Other
> > callers pass the_repository for now.
>
> Keeping 't' first in notes_tree_init() and putting 'r' first in
> notes_tree_load() addresses the v1 (or is that v3?) feedback cleanly.
>
> > @@ -1034,6 +1035,7 @@ void init_notes(struct notes_tree *t, const char *notes_ref,
> >       t->root = (struct int_node *) xcalloc(1, sizeof(struct int_node));
> >       t->first_non_note = NULL;
> >       t->prev_non_note = NULL;
> > +     t->repo = r;
> >       t->ref = xstrdup(notes_ref);
> >       t->update_ref = (flags & NOTES_INIT_WRITABLE) ? t->ref : NULL;
> >       t->combine_notes = combine_notes;
>
> Here we set '.repo' before checking NOTES_INIT_EMPTY or calling
> repo_get_oid_treeish() makes sure that even an empty or newly created
> notes tree records its repository, which is OK.  free_notes() already
> zeroes the whole struct on teardown.
>
>
> > @@ -107,8 +108,9 @@ char *default_notes_ref(struct repository *repo);
> >   * Precondition: The notes_tree structure is zeroed (this can be achieved with
> >   * memset(t, 0, sizeof(struct notes_tree)))
> >   */
> > -void init_notes(struct notes_tree *t, const char *notes_ref,
> > -             combine_notes_fn combine_notes, int flags);
> > +void notes_tree_init(struct notes_tree *t, struct repository *r,
> > +                  const char *notes_ref, combine_notes_fn combine_notes,
> > +                  int flags);
>
> The comment above this declaration seems incomplete; it talks about 't'
> being a notes_tree to be (re)initialized, notes_ref (even though it
> replaces the underscore with a space in the explanation), combine_notes
> function, but not 'flags'.  Now we are adding 'r', so perhaps it is a
> good idea to give a brief explanation for that (just say "the repository
> that this notes_tree belongs to" or something like that)?
>
> > @@ -319,7 +321,8 @@ void format_display_notes(const struct object_id *object_oid,
> >   * Load the notes tree from each ref listed in 'refs'.  The output is
> >   * an array of notes_tree*, terminated by a NULL.
> >   */
> > -struct notes_tree **load_notes_trees(struct string_list *refs, int flags);
> > +struct notes_tree **notes_tree_load(struct repository *r,
> > +                                 struct string_list *refs, int flags);
>
> I trust all existing references to old names are converted correctly
> (which should be easy to verify---if not, the result would not compile
> or link).
>
> Looking good, so far.
Re: [PATCH v2 2/5] notes: use the tree's repository when reading notes
#3790
Author: Okhuomon Ajayi
Date: Wed, 25 Nov 2026 06:45
50 lines
14227 bytes
On Mon, Nov 24, 2026 at 1:34 AM Junio C Hamano <gitster@pobox.com> wrote:
> But others? note_tree_find() calls note_tree_search() which by itself
> does not touch 't' at all [...] The conversion in this step would cause
> them to dereference t->repo without checking if t is not NULL or
> t->initialized [...]

note_tree_find() has a single caller, get_note(). It replaces a NULL 't'
with &default_notes_tree and asserts t->initialized before passing
t->root down, so 't' is already non-NULL and initialized by the time we
read t->repo. note_tree_search() not touching 't' doesn't matter here,
since get_note() has already dereferenced it.

The other functions this patch converts are safe too, for slightly
different reasons: remove_note() and format_note() guard a NULL 't'
themselves, and add_non_note() and load_subtree() are only reached from
init_notes() (and load_subtree()'s own recursion), where 't' is the tree
being initialized and so is never NULL. So I believe this step is safe
as it stands.

Okhuomon

On Wed, Nov 25, 2026 at 1:54 AM Junio C Hamano <gitster@pobox.com> wrote:
>
> 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.
>
> Hmph.
>
> Some of these functions like remove_note() and prune_notes() use
> default_notes_tree as a stand-in when NULL is passed to 't', and they
> also assert t->initialized before accessing t->repo.  So it should be
> safe to convert them to access t->repo instead of the_repository.
>
> But others?  note_tree_find() calls note_tree_search() which by itself
> does not touch 't' at all as far as I can tell (which means 't' can
> safely be NULL for notes_tree_search() because it does not dereference
> it to access t->repo).  The conversion in this step would cause them to
> dereference t->repo without checking if t is not NULL or t->initialized
> member.  If they are already dereferencing t in the existing code and
> assuming t is initialized, then this conversion is safe.  Otherwise, I
> am not sure if a mechanical the_repository -> t->repo replacement is
> good here.
>
Re: [PATCH v2 3/5] notes: use the tree's repository when writing and pruning
#3791
Author: Okhuomon Ajayi
Date: Wed, 25 Nov 2026 06:48
80 lines
15025 bytes
On Mon, Nov 24, 2026 at 1:34 AM Junio C Hamano <gitster@pobox.com> wrote:
> Unlike prune_notes() and write_notes_tree(), copy_notes() does not like
> to be fed a NULL as 't' and use the default_notes_tree as a stand-in.
> [...] Dereferencing t->repo->hash_algo here would probably be wrong in
> such a case. Instead, this function probably want the same
> if (!t)
> t = &default_notes_tree();
> assert(t->initialized);
> dance as the others have.

You're right. copy_note() reaches t->repo->hash_algo without ever
substituting the default tree, so a NULL 't' would crash where it
didn't before. I'll add the

if (!t)
t = &default_notes_tree;
assert(t->initialized);

dance at the top of copy_note() in v5, matching remove_note() and the
others.

And thank you for the thorough read through the whole series. The
reviews have been genuinely helpful, and I'll roll all of this into v5.

Okhuomon

On Wed, Nov 25, 2026 at 1:54 AM Junio C Hamano <gitster@pobox.com> wrote:
>
> Okhuomon Ajayi <okhuomonajayi54@gmail.com> writes:
>
> > write_notes_tree() writes the notes tree into the_repository,
> > and prune_notes() looks for missing objects there too. Both
> > already have the notes tree.
> >
> > Write through t->repo. tree_write_stack_finish_subtree() takes
> > the repository, passed down from the tree. prune_notes() hands
> > the repository to its callback in a small struct.
> >
> > copy_note() also writes through the tree, by calling add_note(),
> > so it uses the tree's hash algorithm for its null object ID.
> >
> > Signed-off-by: Okhuomon Ajayi <okhuomonajayi54@gmail.com>
> > ---
> > ...
> > @@ -1368,7 +1379,8 @@ int copy_note(struct notes_tree *t,
> >       if (note)
> >               return add_note(t, to_obj, note, combine_notes);
> >       else if (existing_note)
> > -             return add_note(t, to_obj, null_oid(the_hash_algo), combine_notes);
> > +             return add_note(t, to_obj, null_oid(t->repo->hash_algo),
> > +                             combine_notes);
> >
> >       return 0;
> >  }
>
> Unlike prune_notes() and write_notes_tree(), copy_notes() does not like
> to be fed a NULL as 't' and use the default_notes_tree as a stand-in.
> The function begins with a call to get_note()
>
>         const struct object_id *note = get_note(t, from_obj);
>         const struct object_id *existing_note = get_note(t, to_obj);
>
> so they can give you note and existing_note back to you safely, but t
> copy_note() has may still be NULL, if the caller gave it a NULL.
> Dereferencing t->repo->hash_algo here would probably be wrong in such a
> case.  Instead, this function probably want the same
>
>         if (!t)
>                 t = &default_notes_tree();
>         assert(t->initialized);
>
> dance as the others have.
>
> Together with the earlier review on [2/5], if we were keeping
> default_notes_tree support, we probably would want to tighten
> how t==NULL is handled by each function on the call graph before
> moving forward, I am afraid.
Re: [PATCH v2 2/5] notes: use the tree's repository when reading notes
#3793
Author: Christian Couder
Date: Wed, 25 Nov 2026 08:25
40 lines
14016 bytes
On Wed, Nov 25, 2026 at 7:45 AM Okhuomon Ajayi
<okhuomonajayi54@gmail.com> wrote:
>
> On Mon, Nov 24, 2026 at 1:34 AM Junio C Hamano <gitster@pobox.com> wrote:
> > But others? note_tree_find() calls note_tree_search() which by itself
> > does not touch 't' at all [...] The conversion in this step would cause
> > them to dereference t->repo without checking if t is not NULL or
> > t->initialized [...]
>
> note_tree_find() has a single caller, get_note(). It replaces a NULL 't'
> with &default_notes_tree and asserts t->initialized before passing
> t->root down, so 't' is already non-NULL and initialized by the time we
> read t->repo. note_tree_search() not touching 't' doesn't matter here,
> since get_note() has already dereferenced it.
>
> The other functions this patch converts are safe too, for slightly
> different reasons: remove_note() and format_note() guard a NULL 't'
> themselves, and add_non_note() and load_subtree() are only reached from
> init_notes() (and load_subtree()'s own recursion), where 't' is the tree
> being initialized and so is never NULL. So I believe this step is safe
> as it stands.

It looks like load_subtree() can be reached in other ways, as subtrees
are unpacked on demand, like for example:

get_note() -> note_tree_find() -> note_tree_search() -> load_subtree()

So I think that the real argument why the other functions are safe is
that all the public entry points (add_note(), remove_note(),
get_note(), etc., and the internal format_note()) are safe as they
replace a NULL `t` with `&default_notes_tree` and assert
`t->initialized`.

copy_note() seems to be the only public function that doesn't do that,
which is what Junio found in 3/5.

It would be nice if the commit message of 2/5 in v5 briefly explained this.

Thanks.
Re: [PATCH v2 2/5] notes: use the tree's repository when reading notes
#3821
Author: Junio C Hamano
Date: Wed, 25 Nov 2026 17:50
22 lines
13738 bytes
Okhuomon Ajayi <okhuomonajayi54@gmail.com> writes:

> On Mon, Nov 24, 2026 at 1:34 AM Junio C Hamano <gitster@pobox.com> wrote:
>> But others? note_tree_find() calls note_tree_search() which by itself
>> does not touch 't' at all [...] The conversion in this step would cause
>> them to dereference t->repo without checking if t is not NULL or
>> t->initialized [...]
>
> note_tree_find() has a single caller, get_note(). It replaces a NULL 't'
> with &default_notes_tree and asserts t->initialized before passing
> t->root down, so 't' is already non-NULL and initialized by the time we
> read t->repo. note_tree_search() not touching 't' doesn't matter here,
> since get_note() has already dereferenced it.

OK, I missed the guarantees that these limited number of callers give
these functions being modified.

So copy_notes() in [3/5] is the only unsafe conversion we need to
rework in the next iteration, I guess?

Thanks.
Re: [PATCH v2 2/5] notes: use the tree's repository when reading notes
#3823
Author: Okhuomon Ajayi
Date: Wed, 25 Nov 2026 18:13
71 lines
15388 bytes
On Wed, Nov 25, 2026 at 8:25 AM Christian Couder
<christian.couder@gmail.com> wrote:
> It looks like load_subtree() can be reached in other ways, as subtrees
> are unpacked on demand, like for example:
> get_note() -> note_tree_find() -> note_tree_search() -> load_subtree()

Ah, right. I was only looking at the init path and missed that
note_tree_search() unpacks subtrees lazily, so load_subtree() (and
add_non_note() under it) gets reached during ordinary lookups too, not
just from init_notes().

So the cleaner way to put it is yours, the safety comes from the entry
points, not the individual helpers. The public ones (add_note(),
remove_note(), get_note()) swap a NULL 't' for &default_notes_tree and
assert t->initialized before anything downstream runs, and the internal
format_note() does the same NULL swap and initializes the tree if it
isn't already. Either way 't' is valid by the time we reach
note_tree_find()/load_subtree(). copy_note() is the only one that reads
t->repo without that guard, which is what 3/5 fixes. I'll fold that into
the 2/5 commit message.

Okhuomon

On Wed, Nov 25, 2026 at 9:25 AM Christian Couder
<christian.couder@gmail.com> wrote:
>
> On Wed, Nov 25, 2026 at 7:45 AM Okhuomon Ajayi
> <okhuomonajayi54@gmail.com> wrote:
> >
> > On Mon, Nov 24, 2026 at 1:34 AM Junio C Hamano <gitster@pobox.com> wrote:
> > > But others? note_tree_find() calls note_tree_search() which by itself
> > > does not touch 't' at all [...] The conversion in this step would cause
> > > them to dereference t->repo without checking if t is not NULL or
> > > t->initialized [...]
> >
> > note_tree_find() has a single caller, get_note(). It replaces a NULL 't'
> > with &default_notes_tree and asserts t->initialized before passing
> > t->root down, so 't' is already non-NULL and initialized by the time we
> > read t->repo. note_tree_search() not touching 't' doesn't matter here,
> > since get_note() has already dereferenced it.
> >
> > The other functions this patch converts are safe too, for slightly
> > different reasons: remove_note() and format_note() guard a NULL 't'
> > themselves, and add_non_note() and load_subtree() are only reached from
> > init_notes() (and load_subtree()'s own recursion), where 't' is the tree
> > being initialized and so is never NULL. So I believe this step is safe
> > as it stands.
>
> It looks like load_subtree() can be reached in other ways, as subtrees
> are unpacked on demand, like for example:
>
> get_note() -> note_tree_find() -> note_tree_search() -> load_subtree()
>
> So I think that the real argument why the other functions are safe is
> that all the public entry points (add_note(), remove_note(),
> get_note(), etc., and the internal format_note()) are safe as they
> replace a NULL `t` with `&default_notes_tree` and assert
> `t->initialized`.
>
> copy_note() seems to be the only public function that doesn't do that,
> which is what Junio found in 3/5.
>
> It would be nice if the commit message of 2/5 in v5 briefly explained this.
>
> Thanks.
Re: [PATCH v2 2/5] notes: use the tree's repository when reading notes
#3824
Author: Okhuomon Ajayi
Date: Wed, 25 Nov 2026 18:19
37 lines
13431 bytes
On Tue, Nov 25, 2026 at 1:54 AM Junio C Hamano <gitster@pobox.com> wrote:
> So copy_notes() in [3/5] is the only unsafe conversion we need to
> rework in the next iteration, I guess?

Yes, that's right. copy_note() in 3/5 is the only unsafe one. I'll add
the NULL guard there in v5; the rest of the series stays as it is.

Okhuomon

On Wed, Nov 25, 2026 at 6:50 PM Junio C Hamano <gitster@pobox.com> wrote:
>
> Okhuomon Ajayi <okhuomonajayi54@gmail.com> writes:
>
> > On Mon, Nov 24, 2026 at 1:34 AM Junio C Hamano <gitster@pobox.com> wrote:
> >> But others? note_tree_find() calls note_tree_search() which by itself
> >> does not touch 't' at all [...] The conversion in this step would cause
> >> them to dereference t->repo without checking if t is not NULL or
> >> t->initialized [...]
> >
> > note_tree_find() has a single caller, get_note(). It replaces a NULL 't'
> > with &default_notes_tree and asserts t->initialized before passing
> > t->root down, so 't' is already non-NULL and initialized by the time we
> > read t->repo. note_tree_search() not touching 't' doesn't matter here,
> > since get_note() has already dereferenced it.
>
> OK, I missed the guarantees that these limited number of callers give
> these functions being modified.
>
> So copy_notes() in [3/5] is the only unsafe conversion we need to
> rework in the next iteration, I guess?
>
> Thanks.
Re: [PATCH v2 2/5] notes: use the tree's repository when reading notes
#3842
Author: Junio C Hamano
Date: Wed, 25 Nov 2026 19:09
28 lines
13851 bytes
Okhuomon Ajayi <okhuomonajayi54@gmail.com> writes:

> So the cleaner way to put it is yours, the safety comes from the entry
> points, not the individual helpers. The public ones (add_note(),
> remove_note(), get_note()) swap a NULL 't' for &default_notes_tree and
> assert t->initialized before anything downstream runs, and the internal
> format_note() does the same NULL swap and initializes the tree if it
> isn't already.

Can we have a single helper function to do this?  Instead of repeating
the three-line dance all over, perhaps do

	t = helper(t);

where the helper does

        static struct notes_tree *helper(struct notes_tree *t)
        {
                if (!t)
                        t = &default_notes_tree;
                assert(!t->initialized);
                return t;
        }

or something?  Of course the helper must be given a much better name ;-)

Thanks.
Re: [PATCH v2 2/5] notes: use the tree's repository when reading notes
#3853
Author: Okhuomon Ajayi
Date: Wed, 25 Nov 2026 20:36
30 lines
13041 bytes
On Wed, Nov 25, 2026 at 8:09 PM Junio C Hamano <gitster@pobox.com> wrote:

> Can we have a single helper function to do this? Instead of repeating
> the three-line dance all over, perhaps do
>
> t = helper(t);
>
> where the helper does
>
> static struct notes_tree *helper(struct notes_tree *t)
> {
> if (!t)
> t = &default_notes_tree;
> assert(!t->initialized);
> return t;
> }
>
> or something? Of course the helper must be given a much better name ;-)

Good idea, the three lines repeat often enough to be worth a
helper. I'll add one and route add_note(), remove_note(),
get_note(), for_each_note(), write_notes_tree(), prune_notes()
and the new copy_note() through it, as a prep patch at the front
of the series.

I'll keep the assert(t->initialized) the sites already use, and
give it a real name, something like notes_tree_or_default().

Thanks.
[PATCH v5 0/6] notes: start passing the repository through notes.[ch]
#3861
Author: Okhuomon Ajayi
Date: Wed, 25 Nov 2026 22:02
156 lines
17758 bytes
This is a preparatory series. It makes the code in notes.[c,h] and its
direct callers work on the repository stored in struct notes_tree instead
of the_repository. It deliberately does not convert the whole notes
subsystem yet; it does the bulk of the work in notes.[c,h] and leaves the
rest for future series.

What it does:
 - adds notes_tree_or_default() for the shared NULL-tree check;
 - stores the repository in struct notes_tree;
 - uses the tree's repository when reading, writing and pruning notes;
 - passes the repository to the ref glob helpers and the combine_notes
   callbacks.

What is left for future series:
 - notes.c: the display-notes code keeps its state in globals, and log,
   format-patch, diff-tree and format-rev are given a repository but do
   not pass it on. format_note() still falls back to the global
   default_notes_tree, and expand_loose_notes_ref() only takes a strbuf.
   The hash-size helpers are also still on the global.
 - notes-utils.[c,h]: still use the_repository. And the hash-size helpers
   still on the global are reached from here, through create_notes_commit()
   -> write_notes_tree(), so converting notes-utils is tied to converting
   those helpers too.
 - notes-merge.[c,h]: still work on the global repository.
 - notes-cache.c: notes_cache_init() passes its repository through, but
   notes_cache_match_validity(), notes_cache_write(), notes_cache_get()
   and notes_cache_put() still use the_repository.

The previous round was labeled v2. It should have been v4, so this
reroll is v5.

Changes since v4:
 - Add notes_tree_or_default() and use it for the repeated NULL-tree
   check. copy_note() uses that helper for its new guard.
 - Document 'r' and 'flags' above notes_tree_init().
 - Explain in the reading patch why the converted helpers are safe
   when the tree is NULL. copy_note() was the exception.
 - List notes-cache.c with what is left for a future series.

Okhuomon Ajayi (6):
  notes: add notes_tree_or_default()
  notes: store the repository in struct notes_tree
  notes: use the tree's repository when reading notes
  notes: use the tree's repository when writing and pruning
  notes: pass the repository to the ref glob helpers
  notes: pass the repository to the combine_notes callbacks

 builtin/notes.c |   8 +-
 notes-cache.c   |   3 +-
 notes-utils.c   |   9 ++-
 notes.c         | 205 +++++++++++++++++++++++++++---------------------
 notes.h         |  44 +++++++----
 5 files changed, 159 insertions(+), 110 deletions(-)

Range-diff against v4:
-:  ---------- > 1:  c9891e887c notes: add notes_tree_or_default()
1:  5ad0f1bd62 ! 2:  831db4c68a notes: store the repository in struct notes_tree
    @@ notes.h: extern struct notes_tree {
       * This the first of the following to be defined:
       * 1. The '--ref' option to 'git notes', if given
     @@ notes.h: char *default_notes_ref(struct repository *repo);
    +  *
    +  * If you pass t == NULL, the default internal notes_tree will be initialized.
    +  *
    ++ * 'r' is the repository that this notes_tree belongs to.
    ++ *
    +  * The combine_notes function that is passed becomes the default combine_notes
    +  * function for the given notes_tree. If NULL is passed, the default
    +  * combine_notes function is combine_notes_concatenate().
    +  *
    ++ * 'flags' is a combination of the NOTES_INIT_* flags above.
    ++ *
       * Precondition: The notes_tree structure is zeroed (this can be achieved with
       * memset(t, 0, sizeof(struct notes_tree)))
       */
2:  1018419720 ! 3:  82f6f6ea7c notes: use the tree's repository when reading notes
    @@ Commit message
     
         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.
    +
         Signed-off-by: Okhuomon Ajayi <okhuomonajayi54@gmail.com>
     
      ## notes.c ##
    @@ notes.c: static void load_subtree(struct notes_tree *t, struct leaf_node *subtre
      				     entry.mode, entry.oid.hash);
      		}
     @@ notes.c: int remove_note(struct notes_tree *t, const unsigned char *object_sha1)
    - 	if (!t)
    - 		t = &default_notes_tree;
    - 	assert(t->initialized);
    + 	struct leaf_node l;
    + 
    + 	t = notes_tree_or_default(t);
     -	oidread(&l.key_oid, object_sha1, the_repository->hash_algo);
     -	oidclr(&l.val_oid, the_repository->hash_algo);
     +	oidread(&l.key_oid, object_sha1, t->repo->hash_algo);
3:  67a2942c09 ! 4:  b35eb50a45 notes: use the tree's repository when writing and pruning
    @@ Commit message
     
         copy_note() also writes through the tree, by calling add_note(),
         so it uses the tree's hash algorithm for its null object ID.
    +    It now takes a NULL tree the same way as the other entry points,
    +    through notes_tree_or_default(), before reading the tree's
    +    repository.
     
         Signed-off-by: Okhuomon Ajayi <okhuomonajayi54@gmail.com>
     
    @@ notes.c: int write_notes_tree(struct notes_tree *t, struct object_id *result)
     -	struct note_delete_list *l = NULL;
     +	struct prune_notes_data d = { 0 };
      
    - 	if (!t)
    - 		t = &default_notes_tree;
    - 	assert(t->initialized);
    + 	t = notes_tree_or_default(t);
      
     -	for_each_note(t, 0, prune_notes_helper, &l);
     +	d.repo = t->repo;
    @@ notes.c: int write_notes_tree(struct notes_tree *t, struct object_id *result)
      	}
      }
      
    +@@ notes.c: int copy_note(struct notes_tree *t,
    + 	      const struct object_id *from_obj, const struct object_id *to_obj,
    + 	      int force, combine_notes_fn combine_notes)
    + {
    +-	const struct object_id *note = get_note(t, from_obj);
    +-	const struct object_id *existing_note = get_note(t, to_obj);
    ++	const struct object_id *note;
    ++	const struct object_id *existing_note;
    ++
    ++	t = notes_tree_or_default(t);
    ++
    ++	note = get_note(t, from_obj);
    ++	existing_note = get_note(t, to_obj);
    + 
    + 	if (!force && existing_note)
    + 		return 1;
     @@ notes.c: int copy_note(struct notes_tree *t,
      	if (note)
      		return add_note(t, to_obj, note, combine_notes);
4:  7ea6c0e5a2 = 5:  dcda05343a notes: pass the repository to the ref glob helpers
5:  ff8cf4d22a = 6:  69928b58f6 notes: pass the repository to the combine_notes callbacks
-- 
2.56.0
[PATCH v5 1/6] notes: add notes_tree_or_default()
#3862
Author: Okhuomon Ajayi
Date: Wed, 25 Nov 2026 22:02
100 lines
13738 bytes
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.

Signed-off-by: Okhuomon Ajayi <okhuomonajayi54@gmail.com>
---
 notes.c | 32 ++++++++++++++------------------
 1 file changed, 14 insertions(+), 18 deletions(-)

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);
 	t->dirty = 1;
 	if (!combine_notes)
 		combine_notes = t->combine_notes;
@@ -1161,9 +1167,7 @@ int remove_note(struct notes_tree *t, const unsigned char *object_sha1)
 {
 	struct leaf_node l;
 
-	if (!t)
-		t = &default_notes_tree;
-	assert(t->initialized);
+	t = notes_tree_or_default(t);
 	oidread(&l.key_oid, object_sha1, the_repository->hash_algo);
 	oidclr(&l.val_oid, the_repository->hash_algo);
 	note_tree_remove(t, t->root, 0, &l);
@@ -1178,9 +1182,7 @@ const struct object_id *get_note(struct notes_tree *t,
 {
 	struct leaf_node *found;
 
-	if (!t)
-		t = &default_notes_tree;
-	assert(t->initialized);
+	t = notes_tree_or_default(t);
 	found = note_tree_find(t, t->root, 0, oid->hash);
 	return found ? &found->val_oid : NULL;
 }
@@ -1188,9 +1190,7 @@ const struct object_id *get_note(struct notes_tree *t,
 int for_each_note(struct notes_tree *t, int flags, each_note_fn fn,
 		void *cb_data)
 {
-	if (!t)
-		t = &default_notes_tree;
-	assert(t->initialized);
+	t = notes_tree_or_default(t);
 	return for_each_note_helper(t, t->root, 0, 0, flags, fn, cb_data);
 }
 
@@ -1201,9 +1201,7 @@ int write_notes_tree(struct notes_tree *t, struct object_id *result)
 	int ret;
 	int flags;
 
-	if (!t)
-		t = &default_notes_tree;
-	assert(t->initialized);
+	t = notes_tree_or_default(t);
 
 	/* Prepare for traversal of current notes tree */
 	root.next = NULL; /* last forward entry in list is grounded */
@@ -1229,9 +1227,7 @@ void prune_notes(struct notes_tree *t, int flags)
 {
 	struct note_delete_list *l = NULL;
 
-	if (!t)
-		t = &default_notes_tree;
-	assert(t->initialized);
+	t = notes_tree_or_default(t);
 
 	for_each_note(t, 0, prune_notes_helper, &l);
 
-- 
2.56.0
[PATCH v5 2/6] notes: store the repository in struct notes_tree
#3863
Author: Okhuomon Ajayi
Date: Wed, 25 Nov 2026 22:02
241 lines
20057 bytes
A notes tree is always read from one repository, but the tree
does not record which one. Later code has to fall back to
the_repository.

Store the repository on the tree. Rename init_notes() to
notes_tree_init() and load_notes_trees() to notes_tree_load(),
since every caller changes anyway. notes_tree_init() takes the
tree first and the repository second, and saves the repository
in t->repo. notes_tree_load() takes the repository first.
notes_cache_init() passes the repository it was given. Other
callers pass the_repository for now.

Signed-off-by: Okhuomon Ajayi <okhuomonajayi54@gmail.com>
---
 builtin/notes.c |  8 +++++---
 notes-cache.c   |  3 ++-
 notes-utils.c   |  3 ++-
 notes.c         | 30 ++++++++++++++++++------------
 notes.h         | 15 +++++++++++----
 5 files changed, 38 insertions(+), 21 deletions(-)

diff --git a/builtin/notes.c b/builtin/notes.c
index 9f1f0ec840..725280c785 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -370,7 +370,8 @@ static int notes_copy_from_stdin(int force, const char *rewrite_cmd)
 		if (!c)
 			return 0;
 	} else {
-		init_notes(NULL, NULL, NULL, NOTES_INIT_WRITABLE);
+		notes_tree_init(NULL, the_repository, NULL, NULL,
+				NOTES_INIT_WRITABLE);
 		t = &default_notes_tree;
 	}
 
@@ -420,7 +421,7 @@ static struct notes_tree *init_notes_check(const char *subcommand,
 {
 	struct notes_tree *t;
 	const char *ref;
-	init_notes(NULL, NULL, NULL, flags);
+	notes_tree_init(NULL, the_repository, NULL, NULL, flags);
 	t = &default_notes_tree;
 
 	ref = (flags & NOTES_INIT_WRITABLE) ? t->update_ref : t->ref;
@@ -841,7 +842,8 @@ static int merge_commit(struct notes_merge_options *o)
 	else
 		oidclr(&parent_oid, the_repository->hash_algo);
 
-	init_notes(&t, "NOTES_MERGE_PARTIAL", combine_notes_overwrite, 0);
+	notes_tree_init(&t, the_repository, "NOTES_MERGE_PARTIAL",
+			combine_notes_overwrite, 0);
 
 	o->local_ref = local_ref_to_free =
 		refs_resolve_refdup(get_main_ref_store(the_repository),
diff --git a/notes-cache.c b/notes-cache.c
index 74cef802bd..b9a2940435 100644
--- a/notes-cache.c
+++ b/notes-cache.c
@@ -50,7 +50,8 @@ void notes_cache_init(struct repository *r, struct notes_cache *c,
 	strbuf_addf(&ref, "refs/notes/%s", name);
 	if (!notes_cache_match_validity(r, ref.buf, validity))
 		flags |= NOTES_INIT_EMPTY;
-	init_notes(&c->tree, ref.buf, combine_notes_overwrite, flags);
+	notes_tree_init(&c->tree, r, ref.buf,
+			combine_notes_overwrite, flags);
 	strbuf_release(&ref);
 }
 
diff --git a/notes-utils.c b/notes-utils.c
index 5c1c75d5b8..ea43fedd43 100644
--- a/notes-utils.c
+++ b/notes-utils.c
@@ -169,7 +169,8 @@ struct notes_rewrite_cfg *init_copy_notes_for_rewrite(const char *cmd)
 		free(c);
 		return NULL;
 	}
-	c->trees = load_notes_trees(c->refs, NOTES_INIT_WRITABLE);
+	c->trees = notes_tree_load(the_repository, c->refs,
+				   NOTES_INIT_WRITABLE);
 	string_list_clear(c->refs, 0);
 	free(c->refs);
 	return c;
diff --git a/notes.c b/notes.c
index a73a51e1a0..6bfe80f176 100644
--- a/notes.c
+++ b/notes.c
@@ -1012,8 +1012,9 @@ char *default_notes_ref(struct repository *repo)
 	return notes_ref;
 }
 
-void init_notes(struct notes_tree *t, const char *notes_ref,
-		combine_notes_fn combine_notes, int flags)
+void notes_tree_init(struct notes_tree *t, struct repository *r,
+		     const char *notes_ref, combine_notes_fn combine_notes,
+		     int flags)
 {
 	struct object_id oid, object_oid;
 	unsigned short mode;
@@ -1025,7 +1026,7 @@ void init_notes(struct notes_tree *t, const char *notes_ref,
 	assert(!t->initialized);
 
 	if (!notes_ref)
-		notes_ref = to_free = default_notes_ref(the_repository);
+		notes_ref = to_free = default_notes_ref(r);
 	update_ref_namespace(NAMESPACE_NOTES, xstrdup(notes_ref));
 
 	if (!combine_notes)
@@ -1034,6 +1035,7 @@ void init_notes(struct notes_tree *t, const char *notes_ref,
 	t->root = (struct int_node *) xcalloc(1, sizeof(struct int_node));
 	t->first_non_note = NULL;
 	t->prev_non_note = NULL;
+	t->repo = r;
 	t->ref = xstrdup(notes_ref);
 	t->update_ref = (flags & NOTES_INIT_WRITABLE) ? t->ref : NULL;
 	t->combine_notes = combine_notes;
@@ -1041,15 +1043,15 @@ void init_notes(struct notes_tree *t, const char *notes_ref,
 	t->dirty = 0;
 
 	if (flags & NOTES_INIT_EMPTY ||
-	    repo_get_oid_treeish(the_repository, notes_ref, &object_oid))
+	    repo_get_oid_treeish(r, notes_ref, &object_oid))
 		goto out;
-	if (flags & NOTES_INIT_WRITABLE && refs_read_ref(get_main_ref_store(the_repository), notes_ref, &object_oid))
+	if (flags & NOTES_INIT_WRITABLE && refs_read_ref(get_main_ref_store(r), notes_ref, &object_oid))
 		die("Cannot use notes ref %s", notes_ref);
-	if (get_tree_entry(the_repository, &object_oid, "", &oid, &mode))
+	if (get_tree_entry(r, &object_oid, "", &oid, &mode))
 		die("Failed to read notes tree referenced by %s (%s)",
 		    notes_ref, oid_to_hex(&object_oid));
 
-	oidclr(&root_tree.key_oid, the_repository->hash_algo);
+	oidclr(&root_tree.key_oid, r->hash_algo);
 	oidcpy(&root_tree.val_oid, &oid);
 	load_subtree(t, &root_tree, t->root, 0);
 
@@ -1057,7 +1059,8 @@ void init_notes(struct notes_tree *t, const char *notes_ref,
 	free(to_free);
 }
 
-struct notes_tree **load_notes_trees(struct string_list *refs, int flags)
+struct notes_tree **notes_tree_load(struct repository *r,
+				    struct string_list *refs, int flags)
 {
 	struct string_list_item *item;
 	int counter = 0;
@@ -1065,7 +1068,8 @@ struct notes_tree **load_notes_trees(struct string_list *refs, int flags)
 	ALLOC_ARRAY(trees, refs->nr + 1);
 	for_each_string_list_item(item, refs) {
 		struct notes_tree *t = xcalloc(1, sizeof(struct notes_tree));
-		init_notes(t, item->string, combine_notes_ignore, flags);
+		notes_tree_init(t, r, item->string,
+				combine_notes_ignore, flags);
 		trees[counter++] = t;
 	}
 	trees[counter] = NULL;
@@ -1136,7 +1140,8 @@ void load_display_notes(struct display_notes_opt *opt)
 						     item->string);
 	}
 
-	display_notes_trees = load_notes_trees(&display_notes_refs, 0);
+	display_notes_trees = notes_tree_load(the_repository,
+					      &display_notes_refs, 0);
 	string_list_clear(&display_notes_refs, 0);
 }
 
@@ -1266,7 +1271,8 @@ void free_notes(struct notes_tree *t)
  * Fill the given strbuf with the notes associated with the given object.
  *
  * If the given notes_tree structure is not initialized, it will be auto-
- * initialized to the default value (see documentation for init_notes() above).
+ * initialized to the default value (see documentation for
+ * notes_tree_init() above).
  * If the given notes_tree is NULL, the internal/default notes_tree will be
  * used instead.
  *
@@ -1286,7 +1292,7 @@ static void format_note(struct notes_tree *t, const struct object_id *object_oid
 	if (!t)
 		t = &default_notes_tree;
 	if (!t->initialized)
-		init_notes(t, NULL, NULL, 0);
+		notes_tree_init(t, the_repository, NULL, NULL, 0);
 
 	oid = get_note(t, object_oid);
 	if (!oid)
diff --git a/notes.h b/notes.h
index 6dc6d7b265..f4d1e31cd8 100644
--- a/notes.h
+++ b/notes.h
@@ -50,6 +50,7 @@ int combine_notes_cat_sort_uniq(struct object_id *cur_oid,
  * simultaneously.
  */
 extern struct notes_tree {
+	struct repository *repo;
 	struct int_node *root;
 	struct non_note *first_non_note, *prev_non_note;
 	char *ref;
@@ -63,7 +64,7 @@ extern struct notes_tree {
  * Return the default notes ref.
  *
  * The default notes ref is the notes ref that is used when notes_ref == NULL
- * is passed to init_notes().
+ * is passed to notes_tree_init().
  *
  * This the first of the following to be defined:
  * 1. The '--ref' option to 'git notes', if given
@@ -100,15 +101,20 @@ char *default_notes_ref(struct repository *repo);
  *
  * If you pass t == NULL, the default internal notes_tree will be initialized.
  *
+ * 'r' is the repository that this notes_tree belongs to.
+ *
  * The combine_notes function that is passed becomes the default combine_notes
  * function for the given notes_tree. If NULL is passed, the default
  * combine_notes function is combine_notes_concatenate().
  *
+ * 'flags' is a combination of the NOTES_INIT_* flags above.
+ *
  * Precondition: The notes_tree structure is zeroed (this can be achieved with
  * memset(t, 0, sizeof(struct notes_tree)))
  */
-void init_notes(struct notes_tree *t, const char *notes_ref,
-		combine_notes_fn combine_notes, int flags);
+void notes_tree_init(struct notes_tree *t, struct repository *r,
+		     const char *notes_ref, combine_notes_fn combine_notes,
+		     int flags);
 
 /*
  * Add the given note object to the given notes_tree structure
@@ -319,7 +325,8 @@ void format_display_notes(const struct object_id *object_oid,
  * Load the notes tree from each ref listed in 'refs'.  The output is
  * an array of notes_tree*, terminated by a NULL.
  */
-struct notes_tree **load_notes_trees(struct string_list *refs, int flags);
+struct notes_tree **notes_tree_load(struct repository *r,
+				    struct string_list *refs, int flags);
 
 /*
  * Add all refs that match 'glob' to the 'list'.
-- 
2.56.0
[PATCH v5 3/6] notes: use the tree's repository when reading notes
#3864
Author: Okhuomon Ajayi
Date: Wed, 25 Nov 2026 22:02
98 lines
14797 bytes
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.

Signed-off-by: Okhuomon Ajayi <okhuomonajayi54@gmail.com>
---
 notes.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/notes.c b/notes.c
index 6bfe80f176..da63d35935 100644
--- a/notes.c
+++ b/notes.c
@@ -153,7 +153,7 @@ static struct leaf_node *note_tree_find(struct notes_tree *t,
 	void **p = note_tree_search(t, &tree, &n, key_sha1);
 	if (GET_PTR_TYPE(*p) == PTR_TYPE_NOTE) {
 		struct leaf_node *l = (struct leaf_node *) CLR_PTR_TYPE(*p);
-		if (hasheq(key_sha1, l->key_oid.hash, the_repository->hash_algo))
+		if (hasheq(key_sha1, l->key_oid.hash, t->repo->hash_algo))
 			return l;
 	}
 	return NULL;
@@ -357,7 +357,7 @@ static void add_non_note(struct notes_tree *t, char *path,
 	n->next = NULL;
 	n->path = path;
 	n->mode = mode;
-	oidread(&n->oid, sha1, the_repository->hash_algo);
+	oidread(&n->oid, sha1, t->repo->hash_algo);
 	t->prev_non_note = n;
 
 	if (!t->first_non_note) {
@@ -402,9 +402,9 @@ static void load_subtree(struct notes_tree *t, struct leaf_node *subtree,
 	void *buf;
 	struct tree_desc desc;
 	struct name_entry entry;
-	const unsigned hashsz = the_hash_algo->rawsz;
+	const unsigned hashsz = t->repo->hash_algo->rawsz;
 
-	buf = fill_tree_descriptor(the_repository, &desc, &subtree->val_oid);
+	buf = fill_tree_descriptor(t->repo, &desc, &subtree->val_oid);
 	if (!buf)
 		die("Could not read %s for notes-index",
 		     oid_to_hex(&subtree->val_oid));
@@ -462,8 +462,8 @@ static void load_subtree(struct notes_tree *t, struct leaf_node *subtree,
 		CALLOC_ARRAY(l, 1);
 		oidcpy(&l->key_oid, &object_oid);
 		oidcpy(&l->val_oid, &entry.oid);
-		oid_set_algo(&l->key_oid, the_hash_algo);
-		oid_set_algo(&l->val_oid, the_hash_algo);
+		oid_set_algo(&l->key_oid, t->repo->hash_algo);
+		oid_set_algo(&l->val_oid, t->repo->hash_algo);
 		if (note_tree_insert(t, node, n, l, type,
 				     combine_notes_concatenate))
 			die("Failed to load %s %s into notes tree "
@@ -493,7 +493,7 @@ static void load_subtree(struct notes_tree *t, struct leaf_node *subtree,
 				strbuf_addch(&non_note_path, '/');
 			}
 			strbuf_addstr(&non_note_path, entry.path);
-			oid_set_algo(&entry.oid, the_hash_algo);
+			oid_set_algo(&entry.oid, t->repo->hash_algo);
 			add_non_note(t, strbuf_detach(&non_note_path, NULL),
 				     entry.mode, entry.oid.hash);
 		}
@@ -1173,8 +1173,8 @@ int remove_note(struct notes_tree *t, const unsigned char *object_sha1)
 	struct leaf_node l;
 
 	t = notes_tree_or_default(t);
-	oidread(&l.key_oid, object_sha1, the_repository->hash_algo);
-	oidclr(&l.val_oid, the_repository->hash_algo);
+	oidread(&l.key_oid, object_sha1, t->repo->hash_algo);
+	oidclr(&l.val_oid, t->repo->hash_algo);
 	note_tree_remove(t, t->root, 0, &l);
 	if (is_null_oid(&l.val_oid)) /* no note was removed */
 		return 1;
@@ -1298,7 +1298,7 @@ static void format_note(struct notes_tree *t, const struct object_id *object_oid
 	if (!oid)
 		return;
 
-	if (!(msg = odb_read_object(the_repository->objects, oid, &type, &msglen)) ||
+	if (!(msg = odb_read_object(t->repo->objects, oid, &type, &msglen)) ||
 	    type != OBJ_BLOB) {
 		free(msg);
 		return;
-- 
2.56.0
Page 1 of 2 • 79 total messages
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads